From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/document/controllers/document.js | 36 +- js/document/document-html.js | 136 +++---- js/document/document-text.js | 38 +- js/document/helpers/url-parser.js | 118 +++--- js/document/helpers/webgl-helper.js | 318 +++++++-------- js/document/mediators/io.js | 18 +- js/document/mediators/template.js | 486 +++++++++++------------ js/document/models/base.js | 448 ++++++++++----------- js/document/models/html.js | 46 +-- js/document/models/text.js | 62 +-- js/document/templates/app/main.js | 10 +- js/document/templates/banner/index.html | 118 +++--- js/document/templates/html/index.html | 66 ++-- js/document/templates/preview/banner.html | 92 ++--- js/document/views/base.js | 72 ++-- js/document/views/code.js | 18 +- js/document/views/design.js | 638 +++++++++++++++--------------- 17 files changed, 1360 insertions(+), 1360 deletions(-) (limited to 'js/document') diff --git a/js/document/controllers/document.js b/js/document/controllers/document.js index 1b1e1b85..8033c2e9 100755 --- a/js/document/controllers/document.js +++ b/js/document/controllers/document.js @@ -30,40 +30,40 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// // -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; //////////////////////////////////////////////////////////////////////// -// +// exports.DocumentController = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { - enumerable: false, + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { + enumerable: false, value: false }, //////////////////////////////////////////////////////////////////// - // - save: { + // + save: { value: function () { - // + // } }, //////////////////////////////////////////////////////////////////// - // - saveAs: { + // + saveAs: { value: function () { - // + // } }, //////////////////////////////////////////////////////////////////// - // - close: { + // + close: { value: function () { - // + // } } - //////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// diff --git a/js/document/document-html.js b/js/document/document-html.js index 566e5078..a7a0f03a 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -30,40 +30,40 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, - DesignDocumentView = require("js/document/views/design").DesignDocumentView; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, + DesignDocumentView = require("js/document/views/design").DesignDocumentView; //////////////////////////////////////////////////////////////////////// -// +// exports.HtmlDocument = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { value: false }, //////////////////////////////////////////////////////////////////// - // + // model: { value: null }, - //////////////////////////////////////////////////////////////////// - // + //////////////////////////////////////////////////////////////////// + // loaded: { value: {callback: null, context: null} }, //////////////////////////////////////////////////////////////////// - // + // _observer: { value: null }, - //////////////////////////////////////////////////////////////////// - // + //////////////////////////////////////////////////////////////////// + // exclusionList: { value: ["HTML", "BODY", "NINJA-CONTENT", "NINJA-VIEWPORT"] }, //////////////////////////////////////////////////////////////////// - // + // inExclusion: { value: function(element) { if(this.exclusionList.indexOf(element.nodeName) === -1) { @@ -72,62 +72,62 @@ exports.HtmlDocument = Montage.create(Component, { return 1; } }, - //////////////////////////////////////////////////////////////////// - // + //////////////////////////////////////////////////////////////////// + // init: { value:function(file, context, callback, view, template) { - //Storing callback data for loaded dispatch - this.loaded.callback = callback; - this.loaded.context = context; + //Storing callback data for loaded dispatch + this.loaded.callback = callback; + this.loaded.context = context; //Creating instance of HTML Document Model this.model = Montage.create(HtmlDocumentModel,{ - file: {value: file}, - fileTemplate: {value: template}, - parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach - views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic + file: {value: file}, + fileTemplate: {value: template}, + parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach + views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic }); //Calling the any init routines in the model this.model.init(); //Initiliazing views and hiding - if (this.model.views.design.initialize(this.model.parentContainer)) { - //Hiding iFrame, just initiliazing - this.model.views.design.hide(); - //Setting the iFrame property for reference in helper class - this.model.webGlHelper.iframe = this.model.views.design.iframe; - } else { - //ERROR: Design View not initialized - } + if (this.model.views.design.initialize(this.model.parentContainer)) { + //Hiding iFrame, just initiliazing + this.model.views.design.hide(); + //Setting the iFrame property for reference in helper class + this.model.webGlHelper.iframe = this.model.views.design.iframe; + } else { + //ERROR: Design View not initialized + } // if (view === 'design') { - //TODO: Remove reference and use as part of model - this.currentView = 'design'; - //Setting current view object to design - this.model.currentView = this.model.views.design; - //Showing design iFrame - this.model.views.design.show(); - this.model.views.design.iframe.style.opacity = 0; - this.model.views.design.content = this.model.file.content; - //TODO: Improve reference (probably through binding values) - this.model.views.design._webGlHelper = this.model.webGlHelper; - //Rendering design view, using observers to know when template is ready - this.model.views.design.render(function () { - //Adding observer to know when template is ready - this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); - this._observer.observe(this.model.views.design.document.head, {childList: true}); - }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); + //TODO: Remove reference and use as part of model + this.currentView = 'design'; + //Setting current view object to design + this.model.currentView = this.model.views.design; + //Showing design iFrame + this.model.views.design.show(); + this.model.views.design.iframe.style.opacity = 0; + this.model.views.design.content = this.model.file.content; + //TODO: Improve reference (probably through binding values) + this.model.views.design._webGlHelper = this.model.webGlHelper; + //Rendering design view, using observers to know when template is ready + this.model.views.design.render(function () { + //Adding observer to know when template is ready + this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); + this._observer.observe(this.model.views.design.document.head, {childList: true}); + }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); } else { - //TODO: Identify default view (probably code) + //TODO: Identify default view (probably code) } } }, //////////////////////////////////////////////////////////////////// - // + // handleTemplateReady: { - value: function (e) { - //Removing observer, only needed on initial load - this._observer.disconnect(); - this._observer = null; - } + value: function (e) { + //Removing observer, only needed on initial load + this._observer.disconnect(); + this._observer = null; + } }, handleViewReady: { value: function(mObjects) { @@ -143,17 +143,17 @@ exports.HtmlDocument = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// - // - closeDocument: { - value: function (context, callback) { - //Closing document (sending null to close all views) - this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this)); - } - }, + // + closeDocument: { + value: function (context, callback) { + //Closing document (sending null to close all views) + this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this)); + } + }, //////////////////////////////////////////////////////////////////// - // + // serializeDocument: { - value: function () { + value: function () { // Serialize the current scroll position //TODO: Move these properties to the design view class this.model.scrollLeft = this.application.ninja.stage._scrollLeft; @@ -169,12 +169,12 @@ exports.HtmlDocument = Montage.create(Component, { // Pause the videos //TODO: Move these to be handled on the show/hide methods in the view this.model.views.design.pauseVideos(); - } + } }, //////////////////////////////////////////////////////////////////// - // + // deserializeDocument: { - value: function () { + value: function () { // Deserialize the current scroll position //TODO: Move these properties to the design view class this.application.ninja.stage._scrollLeft = this.model.scrollLeft; @@ -184,7 +184,7 @@ exports.HtmlDocument = Montage.create(Component, { // Serialize the undo // TODO: Save the montage undo queue - } + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/js/document/document-text.js b/js/document/document-text.js index fd01b2e6..2eb88022 100755 --- a/js/document/document-text.js +++ b/js/document/document-text.js @@ -30,19 +30,19 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// // -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, TextDocumentModel = require("js/document/models/text").TextDocumentModel, - CodeDocumentView = require("js/document/views/code").CodeDocumentView; + CodeDocumentView = require("js/document/views/code").CodeDocumentView; //////////////////////////////////////////////////////////////////////// -// +// exports.TextDocument = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { value: false }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// // model: { value: null @@ -51,7 +51,7 @@ exports.TextDocument = Montage.create(Component, { // init:{ value: function(file, context, callback, view){ - // + // var codeDocumentView = CodeDocumentView.create(), container = null; //TODO: Why is this initilzied to null? //Creating instance of Text Document Model this.model = Montage.create(TextDocumentModel,{ @@ -72,22 +72,22 @@ exports.TextDocument = Montage.create(Component, { codeDocumentView.textArea.value = file.content; codeDocumentView.initializeTextView(file, this); } else { - //Other view(s) logic goes here + //Other view(s) logic goes here } //Checking if callback is needed if (callback) callback.call(context, this); } }, //////////////////////////////////////////////////////////////////// - // - closeDocument: { - value: function (context, callback) { - //Closing document and getting outcome - var closed = this.model.close(null); - //Making callback if specified - if (callback) callback.call(context, this); - } - } + // + closeDocument: { + value: function (context, callback) { + //Closing document and getting outcome + var closed = this.model.close(null); + //Making callback if specified + if (callback) callback.call(context, this); + } + } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js index 9c663e8a..c0c71511 100755 --- a/js/document/helpers/url-parser.js +++ b/js/document/helpers/url-parser.js @@ -30,81 +30,81 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// // -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; //////////////////////////////////////////////////////////////////////// -// +// exports.UrlParser = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { value: false }, //////////////////////////////////////////////////////////////////// - // - parseStyleUrls: { + // + parseStyleUrls: { value: function (css, href, local) { - // - if (local) { - var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0]; - } else { - //TODO: Add logic for external URLs - } - //TODO: Clean up functions - css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this)); - // - function parseToNinjaUrl (prop) { - // - return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this)); - } - // - function prefixWithNinjaUrl (url) { - // - 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)) { - url = fileCouldDirUrl+url; - } - // - return url; - } - // - return css; + // + if (local) { + var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0]; + } else { + //TODO: Add logic for external URLs + } + //TODO: Clean up functions + css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this)); + // + function parseToNinjaUrl (prop) { + // + return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this)); + } + // + function prefixWithNinjaUrl (url) { + // + 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)) { + url = fileCouldDirUrl+url; + } + // + return url; + } + // + return css; } }, //////////////////////////////////////////////////////////////////// - // - loadLocalStyleSheet: { + // + loadLocalStyleSheet: { value: function (href) { - //Getting file URI (not URL since we must load through I/O API) - var css = {}, file; - css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1]; - css.fileUri = this.application.ninja.coreIoApi.cloudData.root + unescape(css.cssUrl); - //Loading data from CSS file - file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri}); - //Checking for file to be writable on disk - css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly; - //Returning loaded file - if (file && file.content) { - //Getting file contents - css.content = this.parseStyleUrls(file.content, href, true); - //Returning CSS object - return css; - } else { - return false; - } + //Getting file URI (not URL since we must load through I/O API) + var css = {}, file; + css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1]; + css.fileUri = this.application.ninja.coreIoApi.cloudData.root + unescape(css.cssUrl); + //Loading data from CSS file + file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri}); + //Checking for file to be writable on disk + css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly; + //Returning loaded file + if (file && file.content) { + //Getting file contents + css.content = this.parseStyleUrls(file.content, href, true); + //Returning CSS object + return css; + } else { + return false; + } } }, //////////////////////////////////////////////////////////////////// - // - loadExternalStyleSheet: { + // + loadExternalStyleSheet: { value: function (href) { - //Loading external file - var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false}); - //Returning file - return file; + //Loading external file + var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false}); + //Returning file + return file; } } - //////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js index 4d73758b..86e2cdc1 100755 --- a/js/document/helpers/webgl-helper.js +++ b/js/document/helpers/webgl-helper.js @@ -30,72 +30,72 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - MaterialsModel = require("js/models/materials-model").MaterialsModel, - NJUtils = require("js/lib/NJUtils").NJUtils, - GLWorld = require("js/lib/drawing/world").World; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + MaterialsModel = require("js/models/materials-model").MaterialsModel, + NJUtils = require("js/lib/NJUtils").NJUtils, + GLWorld = require("js/lib/drawing/world").World; //////////////////////////////////////////////////////////////////////// -// +// exports.webGlDocumentHelper = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { value: false }, //////////////////////////////////////////////////////////////////// - //This is set when the design view is ready, for local reference - iframe: { + //This is set when the design view is ready, for local reference + iframe: { value: null }, //////////////////////////////////////////////////////////////////// - // + // _glData: { - value: null + value: null }, //////////////////////////////////////////////////////////////////// - // + // glData: { - // - get: function() { - // - var elt = this.iframe.contentWindow.document.body; - // - if (elt) { - var matLib = MaterialsModel.exportMaterials(); - this._glData = [matLib]; - this.collectGLData(this.iframe.contentWindow.document, this._glData ); - } else { - this._glData = null - } - // - return this._glData; - }, - // + // + get: function() { + // + var elt = this.iframe.contentWindow.document.body; + // + if (elt) { + var matLib = MaterialsModel.exportMaterials(); + this._glData = [matLib]; + this.collectGLData(this.iframe.contentWindow.document, this._glData ); + } else { + this._glData = null + } + // + return this._glData; + }, + // set: function(value) { - // - var elt = this.iframe.contentWindow.document.body; - // - if (elt) { - /* - // Use this code to test the runtime version of WebGL - var cdm = new NinjaCvsRt.CanvasDataManager(); - cdm.loadGLData(elt, value, null ); - */ + // + var elt = this.iframe.contentWindow.document.body; + // + if (elt) { + /* + // Use this code to test the runtime version of WebGL + var cdm = new NinjaCvsRt.CanvasDataManager(); + cdm.loadGLData(elt, value, null ); + */ - // - var i, nWorlds= value.length; - // - for (i = 0; i < nWorlds; i++) { - // get the data for the next canvas - var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; - // determine if it is the new (JSON) or old style format - if ((importStr[0] === 'v') && (index < 24)) { - // JSON format. pull off the - importStr = importStr.substr(index+1); - jObj = JSON.parse(importStr); - id = jObj.id; - } else { + // + var i, nWorlds= value.length; + // + for (i = 0; i < nWorlds; i++) { + // get the data for the next canvas + var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world; + // determine if it is the new (JSON) or old style format + if ((importStr[0] === 'v') && (index < 24)) { + // JSON format. pull off the + importStr = importStr.substr(index+1); + jObj = JSON.parse(importStr); + id = jObj.id; + } else { // at this point the data could be either the materials library or // an old style world. We can determine which by converting the string // to an object via JSON.parse. That operation will fail if the string @@ -107,113 +107,113 @@ exports.webGlDocumentHelper = Montage.create(Component, { matLibObj = JSON.parse(importStr); MaterialsModel.importMaterials(matLibObj); } else { - startIndex = importStr.indexOf("id: "); - if (startIndex >= 0) { - endIndex = importStr.indexOf("\n", startIndex); - if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); - } + startIndex = importStr.indexOf("id: "); + if (startIndex >= 0) { + endIndex = importStr.indexOf("\n", startIndex); + if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex); + } } - } - // - if (id != null) { - // - canvas = this.findCanvasWithID(id, elt); - // - if (canvas) { - // - if (canvas.elementModel) { - if (canvas.elementModel.shapeModel.GLWorld) { - canvas.elementModel.shapeModel.GLWorld.clearTree(); - } - // - if (jObj) { - useWebGL = jObj.webGL; - world = new GLWorld(canvas, useWebGL); - world.importJSON(jObj); - } - // - this.buildShapeModel(canvas.elementModel, world); - } - } - } - } - } - } + } + // + if (id != null) { + // + canvas = this.findCanvasWithID(id, elt); + // + if (canvas) { + // + if (canvas.elementModel) { + if (canvas.elementModel.shapeModel.GLWorld) { + canvas.elementModel.shapeModel.GLWorld.clearTree(); + } + // + if (jObj) { + useWebGL = jObj.webGL; + world = new GLWorld(canvas, useWebGL); + world.importJSON(jObj); + } + // + this.buildShapeModel(canvas.elementModel, world); + } + } + } + } + } + } }, //////////////////////////////////////////////////////////////////// - // + // findCanvasWithID: { - value: function(id, elt) { - // - var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id"); - // - if (cid == id) return elt; - // - if (elt.children) { - nKids = elt.children.length; - for (i=0; i 0) { - template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, ''); - template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, ''); - // - mJsSerialization = montageTemplate._ownerSerialization; + template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, ''); + template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, ''); + // + mJsSerialization = montageTemplate._ownerSerialization; } else { - template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); - template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); + template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); + template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); } //Removes all attributes from node function wipeAttributes (node) { - for (var f in node.attributes) { - node.removeAttribute(node.attributes[f].name); - } + for (var f in node.attributes) { + node.removeAttribute(node.attributes[f].name); + } } //Copying attributes to maintain same properties as the wipeAttributes(template.file.content.document.body); - for (var n in template.body.attributes) { - if (template.body.attributes[n].value) { - template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); - } - } - // + for (var n in template.body.attributes) { + if (template.body.attributes[n].value) { + template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); + } + } + // if(template.template) { // // TODO - Need to handle banner and animation templates. @@ -201,53 +201,53 @@ exports.TemplateDocumentMediator = Montage.create(Component, { } } - wipeAttributes(template.file.content.document.head); + wipeAttributes(template.file.content.document.head); //Copying attributes to maintain same properties as the - for (var m in template.document.head.attributes) { - if (template.document.head.attributes[m].value) { - template.file.content.document.head.setAttribute(template.document.head.attributes[m].name, template.document.head.attributes[m].value); - } - } + for (var m in template.document.head.attributes) { + if (template.document.head.attributes[m].value) { + template.file.content.document.head.setAttribute(template.document.head.attributes[m].name, template.document.head.attributes[m].value); + } + } //Copying attributes to maintain same properties as the - var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; - wipeAttributes(htmlTagDoc); - // - for (var m in htmlTagMem.attributes) { - if (htmlTagMem.attributes[m].value) { - if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { - htmlTagDoc.setAttribute(htmlTagMem.attributes[m].name, htmlTagMem.attributes[m].value.replace(/ montage-app-bootstrapping/gi, '')); - } - } - } - // - if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') !== null) { - htmlTagDoc.setAttribute('style', htmlTagMem.getAttribute('data-ninja-style')); - htmlTagDoc.removeAttribute('data-ninja-style'); - } else if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') === null) { - htmlTagDoc.removeAttribute('style'); - htmlTagDoc.removeAttribute('data-ninja-style'); - } + var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; + wipeAttributes(htmlTagDoc); + // + for (var m in htmlTagMem.attributes) { + if (htmlTagMem.attributes[m].value) { + if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { + htmlTagDoc.setAttribute(htmlTagMem.attributes[m].name, htmlTagMem.attributes[m].value.replace(/ montage-app-bootstrapping/gi, '')); + } + } + } + // + if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') !== null) { + htmlTagDoc.setAttribute('style', htmlTagMem.getAttribute('data-ninja-style')); + htmlTagDoc.removeAttribute('data-ninja-style'); + } else if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') === null) { + htmlTagDoc.removeAttribute('style'); + htmlTagDoc.removeAttribute('data-ninja-style'); + } //Getting list of current nodes (Ninja DOM) presentNodes = template.file.content.document.getElementsByTagName('*'); //Looping through nodes to determine origin and removing if not inserted by Ninja for (var n in presentNodes) { - // - if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { - toremovetags.push(presentNodes[n]); - } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { - //Removing attribute - presentNodes[n].removeAttribute('data-ninja-node'); - } - } + // + if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { + toremovetags.push(presentNodes[n]); + } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { + //Removing attribute + presentNodes[n].removeAttribute('data-ninja-node'); + } + } //Getting all CSS (style or link) tags var styletags = template.file.content.document.getElementsByTagName('style'), - linktags = template.file.content.document.getElementsByTagName('link'), - njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); - - //Adding to tags to be removed form template - for (var f in njtemplatetags) { - if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); - } + linktags = template.file.content.document.getElementsByTagName('link'), + njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); + + //Adding to tags to be removed form template + for (var f in njtemplatetags) { + if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); + } //Getting styles tags to be removed from document if (styletags.length) { for (var j = 0; j < styletags.length; j++) { @@ -308,7 +308,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { if (template.styles) { //Getting all style tags var styleCounter = 0, - docStyles = template.file.content.document.getElementsByTagName('style'); + docStyles = template.file.content.document.getElementsByTagName('style'); //Looping through all style tags for (var i in template.styles) { if (template.styles[i].ownerNode) { @@ -328,8 +328,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, { } else if (template.css) { //Getting all style and link tags var styleCounter = 0, - docStyles = template.file.content.document.getElementsByTagName('style'), - docLinks = template.file.content.document.getElementsByTagName('link'); + docStyles = template.file.content.document.getElementsByTagName('style'), + docLinks = template.file.content.document.getElementsByTagName('link'); //Removing Ninja Data Attributes for (var n in docLinks) { if (docLinks[n].attributes) { @@ -373,10 +373,10 @@ exports.TemplateDocumentMediator = Montage.create(Component, { var cleanedCss, - dirtyCss = this.getCssFromRules(template.css[i].cssRules), - fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'), - fileRootUrl = this.application.ninja.coreIoApi.rootUrl + fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length - 1])[0], - cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this)); + dirtyCss = this.getCssFromRules(template.css[i].cssRules), + fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'), + fileRootUrl = this.application.ninja.coreIoApi.rootUrl + fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length - 1])[0], + cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this)); function parseNinjaUrl(url) { if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { @@ -420,28 +420,28 @@ exports.TemplateDocumentMediator = Montage.create(Component, { // var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], - scripts = template.file.content.document.getElementsByTagName('script'), - libsobserver = {montage: false, canvas: false, montageCopied: null, canvasCopied: null, callback: libCopyCallback, dispatched: false}; + scripts = template.file.content.document.getElementsByTagName('script'), + libsobserver = {montage: false, canvas: false, montageCopied: null, canvasCopied: null, callback: libCopyCallback, dispatched: false}; //TODO: Clean up, this is messy if (mJsSerialization) libsobserver.montage = true; if (template.webgl && template.webgl.length > 1) libsobserver.canvas = true; // for (var i in scripts) { - if (scripts[i].getAttribute) { - if (scripts[i].getAttribute('data-ninja-canvas') !== null) {//TODO: Use querySelectorAll - matchingtags.push(scripts[i]); + if (scripts[i].getAttribute) { + if (scripts[i].getAttribute('data-ninja-canvas') !== null) {//TODO: Use querySelectorAll + matchingtags.push(scripts[i]); } if (scripts[i].getAttribute('data-ninja-canvas-lib') !== null) { webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags } if (scripts[i].getAttribute('data-ninja-canvas-rdge') !== null) { - webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags + webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags } if (scripts[i].getAttribute('type') === 'text/montage-serialization') { mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags } if (scripts[i].getAttribute('data-mjs-lib') !== null) { - mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags + mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags } } } @@ -458,23 +458,23 @@ exports.TemplateDocumentMediator = Montage.create(Component, { // if (cvsDataDir && !matchingtags.length && !webgllibtag) { - if (template.libs.canvasId) { - libsobserver.canvasId = template.libs.canvasId; - } else { - libsobserver.canvasId = ClassUuid.generate(); - } - - //Creating data directory, will include materials at a later time - fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; - - if (!this._getUserDirectory(fileCvsDir)) { - //TODO: create proper logic not to overwrite files - console.log('error'); - } - - fileCvsDir += '/'; + if (template.libs.canvasId) { + libsobserver.canvasId = template.libs.canvasId; + } else { + libsobserver.canvasId = ClassUuid.generate(); + } + + //Creating data directory, will include materials at a later time + fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; + + if (!this._getUserDirectory(fileCvsDir)) { + //TODO: create proper logic not to overwrite files + console.log('error'); + } + + fileCvsDir += '/'; } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { - fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); + fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); } //Copy webGL library if needed for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { @@ -503,9 +503,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); webglrdgetag.setAttribute('data-ninja-canvas-rdge', 'true'); if (ninjaWrapper) { - template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); } else { - template.file.content.document.head.appendChild(webglrdgetag); + template.file.content.document.head.appendChild(webglrdgetag); } } // @@ -515,9 +515,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); webgllibtag.setAttribute('data-ninja-canvas-lib', 'true'); if (ninjaWrapper) { - template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); } else { - template.file.content.document.head.appendChild(webgllibtag); + template.file.content.document.head.appendChild(webgllibtag); } } // @@ -525,10 +525,10 @@ exports.TemplateDocumentMediator = Montage.create(Component, { webgltag = template.file.content.document.createElement('script'); webgltag.setAttribute('data-ninja-canvas', 'true'); if (ninjaWrapper) { - template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); } else { - template.file.content.document.head.appendChild(webgltag); - } + template.file.content.document.head.appendChild(webgltag); + } } //TODO: Decide if this should be over-writter or only written on creation @@ -539,41 +539,41 @@ exports.TemplateDocumentMediator = Montage.create(Component, { //Looping through data to create escaped array for (var j = 0; template.webgl[j]; j++) { if (j === 0) { - json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; + json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; } else { - json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; + json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; } } //Closing array (make-shift JSON string to validate data in