diff options
author | Nivesh Rajbhandari | 2012-02-22 10:34:46 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-02-22 10:34:46 -0800 |
commit | 50bb05efbafc9a80f069dfde32988e5cd6826865 (patch) | |
tree | 64332f1c2f22b5c0a17f6df2f9a02d77f1c87274 /js/document | |
parent | a69c929602e64f10fb3903b89a2ca9e9ed2c8dfb (diff) | |
parent | 2f24dafec79583547fe663d5a387d8ef15aae3bf (diff) | |
download | ninja-50bb05efbafc9a80f069dfde32988e5cd6826865.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/html-document.js | 236 | ||||
-rwxr-xr-x | js/document/text-document.js | 26 |
2 files changed, 132 insertions, 130 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 77cc711d..9a7755e6 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 | */ |
@@ -358,22 +349,40 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
358 | 349 | ||
359 | 350 | ||
360 | 351 | ||
361 | 352 | ||
353 | |||
354 | |||
355 | /* | ||
356 | DOM Mutation Events: | ||
357 | |||
358 | DOMActivate, DOMFocusIn, DOMFocusOut, DOMAttrModified, | ||
359 | DOMCharacterDataModified, DOMNodeInserted, DOMNodeInsertedIntoDocument, | ||
360 | DOMNodeRemoved, DOMNodeRemovedFromDocument, DOMSubtreeModified, DOMContentLoaded | ||
361 | |||
362 | */ | ||
363 | |||
364 | |||
365 | |||
366 | /* | ||
367 | //TODO: Remove and clean up event listener (DOMSubtreeModified) | ||
368 | _hackCount: { | ||
369 | value: 0 | ||
370 | }, | ||
371 | */ | ||
372 | |||
373 | |||
362 | //////////////////////////////////////////////////////////////////// | 374 | //////////////////////////////////////////////////////////////////// |
363 | // | 375 | // |
364 | handleEvent: { | 376 | handleEvent: { |
365 | value: function(event){ | 377 | value: function(event){ |
366 | //TODO: Remove | ||
367 | window.hackPreview = this.livePreview.bind(this); | ||
368 | |||
369 | this.application.ninja.documentController._hackRootFlag = true; | ||
370 | //console.log(this._userDocument.root, this); | ||
371 | //TODO: Clean up, using for prototyping save | 378 | //TODO: Clean up, using for prototyping save |
372 | this._templateDocument = {}; | 379 | this._templateDocument = {}; |
373 | this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead");; | 380 | this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); |
374 | this._templateDocument.body = this.iframe.contentWindow.document.getElementById("UserContent");; | 381 | this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); |
382 | //TODO: Remove, also for prototyping | ||
383 | this.application.ninja.documentController._hackRootFlag = true; | ||
375 | // | 384 | // |
376 | this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); | 385 | //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); |
377 | this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); | 386 | this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); |
378 | this.stageBG.onclick = null; | 387 | this.stageBG.onclick = null; |
379 | this._document = this.iframe.contentWindow.document; | 388 | this._document = this.iframe.contentWindow.document; |
@@ -381,83 +390,103 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
381 | // | 390 | // |
382 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; | 391 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; |
383 | // | 392 | // |
393 | this._templateDocument.head.innerHTML = this._userDocument.content.head; | ||
394 | this._templateDocument.body.innerHTML = this._userDocument.content.body; | ||
395 | |||
396 | // Adding a handler for the main user document reel to finish loading. | ||
397 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | ||
384 | 398 | ||
385 | this.documentRoot.innerHTML = this._userDocument.content.body; | 399 | |
386 | this.iframe.contentWindow.document.getElementById("userHead").innerHTML = this._userDocument.content.head; | 400 | /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once |
387 | 401 | ||
388 | 402 | //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified | |
389 | //TODO: Look at code below and clean up | 403 | setTimeout(function () { |
390 | 404 | ||
391 | 405 | ||
406 | |||
407 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
408 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
409 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
410 | if(this._document.styleSheets.length > 1) { | ||
411 | this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; | ||
412 | this._stylesheets = this._document.styleSheets; // Entire stlyesheets array | ||
413 | |||
414 | //TODO Finish this implementation once we start caching Core Elements | ||
415 | // Assign a model to the UserContent and add the ViewPort reference to it. | ||
416 | NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); | ||
417 | //this.documentRoot.elementModel.viewPort = this.iframe.contentWindow.document.getElementById("Viewport"); | ||
418 | NJUtils.makeElementModel(this.stageBG, "Stage", "stage"); | ||
419 | NJUtils.makeElementModel(this.iframe.contentWindow.document.getElementById("Viewport"), "Stage", "stage"); | ||
420 | |||
421 | for(i = 0; i < this._stylesheets.length; i++) { | ||
422 | if(this._stylesheets[i].ownerNode.id === this._stageStyleSheetId) { | ||
423 | this.documentRoot.elementModel.defaultRule = this._stylesheets[i]; | ||
424 | break; | ||
425 | } | ||
426 | } | ||
427 | |||
428 | //Temporary create properties for each rule we need to save the index of the rule | ||
429 | var len = this.documentRoot.elementModel.defaultRule.cssRules.length; | ||
430 | for(var j = 0; j < len; j++) { | ||
431 | //console.log(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText); | ||
432 | if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "*") { | ||
433 | |||
434 | this.documentRoot.elementModel.transitionStopRule = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
435 | |||
436 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "body") { | ||
437 | |||
438 | this.documentRoot.elementModel.body = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
439 | |||
440 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#Viewport") { | ||
441 | |||
442 | this.documentRoot.elementModel.viewPort = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
443 | |||
444 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === ".stageDimension") { | ||
445 | |||
446 | this.documentRoot.elementModel.stageDimension = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
447 | |||
448 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === ".stageView") { | ||
449 | |||
450 | this.documentRoot.elementModel.stageView = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
451 | |||
452 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#stageBG") { | ||
453 | |||
454 | this.documentRoot.elementModel.stageBackground = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
455 | } | ||
456 | } | ||
457 | |||
458 | this.callback(this); | ||
459 | |||
460 | } | ||
461 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
462 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
463 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
464 | |||
465 | |||
466 | |||
467 | |||
468 | |||
469 | }.bind(this), 1000); | ||
470 | |||
471 | |||
392 | 472 | ||
393 | |||
394 | this.cssLoadInterval = setInterval(function() { | ||
395 | if(this._document.styleSheets.length > 1) { | ||
396 | clearInterval(this.cssLoadInterval); | ||
397 | this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; | ||
398 | this._stylesheets = this._document.styleSheets; // Entire stlyesheets array | ||
399 | |||
400 | this.callback(this); | ||
401 | |||
402 | //console.log('file content end'); | ||
403 | } | ||
404 | }.bind(this), 50); | ||
405 | 473 | ||
406 | this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; | 474 | } |
407 | this._stylesheets = this._document.styleSheets; // Entire stlyesheets array | 475 | }, |
408 | |||
409 | /* TODO Finish this implementation once we start caching Core Elements */ | ||
410 | // Assign a model to the UserContent and add the ViewPort reference to it. | ||
411 | NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); | ||
412 | //this.documentRoot.elementModel.viewPort = this.iframe.contentWindow.document.getElementById("Viewport"); | ||
413 | NJUtils.makeElementModel(this.stageBG, "Stage", "stage"); | ||
414 | NJUtils.makeElementModel(this.iframe.contentWindow.document.getElementById("Viewport"), "Stage", "stage"); | ||
415 | |||
416 | for(i = 0; i < this._stylesheets.length; i++) { | ||
417 | if(this._stylesheets[i].ownerNode.id === this._stageStyleSheetId) { | ||
418 | this.documentRoot.elementModel.defaultRule = this._stylesheets[i]; | ||
419 | break; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | // Temporary create properties for each rule we need to save the index of the rule. | ||
424 | var len = this.documentRoot.elementModel.defaultRule.cssRules.length; | ||
425 | for(var j = 0; j < len; j++) { | ||
426 | // console.log(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText); | ||
427 | if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "*") { | ||
428 | |||
429 | this.documentRoot.elementModel.transitionStopRule = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
430 | |||
431 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "body") { | ||
432 | |||
433 | this.documentRoot.elementModel.body = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||
434 | |||
435 | } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#Viewport") { | ||
436 | |||
437 | this.documentRoot.elementModel.viewPort = this.documentRoot.elementModel.defaultRule.cssRules[j]; | ||