From c37f2cb15b90d7315e9580fee1ae7f6e0694052c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 28 Jun 2012 16:50:46 -0700 Subject: Preventing video playback on open This stops all videos from playing on open file. The same fix needs to be applied when an users sets autoplay in the PI. --- js/document/views/design.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'js/document/views/design.js') diff --git a/js/document/views/design.js b/js/document/views/design.js index 6a60e1f9..fea607ef 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -285,7 +285,8 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { userStyles, stags = this.document.getElementsByTagName('style'), ltags = this.document.getElementsByTagName('link'), i, orgNodes, - scripttags = this.document.getElementsByTagName('script'); + scripttags = this.document.getElementsByTagName('script'), + videotags = this.document.getElementsByTagName('video'); //Temporarily checking for disabled special case (we must enabled for Ninja to access styles) this.ninjaDisableAttribute(stags); this.ninjaDisableAttribute(ltags); @@ -308,10 +309,28 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { } } } - + //Checking for video tags + if (videotags.length > 0) { + //Looping through all video tags + for (i = 0; i < videotags.length; i++) { + //Stopping all videos from playing + if (videotags[i].getAttribute && videotags[i].getAttribute('autoplay') !== null) { + //Stopping the video on open + videotags[i].addEventListener('canplay', function(e) { + //TODO: Figure out why the video must be seeked to the end before pausing + var time = Math.ceil(this.duration); + //Trying to display the last frame (doing minus 2 seconds if long video) + if (time > 2) this.currentTime = time - 2; + else if (time > 1) this.currentTime = time - 1; + else this.currentTime = time || 0; + //Pauing video + this.pause(); + }, false); + } + } + } // Assign the modelGenerator reference from the template to our own modelGenerator this.document.modelGenerator = ElementModel.modelGenerator; - //Checking for script tags then parsing check for montage and webgl if (scripttags.length > 0) { //Checking and initializing webGL -- cgit v1.2.3