/* $id: global.js 15469 2008-12-19 06:34:44z testyang $ */ object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; } /* object.prototype.extend = function(object) { return object.extend.apply(this, [this, object]); } */ //封装geteelementbyid函数 function $e() { var elements = new array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getelementbyid(element); if (arguments.length == 1) return element; elements.push(element); } return elements; } //创建元素 function $ce(tagname) { return document.createelement(tagname); } //定义类类型 var class = { create : function() { return function() { this.initialize.apply(this, arguments); } } } //对象绑定 function.prototype.bind = function(object) { var __method = this; return function() { __method.apply(object, arguments); } } if (!window.event) { var event = new object(); } object.extend(event, { element: function(event) { return event.target || event.srcelement; }, pointerx: function(event) { return event.pagex || (event.clientx + (document.documentelement.scrollleft || document.body.scrollleft)); }, pointery: function(event) { return event.pagey || (event.clienty + (document.documentelement.scrolltop || document.body.scrolltop)); }, stop: function(event) { if (event.preventdefault) { event.preventdefault(); event.stoppropagation(); } else { event.returnvalue = false; } }, position: function(element) { var t = element.offsettop; var l = element.offsetleft; while(element = element.offsetparent) { t += element.offsettop; l += element.offsetleft; } var pos={top:t,left:l}; return pos; } , observers: false, _observeandcache: function(element, name, observer, usecapture) { if (!this.observers) this.observers = []; if (element.addeventlistener) { this.observers.push([element, name, observer, usecapture]); element.addeventlistener(name, observer, usecapture); } else if (element.attachevent) { this.observers.push([element, name, observer, usecapture]); element.attachevent('on' + name, observer); } }, observe: function(element, name, observer, usecapture) { var element = $e(element); usecapture = usecapture || false; if (name == 'keypress' && ((navigator.appversion.indexof('applewebkit') > 0) || element.attachevent)) name = 'keydown'; this._observeandcache(element, name, observer, usecapture); }, stopobserving: function(element, name, observer, usecapture) { var element = $e(element); usecapture = usecapture || false; if (name == 'keypress' && ((navigator.appversion.indexof('applewebkit') > 0) || element.detachevent)) name = 'keydown'; if (element.removeeventlistener) { element.removeeventlistener(name, observer, usecapture); } else if (element.detachevent) { element.detachevent('on' + name, observer); } } });