aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorAnanya Sen2012-02-22 12:18:25 -0800
committerAnanya Sen2012-02-22 12:18:25 -0800
commitdbf0ca5637a3bca87c21c65ada47f8a4d794f78c (patch)
treeace2a2415ef14662c27cdb2528914bef0a7f9208 /js/document
parent9aa442da1ac9fd3212b37fa63a36090af47b6808 (diff)
parent27589634d3e8ea52abe8623f8f2cc48ce0aa04c9 (diff)
downloadninja-dbf0ca5637a3bca87c21c65ada47f8a4d794f78c.tar.gz
Merge branch 'refs/heads/FileIO-jose' into FileIO
Conflicts: js/controllers/document-controller.js Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js74
-rwxr-xr-xjs/document/text-document.js36
2 files changed, 68 insertions, 42 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 28818774..02e9918f 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -290,15 +290,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
290 } 290 }
291 }, 291 },
292 292
293
294
295 AppendElement: {
296 value: function(element, parent) {
297 this.dirtyFlag = true;
298 }
299 },
300
301
302 /** 293 /**
303 * Return the specified inline attribute from the element. 294 * Return the specified inline attribute from the element.
304 */ 295 */
@@ -386,28 +377,29 @@ exports.HTMLDocument = Montage.create(TextDocument, {
386 value: function(event){ 377 value: function(event){
387 //TODO: Clean up, using for prototyping save 378 //TODO: Clean up, using for prototyping save
388 this._templateDocument = {}; 379 this._templateDocument = {};
380 this._templateDocument.html = this.iframe.contentWindow.document;
389 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); 381 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead");
390 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); 382 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
391 //TODO: Remove, also for prototyping 383 //TODO: Remove, also for prototyping
392 this.application.ninja.documentController._hackRootFlag = true; 384 this.application.ninja.documentController._hackRootFlag = true;
393 // 385 //
394 //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
395 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); 386 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG");
396 this.stageBG.onclick = null; 387 this.stageBG.onclick = null;
397 this._document = this.iframe.contentWindow.document; 388 this._document = this.iframe.contentWindow.document;
398 this._window = this.iframe.contentWindow; 389 this._window = this.iframe.contentWindow;
399 // 390 //
400 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 391 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
401 // 392 //Inserting user's document into template
402 this._templateDocument.head.innerHTML = this._userDocument.content.head; 393 this._templateDocument.head.innerHTML = this._userDocument.content.head;
403 this._templateDocument.body.innerHTML = this._userDocument.content.body; 394 this._templateDocument.body.innerHTML = this._userDocument.content.body;
404 395
405 396 //Adding a handler for the main user document reel to finish loading
406 397 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
398
407 399
408 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once 400 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once
409 401
410 //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified 402 //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified
411 setTimeout(function () { 403 setTimeout(function () {
412 404
413 405
@@ -416,9 +408,47 @@ exports.HTMLDocument = Montage.create(TextDocument, {
416 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 408 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
417 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 409 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
418 if(this._document.styleSheets.length > 1) { 410 if(this._document.styleSheets.length > 1) {
419 this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; 411 //Checking all styleSheets in document
412 for (var i in this._document.styleSheets) {
413 //If rules are null, assuming cross-origin issue
414 if(this._document.styleSheets[i].rules === null) {
415 //TODO: Revisit URLs and URI creation logic, very hack right now
416 var fileUri, cssUrl, cssData, tag, query;
417 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) {
418 //Getting the url of the CSS file
419 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];
420 //Creating the URI of the file (this is wrong should not be splitting cssUrl)
421 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1];
422 //Loading the data from the file
423 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
424 //Creating tag with file content
425 tag = this.iframe.contentWindow.document.createElement('style');
426 tag.setAttribute('ninjauri', fileUri);
427 tag.setAttribute('ninjafileurl', cssUrl);
428 tag.innerHTML = cssData.content;
429 //Looping through DOM to insert style tag at location of link element
430 query = this._templateDocument.html.querySelectorAll(['link']);
431 for (var j in query) {
432 if (query[j].href === this._document.styleSheets[i].href) {
433 //Disabling style sheet to reload via inserting in style tag
434 query[j].setAttribute('disabled', 'true');
435 //Inserting tag
436 this._templateDocument.head.insertBefore(tag, query[j]);
437 }
438 }
439 }
440 }
441 }
442
443 //TODO: Revisit this logic
444 this._styles = this._document.styleSheets[1];
420 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array 445 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array
421 446
447 console.log(this._document.styleSheets);
448
449 ////////////////////////////////////////////////////////////////////////////
450 ////////////////////////////////////////////////////////////////////////////
451
422 //TODO Finish this implementation once we start caching Core Elements 452 //TODO Finish this implementation once we start caching Core Elements
423 // Assign a model to the UserContent and add the ViewPort reference to it. 453 // Assign a model to the UserContent and add the ViewPort reference to it.
424 NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); 454 NJUtils.makeElementModel(this.documentRoot, "Stage", "stage");
@@ -481,12 +511,20 @@ exports.HTMLDocument = Montage.create(TextDocument, {
481 511
482 } 512 }
483 }, 513 },
514
484 //////////////////////////////////////////////////////////////////// 515 ////////////////////////////////////////////////////////////////////
516
517 // Handler for user content main reel. Gets called once the main reel of the template
518 // gets deserialized.
519 // Setting up the currentSelectedContainer to the document body.
520 userTemplateDidLoad: {
521 value: function(){
522 this.application.ninja.currentSelectedContainer = this.documentRoot;
523 }
524 },
485 525
486 526
487 527 ////////////////////////////////////////////////////////////////////
488
489
490 _setSWFObjectScript: { 528 _setSWFObjectScript: {
491 value: function() { 529 value: function() {
492 if(!this._swfObject) { 530 if(!this._swfObject) {
diff --git a/js/document/text-document.js b/js/document/text-document.js
index 1132ba65..88464d87 100755
--- a/js/document/text-document.js
+++ b/js/document/text-document.js
@@ -120,15 +120,15 @@ var TextDocument = exports.TextDocument = Montage.create(Component, {
120 120
121 121
122 /** Private Members **/ 122 /** Private Members **/
123 _name: { value: null, enumerable: false }, 123 _name: { value: null, enumerable: false },
124 _uri: { value: null, enumerable: false }, 124 _uri: { value: null, enumerable: false },
125 _documentType: { value: null, enumerable: false }, 125 _documentType: { value: null, enumerable: false },
126 _container: {value: null, enumerable: false }, 126 _container: { value: null, enumerable: false },
127 _uuid: { value: null, enumerable: false }, 127 _uuid: { value: null, enumerable: false },
128 _isActive: { value: true, enumerable: false }, 128 _isActive: { value: true, enumerable: false },
129 _dirtyFlag: { value: false, enumerable: false }, 129 _needsSave: { value: false, enumarable: false },
130 _callback: { value: null, enumerable: false }, 130 _callback: { value: null, enumerable: false },
131 _currentView: { value: null, enumerable: false}, 131 _currentView: { value: null, enumerable: false},
132 132
133 /** Getters/Setters **/ 133 /** Getters/Setters **/
134 name: { 134 name: {
@@ -161,9 +161,9 @@ var TextDocument = exports.TextDocument = Montage.create(Component, {
161 set: function(value) { this._isActive = value; } 161 set: function(value) { this._isActive = value; }
162 }, 162 },
163 163
164 dirtyFlag: { 164 needsSave: {
165 get: function() { return this._dirtyFlag; }, 165 get: function() { return this._needsSave; },
166 set: function(value) { this._dirtyFlag = value; } 166 set: function(value) { this._needsSave = value }
167 }, 167 },
168 168
169 callback: { 169 callback: {
@@ -192,17 +192,5 @@ var TextDocument = exports.TextDocument = Montage.create(Component, {
192 value: function() { 192 value: function() {
193 // Have the XHR here? 193 // Have the XHR here?
194 } 194 }
195 },
196
197 markEdited:{
198 value: function() {
199 this.dirtyFlag = true;
200 }
201 },
202
203 markUnedited:{
204 value: function() {
205 this.dirtyFlag = false;
206 }
207 } 195 }
208}); \ No newline at end of file 196}); \ No newline at end of file