aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/views/design.js87
-rwxr-xr-xjs/io/system/coreioapi.js64
2 files changed, 125 insertions, 26 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index e5213761..4f598305 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -127,21 +127,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
127 this._observer.body = null; 127 this._observer.body = null;
128 //Removing loading container 128 //Removing loading container
129 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]); 129 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]);
130 130 //Getting style and link tags in document
131
132
133
134
135 //
136 var stags = this.document.getElementsByTagName('style'), 131 var stags = this.document.getElementsByTagName('style'),
137 ltags = this.document.getElementsByTagName('link'); 132 ltags = this.document.getElementsByTagName('link');
138 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles) 133 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles)
139 this.ninjaDisableAttribute(stags); 134 this.ninjaDisableAttribute(stags);
140 this.ninjaDisableAttribute(ltags); 135 this.ninjaDisableAttribute(ltags);
141
142
143
144
145 //Looping through all link tags to reload into style tags 136 //Looping through all link tags to reload into style tags
146 if(ltags.length > 0) { 137 if(ltags.length > 0) {
147 for (var i = 0; i < ltags.length; i++) { 138 for (var i = 0; i < ltags.length; i++) {
@@ -152,14 +143,15 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
152 //Disabling tag once it has been reloaded 143 //Disabling tag once it has been reloaded
153 ltags[i].setAttribute('disabled', 'true'); 144 ltags[i].setAttribute('disabled', 'true');
154 } else { 145 } else {
155 //Error: broken? 146 //Error: TBD
147 //TODO: Determine what link tags would not have href data and error
156 } 148 }
157 } 149 }
158 } 150 }
159 151
152 //TODO: Load webGL (blocking)
160 153
161 154 //TODO: Load Montage Components (blocking)
162
163 155
164 //Makign callback if specified 156 //Makign callback if specified
165 if (this._callback) this._callback(); 157 if (this._callback) this._callback();
@@ -186,6 +178,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
186 value: function (linktag) { 178 value: function (linktag) {
187 // 179 //
188 var tag, cssUrl, fileUri, cssData, docRootUrl; 180 var tag, cssUrl, fileUri, cssData, docRootUrl;
181 //Creating style tag to load CSS content into
182 tag = this.document.createElement('style');
183 tag.setAttribute('type', 'text/css');
189 //TODO: Remove usage of hack reference of URL 184 //TODO: Remove usage of hack reference of URL
190 docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); 185 docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
191 //Checking for location of href to load (special case for cross-domain) 186 //Checking for location of href to load (special case for cross-domain)
@@ -195,19 +190,19 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
195 fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl; 190 fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl;
196 //Loading data from CSS file 191 //Loading data from CSS file
197 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); 192 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
198 // 193 //Setting properties of locally loaded styles
194 tag.setAttribute('data-ninja-uri', fileUri);
195 tag.setAttribute('data-ninja-file-url', cssUrl);
196 tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly);
197 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]);
199 } else { 198 } else {
200 //Cross-domain resource 199 //Cross-domain content
200 cssData = this.application.ninja.coreIoApi.readExternalFile({url: linktag.href, binary: false});
201 //Setting properties of externally loaded styles
202 tag.setAttribute('data-ninja-external-url', linktag.href);
203 tag.setAttribute('data-ninja-file-read-only', "true");
204 tag.setAttribute('data-ninja-file-name', linktag.href.split('/')[linktag.href.split('/').length-1]);
201 } 205 }
202 //TODO: Improve into single method
203 fileCouldDirUrl = linktag.href.split(linktag.href.split('/')[linktag.href.split('/').length-1])[0];
204 //Creating style tag to load CSS content into
205 tag = this.document.createElement('style');
206 tag.setAttribute('type', 'text/css');
207 tag.setAttribute('data-ninja-uri', fileUri);
208 tag.setAttribute('data-ninja-file-url', cssUrl);
209 tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly);
210 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]);
211 //Copying attributes to maintain same properties as the <link> 206 //Copying attributes to maintain same properties as the <link>
212 for (var n in linktag.attributes) { 207 for (var n in linktag.attributes) {
213 if (linktag.attributes[n].value && linktag.attributes[n].name !== 'disabled') { 208 if (linktag.attributes[n].value && linktag.attributes[n].name !== 'disabled') {
@@ -218,9 +213,49 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
218 } 213 }
219 } 214 }
220 } 215 }
216
217
218
219
220
221
222
223
224
225
226
227 ////////////////////////////////////////////////////////
228 ////////////////////////////////////////////////////////
229 //TODO: Clean up and make proper method
230 fileCouldDirUrl = linktag.href.split(linktag.href.split('/')[linktag.href.split('/').length-1])[0];
231 //
232 if (cssData && cssData.content) {
233 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
234 } else {
235 //Error: no data was loaded
236 }
237 //
238 function parseToNinjaUrl (prop) {
239 //
240 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
241 }
221 // 242 //
222 //tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); 243 function prefixWithNinjaUrl (url) {
223 tag.innerHTML = cssData.content; 244 //
245 if (url !== 'url' && !url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
246 url = fileCouldDirUrl+url;
247 }
248 //
249 return url;
250 }
251 ////////////////////////////////////////////////////////
252 ////////////////////////////////////////////////////////
253
254
255
256
257
258
224 // 259 //
225 return tag; 260 return tag;
226 } 261 }
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
index a06f45c6..1e6518fe 100755
--- a/js/io/system/coreioapi.js
+++ b/js/io/system/coreioapi.js
@@ -193,6 +193,23 @@ exports.CoreIoApi = Montage.create(Component, {
193 this._fileServiceURL = value; 193 this._fileServiceURL = value;
194 } 194 }
195 }, 195 },
196 ////////////////////////////////////////////////////////////////////
197 //File service API URL
198 _webServiceURL: {
199 enumerable: false,
200 value: '/web'
201 },
202 ////////////////////////////////////////////////////////////////////
203 //
204 webServiceURL: {
205 enumerable: false,
206 get: function() {
207 return String(this.rootUrl+this._webServiceURL);
208 },
209 set: function(value) {
210 this._webServiceURL = value;
211 }
212 },
196 //////////////////////////////////////////////////////////////////// 213 ////////////////////////////////////////////////////////////////////
197 //Directory service API URL 214 //Directory service API URL
198 _directoryServiceURL: { 215 _directoryServiceURL: {
@@ -647,6 +664,53 @@ exports.CoreIoApi = Montage.create(Component, {
647 } 664 }
648 }, 665 },
649 //////////////////////////////////////////////////////////////////// 666 ////////////////////////////////////////////////////////////////////
667 // Reads an external file (cross-domain)
668 // Parameters:
669 // the file parameter must contain the following properties
670 // url: string value containing the full file path/URL i.e. "http://google.com/motorola.html"
671 // binary parameter is optional if the content is to be binary
672 // Return values:
673 // returns an object with two properties
674 // success: boolean indicating if the call succeeded or failed
675 // content: string containing the file contents
676 // status: int indicating the request HTTP status code
677 // 200 - the file was read and its contents were returned
678 // 404 - the file does not exist
679 // 500 - unknown server error occurred
680 readExternalFile: {
681 enumerable: false,
682 value: function(file) {
683 //
684 var retValue = {success:null, content:null, status:null};
685 //
686 if(file && file.url && file.url.length) {
687 try {
688 var serviceURL = this._prepareServiceURL(this.webServiceURL, ''),
689 xhr = new XMLHttpRequest();
690 //
691 xhr.open("GET", serviceURL+"?url="+file.url, false);
692 if (file.binary) xhr.setRequestHeader("return-type", "binary");
693 xhr.setRequestHeader("Content-Type", "text/plain");
694 xhr.send();
695 //
696 if (xhr.readyState === 4) {
697 retValue.status = xhr.status;
698 if(xhr.status == 200) {
699 retValue.content = xhr.response;
700 }
701 retValue.success = true;