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

📄 silverna-packs.js

📁 《JavaScript王者归来》examples.rar
💻 JS
📖 第 1 页 / 共 3 页
字号:
								var ret = evt.call($pointer,eventArgs);
								//如果有捕获事件的方法,并且没有阻止事件气泡,在最后一个事件处理程序结束之后调用它
								if(!eventArgs.cancelBubble && called == len && capturer && capturerName && capturer[capturerName])
								{
									setTimeout(function(){
											capturer[capturerName](eventArgs)
										},1)
								}
								//如果定义了默认动作,在最后一个事件处理程序结束之后执行它
								if(called == len && eventArgs.defaultOp) 
								{
									eventArgs.defaultOp.call($pointer, eventArgs);
								}
								return ret;
							}
						})(i), 1
					);
				}
			}
			else if(eventArgs.defaultOp)
			{
				eventArgs.defaultOp.call($pointer, eventArgs);
			}
		}
		this.fireEvent = this.dispatchEvent;
		this.captureEvents = function(target, eventType, capturerName, closure)
		{
			if(capturerName instanceof Function)
			{
				closure = capturerName;
				capturerName = null;
			}
			capturerName = capturerName || "on" + eventType;
			target["on"+eventType] = target["on"+eventType] || [function(){}];
			var events = target["on"+eventType];
			if(typeof(events) == "function")
			{
				target["on"+eventType] = [events];
			}

			target["on"+eventType].capturer = this;
			target["on"+eventType].capturerName = capturerName;

			if(closure)
				this[capturerName] = closure;
		}

		this.addEventListener = function(eventType, closure)
		{
			if(this["on"+eventType] == null)
			{
				this["on"+eventType] = [];
			}
			var events = this["on"+eventType];
			if(events && typeof(events) == "function"){
				this["on"+eventType] = [events];		
				events = this["on"+eventType];
			}
			events.push(closure);
			return closure;
		}

		this.removeEventListener = function(eventType, closure)
		{
			var events = this["on"+eventType];
			if(events && typeof(events) == "function")
				events = [events];		
			
			for(var i = 0; i < events.length; i++)
			{
				if(events[i] == closure)
					events.splice(i, 1);
			}
			return closure;
		}
	}
}

if(typeof(HTMLElement)!="undefined" && !window.opera)
{
  HTMLElement.prototype.__defineGetter__("outerHTML",function()
  {
    var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
    if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
    if(!this.canHaveChildren) return str+" />";
    return str+">"+this.innerHTML+"</"+this.tagName+">";
  });
  HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
  {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var df = r.createContextualFragment(s);
    this.parentNode.replaceChild(df, this);
    return s;
  });
  HTMLElement.prototype.__defineGetter__("innerText",function()
  {
		return this.textContent;
  });
  HTMLElement.prototype.__defineSetter__("innerText",function(s)
  {
    this.textContent = s;
    return s;
  });
  HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
  {
    return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
  });
}

