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

📄 atlasruntime.js

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 JS
📖 第 1 页 / 共 5 页
字号:
    var _currentLoadingReference;
    var _components;
    
    var _markupContext;
    var _disposableObjects;
    var _unloading;
    
        var _type;

    window.attachEvent('onload', onWindowLoad);
    window.attachEvent('onunload', onWindowUnload);
    
    this.get_type = function() {
        if (!_type) {
            _type = Web.ApplicationType.Other;
            
            if (navigator.userAgent.indexOf('MSIE') != -1) {
                _type = Web.ApplicationType.InternetExplorer;
            }
            else if (navigator.userAgent.indexOf('Firefox') != -1) {
                _type = Web.ApplicationType.Firefox;
            }
        }
        return _type;
    }
    
    this.get_userAgent = function() {
        return navigator.userAgent;
    }

        
    this.load = new Web.Event(this);
    this.unload = new Web.Event(this);
    
    this.dispose = function() {
    }
    
    this.findObject = function(id) {
        if (_markupContext) {
            return _markupContext.findObject(id, false);
        }
        return null;
    }
    

    this.getProperty = function(name, key) {
    }
    
    this.getService = function(serviceType) {
                return null;
    }

    this._initialize = function() {
        _references = [];
        _components = [];
        
        var atlasScripts = [];
        
        var scriptElements = document.getElementsByTagName('script');
        for (var e = 0; e < scriptElements.length; e++) {
            if (scriptElements[e].type == 'text/xml-script') {
                atlasScripts.add(scriptElements[e]);
            }
        }

        if (!atlasScripts.length) {
            onLoad();
            return;
        }
        
        for (var s = 0; s < atlasScripts.length; s++) {
            var atlasScript = atlasScripts[s];

            var scriptMarkup = atlasScript.text ? atlasScript.text : atlasScript.innerHTML;
            if (scriptMarkup.startsWith('<!--')) {
                var startIndex = scriptMarkup.indexOf('<', 1);
                var endIndex = scriptMarkup.lastIndexOf('>');
                endIndex = scriptMarkup.lastIndexOf('>', endIndex - 1);
                
                scriptMarkup = scriptMarkup.substring(startIndex, endIndex + 1);
            }

            var scriptDOM = new XMLDOM(scriptMarkup);
            var scriptDocumentNode = scriptDOM.childNodes[0];
            var scriptDocumentItemNodes = scriptDocumentNode.childNodes;
            
            for (var i = scriptDocumentItemNodes.length - 1; i >= 0; i--) {
                var node = scriptDocumentItemNodes[i];
                if (node.nodeType != 1) {
                    continue;
                }
                
                if (node.baseName == 'components') {
                    for (var c = 0; c < node.childNodes.length; c++) {
                        var componentNode = node.childNodes[c];
                        if (componentNode.nodeType != 1) {
                            continue;
                        }
                        
                        _components.add(componentNode);
                    }
                }
                else if (node.baseName == 'references') {
                    for (var r = 0; r < node.childNodes.length; r++) {
                        var referenceNode = node.childNodes[r];
                        if (referenceNode.nodeType != 1) {
                            continue;
                        }
                        
                        if (referenceNode.baseName == 'add') {
                            var srcAttribute = referenceNode.attributes.getNamedItem('src');
                            if (srcAttribute) {
                                _references.queue(srcAttribute.nodeValue);
                            }
                        }
                    }
                }
            }
        }
        
        if (_references && _references.length) {
            loadReferences();
        }
        else {
            loadObjects();
        }
    }
    
    this.invokeMethod = function(methodName, parameters) {
        var method = Function.parse(methodName);
        if (typeof(method) == 'function') {
            method();
        }
    }
    
    this.registerDisposableObject = function(object) {
        if (!_disposableObjects) {
            _disposableObjects = [];
        }
        
        _disposableObjects.add(object);
    }
    
    this.unregisterDisposableObject = function(object) {
        if (!_unloading && _disposableObjects) {
            _disposableObjects.remove(object);
        }
    }
    
    this.requiresReference = function(scriptPath) {
                    }
    
    this.setProperty = function(name, value, key) {
    }
    
    function loadObjects() {

        onLoad();
    }

    function loadReferences() {
        if (_currentLoadingReference) {
            if ((_currentLoadingReference.readyState != 'loaded') &&
                (_currentLoadingReference.readyState != 'complete')) {
                return;
            }
            else {
                if (Web.Application.get_type() != Web.ApplicationType.InternetExplorer) {
                    _currentLoadingReference.onload = null;
                }
                else {
                    _currentLoadingReference.onreadystatechange = null;
                }
                _currentLoadingReference = null;
            }
        }

        if (_references && _references.length) {
            var reference = _references.dequeue();
            var scriptElement = document.createElement('script');
            _currentLoadingReference = scriptElement;
            
            if (Web.Application.get_type() != Web.ApplicationType.InternetExplorer) {
                scriptElement.readyState = 'loaded';
                scriptElement.onload = loadReferences;
            }
            else {
                scriptElement.onreadystatechange = loadReferences;
            }
            scriptElement.type = 'text/javascript';
            scriptElement.src = reference;

            var headElement = document.getElementsByTagName('head')[0];
            headElement.appendChild(scriptElement);

            return;
        }

        loadObjects();
    }
    
    function onLoad() {
        Web.Application.load.invoke(Web.Application, Web.EventArgs.Empty);
        var pageLoadHandler = Function.parse('pageLoad');
        if (typeof(pageLoadHandler) == 'function') {
            pageLoadHandler();
        }
    }

    function onWindowLoad() {
        window.detachEvent('onload', onWindowLoad);
        Web.Application._initialize();
    }

    function onWindowUnload() {
        window.detachEvent('onunload', onWindowUnload);

        Web.Application.unload.invoke(Web.Application, Web.EventArgs.Empty);
        var pageUnloadHandler = Function.parse('pageUnload');
        if (typeof(pageUnloadHandler) == 'function') {
            pageUnloadHandler();
        }
        
        if (_disposableObjects) {
            _unloading = true;
            var count = _disposableObjects.length;
            for (var i = 0; i < count; i++) {
                _disposableObjects[i].dispose();
            }
            _disposableObjects.clear();
            _disposableObjects = null;
        }
        
    }

}

