1149bddf52ea95bd0ccb36235e62e014c749984c
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/redmond/';
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...",
85 "size-gigabytes" : "$1 GB",
86 "size-megabytes" : "$1 MB",
87 "size-kilobytes" : "$1 K",
92 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
93 * any file _not_ listed here won't be auto-loadable
94 * @path the path to the file (or set of files) with ending slash
95 * @gClasses the set of classes
96 * if an array $j.className become jquery.className.js
97 * if an asssociative object then key => value paris are used
99 if(typeof mvAutoLoadClasses
== 'undefined')
100 mvAutoLoadClasses
= {};
102 //the script that loads the classet
103 function lcPaths( classSet
){
104 for(var i
in classSet
){
105 mvAutoLoadClasses
[i
] = classSet
[i
];
109 function mvGetClassPath(k
){
110 if( mvAutoLoadClasses
[k
] ){
111 //js_log('got classpath:' + k + ' : '+ mvClassPaths[k]);
112 return mvAutoLoadClasses
[k
];
114 return js_error('could not find path for requested class ' + k
);
117 if(typeof mvCssPaths
== 'undefined')
120 function lcCssPath(cssSet
){
121 for(var i
in cssSet
){
122 mvCssPaths
[i
]= mv_embed_path
+ cssSet
[i
];
127 * -- Load Class Paths --
129 * MUST BE VALID JSON (NOT JS)
130 * is used by the scriptloader to autoLoad classes (so we only define this once for php & javascript)
132 * this is more verbose than earlier version that compressed paths
133 * but its all good gziping help compress repetative path strings
136 * right now php AutoLoader only reads this mv_embed.js file
137 * in the future we could have multiple lcPath calls that php reads
138 * (if our autoloading class list becomes too long) just have to add thouse
139 * files to the jsAutoLoader file list.
142 "mv_embed" : "mv_embed.js",
143 "window.jQuery" : "jquery/jquery-1.3.2.js",
144 "$j.fn.pngFix" : "jquery/plugins/jquery.pngFix.js",
145 "$j.fn.autocomplete": "jquery/plugins/jquery.autocomplete.js",
146 "$j.fn.hoverIntent" : "jquery/plugins/jquery.hoverIntent.js",
147 "$j.fn.datePicker" : "jquery/plugins/jquery.datePicker.js",
148 "$j.ui" : "jquery/jquery.ui/ui/ui.core.js",
149 "$j.fn.ColorPicker" : "libClipEdit/colorpicker/js/colorpicker.js",
150 "$j.Jcrop" : "libClipEdit/Jcrop/js/jquery.Jcrop.js",
151 "$j.fn.simpleUploadForm": "libAddMedia/simpleUploadForm.js",
153 "baseSkin" : "skins/baseSkin.js",
154 "kskin" : "skins/kskin/kskin.js",
155 "mvpcf" : "skins/mvpcf/mvpcf.js",
157 "$j.secureEvalJSON" : "jquery/plugins/jquery.secureEvalJSON.js",
158 "$j.cookie" : "jquery/plugins/jquery.cookie.js",
159 "$j.contextMenu" : "jquery/plugins/jquery.contextMenu.js",
161 "$j.effects.blind" : "jquery/jquery.ui/ui/effects.blind.js",
162 "$j.effects.drop" : "jquery/jquery.ui/ui/effects.drop.js",
163 "$j.effects.pulsate" : "jquery/jquery.ui/ui/effects.pulsate.js",
164 "$j.effects.transfer" : "jquery/jquery.ui/ui/effects.transfer.js",
165 "$j.ui.droppable" : "jquery/jquery.ui/ui/ui.droppable.js",
166 "$j.ui.slider" : "jquery/jquery.ui/ui/ui.slider.js",
167 "$j.effects.bounce" : "jquery/jquery.ui/ui/effects.bounce.js",
168 "$j.effects.explode" : "jquery/jquery.ui/ui/effects.explode.js",
169 "$j.effects.scale" : "jquery/jquery.ui/ui/effects.scale.js",
170 "$j.ui.datepicker" : "jquery/jquery.ui/ui/ui.datepicker.js",
171 "$j.ui.progressbar" : "jquery/jquery.ui/ui/ui.progressbar.js",
172 "$j.ui.sortable" : "jquery/jquery.ui/ui/ui.sortable.js",
173 "$j.effects.clip" : "jquery/jquery.ui/ui/effects.clip.js",
174 "$j.effects.fold" : "jquery/jquery.ui/ui/effects.fold.js",
175 "$j.effects.shake" : "jquery/jquery.ui/ui/effects.shake.js",
176 "$j.ui.dialog" : "jquery/jquery.ui/ui/ui.dialog.js",
177 "$j.ui.resizable" : "jquery/jquery.ui/ui/ui.resizable.js",
178 "$j.ui.tabs" : "jquery/jquery.ui/ui/ui.tabs.js",
179 "$j.effects.core" : "jquery/jquery.ui/ui/effects.core.js",
180 "$j.effects.highlight" : "jquery/jquery.ui/ui/effects.highlight.js",
181 "$j.effects.slide" : "jquery/jquery.ui/ui/effects.slide.js",
182 "$j.ui.accordion" : "jquery/jquery.ui/ui/ui.accordion.js",
183 "$j.ui.draggable" : "jquery/jquery.ui/ui/ui.draggable.js",
184 "$j.ui.selectable" : "jquery/jquery.ui/ui/ui.selectable.js",
186 "mvFirefogg" : "libAddMedia/mvFirefogg.js",
187 "mvAdvFirefogg" : "libAddMedia/mvAdvFirefogg.js",
188 "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
189 "remoteSearchDriver" : "libAddMedia/remoteSearchDriver.js",
190 "seqRemoteSearchDriver" : "libAddMedia/seqRemoteSearchDriver.js",
192 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
193 "mediaWikiSearch" : "libAddMedia/searchLibs/mediaWikiSearch.js",
194 "metavidSearch" : "libAddMedia/searchLibs/metavidSearch.js",
195 "archiveOrgSearch" : "libAddMedia/searchLibs/archiveOrgSearch.js",
196 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
198 "mvClipEdit" : "libClipEdit/mvClipEdit.js",
200 "embedVideo" : "libEmbedVideo/embedVideo.js",
201 "flashEmbed" : "libEmbedVideo/flashEmbed.js",
202 "genericEmbed" : "libEmbedVideo/genericEmbed.js",
203 "htmlEmbed" : "libEmbedVideo/htmlEmbed.js",
204 "javaEmbed" : "libEmbedVideo/javaEmbed.js",
205 "nativeEmbed" : "libEmbedVideo/nativeEmbed.js",
206 "quicktimeEmbed" : "libEmbedVideo/quicktimeEmbed.js",
207 "vlcEmbed" : "libEmbedVideo/vlcEmbed.js",
209 "mvPlayList" : "libSequencer/mvPlayList.js",
210 "mvSequencer" : "libSequencer/mvSequencer.js",
211 "mvFirefoggRender" : "libSequencer/mvFirefoggRender.js",
212 "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
214 "libTimedText" : "libTimedText/mvTextInterface.js"
218 //depencency mapping for css files for self contained included plugins:
220 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
221 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/css/colorpicker.css'
225 * Language Functions:
227 * These functions try to losely mirro the functionality of Language.php in mediaWiki
229 function gM( key
, args
) {
233 if(typeof args
== 'object' || typeof args
== 'array'){
235 //msg test replace arguments start at 1 insted of zero:
236 var rep
= '\$'+ ( parseInt(v
) + 1 );
237 ms
= ms
.replace( rep
, args
[v
]);
239 }else if(typeof args
=='string' || typeof args
=='number'){
240 ms
= ms
.replace(/\$1/, args
);
244 //key is missing return indication:
245 return '<' + key
+ '>';
249 * msgSet is either a string corresponding to a single msg to load
250 * or msgSet is an array with set of msg to load
252 function gMsgLoadRemote(msgSet
, callback
){
254 if(typeof msgSet
== 'object' ){
255 for(var i
in msgSet
){
256 ammessages
+= msgSet
[i
] + '|';
258 }else if(typeof msgSet
== 'string'){
259 ammessages
+= msgSet
;
261 if(ammessages
== ''){
262 js_log('gMsgLoadRemote::no msg set requested');
267 'meta':'allmessages',
268 'ammessages':ammessages
271 if(data
.query
.allmessages
){
272 var msgs
= data
.query
.allmessages
;
275 ld
[ msgs
[i
]['name'] ] = msgs
[i
]['*'];
279 //load the result into local msg var
285 * Format a size in bytes for output, using an appropriate
286 * unit (B, KB, MB or GB) according to the magnitude in question
288 * @param size Size to format
289 * @return string Plain text (not HTML)
291 function formatSize( size
) {
292 // For small sizes no decimal places necessary
299 // For MB and bigger two decimal places are smarter
303 msg
= 'size-gigabytes';
305 msg
= 'size-megabytes';
308 msg
= 'size-kilobytes';
313 //javascript does not let you do precession points in rounding
314 var p
= Math
.pow(10,round
);
315 var size
= Math
.round( size
* p
) / p
;
316 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
317 return gM( msg
, size
);
320 //gets the loading image:
321 function mv_get_loading_img( style
, class_attr
){
322 var style_txt
= (style
)?style
:'';
323 var class_attr
= (class_attr
)?'class="'+class_attr
+'"':'class="mv_loading_img"';
324 return '<div '+class_attr
+' style="' + style
+'"></div>';
327 function mv_set_loading(target
, load_id
){
328 var id_attr
= ( load_id
)?' id="' + load_id
+ '" ':'';
329 $j(target
).append('<div '+id_attr
+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
330 'background-color:#FFF;">' +
331 mv_get_loading_img('top:30px;left:30px') +
336 * mvJsLoader class handles initialization and js file loads
342 onReadyEvents
:new Array(),
343 doneReadyEvents
:false,
344 jQueryCheckFlag
:false,
345 //to keep consistency across threads:
348 load_error
:false, //load error flag (false by default)
350 callbacks
:new Array(),
353 doLoad:function(loadLibs
, callback
){
355 if( loadLibs
&& loadLibs
.length
!=0 ){ //setup this.libs:
357 //first check if we already have this lib loaded
358 var all_libs_loaded
=true;
359 for(var i
=0; i
< loadLibs
.length
; i
++){
360 //check if the lib is already loaded:
361 if( ! this.checkObjPath( loadLibs
[i
] ) ){
362 all_libs_loaded
=false;
365 if( all_libs_loaded
){
366 js_log('all libs already loaded skipping... load req');
370 //do a check for any css we may need and get it:
371 for(var i
=0; i
< loadLibs
.length
; i
++){
372 if( typeof mvCssPaths
[ loadLibs
[i
] ] != 'undefined' ){
373 loadExternalCss( mvCssPaths
[ loadLibs
[i
] ]);
377 //check if we should use the script loader to combine all the requests into one:
378 if( typeof mwSlScript
!= 'undefined' ){
382 for(var i
=0; i
< loadLibs
.length
; i
++){
383 var curLib
= loadLibs
[i
];
384 //only add if not included yet:
385 if( ! this.checkObjPath( curLib
) ){
386 class_set
+=coma
+ curLib
;
391 var puri
= parseUri( getMvEmbedURL() );
392 if( (getMvEmbedURL().indexOf('://')!=-1) && puri
.host
!= parseUri( document
.URL
).host
){
393 mwSlScript
= puri
.protocol
+ '://' + puri
.authority
+ mwSlScript
;
396 var dbug_attr
= (puri
.queryKey
['debug'])?'&debug=true':'';
397 this.libs
[ last_class
] = mwSlScript
+ '?class=' + class_set
+
398 '&urid=' + getMvUniqueReqId() + dbug_attr
;
402 for(var i
=0; i
< loadLibs
.length
; i
++){
403 var curLib
= loadLibs
[i
];
405 var libLoc
= mvGetClassPath(curLib
);
406 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
407 var qmark
= (libLoc
.indexOf('?')!==true)?'?':'&';
408 this.libs
[curLib
] = mv_embed_path
+ libLoc
+ qmark
+ 'urid='+ getMvUniqueReqId();
414 this.callbacks
.push(callback
);
416 if( this.checkLoading() ){
417 if( this.load_time
++ > 1000){ //time out after ~80seconds
418 js_error( gM('error_load_lib') + this.missing_path
);
419 this.load_error
=true;
421 setTimeout( 'mvJsLoader.doLoad()', 20 );
424 //js_log('checkLoading passed run callbacks');
425 //only do callback if we are in the same instance (weird concurency issue)
427 for(var i
=0; i
< this.callbacks
.length
; i
++)
429 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
432 //js_log('done loading do call: ' + this.callbacks[0] );
433 while( this.callbacks
.length
!=0 ){
434 if( this.ptime
== ( this.ctime
-1) ){ //enforce thread consistency
435 this.callbacks
.pop()();
436 //func = this.callbacks.pop();
437 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
440 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
441 setTimeout( 'mvJsLoader.doLoad()', 25 );
446 this.ptime
=this.ctime
;
448 doLoadFullPaths:function(loadObj
, callback
){
451 doLoadDepMode:function(loadChain
, callback
){
452 //firefox executes js ~in-order of it being included~ so just directly issue request:
453 if( $j
.browser
.firefox
){
455 for(var i
=0; i
< loadChain
.length
;i
++){
456 for(var j
=0;j
<loadChain
[i
].length
;j
++){
457 loadSet
.push(loadChain
[i
][j
]);
460 mvJsLoader
.doLoad(loadSet
, callback
);
462 //safari and IE tend to execute out of order so load with dependenciy checks
463 mvJsLoader
.doLoad(loadChain
.shift(),function(){
464 if(loadChain
.length
!=0){
465 mvJsLoader
.doLoadDepMode(loadChain
, callback
);
471 checkLoading:function(){
474 for(var i
in this.libs
){ //for in loop oky on object
475 if( !this.checkObjPath( i
) ){
477 loadExternalJs( this.libs
[i
] );
481 //js_log("has not yet loaded: " + i);
487 checkObjPath:function( libVar
){
490 var objPath
= libVar
.split('.')
492 for(var p
=0; p
< objPath
.length
; p
++){
493 cur_path
= (cur_path
=='')?cur_path
+objPath
[p
]:cur_path
+'.'+objPath
[p
];
494 eval( 'var ptest = typeof ( '+ cur_path
+ ' ); ');
495 if( ptest
== 'undefined'){
496 this.missing_path
= cur_path
;
500 this.cur_path
= cur_path
;
504 * checks for jQuery and adds the $j noConflict var
506 jQueryCheck:function(callback
){
507 //skip stuff if $j is already loaded:
508 if(_global
['$j'] && callback
)
515 _global
['$j'] = jQuery
.noConflict();
516 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
520 js_log('jquery loaded');
521 //setup mvEmbed jquery bindigns:
529 embedVideoCheck:function( callback
){
531 js_log('embedVideoCheck:');
532 //set videonojs to loading
533 //issue a style sheet request get both mv_embed and jquery styles:
534 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
535 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css');
537 //make sure we have jQuery
538 _this
.jQueryCheck(function(){
539 $j('.videonojs').html( gM('loading_txt') );
550 //add png fix if needed:
551 if($j
.browser
.msie
|| $j
.browser
.version
< 7)
552 depReq
[0].push( '$j.fn.pngFix' );
554 _this
.doLoadDepMode(depReq
,function(){
557 $j('.videonojs').remove();
561 addLoadEvent:function(fn
){
562 this.onReadyEvents
.push(fn
);
564 //checks the jQuery flag (this way when remote embeding we don't load jQuery
565 // unless js2AddOnloadHook was used or there is video on the page
566 runQuededFunctions:function(){
568 this.doneReadyEvents
=true;
569 if(this.jQueryCheckFlag
){
570 this.jQueryCheck(function(){
571 _this
.runReadyEvents();
574 this.runReadyEvents();
577 runReadyEvents:function(){
578 js_log("runReadyEvents");
579 while( this.onReadyEvents
.length
){
580 this.onReadyEvents
.shift()();
585 //load an external JS (similar to jquery .require plugin)
586 //but checks for object availability rather than load state
588 /*********** INITIALIZATION CODE *************
589 * this will get called when DOM is ready
590 *********************************************/
591 /* jQuery .ready does not work when jQuery is loaded dynamically
592 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
593 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
594 * $j(document).ready( function(){ */
595 function mwdomReady(force
){
596 js_log('f:mwdomReady:');
597 if( !force
&& mv_init_done
){
598 js_log("mv_init_done already done do nothing...");
602 //handle the execution of Queded function with jQuery "ready"
604 //check if this page does have video or playlist
606 document
.getElementsByTagName("video"),
607 document
.getElementsByTagName("audio"),
608 document
.getElementsByTagName("playlist")
610 if(e
[0].length
!=0 || e
[1].length
!=0 || e
[2].length
!=0){
611 js_log('we have items to rewrite');
613 //load libs and proccess:
614 mvJsLoader
.embedVideoCheck(function(){
615 //run any queded global events:
616 mv_video_embed( function(){
617 mvJsLoader
.runQuededFunctions();
621 //if we already have jQuery make sure its loaded into its proper context $j
622 //run any queded global events:
623 mvJsLoader
.runQuededFunctions();
626 //js2AddOnloadHook: ensure jQuery and the DOM are ready:
627 function js2AddOnloadHook( func
) {
628 //make sure the skin/style sheets are avaliable always:
629 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
630 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css');
632 //if we have already run the dom ready just run the function directly:
633 if( mvJsLoader
.doneReadyEvents
){
634 //make sure jQuery is there:
635 mvJsLoader
.jQueryCheck(function(){
639 //if using js2AddOnloadHook we need to get jQuery into place (if its not already included)
640 mvJsLoader
.jQueryCheckFlag
= true;
641 mvJsLoader
.addLoadEvent( func
);
644 //depreciated mwAddOnloadHook in favor of js2 naming (for clear seperation of js2 code from old mw code
645 var mwAddOnloadHook
= js2AddOnloadHook
;
647 * this function allows for targeted rewriting
649 function rewrite_by_id( vid_id
, ready_callback
){
650 js_log('f:rewrite_by_id: ' + vid_id
);
651 //force a recheck of the dom for playlist or video element:
652 mvJsLoader
.embedVideoCheck(function(){
653 mv_video_embed(ready_callback
, vid_id
);
656 //depricated in favor of updates to oggHanlder
657 function rewrite_for_oggHanlder( vidIdList
){
658 for(var i
= 0; i
< vidIdList
.length
; i
++){
659 var vidId
= vidIdList
[i
];
660 js_log('looking at vid: ' + i
+' ' + vidId
);
661 //grab the thumbnail and src video
662 var pimg
= $j('#'+vidId
+ ' img');
663 var poster_attr
= 'poster = "' + pimg
.attr('src') + '" ';
664 var pwidth
= pimg
.attr('width');
665 var pheight
= pimg
.attr('height');
669 if( pwidth
=='22' && pheight
=='22'){
672 type_attr
= 'type="audio/ogg"';
680 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
681 src
= re
.exec( $j('#'+vidId
).html() )[2];
683 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
684 duration
= re
.exec( $j('#'+vidId
).html() )[2];
686 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
687 offset
= re
.exec( $j('#'+vidId
).html() )[2];
688 var offset_attr
= (offset
)? 'startOffset="'+ offset
+ '"': '';
691 //replace the top div with mv_embed based player:
692 var vid_html
= '<video id="vid_' + i
+'" '+
693 'src="' + src
+ '" ' +
697 'duration="' + duration
+ '" ' +
698 'style="width:' + pwidth
+ 'px;height:' +
699 pheight
+ 'px;"></video>';
700 //js_log("video html: " + vid_html);
701 $j('#'+vidId
).html( vid_html
);
704 //rewrite that video id:
705 rewrite_by_id('vid_' + i
);
710 /*********** INITIALIZATION CODE *************
711 * set DOM ready callback to init_mv_embed
712 *********************************************/
713 // for Mozilla browsers
714 if (document
.addEventListener
) {
715 document
.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
717 //backup "onload" method in case on DOMContentLoaded does not exist
718 window
.onload = function(){ mwdomReady() };
721 * should depreciate and use jquery.ui.dialog instead
723 function mv_write_modal(content
, speed
){
724 $j('#modalbox,#mv_overlay').remove();
725 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
726 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
729 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
730 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
732 $j('#modalbox,#mv_overlay').show( speed
);
734 function mv_remove_modal(speed
){
735 $j('#modalbox,#mv_overlay').remove( speed
);
739 * stores all the mwEmbed jQuery specific bindings
740 * (setup after jQuery is avaliable)
741 * lets you call rewrites in a jquery "way"
743 * @@ eventually we should refactor mwCode over to jQuery style plugins
744 * and mv_embed.js will just hanndle dependency mapping and loading.
747 function mv_jqueryBindings(){
748 js_log('mv_jqueryBindings');
750 $.fn
.addMediaWiz = function( iObj
, callback
){
751 //first set the cursor for the button to "loading"
752 $j(this.selector
).css('cursor','wait').attr('title', gM('loading_title'));
754 iObj
['target_invocation'] = this.selector
;
756 //load the mv_embed_base skin:
757 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
758 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css' );
759 //load all the req libs:
760 mvJsLoader
.jQueryCheck(function(){
761 //load with staged dependeinces (for ie and safari that don't execute in order)
762 mvJsLoader
.doLoadDepMode([
763 [ 'remoteSearchDriver',
774 iObj
['instance_name']= 'rsdMVRS';
775 _global
['rsdMVRS'] = new remoteSearchDriver( iObj
);
777 callback( _global
['rsdMVRS'] );
782 $.fn
.sequencer = function( iObj
, callback
){
784 iObj
['target_sequence_container'] = this.selector
;
785 //issue a request to get the css file (if not already included):
786 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
787 loadExternalCss( mv_embed_path
+'skins/'+mwConfig
['skin_name']+'/mv_sequence.css');
788 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
789 mvJsLoader
.embedVideoCheck(function(){
790 //load playlist object and then jquery ui stuff:
791 mvJsLoader
.doLoadDepMode([
811 js_log('calling new mvSequencer');
812 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
813 if(!_global
['mvSeq']){
814 _global
['mvSeq'] = new mvSequencer(iObj
);
816 js_log('mvSeq already init');
822 * the firefogg jquery function:
823 * @@note this firefogg envocation could be made to work more like real jquery plugins
825 $.fn
.firefogg = function( iObj
, callback
) {
828 //add base theme css:
829 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
830 loadExternalCss( mv_embed_path
+ 'skins/'+mwConfig
['skin_name']+'/styles.css' );
832 //check if we already have firefogg loaded (the call just updates properties for that element)
833 var sElm
= $j(this.selector
).get(0);
834 if(sElm
['firefogg']){
835 if(sElm
['firefogg']=='loading'){
836 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
841 js_log("firefogg::updated: "+ i
+ ' to '+ iObj
[i
]);
842 sElm
['firefogg'][i
] = iObj
[i
];
844 return sElm
['firefogg'];
847 sElm
['firefogg'] = 'loading';
850 iObj
['selector'] = this.selector
;
854 'mvBaseUploadInterface',
863 if( iObj
.encoder_interface
){
872 //make sure we have everything loaded that we need:
873 mvJsLoader
.doLoadDepMode( loadSet
, function(){
874 js_log('firefogg libs loaded. target select:' + iObj
.selector
);
875 //select interface provicer based on if we want to include the encoder interface or not:
876 if(iObj
.encoder_interface
){
877 var myFogg
= new mvAdvFirefogg( iObj
);
879 var myFogg
= new mvFirefogg( iObj
);
882 myFogg
.doRewrite( callback
);
883 var selectorElement
= $j( iObj
.selector
).get(0);
884 selectorElement
['firefogg']=myFogg
;
888 //takes a input player as the selector and exposes basic rendering controls
889 $.fn
.firefoggRender = function( iObj
, callback
){
890 //check if we already have render loaded then just pass on updates/actions
891 var sElm
= $j(this.selector
).get(0);
892 if(sElm
['fogg_render']){
893 if(sElm
['fogg_render']=='loading'){
894 js_log("Error: called firefoggRender while loading");
897 //call or update the property:
899 sElm
['fogg_render']='loading';
901 iObj
['player_target'] = this.selector
;
906 sElm
['fogg_render']= new mvFirefoggRender( iObj
);
907 if( callback
&& typeof callback
== 'function' )
908 callback( sElm
['fogg_render'] );
912 $.fn
.baseUploadInterface = function(iObj
){
913 mvJsLoader
.doLoadDepMode([
915 'mvBaseUploadInterface',
923 myUp
= new mvBaseUploadInterface( iObj
);
928 //shortcut to a themed button:
929 $.btnHtml = function(msg
, className
, iconId
, opt
){
932 var href
= (opt
.href
)?opt
.href
:'#';
933 var target_attr
= (opt
.target
)?' target="' + opt
.target
+ '" ':'';
934 var style_attr
= (opt
.style
)?' style="'+opt
.style
+'" ':'';
935 return '<a href="' + href
+ '" ' + target_attr
+ style_attr
+' class="ui-state-default ui-corner-all ui-icon_link ' +
936 className
+ '"><span class="ui-icon ui-icon-' + iconId
+ '" />' +
939 //shortcut to bind hover state:
940 $.fn
.btnBind = function(){
943 $j(this).addClass('ui-state-hover');
946 $j(this).removeClass('ui-state-hover');
957 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
958 function getURLParamReplace( url
, opt
){
959 var pSrc
= parseUri( url
);
960 if(pSrc
.protocol
!= '' ){
961 var new_url
= pSrc
.protocol
+'://'+ pSrc
.authority
+ pSrc
.path
+'?';
963 var new_url
= pSrc
.path
+'?';
966 for(var key
in pSrc
.queryKey
){
967 var val
= pSrc
.queryKey
[ key
];
968 //do override if requested
971 new_url
+= amp
+ key
+ '=' + val
;
974 //add any vars that did were not originally there:
976 if(!pSrc
.queryKey
[i
]){
977 new_url
+=amp
+ i
+ '=' + opt
[i
];
984 * seconds2npt given a float seconds returns npt format response:
985 * @param float seconds
986 * @param boolean if we should show ms or not.
988 function seconds2npt(sec
, show_ms
){
990 //js_log("warning: trying to get npt time on NaN:" + sec);
993 var hours
= Math
.floor(sec
/ 3600);
994 var minutes
= Math
.floor((sec
/60) % 60);
995 var seconds
= sec
% 60;
996 //round the second amount requested significant digits
998 seconds
= Math
.round( seconds
* 1000 ) / 1000;
1000 seconds
= Math
.round( seconds
);
1003 seconds
= '0'+ seconds
;
1005 minutes
= '0' + minutes
;
1007 return hours
+":"+minutes
+":"+seconds
;
1010 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
1012 function npt2seconds( npt_str
){
1014 //js_log('npt2seconds:not valid ntp:'+ntp);
1017 //strip npt: time definition if present
1018 npt_str
= npt_str
.replace('npt:', '');
1020 times
= npt_str
.split(':');
1021 if(times
.length
!=3){
1022 js_log('error: npt2seconds on ' + npt_str
);
1025 //sometimes the comma is used inplace of pereid for ms
1026 times
[2] = times
[2].replace(/,\s?/,'.');
1027 //return seconds float (ie take seconds float value if present):
1028 return parseInt(times
[0]*3600)+parseInt(times
[1]*60)+parseFloat(times
[2]);
1031 * simple helper to grab a edit token
1033 * @param title the wiki page title you want to edit )
1034 * @param api_url 'optional' the target api url
1035 * @param callback the callback function to pass the token or "false" to
1037 function get_mw_token( title
, api_url
, callback
){
1038 js_log(':get_mw_token:');
1039 if(!title
&& wgUserName
){
1040 title
= 'User:' + wgUserName
;
1052 for(var i
in data
.query
.pages
){
1053 if(data
.query
.pages
[i
]['edittoken']){
1054 if(typeof callback
== 'function')
1055 callback ( data
.query
.pages
[i
]['edittoken'] );
1063 //does a remote or local api request based on request url
1064 //@param options: url, data, cbParam, callback
1065 function do_api_req( options
, callback
){
1066 if(typeof options
.data
!= 'object'){
1067 return js_error('Error: request paramaters must be an object');;
1069 //gennerate the url if its missing:
1070 if( typeof options
.url
== 'undefined' || options
.url
=== false){
1071 if(!wgServer
|| ! wgScriptPath
){
1072 return js_error('Error: no api url for api request');;
1074 //update to api.php (if index.php was in the wgScript path):
1075 options
.url
= mwGetLocalApiUrl();
1077 if( typeof options
.data
== 'undefined' )
1080 //force format to json (if not already set)
1081 options
.data
['format'] = 'json';
1083 //if action not set assume query
1084 if(!options
.data
['action'])
1085 options
.data
['action']='query';
1087 js_log('do api req: ' + options
.url
+'?' + jQuery
.param(options
.data
) );
1088 //build request string:
1089 if( parseUri( document
.URL
).host
== parseUri( options
.url
).host
){
1090 //local request do api request directly
1095 dataType
:'json', //api requests _should_ always return JSON data:
1097 success:function(data
){
1101 js_error( ' error' + e
+' in getting: ' + options
.url
);
1105 //set the callback param if not already set:
1106 if( typeof options
.jsonCB
== 'undefined')
1107 options
.jsonCB
= 'callback';
1109 var req_url
= options
.url
;
1110 var paramAnd
= (req_url
.indexOf('?')==-1)?'?':'&';
1111 //put all the values into the GET req:
1112 for(var i
in options
.data
){
1113 req_url
+= paramAnd
+ encodeURIComponent( i
) + '=' + encodeURIComponent( options
.data
[i
] );
1116 var fname
= 'mycpfn_' + ( global_cb_count
++ );
1117 _global
[ fname
] = callback
;
1118 req_url
+= '&' + options
.jsonCB
+ '=' + fname
;
1119 loadExternalJs( req_url
);
1122 function mwGetLocalApiUrl(url
){
1123 if (wgServer
&& wgScriptPath
){
1124 return wgServer
+ wgScriptPath
+ '/api.php';
1128 //grab wiki form error for wiki html page proccessing (should be depricated)
1129 function grabWikiFormError ( result_page
){
1131 sp
= result_page
.indexOf('<span class="error">');
1133 se
= result_page
.indexOf('</span>', sp
);
1134 res
.error_txt
= result_page
.substr(sp
, (sp
-se
)) + '</span>';
1137 sp
= result_page
.indexOf('<ul class="warning">')
1139 se
= result_page
.indexOf('</ul>', sp
);
1140 res
.error_txt
= result_page
.substr(sp
, (se
-sp
)) + '</ul>';
1141 //try and add the ignore form item:
1142 sfp
= result_page
.indexOf('<form method="post"');
1144 sfe
= result_page
.indexOf('</form>', sfp
);
1145 res
.form_txt
= result_page
.substr(sfp
, ( sfe
- sfp
)) + '</form>';
1148 //one more error type check:
1149 sp
= result_page
.indexOf('class="mw-warning-with-logexcerpt">')
1151 se
= result_page
.indexOf('</div>', sp
);
1152 res
.error_txt
= result_page
.substr(sp
, ( se
- sp
)) + '</div>';
1158 //do a "normal" request
1159 function do_request(req_url
, callback
){
1160 js_log('do_request::req_url:' + req_url
+ ' != ' + parseUri( req_url
).host
);
1161 //if we are doing a request to the same domain or relative link do a normal GET:
1162 if( parseUri(document
.URL
).host
== parseUri(req_url
).host
||
1163 req_url
.indexOf('://') == -1 ){ //relative url
1164 //do a direct request:
1169 success:function(data
){
1174 //get data via DOM injection with callback
1175 global_req_cb
.push(callback
);
1176 //prepend json_ to feed_format if not already requesting json format
1177 if( req_url
.indexOf("feed_format=")!=-1 && req_url
.indexOf("feed_format=json")==-1)
1178 req_url
= req_url
.replace(/feed_format=/, 'feed_format=json_');
1179 loadExternalJs( req_url
+ '&cb=mv_jsdata_cb&cb_inx=' + (global_req_cb
.length
-1));
1183 function mv_jsdata_cb(response
){
1184 js_log('f:mv_jsdata_cb:'+ response
['cb_inx']);
1185 //run the callback from the global req cb object:
1186 if( !global_req_cb
[response
['cb_inx']] ){
1187 js_log('missing req cb index');
1190 if( !response
['pay_load'] ){
1191 js_log("missing pay load");
1194 //switch on content type:
1195 switch(response
['content-type']){
1199 if(typeof response
['pay_load'] == 'string'){
1200 //js_log('load string:'+"\n"+ response['pay_load']);
1202 //attempt to parse as xml for IE
1203 if( $j
.browser
.msie
){
1204 var xmldata
=new ActiveXObject("Microsoft.XMLDOM");
1205 xmldata
.async
="false";
1206 xmldata
.loadXML(response
['pay_load']);
1207 }else{ //for others (firefox, safari etc)
1209 var xmldata
= (new DOMParser()).parseFromString(response
['pay_load'], "text/xml");
1211 js_log('XML parse ERROR: ' + e
.message
);
1214 //@@todo hanndle xml parser errors
1215 if(xmldata
)response
['pay_load']=xmldata
;
1219 js_log('bad response type' + response
['content-type']);
1223 global_req_cb
[response
['cb_inx']]( response
['pay_load'] );
1225 //load external js via dom injection
1226 function loadExternalJs( url
, callback
){
1227 js_log('load js: '+ url
);
1228 //if(window['$j']) //use jquery call:
1236 var e
= document
.createElement("script");
1237 e
.setAttribute('src', url
);
1238 e
.setAttribute('type', "text/javascript");
1240 e.onload = callback;
1242 //e.setAttribute('defer', true);
1243 document
.getElementsByTagName("head")[0].appendChild(e
);
1246 function styleSheetPresent(url
){
1247 style_elements
= document
.getElementsByTagName('link');
1248 if( style_elements
.length
> 0) {
1249 for(i
= 0; i
< style_elements
.length
; i
++) {
1250 if(style_elements
[i
].href
== url
)
1256 function loadExternalCss(url
){
1257 //if could have script loader group thes css request
1258 //but debatable it may hurt more than it helps with caching and all
1259 if(typeof url
=='object'){
1261 loadExternalCss ( url
[i
] );
1266 if( url
.indexOf('?') == -1 ){
1267 url
+='?'+getMvUniqueReqId();
1269 if(!styleSheetPresent(url
) ){
1270 js_log('load css: ' + url
);
1271 var e
= document
.createElement("link");
1273 e
.type
= "text/css";
1274 e
.rel
= 'stylesheet';
1275 document
.getElementsByTagName("head")[0].appendChild(e
);
1278 function getMvEmbedURL(){
1279 if( _global
['mv_embed_url'] )
1280 return _global
['mv_embed_url'];
1281 var js_elements
= document
.getElementsByTagName("script");
1282 for(var i
=0; i
< js_elements
.length
; i
++){
1283 //check for normal mv_embed.js and or script loader
1284 var src
= js_elements
[i
].getAttribute("src");
1286 if( src
.indexOf('mv_embed.js') !=-1 || (
1287 ( src
.indexOf('mwScriptLoader.php') != -1 || src
.indexOf('jsScriptLoader.php') != -1 )
1288 && src
.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1289 _global
['mv_embed_url'] = src
;
1294 js_error('Error: getMvEmbedURL failed to get Embed Path');
1297 //gets a unique request id to ensure fresh javascript
1298 function getMvUniqueReqId(){
1299 if( _global
['urid'] )
1300 return _global
['urid'];
1301 var mv_embed_url
= getMvEmbedURL();
1302 //if we have a uri retun that:
1303 var urid
= parseUri( mv_embed_url
).queryKey
['urid']
1305 _global
['urid'] = urid
;
1308 //if in debug mode get a fresh unique request key:
1309 if( parseUri( mv_embed_url
).queryKey
['debug'] == 'true'){
1311 var urid
= d
.getTime();
1312 _global
['urid'] = urid
;
1315 //else just return the mv_embed version;
1316 return MV_EMBED_VERSION
;
1319 * sets the global mv_embed path based on the scripts location
1321 function getMvEmbedPath(){
1322 if( _global
['mv_embed_path'])
1323 return _global
['mv_embed_path'];
1324 var mv_embed_url
= getMvEmbedURL();
1325 if( mv_embed_url
.indexOf('mv_embed.js') !== -1 ){
1326 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mv_embed.js'));
1327 }else if(mv_embed_url
.indexOf('mwScriptLoader.php')!==-1){
1328 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1329 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path
;
1331 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('jsScriptLoader.php'));
1333 //absolute the url (if relative) (if we don't have mv_embed path)
1334 if( mv_embed_path
.indexOf('://') == -1){
1335 var pURL
= parseUri( document
.URL
);
1336 if(mv_embed_path
.charAt(0)=='/'){
1337 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ mv_embed_path
;
1340 if(mv_embed_path
==''){
1341 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ pURL
.directory
+ mv_embed_path
;
1345 _global
['mv_embed_path'] = mv_embed_path
;
1346 return mv_embed_path
;
1349 if (typeof DOMParser
== "undefined") {
1350 DOMParser = function () {}
1351 DOMParser
.prototype.parseFromString = function (str
, contentType
) {
1352 if (typeof ActiveXObject
!= "undefined") {
1353 var d
= new ActiveXObject("MSXML.DomDocument");
1356 } else if (typeof XMLHttpRequest
!= "undefined") {
1357 var req
= new XMLHttpRequest
;
1358 req
.open("GET", "data:" + (contentType
|| "application/xml") +
1359 ";charset=utf-8," + encodeURIComponent(str
), false);
1360 if (req
.overrideMimeType
) {
1361 req
.overrideMimeType(contentType
);
1364 return req
.responseXML
;
1369 * utility functions:
1371 function js_log(string
){
1372 if( window
.console
){
1373 window
.console
.log(string
);
1376 * IE and non-firebug debug:
1378 /*var log_elm = document.getElementById('mv_js_log');
1380 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1381 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1382 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1385 var log_elm = document.getElementById('mv_js_log');
1388 log_elm.value+=string+"\n";
1394 function checkDefaultMwConfig(){
1395 for(var i
in defaultMwConfig
){
1396 if(typeof(mwConfig
[i
])=='undefined'){
1397 mwConfig
[i
] =defaultMwConfig
[i
];
1402 function js_error(string
){