📄 start.js
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var FrameworkConfiguration = null; //global framework config
var ApplicationConfiguration = null; //global application config
var Framework = {
connectedWithServer: function(success, win) {
if(success){
//unlock application
Application.context.put("UIlocked", false);
Application.sm.lookup("framework.authenticationmanager").restart(); //will do a synchronized ajax request
window.setTimeout(function(){win.close();},500);
}
}
};
var FrameworkStarted = false;
var Application = {};
var workbench = {}; //here for backward compatibility
/**
* Application bootstrapper
*/
function startupApplication() {
var myConf = FrameworkConfiguration.framework;
if(myConf.showLogger &&
myConf.logEnabled){
//top.mainframeset.rows = '100,*,0,0,1';
//TODO: create bottomframe here with dom
top.frames[myConf.logFrame].toggleDebug(); //open the debug frame
if(myConf.undockLogger)
top.frames[myConf.logFrame].toggleUndock(); //and undock it
Framework.log = new DefaultLogger(myConf.id, top.frames[myConf.logFrame], myConf.logger, myConf.logLevel);
}
else { //if logging isn't enabled use lightweight EmptyLogger
Framework.log = new EmptyLogger(myConf.id)
}
try {
if(!FrameworkStarted) { //prevent it from accidentally reinitializing
var start = new Date(); //stopwatch.start
//Check if the user browser engine is compatible by comparing with compatible browsers
//TODO: replace with object detection (http://www.quirksmode.org/js/support.html)
var browserEngine = jsrsBrowserSniff();
var compatibleBrowser = false;
for(x=0;x<myConf.supportedBrowsers.length;x++) {
if(browserEngine == myConf.supportedBrowsers[x]) {
compatibleBrowser=true;
break;
}
}
if(!compatibleBrowser) {
infoScreen(true);
throw new FrameworkException("Browser " + browserEngine + " not supported");
}
splashScreen(true);
if(Framework.log.debugging()) {
Framework.log.debug("starting engine");
Framework.log.debug("browser engine: " + jsrsBrowserSniff());
}
// setup root context
rootContext = new DefaultContext();
rootContext.put("top", top.frames[myConf.topFrame]);
rootContext.put("main", top.frames[myConf.mainFrame]);
rootContext.put("bottom", top.frames[myConf.logFrame]);
rootContext.put("browser", browserEngine);
rootContext.put("UIlocked", false);
var loadingLabel = " loading..";
if(!Cfx.Js.IsEmpty(myConf.loadingLabel)) {
loadingLabel = myConf.loadingLabel;
}
rootContext.put("loadingLabel", loadingLabel);
if(CMS_PREVIEW_URL && CMS_PREVIEW_URL != '')
rootContext.put("previewUrl", CMS_PREVIEW_URL); //temporary workaround for 6.0.3.1 ONLY!
var serviceManager = new DefaultServiceManager(null, Framework.log.getChildLogger("serviceManager"));
var componentFactory = new DefaultComponentFactory(Framework.log.getChildLogger("componentFactory"));
serviceManager.put(myConf.id + ".componentFactory", componentFactory);
for(var i=0;i<myConf.list.length;i++){
//add framework services
//will be exposed to all components
var comp = componentFactory.createComponent(myConf.list[i], Framework.log, rootContext, serviceManager);
comp.init();
serviceManager.put(myConf.id + "." + myConf.list[i].id, comp);
}
Application = componentFactory.createComponent(ApplicationConfiguration.application, null, rootContext, serviceManager);
Application.init();
FrameworkStarted = true;
Framework.log.info("loaded in " + (new Date().getTime() - start.getTime()) + " ms");
splashScreenWhenInitialized();
}
} catch (e) {
if (Framework.log) {
Framework.log.error(e, "startupApplication(): ");
}
throw e;
}
}
/**
* Call's itself with a timeout untill the workbench has initialized
* It then hides the splash again
*/
var MAX_WAIT_INITIALIZATION = 30;
function splashScreenWhenInitialized(times){
var timeoutLength = 300;
if(Cfx.Js.IsEmpty(times)){ times = 1; }
if (Application.initialized()){
splashScreen(false);
executeScheduledTasks();
}
else if(times*timeoutLength < MAX_WAIT_INITIALIZATION*1000){
if(Framework.log.debugging()) {
Framework.log.debug("Waiting for end of initialization.. times=" + times);
}
window.setTimeout("splashScreenWhenInitialized(" + ++times + ");",timeoutLength);
}else{
Framework.log.error("Application initialization took more than " + MAX_WAIT_INITIALIZATION + " seconds and therefore failed.");
Application.sm.lookup("framework.authenticationmanager").stopAll();
window.top.location.href = '/login/logout';
}
}
/*
* Fires events which were determined after login
*
*/
function executeScheduledTasks(){
var i;
for (i=0; i<scheduledTasks.length; i++){
if (typeof scheduledTasks[i].wait != 'undefined')
window.setTimeout("executeScheduledTask("+i+")",scheduledTasks[i].wait);
else
executeScheduledTask(i);
}
}
function executeScheduledTask(i) {
var em = Application.sm.lookup('framework.eventmanager');
em.fireEvent(scheduledTasks[i].event, scheduledTasks[i].arguments);
}
/**
* Shows or hides the splash screen
*
* @param bShow flag that controls the visibility
*/
function splashScreen(bShow){
var myConf = FrameworkConfiguration.framework;
var splash = top.frames[myConf.mainFrame].document.getElementById('splashscreen');
if(bShow){
splash.style.visibility = 'visible';
}else{
//before hiding the splash screen, load the first perspective
//(maybe create a seperate class with pre-hide commands)
Application.sm.lookup("cms.workbench").loadInitialTab();
splash.style.display = 'none';
}
}
/**
* Shows or hides the info screen
*
* @param bShow flag that controls the visibility
*/
function infoScreen(bShow){
var myConf = FrameworkConfiguration.framework;
var domEl = top.frames[myConf.mainFrame].document.getElementById('infoscreen');
domEl.style.display = (bShow) ? '' : 'none';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -