2 * ~mv_embed version 1.0~
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.0r18';
26 * Configuration variables (can be set from some precceding script)
28 //the name of the player skin (default is mvpcf)
30 var mv_skin_name
= 'mvpcf';
33 var mwjQueryUiSkin
= 'redmond';
35 //whether or not to load java from an iframe.
36 //note: this is necessary for remote embedding because of java security model)
38 var mv_java_iframe
= true;
40 //the default height/width of the video (if no style or width attribute provided)
41 if(!mv_default_video_size
)
42 var mv_default_video_size
= '400x300';
44 //for when useing mv_embed with script-loader in root mediawiki path
45 var mediaWiki_mvEmbed_path
= 'js2/mwEmbed/';
47 var global_player_list
= new Array(); //the global player list per page
48 var global_req_cb
= new Array(); //the global request callback array
49 var _global
= this; //global obj
50 var mv_init_done
=false;
51 var global_cb_count
=0;
53 /*parseUri class parses URIs:*/
54 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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
57 //get mv_embed location if it has not been set
59 var mv_embed_path
= getMvEmbedPath();
61 var jQueryUiVN
= 'jquery.ui-1.7.1';
64 //setup the skin path:
65 var mv_jquery_skin_path
= mv_embed_path
+ 'jquery/' + jQueryUiVN
+ '/themes/' + mwjQueryUiSkin
+ '/';
66 var mv_skin_img_path
= mv_embed_path
+ 'skins/' + mv_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",
93 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
94 * any file _not_ listed here won't be auto-loadable
95 * @path the path to the file (or set of files) with ending slash
96 * @gClasses the set of classes
97 * if an array $j.className become jquery.className.js
98 * if an asssociative object then key => value paris are used
100 if(typeof mvClassPaths
== 'undefined')
103 function lcPaths( path
, gClasses
, opt
){
106 if(typeof opt
['j_replace'] == 'undefined')
107 opt
['j_replace'] = 'jquery.';
112 for(var i
=0; i
< gClasses
.length
; i
++){
113 if(typeof gClasses
[i
] != 'undefined'){
114 //setup normal replacement of j with jquery
115 var jsName
= ( gClasses
[i
].substr(0,3) == '$j.' ) ? opt
['j_replace'] + gClasses
[i
].substr(3) : gClasses
[i
];
116 mvClassPaths
[ gClasses
[i
] ] = path
+ jsName
+ '.js';
121 for(var i
in gClasses
){
122 //assume object with key:path:
123 mvClassPaths
[i
] = path
+ gClasses
[ i
];
127 function mvGetClassPath(k
){
128 if( mvClassPaths
[k
] ){
129 //js_log('got classpath:' + k + ' : '+ mvClassPaths[k]);
130 return mvClassPaths
[k
];
132 return js_error('could not find path for requested class ' + k
);
135 if(typeof mvCssPaths
== 'undefined')
138 function lcCssPath(cssSet
){
139 for(var i
in cssSet
){
140 mvCssPaths
[i
]= mv_embed_path
+ cssSet
[i
];
143 //core and (non-standard named files relative to class the init):
145 'mv_embed' : 'mv_embed.js',
146 'window.jQuery' : 'jquery/jquery-1.3.2.js',
147 '$j.fn.pngFix' : 'jquery/plugins/jquery.pngFix.js',
148 '$j.fn.autocomplete': 'jquery/plugins/jquery.autocomplete.js',
149 '$j.fn.hoverIntent' : 'jquery/plugins/jquery.hoverIntent.js',
150 '$j.fn.datePicker' : 'jquery/plugins/jquery.datePicker.js',
151 '$j.ui' : 'jquery/jquery.ui-1.7.1/ui/ui.core.js',
152 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/js/colorpicker.js',
153 '$j.Jcrop' : 'libClipEdit/Jcrop/js/jquery.Jcrop.js',
154 '$j.fn.simpleUploadForm': 'libAddMedia/simpleUploadForm.js'
157 lcPaths( 'jquery/plugins/', [
163 lcPaths('jquery/jquery.ui-1.7.1/ui/', [
166 '$j.effects.pulsate',
167 '$j.effects.transfer',
171 '$j.effects.explode',
183 '$j.effects.highlight',
191 lcPaths('libAddMedia/', [
194 'mvBaseUploadInterface',
195 'remoteSearchDriver',
196 'seqRemoteSearchDriver'
199 lcPaths('libAddMedia/searchLibs/', [
207 lcPaths( 'libClipEdit/', [
210 //libEmbedObj (we could load all these clasess in embedVideo):
211 lcPaths( 'libEmbedVideo/', [
222 lcPaths( 'libSequencer/', [
229 lcPaths( 'libTimedText/', [
233 //depencency mapping for css files for self contained included plugins:
235 '$j.ui' : 'jquery/' + jQueryUiVN
+ '.custom.css',
236 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
237 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/css/colorpicker.css'
241 * Language Functions:
243 * These functions try to losely mirro the functionality of Language.php in mediaWiki
245 function gM( key
, args
) {
249 if(typeof args
== 'object' || typeof args
== 'array'){
251 //msg test replace arguments start at 1 insted of zero:
252 var rep
= '\$'+ ( parseInt(v
) + 1 );
253 ms
= ms
.replace( rep
, args
[v
]);
255 }else if(typeof args
=='string' || typeof args
=='number'){
256 ms
= ms
.replace(/\$1/, args
);
260 //key is missing return indication:
261 return '<' + key
+ '>';
265 * msgSet is either a string corresponding to a single msg to load
266 * or msgSet is an array with set of msg to load
268 function gMsgLoadRemote(msgSet
, callback
){
270 if(typeof msgSet
== 'object' ){
271 for(var i
in msgSet
){
272 ammessages
+= msgSet
[i
] + '|';
274 }else if(typeof msgSet
== 'string'){
275 ammessages
+= msgSet
;
277 if(ammessages
== ''){
278 js_log('gMsgLoadRemote::no msg set requested');
283 'meta':'allmessages',
284 'ammessages':ammessages
287 if(data
.query
.allmessages
){
288 var msgs
= data
.query
.allmessages
;
291 ld
[ msgs
[i
]['name'] ] = msgs
[i
]['*'];
295 //load the result into local msg var
301 * Format a size in bytes for output, using an appropriate
302 * unit (B, KB, MB or GB) according to the magnitude in question
304 * @param size Size to format
305 * @return string Plain text (not HTML)
307 function formatSize( size
) {
308 // For small sizes no decimal places necessary
315 // For MB and bigger two decimal places are smarter
319 msg
= 'size-gigabytes';
321 msg
= 'size-megabytes';
324 msg
= 'size-kilobytes';
329 //javascript does not let you do precession points in rounding
330 var p
= Math
.pow(10,round
);
331 var size
= Math
.round( size
* p
) / p
;
332 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
333 return gM( msg
, size
);
336 //gets the loading image:
337 function mv_get_loading_img( style
, class_attr
){
338 var style_txt
= (style
)?style
:'';
339 var class_attr
= (class_attr
)?'class="'+class_attr
+'"':'class="mv_loading_img"';
340 return '<div '+class_attr
+' style="' + style
+'"></div>';
343 function mv_set_loading(target
, load_id
){
344 var id_attr
= ( load_id
)?' id="' + load_id
+ '" ':'';
345 $j(target
).append('<div '+id_attr
+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
346 'background-color:#FFF;">' +
347 mv_get_loading_img('top:30px;left:30px') +
352 * mvJsLoader class handles initialization and js file loads
358 onReadyEvents
:new Array(),
359 doneReadyEvents
:false,
360 jQueryCheckFlag
:false,
361 //to keep consistency across threads:
364 load_error
:false, //load error flag (false by default)
366 callbacks
:new Array(),
369 doLoad:function(loadLibs
, callback
){
371 if( loadLibs
&& loadLibs
.length
!=0 ){ //setup this.libs:
373 //first check if we already have this lib loaded
374 var all_libs_loaded
=true;
375 for(var i
=0; i
< loadLibs
.length
; i
++){
376 //check if the lib is already loaded:
377 if( ! this.checkObjPath( loadLibs
[i
] ) ){
378 all_libs_loaded
=false;
381 if( all_libs_loaded
){
382 js_log('all libs already loaded skipping... load req');
386 //do a check for any css we may need and get it:
387 for(var i
=0; i
< loadLibs
.length
; i
++){
388 if( typeof mvCssPaths
[ loadLibs
[i
] ] != 'undefined' ){
389 loadExternalCss( mvCssPaths
[ loadLibs
[i
] ]);
393 //check if we should use the script loader to combine all the requests into one:
394 if( typeof mwSlScript
!= 'undefined' ){
398 for(var i
=0; i
< loadLibs
.length
; i
++){
399 var curLib
= loadLibs
[i
];
400 //only add if not included yet:
401 if( ! this.checkObjPath( curLib
) ){
402 class_set
+=coma
+ curLib
;
407 var puri
= parseUri( getMvEmbedURL() );
408 if( (getMvEmbedURL().indexOf('://')!=-1) && puri
.host
!= parseUri( document
.URL
).host
){
409 mwSlScript
= puri
.protocol
+ '://' + puri
.authority
+ mwSlScript
;
412 var dbug_attr
= (puri
.queryKey
['debug'])?'&debug=true':'';
413 this.libs
[ last_class
] = mwSlScript
+ '?class=' + class_set
+
414 '&urid=' + getMvUniqueReqId() + dbug_attr
;
418 for(var i
=0; i
< loadLibs
.length
; i
++){
419 var curLib
= loadLibs
[i
];
421 var libLoc
= mvGetClassPath(curLib
);
422 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
423 var qmark
= (libLoc
.indexOf('?')!==true)?'?':'&';
424 this.libs
[curLib
] = mv_embed_path
+ libLoc
+ qmark
+ 'urid='+ getMvUniqueReqId();
430 this.callbacks
.push(callback
);
432 if( this.checkLoading() ){
433 if( this.load_time
++ > 1000){ //time out after ~80seconds
434 js_error( gM('error_load_lib') + this.missing_path
);
435 this.load_error
=true;
437 setTimeout( 'mvJsLoader.doLoad()', 20 );
440 //js_log('checkLoading passed run callbacks');
441 //only do callback if we are in the same instance (weird concurency issue)
443 for(var i
=0; i
< this.callbacks
.length
; i
++)
445 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
448 //js_log('done loading do call: ' + this.callbacks[0] );
449 while( this.callbacks
.length
!=0 ){
450 if( this.ptime
== ( this.ctime
-1) ){ //enforce thread consistency
451 this.callbacks
.pop()();
452 //func = this.callbacks.pop();
453 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
456 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
457 setTimeout( 'mvJsLoader.doLoad()', 25 );
462 this.ptime
=this.ctime
;
464 doLoadFullPaths:function(loadObj
, callback
){
467 doLoadDepMode:function(loadChain
, callback
){
468 //firefox executes js ~in-order of it being included~ so just directly issue request:
469 if( $j
.browser
.firefox
){
471 for(var i
=0; i
< loadChain
.length
;i
++){
472 for(var j
=0;j
<loadChain
[i
].length
;j
++){
473 loadSet
.push(loadChain
[i
][j
]);
476 mvJsLoader
.doLoad(loadSet
, callback
);
478 //safari and IE tend to execute out of order so load with dependenciy checks
479 mvJsLoader
.doLoad(loadChain
.shift(),function(){
480 if(loadChain
.length
!=0){
481 mvJsLoader
.doLoadDepMode(loadChain
, callback
);
487 checkLoading:function(){
490 for(var i
in this.libs
){ //for in loop oky on object
491 if( !this.checkObjPath( i
) ){
493 loadExternalJs( this.libs
[i
] );
497 //js_log("has not yet loaded: " + i);
503 checkObjPath:function( libVar
){
506 var objPath
= libVar
.split('.')
508 for(var p
=0; p
< objPath
.length
; p
++){
509 cur_path
= (cur_path
=='')?cur_path
+objPath
[p
]:cur_path
+'.'+objPath
[p
];
510 eval( 'var ptest = typeof ( '+ cur_path
+ ' ); ');
511 if( ptest
== 'undefined'){
512 this.missing_path
= cur_path
;
516 this.cur_path
= cur_path
;
520 * checks for jQuery and adds the $j noConflict var
522 jQueryCheck:function(callback
){
523 //skip stuff if $j is already loaded:
524 if(_global
['$j'] && callback
)
531 _global
['$j'] = jQuery
.noConflict();
532 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
536 js_log('jquery loaded');
537 //setup mvEmbed jquery bindigns:
545 embedVideoCheck:function( callback
){
547 js_log('embedVideoCheck:');
548 //set videonojs to loading
549 //issue a style sheet request get both mv_embed and jquery styles:
550 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
551 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css');
553 //make sure we have jQuery
554 _this
.jQueryCheck(function(){
555 $j('.videonojs').html( gM('loading_txt') );
566 //add png fix if needed:
567 if($j
.browser
.msie
|| $j
.browser
.version
< 7)
568 depReq
[0].push( '$j.fn.pngFix' );
570 _this
.doLoadDepMode(depReq
,function(){
573 $j('.videonojs').remove();
577 addLoadEvent:function(fn
){
578 this.onReadyEvents
.push(fn
);
580 //checks the jQuery flag (this way when remote embeding we don't load jQuery
581 // unless js2AddOnloadHook was used or there is video on the page
582 runQuededFunctions:function(){
584 this.doneReadyEvents
=true;
585 if(this.jQueryCheckFlag
){
586 this.jQueryCheck(function(){
587 _this
.runReadyEvents();
590 this.runReadyEvents();
593 runReadyEvents:function(){
594 js_log("runReadyEvents");
595 while( this.onReadyEvents
.length
){
596 this.onReadyEvents
.shift()();
601 //load an external JS (similar to jquery .require plugin)
602 //but checks for object availability rather than load state
604 /*********** INITIALIZATION CODE *************
605 * this will get called when DOM is ready
606 *********************************************/
607 /* jQuery .ready does not work when jQuery is loaded dynamically
608 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
609 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
610 * $j(document).ready( function(){ */
611 function mwdomReady(force
){
612 js_log('f:mwdomReady:');
613 if( !force
&& mv_init_done
){
614 js_log("mv_init_done already done do nothing...");
618 //handle the execution of Queded function with jQuery "ready"
620 //check if this page does have video or playlist
622 document
.getElementsByTagName("video"),
623 document
.getElementsByTagName("audio"),
624 document
.getElementsByTagName("playlist")
626 if(e
[0].length
!=0 || e
[1].length
!=0 || e
[2].length
!=0){
627 js_log('we have items to rewrite');
629 //load libs and proccess:
630 mvJsLoader
.embedVideoCheck(function(){
631 //run any queded global events:
632 mv_video_embed( function(){
633 mvJsLoader
.runQuededFunctions();
637 //if we already have jQuery make sure its loaded into its proper context $j
638 //run any queded global events:
639 mvJsLoader
.runQuededFunctions();
642 //js2AddOnloadHook: ensure jQuery and the DOM are ready:
643 function js2AddOnloadHook( func
) {
644 //make sure the skin/style sheets are avaliable always:
645 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
646 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css');
648 //if we have already run the dom ready just run the function directly:
649 if( mvJsLoader
.doneReadyEvents
){
650 //make sure jQuery is there:
651 mvJsLoader
.jQueryCheck(function(){
655 //if using js2AddOnloadHook we need to get jQuery into place (if its not already included)
656 mvJsLoader
.jQueryCheckFlag
= true;
657 mvJsLoader
.addLoadEvent( func
);
660 //depreciated mwAddOnloadHook in favor of js2 naming (for clear seperation of js2 code from old mw code
661 var mwAddOnloadHook
= js2AddOnloadHook
;
663 * this function allows for targeted rewriting
665 function rewrite_by_id( vid_id
, ready_callback
){
666 js_log('f:rewrite_by_id: ' + vid_id
);
667 //force a recheck of the dom for playlist or video element:
668 mvJsLoader
.embedVideoCheck(function(){
669 mv_video_embed(ready_callback
, vid_id
);
672 //depricated in favor of updates to oggHanlder
673 function rewrite_for_oggHanlder( vidIdList
){
674 for(var i
= 0; i
< vidIdList
.length
; i
++){
675 var vidId
= vidIdList
[i
];
676 js_log('looking at vid: ' + i
+' ' + vidId
);
677 //grab the thumbnail and src video
678 var pimg
= $j('#'+vidId
+ ' img');
679 var poster_attr
= 'poster = "' + pimg
.attr('src') + '" ';
680 var pwidth
= pimg
.attr('width');
681 var pheight
= pimg
.attr('height');
685 if( pwidth
=='22' && pheight
=='22'){
688 type_attr
= 'type="audio/ogg"';
696 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
697 src
= re
.exec( $j('#'+vidId
).html() )[2];
699 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
700 duration
= re
.exec( $j('#'+vidId
).html() )[2];
702 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
703 offset
= re
.exec( $j('#'+vidId
).html() )[2];
704 var offset_attr
= (offset
)? 'startOffset="'+ offset
+ '"': '';
707 //replace the top div with mv_embed based player:
708 var vid_html
= '<video id="vid_' + i
+'" '+
709 'src="' + src
+ '" ' +
713 'duration="' + duration
+ '" ' +
714 'style="width:' + pwidth
+ 'px;height:' +
715 pheight
+ 'px;"></video>';
716 //js_log("video html: " + vid_html);
717 $j('#'+vidId
).html( vid_html
);
720 //rewrite that video id:
721 rewrite_by_id('vid_' + i
);
726 /*********** INITIALIZATION CODE *************
727 * set DOM ready callback to init_mv_embed
728 *********************************************/
729 // for Mozilla browsers
730 if (document
.addEventListener
) {
731 document
.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
733 //backup "onload" method in case on DOMContentLoaded does not exist
734 window
.onload = function(){ mwdomReady() };
737 * should depreciate and use jquery.ui.dialog instead
739 function mv_write_modal(content
, speed
){
740 $j('#modalbox,#mv_overlay').remove();
741 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
742 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
745 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
746 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
748 $j('#modalbox,#mv_overlay').show( speed
);
750 function mv_remove_modal(speed
){
751 $j('#modalbox,#mv_overlay').remove( speed
);
755 * stores all the mwEmbed jQuery specific bindings
756 * (setup after jQuery is avaliable)
757 * lets you call rewrites in a jquery "way"
759 * @@ eventually we should refactor mwCode over to jQuery style plugins
760 * and mv_embed.js will just hanndle dependency mapping and loading.
763 function mv_jqueryBindings(){
764 js_log('mv_jqueryBindings');
766 $.fn
.addMediaWiz = function( iObj
, callback
){
767 //first set the cursor for the button to "loading"
768 $j(this.selector
).css('cursor','wait').attr('title', gM('loading_title'));
770 iObj
['target_invocation'] = this.selector
;
772 //load the mv_embed_base skin:
773 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
774 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
775 //load all the req libs:
776 mvJsLoader
.jQueryCheck(function(){
777 //load with staged dependeinces (for ie and safari that don't execute in order)
778 mvJsLoader
.doLoadDepMode([
779 [ 'remoteSearchDriver',
790 iObj
['instance_name']= 'rsdMVRS';
791 _global
['rsdMVRS'] = new remoteSearchDriver( iObj
);
793 callback( _global
['rsdMVRS'] );
798 $.fn
.sequencer = function( iObj
, callback
){
800 iObj
['target_sequence_container'] = this.selector
;
801 //issue a request to get the css file (if not already included):
802 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
803 loadExternalCss( mv_embed_path
+'skins/'+mv_skin_name
+'/mv_sequence.css');
804 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
805 mvJsLoader
.embedVideoCheck(function(){
806 //load playlist object and then jquery ui stuff:
807 mvJsLoader
.doLoadDepMode([
827 js_log('calling new mvSequencer');
828 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
829 if(!_global
['mvSeq']){
830 _global
['mvSeq'] = new mvSequencer(iObj
);
832 js_log('mvSeq already init');
838 * the firefogg jquery function:
839 * @@note this firefogg envocation could be made to work more like real jquery plugins
841 $.fn
.firefogg = function( iObj
, callback
) {
844 //add base theme css:
845 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
846 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
848 //check if we already have firefogg loaded (the call just updates properties for that element)
849 var sElm
= $j(this.selector
).get(0);
850 if(sElm
['firefogg']){
851 if(sElm
['firefogg']=='loading'){
852 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
857 js_log("firefogg::updated: "+ i
+ ' to '+ iObj
[i
]);
858 sElm
['firefogg'][i
] = iObj
[i
];
860 return sElm
['firefogg'];
863 sElm
['firefogg'] = 'loading';
866 iObj
['selector'] = this.selector
;
870 'mvBaseUploadInterface',
879 if( iObj
.encoder_interface
){
888 //make sure we have everything loaded that we need:
889 mvJsLoader
.doLoadDepMode( loadSet
, function(){
890 js_log('firefogg libs loaded. target select:' + iObj
.selector
);
891 //select interface provicer based on if we want to include the encoder interface or not:
892 if(iObj
.encoder_interface
){
893 var myFogg
= new mvAdvFirefogg( iObj
);
895 var myFogg
= new mvFirefogg( iObj
);
898 myFogg
.doRewrite( callback
);
899 var selectorElement
= $j( iObj
.selector
).get(0);
900 selectorElement
['firefogg']=myFogg
;
904 //takes a input player as the selector and exposes basic rendering controls
905 $.fn
.firefoggRender = function( iObj
, callback
){
906 //check if we already have render loaded then just pass on updates/actions
907 var sElm
= $j(this.selector
).get(0);
908 if(sElm
['fogg_render']){
909 if(sElm
['fogg_render']=='loading'){
910 js_log("Error: called firefoggRender while loading");
913 //call or update the property:
915 sElm
['fogg_render']='loading';
917 iObj
['player_target'] = this.selector
;
922 sElm
['fogg_render']= new mvFirefoggRender( iObj
);
923 if( callback
&& typeof callback
== 'function' )
924 callback( sElm
['fogg_render'] );
928 $.fn
.baseUploadInterface = function(iObj
){
929 mvJsLoader
.doLoadDepMode([
931 'mvBaseUploadInterface',
939 myUp
= new mvBaseUploadInterface( iObj
);
944 //shortcut to a themed button:
945 $.btnHtml = function(msg
, className
, iconId
, opt
){
948 var href
= (opt
.href
)?opt
.href
:'#';
949 var target_attr
= (opt
.target
)?' target="' + opt
.target
+ '" ':'';
950 var style_attr
= (opt
.style
)?' style="'+opt
.style
+'" ':'';
951 return '<a href="' + href
+ '" ' + target_attr
+ style_attr
+' class="ui-state-default ui-corner-all ui-icon_link ' +
952 className
+ '"><span class="ui-icon ui-icon-' + iconId
+ '" />' +
955 //shortcut to bind hover state:
956 $.fn
.btnBind = function(){
959 $j(this).addClass('ui-state-hover');
962 $j(this).removeClass('ui-state-hover');
973 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
974 function getURLParamReplace( url
, opt
){
975 var pSrc
= parseUri( url
);
976 if(pSrc
.protocol
!= '' ){
977 var new_url
= pSrc
.protocol
+'://'+ pSrc
.authority
+ pSrc
.path
+'?';
979 var new_url
= pSrc
.path
+'?';
982 for(var key
in pSrc
.queryKey
){
983 var val
= pSrc
.queryKey
[ key
];
984 //do override if requested
987 new_url
+= amp
+ key
+ '=' + val
;
990 //add any vars that did were not originally there:
992 if(!pSrc
.queryKey
[i
]){
993 new_url
+=amp
+ i
+ '=' + opt
[i
];
1000 * seconds2npt given a float seconds returns npt format response:
1001 * @param float seconds
1002 * @param boolean if we should show ms or not.
1004 function seconds2npt(sec
, show_ms
){
1006 //js_log("warning: trying to get npt time on NaN:" + sec);
1009 var hours
= Math
.floor(sec
/ 3600);
1010 var minutes
= Math
.floor((sec
/60) % 60);
1011 var seconds
= sec
% 60;
1012 //round the second amount requested significant digits
1014 seconds
= Math
.round( seconds
* 1000 ) / 1000;
1016 seconds
= Math
.round( seconds
);
1019 seconds
= '0'+ seconds
;
1021 minutes
= '0' + minutes
;
1023 return hours
+":"+minutes
+":"+seconds
;
1026 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
1028 function npt2seconds( npt_str
){
1030 //js_log('npt2seconds:not valid ntp:'+ntp);
1033 //strip npt: time definition if present
1034 npt_str
= npt_str
.replace('npt:', '');
1036 times
= npt_str
.split(':');
1037 if(times
.length
!=3){
1038 js_log('error: npt2seconds on ' + npt_str
);
1041 //sometimes the comma is used inplace of pereid for ms
1042 times
[2] = times
[2].replace(/,\s?/,'.');
1043 //return seconds float (ie take seconds float value if present):
1044 return parseInt(times
[0]*3600)+parseInt(times
[1]*60)+parseFloat(times
[2]);
1047 * simple helper to grab a edit token
1049 * @param title the wiki page title you want to edit )
1050 * @param api_url 'optional' the target api url
1051 * @param callback the callback function to pass the token or "false" to
1053 function get_mw_token( title
, api_url
, callback
){
1054 js_log(':get_mw_token:');
1055 if(!title
&& wgUserName
){
1056 title
= 'User:' + wgUserName
;
1068 for(var i
in data
.query
.pages
){
1069 if(data
.query
.pages
[i
]['edittoken']){
1070 if(typeof callback
== 'function')
1071 callback ( data
.query
.pages
[i
]['edittoken'] );
1079 //does a remote or local api request based on request url
1080 //@param options: url, data, cbParam, callback
1081 function do_api_req( options
, callback
){
1082 if(typeof options
.data
!= 'object'){
1083 return js_error('Error: request paramaters must be an object');;
1085 //gennerate the url if its missing:
1086 if( typeof options
.url
== 'undefined' || options
.url
=== false){
1087 if(!wgServer
|| ! wgScriptPath
){
1088 return js_error('Error: no api url for api request');;
1090 //update to api.php (if index.php was in the wgScript path):
1091 options
.url
= mwGetLocalApiUrl();
1093 if( typeof options
.data
== 'undefined' )
1096 //force format to json (if not already set)
1097 options
.data
['format'] = 'json';
1099 //if action not set assume query
1100 if(!options
.data
['action'])
1101 options
.data
['action']='query';
1103 js_log('do api req: ' + options
.url
+'?' + jQuery
.param(options
.data
) );
1104 //build request string:
1105 if( parseUri( document
.URL
).host
== parseUri( options
.url
).host
){
1106 //local request do api request directly
1111 dataType
:'json', //api requests _should_ always return JSON data:
1113 success:function(data
){
1117 js_error( ' error' + e
+' in getting: ' + options
.url
);
1121 //set the callback param if not already set:
1122 if( typeof options
.jsonCB
== 'undefined')
1123 options
.jsonCB
= 'callback';
1125 var req_url
= options
.url
;
1126 var paramAnd
= (req_url
.indexOf('?')==-1)?'?':'&';
1127 //put all the values into the GET req:
1128 for(var i
in options
.data
){
1129 req_url
+= paramAnd
+ encodeURIComponent( i
) + '=' + encodeURIComponent( options
.data
[i
] );
1132 var fname
= 'mycpfn_' + ( global_cb_count
++ );
1133 _global
[ fname
] = callback
;
1134 req_url
+= '&' + options
.jsonCB
+ '=' + fname
;
1135 loadExternalJs( req_url
);
1138 function mwGetLocalApiUrl(url
){
1139 if (wgServer
&& wgScriptPath
){
1140 return wgServer
+ wgScriptPath
+ '/api.php';
1144 //grab wiki form error for wiki html page proccessing (should be depricated)
1145 function grabWikiFormError ( result_page
){
1147 sp
= result_page
.indexOf('<span class="error">');
1149 se
= result_page
.indexOf('</span>', sp
);
1150 res
.error_txt
= result_page
.substr(sp
, (sp
-se
)) + '</span>';
1153 sp
= result_page
.indexOf('<ul class="warning">')
1155 se
= result_page
.indexOf('</ul>', sp
);
1156 res
.error_txt
= result_page
.substr(sp
, (se
-sp
)) + '</ul>';
1157 //try and add the ignore form item:
1158 sfp
= result_page
.indexOf('<form method="post"');
1160 sfe
= result_page
.indexOf('</form>', sfp
);
1161 res
.form_txt
= result_page
.substr(sfp
, ( sfe
- sfp
)) + '</form>';
1164 //one more error type check:
1165 sp
= result_page
.indexOf('class="mw-warning-with-logexcerpt">')
1167 se
= result_page
.indexOf('</div>', sp
);
1168 res
.error_txt
= result_page
.substr(sp
, ( se
- sp
)) + '</div>';
1174 //do a "normal" request
1175 function do_request(req_url
, callback
){
1176 js_log('do_request::req_url:' + req_url
+ ' != ' + parseUri( req_url
).host
);
1177 //if we are doing a request to the same domain or relative link do a normal GET:
1178 if( parseUri(document
.URL
).host
== parseUri(req_url
).host
||
1179 req_url
.indexOf('://') == -1 ){ //relative url
1180 //do a direct request:
1185 success:function(data
){
1190 //get data via DOM injection with callback
1191 global_req_cb
.push(callback
);
1192 //prepend json_ to feed_format if not already requesting json format
1193 if( req_url
.indexOf("feed_format=")!=-1 && req_url
.indexOf("feed_format=json")==-1)
1194 req_url
= req_url
.replace(/feed_format=/, 'feed_format=json_');
1195 loadExternalJs( req_url
+ '&cb=mv_jsdata_cb&cb_inx=' + (global_req_cb
.length
-1));
1199 function mv_jsdata_cb(response
){
1200 js_log('f:mv_jsdata_cb:'+ response
['cb_inx']);
1201 //run the callback from the global req cb object:
1202 if( !global_req_cb
[response
['cb_inx']] ){
1203 js_log('missing req cb index');
1206 if( !response
['pay_load'] ){
1207 js_log("missing pay load");
1210 //switch on content type:
1211 switch(response
['content-type']){
1215 if(typeof response
['pay_load'] == 'string'){
1216 //js_log('load string:'+"\n"+ response['pay_load']);
1218 //attempt to parse as xml for IE
1219 if( $j
.browser
.msie
){
1220 var xmldata
=new ActiveXObject("Microsoft.XMLDOM");
1221 xmldata
.async
="false";
1222 xmldata
.loadXML(response
['pay_load']);
1223 }else{ //for others (firefox, safari etc)
1225 var xmldata
= (new DOMParser()).parseFromString(response
['pay_load'], "text/xml");
1227 js_log('XML parse ERROR: ' + e
.message
);
1230 //@@todo hanndle xml parser errors
1231 if(xmldata
)response
['pay_load']=xmldata
;
1235 js_log('bad response type' + response
['content-type']);
1239 global_req_cb
[response
['cb_inx']]( response
['pay_load'] );
1241 //load external js via dom injection
1242 function loadExternalJs( url
, callback
){
1243 js_log('load js: '+ url
);
1244 //if(window['$j']) //use jquery call:
1252 var e
= document
.createElement("script");
1253 e
.setAttribute('src', url
);
1254 e
.setAttribute('type',"text/javascript");
1256 e.onload = callback;
1258 //e.setAttribute('defer', true);
1259 document
.getElementsByTagName("head")[0].appendChild(e
);
1262 function styleSheetPresent(url
){
1263 style_elements
= document
.getElementsByTagName('link');
1264 if( style_elements
.length
> 0) {
1265 for(i
= 0; i
< style_elements
.length
; i
++) {
1266 if(style_elements
[i
].href
== url
)
1272 function loadExternalCss(url
){
1273 //if could have script loader group thes css request
1274 //but debatable it may hurt more than it helps with caching and all
1275 if(typeof url
=='object'){
1277 loadExternalCss ( url
[i
] );
1282 if( url
.indexOf('?') == -1 ){
1283 url
+='?'+getMvUniqueReqId();
1285 if(!styleSheetPresent(url
) ){
1286 js_log('load css: ' + url
);
1287 var e
= document
.createElement("link");
1289 e
.type
= "text/css";
1290 e
.rel
= 'stylesheet';
1291 document
.getElementsByTagName("head")[0].appendChild(e
);
1294 function getMvEmbedURL(){
1295 if( _global
['mv_embed_url'] )
1296 return _global
['mv_embed_url'];
1297 var js_elements
= document
.getElementsByTagName("script");
1298 for(var i
=0; i
< js_elements
.length
; i
++){
1299 //check for normal mv_embed.js and or script loader
1300 var src
= js_elements
[i
].getAttribute("src");
1302 if( src
.indexOf('mv_embed.js') !=-1 || (
1303 ( src
.indexOf('mwScriptLoader.php') != -1 || src
.indexOf('jsScriptLoader.php') != -1 )
1304 && src
.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1305 _global
['mv_embed_url'] = src
;
1310 js_error('Error: getMvEmbedURL failed to get Embed Path');
1313 //gets a unique request id to ensure fresh javascript
1314 function getMvUniqueReqId(){
1315 if( _global
['urid'] )
1316 return _global
['urid'];
1317 var mv_embed_url
= getMvEmbedURL();
1318 //if we have a uri retun that:
1319 var urid
= parseUri( mv_embed_url
).queryKey
['urid']
1321 _global
['urid'] = urid
;
1324 //if in debug mode get a fresh unique request key:
1325 if( parseUri( mv_embed_url
).queryKey
['debug'] == 'true'){
1327 var urid
= d
.getTime();
1328 _global
['urid'] = urid
;
1331 //else just return the mv_embed version;
1332 return MV_EMBED_VERSION
;
1335 * sets the global mv_embed path based on the scripts location
1337 function getMvEmbedPath(){
1338 if( _global
['mv_embed_path'])
1339 return _global
['mv_embed_path'];
1340 var mv_embed_url
= getMvEmbedURL();
1341 if( mv_embed_url
.indexOf('mv_embed.js') !== -1 ){
1342 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mv_embed.js'));
1343 }else if(mv_embed_url
.indexOf('mwScriptLoader.php')!==-1){
1344 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1345 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path
;
1347 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('jsScriptLoader.php'));
1349 //absolute the url (if relative) (if we don't have mv_embed path)
1350 if( mv_embed_path
.indexOf('://') == -1){
1351 var pURL
= parseUri( document
.URL
);
1352 if(mv_embed_path
.charAt(0)=='/'){
1353 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ mv_embed_path
;
1356 if(mv_embed_path
==''){
1357 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ pURL
.directory
+ mv_embed_path
;
1361 _global
['mv_embed_path'] = mv_embed_path
;
1362 return mv_embed_path
;
1365 if (typeof DOMParser
== "undefined") {
1366 DOMParser = function () {}
1367 DOMParser
.prototype.parseFromString = function (str
, contentType
) {
1368 if (typeof ActiveXObject
!= "undefined") {
1369 var d
= new ActiveXObject("MSXML.DomDocument");
1372 } else if (typeof XMLHttpRequest
!= "undefined") {
1373 var req
= new XMLHttpRequest
;
1374 req
.open("GET", "data:" + (contentType
|| "application/xml") +
1375 ";charset=utf-8," + encodeURIComponent(str
), false);
1376 if (req
.overrideMimeType
) {
1377 req
.overrideMimeType(contentType
);
1380 return req
.responseXML
;
1385 * utility functions:
1387 function js_log(string
){
1388 if( window
.console
){
1389 window
.console
.log(string
);
1392 * IE and non-firebug debug:
1394 /*var log_elm = document.getElementById('mv_js_log');
1396 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1397 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1398 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1401 var log_elm = document.getElementById('mv_js_log');
1404 log_elm.value+=string+"\n";
1410 function js_error(string
){