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.0r17';
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 //media_server mv_embed_path (the path on media servers to mv_embed for java iframe with leading and trailing slashes)
41 if(!mv_media_iframe_path
)
42 var mv_media_iframe_path
= '/mv_embed/';
44 //the default height/width of the video (if no style or width attribute provided)
45 if(!mv_default_video_size
)
46 var mv_default_video_size
= '400x300';
48 //for when useing mv_embed with script-loader in root mediawiki path
49 var mediaWiki_mvEmbed_path
= 'js2/mwEmbed/';
51 var global_player_list
= new Array(); //the global player list per page
52 var global_req_cb
= new Array(); //the global request callback array
53 var _global
= this; //global obj
54 var mv_init_done
=false;
55 var global_cb_count
=0;
57 /*parseUri class parses URIs:*/
58 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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
61 //get mv_embed location if it has not been set
63 var mv_embed_path
= getMvEmbedPath();
65 jQueryUiVN
= 'jquery.ui-1.7.1';
68 //setup the skin path:
69 var mv_jquery_skin_path
= mv_embed_path
+ 'jquery/' + jQueryUiVN
+ '/themes/' + mwjQueryUiSkin
+ '/';
70 var mv_skin_img_path
= mv_embed_path
+ 'skins/' + mv_skin_name
+ '/images/';
71 var mv_default_thumb_url
= mv_skin_img_path
+ 'vid_default_thumb.jpg';
74 //init the global Msg if not already
75 if(!gMsg
){var gMsg
={};}
77 function loadGM( msgSet
){
79 gMsg
[ i
] = msgSet
[i
];
83 //all default msg in [English] should be overwritten by the CMS language msg system.
85 "loading_txt":"loading <blink>...</blink>",
86 "loading_title" : "Loading...",
88 "size-gigabytes" : "$1 GB",
89 "size-megabytes" : "$1 MB",
90 "size-kilobytes" : "$1 K",
96 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
97 * any file _not_ listed here won't be auto-loadable
98 * @path the path to the file (or set of files) with ending slash
99 * @gClasses the set of classes
100 * if an array $j.className become jquery.className.js
101 * if an asssociative objec then key => value paris are used
103 if(typeof mvClassPaths
== 'undefined')
106 function lcPaths( path
, gClasses
, opt
){
109 if(typeof opt
['j_replace'] == 'undefined')
110 opt
['j_replace'] = 'jquery.';
115 for(var i
=0; i
<gClasses
.length
; i
++){
116 if(typeof gClasses
[i
] != 'undefined'){
117 //setup normal replacement of j with jquery
118 var jsName
= ( gClasses
[i
].substr(0,3) == '$j.' ) ? opt
['j_replace'] + gClasses
[i
].substr(3) : gClasses
[i
];
119 mvClassPaths
[ gClasses
[i
] ] = path
+ jsName
+ '.js';
124 for(var i
in gClasses
){
125 //assume object with key:path:
126 mvClassPaths
[i
] = path
+ gClasses
[ i
];
129 var cat
= mvClassPaths
;
131 function mvGetClassPath(k
){
132 if( mvClassPaths
[k
] ){
133 //js_log('got classpath:' + k + ' : '+ mvClassPaths[k]);
134 return mvClassPaths
[k
];
136 return js_error('could not find path for requested class ' + k
);
139 if(typeof mvCssPaths
== 'undefined')
142 function lcCssPath(cssSet
){
143 for(var i
in cssSet
){
144 mvCssPaths
[i
]= mv_embed_path
+ cssSet
[i
];
147 //core and (non-standard named files relative to class the init):
149 'mv_embed' : 'mv_embed.js',
150 'window.jQuery' : 'jquery/jquery-1.3.2.js',
151 '$j.fn.pngFix' : 'jquery/plugins/jquery.pngFix.js',
152 '$j.fn.autocomplete': 'jquery/plugins/jquery.autocomplete.js',
153 '$j.fn.hoverIntent' : 'jquery/plugins/jquery.hoverIntent.js',
154 '$j.fn.datePicker' : 'jquery/plugins/jquery.datePicker.js',
155 '$j.ui' : 'jquery/jquery.ui-1.7.1/ui/ui.core.js',
156 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/js/colorpicker.js',
157 '$j.Jcrop' : 'libClipEdit/Jcrop/js/jquery.Jcrop.js'
160 lcPaths( 'jquery/plugins/', [
166 lcPaths('jquery/jquery.ui-1.7.1/ui/', [
169 '$j.effects.pulsate',
170 '$j.effects.transfer',
174 '$j.effects.explode',
186 '$j.effects.highlight',
194 lcPaths('libAddMedia/', [
197 'mvBaseUploadInterface',
198 'remoteSearchDriver',
199 'seqRemoteSearchDriver',
202 lcPaths('libAddMedia/searchLibs/', [
210 lcPaths( 'libClipEdit/', [
213 //libEmbedObj (we could load all these clasess in embedVideo):
214 lcPaths( 'libEmbedVideo/', [
225 lcPaths( 'libSequencer/', [
231 lcPaths( 'libTimedText/', [
235 //depencency mapping for css files for self contained included plugins:
237 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
238 '$j.fn.ColorPicker': 'libClipEdit/colorpicker/css/colorpicker.css'
242 * Language Functions:
244 * These functions try to losely mirro the functionality of Language.php in mediaWiki
246 function gM( key
, args
) {
250 if(typeof args
== 'object' || typeof args
== 'array'){
252 //msg test replace arguments start at 1 insted of zero:
253 var rep
= '\$'+ ( parseInt(v
) + 1 );
254 ms
= ms
.replace( rep
, args
[v
]);
256 }else if(typeof args
=='string' || typeof args
=='number'){
257 ms
= ms
.replace(/\$1/, args
);
261 //key is missing return indication:
262 return '<' + key
+ '>';
266 * msgSet is either a string corresponding to a single msg to load
267 * or msgSet is an array with set of msg to load
269 function gMsgLoadRemote(msgSet
, callback
){
271 if(typeof msgSet
== 'object' ){
272 for(var i
in msgSet
){
273 ammessages
+= msgSet
[i
] + '|';
275 }else if(typeof msgSet
== 'string'){
276 ammessages
+= msgSet
;
278 if(ammessages
== ''){
279 js_log('gMsgLoadRemote::no msg set requested');
284 'meta':'allmessages',
285 'ammessages':ammessages
288 if(data
.query
.allmessages
){
289 var msgs
= data
.query
.allmessages
;
292 ld
[ msgs
[i
]['name'] ] = msgs
[i
]['*'];
296 //load the result into local msg var
302 * Format a size in bytes for output, using an appropriate
303 * unit (B, KB, MB or GB) according to the magnitude in question
305 * @param size Size to format
306 * @return string Plain text (not HTML)
308 function formatSize( size
) {
309 // For small sizes no decimal places necessary
316 // For MB and bigger two decimal places are smarter
320 msg
= 'size-gigabytes';
322 msg
= 'size-megabytes';
325 msg
= 'size-kilobytes';
330 //javascript does not let you do precession points in rounding
331 var p
= Math
.pow(10,round
);
332 var size
= Math
.round( size
* p
) / p
;
333 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
334 return gM( msg
, size
);
337 //gets the loading image:
338 function mv_get_loading_img( style
, class_attr
){
339 var style_txt
= (style
)?style
:'';
340 var class_attr
= (class_attr
)?'class="'+class_attr
+'"':'class="mv_loading_img"';
341 return '<div '+class_attr
+' style="' + style
+'"></div>';
344 function mv_set_loading(target
, load_id
){
345 var id_attr
= ( load_id
)?' id="' + load_id
+ '" ':'';
346 $j(target
).append('<div '+id_attr
+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
347 'background-color:#FFF;">' +
348 mv_get_loading_img('top:30px;left:30px') +
353 * mvJsLoader class handles initialization and js file loads
359 onReadyEvents
:new Array(),
360 doneReadyEvents
:false,
361 jQueryCheckFlag
:false,
362 //to keep consistency across threads:
365 load_error
:false, //load error flag (false by default)
367 callbacks
:new Array(),
370 doLoad:function(loadLibs
, callback
){
372 if( loadLibs
&& loadLibs
.length
!=0 ){ //setup this.libs:
374 //first check if we already have this lib loaded
375 var all_libs_loaded
=true;
376 for(var i
=0; i
< loadLibs
.length
; i
++){
377 //check if the lib is already loaded:
378 if( ! this.checkObjPath( loadLibs
[i
] ) ){
379 all_libs_loaded
=false;
382 if( all_libs_loaded
){
383 js_log('all libs already loaded skipping... load req');
387 //do a check for any css we may need and get it:
388 for(var i
=0; i
< loadLibs
.length
; i
++){
389 if( typeof mvCssPaths
[ loadLibs
[i
] ] != 'undefined' ){
390 loadExternalCss( mvCssPaths
[ loadLibs
[i
] ]);
394 //check if we should use the script loader to combine all the requests into one:
395 if( typeof mwSlScript
!= 'undefined' ){
399 for(var i
=0; i
< loadLibs
.length
; i
++){
400 var curLib
= loadLibs
[i
];
401 //only add if not included yet:
402 if( ! this.checkObjPath( curLib
) ){
403 class_set
+=coma
+ curLib
;
408 var puri
= parseUri( getMvEmbedURL() );
409 if( (getMvEmbedURL().indexOf('://')!=-1) && puri
.host
!= parseUri( document
.URL
).host
){
410 mwSlScript
= puri
.protocol
+ '://' + puri
.authority
+ mwSlScript
;
413 var dbug_attr
= (puri
.queryKey
['debug'])?'&debug=true':'';
414 this.libs
[ last_class
] = mwSlScript
+ '?class=' + class_set
+
415 '&urid=' + getMvUniqueReqId() + dbug_attr
;
419 for(var i
=0; i
< loadLibs
.length
; i
++){
420 var curLib
= loadLibs
[i
];
422 var libLoc
= mvGetClassPath(curLib
);
423 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
424 var qmark
= (libLoc
.indexOf('?')!==true)?'?':'&';
425 this.libs
[curLib
] = mv_embed_path
+ libLoc
+ qmark
+ 'urid='+ getMvUniqueReqId();
431 this.callbacks
.push(callback
);
433 if( this.checkLoading() ){
434 if( this.load_time
++ > 1000){ //time out after ~80seconds
435 js_error( gM('error_load_lib') + this.missing_path
);
436 this.load_error
=true;
438 setTimeout( 'mvJsLoader.doLoad()', 20 );
441 //js_log('checkLoading passed run callbacks');
442 //only do callback if we are in the same instance (weird concurency issue)
444 for(var i
=0; i
< this.callbacks
.length
; i
++)
446 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
449 //js_log('done loading do call: ' + this.callbacks[0] );
450 while( this.callbacks
.length
!=0 ){
451 if( this.ptime
== ( this.ctime
-1) ){ //enforce thread consistency
452 this.callbacks
.pop()();
453 //func = this.callbacks.pop();
454 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
457 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
458 setTimeout( 'mvJsLoader.doLoad()', 25 );
463 this.ptime
=this.ctime
;
465 doLoadFullPaths:function(loadObj
, callback
){
468 doLoadDepMode:function(loadChain
, callback
){
469 //firefox executes js ~in-order of it being included~ so just directly issue request:
470 if( $j
.browser
.firefox
){
472 for(var i
=0; i
< loadChain
.length
;i
++){
473 for(var j
=0;j
<loadChain
[i
].length
;j
++){
474 loadSet
.push(loadChain
[i
][j
]);
477 mvJsLoader
.doLoad(loadSet
, callback
);
479 //safari and IE tend to execute out of order so load with dependenciy checks
480 mvJsLoader
.doLoad(loadChain
.shift(),function(){
481 if(loadChain
.length
!=0){
482 mvJsLoader
.doLoadDepMode(loadChain
, callback
);
488 checkLoading:function(){
491 for(var i
in this.libs
){ //for in loop oky on object
492 if( !this.checkObjPath( i
) ){
494 loadExternalJs( this.libs
[i
] );
498 //js_log("has not yet loaded: " + i);
504 checkObjPath:function( libVar
){
507 var objPath
= libVar
.split('.')
509 for(var p
=0; p
< objPath
.length
; p
++){
510 cur_path
= (cur_path
=='')?cur_path
+objPath
[p
]:cur_path
+'.'+objPath
[p
];
511 eval( 'var ptest = typeof ( '+ cur_path
+ ' ); ');
512 if( ptest
== 'undefined'){
513 this.missing_path
= cur_path
;
517 this.cur_path
= cur_path
;
521 * checks for jQuery and adds the $j noConflict var
523 jQueryCheck:function(callback
){
524 //skip stuff if $j is already loaded:
525 if(_global
['$j'] && callback
)
532 _global
['$j'] = jQuery
.noConflict();
533 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
537 js_log('jquery loaded');
538 //setup mvEmbed jquery bindigns:
546 embedVideoCheck:function( callback
){
548 js_log('embedVideoCheck:');
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(){
565 //add png fix if needed:
566 if($j
.browser
.msie
|| $j
.browser
.version
< 7)
567 depReq
[0].push( '$j.fn.pngFix' );
569 _this
.doLoadDepMode(depReq
,function(){
575 addLoadEvent:function(fn
){
576 this.onReadyEvents
.push(fn
);
578 //checks the jQuery flag (this way when remote embeding we don't load jQuery
579 // unless mwAddOnloadHook was used or there is video on the page
580 runQuededFunctions:function(){
582 this.doneReadyEvents
=true;
583 if(this.jQueryCheckFlag
){
584 this.jQueryCheck(function(){
585 _this
.runReadyEvents();
588 this.runReadyEvents();
591 runReadyEvents:function(){
592 js_log("runReadyEvents");
593 while( this.onReadyEvents
.length
){
594 this.onReadyEvents
.shift()();
599 //load an external JS (similar to jquery .require plugin)
600 //but checks for object availability rather than load state
602 /*********** INITIALIZATION CODE *************
603 * this will get called when DOM is ready
604 *********************************************/
605 /* jQuery .ready does not work when jQuery is loaded dynamically
606 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
607 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
608 * $j(document).ready( function(){ */
609 function mwdomReady(force
){
610 js_log('f:mwdomReady:');
611 if( !force
&& mv_init_done
){
612 js_log("mv_init_done already done do nothing...");
616 //handle the execution of Queded function with jQuery "ready"
618 //check if this page does have video or playlist
619 if(document
.getElementsByTagName("video").length
!=0 ||
620 document
.getElementsByTagName("audio").length
!=0 ||
621 document
.getElementsByTagName("playlist").length
!=0){
622 js_log('we have things to rewrite');
623 //load libs and proccess:
624 mvJsLoader
.embedVideoCheck(function(){
625 //run any queded global events:
626 mv_video_embed( function(){
627 mvJsLoader
.runQuededFunctions();
631 //if we already have jQuery make sure its loaded into its proper context $j
632 //run any queded global events:
633 mvJsLoader
.runQuededFunctions();
636 //mwAddOnloadHook: ensure jQuery and the DOM are ready:
637 function mwAddOnloadHook( func
) {
638 //make sure the skin/style sheets are avaliable always:
639 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
640 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css');
642 //if we have already run the dom ready just run the function directly:
643 if( mvJsLoader
.doneReadyEvents
){
644 //make sure jQuery is there:
645 mvJsLoader
.jQueryCheck(function(){
649 //if using mwAddOnloadHook we need to get jQuery into place (if its not already included)
650 mvJsLoader
.jQueryCheckFlag
= true;
651 mvJsLoader
.addLoadEvent( func
);
655 * this function allows for targeted rewriting
657 function rewrite_by_id( vid_id
, ready_callback
){
658 js_log('f:rewrite_by_id: ' + vid_id
);
659 //force a recheck of the dom for playlist or video element:
660 mvJsLoader
.embedVideoCheck(function(){
661 mv_video_embed(ready_callback
, vid_id
);
664 //depricated in favor of updates to oggHanlder
665 function rewrite_for_oggHanlder( vidIdList
){
666 for(var i
= 0; i
< vidIdList
.length
; i
++){
667 var vidId
= vidIdList
[i
];
668 js_log('looking at vid: ' + i
+' ' + vidId
);
669 //grab the thumbnail and src video
670 var pimg
= $j('#'+vidId
+ ' img');
671 var poster_attr
= 'poster = "' + pimg
.attr('src') + '" ';
672 var pwidth
= pimg
.attr('width');
673 var pheight
= pimg
.attr('height');
677 if( pwidth
=='22' && pheight
=='22'){
680 type_attr
= 'type="audio/ogg"';
688 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
689 src
= re
.exec( $j('#'+vidId
).html() )[2];
691 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
692 duration
= re
.exec( $j('#'+vidId
).html() )[2];
694 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
695 offset
= re
.exec( $j('#'+vidId
).html() )[2];
696 var offset_attr
= (offset
)? 'startOffset="'+ offset
+ '"': '';
699 //replace the top div with mv_embed based player:
700 var vid_html
= '<video id="vid_' + i
+'" '+
701 'src="' + src
+ '" ' +
705 'duration="' + duration
+ '" ' +
706 'style="width:' + pwidth
+ 'px;height:' +
707 pheight
+ 'px;"></video>';
708 //js_log("video html: " + vid_html);
709 $j('#'+vidId
).html( vid_html
);
712 //rewrite that video id:
713 rewrite_by_id('vid_' + i
);
718 /*********** INITIALIZATION CODE *************
719 * set DOM ready callback to init_mv_embed
720 *********************************************/
721 // for Mozilla browsers
722 if (document
.addEventListener
) {
723 document
.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
725 //backup "onload" method in case on DOMContentLoaded does not exist
726 window
.onload = function(){ mwdomReady() };
729 * should depreciate and use jquery.ui.dialog instead
731 function mv_write_modal(content
, speed
){
732 $j('#modalbox,#mv_overlay').remove();
733 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
734 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
737 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
738 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
740 $j('#modalbox,#mv_overlay').show( speed
);
742 function mv_remove_modal(speed
){
743 $j('#modalbox,#mv_overlay').remove( speed
);
747 * stores all the mwEmbed jQuery specific bindings
748 * (setup after jQuery is avaliable)
749 * lets you call rewrites in a jquery "way"
751 * @@ eventually we should refactor mwCode over to jQuery style plugins
752 * and mv_embed.js will just hanndle dependency mapping and loading.
755 function mv_jqueryBindings(){
756 js_log('mv_jqueryBindings');
759 $.fn
.addMediaWiz = function( iObj
, callback
){
760 //first set the cursor for the button to "loading"
761 $j(this.selector
).css('cursor','wait').attr('title', gM('loading_title'));
763 iObj
['target_invocation'] = this.selector
;
765 //load the mv_embed_base skin:
766 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
767 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
768 //load all the req libs:
769 mvJsLoader
.jQueryCheck(function(){
770 //load with staged dependeinces (for ie and safari that don't execute in order)
771 mvJsLoader
.doLoadDepMode([
772 [ 'remoteSearchDriver',
783 iObj
['instance_name']= 'rsdMVRS';
784 _global
['rsdMVRS'] = new remoteSearchDriver( iObj
);
786 callback( _global
['rsdMVRS'] );
791 $.fn
.sequencer = function( iObj
, callback
){
793 iObj
['target_sequence_container'] = this.selector
;
794 //issue a request to get the css file (if not already included):
795 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
796 loadExternalCss( mv_embed_path
+'skins/'+mv_skin_name
+'/mv_sequence.css');
797 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
798 mvJsLoader
.embedVideoCheck(function(){
799 //load playlist object and then jquery ui stuff:
800 mvJsLoader
.doLoadDepMode([
820 js_log('calling new mvSequencer');
821 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
822 if(!_global
['mvSeq']){
823 _global
['mvSeq'] = new mvSequencer(iObj
);
825 js_log('mvSeq already init');
831 * the firefogg jquery function:
832 * @@note this firefogg envocation could be made to work more like real jquery plugins
834 $.fn
.firefogg = function( iObj
, callback
) {
837 //add base theme css:
838 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
839 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
841 //check if we already have firefogg loaded (the call just updates properties for that element)
842 var sElm
= $j(this.selector
).get(0);
843 if(sElm
['firefogg']){
844 if(sElm
['firefogg']=='loading'){
845 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
850 js_log("firefogg::updated: "+ i
+ ' to '+ iObj
[i
]);
851 sElm
['firefogg'][i
] = iObj
[i
];
853 return sElm
['firefogg'];
856 sElm
['firefogg'] = 'loading';
859 iObj
['selector'] = this.selector
;
863 'mvBaseUploadInterface',
872 if( iObj
.encoder_interface
){
881 //make sure we have everything loaded that we need:
882 mvJsLoader
.doLoadDepMode( loadSet
, function(){
883 js_log('firefogg libs loaded. target select:' + iObj
.selector
);
884 //select interface provicer based on if we want to include the encoder interface or not:
885 if(iObj
.encoder_interface
){
886 var myFogg
= new mvAdvFirefogg( iObj
);
888 var myFogg
= new mvFirefogg( iObj
);
891 myFogg
.doRewrite( callback
);
892 var selectorElement
= $j( iObj
.selector
).get(0);
893 selectorElement
['firefogg']=myFogg
;
898 $.fn
.baseUploadInterface = function(iObj
){
900 'mvBaseUploadInterface',
905 myUp
= new mvBaseUploadInterface( iObj
);
910 //shortcut to a themed button:
911 $.btnHtml = function(msg
, className
, iconId
, opt
){
914 var href
= (opt
.href
)?opt
.href
:'#';
915 var target_attr
= (opt
.target
)?' target="' + opt
.target
+ '" ':'';
916 var style_attr
= (opt
.style
)?' style="'+opt
.style
+'" ':'';
917 return '<a href="' + href
+ '" ' + target_attr
+ style_attr
+' class="ui-state-default ui-corner-all ui-icon_link ' +
918 className
+ '"><span class="ui-icon ui-icon-' + iconId
+ '" />' +
921 //shortcut to bind hover state:
922 $.fn
.btnBind = function(){
925 $j(this).addClass('ui-state-hover');
928 $j(this).removeClass('ui-state-hover');
939 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
940 function getURLParamReplace( url
, opt
){
941 var pSrc
= parseUri( url
);
942 if(pSrc
.protocol
!= '' ){
943 var new_url
= pSrc
.protocol
+'://'+ pSrc
.authority
+ pSrc
.path
+'?';
945 var new_url
= pSrc
.path
+'?';
948 for(var key
in pSrc
.queryKey
){
949 var val
= pSrc
.queryKey
[ key
];
950 //do override if requested
953 new_url
+= amp
+ key
+ '=' + val
;
956 //add any vars that did were not originally there:
958 if(!pSrc
.queryKey
[i
]){
959 new_url
+=amp
+ i
+ '=' + opt
[i
];
966 * seconds2npt given a float seconds returns npt format response:
967 * @param float seconds
968 * @param boolean if we should show ms or not.
970 function seconds2npt(sec
, show_ms
){
972 js_log("warning: trying to get npt time on NaN:" + sec
);
975 var hours
= Math
.floor(sec
/ 3600);
976 var minutes
= Math
.floor((sec
/60) % 60);
977 var seconds
= sec
% 60;
978 //round the second amount requested significant digits
980 seconds
= Math
.round( seconds
* 1000 ) / 1000;
982 seconds
= Math
.round( seconds
);
985 seconds
= '0'+ seconds
;
987 minutes
= '0' + minutes
;
989 return hours
+":"+minutes
+":"+seconds
;
992 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
994 function npt2seconds( npt_str
){
996 //js_log('npt2seconds:not valid ntp:'+ntp);
999 //strip npt: time definition if present
1000 npt_str
= npt_str
.replace('npt:', '');
1002 times
= npt_str
.split(':');
1003 if(times
.length
!=3){
1004 js_log('error: npt2seconds on ' + npt_str
);
1007 //sometimes the comma is used inplace of pereid for ms
1008 times
[2] = times
[2].replace(/,\s?/,'.');
1009 //return seconds float (ie take seconds float value if present):
1010 return parseInt(times
[0]*3600)+parseInt(times
[1]*60)+parseFloat(times
[2]);
1013 //does a remote or local api request based on request url
1014 //@param options: url, data, cbParam, callback
1015 function do_api_req( options
, callback
){
1016 if(typeof options
.data
!= 'object'){
1017 return js_error('Error: request paramaters must be an object');;
1019 //gennerate the url if its missing:
1020 if( typeof options
.url
== 'undefined' ){
1021 if(!wgServer
|| ! wgScriptPath
){
1022 return js_error('Error: no api url for api request');;
1024 if (wgServer
&& wgScript
)
1025 options
.url
= wgServer
+ wgScript
;
1026 //update to api.php (if index.php was in the wgScript path):
1027 options
.url
= options
.url
.replace(/index.php/, 'api.php');
1029 if( typeof options
.data
== 'undefined' )
1032 //force format to json (if not already set)
1033 options
.data
['format'] = 'json';
1035 //if action not set assume query
1036 if(!options
.data
['action'])
1037 options
.data
['action']='query';
1039 js_log('do api req: ' + options
.url
+'?' + jQuery
.param(options
.data
) );
1040 //build request string:
1041 if( parseUri( document
.URL
).host
== parseUri( options
.url
).host
){
1042 //local request do api request directly
1047 dataType
:'json', //api requests _should_ always return JSON data:
1049 success:function(data
){
1053 js_error( ' error' + e
+' in getting: ' + options
.url
);
1057 //set the callback param if not already set:
1058 if( typeof options
.jsonCB
== 'undefined')
1059 options
.jsonCB
= 'callback';
1061 var req_url
= options
.url
;
1062 var paramAnd
= (req_url
.indexOf('?')==-1)?'?':'&';
1063 //put all the values into the GET req:
1064 for(var i
in options
.data
){
1065 req_url
+= paramAnd
+ encodeURIComponent( i
) + '=' + encodeURIComponent( options
.data
[i
] );
1068 var fname
= 'mycpfn_' + ( global_cb_count
++ );
1069 _global
[ fname
] = callback
;
1070 req_url
+= '&' + options
.jsonCB
+ '=' + fname
;
1071 loadExternalJs( req_url
);
1074 //grab wiki form error for wiki html page proccessing (should be depricated)
1075 function grabWikiFormError ( result_page
){
1077 sp
= result_page
.indexOf('<span class="error">');
1079 se
= result_page
.indexOf('</span>', sp
);
1080 res
.error_txt
= result_page
.substr(sp
, (sp
-se
)) + '</span>';
1083 sp
= result_page
.indexOf('<ul class="warning">')
1085 se
= result_page
.indexOf('</ul>', sp
);
1086 res
.error_txt
= result_page
.substr(sp
, (se
-sp
)) + '</ul>';
1087 //try and add the ignore form item:
1088 sfp
= result_page
.indexOf('<form method="post"');
1090 sfe
= result_page
.indexOf('</form>', sfp
);
1091 res
.form_txt
= result_page
.substr(sfp
, ( sfe
- sfp
)) + '</form>';
1094 //one more error type check:
1095 sp
= result_page
.indexOf('class="mw-warning-with-logexcerpt">')
1097 se
= result_page
.indexOf('</div>', sp
);
1098 res
.error_txt
= result_page
.substr(sp
, ( se
- sp
)) + '</div>';
1104 //do a "normal" request
1105 function do_request(req_url
, callback
){
1106 js_log('do_request::req_url:' + req_url
+ ' != ' + parseUri( req_url
).host
);
1107 //if we are doing a request to the same domain or relative link do a normal GET:
1108 if( parseUri(document
.URL
).host
== parseUri(req_url
).host
||
1109 req_url
.indexOf('://') == -1 ){ //relative url
1110 //do a direct request:
1115 success:function(data
){
1120 //get data via DOM injection with callback
1121 global_req_cb
.push(callback
);
1122 //prepend json_ to feed_format if not already requesting json format
1123 if( req_url
.indexOf("feed_format=")!=-1 && req_url
.indexOf("feed_format=json")==-1)
1124 req_url
= req_url
.replace(/feed_format=/, 'feed_format=json_');
1125 loadExternalJs(req_url
+'&cb=mv_jsdata_cb&cb_inx='+(global_req_cb
.length
-1));
1129 function mv_jsdata_cb(response
){
1130 js_log('f:mv_jsdata_cb:'+ response
['cb_inx']);
1131 //run the callback from the global req cb object:
1132 if( !global_req_cb
[response
['cb_inx']] ){
1133 js_log('missing req cb index');
1136 if( !response
['pay_load'] ){
1137 js_log("missing pay load");
1140 //switch on content type:
1141 switch(response
['content-type']){
1145 if(typeof response
['pay_load'] == 'string'){
1146 //js_log('load string:'+"\n"+ response['pay_load']);
1148 //attempt to parse as xml for IE
1149 if( $j
.browser
.msie
){
1150 var xmldata
=new ActiveXObject("Microsoft.XMLDOM");
1151 xmldata
.async
="false";
1152 xmldata
.loadXML(response
['pay_load']);
1153 }else{ //for others (firefox, safari etc)
1155 var xmldata
= (new DOMParser()).parseFromString(response
['pay_load'], "text/xml");
1157 js_log('XML parse ERROR: ' + e
.message
);
1160 //@@todo hanndle xml parser errors
1161 if(xmldata
)response
['pay_load']=xmldata
;
1165 js_log('bad response type' + response
['content-type']);
1169 global_req_cb
[response
['cb_inx']]( response
['pay_load'] );
1171 //load external js via dom injection
1172 function loadExternalJs( url
){
1173 js_log('load js: '+ url
);
1174 //if(window['$j']) //use jquery call:
1182 var e
= document
.createElement("script");
1183 e
.setAttribute('src', url
);
1184 e
.setAttribute('type',"text/javascript");
1185 //e.setAttribute('defer', true);
1186 document
.getElementsByTagName("head")[0].appendChild(e
);
1190 function styleSheetPresent(url
){
1191 style_elements
= document
.getElementsByTagName('link');
1192 if( style_elements
.length
> 0) {
1193 for(i
= 0; i
< style_elements
.length
; i
++) {
1194 if(style_elements
[i
].href
== url
)
1200 function loadExternalCss(url
){
1201 //if could have script loader group thes css request
1202 //but debatable it may hurt more than it helps with caching and all
1203 if(typeof url
=='object'){
1205 loadExternalCss ( url
[i
] );
1210 if( url
.indexOf('?') == -1 ){
1211 url
+='?'+getMvUniqueReqId();
1213 if(!styleSheetPresent(url
) ){
1214 js_log('load css: ' + url
);
1215 var e
= document
.createElement("link");
1217 e
.type
= "text/css";
1218 e
.rel
= 'stylesheet';
1219 document
.getElementsByTagName("head")[0].appendChild(e
);
1222 function getMvEmbedURL(){
1223 if( _global
['mv_embed_url'] )
1224 return _global
['mv_embed_url'];
1225 var js_elements
= document
.getElementsByTagName("script");
1226 for(var i
=0; i
< js_elements
.length
; i
++){
1227 //check for normal mv_embed.js and or script loader
1228 var src
= js_elements
[i
].getAttribute("src");
1230 if( src
.indexOf('mv_embed.js') !=-1 || (
1231 ( src
.indexOf('mwScriptLoader.php') != -1 || src
.indexOf('jsScriptLoader.php') != -1 )
1232 && src
.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1233 _global
['mv_embed_url'] = src
;
1238 js_error('Error: getMvEmbedURL failed to get Embed Path');
1241 //gets a unique request id to ensure fresh javascript
1242 function getMvUniqueReqId(){
1243 if( _global
['urid'] )
1244 return _global
['urid'];
1245 var mv_embed_url
= getMvEmbedURL();
1246 //if we have a uri retun that:
1247 var urid
= parseUri( mv_embed_url
).queryKey
['urid']
1249 _global
['urid'] = urid
;
1252 //if in debug mode get a fresh unique request key:
1253 if( parseUri( mv_embed_url
).queryKey
['debug'] == 'true'){
1255 var urid
= d
.getTime();
1256 _global
['urid'] = urid
;
1259 //else just return the mv_embed version;
1260 return MV_EMBED_VERSION
;
1263 * sets the global mv_embed path based on the scripts location
1265 function getMvEmbedPath(){
1266 var mv_embed_url
= getMvEmbedURL();
1267 if( mv_embed_url
.indexOf('mv_embed.js') !== -1 ){
1268 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mv_embed.js'));
1269 }else if(mv_embed_url
.indexOf('mwScriptLoader.php')!==-1){
1270 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1271 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path
;
1273 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('jsScriptLoader.php'));
1275 //absolute the url (if relative) (if we don't have mv_embed path)
1276 if( mv_embed_path
.indexOf('://') == -1){
1277 var pURL
= parseUri( document
.URL
);
1278 if(mv_embed_path
.charAt(0)=='/'){
1279 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ mv_embed_path
;
1282 if(mv_embed_path
==''){
1283 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ pURL
.directory
+ mv_embed_path
;
1287 return mv_embed_path
;
1290 if (typeof DOMParser
== "undefined") {
1291 DOMParser = function () {}
1292 DOMParser
.prototype.parseFromString = function (str
, contentType
) {
1293 if (typeof ActiveXObject
!= "undefined") {
1294 var d
= new ActiveXObject("MSXML.DomDocument");
1297 } else if (typeof XMLHttpRequest
!= "undefined") {
1298 var req
= new XMLHttpRequest
;
1299 req
.open("GET", "data:" + (contentType
|| "application/xml") +
1300 ";charset=utf-8," + encodeURIComponent(str
), false);
1301 if (req
.overrideMimeType
) {
1302 req
.overrideMimeType(contentType
);
1305 return req
.responseXML
;
1310 * utility functions:
1312 function js_log(string
){
1313 if( window
.console
){
1314 window
.console
.log(string
);
1317 * IE and non-firebug debug:
1319 /*var log_elm = document.getElementById('mv_js_log');
1321 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1322 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1323 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1326 var log_elm = document.getElementById('mv_js_log');
1329 log_elm.value+=string+"\n";
1335 function js_error(string
){