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

📄 silverna-packs.js

📁 《JavaScript王者归来》examples.rar
💻 JS
📖 第 1 页 / 共 4 页
字号:
					{
						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.toggle = function(_hideHdl, _showHdl){
		this.el.style.display = (this.el.style.display != "none") ? "none" : "block";
		if(_hideHdl && this.el.style.display == "none") _hideHdl(this);
		else if(_showHdl) _showHdl(this);
	}
	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;
	}
	HTMLElement.prototype.getValue = function()
	{
		var o = this.el;
		while(o.childNodes[0] && o.childNodes[0].nodeType == 1)
			o = o.childNodes[0];
		if(typeof o.form != "undefined")
		{
			if(o.type == "checkbox" || o.type == "radio")
			{
				return o.checked;
			}
			return o.value;
		}
		else
			return o.innerText;
	}
	//为一个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 = pageRect();
				_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 
		return null;
}

with(core.web.widgets)
{
	with(adorners.behaviors)
	{
		//Behaviors抽象的是Widget的行为
		//一个Widgets可以注册多个Behaviors
		//Knob “旋钮” Behavior的控制点,可以有多个
		Behavior = function()
		{
			this.panel = null;
			this.knobs = [];
			this.actionList = [];
			this.activeActionList = [];

			core.events.EventManager.apply(this);
		}
		//新增panel,panel是Behavior真正作用的实体对象,而knobs只是对象面板中的几个控制点
		//事实上Behavior对象提供了通过knobs影响panel的能力
		Behavior.prototype.setPanel = function(panel)
		{
			this.panel = panel;
		}
		Behavior.prototype.addPanel = Behavior.prototype.setPanel;
		//新增控制点到Behavior对象,它们是一组core.web.HTMLElement对象
		Behavior.prototype.addKnobs = function()
		{
			this.knobs = this.knobs.concat($arr(arguments));
		}
		//给Behavior增加“活动”, knobIdx表示将该活动作用于的那个knobs的index
		//Action有两种类型,一种是系统的Action,它接管knobs的事件处理
		//另一种是用户自定义的Action(它不太常用)
		Behavior.prototype.addAction = function(evtType, evtHandlerName, knobIdx, userAction)
		{
			//knobIdx = knobIdx || 0;
			userAction = userAction || false;

			if(!this[evtHandlerName]) this[evtHandlerName] = $void;
			if(evtHandlerName instanceof Function)
			{
				this["on" + evtType] = evtHandlerName;
				evtHandlerName = "on" + evtType;
			}
			if(userAction){
				this[evtType] = function(){
					this.dispatchEvent(evtType,{index:knobIdx});
				}
			}
			var evtHandler = function(evt){
				this[evtHandlerName].call(this, evt);
			}
			this.actionList.push({type:evtType, handler:evtHandler, index:knobIdx, userAction:false});
		}
		Behavior.prototype.addBrowserAction = function(evtType, evtHandlerName, knobIdx)
		{
			return this.addAction(evtType, evtHandlerName, knobIdx, false);
		}
		Behavior.prototype.addUserAction = function(evtType, evtHandlerName, knobIdx)
		{
			return this.addAction(evtType, evtHandlerName, knobIdx, true);
		}
		//激活Behavior,增加或者修改活动后需要激活
		Behavior.prototype.active = function(actionIdx)
		{
			var $pointer = this;
			var panel = this.panel;
			if(actionIdx != null)
			{
				var action = this.actionList[actionIdx];
				this.activeActionList[actionIdx] = this.activeActionList[actionIdx] || [];
				//如果该行为是绑定到具体的某个knob的,那么......
				if(action.index != null){
					var knob = this.knobs[action.index];
					if(action.userAction)
					{
						this.activeActionList[actionIdx].push(this.addEventListener(action.type, action.handler));
					}
					else if(knob)
					{
						var active = knob.addEventListener(action.type, action.handler, false, $pointer, {knob:knob, panel:panel});
						active.knob = knob;
						this.activeActionList[actionIdx].push(active);
					}
				}
				//否则将对所有的knobs有效
				else
				{
					if(action.userAction)
					{

⌨️ 快捷键说明

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