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

📄 atlas.js

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


Web._Debug = function() {
    
    this.assert = function(condition, message, displayCaller) {
        if (!condition) {
            message = 'Assertion Failed: ' + message + (displayCaller ? '\r\nat ' + this.assert.caller : '');
            if (confirm(message + '\r\n\r\nBreak into debugger?')) {
                this.fail(message);
            }
        }
    }
    
    this.clearTrace = function() {
        var traceElement = document.getElementById('__atlas_trace');
        if (traceElement) {
            var children = traceElement.childNodes;
            for(var i = children.length - 2; i > 0; i--) {
                traceElement.removeChild(children[i]);
            }
            document.getElementById('__atlas_trace').style.display = 'none';
        }
    }
    
    this.dump = function(object, name, recursive, indentationPadding, loopArray) {
        name = name ? name : '';
        indentationPadding = indentationPadding ? indentationPadding : '';
        if (object == null) {
            this.trace(indentationPadding + name + ': null');
            return;
        }
        switch(typeof(object)) {
            case 'undefined':
                this.trace(indentationPadding + name + ': Undefined');
                break;
            case 'number': case 'string': case 'boolean':
                this.trace(indentationPadding + name + ': ' + object);
                break;
            default:
                if (!loopArray) {
                    loopArray = [];
                }
                else if (loopArray.contains(object)) {
                    this.trace(indentationPadding + name + ': ...');
                    return;
                }
                loopArray.add(object);
                var type = Object.getType(object);
                if (type != null) {
                    var typeName = type.getName();
                    this.trace(indentationPadding + name + (typeof(typeName) == 'string' ? ' {' + typeName + '}' : ''));
                    if ((indentationPadding == '') || recursive) {
                        indentationPadding += '+';
                        var i, length, properties, p, v;
                        if (Web.IArray.isImplementedBy(object)) {
                            length = object.get_length();
                            for (i = 0; i < length; i++) {
                                this.dump(object.getItem(i), '[' + i + ']', recursive, indentationPadding, loopArray);
                            }
                        }
                        if (Web.ITypeDescriptorProvider.isImplementedBy(object)) {
                            var td = Web.TypeDescriptor.getTypeDescriptor(object);
                            properties = td._getProperties();
                            for (p in properties) {
                                var propertyInfo = properties[p];
                                if (propertyInfo.name) {
                                    v = Web.TypeDescriptor.getProperty(object, propertyInfo.name);
                                    this.dump(v, p, recursive, indentationPadding, loopArray);
                                }
                            }
                        }
                        else {
                            for (p in object) {
                                v = object[p];
                                if (!Function.isInstanceOfType(v) && !Web.Event.isInstanceOfType(v)) {
                                    this.dump(v, p, recursive, indentationPadding, loopArray);
                                }
                            }
                        }
                    }
                }
                else {
                    var tagName = object.tagName;
                    var attributes = object.attributes;
                    if (tagName && attributes) {
                        this.trace(indentationPadding + name + ' {' + tagName + '}');
                        indentationPadding += '+';
                        length = attributes.length;
                        for (var i = 0; i < length; i++) {
                            var val = attributes[i].nodeValue;
                            if (val) {
                                this.dump(val, attributes[i].nodeName, recursive, indentationPadding, loopArray);
                            }
                        }
                    }
                    else {
                        this.trace('Unknown object');
                    }
                }
                loopArray.remove(object);
        }
    }
    
    this.fail = function(message) {
        Debug.breakIntoDebugger(message);
    }

    this.trace = function(text) {
        Debug.writeln(text);

        var traceElement = document.getElementById('__atlas_trace');
        if (!traceElement) {
            traceElement = document.createElement('FIELDSET');
            traceElement.id = '__atlas_trace';
            traceElement.style.backgroundColor = 'white';
            traceElement.style.color = 'black';
            traceElement.style.textAlign = 'left';
            traceElement.style.font = 'normal normal normal 1em/1.1em verdana,sans-serif';
            var legend = document.createElement('LEGEND');
            var legendText = document.createTextNode('Debugging Trace');
            legend.appendChild(legendText);
            traceElement.appendChild(legend);
            var clearButton = document.createElement('INPUT');
            clearButton.type = 'button';
            clearButton.value = 'Clear Trace';
            clearButton.onclick = debug.clearTrace;
            traceElement.appendChild(clearButton);
            document.body.appendChild(traceElement);
        }
        var traceLine = document.createElement('DIV');
        traceLine.innerHTML = text;
        traceElement.insertBefore(traceLine, traceElement.childNodes[traceElement.childNodes.length - 1]);
        traceElement.style.display = 'block';
    }
}

