1 | define([ |
---|
2 | "dojo/_base/kernel", |
---|
3 | "dojo/_base/array", |
---|
4 | "dojo/_base/declare", |
---|
5 | "dojo/_base/Deferred", |
---|
6 | "dojo/dom-class", |
---|
7 | "dojo/dom-construct", |
---|
8 | "dijit/registry", |
---|
9 | "../lazyLoadUtils" |
---|
10 | ], function(dojo, array, declare, Deferred, domClass, domConstruct, registry, lazyLoadUtils){ |
---|
11 | |
---|
12 | // module: |
---|
13 | // dojox/mobile/dh/HtmlContentHandler |
---|
14 | |
---|
15 | return declare("dojox.mobile.dh.HtmlContentHandler", null, { |
---|
16 | // summary: |
---|
17 | // A HTML content handler. |
---|
18 | // description: |
---|
19 | // This module is a content handler that creates a view from HTML |
---|
20 | // data. If widgets used in the HTML data are not available, they |
---|
21 | // are loaded automatically before instantiation. |
---|
22 | |
---|
23 | parse: function(/*String*/ content, /*DomNode*/ target, /*DomNode?*/ refNode){ |
---|
24 | // summary: |
---|
25 | // Parses the given data and creates a new view at the given position. |
---|
26 | // content: |
---|
27 | // Content data for a new view. |
---|
28 | // target: |
---|
29 | // A DOM node under which a new view is created. |
---|
30 | // refNode: |
---|
31 | // An optional reference DOM node before which a new view is created. |
---|
32 | if(this.execScript){ |
---|
33 | content = this.execScript(content); |
---|
34 | } |
---|
35 | var container = domConstruct.create("div", { |
---|
36 | innerHTML: content, |
---|
37 | style: {visibility: "hidden"} |
---|
38 | }); |
---|
39 | target.insertBefore(container, refNode); |
---|
40 | |
---|
41 | return Deferred.when(lazyLoadUtils.instantiateLazyWidgets(container), function(){ |
---|
42 | // allows multiple root nodes in the fragment, |
---|
43 | // but transition will be performed to the 1st view. |
---|
44 | var view; |
---|
45 | for(i = 0, len = container.childNodes.length; i < len; i++){ |
---|
46 | var n = container.firstChild; |
---|
47 | if(!view && n.nodeType === 1){ |
---|
48 | view = registry.byNode(n); |
---|
49 | } |
---|
50 | target.insertBefore(container.firstChild, refNode); // reparent |
---|
51 | } |
---|
52 | target.removeChild(container); |
---|
53 | if(!view || !domClass.contains(view.domNode, "mblView")){ |
---|
54 | console.log("HtmlContentHandler.parse: invalid view content"); |
---|
55 | return null; |
---|
56 | } |
---|
57 | return view.id; |
---|
58 | }); |
---|
59 | } |
---|
60 | }); |
---|
61 | }); |
---|