Type.registerSealedClass('Web._Application', null, Web.IDisposable);

Web.Application = new Web._Application();

Web.Component = function(registerAsDisposable) {
    var _id = null;
    var _initialized = false;
    var _updating = false;
    
    
    var _events = [];

    if (registerAsDisposable) {
        Web.Application.registerDisposableObject(this);
    }


    this.get_id = function() {
        return _id;
    }
    this.set_id = function(value) {
        _id = value;
    }
    
    this.get_isInitialized = function() {
        return _initialized;
    }
    
    this.get_isUpdating = function() {
        return _updating;
    }

    this.createEvent = function(autoInvoke) {
        var eventObject = new Web.Event(this, autoInvoke);
        _events.add(eventObject);
        
        return eventObject;
    }
    
    
    this.beginUpdate = function() {
        _updating = true;
    }
    
    this.dispose = function() {
        
        if (_events) {
            for (var e = _events.length - 1; e >= 0; e--) {
                _events[e].dispose();
                _events[e] = null;
            }
            _events = null;
        }
        
        Web.Application.unregisterDisposableObject(this);
            }
    Web.Component.registerBaseMethod(this, 'dispose');
    
    this.endUpdate = function() {
        _updating = false;
        if (!_initialized) {
            this.initialize();
        }
        this.updated();
    }

    
    this.initialize = function() {
        
        _initialized = true;
    }
    Web.Component.registerBaseMethod(this, 'initialize');


    this.updated = function() {
    }
    Web.Component.registerBaseMethod(this, 'updated');
}
Type.registerAbstractClass('Web.Component', null, Web.IDisposable);


Web.Component.createCollection = function(component) {
    var collection = [];
    collection._component = component;

    collection.collectionChanged = new Web.Event(null);
    
    collection._add = collection.add;
    collection.add = function(item) {
        this._add(item);
        item.setOwner(this._component);
    }
    
    collection._clear = collection.clear;
    collection.clear = function() {
        for (var i = this.length - 1; i >= 0; i--) {
            this[i].dispose();
            this[i] = null;
        }
        this._clear();
    }

    collection.dispose = function() {
        this.clear();
        this._component = null;
    }
    
    collection._remove = collection.remove;
    collection.remove = function(item) {
        item.dispose();
        this._remove(item);
    }
    
    collection._removeAt = collection.removeAt;
    collection.removeAt = function(index) {
        var item = this[index];
        item.dispose();
        this._removeAt(index);
    }
    
    return collection;
}

Type.registerNamespace('Web.Serialization');


Web.Serialization.JSON = new function() {

    function serializeWithBuilder(object, stringBuilder) {
        var i;
        
        switch (typeof object) {
        case 'object':
            if (object) {
                                if (Array.isInstanceOfType(object)) {
                    stringBuilder.append('[');
                    for (i = 0; i < object.length; ++i) {
                        if (i > 0) {
                            stringBuilder.append(',');
                        }
                        stringBuilder.append(serializeWithBuilder(object[i], stringBuilder));
                    }
                    stringBuilder.append(']');
                } 
                                else {
                                        if (typeof object.serialize == 'function') {
                        stringBuilder.append(object.serialize());
                        break;
                    }
                
                    stringBuilder.append('{');
                    var needComma = false;
                    for (var name in object) {

                                                if (name.startsWith('$')) {
                            continue;
                        }

                        var value = object[name];
                        if (typeof value != 'undefined' && typeof value != 'function') {
                            if (needComma) {
                                stringBuilder.append(',');
                            }
                            else {
                                needComma = true;
                            }
             
                                                        stringBuilder.append(serializeWithBuilder(name, stringBuilder));
                            stringBuilder.append(':');
                            stringBuilder.append(serializeWithBuilder(value, stringBuilder));
                        }
                    }
                    stringBuilder.append('}');
                }
            }
            else {
                stringBuilder.append('null');
            }
            break;
            
        case 'number':
            if (isFinite(object)) {
                stringBuilder.append(String(object));
            }
                        else {
                stringBuilder.append('null');
            }
            break;
            
        case 'string':
            stringBuilder.append('"');
            var length = object.length;
            for (i = 0; i < length; ++i) {
                var curChar = object.charAt(i);
                                                if (curChar >= ' ') {
                                        if (curChar == '\\' || curChar == '"') {
                        stringBuilder.append('\\');
                    }
                    stringBuilder.append(curChar);
                }
                else {
                                        switch (curChar) {

⌨️ 快捷键说明

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