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

📄 contentpane.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
	//		replace keyword '_container_' in scripts with 'dijit.byId(this.id)'	// NOTE this name might change in the near future	scriptHasHooks: false,	/*======	// ioMethod: dojo.xhrGet|dojo.xhrPost	//		reference to the method that should grab the content	ioMethod: dojo.xhrGet,		// ioArgs: Object	//		makes it possible to add custom args to xhrGet, like ioArgs.headers['X-myHeader'] = 'true'	ioArgs: {},	// onLoadDeferred: dojo.Deferred	//		callbackchain will start when onLoad occurs	onLoadDeferred: new dojo.Deferred(),	// onUnloadDeferred: dojo.Deferred	//		callbackchain will start when onUnload occurs	onUnloadDeferred: new dojo.Deferred(),	setHref: function(url){		// summary: replace current content with url's content		return ;// dojox.layout.ContentPane.DeferredHandle	},	refresh: function(){		summary: force a re-download of content		return ;// dojox.layout.ContentPane.DeferredHandle 	},	======*/	constructor: function(){		// init per instance properties, initializer doesn't work here because how things is hooked up in dijit._Widget		this.ioArgs = {};		this.ioMethod = dojo.xhrGet;		this.onLoadDeferred = new dojo.Deferred();		this.onUnloadDeferred = new dojo.Deferred();	},	postCreate: function(){		// override to support loadDeferred		this._setUpDeferreds();		dijit.layout.ContentPane.prototype.postCreate.apply(this, arguments);	},	onExecError: function(e){		// summary		//		event callback, called on script error or on java handler error		//		overide and return your own html string if you want a some text 		//		displayed within the ContentPane	},	setContent: function(data){		// summary: set data as new content, sort of like innerHTML		// data: String|DomNode|NodeList|dojo.NodeList		if(!this._isDownloaded){			var defObj = this._setUpDeferreds();		}		dijit.layout.ContentPane.prototype.setContent.apply(this, arguments);		return defObj; // dojox.layout.ContentPane.DeferredHandle	},	cancel: function(){		// summary: cancels a inflight download		if(this._xhrDfd && this._xhrDfd.fired == -1){			// we are still in flight, which means we should reset our DeferredHandle			// otherwise we will trigger onUnLoad chain of the canceled content,			// the canceled content have never gotten onLoad so it shouldn't get onUnload			this.onUnloadDeferred = null;		}		dijit.layout.ContentPane.prototype.cancel.apply(this, arguments);	},	_setUpDeferreds: function(){		var _t = this, cancel = function(){ _t.cancel();	}		var onLoad = (_t.onLoadDeferred = new dojo.Deferred());		var onUnload = (_t._nextUnloadDeferred = new dojo.Deferred());		return {			cancel: cancel,			addOnLoad: function(func){onLoad.addCallback(func);},			addOnUnload: function(func){onUnload.addCallback(func);}		};	},	_onLoadHandler: function(){		dijit.layout.ContentPane.prototype._onLoadHandler.apply(this, arguments);		if(this.onLoadDeferred){			this.onLoadDeferred.callback(true);		}	},	_onUnloadHandler: function(){		this.isLoaded = false;		this.cancel();// need to cancel so we don't get any inflight suprises		if(this.onUnloadDeferred){			this.onUnloadDeferred.callback(true);		}		dijit.layout.ContentPane.prototype._onUnloadHandler.apply(this, arguments);		if(this._nextUnloadDeferred){			this.onUnloadDeferred = this._nextUnloadDeferred;		}	},	_onError: function(type, err){		dijit.layout.ContentPane.prototype._onError.apply(this, arguments);		if(this.onLoadDeferred){			this.onLoadDeferred.errback(err);		}	},	_prepareLoad: function(forceLoad){		// sets up for a xhrLoad, load is deferred until widget is showing		var defObj = this._setUpDeferreds();		dijit.layout.ContentPane.prototype._prepareLoad.apply(this, arguments);		return defObj;	},	_setContent: function(cont){		// override dijit.layout.ContentPane._setContent, to enable path adjustments		var styles = [];// init vars		if(dojo.isString(cont)){			if(this.adjustPaths && this.href){				cont = adjustHtmlPaths(this.href, cont);			}			if(this.cleanContent){				cont = secureForInnerHtml(cont);			}			if(this.renderStyles || this.cleanContent){				cont = snarfStyles(this.href, cont, styles);			}			// because of a bug in IE, script tags that is first in html hierarchy doesnt make it into the DOM 			//	when content is innerHTML'ed, so we can't use dojo.query to retrieve scripts from DOM			if(this.executeScripts){				var _t = this, code, byRef = {					downloadRemote: true,					errBack:function(e){						_t._onError.call(_t, 'Exec', 'Error downloading remote script in "'+_t.id+'"', e);					}				};				cont = snarfScripts(cont, byRef);				code = byRef.code;			}			// rationale for this block:			// if containerNode/domNode is a table derivate tag, some browsers dont allow innerHTML on those			var node = (this.containerNode || this.domNode), pre = post = '', walk = 0;			switch(node.nodeName.toLowerCase()){				case 'tr':					pre = '<tr>'; post = '</tr>';					walk += 1;//fallthrough				case 'tbody': case 'thead':// children of THEAD is of same type as TBODY					pre = '<tbody>' + pre; post += '</tbody>';					walk += 1;// falltrough				case 'table':					pre = '<table>' + pre; post += '</table>';					walk += 1;					break;			}			if(walk){				var n = node.ownerDocument.createElement('div');				n.innerHTML = pre + cont + post;				do{					n = n.firstChild;				}while(--walk);				cont = n.childNodes;			}		}		// render the content		dijit.layout.ContentPane.prototype._setContent.call(this, cont);		// clear old stylenodes from the DOM		if(this._styleNodes && this._styleNodes.length){			while(this._styleNodes.length){				dojo._destroyElement(this._styleNodes.pop());			}		}		// render new style nodes		if(this.renderStyles && styles && styles.length){			this._renderStyles(styles);		}		if(this.executeScripts && code){			if(this.cleanContent){				// clean JS from html comments and other crap that browser				// parser takes care of in a normal page load				code = code.replace(/(<!--|(?:\/\/)?-->|<!\[CDATA\[|\]\]>)/g, '');			}			if(this.scriptHasHooks){				// replace _container_ with dijit.byId(this.id)				code = code.replace(/_container_(?!\s*=[^=])/g, dijit._scopeName + ".byId('"+this.id+"')");			}			try{				evalInGlobal(code, (this.containerNode || this.domNode));			}catch(e){				this._onError('Exec', 'Error eval script in '+this.id+', '+e.message, e);			}		}	},	_renderStyles: function(styles){		// insert css from content into document head		this._styleNodes = [];		var st, att, cssText, doc = this.domNode.ownerDocument;		var head = doc.getElementsByTagName('head')[0];		for(var i = 0, e = styles.length; i < e; i++){			cssText = styles[i]; att = styles.attributes[i];			st = doc.createElement('style');			st.setAttribute("type", "text/css"); // this is required in CSS spec!			for(var x in att){				st.setAttribute(x, att[x])			}						this._styleNodes.push(st);			head.appendChild(st); // must insert into DOM before setting cssText			if(st.styleSheet){ // IE				st.styleSheet.cssText = cssText;			}else{ // w3c				st.appendChild(doc.createTextNode(cssText));			}		}	}});})();}

⌨️ 快捷键说明

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