aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-20 16:37:47 -0700
committerValerio Virgillito2012-04-20 16:37:47 -0700
commitc62273126004f057de40ce91ecda5606643f4c92 (patch)
tree4f55b7017e3387b90ae57fa71222706bd0ebec66 /js/document
parentc0bb9d7740a0fa2efce6c53c39054a46da4b63e0 (diff)
downloadninja-c62273126004f057de40ce91ecda5606643f4c92.tar.gz
reverting old template to current working status. New template work.
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/controllers/document.js2
-rwxr-xr-xjs/document/document-html.js304
-rwxr-xr-xjs/document/html-document.js223
-rwxr-xr-xjs/document/models/base.js4
-rwxr-xr-xjs/document/models/html.js4
-rwxr-xr-xjs/document/templates/montage-web/default_html.css11
-rwxr-xr-xjs/document/templates/montage-web/index.html10
7 files changed, 321 insertions, 237 deletions
diff --git a/js/document/controllers/document.js b/js/document/controllers/document.js
index f7260957..feba3e0e 100755
--- a/js/document/controllers/document.js
+++ b/js/document/controllers/document.js
@@ -16,7 +16,7 @@ exports.DocumentController = Montage.create(Component, {
16 hasTemplate: { 16 hasTemplate: {
17 enumerable: false, 17 enumerable: false,
18 value: false 18 value: false
19 } 19 },
20 //////////////////////////////////////////////////////////////////// 20 ////////////////////////////////////////////////////////////////////
21 // 21 //
22 save: { 22 save: {
diff --git a/js/document/document-html.js b/js/document/document-html.js
index b48e004a..841e66ed 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -6,8 +6,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component; 10 Component = require("montage/ui/component").Component;
11 HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel;
11//////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////
12// 13//
13exports.HtmlDocument = Montage.create(Component, { 14exports.HtmlDocument = Montage.create(Component, {
@@ -16,9 +17,306 @@ exports.HtmlDocument = Montage.create(Component, {
16 hasTemplate: { 17 hasTemplate: {
17 enumerable: false, 18 enumerable: false,
18 value: false 19 value: false
19 } 20 },
21
22 model: {
23 value: null
24 },
25
26 loadDelegate: {
27 value: null
28 },
29
30 delegateContext: {
31 value: null
32 },
33
34 // Getters for the model.
35 // TODO: Change how these properties are accessed through Ninja
36 name: {
37 get: function() {
38 return this.model._name;
39 },
40 set: function(value) {
41 this.model._name = value;
42 }
43 },
44
45 // View Properties
46 // TODO: Move those into a view object - for now dump it here
47 iframe: {
48 value: null
49 },
50
51 uuid: {
52 get: function() {
53 return this._uuid;
54 }
55 },
20 //////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////
21 //////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////
58 init: {
59 value:function(file, context, callback) {
60 this.model = Montage.create(HtmlDocumentModel, {
61 file: {
62 value: file
63 }
64 });
65
66 this.name = file.name;
67
68 // this.init(file.name, file.uri, file.extension, iframe, uuid, callback);
69
70 this.iframe = this.createView();
71 this.iframe.addEventListener("load", this.handleWebTemplateLoad.bind(this), true);
72
73 //this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"];
74 //this.currentView = "design";
75 //
76
77 this.delegateContext = context;
78 this.loadDelegate = callback;
79 }
80 },
81
82 // Create View
83 // Move this into a base view object
84 createView: {
85 value: function() {
86 var ifr = document.createElement("iframe");
87 ifr.id = "document_" + this._uuid;
88
89
90 ifr.style.border = "none";
91 ifr.style.background = "#FFF";
92 ifr.style.height = "100%";
93 ifr.style.width = "100%";
94
95 // TODO: Reable opacity to display only when done loading
96// ifr.style.opacity = 0;
97
98 ifr.src = "js/document/templates/montage-web/index.html";
99
100 return document.getElementById("iframeContainer").appendChild(ifr);
101 }
102 },
103
104 handleWebTemplateLoad: {
105 value: function(event) {
106 //TODO: Remove, also for prototyping
107 this.application.ninja.documentController._hackRootFlag = true;
108
109
110 //TODO: Clean up, using for prototyping save
111// this._templateDocument = {};
112// this._templateDocument.html = this.iframe.contentWindow.document;
113// this._templateDocument.body =
114
115 this._window = this.iframe.contentWindow;
116 this._document = this.iframe.contentWindow.document;
117 this.documentRoot = this.iframe.contentWindow.document.body;
118
119 for (var k in this._document.styleSheets) {
120 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) {
121 this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true');
122 }
123 }
124
125 // TODO: We don't need this anymore -> need to setup the main container still
126 //Adding a handler for the main user document reel to finish loading
127 //this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
128 this.documentRoot.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
129
130 // Live node list of the current loaded document
131 this._liveNodeList = this.documentRoot.getElementsByTagName('*');
132
133 // TODO Move this to the appropriate location
134 /*
135 var len = this._liveNodeList.length;
136
137 for(var i = 0; i < len; i++) {
138 NJUtils.makeModelFromElement(this._liveNodeList[i]);
139 }
140 */
141
142 setTimeout(function () {
143
144 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
145 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
146 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147 if(this._document.styleSheets.length) {
148 //Checking all styleSheets in document
149 for (var i in this._document.styleSheets) {
150 //If rules are null, assuming cross-origin issue
151 if(this._document.styleSheets[i].rules === null) {
152 //TODO: Revisit URLs and URI creation logic, very hack right now
153 var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl, docRootUrl;
154 //
155 docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
156 //TODO: Parse out relative URLs and map them to absolute
157 if (this._document.styleSheets[i].href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) {
158 //
159 cssUrl = this._document.styleSheets[i].href.split(this.application.ninja.coreIoApi.rootUrl)[1];
160 fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl;
161 //TODO: Add error handling for reading file
162 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
163 //
164 var tag = this.iframe.contentWindow.document.createElement('style');
165 tag.setAttribute('type', 'text/css');
166 tag.setAttribute('data-ninja-uri', fileUri);
167 tag.setAttribute('data-ninja-file-url', cssUrl);
168 tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly);
169 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]);
170 //Copying attributes to maintain same properties as the <link>
171 for (var n in this._document.styleSheets[i].ownerNode.attributes) {
172 if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') {
173 if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) {
174 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]);
175 } else {
176 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value);
177 }
178 }
179 }
180 //
181 fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0];
182
183 //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT
184 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl);
185
186 function detectUrl (prop) {
187 return prop.replace(/[^()\\""\\'']+/g, prefixUrl);;
188 }
189
190 function prefixUrl (url) {
191 if (url !== 'url') {
192 if (!url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
193 url = fileCouldDirUrl+url;
194 }
195 }
196 return url;
197 }
198