aboutsummaryrefslogtreecommitdiff
path: root/js/document/views
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/views')
-rwxr-xr-xjs/document/views/design.js92
1 files changed, 69 insertions, 23 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 9aeb370a..3d11e138 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -7,7 +7,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 BaseDocumentView = require("js/document/views/base").BaseDocumentView; 10 BaseDocumentView = require("js/document/views/base").BaseDocumentView,
11 ElementModel = require("js/models/element-model");
11//////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////
12// 13//
13exports.DesignDocumentView = Montage.create(BaseDocumentView, { 14exports.DesignDocumentView = Montage.create(BaseDocumentView, {
@@ -23,13 +24,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
23 }, 24 },
24 //////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////
25 // 26 //
26 _template: { 27 _viewCallback: {
27 value: null 28 value: null
28 }, 29 },
29 //////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////
30 // 31 //
31 _document: { 32 _template: {
32 value: null 33 value: null
33 }, 34 },
34 //////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////
35 // 36 //
@@ -52,8 +53,29 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
52 value: null 53 value: null
53 }, 54 },
54 //////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////
55 //TODO: Remove usage 56 //
56 model: { 57 _liveNodeList: {
58 value: null
59 },
60 ////////////////////////////////////////////////////////////////////
61 //
62 _webGlHelper: {
63 value: null
64 },
65 ////////////////////////////////////////////////////////////////////
66 //
67 _baseHref: {
68 value: null
69 },
70 ////////////////////////////////////////////////////////////////////
71 //
72 baseHref: {
73 get: function() {return this._baseHref;},
74 set: function(value) {this._baseHref = value;}
75 },
76 ////////////////////////////////////////////////////////////////////
77 //
78 _document: {
57 value: null 79 value: null
58 }, 80 },
59 //////////////////////////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////
@@ -63,11 +85,17 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
63 set: function(value) {this._document = value;} 85 set: function(value) {this._document = value;}
64 }, 86 },
65 //////////////////////////////////////////////////////////////////// 87 ////////////////////////////////////////////////////////////////////
66 // 88 //
67 _liveNodeList: { 89 _documentRoot: {
68 value: null 90 value: null
69 }, 91 },
70 //////////////////////////////////////////////////////////////////// 92 ////////////////////////////////////////////////////////////////////
93 //
94 documentRoot: {
95 get: function() {return this._documentRoot;},
96 set: function(value) {this._documentRoot = value;}
97 },
98 ////////////////////////////////////////////////////////////////////
71 // 99 //
72 getLiveNodeList: { 100 getLiveNodeList: {
73 value: function(useFilter) { 101 value: function(useFilter) {
@@ -104,12 +132,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
104 //////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////
105 // 133 //
106 render: { 134 render: {
107 value: function (callback, template) { 135 value: function (callback, template, viewCallback) {
108 //TODO: Remove, this is a temp patch for webRequest API gate 136 //TODO: Remove, this is a temp patch for webRequest API gate
109 this.application.ninja.documentController.redirectRequests = false; 137 this.application.ninja.documentController.redirectRequests = false;
110 //Storing callback for dispatch ready 138 //Storing callback for dispatch ready
111 this._callback = callback; 139 this._callback = callback;
112 this._template = template; 140 this._template = template;
141 this._viewCallback = viewCallback;
113 //Adding listener to know when template is loaded to then load user content 142 //Adding listener to know when template is loaded to then load user content
114 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); 143 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false);
115 //TODO: Add source parameter and root (optional) 144 //TODO: Add source parameter and root (optional)
@@ -142,7 +171,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
142 if (basetag.length) { 171 if (basetag.length) {
143 if (basetag[basetag.length-1].getAttribute && basetag[basetag.length-1].getAttribute('href')) { 172 if (basetag[basetag.length-1].getAttribute && basetag[basetag.length-1].getAttribute('href')) {
144 //Setting base HREF in model 173 //Setting base HREF in model
145 this.model.baseHref = basetag[basetag.length-1].getAttribute('href'); 174 this.baseHref = basetag[basetag.length-1].getAttribute('href');
146 } 175 }
147 } 176 }
148 //Checking to content to be template 177 //Checking to content to be template
@@ -154,7 +183,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
154 this._observer.body = new WebKitMutationObserver(this.insertBannerContent.bind(this)); 183 this._observer.body = new WebKitMutationObserver(this.insertBannerContent.bind(this));
155 this._observer.body.observe(this._bodyFragment, {childList: true}); 184 this._observer.body.observe(this._bodyFragment, {childList: true});
156 //Inserting <body> HTML and parsing URLs via mediator method 185 //Inserting <body> HTML and parsing URLs via mediator method
157 this._bodyFragment.innerHTML = '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); 186 this._bodyFragment.innerHTML = '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt));
158 } 187 }
159 } else { 188 } else {
160 //Creating temp code fragement to load head 189 //Creating temp code fragement to load head
@@ -163,12 +192,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
163 this._observer.head = new WebKitMutationObserver(this.insertHeadContent.bind(this)); 192 this._observer.head = new WebKitMutationObserver(this.insertHeadContent.bind(this));
164 this._observer.head.observe(this._headFragment, {childList: true}); 193 this._observer.head.observe(this._headFragment, {childList: true});
165 //Inserting <head> HTML and parsing URLs via mediator method 194 //Inserting <head> HTML and parsing URLs via mediator method
166 this._headFragment.innerHTML = (this.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); 195 this._headFragment.innerHTML = (this.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt));
167 //Adding event listener to know when the body is ready and make callback (using HTML5 new DOM Mutation Events) 196 //Adding event listener to know when the body is ready and make callback (using HTML5 new DOM Mutation Events)
168 this._observer.body = new WebKitMutationObserver(this.bodyContentLoaded.bind(this)); 197 this._observer.body = new WebKitMutationObserver(this.bodyContentLoaded.bind(this));
169 this._observer.body.observe(this.document.body, {childList: true}); 198 this._observer.body.observe(this.document.body, {childList: true});
170 //Inserting <body> HTML and parsing URLs via mediator method 199 //Inserting <body> HTML and parsing URLs via mediator method
171 this.document.body.innerHTML += '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); 200 this.document.body.innerHTML += '<ninjaloadinghack></ninjaloadinghack>'+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt));
172 //Copying attributes to maintain same properties as the <body> 201 //Copying attributes to maintain same properties as the <body>
173 for (var n in this.content.document.body.attributes) { 202 for (var n in this.content.document.body.attributes) {
174 if (this.content.document.body.attributes[n].value) { 203 if (this.content.document.body.attributes[n].value) {
@@ -264,6 +293,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
264 } 293 }
265 } 294 }
266 } 295 }
296
297 // Assign the modelGenerator reference from the template to our own modelGenerator
298 this.document.modelGenerator = ElementModel.modelGenerator;
299
267 //Checking for script tags then parsing check for montage and webgl 300 //Checking for script tags then parsing check for montage and webgl
268 if (scripttags.length > 0) { 301 if (scripttags.length > 0) {
269 //Checking and initializing webGL 302 //Checking and initializing webGL
@@ -272,23 +305,25 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
272 this.initMontage(scripttags); 305 this.initMontage(scripttags);
273 } else { 306 } else {
274 //Else there is not data to parse 307 //Else there is not data to parse
308 if(this._viewCallback) {
309 this._viewCallback.viewCallback.call(this._viewCallback.context);
310 }
275 } 311 }
276 //TODO: Verify appropiate location for this operation 312 //TODO: Verify appropiate location for this operation
277 if (this._template && this._template.type === 'banner') { 313 if (this._template && this._template.type === 'banner') {
278 this.model.documentRoot = this.document.body.getElementsByTagName('ninja-content')[0]; 314 this.documentRoot = this.document.body.getElementsByTagName('ninja-content')[0];
279 } else { 315 } else {
280 this.model.documentRoot = this.document.body; 316 this.documentRoot = this.document.body;
281 } 317 }
282 //Storing node list for reference (might need to store in the model) 318 //Storing node list for reference (might need to store in the model)
283 this._liveNodeList = this.model.documentRoot.getElementsByTagName('*'); 319 this._liveNodeList = this.documentRoot.getElementsByTagName('*');
284 //Getting list of original nodes 320 //Getting list of original nodes
285 orgNodes = this.document.getElementsByTagName('*'); 321 orgNodes = this.document.getElementsByTagName('*');
286 //TODO: Figure out if this is ideal for identifying nodes created by Ninja 322 //TODO: Figure out if this is ideal for identifying nodes created by Ninja
287 for (var n in orgNodes) { 323 for (var n in orgNodes) {
288 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); 324 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true');
289 } 325 }
290 //Initiliazing document model 326
291 document.application.njUtils.makeElementModel(this.model.documentRoot, "Body", "body");
292 //Makign callback if specified 327 //Makign callback if specified
293 if (this._callback) this._callback(); 328 if (this._callback) this._callback();
294 } 329 }
@@ -358,8 +393,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
358 value: function (scripttags) { 393 value: function (scripttags) {
359 // 394 //
360 var n, webgldata, fileRead; 395 var n, webgldata, fileRead;
361 //Setting the iFrame property for reference in helper class
362 this.model.webGlHelper.iframe = this.model.views.design.iframe;
363 //Checking for webGL Data 396 //Checking for webGL Data
364 for (var w in scripttags) {