验证20%
This commit is contained in:
@@ -5,6 +5,77 @@
|
||||
|
||||
var layuiReady = false;
|
||||
var layerApi = null;
|
||||
var genealogyContextStorageKey = 'genealogy_current_context_v1';
|
||||
var mobileMenuId = 'profile-mobile-menu';
|
||||
|
||||
function getSessionStorage() {
|
||||
try {
|
||||
return window.sessionStorage;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeGenealogyName(value) {
|
||||
var name = String(value === undefined || value === null ? '' : value).trim();
|
||||
|
||||
return name && name.length <= 80 ? name : '';
|
||||
}
|
||||
|
||||
function getStoredGenealogyContext() {
|
||||
var storage = getSessionStorage();
|
||||
var stored;
|
||||
var context;
|
||||
var genealogyId;
|
||||
var genealogyName;
|
||||
|
||||
if (!storage) return null;
|
||||
try {
|
||||
stored = storage.getItem(genealogyContextStorageKey);
|
||||
context = stored ? JSON.parse(stored) : null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
genealogyId = normalizeGenealogyId(context && context.genealogyId);
|
||||
genealogyName = normalizeGenealogyName(context && context.genealogyName);
|
||||
return genealogyId && genealogyName ? {
|
||||
genealogyId: genealogyId,
|
||||
genealogyName: genealogyName
|
||||
} : null;
|
||||
}
|
||||
|
||||
function setCurrentGenealogyContext(genealogyId, genealogyName) {
|
||||
var storage = getSessionStorage();
|
||||
var context = {
|
||||
genealogyId: normalizeGenealogyId(genealogyId),
|
||||
genealogyName: normalizeGenealogyName(genealogyName)
|
||||
};
|
||||
|
||||
if (!context.genealogyId || !context.genealogyName) return null;
|
||||
if (storage) {
|
||||
try {
|
||||
storage.setItem(genealogyContextStorageKey, JSON.stringify(context));
|
||||
} catch (error) {}
|
||||
}
|
||||
renderCurrentGenealogyContext();
|
||||
return context;
|
||||
}
|
||||
|
||||
function clearCurrentGenealogyContext() {
|
||||
var storage = getSessionStorage();
|
||||
|
||||
if (!storage) return;
|
||||
try {
|
||||
storage.removeItem(genealogyContextStorageKey);
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
function getCurrentGenealogyContext() {
|
||||
var genealogyId = getGenealogyId();
|
||||
var context = getStoredGenealogyContext();
|
||||
|
||||
return context && context.genealogyId === genealogyId ? context : null;
|
||||
}
|
||||
|
||||
function openLegacyLogout() {
|
||||
var $modal = $('#logoutModal');
|
||||
@@ -58,6 +129,7 @@
|
||||
function performLogout(targetUrl) {
|
||||
var api = window.GenealogyApi && window.GenealogyApi.defaultClient;
|
||||
var redirect = function () {
|
||||
clearCurrentGenealogyContext();
|
||||
window.location.href = targetUrl || 'index.html';
|
||||
};
|
||||
|
||||
@@ -172,6 +244,113 @@
|
||||
});
|
||||
}
|
||||
|
||||
function renderCurrentGenealogyContext() {
|
||||
var context = getCurrentGenealogyContext();
|
||||
var name = context ? context.genealogyName : '正在识别家谱';
|
||||
|
||||
$('[data-current-genealogy-name]').text(name);
|
||||
$('[data-current-genealogy-link]').attr('aria-label', context ?
|
||||
'当前家谱:' + context.genealogyName + ',点击切换家谱' :
|
||||
'当前家谱,点击切换家谱');
|
||||
}
|
||||
|
||||
function refreshCurrentGenealogyContext() {
|
||||
var genealogyId = getGenealogyId();
|
||||
var api = window.GenealogyApi && window.GenealogyApi.defaultClient;
|
||||
|
||||
if (!genealogyId || getCurrentGenealogyContext() || !api || !api.genealogyDetail) return;
|
||||
api.genealogyDetail(genealogyId).then(function (detail) {
|
||||
var detailId = normalizeGenealogyId(detail && detail.genealogyId);
|
||||
var detailName = normalizeGenealogyName(detail && detail.genealogyName);
|
||||
|
||||
if (detailId === genealogyId && detailName) {
|
||||
setCurrentGenealogyContext(detailId, detailName);
|
||||
}
|
||||
}).catch(function () {
|
||||
$('[data-current-genealogy-name]').text('当前家谱');
|
||||
});
|
||||
}
|
||||
|
||||
function initCurrentGenealogyContext() {
|
||||
var genealogyId = getGenealogyId();
|
||||
var $nav;
|
||||
var $actions;
|
||||
var $context;
|
||||
|
||||
if (!genealogyId) return;
|
||||
$nav = $('.site-header .nav').first();
|
||||
if (!$nav.length || $nav.find('[data-current-genealogy-link]').length) return;
|
||||
$context = $('<a class="profile-current-genealogy" data-current-genealogy-link href="profile-families.html">' +
|
||||
'<span>当前家谱</span><strong data-current-genealogy-name>正在识别家谱</strong></a>');
|
||||
$actions = $nav.find('.nav-actions').first();
|
||||
if ($actions.length) $context.insertBefore($actions);
|
||||
else $nav.append($context);
|
||||
renderCurrentGenealogyContext();
|
||||
refreshCurrentGenealogyContext();
|
||||
}
|
||||
|
||||
function setMobileMenuOpen(isOpen) {
|
||||
var $menu = $('[data-profile-mobile-menu]').first();
|
||||
var $toggle = $('[data-profile-mobile-menu-toggle]').first();
|
||||
|
||||
if (!$menu.length || !$toggle.length) return;
|
||||
$menu.prop('hidden', !isOpen).toggleClass('is-open', !!isOpen).attr('aria-hidden', isOpen ? 'false' : 'true');
|
||||
$toggle.attr('aria-expanded', isOpen ? 'true' : 'false');
|
||||
}
|
||||
|
||||
function initMobileMenu() {
|
||||
var $header = $('.site-header').first();
|
||||
var $nav;
|
||||
var currentPage;
|
||||
|
||||
if (!$header.length || $header.find('[data-profile-mobile-menu]').length) return;
|
||||
$nav = $header.find('.nav').first();
|
||||
if (!$nav.length) return;
|
||||
$nav.append('<button class="profile-mobile-menu-toggle" type="button" data-profile-mobile-menu-toggle ' +
|
||||
'aria-expanded="false" aria-controls="' + mobileMenuId + '">菜单</button>');
|
||||
$header.append('<div class="profile-mobile-menu" id="' + mobileMenuId + '" data-profile-mobile-menu hidden aria-hidden="true">' +
|
||||
'<div class="container profile-mobile-menu-inner">' +
|
||||
'<a href="profile.html">个人中心</a>' +
|
||||
'<a href="profile-families.html">我的家谱</a>' +
|
||||
'<a href="profile-create-family.html">创建家谱</a>' +
|
||||
'<a href="profile-family-home.html" data-genealogy-context-link>家谱主页</a>' +
|
||||
'<a href="profile-content.html" data-genealogy-context-link>内容发布</a>' +
|
||||
'<a href="profile-family-admin.html" data-genealogy-context-link>家族管理</a>' +
|
||||
'<a href="profile-data.html">个人资料</a>' +
|
||||
'<a href="profile-messages.html">消息中心</a>' +
|
||||
'<a href="profile-services.html">帮助与服务</a>' +
|
||||
'<button type="button" data-logout-open data-logout-url="index.html">退出登录</button>' +
|
||||
'</div></div>');
|
||||
currentPage = (window.location.pathname.split('/').pop() || 'profile.html').split('?')[0];
|
||||
$header.find('[data-profile-mobile-menu] a').each(function () {
|
||||
var $link = $(this);
|
||||
var target = ($link.attr('href') || '').split('?')[0];
|
||||
|
||||
if (target === currentPage) $link.addClass('is-current').attr('aria-current', 'page');
|
||||
});
|
||||
}
|
||||
|
||||
function bindGenealogySelection() {
|
||||
$(document).on('click', '[data-genealogy-id][data-genealogy-name]', function () {
|
||||
setCurrentGenealogyContext($(this).attr('data-genealogy-id'), $(this).attr('data-genealogy-name'));
|
||||
});
|
||||
}
|
||||
|
||||
function bindMobileMenu() {
|
||||
$(document).on('click', '[data-profile-mobile-menu-toggle]', function () {
|
||||
setMobileMenuOpen($(this).attr('aria-expanded') !== 'true');
|
||||
});
|
||||
$(document).on('click', '[data-profile-mobile-menu] a, [data-profile-mobile-menu] button', function () {
|
||||
setMobileMenuOpen(false);
|
||||
});
|
||||
$(document).on('click', function (event) {
|
||||
if (!$(event.target).closest('.site-header').length) setMobileMenuOpen(false);
|
||||
});
|
||||
$(document).on('keydown', function (event) {
|
||||
if (event.key === 'Escape') setMobileMenuOpen(false);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDisplay($trigger, value) {
|
||||
var target = $trigger.attr('data-update-target');
|
||||
var $target = target ? $(target) : $trigger.closest('p').find('b').first();
|
||||
@@ -277,6 +456,10 @@
|
||||
bindSelectActions();
|
||||
bindMessageActions();
|
||||
bindSelectableCards();
|
||||
bindGenealogySelection();
|
||||
bindMobileMenu();
|
||||
initCurrentGenealogyContext();
|
||||
initMobileMenu();
|
||||
syncGenealogyContextLinks();
|
||||
});
|
||||
|
||||
@@ -288,6 +471,10 @@
|
||||
normalizeGenealogyId: normalizeGenealogyId,
|
||||
withGenealogyId: withGenealogyId,
|
||||
getGenealogyEntryUrl: getGenealogyEntryUrl,
|
||||
getCurrentGenealogyContext: getCurrentGenealogyContext,
|
||||
setCurrentGenealogyContext: setCurrentGenealogyContext,
|
||||
clearCurrentGenealogyContext: clearCurrentGenealogyContext,
|
||||
refreshCurrentGenealogyContext: refreshCurrentGenealogyContext,
|
||||
syncGenealogyContextLinks: syncGenealogyContextLinks
|
||||
};
|
||||
})(window, window.jQuery || (window.layui && window.layui.$));
|
||||
|
||||
Reference in New Issue
Block a user