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

📄 eventmanager.js

📁 ARCGIS程序,可以实现查、缩放等功能
💻 JS
字号:
if (!Array.prototype.push){
    Array.prototype.push = function(elem)
    {
        this[this.length] = elem;
    }
}

var EventManager ={
    _registry: null,

    Initialise: function(){
        if (this._registry == null){
            this._registry = [];

            // Register the cleanup handler on page unload.
            EventManager.Add(window, "unload", this.CleanUp);
        }
    },

    /**
     * Registers an event and handler with the manager.
     *
     * @param  obj         Object handler will be attached to.
     * @param  type        Name of event handler responds to.
     * @param  fn          Handler function.
     * @param  useCapture  Use event capture. False by default.
     *                     If you don't understand this, ignore it.
     *
     * @return True if handler registered, else false.
     */
    Add: function(obj, type, fn, useCapture){
        this.Initialise();

        // If a string was passed in, it's an id.
        if (typeof obj == "string")
            obj = document.getElementById(obj);
        if (obj == null || fn == null)
            return false;

        // Mozilla/W3C listeners?
        if (obj.addEventListener){
            obj.addEventListener(type, fn, useCapture);
            this._registry.push({obj: obj, type: type, fn: fn, useCapture: useCapture});
            return true;
        }

        // IE-style listeners?
        if (obj.attachEvent && obj.attachEvent("on" + type, fn)){
            this._registry.push({obj: obj, type: type, fn: fn, useCapture: false});
            return true;
        }

        return false;
    },

    /**
     * Cleans up all the registered event handlers.
     */
    CleanUp: function(){
        for (var i = 0; i < EventManager._registry.length; i++){
            with (EventManager._registry[i]){
                // Mozilla/W3C listeners?
                if (obj.removeEventListener)
                    obj.removeEventListener(type, fn, useCapture);
                // IE-style listeners?
                else if (obj.detachEvent)
                    obj.detachEvent("on" + type, fn);
                    
                obj = null;
                fn = null;
            }
        }

        // Kill off the registry itself to get rid of the last remaining
        // references.
        EventManager._registry = null;
    }
};


/**
	遍历dom对象,释放由事件引发的循环引用问题.
*/
function ReleaseEvents()
{
    var events = ["focus", "blur", "click", "mouseup", "mouseover", "keypress", "mouseout"];

    var helper = function(obj)
    {
        var i;
        for (i = 0; i < events.length; i++)
        	if(obj["on" + events[i]]){
            	obj["on" + events[i]] = null;
           	}
        for (i = 0; i < obj.childNodes.length; i++)
            helper(obj.childNodes[i]);
    }
    helper(document.body);
}
/**
	为ReleaseEvents添加window.unload事件
*/
//EventManager.Add(window, "unload", ReleaseEvents);

/**
	清除由自定义属性引发的循环引用问题.从而清除内存泄漏.
*/
function clear_mem(obj){
	if(obj&&obj.attributes){
		var temp = obj.attributes.length;
		for(i=0;i<temp;i++){
			var name = obj.attributes[i].name;
					try{
						obj[name]=null;
					}
					catch(E){
					}
		}
	}
}

⌨️ 快捷键说明

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