From eb228e0489928f0464c295a024f0d45cf0a147c8 Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Wed, 20 Jun 2012 11:24:13 -0700 Subject: remove unneeded files Signed-off-by: Jonathan Duran --- js/controllers/elements/element-controller.js.orig | 393 -------- js/document/_toDelete/html-document.js | 873 ---------------- js/mediators/element-mediator.js | 350 +++---- js/panels/Timeline/Layer.reel/Layer.js.orig | 1057 -------------------- .../PropertyTrack.scssc | Bin 5151 -> 0 bytes 5 files changed, 175 insertions(+), 2498 deletions(-) delete mode 100755 js/controllers/elements/element-controller.js.orig delete mode 100755 js/document/_toDelete/html-document.js delete mode 100644 js/panels/Timeline/Layer.reel/Layer.js.orig delete mode 100644 js/panels/Timeline/PropertyTrack.reel/scss/.sass-cache/a26ed2cbe268f8c721d1b1d8dfa075c8c5b47e72/PropertyTrack.scssc diff --git a/js/controllers/elements/element-controller.js.orig b/js/controllers/elements/element-controller.js.orig deleted file mode 100755 index bf631d61..00000000 --- a/js/controllers/elements/element-controller.js.orig +++ /dev/null @@ -1,393 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-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, - njModule = require("js/lib/NJUtils"); - -exports.ElementController = Montage.create(Component, { - - addElement: { - value: function(el, styles) { - - if (el.getAttribute) el.setAttribute('data-ninja-node', 'true'); - - // Updated to use new methods in TimelinePanel. JR. - var insertionIndex = this.application.ninja.timeline.getInsertionIndex(); - if (insertionIndex === false) { - this.application.ninja.currentSelectedContainer.appendChild(el); - } else { - if (insertionIndex === 0) { - this.application.ninja.currentSelectedContainer.appendChild(el); - } else { - var element = this.application.ninja.timeline.arrLayers[insertionIndex].layerData.stageElement; - element.parentNode.insertBefore(el, element.nextSibling); - } - } - - if(styles) { - this.application.ninja.stylesController.setElementStyles(el, styles); - } - - /* - // Old methods. Kept for reference. Delete if not needed. JR. - if(this.application.ninja.timeline.currentLayerSelected) { - var selectedLayerIndex = this.application.ninja.timeline.getLayerIndexByID(this.application.ninja.timeline.currentLayerSelected.layerData.layerID); - - if(selectedLayerIndex === 0) { - this.application.ninja.currentSelectedContainer.appendChild(el); - } else { - var element = this.application.ninja.timeline.arrLayers[selectedLayerIndex].layerData.stageElement; - element.parentNode.insertBefore(el, element.nextSibling); - } - } else { - this.application.ninja.currentSelectedContainer.appendChild(el); - } - - if(styles) { - this.application.ninja.stylesController.setElementStyles(el, styles); - } - */ - } - }, - - // Remove the element from the DOM and clear the GLWord. - removeElement: { - value: function(el) { - if(el.elementModel.shapeModel && el.elementModel.shapeModel.GLWorld) { - el.elementModel.shapeModel.GLWorld.clearTree(); - } - el.parentNode.removeChild(el); - } - }, - - getProperty: { - value: function(el, prop, fallbackOnComputed, isStageElement) { - if(el.nodeType !== 3){ - return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); - }else{ - return null; - } - } - }, - - setProperty: { - value: function(el, p, value) { - this.application.ninja.stylesController.setElementStyle(el, p, value); - } - }, - - setProperties: { - value: function(element, properties) { - for(var property in properties) { - this.application.ninja.stylesController.setElementStyle(element, property, properties[property]); - } - } - }, - - setAttribute: { - value: function(el, att, value) { - el.setAttribute(att, value); - } - }, - - //-------------------------------------------------------------------------------------------------------- - // Routines to get/set color properties - // borderSide : "top", "right", "bottom", or "left" - getColor: { - value: function(el, isFill, borderSide) { - var colorObj, color, image; - - // Return cached value if one exists - if(isFill) { -// if(el.elementModel.fill) { -// return el.elementModel.fill; -// } - //TODO: Once logic for color and gradient is established, this needs to be revised - color = this.getProperty(el, "background-color"); - image = this.getProperty(el, "background-image"); - } else { - // Try getting border color from specific side first - if(borderSide) { - color = this.getProperty(el, "border-" + borderSide + "-color",true); - image = this.getProperty(el, "border-" + borderSide + "-image"); - } - - // If no color was found, look up the shared border color - if(!color && !image) { -// if(el.elementModel.stroke) { -// return el.elementModel.stroke; -// } - - color = this.getProperty(el, "border-color"); - image = this.getProperty(el, "border-image"); - } - } - - if(color || image) { - if (image && image !== 'none' && image.indexOf('-webkit') >= 0) { - //Gradient - colorObj = this.application.ninja.colorController.getColorObjFromCss(image); - } else { - //Solid - colorObj = this.application.ninja.colorController.getColorObjFromCss(color); - } - } - - // Update cache - if(isFill) { - el.elementModel.fill = colorObj; - } else if(!borderSide) { - // TODO - Need to update border style and width also - el.elementModel.stroke = colorObj; - } else { - // TODO - Should update specific border sides too - } - - return colorObj; - } - }, - - setColor: { - value: function(el, color, isFill,borderSide) { - var mode = color.mode; - - if(isFill) { - if(mode) { - switch (mode) { - case 'nocolor': - this.setProperty(el, "background-image", "none"); - this.setProperty(el, "background-color", "none"); - el.elementModel.fill = null; - return; - case 'gradient': - this.setProperty(el, "background-image", color.color.css); - this.setProperty(el, "background-color", "none"); - break; - default: - this.setProperty(el, "background-image", "none"); - this.setProperty(el, "background-color", color.color.css); - } - } - - el.elementModel.fill = color; - } else { - if(mode) { - switch (mode) { - case 'nocolor': - this.setProperty(el, "border-image", "none"); - this.setProperty(el, "border-color", "none"); - el.elementModel.stroke = null; - return; - case 'gradient': - this.setGradientBorder(el, color.color.gradientMode, color.color.css); - break; - default: -<<<<<<< HEAD - if(borderSide){ - this.setProperty(el,"border-"+borderSide+"-color",color.color.css); - }else{ - this.setProperty(el, "border-image", "none"); - this.setProperty(el, "border-color", color.color.css); - } - if(color.borderInfo) { - if(color.borderInfo.borderWidth) { - this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); - } - if(color.borderInfo.borderStyle) { - this.setProperty(el, "border-style", color.borderInfo.borderStyle); - } - } -======= - this.setProperty(el, "border-image", "none"); - this.setProperty(el, "border-image-slice", ""); - this.setProperty(el, "border-color", color.color.css); ->>>>>>> refs/heads/TimelineUberjd - } - } - el.elementModel.stroke = color; - } - } - }, - - setGradientBorder: { - value: function(el, gradientMode, css) { - if(gradientMode === "radial") { - this.setProperty(el, "border-image", css.replace("ellipse", "circle")); - } else { - this.setProperty(el, "border-image", css); - } - this.setProperty(el, "border-color", "none"); - // gradient slice = borderWidth/totalWidth - var b = parseInt(this.getProperty(el, "border-left-width", true)), - w = parseInt(this.getProperty(el, "width", true)), - h = parseInt(this.getProperty(el, "height", true)); - if(h > w) { - w = h; - } - this.setProperty(el, "border-image-slice", Math.floor(b/(w+b+b) * 100) + "%"); - } - }, - - getStroke: { - value: function(el, stroke) { - var strokeInfo = {}, - color, - borderWidth, - border; - if(stroke.colorInfo) { - strokeInfo.colorInfo = {}; - color = this.getColor(el, false); - if(color && color.color) { - strokeInfo.colorInfo.mode = color.mode; - strokeInfo.colorInfo.color = color.color; - } else { - strokeInfo.colorInfo.mode = "nocolor"; - strokeInfo.colorInfo.color = null; - } - } - if(stroke.borderInfo) { - // TODO - Need to figure out which border side user wants - strokeInfo.borderInfo = {}; - if(stroke.borderInfo.borderWidth) { - borderWidth = this.getProperty(el, "border-width"); - if(borderWidth) { - border = njModule.NJUtils.getValueAndUnits(borderWidth); - strokeInfo.borderInfo.borderWidth = border[0]; - strokeInfo.borderInfo.borderUnits = border[1]; - } - } - if(stroke.borderInfo.borderStyle) { - strokeInfo.borderInfo.borderStyle = this.getProperty(el, "border-style"); - } - } - return strokeInfo; - } - }, - - setStroke: { - value: function(el, stroke) { - if(stroke.borderInfo) { - if(stroke.borderInfo.borderWidth) { - this.application.ninja.stylesController.setElementStyle(el, "border-width", stroke.borderInfo.borderWidth + stroke.borderInfo.borderUnits); - } - if(stroke.borderInfo.borderStyle) { - this.application.ninja.stylesController.setElementStyle(el, "border-style", stroke.borderInfo.borderStyle); - } - } - if(stroke.colorInfo) { - this.setColor(el, stroke.colorInfo, false); - } - } - }, - - getFill: { - value: function(el, fill) { - var fillInfo = {}, - color; - if(fill.colorInfo) { - fillInfo.colorInfo = {}; - color = this.getColor(el, true); - if(color && color.color) { - fillInfo.colorInfo.mode = color.mode; - fillInfo.colorInfo.color = color.color; - } else { - fillInfo.colorInfo.mode = "nocolor"; - fillInfo.colorInfo.color = null; - } - } - return fillInfo; - } - }, - - setFill: { - value: function(el, fill) { - if(fill.colorInfo) { - this.setColor(el, fill.colorInfo, true); - } - } - }, - //-------------------------------------------------------------------------------------------------------- - // Routines to get/set 3D properties - get3DProperty: { - value: function(el, prop) { - if(el.elementModel.props3D) { - return el.elementModel.props3D[prop]; - } - } - }, - - getMatrix: { - value: function(el) { - if(el.elementModel.props3D && el.elementModel.props3D.matrix3d) { - return el.elementModel.props3D.matrix3d.slice(0); - } else { - var mat; - - if (el) { - mat = this.application.ninja.stylesController.getMatrixFromElement(el, false); - if (!mat) { - mat = Matrix.I(4); - } - } - - el.elementModel.props3D.matrix3d = mat; - return mat; - } - } - }, - - getPerspectiveDist: { - value: function(el) { - if(el.elementModel.props3D && el.elementModel.props3D.perspectiveDist) { - return el.elementModel.props3D.perspectiveDist; - } else { - var dist = this.application.ninja.stylesController.getPerspectiveDistFromElement(el, false); - el.elementModel.props3D.perspectiveDist = dist; - return dist; - } - } - }, - - // TODO - perspective distance needs to be passed in as "dist" and matrix3d needs to be passed in as "mat" - set3DProperties: { - value: function(el, props, update3DModel) { - var dist = props["dist"], - mat = props["mat"]; - - this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform", "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); - - this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform-style", "preserve-3d"); - - // TODO - We don't support perspective on individual elements yet - // this.application.ninja.stylesController.setElementStyle(el, "-webkit-perspective", dist); - - el.elementModel.props3D.matrix3d = mat; - el.elementModel.props3D.perspectiveDist = dist; - - if(update3DModel) { - this._update3DProperties(el, mat, dist); - } - } - }, - - _update3DProperties: { - value: function(elt, mat, dist) { - var elt3DInfo = MathUtils.decomposeMatrix2(mat); - if(elt3DInfo) - { - elt.elementModel.props3D.xAngle = elt3DInfo.rotation[0] * MathUtils.RAD_TO_DEG; - elt.elementModel.props3D.yAngle = elt3DInfo.rotation[1] * MathUtils.RAD_TO_DEG; - elt.elementModel.props3D.zAngle = elt3DInfo.rotation[2] * MathUtils.RAD_TO_DEG; - - elt.elementModel.props3D.x3D = ~~(elt3DInfo.translation[0]); - elt.elementModel.props3D.y3D = ~~(elt3DInfo.translation[1]); - elt.elementModel.props3D.z3D = ~~(elt3DInfo.translation[2]); - } - } - } - -}); \ No newline at end of file diff --git a/js/document/_toDelete/html-document.js b/js/document/_toDelete/html-document.js deleted file mode 100755 index 1bb643ac..00000000 --- a/js/document/_toDelete/html-document.js +++ /dev/null @@ -1,873 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-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, - TextDocument = require("js/document/text-document").TextDocument, - NJUtils = require("js/lib/NJUtils").NJUtils, - GLWorld = require("js/lib/drawing/world").World, - MaterialsModel = require("js/models/materials-model").MaterialsModel; -//////////////////////////////////////////////////////////////////////// -// -exports.HTMLDocument = Montage.create(TextDocument, { - - _selectionExclude: { value: null, enumerable: false }, - _htmlTemplateUrl: { value: "js/document/templates/montage-html/index.html", enumerable: false}, - _iframe: { value: null, enumerable: false }, - _server: { value: null, enumerable: false }, - _templateDocument: { value: null, enumerable: false }, - _selectionModel: { value: [], enumerable: false }, - _undoModel: { value: { "queue" : [], "position" : 0 }, enumerable: false}, - - _document: { value: null, enumerable: false }, - _documentRoot: { value: null, enumerable: false }, - _liveNodeList: { value: null, enumarable: false }, - _stageBG: { value: null, enumerable: false }, - _window: { value: null, enumerable: false }, - _styles: { value: null, enumerable: false }, - _stylesheets: { value: null, enumerable: false }, - _stageStyleSheetId : { value: 'nj-stage-stylesheet', enumerable: false }, - _userDocument: { value: null, enumerable: false }, - _htmlSource: {value: "", enumerable: false}, - _glData: {value: null, enumerable: false }, - _userComponents: { value: {}, enumarable: false}, - - _elementCounter: { value: 1, enumerable: false }, - _snapping : { value: true, enumerable: false }, - _layoutMode: { value: "all", enumerable: false }, - _draw3DGrid: { value: false, writable: true }, - _swfObject: { value: false, enumerable: false }, - - _zoomFactor: { value: 100, enumerable: false }, - - cssLoadInterval: { value: null, enumerable: false }, - - _savedLeftScroll: {value:null}, - _savedTopScroll: {value:null}, - - _codeViewDocument:{ - writable: true, - enumerable: true, - value:null - }, - - - //drawUtils state - _gridHorizontalSpacing: {value:0}, - _gridVerticalSpacing: {value:0}, - //end - drawUtils state - - _undoStack: { value: [] }, - undoStack: { - get: function() { - return this._undoStack; - }, - set:function(value){ - this._undoStack = value; - } - }, - - _redoStack: { value: [], enumerable: false }, - - redoStack: { - get: function() { - return this._redoStack; - }, - set:function(value){ - this._redoStack = value; - } - }, - - // GETTERS / SETTERS - - codeViewDocument:{ - get: function() { return this._codeViewDocument; }, - set: function(value) { this._codeViewDocument = value} - }, - - savedLeftScroll:{ - get: function() { return this._savedLeftScroll; }, - set: function(value) { this._savedLeftScroll = value} - }, - - savedTopScroll:{ - get: function() { return this._savedTopScroll; }, - set: function(value) { this._savedTopScroll = value} - }, - - gridHorizontalSpacing:{ - get: function() { return this._gridHorizontalSpacing; }, - set: function(value) { this._gridHorizontalSpacing = value} - }, - - gridVerticalSpacing:{ - get: function() { return this._gridVerticalSpacing; }, - set: function(value) { this._gridVerticalSpacing = value} - }, - - selectionExclude: { - get: function() { return this._selectionExclude; }, - set: function(value) { this._selectionExclude = value; } - }, - - iframe: { - get: function() { return this._iframe; }, - set: function(value) { this._iframe = value; } - }, - - server: { - get: function() { return this._server; }, - set: function(value) { this._server = value; } - }, - - selectionModel: { - get: function() { return this._selectionModel; }, - set: function(value) { this._selectionModel = value; } - }, - - undoModel: { - get: function() { return this._undoModel; }, - set: function(value) { this._undoModel.queue = value.queue; this._undoModel.position = value.position; } - }, - - documentRoot: { - get: function() { return this._documentRoot; }, - set: function(value) { this._documentRoot = value; } - }, - - stageBG: { - get: function() { return this._stageBG; }, - set: function(value) { this._stageBG = value; } - }, - - elementCounter: { - set: function(value) { this._elementCounter = value; }, - get: function() { return this._elementCounter; } - }, - - snapping: { - get: function() { return this._snapping; }, - set: function(value) { - if(this._snapping !== value) { - this._snapping = value; - } - } - }, - - // TODO SEND THE EVENT --> Redraw the desired layout - layoutMode: { - get: function() { return this._layoutMode; }, - set: function(mode) { this._layoutMode = mode; } - }, - - draw3DGrid: { - get: function() { return this._draw3DGrid; }, - set: function(value) { - if(this._draw3DGrid !== value) { - this._draw3DGrid = value; - } - } - }, - - userComponents: { - get: function() { - return this._userComponents; - } - }, -// _drawUserComponentsOnOpen:{ -// value:function(){ -// for(var i in this._userComponentSet){ -// console.log(this._userComponentSet[i].control) -// this._userComponentSet[i].control.needsDraw = true; -// } -// } -// }, - - glData: { - get: function() { - // - var elt = this.iframe.contentWindow.document.getElementById("UserContent"); - // - if (elt) { - var matLib = MaterialsModel.exportMaterials(); - this._glData = [matLib]; - this.collectGLData(elt, this._glData ); - } else { - this._glData = null - } - // - return this._glData; - }, - set: function(value) { - var elt = this.documentRoot; - if (elt) - { - /* - // Use this code to test the runtime version of WebGL - var cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {}); - cvsDataMngr.loadGLData(elt, value); - */ - - // /* - var nWorlds= value.length; - for (var i=0; i= 0) { - var endIndex = importStr.indexOf( "\n", startIndex ); - if (endIndex > 0) - id = importStr.substring( startIndex+4, endIndex ); - } - } - } - - if (id != null) - { - var canvas = this.findCanvasWithID( id, elt ); - if (canvas) - { - if (!canvas.elementModel) - { - NJUtils.makeElementModel(canvas, "Canvas", "shape", true); - } - if (canvas.elementModel) - { - if (canvas.elementModel.shapeModel.GLWorld) - canvas.elementModel.shapeModel.GLWorld.clearTree(); - - if (jObj) - { - var useWebGL = jObj.webGL; - var world = new GLWorld( canvas, useWebGL ); - world.importJSON( jObj ); - } - - this.buildShapeModel( canvas.elementModel, world ); - } - } - } - } - // */ - } - } - }, - - buildShapeModel: - { - value: function( elementModel, world ) - { - var shapeModel = elementModel.shapeModel; - shapeModel.shapeCount = 1; // for now... - shapeModel.useWebGl = world._useWebGL; - shapeModel.GLWorld = world; - var root = world.getGeomRoot(); - if (root) - { - shapeModel.GLGeomObj = root; - shapeModel.strokeSize = root._strokeWidth; - shapeModel.strokeStyle = "solid"; - //shapeModel.strokeStyleIndex - switch (root.geomType()) - { - case root.GEOM_TYPE_RECTANGLE: - elementModel.selection = "Rectangle"; - elementModel.pi = "RectanglePi"; - shapeModel.tlRadius = root._tlRadius; - shapeModel.trRadius = root._trRadius; - shapeModel.blRadius = root._blRadius; - shapeModel.brRadius = root._brRadius; - break; - - case root.GEOM_TYPE_CIRCLE: - elementModel.selection = "Oval"; - elementModel.pi = "OvalPi"; - shapeModel.innerRadius = root._innerRadius; - break; - - case root.GEOM_TYPE_LINE: - elementModel.selection = "Line"; - elementModel.pi = "LinePi"; - shapeModel.slope = root._slope; - break; - - case root.GEOM_TYPE_BRUSH_STROKE: - elementModel.selection = "BrushStroke"; - elementModel.pi = "BrushStrokePi"; - break; - - case root.GEOM_TYPE_CUBIC_BEZIER: - elementModel.selection = "Subpath"; - elementModel.pi = "SubpathPi"; - break; - - default: - console.log( "geometry type not supported for file I/O, " + root.geomType()); - break; - } - } - } - }, - - zoomFactor: { - get: function() { return this._zoomFactor; }, - set: function(value) { this._zoomFactor = value; } - }, - - /** - * Add a reference to a component instance to the userComponents hash using the - * element UUID - */ - setComponentInstance: { - value: function(instance, el) { - this.userComponents[el.uuid] = instance; - } - }, - - /** - * Returns the component instance obj from the element - */ - getComponentFromElement: { - value: function(el) { - if(el) { - if(el.uuid) return this.userComponents[el.uuid]; - } else { - return null; - } - } - }, - - /** - * search the DOM tree to find a canvas with the given id - */ - findCanvasWithID: { - value: function( id, elt ) { - var cid = elt.getAttribute( "data-RDGE-id" ); - if (cid == id) return elt; - - if (elt.children) - { - var nKids = elt.children.length; - for (var i=0; i 1) { - //Checking all styleSheets in document - for (var i in this._document.styleSheets) { - //If rules are null, assuming cross-origin issue - if(this._document.styleSheets[i].rules === null) { - //TODO: Revisit URLs and URI creation logic, very hack right now - var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl, docRootUrl; - // - docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - //TODO: Parse out relative URLs and map them to absolute - if (this._document.styleSheets[i].href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { - // - cssUrl = this._document.styleSheets[i].href.split(this.application.ninja.coreIoApi.rootUrl)[1]; - fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl; - //TODO: Add error handling for reading file - cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); - // - var tag = this.iframe.contentWindow.document.createElement('style'); - tag.setAttribute('type', 'text/css'); - tag.setAttribute('data-ninja-uri', fileUri); - tag.setAttribute('data-ninja-file-url', cssUrl); - tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); - tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); - //Copying attributes to maintain same properties as the - for (var n in this._document.styleSheets[i].ownerNode.attributes) { - if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { - if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); - } else { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); - } - } - } - // - fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; - - //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT - tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); - - function detectUrl (prop) { - return prop.replace(/[^()\\""\\'']+/g, prefixUrl);; - } - - function prefixUrl (url) { - if (url !== 'url') { - if (!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; - } - - //Looping through DOM to insert style tag at location of link element - query = this._templateDocument.html.querySelectorAll(['link']); - for (var j in query) { - if (query[j].href === this._document.styleSheets[i].href) { - //Disabling style sheet to reload via inserting in style tag - query[j].setAttribute('disabled', 'true'); - //Inserting tag - this._templateDocument.head.insertBefore(tag, query[j]); - } - } - } else { - console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); - //None local stylesheet, probably on a CDN (locked) - var tag = this.iframe.contentWindow.document.createElement('style'); - tag.setAttribute('type', 'text/css'); - tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); - tag.setAttribute('data-ninja-file-read-only', "true"); - tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); - //Copying attributes to maintain same properties as the - for (var n in this._document.styleSheets[i].ownerNode.attributes) { - if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { - if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value.split(docRootUrl)[1]); - } else { - tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); - } - } - } - /* - - //TODO: Figure out cross-domain XHR issue, might need cloud to handle - var xhr = new XMLHttpRequest(); - xhr.open("GET", this._document.styleSheets[i].href, true); - xhr.send(); - // - if (xhr.readyState === 4) { - console.log(xhr); - } - //tag.innerHTML = xhr.responseText //xhr.response; - */ - //Temp rule so it's registered in the array - tag.innerHTML = 'noRULEjustHACK{background: #000}'; - //Disabling external style sheets - query = this._templateDocument.html.querySelectorAll(['link']); - for (var k in query) { - if (query[k].href === this._document.styleSheets[i].href) { - - //TODO: Removed the temp insertion of the stylesheet - //because it wasn't the proper way to do it - //need to be handled via XHR with proxy in Cloud Sim - - //Disabling style sheet to reload via inserting in style tag - //var tempCSS = query[k].cloneNode(true); - //tempCSS.setAttribute('data-ninja-template', 'true'); - query[k].setAttribute('disabled', 'true'); - //this.iframe.contentWindow.document.head.appendChild(tempCSS); - //Inserting tag - this._templateDocument.head.insertBefore(tag, query[k]); - } - } - } - } - } - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - //TODO: Check if this is needed - this._stylesheets = this._document.styleSheets; - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - //TODO Finish this implementation once we start caching Core Elements - // Assign a model to the UserContent and add the ViewPort reference to it. - NJUtils.makeElementModel(this.documentRoot, "Stage", "stage"); - NJUtils.makeElementModel(this.stageBG, "Stage", "stage"); - NJUtils.makeElementModel(this.iframe.contentWindow.document.getElementById("Viewport"), "Stage", "stage"); - - // Initialize the 3D properties - this.documentRoot.elementModel.props3D.init(this.documentRoot, true); - this.stageBG.elementModel.props3D.init(this.stageBG, true); - this.iframe.contentWindow.document.getElementById("Viewport").elementModel.props3D.init(this.iframe.contentWindow.document.getElementById("Viewport"), true); - - for(i = 0; i < this._stylesheets.length; i++) { - if(this._stylesheets[i].ownerNode.id === this._stageStyleSheetId) { - this.documentRoot.elementModel.defaultRule = this._stylesheets[i]; - break; - } - } - - //Temporary create properties for each rule we need to save the index of the rule - var len = this.documentRoot.elementModel.defaultRule.cssRules.length; - for(var j = 0; j < len; j++) { - //console.log(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText); - if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "*") { - - this.documentRoot.elementModel.transitionStopRule = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "body") { - - this.documentRoot.elementModel.body = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#Viewport") { - - this.documentRoot.elementModel.viewPort = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === ".stageDimension") { - - this.documentRoot.elementModel.stageDimension = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === ".stageView") { - - this.documentRoot.elementModel.stageView = this.documentRoot.elementModel.defaultRule.cssRules[j]; - - } else if(this.documentRoot.elementModel.defaultRule.cssRules[j].selectorText === "#stageBG") { - - this.documentRoot.elementModel.stageBackground = this.documentRoot.elementModel.defaultRule.cssRules[j]; - } - } - - this.callback(this); - - //Setting webGL data - if (this._templateDocument.webgl) { - this.glData = this._templateDocument.webgl; - } - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - - - }.bind(this), 1000); - - - - - } - }, - - //////////////////////////////////////////////////////////////////// - - // Handler for user content main reel. Gets called once the main reel of the template - // gets deserialized. - // Setting up the currentSelectedContainer to the document body. - userTemplateDidLoad: { - value: function(){ - //this.application.ninja.currentSelectedContainer = this.documentRoot; - } - }, - - - //////////////////////////////////////////////////////////////////// - _setSWFObjectScript: { - value: function() { - if(!this._swfObject) { - /* - var swfObj = document.createElement("script"); - swfObj.type = "text/javascript"; - swfObj.src = "../../user-document-templates/external-libs/swf-object/swfobject.js"; - swfObj.id = "swfObject"; - var head= this._document.getElementsByTagName('head')[0]; - head.appendChild(swfObj); - this._swfObject = true; - */ - } - } - }, - - - - - - //////////////////////////////////////////////////////////////////// - // - livePreview: { - enumerable: false, - value: function () { - //TODO: Add logic to handle save before preview - this.application.ninja.documentController.handleExecuteSaveAll(null); - //Temp check for webGL Hack - window.open(this.application.ninja.coreIoApi.rootUrl + this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); - //chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); - } - }, - //////////////////////////////////////////////////////////////////// - // - save: { - enumerable: false, - value: function () { - //TODO: Add code view logic and also styles for HTML - if (this.currentView === 'design') { - var styles = []; - for (var k in this._document.styleSheets) { - if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { - if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { - styles.push(this._document.styleSheets[k]); - } - } - } - //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; - return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; - } else if (this.currentView === "code"){ - //TODO: Would this get call when we are in code of HTML? - } else { - //Error - } - } - }, - //////////////////////////////////////////////////////////////////// - // - saveAll: { - enumerable: false, - value: function () { - //TODO: Add code view logic and also styles for HTML - if (this.currentView === 'design') { - var css = []; - for (var k in this._document.styleSheets) { - if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { - if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { - css.push(this._document.styleSheets[k]); - } - } - } - //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; - return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; - } else if (this.currentView === "code"){ - //TODO: Would this get call when we are in code of HTML? - } else { - //Error - } - } - } -}); \ No newline at end of file diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 99d2f822..ca7aadaf 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -1,42 +1,42 @@ /* -This file contains proprietary software owned by Motorola Mobility, Inc.
-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. -
*/ + This file contains proprietary software owned by Motorola Mobility, Inc.
+ 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 ElementController = require("js/controllers/elements/element-controller").ElementController, - Command = require("js/controllers/undo-controller").Command, + Command = require("js/controllers/undo-controller").Command, NJUtils = require("js/lib/NJUtils").NJUtils; exports.ElementMediator = Montage.create(Component, { - addDelegate: { - enumerable: false, - value: null + addDelegate:{ + enumerable:false, + value:null }, - deleteDelegate: { - enumerable: false, - value: null + deleteDelegate:{ + enumerable:false, + value:null }, - addElements: { - value: function(elements, rules, notify) { - if(Array.isArray(elements)) { - elements.forEach(function(element) { + addElements:{ + value:function (elements, rules, notify) { + if (Array.isArray(elements)) { + elements.forEach(function (element) { ElementController.addElement(element, rules); - element.elementModel.props3D.init(element, false); + element.elementModel.props3D.init(element, false); }); } else { ElementController.addElement(elements, rules); - elements.elementModel.props3D.init(elements, false); + elements.elementModel.props3D.init(elements, false); - } + } - if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { + if (this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { this.addDelegate['onAddElements'].call(this.addDelegate, elements); } @@ -46,23 +46,23 @@ exports.ElementMediator = Montage.create(Component, { this.application.ninja.currentDocument.model.needsSave = true; - if(notify || notify === undefined) { + if (notify || notify === undefined) { NJevent("elementAdded", elements); } } }, - removeElements: { - value: function(elements, notify /* Used for the add undo */) { + removeElements:{ + value:function (elements, notify /* Used for the add undo */) { - if(this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { + if (this.deleteDelegate && (typeof this.deleteDelegate.handleDelete === 'function')) { return this.deleteDelegate.handleDelete(); // this.handleDelete.call(deleteDelegate); } - if(Array.isArray(elements)) { + if (Array.isArray(elements)) { elements = Array.prototype.slice.call(elements, 0); - elements.forEach(function(element) { + elements.forEach(function (element) { ElementController.removeElement(element); }); } else { @@ -79,8 +79,8 @@ exports.ElementMediator = Montage.create(Component, { } }, - replaceElement: { - value: function(newChild, oldChild, notify) { + replaceElement:{ + value:function (newChild, oldChild, notify) { this.application.ninja.currentDocument.model.documentRoot.replaceChild(newChild, oldChild); if (newChild.getAttribute) newChild.setAttribute('data-ninja-node', 'true'); @@ -91,15 +91,15 @@ exports.ElementMediator = Montage.create(Component, { this.application.ninja.currentDocument.model.needsSave = true; - if(notify || notify === undefined) { - NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); + if (notify || notify === undefined) { + NJevent("elementReplaced", {type:"replaceElement", data:{"newChild":newChild, "oldChild":oldChild}}); } } }, - getProperty: { - value: function(el, prop, valueMutator) { - if(valueMutator && typeof valueMutator === "function") { + getProperty:{ + value:function (el, prop, valueMutator) { + if (valueMutator && typeof valueMutator === "function") { return valueMutator(el.elementModel.controller["getProperty"](el, prop)); } else { return el.elementModel.controller["getProperty"](el, prop, valueMutator); @@ -107,28 +107,28 @@ exports.ElementMediator = Montage.create(Component, { } }, - getShapeProperty: { - value: function(el, prop) { + getShapeProperty:{ + value:function (el, prop) { return el.elementModel.controller["getShapeProperty"](el, prop); } }, - setShapeProperty: { - value: function(el, prop, value) { + setShapeProperty:{ + value:function (el, prop, value) { return el.elementModel.controller["setShapeProperty"](el, prop, value); } }, /** - Set a property change command for an element or array of elements - @param element: Element - @param attribute: Attribute to set - @param value: Value to be set. - @param currentValue: current value - @param source: String for the source object making the call - */ - setAttribute: { - value: function(element, attribute, value, currentValue, source) { + Set a property change command for an element or array of elements + @param element: Element + @param attribute: Attribute to set + @param value: Value to be set. + @param currentValue: current value + @param source: String for the source object making the call + */ + setAttribute:{ + value:function (element, attribute, value, currentValue, source) { element.elementModel.controller["setAttribute"](element, attribute, value); // Add to the undo @@ -149,40 +149,40 @@ exports.ElementMediator = Montage.create(Component, { @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline */ - setProperty: { - value: function(els, p, value, eventType, source, currentValue) { - if(eventType === "Changing") { + setProperty:{ + value:function (els, p, value, eventType, source, currentValue) { + if (eventType === "Changing") { this._setProperty(els, p, value, eventType, source); } else { // Calculate currentValue if not found for each element - if(!currentValue) { + if (!currentValue) { var that = this; - currentValue = els.map(function(item) { + currentValue = els.map(function (item) { return that.getProperty((item), p); }); } var command = Montage.create(Command, { - _els: { value: els }, - _p: { value: p }, - _value: { value: value }, - _previous: { value: currentValue }, - _eventType: { value: eventType}, - _source: { value: "undo-redo"}, - description: { value: "Set Property"}, - receiver: { value: this}, - - execute: { - value: function(senderObject) { - if(senderObject) this._source = senderObject; + _els:{ value:els }, + _p:{ value:p }, + _value:{ value:value }, + _previous:{ value:currentValue }, + _eventType:{ value:eventType}, + _source:{ value:"undo-redo"}, + description:{ value:"Set Property"}, + receiver:{ value:this}, + + execute:{ + value:function (senderObject) { + if (senderObject) this._source = senderObject; this.receiver._setProperty(this._els, this._p, this._value, this._eventType, this._source); this._source = "undo-redo"; return ""; } }, - unexecute: { - value: function() { + unexecute:{ + value:function () { this.receiver._setProperty(this._els, this._p, this._previous, this._eventType, this._source); return ""; } @@ -196,15 +196,15 @@ exports.ElementMediator = Montage.create(Component, { } }, - _setProperty: { - value: function(els, p, value, eventType, source) { + _setProperty:{ + value:function (els, p, value, eventType, source) { var el; - for(var i=0, item; item = els[i]; i++) { + for (var i = 0, item; item = els[i]; i++) { item.elementModel.controller["setProperty"](item, p, value[i], eventType, source); } - NJevent("element" + eventType, {type : "setProperty", source: source, data: {"els": els, "prop": p, "value": value}, redraw: null}); + NJevent("element" + eventType, {type:"setProperty", source:source, data:{"els":els, "prop":p, "value":value}, redraw:null}); } }, @@ -214,16 +214,16 @@ exports.ElementMediator = Montage.create(Component, { @param eventType: Change/Changing. Will be passed to the dispatched event @param source: String for the source object making the call */ - setProperties: { - value: function(elements, eventType, source) { + setProperties:{ + value:function (elements, eventType, source) { - elements.forEach(function(elementObject) { + elements.forEach(function (elementObject) { elementObject.element.elementModel.controller["setProperties"](elementObject.element, elementObject.properties); }); - if(eventType !== "Changing") { + if (eventType !== "Changing") { var undoLabel = "Properties change"; - elements.forEach(function(elementObject) { + elements.forEach(function (elementObject) { var swap = elementObject.properties; elementObject.properties = elementObject.previousProperties; elementObject.previousProperties = swap; @@ -233,52 +233,52 @@ exports.ElementMediator = Montage.create(Component, { // Map the elements for the event data // TODO: Clean this up - var els = elements.map(function(element) { + var els = elements.map(function (element) { return element.element; }); // Dispatch the element change/changing event. - NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": elements[0].properties, "value": elements}, redraw: null}); + NJevent("element" + eventType, {type:"setProperties", source:source, data:{"els":els, "prop":elements[0].properties, "value":elements}, redraw:null}); } }, - set3DProperties: { - value: function(elements, eventType, source) { + set3DProperties:{ + value:function (elements, eventType, source) { var update3DModel = false; - if(eventType === "Change") { + if (eventType === "Change") { update3DModel = true; } -