* [misc] enhance app event handling and add getPageInfo method.
This commit is contained in:
@@ -59,13 +59,13 @@ function showLog(code, name, moreTitles, trace, moreInfos)
|
||||
}
|
||||
}
|
||||
|
||||
function triggerAppEvent(code, event, args)
|
||||
function triggerAppEvent(code, event, args, options)
|
||||
{
|
||||
const app = apps.openedMap[code];
|
||||
if(!app) return;
|
||||
|
||||
if(DEBUG) showLog(code, 'Event', event, {args});
|
||||
event = event + '.apps';
|
||||
event = event.includes('.') ? event : `${event}.apps`;
|
||||
if(DEBUG && (!options || options.silent !== true)) showLog(code, 'Event', event, {args});
|
||||
if(!Array.isArray(args)) args = [args];
|
||||
if(app.$app) app.$app.trigger(event, args);
|
||||
try
|
||||
@@ -214,6 +214,10 @@ function openApp(url, code, options)
|
||||
}
|
||||
openedApp.zIndex = ++apps.zIndex;
|
||||
openedApp.$app.show().css('z-index', openedApp.zIndex);
|
||||
openedApp.getPageInfo = () => {
|
||||
const getPageInfo = openedApp.iframe.contentWindow.getPageInfo;
|
||||
return getPageInfo ? getPageInfo() : null;
|
||||
};
|
||||
|
||||
/* Update on app tabs bar */
|
||||
const $tabs = $('#appTabs');
|
||||
@@ -1176,7 +1180,8 @@ $.apps = $.extend(apps,
|
||||
changeAppsTheme: changeAppsTheme,
|
||||
updateUserToolbar: updateUserToolbar,
|
||||
closeApp: closeApp,
|
||||
toggleMenu: toggleMenu
|
||||
toggleMenu: toggleMenu,
|
||||
triggerAppEvent: triggerAppEvent,
|
||||
});
|
||||
|
||||
window.notifyMessage = function(data)
|
||||
|
||||
+20
-4
@@ -44,6 +44,19 @@
|
||||
const localCacheFirst = config.clientCache === 'local-first';
|
||||
const isTutorial = top.config.currentModule === 'tutorial';
|
||||
|
||||
function getPageInfo()
|
||||
{
|
||||
return {
|
||||
app: currentCode,
|
||||
id: `${currentCode}.${config.currentModule}-${config.currentMethod}`,
|
||||
path: `${config.currentModule}-${config.currentMethod}`,
|
||||
url: currentAppUrl,
|
||||
config: config,
|
||||
currentModule: config.currentModule,
|
||||
currentMethod: config.currentMethod,
|
||||
};
|
||||
}
|
||||
|
||||
function getUrlID(url)
|
||||
{
|
||||
const info = $.parseLink(url || currentAppUrl);
|
||||
@@ -127,6 +140,7 @@
|
||||
changeAppsLang: changeAppLang,
|
||||
changeAppsTheme: changeAppTheme,
|
||||
updateUserToolbar: function(){loadPage({selector: '#toolbar', partial: true, target: '#toolbar'})},
|
||||
triggerEvent: function(event, args, options){$.apps.triggerAppEvent(currentCode, event, [getPageInfo(), args], options);}
|
||||
}, parent.window.$.apps);
|
||||
|
||||
const renderMap =
|
||||
@@ -394,6 +408,7 @@
|
||||
function afterUpdate($target, info, options)
|
||||
{
|
||||
if(window.afterPageUpdate) window.afterPageUpdate($target, info, options);
|
||||
$.apps.triggerEvent('updatepart.app', {target: $target, info, options}, {silent: true});
|
||||
}
|
||||
|
||||
function renderWithHtml($target, html, selector, noMorph)
|
||||
@@ -482,18 +497,19 @@
|
||||
function renderPage(list, options)
|
||||
{
|
||||
if(DEBUG) showLog('Render', [options.id, list.length, options.noMorph ? 'html' : 'morph'], list, {options});
|
||||
let hasUpdatePage = false;
|
||||
let updateFullPage = false;
|
||||
list.forEach(item =>
|
||||
{
|
||||
renderPartial(item, options);
|
||||
if(item.name === 'html' || item.name === 'body') hasUpdatePage = true;
|
||||
if(item.name === 'html' || item.name === 'body') updateFullPage = true;
|
||||
});
|
||||
if(hasUpdatePage)
|
||||
if(updateFullPage)
|
||||
{
|
||||
updatePageLayout();
|
||||
$('html').enableScroll();
|
||||
}
|
||||
if(window.afterPageRender) window.afterPageRender(list, options);
|
||||
$.apps.triggerEvent('updatepage.app', {updateFullPage: updateFullPage, options});
|
||||
if(!options.partial)
|
||||
{
|
||||
const newState = $.apps.updateApp(currentCode, currentAppUrl, document.title);
|
||||
@@ -1785,7 +1801,7 @@
|
||||
if($firstControl) $firstControl[0]?.focus();
|
||||
}
|
||||
|
||||
$.extend(window, {registerRender: registerRender, fetchContent: fetchContent, loadTable: loadTable, loadPage: loadPage, postAndLoadPage: postAndLoadPage, loadCurrentPage: loadCurrentPage, parseSelector: parseSelector, toggleLoading: toggleLoading, openUrl: openUrl, openPage: openPage, goBack: goBack, registerTimer: registerTimer, loadModal: loadModal, loadTarget: loadTarget, loadComponent: loadComponent, loadPartial: loadPartial, reloadPage: reloadPage, selectLang: selectLang, selectTheme: selectTheme, selectVision: selectVision, changeAppLang, changeAppTheme: changeAppTheme, waitDom: waitDom, fetchMessage: fetchMessage, setImageSize: setImageSize, showMoreImage: showMoreImage, autoLoad: autoLoad, loadForm: loadForm, showValidateMessage: showValidateMessage});
|
||||
$.extend(window, {registerRender: registerRender, fetchContent: fetchContent, loadTable: loadTable, loadPage: loadPage, postAndLoadPage: postAndLoadPage, loadCurrentPage: loadCurrentPage, parseSelector: parseSelector, toggleLoading: toggleLoading, openUrl: openUrl, openPage: openPage, goBack: goBack, registerTimer: registerTimer, loadModal: loadModal, loadTarget: loadTarget, loadComponent: loadComponent, loadPartial: loadPartial, reloadPage: reloadPage, selectLang: selectLang, selectTheme: selectTheme, selectVision: selectVision, changeAppLang, changeAppTheme: changeAppTheme, waitDom: waitDom, fetchMessage: fetchMessage, setImageSize: setImageSize, showMoreImage: showMoreImage, autoLoad: autoLoad, loadForm: loadForm, showValidateMessage: showValidateMessage, getPageInfo: getPageInfo});
|
||||
$.extend($.apps, {openUrl: openUrl, getAppUrl: () => currentAppUrl});
|
||||
$.extend($, {ajaxSendScore: ajaxSendScore, selectLang: selectLang});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user