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

📄 atlas.js

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 JS
📖 第 1 页 / 共 5 页
字号:
    var properties = td._getProperties();
    var events = td._getEvents();
    
    var attributes = node.attributes;
    if (attributes) {
        for (a = attributes.length - 1; a >= 0; a--) {
            attr = attributes[a];
            attrName = attr.nodeName;
            
            propertyInfo = properties[attrName];
            if (propertyInfo) {
                propertyType = propertyInfo.type;
                propertyValue = attr.nodeValue;
                
                var delayedSet = false;
                
                if (propertyType == Object) {
                    var elementsOnly = (propertyInfo.attributes && propertyInfo.attributes[Web.Attributes.Element]);
                    if (!elementsOnly) {
                        markupContext.addReference(instance, propertyInfo, propertyValue);
                        delayedSet = true;
                    }
                    else {
                        propertyValue = markupContext.findObject(propertyValue, elementsOnly);
                    }
                }
                
                if (!delayedSet) {
                    propertyName = propertyInfo.name;

                    setter = instance['set_' + propertyName];
                    if (propertyType != Object) {
                        if (propertyType == Array) {
                            propertyValue = Array.parse('[' + propertyValue + ']');
                        }
                        else if (propertyType != String) {
                            propertyValue = propertyType.parse(propertyValue);
                        }
                    }
                    
                    setter.call(instance, propertyValue);
                }
            }
            else {
                eventInfo = events[attrName];
                if (eventInfo) {
                    var handler = Function.parse(attr.nodeValue);
                    if (handler) {
                        eventValue = instance[eventInfo.name];
                        eventValue.add(handler);
                    }
                }
            }
        }
    }

    var childNodes = node.childNodes;
    if (childNodes && (childNodes.length != 0)) {
        for (i = childNodes.length - 1; i >= 0; i--) {
            var childNode = childNodes[i];
            var nodeName = childNode.baseName;

            propertyInfo = properties[nodeName];
            if (propertyInfo) {
                propertyName = propertyInfo.name;
                propertyType = propertyInfo.type;

                if (propertyInfo.isReadOnly) {
                    getter = instance['get_' + propertyName];
                    var nestedObject = getter.call(instance);
                    
                    if (propertyType == Array) {
                        if (childNode.childNodes.length != 0) {
                            var items = Web.TypeDescriptor.processMarkupNodes(childNode.childNodes, markupContext);
                            for (var itemIndex = 0; itemIndex < items.length; itemIndex++) {
                                nestedObject.add(items[itemIndex]);
                            }
                        }
                    }
                    else if (propertyType == Object) {
                        attributes = childNode.attributes;
                        for (a = attributes.length - 1; a >= 0; a--) {
                            attr = attributes[a];
                            nestedObject[attr.nodeName] = attr.nodeValue;
                        }
                    }
                    else {
                        Web.TypeDescriptor.initializeInstance(nestedObject, childNode, markupContext);
                    }
                }
                else {
                    propertyValue = null;
                    if (propertyType == String) {
                        propertyValue = childNode.text;
                    }
                    else if (childNode.childNodes.length != 0) {
                        var valueNode;
                        for (var childNodeIndex = 0; childNodeIndex < childNode.childNodes.length; childNodeIndex++) {
                            if (childNode.childNodes[childNodeIndex].nodeType != 1) {
                                continue;
                            }
                            valueNode = childNode.childNodes[childNodeIndex];
                            break;
                        }
                        if (valueNode) {
                            propertyValue = Web.TypeDescriptor.processMarkupNode(valueNode, markupContext);
                        }
                    }
                    
                    if (propertyValue) {
                        setter = instance['set_' + propertyName];
                        setter.call(instance, propertyValue);
                    }
                }
            }
            else {
                eventInfo = events[nodeName];
                if (eventInfo && eventInfo.actions) {
                    var actions = Web.TypeDescriptor.processMarkupNodes(childNode.childNodes, markupContext);
                    if (actions.length) {
                        eventValue = instance[eventInfo.name];
                        for (var e = 0; e < actions.length; e++) {
                            eventValue.addAction(actions[e]);
                        }
                    }
                }
            }
        }
    }

    if (supportsBatchedUpdates) {
        markupContext.addEndUpdate(instance);
    }
    
    return instance;
}

Web.TypeDescriptor.processMarkupNode = function(node, markupContext) {
    var parsedObject = null;
    
    var tagPrefix = node.prefix;
    if (!tagPrefix || (tagPrefix.length == 0)) {
        tagPrefix = 'script';
    }

    var tagName = node.baseName;

    var tagType = Web.TypeDescriptor.getType(tagPrefix, tagName);
    if (tagType) {
        var parseMethod = tagType.parseFromMarkup;
        if (!parseMethod) {
            var baseType = tagType.getBaseType();
            while (baseType) {
                parseMethod = baseType.parseFromMarkup;
                if (parseMethod) {
                    break;
                }
                baseType = baseType.getBaseType();
            }
            tagType.parseFromMarkup = parseMethod;
        }
        
        if (parseMethod) {
            parsedObject = parseMethod.call(null, tagType, node, markupContext);
        }
    }
    return parsedObject;
}

Web.TypeDescriptor.processMarkupNodes = function(nodes, markupContext) {
    var objects = [];
    
    for (var i = 0; i < nodes.length; i++) {
        var objectNode = nodes[i];
        if (objectNode.nodeType != 1) {
                        continue;
        }

        var processedObject = this.processMarkupNode(objectNode, markupContext);
        if (processedObject) {
            objects.add(processedObject);
        }
    }
    
    return objects;
}

Web.TypeDescriptor.unload = function() {
    if (Web.TypeDescriptor._registeredTags) {
                        Web.TypeDescriptor._registeredTags = null;
    }
}