window.debug = new Web._Debug();

Web.Enum = new function() {

    function getValues() {
        if (!this._values) {
            var values = { };
            
            for (var f in this) {
                if (typeof(this[f]) != 'function') {
                    values[f] = this[f];
                }
            }
            this._values = values;
        }
        return this._values;
    }

    function valueFromString(s) {
        for (var f in this) {
            if (f == s) {
                return this[f];
            }
        }
        throw 'Invalid Enumeration Value';
    }

    function valueToString(value) {
        for (var i in this) {
            if (this[i] == value) {
                return i;
            }
        }
        throw 'Invalid Enumeration Value';
    }
    
    this.create = function() {
        var enumeration = { };
        enumeration.getValues = getValues;
        enumeration.parse = valueFromString;
        enumeration.toString = valueToString;
        
        for (var i = 0; i < arguments.length; i++) {
            enumeration[arguments[i]] = i;
        }
        
        return enumeration;
    }
}

Web.Flags = new function() {

    function valueFromString(s) {
        var parts = s.split('|');
        var value = 0;
        
        for (var i = parts.length - 1; i >= 0; i--) {
            var part = parts[i].trim();
            var found = false;
            
            for (var f in this) {
                if (f == part) {
                    value |= this[f];
                    found = true;
                    break;
                }
            }
            if (found == false) {
                throw 'Invalid Enumeration Value';
            }
        }
        
        return value;
    }

    function valueToString(value) {
        var sb = new Web.StringBuilder();
        for (var i in this) {
            if ((this[i] & value) != 0) {
                if (sb.isEmpty() == false) {
                    sb.append(' | ');
                }
                sb.append(i);
            }
        }
        return sb.toString();
    }

    this.create = function() {
        var flags = new Object();
        flags.parse = valueFromString;
        flags.toString = valueToString;
        
        for (var i = 0; i < arguments.length; i += 2) {
            var name = arguments[i];
            var value = arguments[i + 1];
            
            flags[name] = value;
        }
        
        return flags;
    }
}

Web.Attributes = new function() {

    this.defineAttribute = function(attributeName) {
        this[attributeName] = attributeName;
    }
}

Web.IArray = function() {
    this.get_length = Function.abstractMethod;
    this.getItem = Function.abstractMethod;
}
Type.registerInterface("Web.IArray");

Array.prototype.get_length = function() {
    return this.length;
}

Array.prototype.getItem = function(index) {
    return this[index];
}

Array._interfaces = [];
Array._interfaces.add(Web.IArray);


Web.IDisposable = function() {
    this.dispose = Function.abstractMethod;
}
Type.registerInterface('Web.IDisposable');

Web.StringBuilder = function(initialText) {
    var _parts = new Array();
    
    if ((typeof(initialText) == 'string') &&
        (initialText.length != 0)) {
        _parts.add(initialText);
    }

    this.append = function(text) {
        if ((text == null) || (typeof(text) == 'undefined')) {
            return;
        }
        if ((typeof(text) == 'string') && (text.length == 0)) {
            return;
        }
        
        _parts.add(text);
    }

    this.appendLine = function(text) {
        this.append(text);
        _parts.add('\r\n');
    }

    this.clear = function() {
        _parts.clear();
    }

    this.isEmpty = function() {
        return (_parts.length == 0);
    }

    this.toString = function(delimiter) {
        delimiter = delimiter || '';
        return _parts.join(delimiter);
    }
}
Type.registerSealedClass('Web.StringBuilder');

