From 5de553a1b3bdd8783ab6ce017ae70369ad92a890 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 16 May 2012 11:37:05 -0700 Subject: Fixing preview bug Also setting up for Montage component serialization. --- js/document/models/base.js | 2 +- js/document/templates/html/index.html | 5 +++-- js/document/templates/html/main.js | 14 +++++++++++--- js/document/templates/html/package.json | 1 + js/document/views/design.js | 2 +- js/mediators/io-mediator.js | 12 ++++-------- node_modules/tools/package.json | 14 ++++++++++++++ node_modules/tools/template/template-creator.js | 2 +- 8 files changed, 36 insertions(+), 16 deletions(-) create mode 100755 node_modules/tools/package.json diff --git a/js/document/models/base.js b/js/document/models/base.js index f9844b70..033e16f6 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -93,7 +93,7 @@ exports.BaseDocumentModel = Montage.create(Component, { //Currently only supporting current browser (Chrome, obviously) switch (this.browser) { case 'chrome': - if (this.template.type === 'banner' || this.template.type === 'animation') { + if (this.template && (this.template.type === 'banner' || this.template.type === 'animation')) { window.open('/js/document/templates/preview/banner.html?width='+this.template.size.width+'&height='+this.template.size.height+'&url='+this.url); } else { window.open(this.url); diff --git a/js/document/templates/html/index.html b/js/document/templates/html/index.html index a1b8b242..24159841 100755 --- a/js/document/templates/html/index.html +++ b/js/document/templates/html/index.html @@ -12,6 +12,9 @@ must set the 'data-ninja-template' data-ninja-template="true" --> + + + @@ -58,8 +61,6 @@ return document.elementFromPoint(x,y); } - - diff --git a/js/document/templates/html/main.js b/js/document/templates/html/main.js index d5ac88d5..f45657bb 100644 --- a/js/document/templates/html/main.js +++ b/js/document/templates/html/main.js @@ -3,8 +3,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + Template = require("montage/ui/template").Template, + TemplateCreator = require("tools/template/template-creator").TemplateCreator; exports.Main = Montage.create(Component, { @@ -18,6 +20,7 @@ exports.Main = Montage.create(Component, { templateDidLoad: { value: function(){ var self = this; + // window.addComponent = function(element, data, callback) { var component; @@ -36,7 +39,12 @@ exports.Main = Montage.create(Component, { .end(); }; - + // + window.mjsTemplateCreator = TemplateCreator.create(); + // + window.mjsTemplate = Template.create(); + + // Dispatch event when this template has loaded. /* var newEvent = document.createEvent( "CustomEvent" ); diff --git a/js/document/templates/html/package.json b/js/document/templates/html/package.json index d1e839dc..4f36090a 100755 --- a/js/document/templates/html/package.json +++ b/js/document/templates/html/package.json @@ -4,6 +4,7 @@ }, "mappings": { "montage": "../../../../node_modules/montage/", + "tools": "../../../../node_modules/tools/", "montage-google": "../../../../node_modules/montage-google/" } } \ No newline at end of file diff --git a/js/document/views/design.js b/js/document/views/design.js index c7aab1d7..3b2eb11f 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -347,7 +347,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { // initMontage: { value: function () { - // + //initWithDocument(window.document) instantiateWithOwnerAndDocument(null, window.document) } }, //////////////////////////////////////////////////////////////////// diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 8346c75e..e6f2cc2d 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -234,17 +234,13 @@ exports.IoMediator = Montage.create(Component, { //TODO: Add attribute copying for and /* -//Testing using montage clean up method - var mjscode, mjsTemp = TemplateCreator.create(); - - //mjscode = mjsTemp.initWithHeadAndBodyElements(template.head, template.body); - //mjscode = mjsTemp.initWithDocument(template.file.content.document); - mjscode = mjsTemp.initWithDocument(template.document); + var tc = this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.mjsTemplateCreator, code; + code = tc.initWithDocument(this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.document); + console.log(code._ownerSerialization, code._document.getElementsByTagName('html')[0].innerHTML); - console.log(template.head, mjscode._document.head); template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, ''); template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, ''); -*/ + */ diff --git a/node_modules/tools/package.json b/node_modules/tools/package.json new file mode 100755 index 00000000..5d830af3 --- /dev/null +++ b/node_modules/tools/package.json @@ -0,0 +1,14 @@ + +{ + "name": "tools", + "version": "0.1.0", + "description": "Montage Tools", + "main": "tools", + "mappings": { + "montage" : "../montage/" + }, + "dependency": { + "montage" : "0.8" + } + +} \ No newline at end of file diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js index 1cd65ddd..374353f0 100755 --- a/node_modules/tools/template/template-creator.js +++ b/node_modules/tools/template/template-creator.js @@ -39,7 +39,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le script, self = this; - this._objectNamesIndex = {}; + this._componentNamesIndex = {}; doc = this._document = document.implementation.createHTMLDocument(""); function copyNode(sourceNode, targetNode, isRootNode) { -- cgit v1.2.3