📄 domwidget.js
字号:
cn = dojo.body(); } ref = cn.lastChild; } if (!insertIndex) { insertIndex = 0; } widget.domNode.setAttribute("dojoinsertionindex", insertIndex); if (!ref) { cn.appendChild(widget.domNode); } else { if (pos == "insertAtIndex") { dojo.dom.insertAtIndex(widget.domNode, ref.parentNode, insertIndex); } else { if ((pos == "after") && (ref === cn.lastChild)) { cn.appendChild(widget.domNode); } else { dojo.dom.insertAtPosition(widget.domNode, cn, pos); } } }}, registerChild:function (widget, insertionIndex) { widget.dojoInsertionIndex = insertionIndex; var idx = -1; for (var i = 0; i < this.children.length; i++) { if (this.children[i].dojoInsertionIndex <= insertionIndex) { idx = i; } } this.children.splice(idx + 1, 0, widget); widget.parent = this; widget.addedTo(this, idx + 1); delete dojo.widget.manager.topWidgets[widget.widgetId];}, removeChild:function (widget) { dojo.dom.removeNode(widget.domNode); return dojo.widget.DomWidget.superclass.removeChild.call(this, widget);}, getFragNodeRef:function (frag) { if (!frag) { return null; } if (!frag[this.getNamespacedType()]) { dojo.raise("Error: no frag for widget type " + this.getNamespacedType() + ", id " + this.widgetId + " (maybe a widget has set it's type incorrectly)"); } return frag[this.getNamespacedType()]["nodeRef"];}, postInitialize:function (args, frag, parentComp) { var sourceNodeRef = this.getFragNodeRef(frag); if (parentComp && (parentComp.snarfChildDomOutput || !sourceNodeRef)) { parentComp.addWidgetAsDirectChild(this, "", "insertAtIndex", "", args["dojoinsertionindex"], sourceNodeRef); } else { if (sourceNodeRef) { if (this.domNode && (this.domNode !== sourceNodeRef)) { this._sourceNodeRef = dojo.dom.replaceNode(sourceNodeRef, this.domNode); } } } if (parentComp) { parentComp.registerChild(this, args.dojoinsertionindex); } else { dojo.widget.manager.topWidgets[this.widgetId] = this; } if (this.widgetsInTemplate) { var parser = new dojo.xml.Parse(); var subContainerNode; var subnodes = this.domNode.getElementsByTagName("*"); for (var i = 0; i < subnodes.length; i++) { if (subnodes[i].getAttribute("dojoAttachPoint") == "subContainerWidget") { subContainerNode = subnodes[i]; } if (subnodes[i].getAttribute("dojoType")) { subnodes[i].setAttribute("isSubWidget", true); } } if (this.isContainer && !this.containerNode) { if (subContainerNode) { var src = this.getFragNodeRef(frag); if (src) { dojo.dom.moveChildren(src, subContainerNode); 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); dojo.widget.getParser().createSubComponents(templatefrag, this); 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); } } } 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) { 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"]) { this[widget.extraArgs["dojoattachpoint"]] = widget; } } } if (this.isContainer && !frag["dojoDontFollow"]) { dojo.widget.getParser().createSubComponents(frag, this); }}, buildRendering:function (args, frag) { var ts = dojo.widget._templateCache[this.widgetType]; 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"]) && (!dojo.widget._cssStrings[this.templateCssString])) { dojo.html.insertCssText(this.templateCssString, null, cpath); dojo.widget._cssStrings[this.templateCssString] = true; } if ((!this.preventClobber) && ((this.templatePath) || (this.templateNode) || ((this["templateString"]) && (this.templateString.length)) || ((typeof ts != "undefined") && ((ts["string"]) || (ts["node"]))))) { this.buildFromTemplate(args, frag); } else { this.domNode = this.getFragNodeRef(frag); } this.fillInTemplate(args, frag);}, buildFromTemplate:function (args, frag) { var avoidCache = false; if (args["templatepath"]) { args["templatePath"] = args["templatepath"]; } dojo.widget.fillFromTemplateCache(this, args["templatePath"], null, avoidCache); var ts = dojo.widget._templateCache[this.templatePath ? this.templatePath.toString() : 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 = this.templateString; if ((!this.templateNode) && (this.templateString)) { matches = this.templateString.match(/\$\{([^\}]+)\}/g); if (matches) { var hash = this.strings || {}; for (var key in dojo.widget.defaultStrings) { if (dojo.lang.isUndefined(hash[key])) { hash[key] = dojo.widget.defaultStrings[key]; } } 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); while (value.indexOf("\"") > -1) { value = value.replace("\"", """); } tstr = tstr.replace(matches[i], value); } } } else { 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]; } } this.domNode = node; this.attachTemplateNodes(); if (this.isContainer && this.containerNode) { var src = this.getFragNodeRef(frag); if (src) { dojo.dom.moveChildren(src, this.containerNode); } }}, attachTemplateNodes:function (baseNode, targetObj) { if (!baseNode) { baseNode = this.domNode; } if (!targetObj) { targetObj = this; } return dojo.widget.attachTemplateNodes(baseNode, targetObj, dojo.widget.getDojoEventsFromStr(this.templateString));}, fillInTemplate:function () {}, destroyRendering:function () { try { dojo.dom.destroyNode(this.domNode); delete this.domNode; } catch (e) { } if (this._sourceNodeRef) { try { dojo.dom.destroyNode(this._sourceNodeRef); } catch (e) { } }}, createNodesFromText:function () { dojo.unimplemented("dojo.widget.DomWidget.createNodesFromText");}});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -