aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements')
-rw-r--r--js/controllers/elements/block-controller.js35
-rw-r--r--js/controllers/elements/canvas-controller.js37
-rw-r--r--js/controllers/elements/component-controller.js12
-rw-r--r--js/controllers/elements/controller-factory.js49
-rw-r--r--js/controllers/elements/element-controller.js263
-rw-r--r--js/controllers/elements/image-controller.js41
-rw-r--r--js/controllers/elements/shapes-controller.js238
-rw-r--r--js/controllers/elements/stage-controller.js125
-rw-r--r--js/controllers/elements/video-controller.js56
9 files changed, 856 insertions, 0 deletions
diff --git a/js/controllers/elements/block-controller.js b/js/controllers/elements/block-controller.js
new file mode 100644
index 00000000..395a1a4d
--- /dev/null
+++ b/js/controllers/elements/block-controller.js
@@ -0,0 +1,35 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 ElementController = require("js/controllers/elements/element-controller").ElementController;
9
10exports.BlockController = Montage.create(ElementController, {
11
12 /**
13 If the base method needs to be sub-classed
14 setProperty: {
15 value: function(el, p, value) {
16 switch(p) {
17 case "width":
18 console.log("width");
19 break;
20 default:
21 ElementController.setProperty(el, p, value);
22 }
23 }
24 },
25 */
26
27 /*
28 setProperties: {
29 value: function(el, newProps, currentProps, index, eventType, notify, redraw) {
30 ElementController.setProperties(el, newProps, currentProps, index, eventType, notify, redraw);
31 }
32 },
33 */
34
35}); \ No newline at end of file
diff --git a/js/controllers/elements/canvas-controller.js b/js/controllers/elements/canvas-controller.js
new file mode 100644
index 00000000..7af7e824
--- /dev/null
+++ b/js/controllers/elements/canvas-controller.js
@@ -0,0 +1,37 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 ElementController = require("js/controllers/elements/element-controller").ElementController;
9
10exports.CanvasController = Montage.create(ElementController, {
11
12 getProperty: {
13 value: function(el, prop) {
14 switch(prop) {
15 case "height":
16 case "width":
17 return el.getAttribute(prop);
18 break;
19 default:
20 return ElementController.getProperty(el, prop);
21 }
22 }
23 },
24
25 setProperty: {
26 value: function(el, p, value) {
27 switch(p) {
28 case "height":
29 case "width":
30 el.setAttribute(p, parseInt(value));
31 break;
32 default:
33 ElementController.setProperty(el, p, value);
34 }
35 }
36 }
37}); \ No newline at end of file
diff --git a/js/controllers/elements/component-controller.js b/js/controllers/elements/component-controller.js
new file mode 100644
index 00000000..458e6b46
--- /dev/null
+++ b/js/controllers/elements/component-controller.js
@@ -0,0 +1,12 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 ElementController = require("js/controllers/elements/element-controller").ElementController;
9
10exports.ComponentController = Montage.create(ElementController, {
11
12});
diff --git a/js/controllers/elements/controller-factory.js b/js/controllers/elements/controller-factory.js
new file mode 100644
index 00000000..a772eb16
--- /dev/null
+++ b/js/controllers/elements/controller-factory.js
@@ -0,0 +1,49 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage;
8
9var BlockController = require("js/controllers/elements/block-controller").BlockController,
10 StageController = require("js/controllers/elements/stage-controller").StageController,
11 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController,
12 ImageController = require("js/controllers/elements/image-controller").ImageController,
13 VideoController = require("js/controllers/elements/video-controller").VideoController,
14 ComponentController = require("js/controllers/elements/component-controller").ComponentController,
15 CanvasController = require("js/controllers/elements/canvas-controller").CanvasController;
16
17exports.ControllerFactory = Montage.create(Montage, {
18
19 getController: {
20 value: function(value) {
21 if(!value) return;
22
23 try {
24 value = value.toLowerCase();
25
26 if(value.indexOf("block") !== -1) {
27 return BlockController;
28 } else if(value.indexOf("stage") !== -1) {
29 return StageController;
30 } else if(value.indexOf("shape") !== -1) {
31 return ShapesController;
32 } else if(value.indexOf("canvas") !== -1) {
33 return CanvasController;
34 } else if(value.indexOf("component") !== -1) {
35 return ComponentController;
36 } else if(value.indexOf("media") !== -1) {
37 console.log("create media controller");
38 } else if(value.indexOf("image") !== -1) {
39 return ImageController;
40 } else if(value.indexOf("video") !== -1) {
41 return VideoController;
42 }
43 } catch (err) {
44 console.log("Could not create Controller Factory " + err);
45 }
46 }
47 }
48
49}); \ No newline at end of file
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js
new file mode 100644
index 00000000..f254220c
--- /dev/null
+++ b/js/controllers/elements/element-controller.js
@@ -0,0 +1,263 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 NJComponent = require("js/lib/nj-base").NJComponent;
9
10var ElementController = exports.ElementController = Montage.create(NJComponent, {
11
12 addElement: {
13 value: function(el, styles) {
14 this.application.ninja.currentDocument.documentRoot.appendChild(el);
15 this.application.ninja.stylesController.setElementStyles(el, styles);
16 }
17 },
18
19 removeElement: {
20 value: function(el) {
21 el.parentNode.removeChild(el);
22 }
23 },
24
25 getProperty: {
26 value: function(el, prop, fallbackOnComputed, isStageElement) {
27 return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement);
28 }
29 },
30
31 setProperty: {
32 value: function(el, p, value) {
33 this.application.ninja.stylesController.setElementStyle(el, p, value);
34 }
35 },
36
37 setProperties: {
38 value: function(el, props, index) {
39 for(var p in props) {
40 this.application.ninja.stylesController.setElementStyle(el, p, props[p][index]);
41 }
42 }
43 },
44
45 setAttribute: {
46 value: function(el, att, value) {
47 if(att === "id") {
48 if(value === "") {
49 el.setAttribute(att, value);
50 return;
51 }
52
53 // Then check if this is a valid id by the following spec: http://www.w3.org/TR/REC-html40/types.html#h-6.2
54 var regexID = /^([a-zA-Z])+([a-zA-Z0-9_\.\:\-])+/;
55 if(!regexID.test(value)) {
56 alert("Invalid ID");
57 return;
58 } else if (this.application.ninja.currentDocument._document.getElementById(value) !== null) {
59 alert("The following ID: " + value + " is already in Use");
60 }
61
62 }
63
64 el.setAttribute(att, value);
65 }
66 },
67
68 //--------------------------------------------------------------------------------------------------------
69 // Routines to get/set color properties
70 getColor: {