* support for changing theme.
This commit is contained in:
@@ -60,6 +60,18 @@ class pageBase extends wg
|
||||
$css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
|
||||
$js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
|
||||
$imports = context::current()->getImportList();
|
||||
$webRoot = $app->getWebRoot();
|
||||
$themeName = $app->cookie->theme;
|
||||
|
||||
$headImports = array();
|
||||
if($zui)
|
||||
{
|
||||
$headImports[] = h::importCss($config->zin->zuiPath . 'zui.zentao.css', set::id('zuiCSS'));
|
||||
$headImports[] = h::importCss($config->zin->zuiPath . 'themes/' . $themeName . '.css', set::id('zuiTheme'));
|
||||
$headImports[] = h::importJs($config->zin->zuiPath . 'zui.zentao.umd.cjs', set::id('zuiJS'));
|
||||
}
|
||||
$headImports[] = h::jsVar('window.config', $jsConfig, setID('configJS'));
|
||||
$headImports[] = h::importJs($webRoot . 'js/zui3/zin.js', set::id('zinJS'));
|
||||
|
||||
$jsConfig->zin = true;
|
||||
if($config->debug)
|
||||
@@ -80,16 +92,14 @@ class pageBase extends wg
|
||||
(
|
||||
before(html('<!DOCTYPE html>')),
|
||||
set($attrs),
|
||||
set::class("theme-$themeName"),
|
||||
set::lang($currentLang),
|
||||
h::head
|
||||
(
|
||||
html($metas),
|
||||
h::title($title),
|
||||
$this->block('headBefore'),
|
||||
$zui ? h::importCss($config->zin->zuiPath . 'zui.zentao.css', set::id('zuiCSS')) : null,
|
||||
$zui ? h::importJs($config->zin->zuiPath . 'zui.zentao.umd.cjs', set::id('zuiJS')) : null,
|
||||
h::jsVar('window.config', $jsConfig, setID('configJS')),
|
||||
$zui ? h::importJs($app->getWebRoot() . 'js/zui3/zin.js', set::id('zinJS')) : null,
|
||||
$headImports,
|
||||
$head,
|
||||
),
|
||||
h::body
|
||||
|
||||
@@ -51,7 +51,8 @@ function triggerAppEvent(code, event, args)
|
||||
event = event + '.apps';
|
||||
if(!Array.isArray(args)) args = [args];
|
||||
if(app.$app) app.$app.trigger(event, args);
|
||||
if(app.iframe && app.iframe.contentWindow.$) return app.iframe.contentWindow.$(app.iframe.contentWindow.document).trigger(event, args);
|
||||
const iframeWindow = app.iframe && app.iframe.contentWindow;
|
||||
if(iframeWindow) return iframeWindow.$(iframeWindow.document).trigger(event, args);
|
||||
}
|
||||
|
||||
function isOldPage(url)
|
||||
@@ -690,6 +691,18 @@ function changeAppsLang(lang)
|
||||
updateAppsMenu();
|
||||
}
|
||||
|
||||
function changeAppsTheme(theme)
|
||||
{
|
||||
changeAppTheme(theme);
|
||||
$.each(apps.openedMap, function(_code, app)
|
||||
{
|
||||
if(app.iframe && app.iframe.contentWindow && app.iframe.contentWindow.changeAppTheme)
|
||||
{
|
||||
app.iframe.contentWindow.changeAppTheme(theme);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initAppsMenu();
|
||||
/* Refresh more menu on window resize */
|
||||
$(window).on('resize', refreshMenu);
|
||||
@@ -758,5 +771,6 @@ $.apps = $.extend(apps,
|
||||
isOldPage: isOldPage,
|
||||
getAppCode: getAppCode,
|
||||
updateAppsMenu: updateAppsMenu,
|
||||
changeAppsLang: changeAppsLang
|
||||
changeAppsLang: changeAppsLang,
|
||||
changeAppsTheme: changeAppsTheme
|
||||
});
|
||||
|
||||
+30
-2
@@ -58,7 +58,8 @@
|
||||
reloadApp: function(_code, url){loadPage(url);},
|
||||
openApp: function(url, options){loadPage(url, options);},
|
||||
goBack: function(){history.go(-1);},
|
||||
changeAppsLang: changeAppLang
|
||||
changeAppsLang: changeAppLang,
|
||||
changeAppsTheme: changeAppTheme
|
||||
}, parent.window.$.apps);
|
||||
|
||||
const renderMap =
|
||||
@@ -895,6 +896,22 @@
|
||||
$('html').attr('lang', lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change current app theme.
|
||||
* @param {string} lang
|
||||
*/
|
||||
function changeAppTheme(theme)
|
||||
{
|
||||
const classList = $('html').attr('class').split(' ').filter(x => x.length && !x.startsWith('theme-'));
|
||||
classList.push('theme-' + theme);
|
||||
$('html').attr('class', classList.join(' '));
|
||||
const $theme = $('#zuiTheme');
|
||||
const oldPath = $theme.attr('href').split('/');
|
||||
oldPath.pop();
|
||||
oldPath.push(theme + '.css');
|
||||
$theme.attr('href', oldPath.join('/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Select UI language.
|
||||
* @param {string} lang
|
||||
@@ -906,7 +923,18 @@
|
||||
$.apps.changeAppsLang(lang);
|
||||
}
|
||||
|
||||
$.extend(window, {registerRender: registerRender, fetchContent: fetchContent, loadTable: loadTable, loadPage: loadPage, postAndLoadPage: postAndLoadPage, loadCurrentPage: loadCurrentPage, parseSelector: parseSelector, toggleLoading: toggleLoading, openUrl: openUrl, goBack: goBack, registerTimer: registerTimer, loadModal: loadModal, loadTarget: loadTarget, loadComponent: loadComponent, loadPartial: loadPartial, reloadPage: reloadPage, selectLang: selectLang, changeAppLang});
|
||||
/**
|
||||
* Select UI theme.
|
||||
* @param {string} lang
|
||||
*/
|
||||
function selectTheme(theme)
|
||||
{
|
||||
$.cookie.set('theme', theme, {expires: config.cookieLife, path: config.webRoot});
|
||||
$.ajaxSendScore('selectTheme');
|
||||
$.apps.changeAppsTheme(theme);
|
||||
}
|
||||
|
||||
$.extend(window, {registerRender: registerRender, fetchContent: fetchContent, loadTable: loadTable, loadPage: loadPage, postAndLoadPage: postAndLoadPage, loadCurrentPage: loadCurrentPage, parseSelector: parseSelector, toggleLoading: toggleLoading, openUrl: openUrl, goBack: goBack, registerTimer: registerTimer, loadModal: loadModal, loadTarget: loadTarget, loadComponent: loadComponent, loadPartial: loadPartial, reloadPage: reloadPage, selectLang: selectLang, selectTheme: selectTheme, changeAppLang, changeAppTheme: changeAppTheme});
|
||||
$.extend($.apps, {openUrl: openUrl});
|
||||
$.extend($, {ajaxSendScore: ajaxSendScore, selectLang: selectLang});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user