📄 domwidget.js
字号:
dojo.dom.moveChildren(src, subContainerNode); //do not need to follow children nodes in the main html page, as they //will be dealt with in the subContainerWidget frag['dojoDontFollow'] = true; } }else{ dojo.debug("No subContainerWidget node can be found in template file for widget "+this); } } var templatefrag = parser.parseElement(this.domNode, null, true); // createSubComponents not createComponents because frag has already been created dojo.widget.getParser().createSubComponents(templatefrag, this); //find all the sub widgets defined in the template file of this widget var subwidgets = []; var stack = [this]; var w; while((w = stack.pop())){ for(var i = 0; i < w.children.length; i++){ var cwidget = w.children[i]; if(cwidget._processedSubWidgets || !cwidget.extraArgs['_issubwidget']){ continue; } subwidgets.push(cwidget); if(cwidget.isContainer){ stack.push(cwidget); } } } //connect event to this widget/attach dom node for(var i = 0; i < subwidgets.length; i++){ var widget = subwidgets[i]; if(widget._processedSubWidgets){ dojo.debug("This should not happen: widget._processedSubWidgets is already true!"); return; } widget._processedSubWidgets = true; if(widget.extraArgs['dojoattachevent']){ var evts = widget.extraArgs['dojoattachevent'].split(";"); for(var j=0; j<evts.length; j++){ var thisFunc = null; var tevt = dojo.string.trim(evts[j]); if(tevt.indexOf(":") >= 0){ // oh, if only JS had tuple assignment var funcNameArr = tevt.split(":"); tevt = dojo.string.trim(funcNameArr[0]); thisFunc = dojo.string.trim(funcNameArr[1]); } if(!thisFunc){ thisFunc = tevt; } if(dojo.lang.isFunction(widget[tevt])){ dojo.event.kwConnect({ srcObj: widget, srcFunc: tevt, targetObj: this, targetFunc: thisFunc }); }else{ alert(tevt+" is not a function in widget "+widget); } } } if(widget.extraArgs['dojoattachpoint']){ //don't attach widget.domNode here, as we do not know which //dom node we should connect to (in checkbox widget case, //it is inputNode). So we make the widget itself available this[widget.extraArgs['dojoattachpoint']] = widget; } } } //dojo.profile.end(this.widgetType + " postInitialize"); // Expand my children widgets /* dojoDontFollow is important for a very special case * basically if you have a widget that you instantiate from script * and that widget is a container, and it contains a reference to a parent * instance, the parser will start recursively parsing until the browser * complains. So the solution is to set an initialization property of * dojoDontFollow: true and then it won't recurse where it shouldn't */ if(this.isContainer && !frag["dojoDontFollow"]){ //alert("recurse from " + this.widgetId); // build any sub-components with us as the parent dojo.widget.getParser().createSubComponents(frag, this); } }, // method over-ride buildRendering: function(/*Object*/args, /*Object*/frag){ // summary: // Construct the UI for this widget, generally from a // template. This can be over-ridden for custom UI creation to // to side-step the template system. This is an // implementation of the stub function defined in // dojo.widget.Widget. // DOM widgets construct themselves from a template var ts = dojo.widget._templateCache[this.widgetType]; // Handle style for this widget here, as even if templatePath // is not set, style specified by templateCssString or templateCssPath // should be applied. templateCssString has higher priority // than templateCssPath if(args["templatecsspath"]){ args["templateCssPath"] = args["templatecsspath"]; } var cpath = args["templateCssPath"] || this.templateCssPath; if(cpath && !dojo.widget._cssFiles[cpath.toString()]){ if((!this.templateCssString)&&(cpath)){ this.templateCssString = dojo.hostenv.getText(cpath); this.templateCssPath = null; } dojo.widget._cssFiles[cpath.toString()] = true; } if((this["templateCssString"])&&(!this.templateCssString["loaded"])){ dojo.html.insertCssText(this.templateCssString, null, cpath); if(!this.templateCssString){ this.templateCssString = ""; } this.templateCssString.loaded = true; } if( (!this.preventClobber)&&( (this.templatePath)|| (this.templateNode)|| ( (this["templateString"])&&(this.templateString.length) )|| ( (typeof ts != "undefined")&&( (ts["string"])||(ts["node"]) ) ) ) ){ // if it looks like we can build the thing from a template, do it! this.buildFromTemplate(args, frag); }else{ // otherwise, assign the DOM node that was the source of the widget // parsing to be the root node this.domNode = this.getFragNodeRef(frag); } this.fillInTemplate(args, frag); // this is where individual widgets // will handle population of data // from properties, remote data // sets, etc. }, buildFromTemplate: function(/*Object*/args, /*Object*/frag){ // summary: // Called by buildRendering, creates the actual UI in a DomWidget. // var start = new Date(); // copy template properties if they're already set in the templates object // dojo.debug("buildFromTemplate:", this); var avoidCache = false; if(args["templatepath"]){ avoidCache = true; args["templatePath"] = args["templatepath"]; } dojo.widget.fillFromTemplateCache( this, args["templatePath"], null, avoidCache); var ts = dojo.widget._templateCache[this.widgetType]; if((ts)&&(!avoidCache)){ if(!this.templateString.length){ this.templateString = ts["string"]; } if(!this.templateNode){ this.templateNode = ts["node"]; } } var matches = false; var node = null; // var tstr = new String(this.templateString); var tstr = this.templateString; // attempt to clone a template node, if there is one if((!this.templateNode)&&(this.templateString)){ matches = this.templateString.match(/\$\{([^\}]+)\}/g); if(matches) { // if we do property replacement, don't create a templateNode // to clone from. var hash = this.strings || {}; // FIXME: should this hash of default replacements be cached in // templateString? for(var key in dojo.widget.defaultStrings) { if(dojo.lang.isUndefined(hash[key])) { hash[key] = dojo.widget.defaultStrings[key]; } } // FIXME: this is a lot of string munging. Can we make it faster? for(var i = 0; i < matches.length; i++) { var key = matches[i]; key = key.substring(2, key.length-1); var kval = (key.substring(0, 5) == "this.") ? dojo.lang.getObjPathValue(key.substring(5), this) : hash[key]; var value; if((kval)||(dojo.lang.isString(kval))){ value = new String((dojo.lang.isFunction(kval)) ? kval.call(this, key, this.templateString) : kval); // Safer substitution, see heading "Attribute values" in // http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2 while (value.indexOf("\"") > -1) { value=value.replace("\"","""); } tstr = tstr.replace(matches[i], value); } } }else{ // otherwise, we are required to instantiate a copy of the template // string if one is provided. // FIXME: need to be able to distinguish here what should be done // or provide a generic interface across all DOM implementations // FIMXE: this breaks if the template has whitespace as its first // characters // node = this.createNodesFromText(this.templateString, true); // this.templateNode = node[0].cloneNode(true); // we're optimistic here this.templateNode = this.createNodesFromText(this.templateString, true)[0]; if(!avoidCache){ ts.node = this.templateNode; } } } if((!this.templateNode)&&(!matches)){ dojo.debug("DomWidget.buildFromTemplate: could not create template"); return false; }else if(!matches){ node = this.templateNode.cloneNode(true); if(!node){ return false; } }else{ node = this.createNodesFromText(tstr, true)[0]; } // recurse through the node, looking for, and attaching to, our // attachment points which should be defined on the template node. this.domNode = node; // dojo.profile.start("attachTemplateNodes"); this.attachTemplateNodes(); // dojo.profile.end("attachTemplateNodes"); // relocate source contents to templated container node // this.containerNode must be able to receive children, or exceptions will be thrown if (this.isContainer && this.containerNode){ var src = this.getFragNodeRef(frag); if (src){ dojo.dom.moveChildren(src, this.containerNode); } } }, attachTemplateNodes: function(/*DomNode*/baseNode, /*Widget*/targetObj){ // summary: // hooks up event handlers and property/node linkages. Calls // dojo.widget.attachTemplateNodes to do all the hard work. // baseNode: defaults to "this.domNode" // targetObj: defaults to "this" if(!baseNode){ baseNode = this.domNode; } if(!targetObj){ targetObj = this; } return dojo.widget.attachTemplateNodes(baseNode, targetObj, dojo.widget.getDojoEventsFromStr(this.templateString)); }, fillInTemplate: function(){ // summary: // stub function! sub-classes may use as a default UI // initializer function. The UI rendering will be available by // the time this is called from buildRendering. If // buildRendering is over-ridden, this function may not be // fired! // dojo.unimplemented("dojo.widget.DomWidget.fillInTemplate"); }, // method over-ride destroyRendering: function(){ // summary: UI destructor try{ delete this.domNode; }catch(e){ /* squelch! */ } }, // FIXME: method over-ride cleanUp: function(){}, getContainerHeight: function(){ // summary: unimplemented! dojo.unimplemented("dojo.widget.DomWidget.getContainerHeight"); }, getContainerWidth: function(){ // summary: unimplemented! dojo.unimplemented("dojo.widget.DomWidget.getContainerWidth"); }, createNodesFromText: function(){ // summary: unimplemented! dojo.unimplemented("dojo.widget.DomWidget.createNodesFromText"); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -