diff options
author | Armen Kesablyan | 2012-05-15 16:34:46 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-05-15 16:34:46 -0700 |
commit | c8d61c8e72e0eba266575f9df54325fa77fde73d (patch) | |
tree | 556cafd76ab9b2cf4cc2b4cc3ea17b12ce690b69 /js/document/models | |
parent | 15a3aaebb56cb2c9409bfe55c862868726c7fd44 (diff) | |
parent | 46bd3712329cd3c9311e50ed9ee4c2245bd1be5a (diff) | |
download | ninja-c8d61c8e72e0eba266575f9df54325fa77fde73d.tar.gz |
Merge branch 'dom-architecture' of github.com:Motorola-Mobility/ninja-internal into binding
Diffstat (limited to 'js/document/models')
-rwxr-xr-x | js/document/models/base.js | 127 | ||||
-rwxr-xr-x | js/document/models/html.js | 28 |
2 files changed, 141 insertions, 14 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js index 746922ad..5f2a5893 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -62,55 +62,154 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
62 | }, | 62 | }, |
63 | //////////////////////////////////////////////////////////////////// | 63 | //////////////////////////////////////////////////////////////////// |
64 | // | 64 | // |
65 | fileTemplate: { | ||
66 | value: null | ||
67 | }, | ||
68 | //////////////////////////////////////////////////////////////////// | ||
69 | // | ||
70 | parentContainer: { | ||
71 | value: null | ||
72 | }, | ||
73 | //////////////////////////////////////////////////////////////////// | ||
74 | // | ||
65 | views: { | 75 | views: { |
66 | value: null | 76 | value: null |
67 | }, | 77 | }, |
68 | //////////////////////////////////////////////////////////////////// | 78 | //////////////////////////////////////////////////////////////////// |
69 | // | 79 | // |
70 | switchViewTo: { | 80 | switchViewTo: { |
71 | value: function () { | 81 | value: function (view) { |
72 | // | 82 | // |
73 | } | 83 | } |
74 | }, | 84 | }, |
75 | //////////////////////////////////////////////////////////////////// | 85 | //////////////////////////////////////////////////////////////////// |
76 | // | 86 | //TODO: Add API to allow other browser support |
77 | browserPreview: { | 87 | browserPreview: { |
78 | value: function (browser) { | 88 | value: function (browser) { |
79 | // | 89 | //Generating URL for document |
80 | switch (browser) { | 90 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; |
81 | case 'chrome': | 91 | //TODO: Add logic to prompt user to save (all) before preview |
82 | break; | 92 | this.saveAll(function (result) { |
83 | default: | 93 | //Currently only supporting current browser (Chrome, obviously) |
84 | break; | 94 | switch (this.browser) { |
85 | } | 95 | case 'chrome': |
96 | window.open(this.url); | ||
97 | break; | ||
98 | default: | ||
99 | window.open(this.url); | ||
100 | break; | ||
101 | } | ||
102 | }.bind({browser: browser, url: url})); | ||
86 | } | 103 | } |
87 | }, | 104 | }, |
88 | //////////////////////////////////////////////////////////////////// | 105 | //////////////////////////////////////////////////////////////////// |
89 | // | 106 | // |
107 | getStyleSheets: { | ||
108 | value: function () { | ||
109 | // | ||
110 | var styles = []; | ||
111 | // | ||
112 | for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { | ||
113 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { | ||
114 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { | ||
115 | styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | // | ||
120 | return styles; | ||
121 | } | ||
122 | }, | ||
123 | //////////////////////////////////////////////////////////////////// | ||
124 | // | ||
90 | save: { | 125 | save: { |
91 | value: function () { | 126 | value: function (callback) { |
127 | // | ||
128 | if (this.needsSave) { | ||
129 | //Save | ||
130 | } else { | ||
131 | //Ignore command | ||
132 | } | ||
92 | // | 133 | // |
134 | if (this.currentView === this.views.design) { | ||
135 | // | ||
136 | this.application.ninja.ioMediator.fileSave({ | ||
137 | mode: 'html', | ||
138 | file: this.file, | ||
139 | webgl: this.webGlHelper.glData, | ||
140 | styles: this.getStyleSheets(), | ||
141 | template: this.fileTemplate, | ||
142 | document: this.views.design.iframe.contentWindow.document, | ||
143 | head: this.views.design.iframe.contentWindow.document.head, | ||
144 | body: this.views.design.iframe.contentWindow.document.body | ||
145 | }, callback.bind(this)); | ||
146 | } else { | ||
147 | //TODO: Add logic to save code view data | ||
148 | } | ||
93 | } | 149 | } |
94 | }, | 150 | }, |
95 | //////////////////////////////////////////////////////////////////// | 151 | //////////////////////////////////////////////////////////////////// |
96 | // | 152 | // |
97 | saveAs: { | 153 | saveAll: { |
98 | value: function () { | 154 | value: function (callback) { |
155 | // | ||
156 | if (this.needsSave) { | ||
157 | //Save | ||
158 | } else { | ||
159 | //Ignore command | ||
160 | } | ||
99 | // | 161 | // |
162 | if (this.currentView === this.views.design) { | ||
163 | // | ||
164 | this.application.ninja.ioMediator.fileSave({ | ||
165 | mode: 'html', | ||
166 | file: this.file, | ||
167 | webgl: this.webGlHelper.glData, | ||
168 | css: this.getStyleSheets(), | ||
169 | template: this.fileTemplate, | ||
170 | document: this.views.design.iframe.contentWindow.document, | ||
171 | head: this.views.design.iframe.contentWindow.document.head, | ||
172 | body: this.views.design.iframe.contentWindow.document.body | ||
173 | }, callback.bind(this)); | ||
174 | } else { | ||
175 | //TODO: Add logic to save code view data | ||
176 | } | ||
177 | |||
100 | } | 178 | } |
101 | }, | 179 | }, |
102 | //////////////////////////////////////////////////////////////////// | 180 | //////////////////////////////////////////////////////////////////// |
103 | // | 181 | // |
104 | saveAll: { | 182 | saveAs: { |
105 | value: function () { | 183 | value: function () { |
106 | // | 184 | // |
185 | if (this.needsSave) { | ||
186 | //Save current file on memory | ||
187 | } else { | ||
188 | //Copy file from disk | ||
189 | } | ||
107 | } | 190 | } |
108 | }, | 191 | }, |
109 | //////////////////////////////////////////////////////////////////// | 192 | //////////////////////////////////////////////////////////////////// |
110 | // | 193 | // |
111 | close: { | 194 | close: { |
112 | value: function () { | 195 | value: function (view, callback) { |
196 | //Outcome of close (pending on save logic) | ||
197 | var success; | ||
198 | // | ||
199 | if (this.needsSave) { | ||
200 | //Prompt user to save of lose data | ||
201 | } else { | ||
202 | //Close file | ||
203 | success = true; | ||
204 | } | ||
205 | // | ||
206 | if (this.views.design && (!view || view === 'design')) { | ||
207 | // | ||
208 | this.parentContainer.removeChild(this.views.design.iframe); | ||
209 | this.views.design = null; | ||
210 | } | ||
113 | // | 211 | // |
212 | if (callback) callback(success); | ||
114 | } | 213 | } |
115 | } | 214 | } |
116 | //////////////////////////////////////////////////////////////////// | 215 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/document/models/html.js b/js/document/models/html.js index 1639a8e2..b57ff832 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js | |||
@@ -24,8 +24,36 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { | |||
24 | }, | 24 | }, |
25 | //////////////////////////////////////////////////////////////////// | 25 | //////////////////////////////////////////////////////////////////// |
26 | // | 26 | // |
27 | baseHref: { | ||
28 | value: null | ||
29 | }, | ||
30 | //////////////////////////////////////////////////////////////////// | ||
31 | // | ||
27 | webGlHelper: { | 32 | webGlHelper: { |
28 | value: webGlDocumentHelper | 33 | value: webGlDocumentHelper |
34 | }, | ||
35 | //////////////////////////////////////////////////////////////////// | ||
36 | // | ||
37 | userComponents: { | ||
38 | value: {} | ||
39 | }, | ||
40 | //////////////////////////////////////////////////////////////////// | ||
41 | //Add a reference to a component instance to the userComponents hash using the element UUID | ||
42 | setComponentInstance: { | ||
43 | value: function(instance, el) { | ||
44 | this.userComponents[el.uuid] = instance; | ||
45 | } | ||
46 | }, | ||
47 | //////////////////////////////////////////////////////////////////// | ||
48 | //Returns the component instance obj from the element | ||
49 | getComponentFromElement: { | ||
50 | value: function(el) { | ||
51 | if(el) { | ||
52 | if(el.uuid) return this.userComponents[el.uuid]; | ||
53 | } else { | ||
54 | return null; | ||
55 | } | ||
56 | } | ||
29 | } | 57 | } |
30 | //////////////////////////////////////////////////////////////////// | 58 | //////////////////////////////////////////////////////////////////// |
31 | //////////////////////////////////////////////////////////////////// | 59 | //////////////////////////////////////////////////////////////////// |