aboutsummaryrefslogtreecommitdiff
path: root/js/models/element-model.js
diff options
context:
space:
mode:
authorhwc4872012-06-12 15:52:35 -0700
committerhwc4872012-06-12 15:52:35 -0700
commit9490f816924e9e9c9970ef9384241c07ec0a6e9f (patch)
treef44449a2e0055e21960a5513fb3a0738a91db528 /js/models/element-model.js
parentb7a41cbd5a30d32f524ee60e2dfdf9c65c7ec55b (diff)
parent6854a72504f57903bd5de003e377f2aefb02d0da (diff)
downloadninja-9490f816924e9e9c9970ef9384241c07ec0a6e9f.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: assets/canvas-runtime.js js/io/system/ninjalibrary.json js/mediators/element-mediator.js
Diffstat (limited to 'js/models/element-model.js')
-rwxr-xr-xjs/models/element-model.js100
1 files changed, 99 insertions, 1 deletions
diff --git a/js/models/element-model.js b/js/models/element-model.js
index 966158e4..76f15b21 100755
--- a/js/models/element-model.js
+++ b/js/models/element-model.js
@@ -10,7 +10,105 @@ var Montage = require("montage/core/core").Montage,
10 ControllerFactory = require("js/controllers/elements/controller-factory").ControllerFactory, 10 ControllerFactory = require("js/controllers/elements/controller-factory").ControllerFactory,
11 PiData = require("js/data/pi/pi-data").PiData; 11 PiData = require("js/data/pi/pi-data").PiData;
12 12
13exports.ElementModel = Montage.create(Montage, { 13var modelGenerator = exports.modelGenerator = function() {
14 var info = getInfoForElement(this);
15
16 Object.defineProperty(this, "_model", {
17 configurable: true,
18 enumerable: false,
19 writable: true,
20 value: Montage.create(elmo, {
21 type: { value: info.type},
22 selection: { value: info.selection},
23 controller: { value: info.controller},
24 pi: { value: info.pi},
25 props3D: { value: info.props3d},
26 shapeModel: { value: info.shapeModel},
27 isShape: { value: info.isShape}
28 })
29 });
30
31 if(this._model.selection !== "body") {
32 this._model.props3D.init(this, false);
33 }
34
35 return this._model;
36};
37
38var getInfoForElement = function(el) {
39 var elementName, controller, pi, shapeModel = null, isShape = false, isComponent = false;
40
41 elementName = el.nodeName.toLowerCase();
42 controller = elementNameToController(elementName);
43 pi = elementNameToPi(elementName);
44
45 // Element is a shape
46 if(el.getAttribute("data-RDGE-id")) {
47 controller = "shape";
48 shapeModel = Montage.create(ShapeModel);
49 isShape = true;
50 }
51
52 if(el.nodeName.toLowerCase() === "ninja-content") {
53 elementName = "body";
54 controller = elementNameToController(elementName);
55 pi = elementNameToPi(elementName);
56 }
57
58 // TODO: Add this in case there is no controller for the component
59 /*
60 if(el.getAttribute("data-montage-id")) {
61 elementName = null;
62 this.isComponent = true;
63 }
64 */
65
66 // Element is a component
67 if(el.controller) {
68 var componentInfo = Montage.getInfoForObject(el.controller);
69 var componentName = componentInfo.objectName;//.toLowerCase();
70
71 controller = "component";
72 elementName = componentName;
73 pi = elementNameToPi(componentName.replace(/\s+/g, ''));
74 isComponent = true;
75 }
76
77 return {
78 type: el.nodeName,
79 selection: elementName,
80 controller: ControllerFactory.getController(controller),
81 pi: pi,
82 props3d: Montage.create(Properties3D),
83 shapeModel: shapeModel,
84 isShape: isShape,
85 isComponent: isComponent
86 }
87};
88
89var elementNameToController = function(name) {
90 if(name === "div" || name === "custom") {
91 return "block";
92 } else if(name === "img") {
93 return "image";
94 } else {
95 return name;
96 }
97};
98
99var elementNameToPi = function(name) {
100 if(!name) return null;
101
102 var piString = name + "Pi";
103
104 if(!PiData.hasOwnProperty(piString)) {
105 piString = "blockPi";
106 }
107
108 return piString;
109};
110
111var elmo = exports.ElementModel = Montage.create(Montage, {
14 key: { value: "_model_"}, 112 key: { value: "_model_"},
15 113
16 type: { value: null }, // Tag type that was created 114 type: { value: null }, // Tag type that was created