aboutsummaryrefslogtreecommitdiff
path: root/js/document/views/design.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/views/design.js')
-rwxr-xr-xjs/document/views/design.js644
1 files changed, 322 insertions, 322 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index ed98b660..c7f57e58 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -30,50 +30,50 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31//////////////////////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////////////////////
32// 32//
33var Montage = require("montage/core/core").Montage, 33var Montage = require("montage/core/core").Montage,
34 BaseDocumentView = require("js/document/views/base").BaseDocumentView, 34 BaseDocumentView = require("js/document/views/base").BaseDocumentView,
35 ElementModel = require("js/models/element-model"); 35 ElementModel = require("js/models/element-model");
36//////////////////////////////////////////////////////////////////////// 36////////////////////////////////////////////////////////////////////////
37// 37//
38exports.DesignDocumentView = Montage.create(BaseDocumentView, { 38exports.DesignDocumentView = Montage.create(BaseDocumentView, {
39 //////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////
40 // 40 //
41 hasTemplate: { 41 hasTemplate: {
42 value: false 42 value: false
43 }, 43 },
44 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
45 // 45 //
46 _callback: { 46 _callback: {
47 value: null 47 value: null
48 }, 48 },
49 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
50 // 50 //
51 _viewCallback: { 51 _viewCallback: {
52 value: null 52 value: null
53 }, 53 },
54 //////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////
55 // 55 //
56 _template: { 56 _template: {
57 value: null 57 value: null
58 }, 58 },
59 //////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////
60 // 60 //
61 _bodyFragment: { 61 _bodyFragment: {
62 value: null 62 value: null
63 }, 63 },
64 //////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////
65 // 65 //
66 _headFragment: { 66 _headFragment: {
67 value: null 67 value: null
68 }, 68 },
69 //////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////
70 // 70 //
71 _observer: { 71 _observer: {
72 value: {head: null, body: null} 72 value: {head: null, body: null}
73 }, 73 },
74 //////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////
75 // 75 //
76 content: { 76 content: {
77 value: null 77 value: null
78 }, 78 },
79 //////////////////////////////////////////////////////////////////// 79 ////////////////////////////////////////////////////////////////////
@@ -92,29 +92,29 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
92 value: null 92 value: null
93 }, 93 },
94 //////////////////////////////////////////////////////////////////// 94 ////////////////////////////////////////////////////////////////////
95 // 95 //
96 baseHref: { 96 baseHref: {
97 get: function() {return this._baseHref;}, 97 get: function() {return this._baseHref;},
98 set: function(value) {this._baseHref = value;} 98 set: function(value) {this._baseHref = value;}
99 }, 99 },
100 //////////////////////////////////////////////////////////////////// 100 ////////////////////////////////////////////////////////////////////
101 // 101 //
102 _document: { 102 _document: {
103 value: null 103 value: null
104 }, 104 },
105 //////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////
106 // 106 //
107 document: { 107 document: {
108 get: function() {return this._document;}, 108 get: function() {return this._document;},
109 set: function(value) {this._document = value;} 109 set: function(value) {this._document = value;}
110 }, 110 },
111 //////////////////////////////////////////////////////////////////// 111 ////////////////////////////////////////////////////////////////////
112 // 112 //
113 _documentRoot: { 113 _documentRoot: {
114 value: null 114 value: null
115 }, 115 },
116 //////////////////////////////////////////////////////////////////// 116 ////////////////////////////////////////////////////////////////////
117 // 117 //
118 documentRoot: { 118 documentRoot: {
119 get: function() {return this._documentRoot;}, 119 get: function() {return this._documentRoot;},
120 set: function(value) {this._documentRoot = value;} 120 set: function(value) {this._documentRoot = value;}
@@ -140,12 +140,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
140 }, 140 },
141 //////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////
142 // 142 //
143 initialize: { 143 initialize: {
144 value: function (parent) { 144 value: function (parent) {
145 //Creating iFrame for view 145 //Creating iFrame for view
146 this.iframe = document.createElement("iframe"); 146 this.iframe = document.createElement("iframe");
147 //Setting default styles 147 //Setting default styles
148 this.iframe.style.border = "none"; 148 this.iframe.style.border = "none";
149 this.iframe.style.background = "#FFF"; 149 this.iframe.style.background = "#FFF";
150 this.iframe.style.height = "100%"; 150 this.iframe.style.height = "100%";
151 this.iframe.style.width = "100%"; 151 this.iframe.style.width = "100%";
@@ -154,190 +154,190 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
154 } 154 }
155 }, 155 },
156 //////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////
157 // 157 //
158 render: { 158 render: {
159 value: function (callback, template, viewCallback) { 159 value: function (callback, template, viewCallback) {
160 //TODO: Remove, this is a temp patch for webRequest API gate 160 //TODO: Remove, this is a temp patch for webRequest API gate
161 this.application.ninja.documentController.redirectRequests = false; 161 this.application.ninja.documentController.redirectRequests = false;
162 //Storing callback for dispatch ready 162 //Storing callback for dispatch ready
163 this._callback = callback; 163 this._callback = callback;
164 this._template = template; 164 this._template = template;
165 this._viewCallback = viewCallback; 165 this._viewCallback = viewCallback;
166 //Adding listener to know when template is loaded to then load user content 166 //Adding listener to know when template is loaded to then load user content
167 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); 167 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false);
168 //TODO: Add source parameter and root (optional) 168 //TODO: Add source parameter and root (optional)
169 if (template && template.type === 'banner' && template.size) { 169 if (template && template.type === 'banner' && template.size) {
170 this.iframe.src = "js/document/templates/banner/index.html"; 170 this.iframe.src = "js/document/templates/banner/index.html";
171 } else { 171 } else {
172 this.iframe.src = "js/document/templates/html/index.html"; 172 this.iframe.src = "js/document/templates/html/index.html";
173 } 173 }
174 } 174 }
175 }, 175 },
176 //////////////////////////////////////////////////////////////////// 176 ////////////////////////////////////////////////////////////////////
177 // 177 //
178 onTemplateLoad: { 178 onTemplateLoad: {
179 value: function (e) { 179 value: function (e) {
180 //TODO: Remove, this is a temp patch for webRequest API gate 180 //TODO: Remove, this is a temp patch for webRequest API gate
181 this.application.ninja.documentController.redirectRequests = true; 181 this.application.ninja.documentController.redirectRequests = true;
182 //TODO: Add support to constructing URL with a base HREF 182 //TODO: Add support to constructing URL with a base HREF
183 var basetag = this.content.document.getElementsByTagName('base'); 183 var basetag = this.content.document.getElementsByTagName('base');
184 //Removing event 184 //Removing event
185 this.iframe.removeEventListener("load", this.onTemplateLoad.bind(this), false); 185 this.iframe.removeEventListener("load", this.onTemplateLoad.bind(this), false);
186 //TODO: Improve usage of this reference 186 //TODO: Improve usage of this reference
187 this.document = this.iframe.contentWindow.document; 187 this.document = this.iframe.contentWindow.document;
188 //Looping through template styles and marking them with ninja data attribute for I/O clean up 188 //Looping through template styles and marking them with ninja data attribute for I/O clean up
189 for (var k in this.document.styleSheets) { 189 for (var k in this.document.styleSheets) {
190 if (this.document.styleSheets[k].ownerNode && this.document.styleSheets[k].ownerNode.setAttribute) { 190 if (this.document.styleSheets[k].ownerNode && this.document.styleSheets[k].ownerNode.setAttribute) {
191 this.document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); 191 this.document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true');
192 } 192 }
193 } 193 }
194 //Checking for a base URL 194 //Checking for a base URL
195 if (basetag.length) { 195 if (basetag.length) {
196 if (basetag[basetag.length-1].getAttribute && basetag[basetag.length-1].getAttribute('href')) { 196 if (basetag[basetag.length-1].getAttribute && basetag[basetag.length-1].getAttribute('href')) {
197 //Setting base HREF in model 197 //Setting base HREF in model
198 this.baseHref = basetag[basetag.length-1].getAttribute('href'); 198 this.baseHref = basetag[basetag.length-1].getAttribute('href');
199 } 199 }
200 } 200 }
201 //Checking to content to be template 201 //Checking to content to be template
202 if (this._template) { 202 if (this._template) {
203 if (this._template.type === 'banner') { 203 if (this._template.type === 'banner') {
204 //Loading contents into a fragment 204 //Loading contents into a fragment
205 this._bodyFragment = this.document.createElement('body'); 205 this._bodyFragment = this.document.createElement('body');
206 //Listening for content to be ready 206 //Listening for content to be ready
207 this._observer.body = new WebKitMutationObserver(this.insertBannerContent.bind(this)); 207 this._observer.body = new WebKitMutationObserver(this.insertBannerContent.bind(this));
208 this._observer.body.observe(this._bodyFragment, {childList: true}); 208