with(core.web)
{
	//扩展DOM,具有兼容性的HTMLElement类型
	HTMLElement = function(domObj)
	{
		this.el = domObj;
	}

	HTMLElement._floatZIndex = 1000;
	
	HTMLElement.prototype.focus = function()
	{
		this.el.style.zIndex = HTMLElement._floatZIndex;
		HTMLElement._floatZIndex += 10;
	}
	HTMLElement.prototype.blur = function()
	{
		this.el.style.zIndex = 0;
	}
	HTMLElement.prototype.setAttribute = function(propName, value)
	{
		//this.el[propName] = value;
		return this.el.setAttribute(propName, value);
	}
	HTMLElement.prototype.getAttribute = function(propName)
	{
		return this.el.getAttribute(propName);
	}

	HTMLElement.prototype.setStyleRule = function(className,rules)
	{
		if(!rules)
			this.el.className = className;
		else
			this.el.style[className] = rules;
	}

	HTMLElement.prototype.setStyleRuleText = function(ruleText)
	{
		this.el.style.cssText = ruleText;
	}	

	HTMLElement.prototype.setText = function(text)
	{
		if(/^(input)|(select)|(textarea)$/i.test(this.el.tagName))
			this.el.value = text;
		else
			this.el.innerText = text;
	}

	HTMLElement.prototype.addEventListener = function(evtType, evtHandler, capturing, owner, userArgs)
	{
		var $pointer = owner || this;
		var $handler;
		capturing = capturing || false;

		if(this.el.attachEvent)
		{
			$handler = function()
			{	
				var evt = window.event;
				if(userArgs)
				{
					for(var each in userArgs)
					{
						evt[each] = userArgs[each];
					}
				}

				evt.target = evt.srcElement;
				evt.relatedTarget = evt.fromElement || evt.toElement;
				evt.leftButton = function(){return evt.button == 1};
				evt.rightButton = function(){return evt.button == 2};
				evt.layerX = evt.offsetX;
				evt.layerY = evt.offsetY;
				evt.pageX = evt.clientX - document.body.scrollLeft - document.body.clientLeft;
				evt.pageY = evt.clientY - document.body.scrollTop - document.body.clientTop;

				evt.attrName = evt.propertyName;

				return evtHandler.call($pointer,evt)
			};
			this.el.attachEvent("on"+evtType, $handler);
		}
		else if(this.el.addEventListener)
		{
			Event.prototype.leftButton = function(){return this.button == 0};
			Event.prototype.rightButton = function(){return this.button == 2};
			$handler = function(event){
				if(userArgs)
				{
					for(var each in userArgs)
					{
						event[each] = userArgs[each];
					}
				}
				return evtHandler.call($pointer, event)		
			};

			this.el.addEventListener(evtType, $handler, capturing);
		}

		return $handler;
	}

	HTMLElement.prototype.removeEventListener = function(evtType, evtHandler, capturing)
	{
		capturing = capturing || false;
		if(this.el.detachEvent)
		{
			this.el.detachEvent("on"+evtType, evtHandler);
		}
		else if(this.el.removeEventListener)
		{
			this.el.removeEventListener(evtType, evtHandler, capturing);
		}

		return evtHandler;
	}

	HTMLElement.prototype.stopPropagation = function()
	{
		if(this.el.stopPropagation)
		{
			this.el.stopPropagation();
		}
		else if(event && event.cancelBubble != null)
		{
			event.cancelBubble = true;
		}
	}

	HTMLElement.prototype.preventDefault = function()
	{
		if(this.el.preventDefault)
		{
			this.el.preventDefault();
		}
		else if(event && event.returnValue != null)
		{
			event.returnValue = true;
		}
	}
	HTMLElement.prototype.setCapture = function()
	{
		if(window.captureEvents) window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		else this.el.setCapture();
	}
	HTMLElement.prototype.releaseCapture = function()
	{
		if(window.releaseEvents) window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		else this.el.releaseCapture();
	}
	HTMLElement.prototype.setCursor = function(type)
	{
		this.el.style.cursor = type;
	}
	HTMLElement.prototype.moveBy = function(x, y)
	{
		x = x || 0;
		y = y || 0;

		return this.setPosition(pos.x + x, pos.y + y);
	}
	HTMLElement.prototype.moveTo = function(x, y)
	{
		return this.setPosition(x, y);
	}
	HTMLElement.prototype.setAbsPosition = function(x, y)
	{
		this.el.style.position = "absolute";
		var pos = this.getPosition();
		var npos = this.getAbsPosition();
		
		this.setPosition(x - npos.x + pos.x, y - npos.y + pos.y);
	}
	HTMLElement.prototype.setPosition = function(x, y)
	{
		x != null || (x = this.getPosition().x);
		y != null || (y = this.getPosition().y);

		//this.el.style.position = "absolute";
		this.el.style.left = x + "px";
		this.el.style.top = y + "px";
		return this.el;
	}
	HTMLElement.prototype.resize = function(w, h)
	{
		if(w != null)
			this.el.style.width = w + "px";
		if(h != null)
			this.el.style.height = h + "px";
	}
	HTMLElement.prototype.getSize = function()
	{
		return {width:parseInt(this.el.clientWidth), height:parseInt(this.el.clientHeight)};
	}
	HTMLElement.prototype.setFontColor = function(color)
	{
		this.el.style.color = color;
	}
	HTMLElement.prototype.getPosition = function()
	{
		var pTarget = this.el;
		var _x = pTarget.offsetLeft;
		var _y = pTarget.offsetTop;
		return {x:_x, y:_y};
	}
	HTMLElement.prototype.getAbsPosition = function()
	{
		var pTarget = this.el;
		var _x = 0;
		var _y = 0;
		while(pTarget.offsetParent){
				_x += pTarget.offsetLeft;
				_y += pTarget.offsetTop;
				pTarget = pTarget.offsetParent;
		}
		_x += pTarget.offsetLeft;
		_y += pTarget.offsetTop;
			
		return {x:_x,y:_y};
	}
	//获得鼠标相对于元素的位置
	HTMLElement.getMousePosition = function(evt){
		var _x,_y;
		evt = evt || window.event;
		if(evt.layerX && evt.layerY){
			_x = evt.layerX;
			_y = evt.layerY;
		}
		else{
			_x = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
			_y = evt.clientY + document.body.scrollTop - document.body.clientTop;
		}
		return {x:_x,y:_y};
	}
	HTMLElement.prototype.show = function(){
		this.el.style.display = "block";
	}
	HTMLElement.prototype.hide = function(){
		this.el.style.display = "none";
	}
	HTMLElement.prototype.visible = function(){
		return this.el.style.display != "none" && this.el.style.visibility != "hidden";
	}
	HTMLElement.prototype.clone = function(_b)
	{
		return $html(this.el.cloneNode(_b));
	}
	HTMLElement.prototype.hideChildren = function()
	{
		if(this._hideChildren == true) return false;
		for(var i = 0; i < this.el.childNodes.length; i++)
		{
			var _c = this.el.childNodes[i];
			if(_c.nodeType == 1)
			{
				_c.setAttribute("_saveVisibility", _c.style.visibility);
				_c.style.visibility = "hidden";
			}
		}
		this._hideChildren = true;
		return true;
	}
	HTMLElement.prototype.showChildren = function()
	{
		for(var i = 0; i < this.el.childNodes.length; i++)
		{
			var _c = this.el.childNodes[i];
			if(_c.nodeType == 1)
			{
				_c.style.visibility = _c.getAttribute("_saveVisibility") || "visible";
			}
		}
		this._hideChildren = false;
		return true;
	}
	//为一个DOM的指定attribute绑定数据源,绑定了数据源之后,改变这个DOM的attribute值将会同步更新数据源对应
	//属性值,同样改变数据源对应属性值也将立即改变DOM对应的attribute值
	//对于select、input和textarea,默认的attribute为value
	//对于a、iframe、frame、img,默认的attribute为src
	//其他默认为innerText
	//provider提供数据的JSON对象, propertyName是提供数据的属性名称
	HTMLElement.prototype.setDataProvider = function(provider, propertyName, attrName, propertychange)
	{
		var $pointer = this;
		propertyName = propertyName || "value";
		if(/select|input|textarea/ig.test(this.el.tagName))
			attrName = attrName || "value";
		else if(/a|iframe|frame|img/ig.test(this.el.tagName))
			attrName = attrName || "src";
		else
			attrName = attrName || "data";
		var evtType = "propertychange";
		if(document.implementation.hasFeature('MutationEvents','2.0') || window.MutationEvent){
			evtType = "DOMAttrModified";
			if(/input|textarea/ig.test(this.el.tagName))
				this.addEventListener("input",function(evt){
					this.el.setAttribute("value", this.el.value);
				});
			else if(/select/.test(this.el.tagName))
				this.addEventListener("click",function(evt){
					this.el.setAttribute("value", this.el.value);
				});
		}
		this.addEventListener(evtType, 
			function(evt)
			{
				if(evt.attrName == attrName){
					provider[propertyName] = this.getAttribute(attrName);
				}
			},false);
		this.getDataProvider = function()
		{
			return provider;
		}
		this.setAttribute(attrName,provider[propertyName]);
		provider.__extend__(core.events.EventManager);
		provider.__getter__(propertyName, function(){
			return this[propertyName];
		});
		provider.__setter__(propertyName, function(value){
			var evtArgs = {propertyName:propertyName,propertyValue:value};
			this[propertyName] = value;
			evtArgs.defaultOp = function(){
				$pointer.setAttribute(attrName, value);
			}
			this.dispatchEvent("propertychange",evtArgs);
		});
	}
	HTMLElement.blackSheepWall = {
		show:function(opacity)
		{
			var _sheep = $id("_silverna_black_sheep_wall");
			if(!_sheep)
			{
				opacity = opacity || 0;
				var _div = $html("div");
				_div.el.style.position = "absolute";
				_div.el.id = "_silverna_black_sheep_wall";
				_div.el.style.margin = "0 0 0 0";
				_div.setPosition(0,0);
				_div.el.style.backgroundColor = "#999999";
				_div.el.style.filter="alpha(opacity="+opacity+")";
				_div.el.style.opacity = opacity;
				$body().appendChild(_div.el);
				var rect = clientRect();
				_div.el.style.width = rect.width;
				_div.el.style.height = rect.height;
			}
		},
		hide:function()
		{
			$body().removeChild($("_silverna_black_sheep_wall"));
		}
	}

	CSSStyleSheet = function()
	{
	}
	CSSStyleSheet.load = function(fullPath, media)
	{
		media = media || "all";
		var link = document.createElement("link");
		link.setAttribute("href", fullPath);
		link.setAttribute("type", "text/css");
		link.setAttribute("rel", "stylesheet");
		link.setAttribute("rev", "stylesheet");
		link.setAttribute("media", media);
		var head = $head();

		if(head){
			head.appendChild(link);
		}
		return new CSSStyleSheet();
	}
}

function $html(tagName, id, text)
{
	if(tagName.nodeType == 1)
		return new core.web.HTMLElement(tagName);

	var domObj = document.createElement(tagName);
	if(id) domObj.setAttribute("id", id);
	var ret = new core.web.HTMLElement(domObj);
	if(text) ret.setText(text);
	return ret;
}
function $trash(node)
{		
	if($isIE())
	{
		CollectGarbage.defer(100);
	}
	if(node)
	{
		var _id = "_silverna_trash_container";  //用来回收不要的DOM,避免内存泄漏
		var _trash = $id(_id);
		if(!_trash)
		{
			_trash = $html("trash", _id).el;
			_trash.style.display = "none";
			$body().appendChild(_trash);
		}
		_trash.appendChild(node);
	}
}
function $$(id)
{
	var domObj = $(id);
	if(domObj.nodeType == 1)
		return new core.web.HTMLElement(domObj);
	else 

⌨️ 快捷键说明

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