123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688 |
- define(
- "dojo/parser", ["./_base/kernel", "./_base/lang", "./_base/array", "./_base/config", "./_base/html", "./_base/window", "./_base/url",
- "./_base/json", "./aspect", "./date/stamp", "./has", "./query", "./on", "./ready"],
- function(dojo, dlang, darray, config, dhtml, dwindow, _Url, djson, aspect, dates, has, query, don, ready){
- new Date("X");
- if (1) {
- var form = document.createElement("form");
-
- has.add("dom-attributes-explicit", form.attributes.length == 0);
-
-
- has.add("dom-attributes-specified-flag", form.attributes.length < 40);
-
- }
- dojo.parser = new function(){
-
-
- var _nameMap = {
-
-
-
-
-
-
- };
- function getNameMap(proto){
-
-
- var map = {};
- for(var name in proto){
- if(name.charAt(0)=="_"){ continue; }
- map[name.toLowerCase()] = name;
- }
- return map;
- }
-
-
-
- aspect.after(dlang, "extend", function(){
- _nameMap = {};
- }, true);
-
-
- var _ctorMap = {};
- function getCtor(type){
- var map = _ctorMap[type] || (_ctorMap[type] = {});
- return map["__type"] || (map["__type"] = (dlang.getObject(type) || require(type)));
- }
- this._functionFromScript = function(script, attrData){
-
-
-
-
-
-
-
-
- var preamble = "";
- var suffix = "";
- var argsStr = (script.getAttribute(attrData + "args") || script.getAttribute("args"));
- if(argsStr){
- darray.forEach(argsStr.split(/\s*,\s*/), function(part, idx){
- preamble += "var "+part+" = arguments["+idx+"]; ";
- });
- }
- var withStr = script.getAttribute("with");
- if(withStr && withStr.length){
- darray.forEach(withStr.split(/\s*,\s*/), function(part){
- preamble += "with("+part+"){";
- suffix += "}";
- });
- }
- return new Function(preamble+script.innerHTML+suffix);
- };
- this.instantiate = function(nodes, mixin, options) {
-
-
-
-
-
-
-
-
-
-
-
-
-
- mixin = mixin || {};
- options = options || {};
- var dojoType = (options.scope || dojo._scopeName) + "Type",
- attrData = "data-" + (options.scope || dojo._scopeName) + "-",
- dataDojoType = attrData + "type";
- var list = [];
- darray.forEach(nodes, function(node){
- var type = dojoType in mixin ? mixin[dojoType] : node.getAttribute(dataDojoType) || node.getAttribute(dojoType);
- if(type){
- list.push({
- node: node,
- "type": type
- });
- }
- });
-
- return this._instantiate(list, mixin, options);
- };
- this._instantiate = function(nodes, mixin, options){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var thelist = [];
-
-
- var dojoType = (options.scope || dojo._scopeName) + "Type",
- attrData = "data-" + (options.scope || dojo._scopeName) + "-",
- dataDojoType = attrData + "type",
- dataDojoProps = attrData + "props",
- dataDojoAttachPoint = attrData + "attach-point",
- dataDojoAttachEvent = attrData + "attach-event",
- dataDojoId = attrData + "id",
- dataDojoMixins = attrData + "mixins";
-
- var specialAttrs = {};
- darray.forEach([dataDojoProps, dataDojoType, dojoType, dataDojoId, "jsId", dataDojoAttachPoint,
- dataDojoAttachEvent, "dojoAttachPoint", "dojoAttachEvent", "class", "style", dataDojoMixins], function(name){
- specialAttrs[name.toLowerCase()] = name.replace(options.scope, "dojo");
- });
- function extend(type, mixins){
- return type.createSubclass && type.createSubclass(mixins) || type.extend.apply(type, mixins);
- }
- darray.forEach(nodes, function(obj){
- if(!obj){ return; }
- var node = obj.node,
- type = obj.type,
- mixins = node.getAttribute(dataDojoMixins), ctor;
- if(mixins){
- var map = _ctorMap[type];
-
- mixins = mixins.replace(/ /g, "");
- ctor = map && map[mixins];
- if(!ctor){
-
- ctor = getCtor(type);
-
- ctor = _ctorMap[type][mixins] = extend(ctor, darray.map(mixins.split(","), getCtor));
- }
- }else{
- ctor = getCtor(type);
- }
- var proto = ctor && ctor.prototype;
-
-
-
- var params = {};
- if(options.defaults){
-
- dlang.mixin(params, options.defaults);
- }
- if(obj.inherited){
-
- dlang.mixin(params, obj.inherited);
- }
-
- var attributes;
- if(has("dom-attributes-explicit")){
-
- attributes = node.attributes;
- }else if(has("dom-attributes-specified-flag")){
-
- attributes = darray.filter(node.attributes, function(a){ return a.specified;});
- }else{
-
- var clone = /^input$|^img$/i.test(node.nodeName) ? node : node.cloneNode(false),
- attrs = clone.outerHTML.replace(/=[^\s"']+|="[^"]*"|='[^']*'/g, "").replace(/^\s*<[a-zA-Z0-9]*\s*/, "").replace(/\s*>.*$/, "");
- attributes = darray.map(attrs.split(/\s+/), function(name){
- var lcName = name.toLowerCase();
- return {
- name: name,
-
-
- value: (node.nodeName == "LI" && name == "value") || lcName == "enctype" ?
- node.getAttribute(lcName) : node.getAttributeNode(lcName).value
- };
- });
- }
-
-
- var i=0, item;
- while(item = attributes[i++]){
- var name = item.name,
- lcName = name.toLowerCase(),
- value = item.value;
- if(lcName in specialAttrs){
- switch(specialAttrs[lcName]){
-
- case "data-dojo-props":
- var extra = value;
- break;
-
- case "data-dojo-id":
- case "jsId":
- var jsname = value;
- break;
-
- case "data-dojo-attach-point":
- case "dojoAttachPoint":
- params.dojoAttachPoint = value;
- break;
- case "data-dojo-attach-event":
- case "dojoAttachEvent":
- params.dojoAttachEvent = value;
- break;
-
- case "class":
- params["class"] = node.className;
- break;
- case "style":
- params["style"] = node.style && node.style.cssText;
- break;
- }
- }else{
-
-
-
- if(!(name in proto)){
- var map = (_nameMap[type] || (_nameMap[type] = getNameMap(proto)));
- name = map[lcName] || name;
- }
-
- if(name in proto){
- switch(typeof proto[name]){
- case "string":
- params[name] = value;
- break;
- case "number":
- params[name] = value.length ? Number(value) : NaN;
- break;
- case "boolean":
-
- params[name] = value.toLowerCase() != "false";
- break;
- case "function":
- if(value === "" || value.search(/[^\w\.]+/i) != -1){
-
- params[name] = new Function(value);
- }else{
-
-
- params[name] = dlang.getObject(value, false) || new Function(value);
- }
- break;
- default:
- var pVal = proto[name];
- params[name] =
- (pVal && "length" in pVal) ? (value ? value.split(/\s*,\s*/) : []) :
- (pVal instanceof Date) ?
- (value == "" ? new Date("") :
- value == "now" ? new Date() :
- dates.fromISOString(value)) :
- (pVal instanceof dojo._Url) ? (dojo.baseUrl + value) :
- djson.fromJson(value);
- }
- }else{
- params[name] = value;
- }
- }
- }
-
- if(extra){
- try{
- extra = djson.fromJson.call(options.propsThis, "{" + extra + "}");
- dlang.mixin(params, extra);
- }catch(e){
-
- throw new Error(e.toString() + " in data-dojo-props='" + extra + "'");
- }
- }
-
- dlang.mixin(params, mixin);
- var scripts = obj.scripts || (ctor && (ctor._noScript || proto._noScript) ? [] :
- query("> script[type^='dojo/']", node));
-
-
-
-
-
-
-
-
- var connects = [],
- calls = [],
- watch = [],
- on = [];
- if(scripts){
- for(i=0; i<scripts.length; i++){
- var script = scripts[i];
- node.removeChild(script);
-
- var event = (script.getAttribute(attrData + "event") || script.getAttribute("event")),
- prop = script.getAttribute(attrData + "prop"),
- scriptType = script.getAttribute("type"),
- nf = this._functionFromScript(script, attrData);
- if(event){
- if(scriptType == "dojo/connect"){
- connects.push({event: event, func: nf});
- }else if(scriptType == "dojo/on"){
- on.push({event: event, func: nf});
- }else{
- params[event] = nf;
- }
- }else if(scriptType == "dojo/watch"){
- watch.push({prop: prop, func: nf});
- }else{
- calls.push(nf);
- }
- }
- }
-
- var markupFactory = ctor.markupFactory || proto.markupFactory;
- var instance = markupFactory ? markupFactory(params, node, ctor) : new ctor(params, node);
- thelist.push(instance);
-
- if(jsname){
- dlang.setObject(jsname, instance);
- }
-
- for(i=0; i<connects.length; i++){
- aspect.after(instance, connects[i].event, dojo.hitch(instance, connects[i].func), true);
- }
- for(i=0; i<calls.length; i++){
- calls[i].call(instance);
- }
- for(i=0; i<watch.length; i++){
- instance.watch(watch[i].prop, watch[i].func);
- }
- for(i=0; i<on.length; i++){
- don(instance, on[i].event, on[i].func);
- }
- }, this);
-
-
-
- if(!mixin._started){
- darray.forEach(thelist, function(instance){
- if( !options.noStart && instance &&
- dlang.isFunction(instance.startup) &&
- !instance._started
- ){
- instance.startup();
- }
- });
- }
- return thelist;
- };
- this.scan = function(root, options){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var list = [];
- var dojoType = (options.scope || dojo._scopeName) + "Type",
- attrData = "data-" + (options.scope || dojo._scopeName) + "-",
- dataDojoType = attrData + "type",
- dataDojoTextDir = attrData + "textdir";
-
- var node = root.firstChild;
-
-
-
-
- var inherited = options.inherited;
- if(!inherited){
- function findAncestorAttr(node, attr){
- return (node.getAttribute && node.getAttribute(attr)) ||
- (node !== dwindow.doc && node !== dwindow.doc.documentElement && node.parentNode ? findAncestorAttr(node.parentNode, attr) : null);
- }
- inherited = {
- dir: findAncestorAttr(root, "dir"),
- lang: findAncestorAttr(root, "lang"),
- textDir: findAncestorAttr(root, dataDojoTextDir)
- };
- for(var key in inherited){
- if(!inherited[key]){ delete inherited[key]; }
- }
- }
- var parent = {
- inherited: inherited
- };
-
- var scripts;
-
- var scriptsOnly;
- function getEffective(parent){
-
-
-
-
- if(!parent.inherited){
- parent.inherited = {};
- var node = parent.node,
- grandparent = getEffective(parent.parent);
- var inherited = {
- dir: node.getAttribute("dir") || grandparent.dir,
- lang: node.getAttribute("lang") || grandparent.lang,
- textDir: node.getAttribute(dataDojoTextDir) || grandparent.textDir
- };
- for(var key in inherited){
- if(inherited[key]){
- parent.inherited[key] = inherited[key];
- }
- }
- }
- return parent.inherited;
- }
-
- while(true){
- if(!node){
-
- if(!parent || !parent.node){
- break;
- }
- node = parent.node.nextSibling;
- scripts = parent.scripts;
- scriptsOnly = false;
- parent = parent.parent;
- continue;
- }
- if(node.nodeType != 1){
-
- node = node.nextSibling;
- continue;
- }
- if(scripts && node.nodeName.toLowerCase() == "script"){
-
- type = node.getAttribute("type");
- if(type && /^dojo\/\w/i.test(type)){
- scripts.push(node);
- }
- node = node.nextSibling;
- continue;
- }
- if(scriptsOnly){
- node = node.nextSibling;
- continue;
- }
-
- var type = node.getAttribute(dataDojoType) || node.getAttribute(dojoType);
-
- var firstChild = node.firstChild;
- if(!type && (!firstChild || (firstChild.nodeType == 3 && !firstChild.nextSibling))){
- node = node.nextSibling;
- continue;
- }
-
- var current = {
- node: node,
- scripts: scripts,
- parent: parent
- };
-
-
-
- var ctor;
- try{
- ctor = type && getCtor(type);
- }catch(e){
- }
- var childScripts = ctor && !ctor.prototype._noScript ? [] : null;
- if(type){
- list.push({
- "type": type,
- node: node,
- scripts: childScripts,
- inherited: getEffective(current)
- });
- }
-
-
-
- node = firstChild;
- scripts = childScripts;
- scriptsOnly = ctor && ctor.prototype.stopParser && !(options.template);
- parent = current;
- }
- return list;
- };
- this.parse = function(rootNode, options){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var root;
- if(!options && rootNode && rootNode.rootNode){
- options = rootNode;
- root = options.rootNode;
- }else if(rootNode && dlang.isObject(rootNode) && !("nodeType" in rootNode)){
- options = rootNode;
- }else{
- root = rootNode;
- }
- root = root ? dhtml.byId(root) : dwindow.body();
- options = options || {};
-
- var list = this.scan(root, options);
-
- var mixin = options.template ? {template: true} : {};
- return this._instantiate(list, mixin, options);
- };
- }();
- if(config.parseOnLoad){
- ready(100, dojo.parser, "parse");
- }
- return dojo.parser;
- });
|