Web.TypeDescriptor.getAttribute = function(instance, attributeName) {
    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (!td) {
        return null;
    }

    return td._getAttributes()[attributeName];
}

Web.TypeDescriptor.getProperty = function(instance, propertyName, key) {
    if (Web.ICustomTypeDescriptor.isImplementedBy(instance)) {
        return instance.getProperty(propertyName, key);
    }
    
    if ((propertyName == null) || (propertyName.length == 0)) {
        return instance;
    }
    
    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (!td) {
        return null;
    }

    var propertyInfo = td._getProperties()[propertyName];
    if (!propertyInfo) {
        return null;
    }
    
    var getter = instance['get_' + propertyInfo.name];
    var object = getter.call(instance);
    
    if ((propertyInfo.type == Object) && propertyInfo.isReadOnly && key) {
        object = object[key];
    }
    return object;
}

Web.TypeDescriptor.setProperty = function(instance, propertyName, value, key) {
    if (Web.ICustomTypeDescriptor.isImplementedBy(instance)) {
        instance.setProperty(propertyName, value, key);
        return;
    }
    
    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (td) {
        var propertyInfo = td._getProperties()[propertyName];
debug.assert(propertyInfo, String.format("Property {0} not found", propertyName), this);
        if (propertyInfo) {
            if (!propertyInfo.isReadOnly) {
                                                if ((propertyInfo.type != String) && (typeof(value) == 'string') && propertyInfo.type.parse) {
                    value = propertyInfo.type.parse(value);
                }

                var setter = instance['set_' + propertyInfo.name];
                setter.call(instance, value);
            }
            else if ((propertyInfo.type == Object) && key) {
                var getter = instance['get_' + propertyInfo.name];
                var object = getter.call(instance);
                
                object[key] = value;
            }
        }
    }
}

Web.TypeDescriptor.invokeMethod = function(instance, methodName, parameters) {
    if (Web.ICustomTypeDescriptor.isImplementedBy(instance)) {
        return instance.invokeMethod(methodName, parameters);
    }
    
    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (td) {
        var methodInfo = td._getMethods()[methodName];
        if (methodInfo) {
            var method = instance[methodInfo.name];
            
            if (!methodInfo.parameters || !methodInfo.parameters.length) {
                return method.call(instance);
            }
            else {
                if (!parameters) {
                    return null;
                }
                
                var arguments = [];
                for (var i = 0; i < methodInfo.parameters.length; i++) {
                    var parameterInfo = methodInfo.parameters[i];
                    var value = parameters[parameterInfo.name];
                    
                    if (value && (parameterInfo.type != String) && (typeof(value) == 'string')) {
                        value = parameterInfo.type.parse(value);
                    }

                    arguments[i] = value;
                }
                
                return method.apply(instance, arguments);
            }
        }
    }
    
    return null;
}

Web.TypeDescriptor.getPropertyType = function(instance, propertyName, key) {
    if (Web.ICustomTypeDescriptor.isImplementedBy(instance)) {
        return Object;
    }
    
    if (key) {
        return Object;
    }

    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (!td) {
        return null;
    }

    var propertyInfo = td._getProperties()[propertyName];
    if (!propertyInfo) {
        return null;
    }
    
    return propertyInfo.type;
}


Web.TypeDescriptor.MarkupContext = function(document, global, parentContext, dataContext) {
    var _document = document;
    var _global = global;
    var _parentContext = parentContext;
    var _dataContext = dataContext;
    var _dataContextHidden;
    var _objects = { };
    var _pendingReferences = [];
    var _pendingEndUpdates = [];
    
    this.get_dataContext = function() {
        if (_dataContextHidden) {
            return null;
        }
        return _dataContext;
    }
    
    this.get_document = function() {
        return _document;
    }
    
    this.get_isGlobal = function() {
        return _global;
    }
    
    this.addObject = function(id, object) {
        _objects[id] = object;
    }

    this.addEndUpdate = function(instance) {
        _pendingEndUpdates.add(instance);
    }
        
    this.addReference = function(instance, propertyInfo, reference) {
        _pendingReferences.add({ o: instance, p: propertyInfo, r: reference });
    }
    
    this.complete = function() {
                                _document = null;
        
        _dataContext = null;
        
        var i;
        for (i = 0; i < _pendingReferences.length; i++) {
            var pendingReference = _pendingReferences[i];
            
            var instance = pendingReference.o;
            var propertyInfo = pendingReference.p;
            var propertyValue = pendingReference.r;

            var object = this.findObject(propertyValue,  false);
            if (object) {
                var setter = instance['set_' + propertyInfo.name];
                setter.call(instance, object);
            }
        }
        _pendingReferences = null;
        
        for (i = 0; i < _pendingEndUpdates.length; i++) {
            _pendingEndUpdates[i].endUpdate();
        }
        _pendingEndUpdates = null;
    }

    this.dispose = function() {
        if (!_global) {
                                                                        for (var o in _objects) {
                if (Web.IDisposable.isImplementedBy(_objects[o])) {
                    _objects[o].dispose();
                }
                
                _objects[o] = null;
            }
        }
        
        _document = null;
        _objects = null;
        _parentContext = null;
        _dataContext = null;
    }
    
    this.findObject = function(id, elementsOnly) {
        var object;
        if (elementsOnly) {
            if (_document) {
                object = _document.getElementById(id);
            }
            if (!object && _parentContext) {
                object = _parentContext.findObject(id, elementsOnly);
            }
            return object;
        }
        
        object = _objects[id];
        if (!object && _document) {
            object = _document.getElementById(id);
        }
        
        if (!object && _parentContext) {
            object = _parentContext.findObject(id, elementsOnly);
        }
        

⌨️ 快捷键说明

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