aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Reid2012-03-21 15:40:33 -0700
committerJon Reid2012-03-21 15:40:33 -0700
commit2d9cb9ca8f6beb661a3d904b5125afa8243661de (patch)
tree99a76e567aa910ebfee27ae58f257e7551ab5c09
parent3669eea4bde3518ce080048e9f53d2dd111fd8be (diff)
downloadninja-2d9cb9ca8f6beb661a3d904b5125afa8243661de.tar.gz
Timeline: First integration of drag and drop of layers.
-rw-r--r--js/panels/Timeline/DragDrop.js136
-rw-r--r--js/panels/Timeline/Layer.reel/Layer.html34
-rw-r--r--js/panels/Timeline/Layer.reel/Layer.js8
-rw-r--r--js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js22
4 files changed, 178 insertions, 22 deletions
diff --git a/js/panels/Timeline/DragDrop.js b/js/panels/Timeline/DragDrop.js
new file mode 100644
index 00000000..55ee3ab4
--- /dev/null
+++ b/js/panels/Timeline/DragDrop.js
@@ -0,0 +1,136 @@
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;
8var Composer = require("montage/ui/composer/composer").Composer;
9
10exports.DragDropComposer = Montage.create(Composer, {
11
12 draggable: {
13 value: true
14 },
15
16 droppable: {
17 value: true
18 },
19
20 identifier: {
21 value: "generic"
22 },
23
24 _dragover: {
25 value: false
26 },
27
28 load: {
29 value: function() {
30 //TODO: to make this work even better check to see if this is a component or not
31 //right now it does not support data-montage id's
32 this.element.addEventListener("mouseover", this, true);
33 this.element.addEventListener("mouseout", this, true);
34 this.component.element.addEventListener("dragenter", this, true);
35 this.component.element.addEventListener("dragleave", this, true);
36 this.component.element.addEventListener("dragend", this, true);
37 this.component.element.addEventListener("drop", this, true);
38 this.component.element.addEventListener("dragover", this, true);
39 this.component.element.addEventListener("dragstart", this, true);
40 }
41 },
42
43 unload: {
44 value: function() {
45 this.element.removeEventListener("mouseover", this, true);
46 this.element.removeEventListener("mouseout", this, true);
47 this.component.element.removeEventListener("dragenter", this, true);
48 this.component.element.removeEventListener("dragleave", this, true);
49 this.component.element.removeEventListener("dragend", this, true);
50 this.component.element.removeEventListener("drop", this, true);
51 this.component.element.removeEventListener("dragover", this, true);
52 this.component.element.removeEventListener("dragstart", this, true);
53 }
54 },
55
56 captureMouseover: {
57 value: function(e) {
58 if(this.draggable) {
59 this.component.element.draggable = true;
60 }
61 }
62 },
63
64 captureMouseout: {
65 value: function(e) {
66 this.component.element.draggable = false;
67 }
68 },
69
70 /* ------ Drag Drop Events ------- */
71
72 // This Function will determine what is being moved
73 captureDragstart: {
74 value:function(e) {
75 e.dataTransfer.effectAllowed = 'move';
76 e.dataTransfer.setData('Text', this.identifier);
77 this.component.element.classList.add("dragging");
78 this.component.application.ninja.componentBeingDragged = this.component;
79 }
80 },
81
82 captureDragenter: {
83 value: function(e) {
84
85 }
86 },
87
88 captureDragover: {
89 value:function(e) {
90 e.preventDefault();
91 e.stopImmediatePropagation();
92 if (!this._dragover) {
93 this._dragover = true;
94 this.component.element.classList.add("dragOver");
95 }
96 }
97 },
98
99 captureDragleave: {
100 value: function(e) {
101 if (this._dragover) {
102 this._dragover = false;
103 this.component.element.classList.remove("dragOver");
104 }
105 }
106 },
107
108 captureDrop: {
109 value:function(e) {
110 e.stopPropagation(); // Stops some browsers from redirecting.
111 e.preventDefault();
112 if (this._dragover) {
113 this._dragover = false;
114 this.component.element.classList.remove("dragOver");
115 if (this.identifier === e.dataTransfer.getData("Text")) {
116 if(this.component.application.ninja.componentBeingDragged !== this.component) {
117 dropEvent = document.createEvent("CustomEvent");
118 dropEvent.initCustomEvent("dropped", true, false, null);
119 dropEvent.draggedComponent = this.component.application.ninja.componentBeingDragged;
120 dropEvent.droppedComponent = this.component;
121 this.component.dispatchEvent(dropEvent);
122 }
123 }
124 this.component.application.ninja.componentBeingDragged = null;
125 }
126
127 }
128 },
129
130 captureDragend: {
131 value:function(e) {
132 this.component.element.classList.remove("dragging");
133 }
134 }
135
136}); \ No newline at end of file
diff --git a/js/panels/Timeline/Layer.reel/Layer.html b/js/panels/Timeline/Layer.reel/Layer.html
index c8e31fad..ef98bdd5 100644
--- a/js/panels/Timeline/Layer.reel/Layer.html
+++ b/js/panels/Timeline/Layer.reel/Layer.html
@@ -22,7 +22,8 @@
22 "positionCollapser" : {"@" : "positionCollapser"}, 22 "positionCollapser" : {"@" : "positionCollapser"},
23 "transformCollapser" : {"@" : "transformCollapser"}, 23 "transformCollapser" : {"@" : "transformCollapser"},
24 "styleCollapser" : {"@" : "styleCollapser"}, 24 "styleCollapser" : {"@" : "styleCollapser"},
25 "clickerMain" : {"#" : "clicker-main"} 25 "clickerMain" : {"#" : "clicker-main"},
26 "myLabel" : {"#" : "myLabel"}
26 } 27 }
27 }, 28 },
28 "dtext1" : { 29 "dtext1" : {
@@ -314,7 +315,34 @@
314 "oneway" : false 315 "oneway" : false
315 } 316 }
316 } 317 }
317 } 318 },
319
320 "DragDrop": {
321 "module": "js/panels/Timeline/DragDrop.js",
322 "name": "DragDropComposer",
323 "properties": {
324 "element": {"#": "myLabel"},
325 "component": {"@": "owner"}
326 },
327 "listeners": [
328 {
329 "type": "dragStart",
330 "listener": {"@": "owner"}
331 },
332 {
333 "type": "dropHover",
334 "listener": {"@": "owner"}
335 },
336 {
337 "type": "dropped",
338 "listener": {"@": "owner"}
339 },
340 {
341 "type": "dropEnd",
342 "listener": {"@": "owner"}
343 }
344 ]
345 }
318 346
319 347
320 } 348 }
@@ -323,7 +351,7 @@
323 <body> 351 <body>
324 352
325 <div data-montage-id="layer" class="container-layer"> 353 <div data-montage-id="layer" class="container-layer">
326 <div class="label-layer"> 354 <div class="label-layer" data-montage-id="myLabel">
327 <span class="collapsible-label" data-montage-id="layer-label-text" spellcheck="false">Label</span> 355 <span class="collapsible-label" data-montage-id="layer-label-text" spellcheck="false">Label</span>
328 <span class="collapsible-clicker collapsible-collapsed" data-montage-id="clicker-main"></span> 356 <span class="collapsible-clicker collapsible-collapsed" data-montage-id="clicker-main"></span>
329 <div class="cssbutton button-lock"></div> 357 <div class="cssbutton button-lock"></div>
diff --git a/js/panels/Timeline/Layer.reel/Layer.js b/js/panels/Timeline/Layer.reel/Layer.js
index fcdbcd22..bddfcd3e 100644
--- a/js/panels/Timeline/Layer.reel/Layer.js
+++ b/js/panels/Timeline/Layer.reel/Layer.js
@@ -505,6 +505,9 @@ var Layer = exports.Layer = Montage.create(Component, {
505 // Add mousedown listener to set isActive 505 // Add mousedown listener to set isActive
506 this.element.addEventListener("mousedown", this, false); 506 this.element.addEventListener("mousedown", this, false);
507 this.element.addEventListener("click", this, false); 507 this.element.addEventListener("click", this, false);
508
509 // Drag and drop event hanlders
510 this.element.addEventListener("dropped", this, false);
508 511
509 } 512 }
510 }, 513 },
@@ -783,6 +786,11 @@ var Layer = exports.Layer = Montage.create(Component, {
783 this.triggerOutgoingBinding(); 786 this.triggerOutgoingBinding();
784 } 787 }
785 }, 788 },
789 handleDropped : {
790 value: function(event) {
791