1 | define([ |
---|
2 | "require", |
---|
3 | "dojo/_base/kernel", |
---|
4 | "dojo/_base/lang", |
---|
5 | "dojo/has!dojo-parser?:dojo/_base/window", |
---|
6 | "dojo/has", |
---|
7 | "dojo/has!dojo-mobile-parser?:dojo/parser", |
---|
8 | "dojo/has!dojo-parser?:dojox/mobile/parser", |
---|
9 | "dojox/mvc/_atBindingMixin", |
---|
10 | "dojox/mvc/Element" |
---|
11 | ], function(require, kernel, lang, win, has, parser, mobileParser, _atBindingMixin){ |
---|
12 | |
---|
13 | // module: |
---|
14 | // dojox/mvc/parserExtension |
---|
15 | // summary: |
---|
16 | // A extension of Dojo parser that allows data binding without specifying data-dojo-type. |
---|
17 | |
---|
18 | has.add("dom-qsa", !!document.createElement("div").querySelectorAll); |
---|
19 | try{ has.add("dojo-parser", !!require("dojo/parser")); }catch(e){} |
---|
20 | try{ has.add("dojo-mobile-parser", !!require("dojox/mobile/parser")); }catch(e){} |
---|
21 | |
---|
22 | if(has("dojo-parser")){ |
---|
23 | var oldScan = parser.scan; |
---|
24 | |
---|
25 | parser.scan = function(/*DOMNode?*/ root, /*Object*/ options){ |
---|
26 | // summary: |
---|
27 | // Find list of DOM nodes that has data-dojo-bind, but not data-dojo-type. |
---|
28 | // And add them to list of DOM nodes to instantiate widget (dojox/mvc/Element). |
---|
29 | |
---|
30 | return oldScan.apply(this, lang._toArray(arguments)).then(function(list){ |
---|
31 | var dojoType = (options.scope || kernel._scopeName) + "Type", // typically "dojoType" |
---|
32 | attrData = "data-" + (options.scope || kernel._scopeName) + "-", // typically "data-dojo-" |
---|
33 | dataDojoType = attrData + "type"; // typically "data-dojo-type" |
---|
34 | |
---|
35 | for(var nodes = has("dom-qsa") ? root.querySelectorAll("[" + _atBindingMixin.prototype.dataBindAttr + "]") : root.getElementsByTagName("*"), i = 0, l = nodes.length; i < l; i++){ |
---|
36 | var node = nodes[i], foundBindingInAttribs = false; |
---|
37 | if(!node.getAttribute(dataDojoType) && !node.getAttribute(dojoType) && node.getAttribute(_atBindingMixin.prototype.dataBindAttr)){ |
---|
38 | list.push({ |
---|
39 | types: ["dojox/mvc/Element"], |
---|
40 | node: node |
---|
41 | }); |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | return list; |
---|
46 | }); |
---|
47 | }; |
---|
48 | } |
---|
49 | |
---|
50 | if(has("dojo-mobile-parser")){ |
---|
51 | var oldParse = mobileParser.parse; |
---|
52 | |
---|
53 | mobileParser.parse = function(/*DOMNode?*/ root, /*Object*/ options){ |
---|
54 | // summary: |
---|
55 | // Find list of DOM nodes that has data-dojo-bind, but not data-dojo-type. |
---|
56 | // Set dojox/mvc/Element to their data-dojo-type. |
---|
57 | |
---|
58 | var dojoType = ((options || {}).scope || kernel._scopeName) + "Type", // typically "dojoType" |
---|
59 | attrData = "data-" + ((options || {}).scope || kernel._scopeName) + "-", // typically "data-dojo-" |
---|
60 | dataDojoType = attrData + "type"; // typically "data-dojo-type" |
---|
61 | nodes = has("dom-qsa") ? (root || win.body()).querySelectorAll("[" + _atBindingMixin.prototype.dataBindAttr + "]") : (root || win.body()).getElementsByTagName("*"); |
---|
62 | |
---|
63 | for(var i = 0, l = nodes.length; i < l; i++){ |
---|
64 | var node = nodes[i], foundBindingInAttribs = false, bindingsInAttribs = []; |
---|
65 | if(!node.getAttribute(dataDojoType) && !node.getAttribute(dojoType) && node.getAttribute(_atBindingMixin.prototype.dataBindAttr)){ |
---|
66 | node.setAttribute(dataDojoType, "dojox/mvc/Element"); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | return oldParse.apply(this, lang._toArray(arguments)); |
---|
71 | }; |
---|
72 | } |
---|
73 | |
---|
74 | return parser || mobileParser; |
---|
75 | }); |
---|