diff options
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/element-mediator.js | 6 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 25 |
2 files changed, 22 insertions, 9 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index f71a6f4d..1d5e9ade 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -48,7 +48,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
48 | 48 | ||
49 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); | 49 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); |
50 | 50 | ||
51 | this.application.ninja.documentController.activeDocument.model.needsSave = true; | 51 | this.application.ninja.currentDocument.model.needsSave = true; |
52 | 52 | ||
53 | if(notify || notify === undefined) { | 53 | if(notify || notify === undefined) { |
54 | NJevent("elementAdded", elements); | 54 | NJevent("elementAdded", elements); |
@@ -77,7 +77,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
77 | 77 | ||
78 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); | 78 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); |
79 | 79 | ||
80 | this.application.ninja.documentController.activeDocument.model.needsSave = true; | 80 | this.application.ninja.currentDocument.model.needsSave = true; |
81 | 81 | ||
82 | NJevent("elementsRemoved", elements); | 82 | NJevent("elementsRemoved", elements); |
83 | } | 83 | } |
@@ -92,7 +92,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
92 | 92 | ||
93 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); | 93 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); |
94 | 94 | ||
95 | this.application.ninja.documentController.activeDocument.model.needsSave = true; | 95 | this.application.ninja.currentDocument.model.needsSave = true; |
96 | 96 | ||
97 | if(notify || notify === undefined) { | 97 | if(notify || notify === undefined) { |
98 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); | 98 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index e9ed86d7..4dbf32d5 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -277,6 +277,8 @@ exports.IoMediator = Montage.create(Component, { | |||
277 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), | 277 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), |
278 | mjsCreator = template.mjsTemplateCreator.create(), | 278 | mjsCreator = template.mjsTemplateCreator.create(), |
279 | mJsSerialization, | 279 | mJsSerialization, |
280 | toremovetags = [], | ||
281 | presentNodes, | ||
280 | montageTemplate; | 282 | montageTemplate; |
281 | //Creating instance of template creator | 283 | //Creating instance of template creator |
282 | montageTemplate = mjsCreator.initWithDocument(template.document); | 284 | montageTemplate = mjsCreator.initWithDocument(template.document); |
@@ -299,23 +301,34 @@ exports.IoMediator = Montage.create(Component, { | |||
299 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); | 301 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); |
300 | } | 302 | } |
301 | } | 303 | } |
302 | //TODO: Add attribute copying for <HEAD> and <HTML> | ||
303 | 304 | ||
304 | 305 | ||
305 | //console.log(template.file.content.document.getElementsByTagName('html')[0].innerHTML); | 306 | |
307 | //TODO: Add attribute copying for <HEAD> and <HTML> | ||
306 | 308 | ||
307 | 309 | ||
310 | |||
311 | //Getting list of current nodes (Ninja DOM) | ||
312 | presentNodes = template.file.content.document.getElementsByTagName('*'); | ||
313 | //Looping through nodes to determine origin and removing if not inserted by Ninja | ||
314 | for (var n in presentNodes) { | ||
315 | if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { | ||
316 | toremovetags.push(presentNodes[n]); | ||
317 | } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { | ||
318 | //Removing attribute | ||
319 | presentNodes[n].removeAttribute('data-ninja-node'); | ||
320 | } | ||
321 | } | ||
308 | //Getting all CSS (style or link) tags | 322 | //Getting all CSS (style or link) tags |
309 | var styletags = template.file.content.document.getElementsByTagName('style'), | 323 | var styletags = template.file.content.document.getElementsByTagName('style'), |
310 | linktags = template.file.content.document.getElementsByTagName('link'), | 324 | linktags = template.file.content.document.getElementsByTagName('link'), |
311 | toremovetags = [], | ||
312 | njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); | 325 | njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); |
313 | 326 | ||
314 | ////////////////////////////////////////////////// | 327 | ////////////////////////////////////////////////// |
315 | //TODO: Remove, temp hack, this is to be fixed by Montage | 328 | //TODO: Remove, temp hack, this is to be fixed by Montage |
316 | var basetags = template.file.content.document.getElementsByTagName('base'); | 329 | var basetags = template.file.content.document.getElementsByTagName('base'); |
317 | for (var g in basetags) { | 330 | for (var g in basetags) { |
318 | if (basetags[g].getAttribute) toremovetags.push(basetags[g]); | 331 | if (basetags[g].getAttribute && basetags[g].href && basetags[g].href.indexOf('chrome-extension://') !== -1) toremovetags.push(basetags[g]); |
319 | } | 332 | } |
320 | ////////////////////////////////////////////////// | 333 | ////////////////////////////////////////////////// |
321 | 334 | ||
@@ -392,7 +405,7 @@ exports.IoMediator = Montage.create(Component, { | |||
392 | for (var n in docLinks) { | 405 | for (var n in docLinks) { |
393 | if (docLinks[n].attributes) { | 406 | if (docLinks[n].attributes) { |
394 | for (var m in docLinks[n].attributes) { | 407 | for (var m in docLinks[n].attributes) { |
395 | if (docLinks[n].attributes[m].name && docLinks[n].attributes[m].name.indexOf('data-ninja') != -1) { | 408 | if (docLinks[n].attributes[m].name && docLinks[n].attributes[m].name.indexOf('data-ninja') !== -1) { |
396 | docLinks[n].removeAttribute(docLinks[n].attributes[m].name); | 409 | docLinks[n].removeAttribute(docLinks[n].attributes[m].name); |
397 | } | 410 | } |
398 | } | 411 | } |
@@ -404,7 +417,7 @@ exports.IoMediator = Montage.create(Component, { | |||
404 | if (template.css[i].ownerNode.getAttribute) { | 417 | if (template.css[i].ownerNode.getAttribute) { |
405 | if (template.css[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.css[i].ownerNode.getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll | 418 | if (template.css[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.css[i].ownerNode.getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll |
406 | //Inseting data from rules array into <style> as string | 419 | //Inseting data from rules array into <style> as string |
407 | if (docStyles[styleCounter] && !template.css[i].ownerNode.getAttribute('data-ninja-external-url')) { | 420 | if (docStyles[styleCounter] && !template.css[i].ownerNode.getAttribute('data-ninja-external-url') && template.css[i].ownerNode.getAttribute('data-ninja-node')) { |
408 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); | 421 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); |
409 | styleCounter++; | 422 | styleCounter++; |
410 | } | 423 | } |