From: Michael Dale Date: Thu, 12 Nov 2009 16:07:32 +0000 (+0000) Subject: * some re-factoring and comments clean up X-Git-Tag: 1.31.0-rc.0~38843 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=516656025da8acf00b3a88cf8c2b1f0b4b1710b9;p=lhc%2Fweb%2Fwiklou.git * some re-factoring and comments clean up --- diff --git a/js2/mwEmbed/libEmbedVideo/embedVideo.js b/js2/mwEmbed/libEmbedVideo/embedVideo.js index ce8f4cd006..69ae853f44 100644 --- a/js2/mwEmbed/libEmbedVideo/embedVideo.js +++ b/js2/mwEmbed/libEmbedVideo/embedVideo.js @@ -126,83 +126,80 @@ function mv_video_embed(swap_done_callback, force_id){ mvEmbed = { //flist stores the set of functions to run after the video has been swapped in. flist:new Array(), - init:function( swap_done_callback, force_id ){ - if(swap_done_callback) - mvEmbed.flist.push( swap_done_callback ); - - //get mv_embed location if it has not been set - js_log('mv_video_embed:: ' + mw.version); + init:function( swap_callback, force_id ){ + var _this = this; + + if(swap_callback) + mvEmbed.flist.push( swap_callback ); + // Get mv_embed location if it has not been set + js_log('mvEmbed:init: ' + mw.version); var loadPlaylistLib=false; - var eAction = function(this_elm){ - js_log( "Do SWAP: " + $j(this_elm).attr("id") + ' tag: '+ this_elm.tagName.toLowerCase() ); - - if( $j(this_elm).attr("id") == '' ){ - $j(this_elm).attr("id", 'v'+ mw.player_list.length); - } - //store a global reference to the id - mw.player_list.push( $j(this_elm).attr("id") ); - - //if video doSwap - switch( this_elm.tagName.toLowerCase()){ - case 'video': - var videoInterface = new embedVideo(this_elm); - mvEmbed.swapEmbedVideoElement( this_elm, videoInterface ); - break; - case 'audio': - var videoInterface = new embedVideo(this_elm); - mvEmbed.swapEmbedVideoElement( this_elm, videoInterface ); - break; - case 'playlist': - loadPlaylistLib=true; - break; - } - } + // Setup the selector (should be a configuration option) if( force_id == null && force_id != '' ){ var j_selector = 'video,audio,playlist'; }else{ var j_selector = '#' + force_id; - } - - js_log('j_selector:: ' + j_selector); - //process selected elements: - //ie8 does not play well with the jQuery video,audio,playlist selector use native: + } + js_log('EmbedVideo:: rewrite j_selector:: ' + j_selector); + // Process selected elements: + // ie8 does not play well with the jQuery video,audio,playlist selector use native: if($j.browser.msie && $j.browser.version >= 8){ jtags = j_selector.split(','); - for( var i=0; i < jtags.length; i++){ - $j( document.getElementsByTagName( jtags[i] )).each(function(){ - eAction(this); - }); + for( var i=0; i < jtags.length; i++){ + if( jtags[i].indexOf('#') === 1){ + _this.doElementSwap( $j( j_selector ).get(0) ); + }else{ + $j( document.getElementsByTagName( jtags[i] )).each(function(){ + _this.doElementSwap( this ); + }); + } } }else{ $j( j_selector ).each(function(){ - eAction(this); + _this.doElementSwap( this ); }); - } - if(loadPlaylistLib){ - mvJsLoader.doLoad([ - 'mvPlayList', - '$j.ui', //include dialog for pop-ing up thigns - '$j.ui.dialog' - ], function(){ - //deal with each playlist instance - $j('playlist').each(function(){ - //create new playlist interface: - var plObj = new mvPlayList( this ); - mvEmbed.swapEmbedVideoElement(this, plObj); + } + // Check clips ready to call swap_callback now in ( mvEmbed.flist ) + this.checkClipsReady(); + }, + doElementSwap: function( element ){ + if( $j(element).attr("id") == '' ){ + $j(element).attr("id", 'v'+ mw.player_list.length); + } + js_log( "mvEmbed::rewrite:: " + $j( element ).attr("id") + ' tag: '+ element.tagName.toLowerCase() ); + // Store a global reference to the id + mw.player_list.push( $j( element ).attr("id") ); + + switch( element.tagName.toLowerCase()){ + case 'video': + case 'audio': + var videoInterface = new embedVideo( element ); + mvEmbed.swapEmbedVideoElement( element, videoInterface ); + break; + case 'playlist': + // Make sure we have the necessary play-list libs loaded: + mvJsLoader.doLoad([ + 'mvPlayList', + '$j.ui', //Include dialog for pop-ing up things + '$j.ui.dialog' + ], function(){ + var plObj = new mvPlayList( element ); + mvEmbed.swapEmbedVideoElement( element, plObj ); var added_height = plObj.pl_layout.title_bar_height + plObj.pl_layout.control_height; - //move into a blocking display container with height + controls + title height: - $j('#'+plObj.id).wrap('
'); + // Wrap a blocking display container with height + controls + title height: + $j('#'+plObj.id).wrap('
'); }); - }); - } - this.checkClipsReady(); + break; + } }, /* * swapEmbedVideoElement * takes a video element as input and swaps it out with * an embed video interface based on the video_elements attributes + * @param {Element} video_element + * @param {Object} */ swapEmbedVideoElement:function(video_element, videoInterface){ js_log('do swap ' + videoInterface.id + ' for ' + video_element); @@ -229,35 +226,42 @@ mvEmbed = { } } //string -> boolean: - if(embed_video[method]=="false")embed_video[method]=false; - if(embed_video[method]=="true")embed_video[method]=true; + if(embed_video[method]=="false") + embed_video[method]=false; + + if(embed_video[method]=="true") + embed_video[method]=true; } - ///js_log('did vI style'); - //now swap out the video element for the embed_video obj: - $j(video_element).after(embed_video).remove(); - //js_log('did swap'); + + // Now swap out the video element for the embed_video obj: + $j(video_element).after(embed_video).remove(); $j('#'+embed_video.id).get(0).on_dom_swap(); - // now that "embed_video" is stable, do more initialization (if we are ready) + // Now that "embed_video" is stable, do more initialization (if we are ready) if($j('#'+embed_video.id).get(0).loading_external_data == false && $j('#'+embed_video.id).get(0).init_with_sources_loadedDone == false){ //load and set ready state since source are available: $j('#'+embed_video.id).get(0).init_with_sources_loaded(); - } - + } js_log('done with child: ' + embed_video.id + ' len:' + mw.player_list.length); return true; }, - //this should not be needed. + /** + * Check if Clips in the player_list are ready and runs + * any associated queued functions + */ checkClipsReady : function(){ //js_log('checkClipsReady'); var is_ready=true; - for(var i=0; i < mw.player_list.length; i++){ + for(var i=0; i < mw.player_list.length; i++){ if( $j('#'+mw.player_list[i]).length !=0){ - var cur_vid = $j('#'+mw.player_list[i]).get(0); + var cur_vid = $j('#'+mw.player_list[i]).get(0); + is_ready = ( cur_vid.ready_to_play ) ? is_ready : false; + if( !is_ready && cur_vid.load_error ){ is_ready=true; + // Update the video with its load error: $j(cur_vid).html( cur_vid.load_error ); } } @@ -280,18 +284,14 @@ mvEmbed = { /** * mediaSource class represents a source for a media element. - * @param {String} type MIME type of the source. - * @param {String} uri URI of the source. + * @param {Element} element: MIME type of the source. * @constructor */ -function mediaSource(element) -{ +function mediaSource(element){ this.init(element); } - -mediaSource.prototype = -{ +mediaSource.prototype = { /** MIME type of the source. */ mime_type:null, /** URI of the source. */ @@ -312,18 +312,19 @@ mediaSource.prototype = id:null, start_ntp:null, end_ntp:null, - - init : function(element) - { + /** + * MediaSource constructor: + */ + init : function(element){ //js_log('adding mediaSource: ' + element); this.src = $j(element).attr('src'); this.marked_default = false; if ( element.tagName.toLowerCase() == 'video') this.marked_default = true; - //set default URLTimeEncoding if we have a time url: - //not ideal way to discover if content is on an oggz_chop server. - //should check some other way. + // Set default URLTimeEncoding if we have a time url: + // not ideal way to discover if content is on an oggz_chop server. + // should check some other way. var pUrl = parseUri ( this.src ); if(typeof pUrl['queryKey']['t'] != 'undefined'){ this['URLTimeEncoding']=true; @@ -343,20 +344,25 @@ mediaSource.prototype = else this.mime_type = this.detectType(this.src); - //set the title if unset: + // Set the title if unset: if( !this.title ) this.title = this.mime_type; this.parseURLDuration(); }, + /** + * Update Source title via Element + * @param Element: + */ updateSource:function(element){ //for now just update the title: if ($j(element).attr("title")) this.title = $j(element).attr("title"); }, - /** updates the src time and start & end - * @param {String} start_time in NTP format - * @param {String} end_time in NTP format + /** + * Updates the src time and start & end + * @param {String} start_time: in NTP format + * @param {String} end_time: in NTP format */ updateSrcTime:function (start_ntp, end_ntp){ //js_log("f:updateSrcTime: "+ start_ntp+'/'+ end_ntp + ' from org: ' + this.start_ntp+ '/'+this.end_ntp); @@ -376,52 +382,54 @@ mediaSource.prototype = this.parseURLDuration(); } }, - setDuration:function (duration) - { + /** + * Sets the duration and sets the end time if unset + * @param {Float} duration: in seconds + */ + setDuration:function (duration){ this.duration = duration; if(!this.end_ntp){ this.end_ntp = seconds2npt( this.start_offset + duration); } }, - /** MIME type accessor function. - @return the MIME type of the source. - @type String + /** + * MIME type accessor function. + * @return {String} the MIME type of the source. */ - getMIMEType : function() - { + getMIMEType : function(){ return this.mime_type; }, - /** URI accessor function. - * @param int seek_time_sec (used to adjust the URI for url based seeks) - @return the URI of the source. - @type String + /** URI function. + * @param {Number} seek_time_sec Int: Used to adjust the URI for url based seeks) + * @return {String} the URI of the source. */ - getURI : function( seek_time_sec ) - { - if( !seek_time_sec || !this.URLTimeEncoding ){ - return this.src; - } - if(!this.end_ntp){ - var endvar = ''; - }else{ - var endvar = '/'+ this.end_ntp; - } - return getURLParamReplace(this.src, { 't': seconds2npt( seek_time_sec )+endvar } ); ; + getURI : function( seek_time_sec ){ + if( !seek_time_sec || !this.URLTimeEncoding ){ + return this.src; + } + if(!this.end_ntp){ + var endvar = ''; + }else{ + var endvar = '/'+ this.end_ntp; + } + return getURLParamReplace(this.src, + { + 't': seconds2npt( seek_time_sec ) + endvar + } + ); }, /** Title accessor function. @return the title of the source. @type String */ - getTitle : function() - { + getTitle : function(){ return this.title; }, /** Index accessor function. @return the source's index within the enclosing mediaElement container. @type Integer */ - getIndex : function() - { + getIndex : function(){ return this.index; }, /* @@ -450,22 +458,18 @@ mediaSource.prototype = this.end_ntp = seconds2npt( parseInt(this.duration) + parseInt(this.start_offset) ); } } - } - //else nothing to parse just keep whatever info we already have - - //js_log('f:parseURLDuration() for:' + this.src + ' d:' + this.duration); + } }, /** Attempts to detect the type of a media file based on the URI. * @param {String} uri URI of the media file. - * @returns The guessed MIME type of the file. + * @returns {String} The guessed MIME type of the file. * @type String */ - detectType:function(uri) - { - //@@todo if media is on the same server as the javascript or we have mv_proxy configured - //we can issue a HEAD request and read the mime type of the media... + detectType:function(uri){ + //@@todo if media is on the same server as the javascript + // we can issue a HEAD request and read the mime type of the media... // (this will detect media mime type independently of the url name) - //http://www.jibbering.com/2002/4/httprequest.html (this should be done by extending jquery's ajax objects) + // http://www.jibbering.com/2002/4/httprequest.html (this should be done by extending jquery's ajax objects) var end_inx = (uri.indexOf('?')!=-1)? uri.indexOf('?') : uri.length; var no_param_uri = uri.substr(0, end_inx); switch( no_param_uri.substr(no_param_uri.lastIndexOf('.'),4).toLowerCase() ){ @@ -489,20 +493,21 @@ mediaSource.prototype = } }; -/** A media element corresponding to a