3 * for details see: http://metavid.org/wiki/index.php/Mv_embed
5 * All Metavid Wiki code is Released under the GPL2
6 * for more info visit http://metavid.org/wiki/Code
8 * @url http://metavid.org
11 * http://stevenlevithan.com/demo/parseuri/js/
13 * config values you can manually set the location of the mv_embed folder here
14 * (in cases where media will be hosted in a different place than the embedding page)
17 //fix multiple instances of mv_embed (ie include twice from two different servers)
19 if( MV_EMBED_VERSION
){
22 //used to grab fresh copies of scripts. (should be changed on commit)
23 var MV_EMBED_VERSION
= '1.0r19';
26 * Configuration variables (can be set from some precceding script)
27 * set up mwConfig global overide any of the defaultMwConfig values:
28 * @@ more config valuse on the way ;)
30 var defaultMwConfig
= {
32 'video_size':'400x300'
38 //install the default config values for anything not set in mwConfig
39 checkDefaultMwConfig();
41 //whether or not to load java from an iframe.
42 //note: this is necessary for remote embedding because of java security model)
44 var mv_java_iframe
= true;
46 //for when useing mv_embed with script-loader in root mediawiki path
47 var mediaWiki_mvEmbed_path
= 'js2/mwEmbed/';
49 var global_player_list
= new Array(); //the global player list per page
50 var global_req_cb
= new Array(); //the global request callback array
51 var _global
= this; //global obj
52 var mv_init_done
=false;
53 var global_cb_count
=0;
55 /*parseUri class parses URIs:*/
56 var parseUri=function(d
){var o
=parseUri
.options
,value
=o
.parser
[o
.strictMode
?"strict":"loose"].exec(d
);for(var i
=0,uri
={};i
<14;i
++){uri
[o
.key
[i
]]=value
[i
]||""}uri
[o
.q
.name
]={};uri
[o
.key
[12]].replace(o
.q
.parser
,function(a
,b
,c
){if(b
)uri
[o
.q
.name
][b
]=c
});return uri
};parseUri
.options
={strictMode
:false,key
:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q
:{name
:"queryKey",parser
:/(?:^|&)([^&=]*)=?([^&]*)/g},parser
:{strict
:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose
:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
59 //get mv_embed location if it has not been set
61 var mv_embed_path
= getMvEmbedPath();
64 //setup the skin path:
65 var mv_jquery_skin_path
= mv_embed_path
+ 'jquery/jquery.ui/themes/base/';
66 var mv_skin_img_path
= mv_embed_path
+ 'skins/' + mwConfig
['skin_name'] + '/images/';
67 var mv_default_thumb_url
= mv_skin_img_path
+ 'vid_default_thumb.jpg';
70 //init the global Msg if not already
71 if(!gMsg
){var gMsg
={};}
74 function loadGM( msgSet
){
76 gMsg
[ i
] = msgSet
[i
];
80 //all default msg in [English] should be overwritten by the CMS language msg system.
82 "loading_txt" : "loading <blink>...<\/blink>",
83 "loading_title" : "Loading...",
84 "size-gigabytes" : "$1 GB",
85 "size-megabytes" : "$1 MB",
86 "size-kilobytes" : "$1 K",
91 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
92 * any file _not_ listed here won't be auto-loadable
93 * @path the path to the file (or set of files) with ending slash
94 * @gClasses the set of classes
95 * if an array $j.className become jquery.className.js
96 * if an asssociative object then key => value paris are used
98 if(typeof mvAutoLoadClasses
== 'undefined')
99 mvAutoLoadClasses
= {};
101 //the script that loads the classet
102 function lcPaths( classSet
){
103 for(var i
in classSet
){
104 mvAutoLoadClasses
[i
] = classSet
[i
];
108 function mvGetClassPath(k
){
109 if( mvAutoLoadClasses
[k
] ){
110 //js_log('got classpath:' + k + ' : '+ mvClassPaths[k]);
111 return mvAutoLoadClasses
[k
];
113 return js_error('could not find path for requested class ' + k
);
116 if(typeof mvCssPaths
== 'undefined')
119 function lcCssPath(cssSet
){
120 for(var i
in cssSet
){
121 mvCssPaths
[i
]= mv_embed_path
+ cssSet
[i
];
126 * -- Load Class Paths --
128 * MUST BE VALID JSON (NOT JS)
129 * is used by the scriptloader to autoLoad classes (so we only define this once for php & javascript)
131 * this is more verbose than earlier version that compressed paths
132 * but its all good gziping help compress repetative path strings
135 * right now php AutoLoader only reads this mv_embed.js file
136 * in the future we could have multiple lcPath calls that php reads
137 * (if our autoloading class list becomes too long) just have to add thouse
138 * files to the jsAutoLoader file list.
141 "mv_embed" : "mv_embed.js",
142 "window.jQuery" : "jquery/jquery-1.3.2.js",
143 "$j.fn.pngFix" : "jquery/plugins/jquery.pngFix.js",
144 "$j.fn.autocomplete": "jquery/plugins/jquery.autocomplete.js",
145 "$j.fn.hoverIntent" : "jquery/plugins/jquery.hoverIntent.js",
146 "$j.fn.datePicker" : "jquery/plugins/jquery.datePicker.js",
147 "$j.ui" : "jquery/jquery.ui/ui/ui.core.js",
148 "$j.fn.ColorPicker" : "libClipEdit/colorpicker/js/colorpicker.js",
149 "$j.Jcrop" : "libClipEdit/Jcrop/js/jquery.Jcrop.js",
150 "$j.fn.simpleUploadForm": "libAddMedia/simpleUploadForm.js",
152 "baseSkin" : "skins/baseSkin.js",
153 "kskin" : "skins/kskin/kskin.js",
154 "mvpcf" : "skins/mvpcf/mvpcf.js",
156 "$j.secureEvalJSON" : "jquery/plugins/jquery.secureEvalJSON.js",
157 "$j.cookie" : "jquery/plugins/jquery.cookie.js",
158 "$j.contextMenu" : "jquery/plugins/jquery.contextMenu.js",
160 "$j.effects.blind" : "jquery/jquery.ui/ui/effects.blind.js",
161 "$j.effects.drop" : "jquery/jquery.ui/ui/effects.drop.js",
162 "$j.effects.pulsate" : "jquery/jquery.ui/ui/effects.pulsate.js",
163 "$j.effects.transfer" : "jquery/jquery.ui/ui/effects.transfer.js",
164 "$j.ui.droppable" : "jquery/jquery.ui/ui/ui.droppable.js",
165 "$j.ui.slider" : "jquery/jquery.ui/ui/ui.slider.js",
166 "$j.effects.bounce" : "jquery/jquery.ui/ui/effects.bounce.js",
167 "$j.effects.explode" : "jquery/jquery.ui/ui/effects.explode.js",
168 "$j.effects.scale" : "jquery/jquery.ui/ui/effects.scale.js",
169 "$j.ui.datepicker" : "jquery/jquery.ui/ui/ui.datepicker.js",
170 "$j.ui.progressbar" : "jquery/jquery.ui/ui/ui.progressbar.js",
171 "$j.ui.sortable" : "jquery/jquery.ui/ui/ui.sortable.js",
172 "$j.effects.clip" : "jquery/jquery.ui/ui/effects.clip.js",
173 "$j.effects.fold" : "jquery/jquery.ui/ui/effects.fold.js",
174 "$j.effects.shake" : "jquery/jquery.ui/ui/effects.shake.js",
175 "$j.ui.dialog" : "jquery/jquery.ui/ui/ui.dialog.js",
176 "$j.ui.resizable" : "jquery/jquery.ui/ui/ui.resizable.js",
177 "$j.ui.tabs" : "jquery/jquery.ui/ui/ui.tabs.js",
178 "$j.effects.core" : "jquery/jquery.ui/ui/effects.core.js",
179 "$j.effects.highlight" : "jquery/jquery.ui/ui/effects.highlight.js",
180 "$j.effects.slide" : "jquery/jquery.ui/ui/effects.slide.js",
181 "$j.ui.accordion" : "jquery/jquery.ui/ui/ui.accordion.js",
182 "$j.ui.draggable" : "jquery/jquery.ui/ui/ui.draggable.js",
183 "$j.ui.selectable" : "jquery/jquery.ui/ui/ui.selectable.js",
185 "mvFirefogg" : "libAddMedia/mvFirefogg.js",
186 "mvAdvFirefogg" : "libAddMedia/mvAdvFirefogg.js",
187 "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
188 "remoteSearchDriver" : "libAddMedia/remoteSearchDriver.js",
189 "seqRemoteSearchDriver" : "libAddMedia/seqRemoteSearchDriver.js",
191 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
192 "mediaWikiSearch" : "libAddMedia/searchLibs/mediaWikiSearch.js",
193 "metavidSearch" : "libAddMedia/searchLibs/metavidSearch.js",
194 "archiveOrgSearch" : "libAddMedia/searchLibs/archiveOrgSearch.js",
195 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
197 "mvClipEdit" : "libClipEdit/mvClipEdit.js",
199 "embedVideo" : "libEmbedVideo/embedVideo.js",
200 "flashEmbed" : "libEmbedVideo/flashEmbed.js",
201 "genericEmbed" : "libEmbedVideo/genericEmbed.js",
202 "htmlEmbed" : "libEmbedVideo/htmlEmbed.js",
203 "javaEmbed" : "libEmbedVideo/javaEmbed.js",
204 "nativeEmbed" : "libEmbedVideo/nativeEmbed.js",
205 "quicktimeEmbed" : "libEmbedVideo/quicktimeEmbed.js",
206 "vlcEmbed" : "libEmbedVideo/vlcEmbed.js",
208 "mvPlayList" : "libSequencer/mvPlayList.js",
209 "mvSequencer" : "libSequencer/mvSequencer.js",
210 "mvFirefoggRender" : "libSequencer/mvFirefoggRender.js",
211 "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
213 "libTimedText" : "libTimedText/mvTextInterface.js"
217 //depencency mapping for css files for self contained included plugins:
219 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
220 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/css/colorpicker.css'
224 * Language Functions:
226 * These functions try to losely mirro the functionality of Language.php in mediaWiki
228 function gM( key
, args
) {
232 if(typeof args
== 'object' || typeof args
== 'array'){
234 //msg test replace arguments start at 1 insted of zero:
235 var rep
= '\$'+ ( parseInt(v
) + 1 );
236 ms
= ms
.replace( rep
, args
[v
]);
238 }else if(typeof args
=='string' || typeof args
=='number'){
239 ms
= ms
.replace(/\$1/, args
);
243 //key is missing return indication:
244 return '<' + key
+ '>';
248 * msgSet is either a string corresponding to a single msg to load
249 * or msgSet is an array with set of msg to load
251 function gMsgLoadRemote(msgSet
, callback
){
253 if(typeof msgSet
== 'object' ){
254 for(var i
in msgSet
){
255 ammessages
+= msgSet
[i
] + '|';
257 }else if(typeof msgSet
== 'string'){
258 ammessages
+= msgSet
;
260 if(ammessages
== ''){
261 js_log('gMsgLoadRemote::no msg set requested');
266 'meta':'allmessages',
267 'ammessages':ammessages
270 if(data
.query
.allmessages
){
271 var msgs
= data
.query
.allmessages
;
274 ld
[ msgs
[i
]['name'] ] = msgs
[i
]['*'];
278 //load the result into local msg var
284 * Format a size in bytes for output, using an appropriate
285 * unit (B, KB, MB or GB) according to the magnitude in question
287 * @param size Size to format
288 * @return string Plain text (not HTML)
290 function formatSize( size
) {
291 // For small sizes no decimal places necessary
298 // For MB and bigger two decimal places are smarter
302 msg
= 'size-gigabytes';
304 msg
= 'size-megabytes';
307 msg
= 'size-kilobytes';
312 //javascript does not let you do precession points in rounding
313 var p
= Math
.pow(10,round
);
314 var size
= Math
.round( size
* p
) / p
;
315 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
316 return gM( msg
, size
);
319 //gets the loading image:
320 function mv_get_loading_img( style
, class_attr
){
321 var style_txt
= (style
)?style
:'';
322 var class_attr
= (class_attr
)?'class="'+class_attr
+'"':'class="mv_loading_img"';
323 return '<div '+class_attr
+' style="' + style
+'"></div>';
326 function mv_set_loading(target
, load_id
){
327 var id_attr
= ( load_id
)?' id="' + load_id
+ '" ':'';
328 $j(target
).append('<div '+id_attr
+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
329 'background-color:#FFF;">' +
330 mv_get_loading_img('top:30px;left:30px') +
335 * mvJsLoader class handles initialization and js file loads
341 onReadyEvents
:new Array(),
342 doneReadyEvents
:false,
343 jQueryCheckFlag
:false,
344 //to keep consistency across threads:
347 load_error
:false, //load error flag (false by default)
349 callbacks
:new Array(),
352 doLoad:function(loadLibs
, callback
){
354 if( loadLibs
&& loadLibs
.length
!=0 ){ //setup this.libs:
356 //first check if we already have this lib loaded
357 var all_libs_loaded
=true;
358 for(var i
=0; i
< loadLibs
.length
; i
++){
359 //check if the lib is already loaded:
360 if( ! this.checkObjPath( loadLibs
[i
] ) ){
361 all_libs_loaded
=false;
364 if( all_libs_loaded
){
365 js_log('all libs already loaded skipping... load req');
369 //do a check for any css we may need and get it:
370 for(var i
=0; i
< loadLibs
.length
; i
++){
371 if( typeof mvCssPaths
[ loadLibs
[i
] ] != 'undefined' ){
372 loadExternalCss( mvCssPaths
[ loadLibs
[i
] ]);
376 //check if we should use the script loader to combine all the requests into one:
377 if( typeof mwSlScript
!= 'undefined' ){
381 for(var i
=0; i
< loadLibs
.length
; i
++){
382 var curLib
= loadLibs
[i
];
383 //only add if not included yet:
384 if( ! this.checkObjPath( curLib
) ){
385 class_set
+=coma
+ curLib
;
390 var puri
= parseUri( getMvEmbedURL() );
391 if( (getMvEmbedURL().indexOf('://')!=-1) && puri
.host
!= parseUri( document
.URL
).host
){
392 mwSlScript
= puri
.protocol
+ '://' + puri
.authority
+ mwSlScript
;
395 var dbug_attr
= (puri
.queryKey
['debug'])?'&debug=true':'';
396 this.libs
[ last_class
] = mwSlScript
+ '?class=' + class_set
+
397 '&urid=' + getMvUniqueReqId() + dbug_attr
;
401 for(var i
=0; i
< loadLibs
.length
; i
++){
402 var curLib
= loadLibs
[i
];
404 var libLoc
= mvGetClassPath(curLib
);
405 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
406 var qmark
= (libLoc
.indexOf('?')!==true)?'?':'&';
407 this.libs
[curLib
] = mv_embed_path
+ libLoc
+ qmark
+ 'urid='+ getMvUniqueReqId();
413 this.callbacks
.push(callback
);
415 if( this.checkLoading() ){
416 if( this.load_time
++ > 1000){ //time out after ~80seconds
417 js_error( gM('error_load_lib') + this.missing_path
);
418 this.load_error
=true;
420 setTimeout( 'mvJsLoader.doLoad()', 20 );
423 //js_log('checkLoading passed run callbacks');
424 //only do callback if we are in the same instance (weird concurency issue)
426 for(var i
=0; i
< this.callbacks
.length
; i
++)
428 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
431 //js_log('done loading do call: ' + this.callbacks[0] );
432 while( this.callbacks
.length
!=0 ){
433 if( this.ptime
== ( this.ctime
-1) ){ //enforce thread consistency
434 this.callbacks
.pop()();
435 //func = this.callbacks.pop();
436 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
439 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
440 setTimeout( 'mvJsLoader.doLoad()', 25 );
445 this.ptime
=this.ctime
;
447 doLoadFullPaths:function(loadObj
, callback
){
450 doLoadDepMode:function(loadChain
, callback
){
451 //firefox executes js ~in-order of it being included~ so just directly issue request:
452 if( $j
.browser
.firefox
){
454 for(var i
=0; i
< loadChain
.length
;i
++){
455 for(var j
=0;j
<loadChain
[i
].length
;j
++){
456 loadSet
.push(loadChain
[i
][j
]);
459 mvJsLoader
.doLoad(loadSet
, callback
);
461 //safari and IE tend to execute out of order so load with dependenciy checks
462 mvJsLoader
.doLoad(loadChain
.shift(),function(){
463 if(loadChain
.length
!=0){
464 mvJsLoader
.doLoadDepMode(loadChain
, callback
);
470 checkLoading:function(){
473 for(var i
in this.libs
){ //for in loop oky on object
474 if( !this.checkObjPath( i
) ){
476 loadExternalJs( this.libs
[i
] );
480 //js_log("has not yet loaded: " + i);
486 checkObjPath:function( libVar
){
489 var objPath
= libVar
.split('.')
491 for(var p
=0; p
< objPath
.length
; p
++){
492 cur_path
= (cur_path
=='')?cur_path
+objPath
[p
]:cur_path
+'.'+objPath
[p
];
493 eval( 'var ptest = typeof ( '+ cur_path
+ ' ); ');
494 if( ptest
== 'undefined'){
495 this.missing_path
= cur_path
;
499 this.cur_path
= cur_path
;
503 * checks for jQuery and adds the $j noConflict var
505 jQueryCheck:function(callback
){
506 //skip stuff if $j is already loaded:
507 if(_global
['$j'] && callback
)
514 _global
['$j'] = jQuery
.noConflict();
515 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
519 js_log('jquery loaded');
520 //setup mvEmbed jquery bindigns:
528 embedVideoCheck:function( callback
){
530 js_log('embedVideoCheck:');
531 //set videonojs to loading
532 //issue a style sheet request get both mv_embed and jquery styles:
533 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
534 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css');
536 //make sure we have jQuery
537 _this
.jQueryCheck(function(){
538 $j('.videonojs').html( gM('loading_txt') );
549 //add png fix if needed:
550 if($j
.browser
.msie
|| $j
.browser
.version
< 7)
551 depReq
[0].push( '$j.fn.pngFix' );
553 _this
.doLoadDepMode(depReq
,function(){
556 $j('.videonojs').remove();
560 addLoadEvent:function(fn
){
561 this.onReadyEvents
.push(fn
);
563 //checks the jQuery flag (this way when remote embeding we don't load jQuery
564 // unless js2AddOnloadHook was used or there is video on the page
565 runQuededFunctions:function(){
567 this.doneReadyEvents
=true;
568 if(this.jQueryCheckFlag
){
569 this.jQueryCheck(function(){
570 _this
.runReadyEvents();
573 this.runReadyEvents();
576 runReadyEvents:function(){
577 js_log("runReadyEvents");
578 while( this.onReadyEvents
.length
){
579 this.onReadyEvents
.shift()();
584 //load an external JS (similar to jquery .require plugin)
585 //but checks for object availability rather than load state
587 /*********** INITIALIZATION CODE *************
588 * this will get called when DOM is ready
589 *********************************************/
590 /* jQuery .ready does not work when jQuery is loaded dynamically
591 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
592 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
593 * $j(document).ready( function(){ */
594 function mwdomReady(force
){
595 js_log('f:mwdomReady:');
596 if( !force
&& mv_init_done
){
597 js_log("mv_init_done already done do nothing...");
601 //handle the execution of Queded function with jQuery "ready"
603 //check if this page does have video or playlist
605 document
.getElementsByTagName("video"),
606 document
.getElementsByTagName("audio"),
607 document
.getElementsByTagName("playlist")
609 if(e
[0].length
!=0 || e
[1].length
!=0 || e
[2].length
!=0){
610 js_log('we have items to rewrite');
612 //load libs and proccess:
613 mvJsLoader
.embedVideoCheck(function(){
614 //run any queded global events:
615 mv_video_embed( function(){
616 mvJsLoader
.runQuededFunctions();
620 //if we already have jQuery make sure its loaded into its proper context $j
621 //run any queded global events:
622 mvJsLoader
.runQuededFunctions();
625 //js2AddOnloadHook: ensure jQuery and the DOM are ready:
626 function js2AddOnloadHook( func
) {
627 //make sure the skin/style sheets are avaliable always:
628 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
629 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css');
631 //if we have already run the dom ready just run the function directly:
632 if( mvJsLoader
.doneReadyEvents
){
633 //make sure jQuery is there:
634 mvJsLoader
.jQueryCheck(function(){
638 //if using js2AddOnloadHook we need to get jQuery into place (if its not already included)
639 mvJsLoader
.jQueryCheckFlag
= true;
640 mvJsLoader
.addLoadEvent( func
);
643 //depreciated mwAddOnloadHook in favor of js2 naming (for clear seperation of js2 code from old mw code
644 var mwAddOnloadHook
= js2AddOnloadHook
;
646 * this function allows for targeted rewriting
648 function rewrite_by_id( vid_id
, ready_callback
){
649 js_log('f:rewrite_by_id: ' + vid_id
);
650 //force a recheck of the dom for playlist or video element:
651 mvJsLoader
.embedVideoCheck(function(){
652 mv_video_embed(ready_callback
, vid_id
);
655 //depricated in favor of updates to oggHanlder
656 function rewrite_for_oggHanlder( vidIdList
){
657 for(var i
= 0; i
< vidIdList
.length
; i
++){
658 var vidId
= vidIdList
[i
];
659 js_log('looking at vid: ' + i
+' ' + vidId
);
660 //grab the thumbnail and src video
661 var pimg
= $j('#'+vidId
+ ' img');
662 var poster_attr
= 'poster = "' + pimg
.attr('src') + '" ';
663 var pwidth
= pimg
.attr('width');
664 var pheight
= pimg
.attr('height');
668 if( pwidth
=='22' && pheight
=='22'){
671 type_attr
= 'type="audio/ogg"';
679 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
680 src
= re
.exec( $j('#'+vidId
).html() )[2];
682 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
683 duration
= re
.exec( $j('#'+vidId
).html() )[2];
685 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
686 offset
= re
.exec( $j('#'+vidId
).html() )[2];
687 var offset_attr
= (offset
)? 'startOffset="'+ offset
+ '"': '';
690 //replace the top div with mv_embed based player:
691 var vid_html
= '<video id="vid_' + i
+'" '+
692 'src="' + src
+ '" ' +
696 'duration="' + duration
+ '" ' +
697 'style="width:' + pwidth
+ 'px;height:' +
698 pheight
+ 'px;"></video>';
699 //js_log("video html: " + vid_html);
700 $j('#'+vidId
).html( vid_html
);
703 //rewrite that video id:
704 rewrite_by_id('vid_' + i
);
709 /*********** INITIALIZATION CODE *************
710 * set DOM ready callback to init_mv_embed
711 *********************************************/
712 // for Mozilla browsers
713 if (document
.addEventListener
) {
714 document
.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
716 //backup "onload" method in case on DOMContentLoaded does not exist
717 window
.onload = function(){ mwdomReady() };
720 * should depreciate and use jquery.ui.dialog instead
722 function mv_write_modal(content
, speed
){
723 $j('#modalbox,#mv_overlay').remove();
724 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
725 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
728 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
729 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
731 $j('#modalbox,#mv_overlay').show( speed
);
733 function mv_remove_modal(speed
){
734 $j('#modalbox,#mv_overlay').remove( speed
);
738 * stores all the mwEmbed jQuery specific bindings
739 * (setup after jQuery is avaliable)
740 * lets you call rewrites in a jquery "way"
742 * @@ eventually we should refactor mwCode over to jQuery style plugins
743 * and mv_embed.js will just hanndle dependency mapping and loading.
746 function mv_jqueryBindings(){
747 js_log('mv_jqueryBindings');
749 $.fn
.addMediaWiz = function( iObj
, callback
){
750 //first set the cursor for the button to "loading"
751 $j(this.selector
).css('cursor','wait').attr('title', gM('loading_title'));
753 iObj
['target_invocation'] = this.selector
;
755 //load the mv_embed_base skin:
756 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
757 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css' );
758 //load all the req libs:
759 mvJsLoader
.jQueryCheck(function(){
760 //load with staged dependeinces (for ie and safari that don't execute in order)
761 mvJsLoader
.doLoadDepMode([
762 [ 'remoteSearchDriver',
773 iObj
['instance_name']= 'rsdMVRS';
774 _global
['rsdMVRS'] = new remoteSearchDriver( iObj
);
776 callback( _global
['rsdMVRS'] );
781 $.fn
.sequencer = function( iObj
, callback
){
783 iObj
['target_sequence_container'] = this.selector
;
784 //issue a request to get the css file (if not already included):
785 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
786 loadExternalCss( mv_embed_path
+'skins/'+mwConfig
['skin_name']+'/mv_sequence.css');
787 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
788 mvJsLoader
.embedVideoCheck(function(){
789 //load playlist object and then jquery ui stuff:
790 mvJsLoader
.doLoadDepMode([
810 js_log('calling new mvSequencer');
811 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
812 if(!_global
['mvSeq']){
813 _global
['mvSeq'] = new mvSequencer(iObj
);
815 js_log('mvSeq already init');
821 * the firefogg jquery function:
822 * @@note this firefogg envocation could be made to work more like real jquery plugins
824 $.fn
.firefogg = function( iObj
, callback
) {
827 //add base theme css:
828 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
829 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css' );
831 //check if we already have firefogg loaded (the call just updates properties for that element)
832 var sElm
= $j(this.selector
).get(0);
833 if(sElm
['firefogg']){
834 if(sElm
['firefogg']=='loading'){
835 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
840 js_log("firefogg::updated: "+ i
+ ' to '+ iObj
[i
]);
841 sElm
['firefogg'][i
] = iObj
[i
];
843 return sElm
['firefogg'];
846 sElm
['firefogg'] = 'loading';
849 iObj
['selector'] = this.selector
;
853 'mvBaseUploadInterface',
862 if( iObj
.encoder_interface
){
871 //make sure we have everything loaded that we need:
872 mvJsLoader
.doLoadDepMode( loadSet
, function(){
873 js_log('firefogg libs loaded. target select:' + iObj
.selector
);
874 //select interface provicer based on if we want to include the encoder interface or not:
875 if(iObj
.encoder_interface
){
876 var myFogg
= new mvAdvFirefogg( iObj
);
878 var myFogg
= new mvFirefogg( iObj
);
881 myFogg
.doRewrite( callback
);
882 var selectorElement
= $j( iObj
.selector
).get(0);
883 selectorElement
['firefogg']=myFogg
;
887 //takes a input player as the selector and exposes basic rendering controls
888 $.fn
.firefoggRender = function( iObj
, callback
){
889 //check if we already have render loaded then just pass on updates/actions
890 var sElm
= $j(this.selector
).get(0);
891 if(sElm
['fogg_render']){
892 if(sElm
['fogg_render']=='loading'){
893 js_log("Error: called firefoggRender while loading");
896 //call or update the property:
898 sElm
['fogg_render']='loading';
900 iObj
['player_target'] = this.selector
;
905 sElm
['fogg_render']= new mvFirefoggRender( iObj
);
906 if( callback
&& typeof callback
== 'function' )
907 callback( sElm
['fogg_render'] );
911 $.fn
.baseUploadInterface = function(iObj
){
912 mvJsLoader
.doLoadDepMode([
914 'mvBaseUploadInterface',
922 myUp
= new mvBaseUploadInterface( iObj
);
927 //shortcut to a themed button:
928 $.btnHtml = function(msg
, className
, iconId
, opt
){
931 var href
= (opt
.href
)?opt
.href
:'#';
932 var target_attr
= (opt
.target
)?' target="' + opt
.target
+ '" ':'';
933 var style_attr
= (opt
.style
)?' style="'+opt
.style
+'" ':'';
934 return '<a href="' + href
+ '" ' + target_attr
+ style_attr
+' class="ui-state-default ui-corner-all ui-icon_link ' +
935 className
+ '"><span class="ui-icon ui-icon-' + iconId
+ '" />' +
938 //shortcut to bind hover state:
939 $.fn
.btnBind = function(){
942 $j(this).addClass('ui-state-hover');
945 $j(this).removeClass('ui-state-hover');
956 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
957 function getURLParamReplace( url
, opt
){
958 var pSrc
= parseUri( url
);
959 if(pSrc
.protocol
!= '' ){
960 var new_url
= pSrc
.protocol
+'://'+ pSrc
.authority
+ pSrc
.path
+'?';
962 var new_url
= pSrc
.path
+'?';
965 for(var key
in pSrc
.queryKey
){
966 var val
= pSrc
.queryKey
[ key
];
967 //do override if requested
970 new_url
+= amp
+ key
+ '=' + val
;
973 //add any vars that did were not originally there:
975 if(!pSrc
.queryKey
[i
]){
976 new_url
+=amp
+ i
+ '=' + opt
[i
];
983 * seconds2npt given a float seconds returns npt format response:
984 * @param float seconds
985 * @param boolean if we should show ms or not.
987 function seconds2npt(sec
, show_ms
){
989 //js_log("warning: trying to get npt time on NaN:" + sec);
992 var hours
= Math
.floor(sec
/ 3600);
993 var minutes
= Math
.floor((sec
/60) % 60);
994 var seconds
= sec
% 60;
995 //round the second amount requested significant digits
997 seconds
= Math
.round( seconds
* 1000 ) / 1000;
999 seconds
= Math
.round( seconds
);
1002 seconds
= '0'+ seconds
;
1004 minutes
= '0' + minutes
;
1006 return hours
+":"+minutes
+":"+seconds
;
1009 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
1011 function npt2seconds( npt_str
){
1013 //js_log('npt2seconds:not valid ntp:'+ntp);
1016 //strip npt: time definition if present
1017 npt_str
= npt_str
.replace('npt:', '');
1019 times
= npt_str
.split(':');
1020 if(times
.length
!=3){
1021 js_log('error: npt2seconds on ' + npt_str
);
1024 //sometimes the comma is used inplace of pereid for ms
1025 times
[2] = times
[2].replace(/,\s?/,'.');
1026 //return seconds float (ie take seconds float value if present):
1027 return parseInt(times
[0]*3600)+parseInt(times
[1]*60)+parseFloat(times
[2]);
1030 * simple helper to grab a edit token
1032 * @param title the wiki page title you want to edit )
1033 * @param api_url 'optional' the target api url
1034 * @param callback the callback function to pass the token or "false" to
1036 function get_mw_token( title
, api_url
, callback
){
1037 js_log(':get_mw_token:');
1038 if(!title
&& wgUserName
){
1039 title
= 'User:' + wgUserName
;
1051 for(var i
in data
.query
.pages
){
1052 if(data
.query
.pages
[i
]['edittoken']){
1053 if(typeof callback
== 'function')
1054 callback ( data
.query
.pages
[i
]['edittoken'] );
1062 //does a remote or local api request based on request url
1063 //@param options: url, data, cbParam, callback
1064 function do_api_req( options
, callback
){
1065 if(typeof options
.data
!= 'object'){
1066 return js_error('Error: request paramaters must be an object');;
1068 //gennerate the url if its missing:
1069 if( typeof options
.url
== 'undefined' || options
.url
=== false){
1070 if(!wgServer
|| ! wgScriptPath
){
1071 return js_error('Error: no api url for api request');;
1073 //update to api.php (if index.php was in the wgScript path):
1074 options
.url
= mwGetLocalApiUrl();
1076 if( typeof options
.data
== 'undefined' )
1079 //force format to json (if not already set)
1080 options
.data
['format'] = 'json';
1082 //if action not set assume query
1083 if(!options
.data
['action'])
1084 options
.data
['action']='query';
1086 js_log('do api req: ' + options
.url
+'?' + jQuery
.param(options
.data
) );
1087 //build request string:
1088 if( parseUri( document
.URL
).host
== parseUri( options
.url
).host
){
1089 //local request do api request directly
1094 dataType
:'json', //api requests _should_ always return JSON data:
1096 success:function(data
){
1100 js_error( ' error' + e
+' in getting: ' + options
.url
);
1104 //set the callback param if not already set:
1105 if( typeof options
.jsonCB
== 'undefined')
1106 options
.jsonCB
= 'callback';
1108 var req_url
= options
.url
;
1109 var paramAnd
= (req_url
.indexOf('?')==-1)?'?':'&';
1110 //put all the values into the GET req:
1111 for(var i
in options
.data
){
1112 req_url
+= paramAnd
+ encodeURIComponent( i
) + '=' + encodeURIComponent( options
.data
[i
] );
1115 var fname
= 'mycpfn_' + ( global_cb_count
++ );
1116 _global
[ fname
] = callback
;
1117 req_url
+= '&' + options
.jsonCB
+ '=' + fname
;
1118 loadExternalJs( req_url
);
1121 function mwGetLocalApiUrl(url
){
1122 if (wgServer
&& wgScriptPath
){
1123 return wgServer
+ wgScriptPath
+ '/api.php';
1127 //grab wiki form error for wiki html page proccessing (should be depricated)
1128 function grabWikiFormError ( result_page
){
1130 sp
= result_page
.indexOf('<span class="error">');
1132 se
= result_page
.indexOf('</span>', sp
);
1133 res
.error_txt
= result_page
.substr(sp
, (sp
-se
)) + '</span>';
1136 sp
= result_page
.indexOf('<ul class="warning">')
1138 se
= result_page
.indexOf('</ul>', sp
);
1139 res
.error_txt
= result_page
.substr(sp
, (se
-sp
)) + '</ul>';
1140 //try and add the ignore form item:
1141 sfp
= result_page
.indexOf('<form method="post"');
1143 sfe
= result_page
.indexOf('</form>', sfp
);
1144 res
.form_txt
= result_page
.substr(sfp
, ( sfe
- sfp
)) + '</form>';
1147 //one more error type check:
1148 sp
= result_page
.indexOf('class="mw-warning-with-logexcerpt">')
1150 se
= result_page
.indexOf('</div>', sp
);
1151 res
.error_txt
= result_page
.substr(sp
, ( se
- sp
)) + '</div>';
1157 //do a "normal" request
1158 function do_request(req_url
, callback
){
1159 js_log('do_request::req_url:' + req_url
+ ' != ' + parseUri( req_url
).host
);
1160 //if we are doing a request to the same domain or relative link do a normal GET:
1161 if( parseUri(document
.URL
).host
== parseUri(req_url
).host
||
1162 req_url
.indexOf('://') == -1 ){ //relative url
1163 //do a direct request:
1168 success:function(data
){
1173 //get data via DOM injection with callback
1174 global_req_cb
.push(callback
);
1175 //prepend json_ to feed_format if not already requesting json format
1176 if( req_url
.indexOf("feed_format=")!=-1 && req_url
.indexOf("feed_format=json")==-1)
1177 req_url
= req_url
.replace(/feed_format=/, 'feed_format=json_');
1178 loadExternalJs( req_url
+ '&cb=mv_jsdata_cb&cb_inx=' + (global_req_cb
.length
-1));
1182 function mv_jsdata_cb(response
){
1183 js_log('f:mv_jsdata_cb:'+ response
['cb_inx']);
1184 //run the callback from the global req cb object:
1185 if( !global_req_cb
[response
['cb_inx']] ){
1186 js_log('missing req cb index');
1189 if( !response
['pay_load'] ){
1190 js_log("missing pay load");
1193 //switch on content type:
1194 switch(response
['content-type']){
1198 if(typeof response
['pay_load'] == 'string'){
1199 //js_log('load string:'+"\n"+ response['pay_load']);
1201 //attempt to parse as xml for IE
1202 if( $j
.browser
.msie
){
1203 var xmldata
=new ActiveXObject("Microsoft.XMLDOM");
1204 xmldata
.async
="false";
1205 xmldata
.loadXML(response
['pay_load']);
1206 }else{ //for others (firefox, safari etc)
1208 var xmldata
= (new DOMParser()).parseFromString(response
['pay_load'], "text/xml");
1210 js_log('XML parse ERROR: ' + e
.message
);
1213 //@@todo hanndle xml parser errors
1214 if(xmldata
)response
['pay_load']=xmldata
;
1218 js_log('bad response type' + response
['content-type']);
1222 global_req_cb
[response
['cb_inx']]( response
['pay_load'] );
1224 //load external js via dom injection
1225 function loadExternalJs( url
, callback
){
1226 js_log('load js: '+ url
);
1227 //if(window['$j']) //use jquery call:
1235 var e
= document
.createElement("script");
1236 e
.setAttribute('src', url
);
1237 e
.setAttribute('type', "text/javascript");
1239 e.onload = callback;
1241 //e.setAttribute('defer', true);
1242 document
.getElementsByTagName("head")[0].appendChild(e
);
1245 function styleSheetPresent(url
){
1246 style_elements
= document
.getElementsByTagName('link');
1247 if( style_elements
.length
> 0) {
1248 for(i
= 0; i
< style_elements
.length
; i
++) {
1249 if(style_elements
[i
].href
== url
)
1255 function loadExternalCss(url
){
1256 //if could have script loader group thes css request
1257 //but debatable it may hurt more than it helps with caching and all
1258 if(typeof url
=='object'){
1260 loadExternalCss ( url
[i
] );
1265 if( url
.indexOf('?') == -1 ){
1266 url
+='?'+getMvUniqueReqId();
1268 if(!styleSheetPresent(url
) ){
1269 js_log('load css: ' + url
);
1270 var e
= document
.createElement("link");
1272 e
.type
= "text/css";
1273 e
.rel
= 'stylesheet';
1274 document
.getElementsByTagName("head")[0].appendChild(e
);
1277 function getMvEmbedURL(){
1278 if( _global
['mv_embed_url'] )
1279 return _global
['mv_embed_url'];
1280 var js_elements
= document
.getElementsByTagName("script");
1281 for(var i
=0; i
< js_elements
.length
; i
++){
1282 //check for normal mv_embed.js and or script loader
1283 var src
= js_elements
[i
].getAttribute("src");
1285 if( src
.indexOf('mv_embed.js') !=-1 || (
1286 ( src
.indexOf('mwScriptLoader.php') != -1 || src
.indexOf('jsScriptLoader.php') != -1 )
1287 && src
.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1288 _global
['mv_embed_url'] = src
;
1293 js_error('Error: getMvEmbedURL failed to get Embed Path');
1296 //gets a unique request id to ensure fresh javascript
1297 function getMvUniqueReqId(){
1298 if( _global
['urid'] )
1299 return _global
['urid'];
1300 var mv_embed_url
= getMvEmbedURL();
1301 //if we have a uri retun that:
1302 var urid
= parseUri( mv_embed_url
).queryKey
['urid']
1304 _global
['urid'] = urid
;
1307 //if in debug mode get a fresh unique request key:
1308 if( parseUri( mv_embed_url
).queryKey
['debug'] == 'true'){
1310 var urid
= d
.getTime();
1311 _global
['urid'] = urid
;
1314 //else just return the mv_embed version;
1315 return MV_EMBED_VERSION
;
1318 * sets the global mv_embed path based on the scripts location
1320 function getMvEmbedPath(){
1321 if( _global
['mv_embed_path'])
1322 return _global
['mv_embed_path'];
1323 var mv_embed_url
= getMvEmbedURL();
1324 if( mv_embed_url
.indexOf('mv_embed.js') !== -1 ){
1325 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mv_embed.js'));
1326 }else if(mv_embed_url
.indexOf('mwScriptLoader.php')!==-1){
1327 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1328 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path
;
1330 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('jsScriptLoader.php'));
1332 //absolute the url (if relative) (if we don't have mv_embed path)
1333 if( mv_embed_path
.indexOf('://') == -1){
1334 var pURL
= parseUri( document
.URL
);
1335 if(mv_embed_path
.charAt(0)=='/'){
1336 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ mv_embed_path
;
1339 if(mv_embed_path
==''){
1340 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ pURL
.directory
+ mv_embed_path
;
1344 _global
['mv_embed_path'] = mv_embed_path
;
1345 return mv_embed_path
;
1348 if (typeof DOMParser
== "undefined") {
1349 DOMParser = function () {}
1350 DOMParser
.prototype.parseFromString = function (str
, contentType
) {
1351 if (typeof ActiveXObject
!= "undefined") {
1352 var d
= new ActiveXObject("MSXML.DomDocument");
1355 } else if (typeof XMLHttpRequest
!= "undefined") {
1356 var req
= new XMLHttpRequest
;
1357 req
.open("GET", "data:" + (contentType
|| "application/xml") +
1358 ";charset=utf-8," + encodeURIComponent(str
), false);
1359 if (req
.overrideMimeType
) {
1360 req
.overrideMimeType(contentType
);
1363 return req
.responseXML
;
1368 * utility functions:
1370 function js_log(string
){
1371 if( window
.console
){
1372 window
.console
.log(string
);
1375 * IE and non-firebug debug:
1377 /*var log_elm = document.getElementById('mv_js_log');
1379 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1380 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1381 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1384 var log_elm = document.getElementById('mv_js_log');
1387 log_elm.value+=string+"\n";
1393 function checkDefaultMwConfig(){
1394 for(var i
in defaultMwConfig
){
1395 if(typeof(mwConfig
[i
])=='undefined'){
1396 mwConfig
[i
] =defaultMwConfig
[i
];
1401 function js_error(string
){