⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssfx.core.debug.js

📁 经典编程900例(C语言),主要是C基础知识
💻 JS
📖 第 1 页 / 共 5 页
字号:
// Script# Framework
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
// http://projects.nikhilk.net
//


Type.createNamespace('ScriptFX');

////////////////////////////////////////////////////////////////////////////////
// ScriptFX.CollectionChangedAction

ScriptFX.CollectionChangedAction = function() { };
ScriptFX.CollectionChangedAction.prototype = {
    add: 0, 
    remove: 1, 
    reset: 2
}
ScriptFX.CollectionChangedAction.createEnum('ScriptFX.CollectionChangedAction', false);


////////////////////////////////////////////////////////////////////////////////
// ScriptFX._registeredEvent

ScriptFX.$create__registeredEvent = function ScriptFX__registeredEvent(eventType, sender, eventArgs, eventCookie) {
    var $o = { };
    $o.eventType = eventType;
    $o.sender = sender;
    $o.eventArgs = eventArgs;
    $o.eventCookie = eventCookie;
    return $o;
}


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.IEventManager

ScriptFX.IEventManager = function() { };
ScriptFX.IEventManager.prototype = {
    raiseEvent : null,
    registerEvent : null,
    registerEventHandler : null,
    unregisterEvent : null,
    unregisterEventHandler : null
}
ScriptFX.IEventManager.createInterface('ScriptFX.IEventManager');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.ISupportInitialize

ScriptFX.ISupportInitialize = function() { };
ScriptFX.ISupportInitialize.prototype = {
    beginInitialize : null,
    endInitialize : null
}
ScriptFX.ISupportInitialize.createInterface('ScriptFX.ISupportInitialize');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.INotifyDisposing

ScriptFX.INotifyDisposing = function() { };
ScriptFX.INotifyDisposing.prototype = {
    add_disposing : null,
    remove_disposing : null
}
ScriptFX.INotifyDisposing.createInterface('ScriptFX.INotifyDisposing');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.HostName

ScriptFX.HostName = function() { };
ScriptFX.HostName.prototype = {
    other: 0, 
    IE: 1, 
    mozilla: 2, 
    safari: 3, 
    opera: 4
}
ScriptFX.HostName.createEnum('ScriptFX.HostName', false);


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.INotifyCollectionChanged

ScriptFX.INotifyCollectionChanged = function() { };
ScriptFX.INotifyCollectionChanged.prototype = {
    add_collectionChanged : null,
    remove_collectionChanged : null
}
ScriptFX.INotifyCollectionChanged.createInterface('ScriptFX.INotifyCollectionChanged');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.INotifyPropertyChanged

ScriptFX.INotifyPropertyChanged = function() { };
ScriptFX.INotifyPropertyChanged.prototype = {
    add_propertyChanged : null,
    remove_propertyChanged : null
}
ScriptFX.INotifyPropertyChanged.createInterface('ScriptFX.INotifyPropertyChanged');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.ITask

ScriptFX.ITask = function() { };
ScriptFX.ITask.prototype = {
    execute : null
}
ScriptFX.ITask.createInterface('ScriptFX.ITask');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.IObjectWithOwner

ScriptFX.IObjectWithOwner = function() { };
ScriptFX.IObjectWithOwner.prototype = {
    get_owner : null,
    setOwner : null
}
ScriptFX.IObjectWithOwner.createInterface('ScriptFX.IObjectWithOwner');


////////////////////////////////////////////////////////////////////////////////
// ScriptFX.Application