Web.Attributes.defineAttribute('Element');


Web.TypeDescriptor = function() {
    var _properties = { };
    var _events = { };
    var _methods = { };
    var _attributes = { };
    
    this._getAttributes = function() {
        return _attributes;
    }
    
    this._getEvents = function() {
        return _events;
    }
    
    this._getMethods = function() {
        return _methods;
    }
    
    this._getProperties = function() {
        return _properties;
    }
}

Web.TypeDescriptor.prototype.addAttribute = function(attributeName, attributeValue) {
    this._getAttributes()[attributeName] = attributeValue;
}

Web.TypeDescriptor.prototype.addEvent = function(eventName, supportsActions) {
    this._getEvents()[eventName] = { name: eventName, actions: supportsActions };
}

Web.TypeDescriptor.prototype.addMethod = function(methodName, associatedParameters) {
    this._getMethods()[methodName] = { name: methodName, parameters: associatedParameters };
}

Web.TypeDescriptor.prototype.addProperty = function(propertyName, propertyType, readOnly) {
    if (!readOnly) {
        readOnly = false;
    }
    var associatedAttributes;
    if (arguments.length > 3) {
        associatedAttributes = { };
        for (var i = 3; i < arguments.length; i += 2) {
            var attribute = arguments[i];
            var value = arguments[i + 1];
            associatedAttributes[attribute] = value;
        }
    }
    this._getProperties()[propertyName] = { name: propertyName, type: propertyType, isReadOnly: readOnly, attributes: associatedAttributes };
}

Web.TypeDescriptor.addType = function(tagPrefix, tagName, type) {
    if (!Web.TypeDescriptor._registeredTags) {
        Web.TypeDescriptor._registeredTags = { };
    }

    var tagTable = Web.TypeDescriptor._registeredTags[tagPrefix];
    if (!tagTable) {
        tagTable = { };
        Web.TypeDescriptor._registeredTags[tagPrefix] = tagTable;
    }

    tagTable[tagName] = type;
}

Web.TypeDescriptor.createParameter = function(parameterName, parameterType) {
    return { name: parameterName, type: parameterType };
}

Web.TypeDescriptor.getType = function(tagPrefix, tagName) {
    if (Web.TypeDescriptor._registeredTags) {
        var tagNameTable = Web.TypeDescriptor._registeredTags[tagPrefix];
        if (tagNameTable) {
debug.assert(typeof(tagNameTable[tagName]) != "undefined", String.format("Unrecognized tag {0}:{1}", tagPrefix, tagName), false);
            return tagNameTable[tagName];
        }
    }
    return null;
}

Web.TypeDescriptor.getTypeDescriptor = function(instance) {
debug.assert(instance, "instance cannot be null.");
    var type = Object.getType(instance);
    var td = type._descriptor;
    if (!td) {
        td = instance.getDescriptor();
        type._descriptor = td;
    }

    return td;
}

Web.TypeDescriptor.initializeInstance = function(instance, node, markupContext) {
    var td = Web.TypeDescriptor.getTypeDescriptor(instance);
    if (!td) {
        return null;
    }
    
    var supportsBatchedUpdates = false;
    if (Web.ISupportBatchedUpdates.isImplementedBy(instance)) {
        supportsBatchedUpdates = true;
        instance.beginUpdate();
    }
    
    var i, a;
    var attr, attrName;
    var propertyInfo, propertyName, propertyType, propertyValue;
    var eventInfo, eventValue;
    var setter, getter;
    

⌨️ 快捷键说明

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