aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-28 22:46:07 -0700
committerValerio Virgillito2012-06-28 22:46:07 -0700
commit1b6202d3cd517480aebafdfe97e9b89600d715ce (patch)
treedd4478eea3294a7a41d150247b3eac8791acc1ee
parent35af74aa558a642af8bcdbd8c18098b94771537d (diff)
downloadninja-1b6202d3cd517480aebafdfe97e9b89600d715ce.tar.gz
video autopsy fix: moving the event handler on creation
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
-rwxr-xr-xjs/controllers/elements/video-controller.js13
-rwxr-xr-xjs/tools/TagTool.js24
2 files changed, 23 insertions, 14 deletions
diff --git a/js/controllers/elements/video-controller.js b/js/controllers/elements/video-controller.js
index 44ba5aa1..c36752f5 100755
--- a/js/controllers/elements/video-controller.js
+++ b/js/controllers/elements/video-controller.js
@@ -28,19 +28,6 @@ exports.VideoController = Montage.create(ElementController, {
28 value: function(el, p, value) { 28 value: function(el, p, value) {
29 switch(p) { 29 switch(p) {
30 case "src": 30 case "src":
31
32 //TODO: Move this to the location where the element is created
33 el.addEventListener('canplay', function(e) {
34 //TODO: Figure out why the video must be seeked to the end before pausing
35 var time = Math.ceil(this.duration);
36 //Trying to display the last frame (doing minus 2 seconds if long video)
37 if (time > 2) this.currentTime = time - 2;
38 else if (time > 1) this.currentTime = time - 1;
39 else this.currentTime = time || 0;
40 //Pauing video
41 this.pause();
42 }, false);
43
44 el.setAttribute(p, value); 31 el.setAttribute(p, value);
45 break; 32 break;
46 case "poster": 33 case "poster":
diff --git a/js/tools/TagTool.js b/js/tools/TagTool.js
index 31918f92..27665ee6 100755
--- a/js/tools/TagTool.js
+++ b/js/tools/TagTool.js
@@ -86,11 +86,15 @@ exports.TagTool = Montage.create(DrawingTool, {
86 // Create the element 86 // Create the element
87 if(this.options.selectedElement === "custom") { 87 if(this.options.selectedElement === "custom") {
88 element = document.application.njUtils.make(this.options.customName.value, null, this.application.ninja.currentDocument); 88 element = document.application.njUtils.make(this.options.customName.value, null, this.application.ninja.currentDocument);
89
90 } else { 89 } else {
91 element = document.application.njUtils.make(this.options.selectedElement, null, this.application.ninja.currentDocument); 90 element = document.application.njUtils.make(this.options.selectedElement, null, this.application.ninja.currentDocument);
92 } 91 }
93 92
93 // Adding a canplay event to videos to pause them and prevent autoplay on stage
94 if(this.options.selectedElement === "video") {
95 element.addEventListener("canplay", this, false);
96 }
97
94 // Create the styles 98 // Create the styles
95 styles = document.application.njUtils.stylesFromDraw(element, ~~drawData.width, ~~drawData.height, drawData); 99 styles = document.application.njUtils.stylesFromDraw(element, ~~drawData.width, ~~drawData.height, drawData);
96 100
@@ -109,6 +113,24 @@ exports.TagTool = Montage.create(DrawingTool, {
109 // Add the element and styles 113 // Add the element and styles
110 this.application.ninja.elementMediator.addElements(element, styles); 114 this.application.ninja.elementMediator.addElements(element, styles);
111 } 115 }
116 },
117
118 handleCanplay: {
119 value: function(event) {
120 //TODO: Figure out why the video must be seeked to the end before pausing
121 var time = Math.ceil(this.duration);
122 //Trying to display the last frame (doing minus 2 seconds if long video)
123 if (time > 2) {
124 this.currentTime = time - 2;
125 } else if (time > 1) {
126 this.currentTime = time - 1;
127 } else {
128 this.currentTime = time || 0;
129 }
130 //Pauing video
131 event.target.pause();
132 }
112 } 133 }
134
113}); 135});
114 136