ScriptFX.Application = function ScriptFX_Application() {
    this._disposableObjects = [];
    this._idleFrequency = 100;
    ScriptHost.add_load(Delegate.create(this, this._onScriptHostLoad));
    ScriptHost.add_unload(Delegate.create(this, this._onScriptHostUnload));
    this._windowUnloadingHandler = Delegate.create(this, this._onWindowUnloading);
    window.attachEvent('onbeforeunload', this._windowUnloadingHandler);
    this._windowErrorHandler = Delegate.create(this, this._onWindowError);
    window.attachEvent('onerror', this._windowErrorHandler);
    var rootElement = document.documentElement;
    var className = rootElement.className;
    if (className.startsWith('$')) {
        var hostInfo = this.get_host();
        className = className.replace('$browser', Enum.toString(ScriptFX.HostName, hostInfo.get_name()));
        className = className.replace('$majorver', hostInfo.get_majorVersion().toString());
        className = className.replace('$minorver', hostInfo.get_minorVersion().toString());
        rootElement.className = className;
    }
}
ScriptFX.Application.prototype = {
    _host: null,
    _isIE: 0,
    _scriptlets: null,
    _loaded: false,
    _disposing: false,
    _firstLoad: false,
    _sessionState: null,
    _history: null,
    _events: null,
    _disposableObjects: null,
    _idleFrequency: 0,
    _idleTimer: 0,
    _taskQueue: null,
    _taskTimer: 0,
    _registeredEventHandlers: null,
    _registeredEventTypes: null,
    _registeredEvents: null,
    _services: null,
    _windowUnloadingHandler: null,
    _windowErrorHandler: null,
    _idleTimerTickHandler: null,
    _taskTimerTickHandler: null,
    
    get_domain: function ScriptFX_Application$get_domain() {
        return window.document.domain;
    },
    set_domain: function ScriptFX_Application$set_domain(value) {
        window.document.domain = value;
        return value;
    },
    
    get__events: function ScriptFX_Application$get__events() {
        if (!this._events) {
            this._events = new ScriptFX.EventList();
        }
        return this._events;
    },
    
    get_history: function ScriptFX_Application$get_history() {
        Debug.assert(this._history, 'History has not been enabled.');
        return this._history;
    },
    
    get_host: function ScriptFX_Application$get_host() {
        if (!this._host) {
            this._host = new ScriptFX.HostInfo();
        }
        return this._host;
    },
    
    get_idleFrequency: function ScriptFX_Application$get_idleFrequency() {
        return this._idleFrequency;
    },
    set_idleFrequency: function ScriptFX_Application$set_idleFrequency(value) {
        Debug.assert(value >= 100, 'IdleFrequency must be atleast 100ms');
        this._idleFrequency = value;
        return value;
    },
    
    get_isFirstLoad: function ScriptFX_Application$get_isFirstLoad() {
        return this._firstLoad;
    },
    
    get_isIE: function ScriptFX_Application$get_isIE() {
        if (!this._isIE) {
            this._isIE = (this.get_host().get_name() === ScriptFX.HostName.IE) ? 1 : -1;
        }
        return (this._isIE === 1) ? true : false;
    },
    
    get_sessionState: function ScriptFX_Application$get_sessionState() {
        Debug.assert(this._loaded, 'You must wait until the load event before accessing session.');
        Debug.assert(this._sessionState, 'In order to use session, you must add an <input type=\"hidden\" id=\"__session\" /> within a <form>.');
        return this._sessionState;
    },
    
    add_error: function ScriptFX_Application$add_error(value) {
        this.get__events().addHandler('error', value);
    },
    remove_error: function ScriptFX_Application$remove_error(value) {
        this.get__events().removeHandler('error', value);
    },
    
    add_idle: function ScriptFX_Application$add_idle(value) {
        this.get__events().addHandler('idle', value);
        if (!this._idleTimer) {
            if (!this._idleTimerTickHandler) {
                this._idleTimerTickHandler = Delegate.create(this, this._onIdleTimerTick);
            }
            this._idleTimer = window.setTimeout(this._idleTimerTickHandler, this._idleFrequency);
        }
    },
    remove_idle: function ScriptFX_Application$remove_idle(value) {
        var isActive = this.get__events().removeHandler('idle', value);
        if ((!isActive) && (this._idleTimer)) {
            window.clearTimeout(this._idleTimer);
            this._idleTimer = 0;
        }
    },
    
    add_load: function ScriptFX_Application$add_load(value) {
        if (this._loaded) {
            value.invoke(this, EventArgs.Empty);
        }
        else {
            this.get__events().addHandler('load', value);
        }
    },
    remove_load: function ScriptFX_Application$remove_load(value) {
        this.get__events().removeHandler('load', value);
    },
    
    add_unload: function ScriptFX_Application$add_unload(value) {
        this.get__events().addHandler('unload', value);
    },
    remove_unload: function ScriptFX_Application$remove_unload(value) {
        this.get__events().removeHandler('unload', value);
    },
    
    add_unloading: function ScriptFX_Application$add_unloading(value) {
        this.get__events().addHandler('unloading', value);
    },
    remove_unloading: function ScriptFX_Application$remove_unloading(value) {
        this.get__events().removeHandler('unloading', value);
    },
    
    addTask: function ScriptFX_Application$addTask(task) {
        if (!this._taskQueue) {
            this._taskQueue = [];
        }
        this._taskQueue.enqueue(task);
        if (!this._taskTimer) {
            if (!this._taskTimerTickHandler) {
                this._taskTimerTickHandler = Delegate.create(this, this._onTaskTimerTick);
            }
            this._taskTimer = window.setTimeout(this._taskTimerTickHandler, 0);
        }
    },
    
    enableHistory: function ScriptFX_Application$enableHistory() {
        if (this._history) {
            return;
        }
        this._history = ScriptFX.HistoryManager._createHistory();
    },
    
    getService: function ScriptFX_Application$getService(serviceType) {
        Debug.assert(serviceType);
        if ((serviceType === IServiceContainer) || (serviceType === ScriptFX.IEventManager)) {
            return this;
        }
        if (this._services) {
            var name = serviceType.get_fullName().replace('.', '$');
            return this._services[name];
        }
        return null;
    },
    
    _onIdleTimerTick: function ScriptFX_Application$_onIdleTimerTick() {
        this._idleTimer = 0;
        var handler = this.get__events().getHandler('idle');
        if (handler) {
            handler.invoke(this, EventArgs.Empty);
            this._idleTimer = window.setTimeout(this._idleTimerTickHandler, this._idleFrequency);
        }
    },
    
    _onScriptHostLoad: function ScriptFX_Application$_onScriptHostLoad(sender, e) {
        var sessionElement = $('__session');
        if (sessionElement) {
            var value = sessionElement.value;
            if (String.isNullOrEmpty(value)) {
                this._firstLoad = true;
                this._sessionState = {};
            }
            else {
                this._sessionState = ScriptFX.JSON.deserialize(value);
                if (isUndefined(this._sessionState['__appLoaded'])) {
                    this._firstLoad = true;
                }
            }
            this._sessionState['__appLoaded'] = true;
        }
        else {
            this._firstLoad = true;
        }
        if (this._scriptlets) {
            for (var i = 0; i < this._scriptlets.length; i += 2) {
                this._scriptlets[i].main(this._scriptlets[i + 1]);
            }
            this._scriptlets = null;
        }
        this._loaded = true;
        var handler = this.get__events().getHandler('load');
        if (handler) {
            handler.invoke(this, EventArgs.Empty);
        }
        if (this._history) {
            this._history._initialize();
        }
    },
    
    _onScriptHostUnload: function ScriptFX_Application$_onScriptHostUnload(sender, e) {
        if (!this._disposing) {
            this._disposing = true;
            if (this._taskTimer) {
                window.clearTimeout(this._taskTimer);
            }
            if (this._idleTimer) {
                window.clearTimeout(this._idleTimer);
            }
            var handler = this.get__events().getHandler('unload');
            if (handler) {
                handler.invoke(this, EventArgs.Empty);
            }
            if (this._taskQueue) {
                while (this._taskQueue.length) {
                    var task = this._taskQueue.dequeue();
                    if (Type.canCast(task, IDisposable)) {
                        (task).dispose();
                    }
                }
            }
            if (this._disposableObjects.length) {
                var $enum1 = this._disposableObjects.getEnumerator();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -