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 //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
={};}
78 function loadGM( msgSet
){
80 gMsg
[ i
] = msgSet
[i
];
84 //all default msg in [English] should be overwritten by the CMS language msg system.
86 "loading_txt":"loading <blink>...</blink>",
87 "loading_title" : "Loading...",
89 "size-gigabytes" : "$1 GB",
90 "size-megabytes" : "$1 MB",
91 "size-kilobytes" : "$1 K",
97 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
98 * any file _not_ listed here won't be auto-loadable
99 * @path the path to the file (or set of files) with ending slash
100 * @gClasses the set of classes
101 * if an array $j.className become jquery.className.js
102 * if an asssociative object then key => value paris are used
104 if(typeof mvClassPaths
== 'undefined')
107 function lcPaths( path
, gClasses
, opt
){
110 if(typeof opt
['j_replace'] == 'undefined')
111 opt
['j_replace'] = 'jquery.';
116 for(var i
=0; i
< gClasses
.length
; i
++){
117 if(typeof gClasses
[i
] != 'undefined'){
118 //setup normal replacement of j with jquery
119 var jsName
= ( gClasses
[i
].substr(0,3) == '$j.' ) ? opt
['j_replace'] + gClasses
[i
].substr(3) : gClasses
[i
];
120 mvClassPaths
[ gClasses
[i
] ] = path
+ jsName
+ '.js';
125 for(var i
in gClasses
){
126 //assume object with key:path:
127 mvClassPaths
[i
] = path
+ gClasses
[ i
];
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/', [
232 lcPaths( 'libTimedText/', [
236 //depencency mapping for css files for self contained included plugins:
238 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
239 '$j.fn.ColorPicker': 'libClipEdit/colorpicker/css/colorpicker.css'
243 * Language Functions:
245 * These functions try to losely mirro the functionality of Language.php in mediaWiki
247 function gM( key
, args
) {
251 if(typeof args
== 'object' || typeof args
== 'array'){
253 //msg test replace arguments start at 1 insted of zero:
254 var rep
= '\$'+ ( parseInt(v
) + 1 );
255 ms
= ms
.replace( rep
, args
[v
]);
257 }else if(typeof args
=='string' || typeof args
=='number'){
258 ms
= ms
.replace(/\$1/, args
);
262 //key is missing return indication:
263 return '<' + key
+ '>';
267 * msgSet is either a string corresponding to a single msg to load
268 * or msgSet is an array with set of msg to load
270 function gMsgLoadRemote(msgSet
, callback
){
272 if(typeof msgSet
== 'object' ){
273 for(var i
in msgSet
){
274 ammessages
+= msgSet
[i
] + '|';
276 }else if(typeof msgSet
== 'string'){
277 ammessages
+= msgSet
;
279 if(ammessages
== ''){
280 js_log('gMsgLoadRemote::no msg set requested');
285 'meta':'allmessages',
286 'ammessages':ammessages
289 if(data
.query
.allmessages
){
290 var msgs
= data
.query
.allmessages
;
293 ld
[ msgs
[i
]['name'] ] = msgs
[i
]['*'];
297 //load the result into local msg var
303 * Format a size in bytes for output, using an appropriate
304 * unit (B, KB, MB or GB) according to the magnitude in question
306 * @param size Size to format
307 * @return string Plain text (not HTML)
309 function formatSize( size
) {
310 // For small sizes no decimal places necessary
317 // For MB and bigger two decimal places are smarter
321 msg
= 'size-gigabytes';
323 msg
= 'size-megabytes';
326 msg
= 'size-kilobytes';
331 //javascript does not let you do precession points in rounding
332 var p
= Math
.pow(10,round
);
333 var size
= Math
.round( size
* p
) / p
;
334 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
335 return gM( msg
, size
);
338 //gets the loading image:
339 function mv_get_loading_img( style
, class_attr
){
340 var style_txt
= (style
)?style
:'';
341 var class_attr
= (class_attr
)?'class="'+class_attr
+'"':'class="mv_loading_img"';
342 return '<div '+class_attr
+' style="' + style
+'"></div>';
345 function mv_set_loading(target
, load_id
){
346 var id_attr
= ( load_id
)?' id="' + load_id
+ '" ':'';
347 $j(target
).append('<div '+id_attr
+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
348 'background-color:#FFF;">' +
349 mv_get_loading_img('top:30px;left:30px') +
354 * mvJsLoader class handles initialization and js file loads
360 onReadyEvents
:new Array(),
361 doneReadyEvents
:false,
362 jQueryCheckFlag
:false,
363 //to keep consistency across threads:
366 load_error
:false, //load error flag (false by default)
368 callbacks
:new Array(),
371 doLoad:function(loadLibs
, callback
){
373 if( loadLibs
&& loadLibs
.length
!=0 ){ //setup this.libs:
375 //first check if we already have this lib loaded
376 var all_libs_loaded
=true;
377 for(var i
=0; i
< loadLibs
.length
; i
++){
378 //check if the lib is already loaded:
379 if( ! this.checkObjPath( loadLibs
[i
] ) ){
380 all_libs_loaded
=false;
383 if( all_libs_loaded
){
384 js_log('all libs already loaded skipping... load req');
388 //do a check for any css we may need and get it:
389 for(var i
=0; i
< loadLibs
.length
; i
++){
390 if( typeof mvCssPaths
[ loadLibs
[i
] ] != 'undefined' ){
391 loadExternalCss( mvCssPaths
[ loadLibs
[i
] ]);
395 //check if we should use the script loader to combine all the requests into one:
396 if( typeof mwSlScript
!= 'undefined' ){
400 for(var i
=0; i
< loadLibs
.length
; i
++){
401 var curLib
= loadLibs
[i
];
402 //only add if not included yet:
403 if( ! this.checkObjPath( curLib
) ){
404 class_set
+=coma
+ curLib
;
409 var puri
= parseUri( getMvEmbedURL() );
410 if( (getMvEmbedURL().indexOf('://')!=-1) && puri
.host
!= parseUri( document
.URL
).host
){
411 mwSlScript
= puri
.protocol
+ '://' + puri
.authority
+ mwSlScript
;
414 var dbug_attr
= (puri
.queryKey
['debug'])?'&debug=true':'';
415 this.libs
[ last_class
] = mwSlScript
+ '?class=' + class_set
+
416 '&urid=' + getMvUniqueReqId() + dbug_attr
;
420 for(var i
=0; i
< loadLibs
.length
; i
++){
421 var curLib
= loadLibs
[i
];
423 var libLoc
= mvGetClassPath(curLib
);
424 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
425 var qmark
= (libLoc
.indexOf('?')!==true)?'?':'&';
426 this.libs
[curLib
] = mv_embed_path
+ libLoc
+ qmark
+ 'urid='+ getMvUniqueReqId();
432 this.callbacks
.push(callback
);
434 if( this.checkLoading() ){
435 if( this.load_time
++ > 1000){ //time out after ~80seconds
436 js_error( gM('error_load_lib') + this.missing_path
);
437 this.load_error
=true;
439 setTimeout( 'mvJsLoader.doLoad()', 20 );
442 //js_log('checkLoading passed run callbacks');
443 //only do callback if we are in the same instance (weird concurency issue)
445 for(var i
=0; i
< this.callbacks
.length
; i
++)
447 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
450 //js_log('done loading do call: ' + this.callbacks[0] );
451 while( this.callbacks
.length
!=0 ){
452 if( this.ptime
== ( this.ctime
-1) ){ //enforce thread consistency
453 this.callbacks
.pop()();
454 //func = this.callbacks.pop();
455 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
458 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
459 setTimeout( 'mvJsLoader.doLoad()', 25 );
464 this.ptime
=this.ctime
;
466 doLoadFullPaths:function(loadObj
, callback
){
469 doLoadDepMode:function(loadChain
, callback
){
470 //firefox executes js ~in-order of it being included~ so just directly issue request:
471 if( $j
.browser
.firefox
){
473 for(var i
=0; i
< loadChain
.length
;i
++){
474 for(var j
=0;j
<loadChain
[i
].length
;j
++){
475 loadSet
.push(loadChain
[i
][j
]);
478 mvJsLoader
.doLoad(loadSet
, callback
);
480 //safari and IE tend to execute out of order so load with dependenciy checks
481 mvJsLoader
.doLoad(loadChain
.shift(),function(){
482 if(loadChain
.length
!=0){
483 mvJsLoader
.doLoadDepMode(loadChain
, callback
);
489 checkLoading:function(){
492 for(var i
in this.libs
){ //for in loop oky on object
493 if( !this.checkObjPath( i
) ){
495 loadExternalJs( this.libs
[i
] );
499 //js_log("has not yet loaded: " + i);
505 checkObjPath:function( libVar
){
508 var objPath
= libVar
.split('.')
510 for(var p
=0; p
< objPath
.length
; p
++){
511 cur_path
= (cur_path
=='')?cur_path
+objPath
[p
]:cur_path
+'.'+objPath
[p
];
512 eval( 'var ptest = typeof ( '+ cur_path
+ ' ); ');
513 if( ptest
== 'undefined'){
514 this.missing_path
= cur_path
;
518 this.cur_path
= cur_path
;
522 * checks for jQuery and adds the $j noConflict var
524 jQueryCheck:function(callback
){
525 //skip stuff if $j is already loaded:
526 if(_global
['$j'] && callback
)
533 _global
['$j'] = jQuery
.noConflict();
534 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
538 js_log('jquery loaded');
539 //setup mvEmbed jquery bindigns:
547 embedVideoCheck:function( callback
){
549 js_log('embedVideoCheck:');
550 //issue a style sheet request get both mv_embed and jquery styles:
551 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
552 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css');
554 //make sure we have jQuery
555 _this
.jQueryCheck(function(){
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(){
576 addLoadEvent:function(fn
){
577 this.onReadyEvents
.push(fn
);
579 //checks the jQuery flag (this way when remote embeding we don't load jQuery
580 // unless js2AddOnloadHook was used or there is video on the page
581 runQuededFunctions:function(){
583 this.doneReadyEvents
=true;
584 if(this.jQueryCheckFlag
){
585 this.jQueryCheck(function(){
586 _this
.runReadyEvents();
589 this.runReadyEvents();
592 runReadyEvents:function(){
593 js_log("runReadyEvents");
594 while( this.onReadyEvents
.length
){
595 this.onReadyEvents
.shift()();
600 //load an external JS (similar to jquery .require plugin)
601 //but checks for object availability rather than load state
603 /*********** INITIALIZATION CODE *************
604 * this will get called when DOM is ready
605 *********************************************/
606 /* jQuery .ready does not work when jQuery is loaded dynamically
607 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
608 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
609 * $j(document).ready( function(){ */
610 function mwdomReady(force
){
611 js_log('f:mwdomReady:');
612 if( !force
&& mv_init_done
){
613 js_log("mv_init_done already done do nothing...");
617 //handle the execution of Queded function with jQuery "ready"
619 //check if this page does have video or playlist
620 if(document
.getElementsByTagName("video").length
!=0 ||
621 document
.getElementsByTagName("audio").length
!=0 ||
622 document
.getElementsByTagName("playlist").length
!=0){
623 js_log('we have things to rewrite');
624 //load libs and proccess:
625 mvJsLoader
.embedVideoCheck(function(){
626 //run any queded global events:
627 mv_video_embed( function(){
628 mvJsLoader
.runQuededFunctions();
632 //if we already have jQuery make sure its loaded into its proper context $j
633 //run any queded global events:
634 mvJsLoader
.runQuededFunctions();
637 //js2AddOnloadHook: ensure jQuery and the DOM are ready:
638 function js2AddOnloadHook( func
) {
639 //make sure the skin/style sheets are avaliable always:
640 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
641 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css');
643 //if we have already run the dom ready just run the function directly:
644 if( mvJsLoader
.doneReadyEvents
){
645 //make sure jQuery is there:
646 mvJsLoader
.jQueryCheck(function(){
650 //if using js2AddOnloadHook we need to get jQuery into place (if its not already included)
651 mvJsLoader
.jQueryCheckFlag
= true;
652 mvJsLoader
.addLoadEvent( func
);
655 //depreciated mwAddOnloadHook in favor of js2 naming (for clear seperation of js2 code from old mw code
656 var mwAddOnloadHook
= js2AddOnloadHook
;
658 * this function allows for targeted rewriting
660 function rewrite_by_id( vid_id
, ready_callback
){
661 js_log('f:rewrite_by_id: ' + vid_id
);
662 //force a recheck of the dom for playlist or video element:
663 mvJsLoader
.embedVideoCheck(function(){
664 mv_video_embed(ready_callback
, vid_id
);
667 //depricated in favor of updates to oggHanlder
668 function rewrite_for_oggHanlder( vidIdList
){
669 for(var i
= 0; i
< vidIdList
.length
; i
++){
670 var vidId
= vidIdList
[i
];
671 js_log('looking at vid: ' + i
+' ' + vidId
);
672 //grab the thumbnail and src video
673 var pimg
= $j('#'+vidId
+ ' img');
674 var poster_attr
= 'poster = "' + pimg
.attr('src') + '" ';
675 var pwidth
= pimg
.attr('width');
676 var pheight
= pimg
.attr('height');
680 if( pwidth
=='22' && pheight
=='22'){
683 type_attr
= 'type="audio/ogg"';
691 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
692 src
= re
.exec( $j('#'+vidId
).html() )[2];
694 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
695 duration
= re
.exec( $j('#'+vidId
).html() )[2];
697 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
698 offset
= re
.exec( $j('#'+vidId
).html() )[2];
699 var offset_attr
= (offset
)? 'startOffset="'+ offset
+ '"': '';
702 //replace the top div with mv_embed based player:
703 var vid_html
= '<video id="vid_' + i
+'" '+
704 'src="' + src
+ '" ' +
708 'duration="' + duration
+ '" ' +
709 'style="width:' + pwidth
+ 'px;height:' +
710 pheight
+ 'px;"></video>';
711 //js_log("video html: " + vid_html);
712 $j('#'+vidId
).html( vid_html
);
715 //rewrite that video id:
716 rewrite_by_id('vid_' + i
);
721 /*********** INITIALIZATION CODE *************
722 * set DOM ready callback to init_mv_embed
723 *********************************************/
724 // for Mozilla browsers
725 if (document
.addEventListener
) {
726 document
.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
728 //backup "onload" method in case on DOMContentLoaded does not exist
729 window
.onload = function(){ mwdomReady() };
732 * should depreciate and use jquery.ui.dialog instead
734 function mv_write_modal(content
, speed
){
735 $j('#modalbox,#mv_overlay').remove();
736 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
737 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
740 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
741 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
743 $j('#modalbox,#mv_overlay').show( speed
);
745 function mv_remove_modal(speed
){
746 $j('#modalbox,#mv_overlay').remove( speed
);
750 * stores all the mwEmbed jQuery specific bindings
751 * (setup after jQuery is avaliable)
752 * lets you call rewrites in a jquery "way"
754 * @@ eventually we should refactor mwCode over to jQuery style plugins
755 * and mv_embed.js will just hanndle dependency mapping and loading.
758 function mv_jqueryBindings(){
759 js_log('mv_jqueryBindings');
761 $.fn
.addMediaWiz = function( iObj
, callback
){
762 //first set the cursor for the button to "loading"
763 $j(this.selector
).css('cursor','wait').attr('title', gM('loading_title'));
765 iObj
['target_invocation'] = this.selector
;
767 //load the mv_embed_base skin:
768 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css' );
769 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
770 //load all the req libs:
771 mvJsLoader
.jQueryCheck(function(){
772 //load with staged dependeinces (for ie and safari that don't execute in order)
773 mvJsLoader
.doLoadDepMode([
774 [ 'remoteSearchDriver',
785 iObj
['instance_name']= 'rsdMVRS';
786 _global
['rsdMVRS'] = new remoteSearchDriver( iObj
);
788 callback( _global
['rsdMVRS'] );
793 $.fn
.sequencer = function( iObj
, callback
){
795 iObj
['target_sequence_container'] = this.selector
;
796 //issue a request to get the css file (if not already included):
797 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
798 loadExternalCss( mv_embed_path
+'skins/'+mv_skin_name
+'/mv_sequence.css');
799 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
800 mvJsLoader
.embedVideoCheck(function(){
801 //load playlist object and then jquery ui stuff:
802 mvJsLoader
.doLoadDepMode([
822 js_log('calling new mvSequencer');
823 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
824 if(!_global
['mvSeq']){
825 _global
['mvSeq'] = new mvSequencer(iObj
);
827 js_log('mvSeq already init');
833 * the firefogg jquery function:
834 * @@note this firefogg envocation could be made to work more like real jquery plugins
836 $.fn
.firefogg = function( iObj
, callback
) {
839 //add base theme css:
840 loadExternalCss( mv_jquery_skin_path
+ 'jquery-ui-1.7.1.custom.css');
841 loadExternalCss( mv_embed_path
+ 'skins/'+mv_skin_name
+'/styles.css' );
843 //check if we already have firefogg loaded (the call just updates properties for that element)
844 var sElm
= $j(this.selector
).get(0);
845 if(sElm
['firefogg']){
846 if(sElm
['firefogg']=='loading'){
847 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
852 js_log("firefogg::updated: "+ i
+ ' to '+ iObj
[i
]);
853 sElm
['firefogg'][i
] = iObj
[i
];
855 return sElm
['firefogg'];
858 sElm
['firefogg'] = 'loading';
861 iObj
['selector'] = this.selector
;
865 'mvBaseUploadInterface',
874 if( iObj
.encoder_interface
){
883 //make sure we have everything loaded that we need:
884 mvJsLoader
.doLoadDepMode( loadSet
, function(){
885 js_log('firefogg libs loaded. target select:' + iObj
.selector
);
886 //select interface provicer based on if we want to include the encoder interface or not:
887 if(iObj
.encoder_interface
){
888 var myFogg
= new mvAdvFirefogg( iObj
);
890 var myFogg
= new mvFirefogg( iObj
);
893 myFogg
.doRewrite( callback
);
894 var selectorElement
= $j( iObj
.selector
).get(0);
895 selectorElement
['firefogg']=myFogg
;
899 //takes a input player as the selector and exposes basic rendering controls
900 $.fn
.firefoggRender = function( iObj
, callback
){
901 //check if we already have render loaded then just pass on updates/actions
902 var sElm
= $j(this.selector
).get(0);
903 if(sElm
['fogg_render']){
904 if(sElm
['fogg_render']=='loading'){
905 js_log("Error: called firefoggRender while loading");
908 //call or update the property:
910 sElm
['fogg_render']='loading';
912 iObj
['player_target'] = this.selector
;
917 sElm
['fogg_render']= new mvFirefoggRender( iObj
);
918 if( callback
&& typeof callback
== 'function' )
919 callback( sElm
['fogg_render'] );
923 $.fn
.baseUploadInterface = function(iObj
){
924 mvJsLoader
.doLoadDepMode([
926 'mvBaseUploadInterface',
934 myUp
= new mvBaseUploadInterface( iObj
);
939 //shortcut to a themed button:
940 $.btnHtml = function(msg
, className
, iconId
, opt
){
943 var href
= (opt
.href
)?opt
.href
:'#';
944 var target_attr
= (opt
.target
)?' target="' + opt
.target
+ '" ':'';
945 var style_attr
= (opt
.style
)?' style="'+opt
.style
+'" ':'';
946 return '<a href="' + href
+ '" ' + target_attr
+ style_attr
+' class="ui-state-default ui-corner-all ui-icon_link ' +
947 className
+ '"><span class="ui-icon ui-icon-' + iconId
+ '" />' +
950 //shortcut to bind hover state:
951 $.fn
.btnBind = function(){
954 $j(this).addClass('ui-state-hover');
957 $j(this).removeClass('ui-state-hover');
968 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
969 function getURLParamReplace( url
, opt
){
970 var pSrc
= parseUri( url
);
971 if(pSrc
.protocol
!= '' ){
972 var new_url
= pSrc
.protocol
+'://'+ pSrc
.authority
+ pSrc
.path
+'?';
974 var new_url
= pSrc
.path
+'?';
977 for(var key
in pSrc
.queryKey
){
978 var val
= pSrc
.queryKey
[ key
];
979 //do override if requested
982 new_url
+= amp
+ key
+ '=' + val
;
985 //add any vars that did were not originally there:
987 if(!pSrc
.queryKey
[i
]){
988 new_url
+=amp
+ i
+ '=' + opt
[i
];
995 * seconds2npt given a float seconds returns npt format response:
996 * @param float seconds
997 * @param boolean if we should show ms or not.
999 function seconds2npt(sec
, show_ms
){
1001 //js_log("warning: trying to get npt time on NaN:" + sec);
1004 var hours
= Math
.floor(sec
/ 3600);
1005 var minutes
= Math
.floor((sec
/60) % 60);
1006 var seconds
= sec
% 60;
1007 //round the second amount requested significant digits
1009 seconds
= Math
.round( seconds
* 1000 ) / 1000;
1011 seconds
= Math
.round( seconds
);
1014 seconds
= '0'+ seconds
;
1016 minutes
= '0' + minutes
;
1018 return hours
+":"+minutes
+":"+seconds
;
1021 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
1023 function npt2seconds( npt_str
){
1025 //js_log('npt2seconds:not valid ntp:'+ntp);
1028 //strip npt: time definition if present
1029 npt_str
= npt_str
.replace('npt:', '');
1031 times
= npt_str
.split(':');
1032 if(times
.length
!=3){
1033 js_log('error: npt2seconds on ' + npt_str
);
1036 //sometimes the comma is used inplace of pereid for ms
1037 times
[2] = times
[2].replace(/,\s?/,'.');
1038 //return seconds float (ie take seconds float value if present):
1039 return parseInt(times
[0]*3600)+parseInt(times
[1]*60)+parseFloat(times
[2]);
1042 * simple helper to grab a edit token
1044 * @param title the wiki page title you want to edit )
1045 * @param api_url 'optional' the target api url
1046 * @param callback the callback function to pass the token or "false" to
1048 function get_mw_token( title
, api_url
, callback
){
1049 if(!title
&& wgUserName
){
1050 title
= 'User:' + wgUserName
;
1062 for(var i
in data
.query
.pages
){
1063 if(data
.query
.pages
[i
]['edittoken']){
1064 if(typeof callback
== 'function')
1065 callback ( data
.query
.pages
[i
]['edittoken'] );
1073 //does a remote or local api request based on request url
1074 //@param options: url, data, cbParam, callback
1075 function do_api_req( options
, callback
){
1076 if(typeof options
.data
!= 'object'){
1077 return js_error('Error: request paramaters must be an object');;
1079 //gennerate the url if its missing:
1080 if( typeof options
.url
== 'undefined' || options
.url
=== false){
1081 if(!wgServer
|| ! wgScriptPath
){
1082 return js_error('Error: no api url for api request');;
1084 if (wgServer
&& wgScript
)
1085 options
.url
= wgServer
+ wgScript
;
1086 //update to api.php (if index.php was in the wgScript path):
1087 options
.url
= options
.url
.replace(/index.php/, 'api.php');
1089 if( typeof options
.data
== 'undefined' )
1092 //force format to json (if not already set)
1093 options
.data
['format'] = 'json';
1095 //if action not set assume query
1096 if(!options
.data
['action'])
1097 options
.data
['action']='query';
1099 js_log('do api req: ' + options
.url
+'?' + jQuery
.param(options
.data
) );
1100 //build request string:
1101 if( parseUri( document
.URL
).host
== parseUri( options
.url
).host
){
1102 //local request do api request directly
1107 dataType
:'json', //api requests _should_ always return JSON data:
1109 success:function(data
){
1113 js_error( ' error' + e
+' in getting: ' + options
.url
);
1117 //set the callback param if not already set:
1118 if( typeof options
.jsonCB
== 'undefined')
1119 options
.jsonCB
= 'callback';
1121 var req_url
= options
.url
;
1122 var paramAnd
= (req_url
.indexOf('?')==-1)?'?':'&';
1123 //put all the values into the GET req:
1124 for(var i
in options
.data
){
1125 req_url
+= paramAnd
+ encodeURIComponent( i
) + '=' + encodeURIComponent( options
.data
[i
] );
1128 var fname
= 'mycpfn_' + ( global_cb_count
++ );
1129 _global
[ fname
] = callback
;
1130 req_url
+= '&' + options
.jsonCB
+ '=' + fname
;
1131 loadExternalJs( req_url
);
1134 //grab wiki form error for wiki html page proccessing (should be depricated)
1135 function grabWikiFormError ( result_page
){
1137 sp
= result_page
.indexOf('<span class="error">');
1139 se
= result_page
.indexOf('</span>', sp
);
1140 res
.error_txt
= result_page
.substr(sp
, (sp
-se
)) + '</span>';
1143 sp
= result_page
.indexOf('<ul class="warning">')
1145 se
= result_page
.indexOf('</ul>', sp
);
1146 res
.error_txt
= result_page
.substr(sp
, (se
-sp
)) + '</ul>';
1147 //try and add the ignore form item:
1148 sfp
= result_page
.indexOf('<form method="post"');
1150 sfe
= result_page
.indexOf('</form>', sfp
);
1151 res
.form_txt
= result_page
.substr(sfp
, ( sfe
- sfp
)) + '</form>';
1154 //one more error type check:
1155 sp
= result_page
.indexOf('class="mw-warning-with-logexcerpt">')
1157 se
= result_page
.indexOf('</div>', sp
);
1158 res
.error_txt
= result_page
.substr(sp
, ( se
- sp
)) + '</div>';
1164 //do a "normal" request
1165 function do_request(req_url
, callback
){
1166 js_log('do_request::req_url:' + req_url
+ ' != ' + parseUri( req_url
).host
);
1167 //if we are doing a request to the same domain or relative link do a normal GET:
1168 if( parseUri(document
.URL
).host
== parseUri(req_url
).host
||
1169 req_url
.indexOf('://') == -1 ){ //relative url
1170 //do a direct request:
1175 success:function(data
){
1180 //get data via DOM injection with callback
1181 global_req_cb
.push(callback
);
1182 //prepend json_ to feed_format if not already requesting json format
1183 if( req_url
.indexOf("feed_format=")!=-1 && req_url
.indexOf("feed_format=json")==-1)
1184 req_url
= req_url
.replace(/feed_format=/, 'feed_format=json_');
1185 loadExternalJs(req_url
+'&cb=mv_jsdata_cb&cb_inx='+(global_req_cb
.length
-1));
1189 function mv_jsdata_cb(response
){
1190 js_log('f:mv_jsdata_cb:'+ response
['cb_inx']);
1191 //run the callback from the global req cb object:
1192 if( !global_req_cb
[response
['cb_inx']] ){
1193 js_log('missing req cb index');
1196 if( !response
['pay_load'] ){
1197 js_log("missing pay load");
1200 //switch on content type:
1201 switch(response
['content-type']){
1205 if(typeof response
['pay_load'] == 'string'){
1206 //js_log('load string:'+"\n"+ response['pay_load']);
1208 //attempt to parse as xml for IE
1209 if( $j
.browser
.msie
){
1210 var xmldata
=new ActiveXObject("Microsoft.XMLDOM");
1211 xmldata
.async
="false";
1212 xmldata
.loadXML(response
['pay_load']);
1213 }else{ //for others (firefox, safari etc)
1215 var xmldata
= (new DOMParser()).parseFromString(response
['pay_load'], "text/xml");
1217 js_log('XML parse ERROR: ' + e
.message
);
1220 //@@todo hanndle xml parser errors
1221 if(xmldata
)response
['pay_load']=xmldata
;
1225 js_log('bad response type' + response
['content-type']);
1229 global_req_cb
[response
['cb_inx']]( response
['pay_load'] );
1231 //load external js via dom injection
1232 function loadExternalJs( url
){
1233 js_log('load js: '+ url
);
1234 //if(window['$j']) //use jquery call:
1242 var e
= document
.createElement("script");
1243 e
.setAttribute('src', url
);
1244 e
.setAttribute('type',"text/javascript");
1245 //e.setAttribute('defer', true);
1246 document
.getElementsByTagName("head")[0].appendChild(e
);
1250 function styleSheetPresent(url
){
1251 style_elements
= document
.getElementsByTagName('link');
1252 if( style_elements
.length
> 0) {
1253 for(i
= 0; i
< style_elements
.length
; i
++) {
1254 if(style_elements
[i
].href
== url
)
1260 function loadExternalCss(url
){
1261 //if could have script loader group thes css request
1262 //but debatable it may hurt more than it helps with caching and all
1263 if(typeof url
=='object'){
1265 loadExternalCss ( url
[i
] );
1270 if( url
.indexOf('?') == -1 ){
1271 url
+='?'+getMvUniqueReqId();
1273 if(!styleSheetPresent(url
) ){
1274 js_log('load css: ' + url
);
1275 var e
= document
.createElement("link");
1277 e
.type
= "text/css";
1278 e
.rel
= 'stylesheet';
1279 document
.getElementsByTagName("head")[0].appendChild(e
);
1282 function getMvEmbedURL(){
1283 if( _global
['mv_embed_url'] )
1284 return _global
['mv_embed_url'];
1285 var js_elements
= document
.getElementsByTagName("script");
1286 for(var i
=0; i
< js_elements
.length
; i
++){
1287 //check for normal mv_embed.js and or script loader
1288 var src
= js_elements
[i
].getAttribute("src");
1290 if( src
.indexOf('mv_embed.js') !=-1 || (
1291 ( src
.indexOf('mwScriptLoader.php') != -1 || src
.indexOf('jsScriptLoader.php') != -1 )
1292 && src
.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1293 _global
['mv_embed_url'] = src
;
1298 js_error('Error: getMvEmbedURL failed to get Embed Path');
1301 //gets a unique request id to ensure fresh javascript
1302 function getMvUniqueReqId(){
1303 if( _global
['urid'] )
1304 return _global
['urid'];
1305 var mv_embed_url
= getMvEmbedURL();
1306 //if we have a uri retun that:
1307 var urid
= parseUri( mv_embed_url
).queryKey
['urid']
1309 _global
['urid'] = urid
;
1312 //if in debug mode get a fresh unique request key:
1313 if( parseUri( mv_embed_url
).queryKey
['debug'] == 'true'){
1315 var urid
= d
.getTime();
1316 _global
['urid'] = urid
;
1319 //else just return the mv_embed version;
1320 return MV_EMBED_VERSION
;
1323 * sets the global mv_embed path based on the scripts location
1325 function getMvEmbedPath(){
1326 var mv_embed_url
= getMvEmbedURL();
1327 if( mv_embed_url
.indexOf('mv_embed.js') !== -1 ){
1328 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mv_embed.js'));
1329 }else if(mv_embed_url
.indexOf('mwScriptLoader.php')!==-1){
1330 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1331 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path
;
1333 mv_embed_path
= mv_embed_url
.substr(0, mv_embed_url
.indexOf('jsScriptLoader.php'));
1335 //absolute the url (if relative) (if we don't have mv_embed path)
1336 if( mv_embed_path
.indexOf('://') == -1){
1337 var pURL
= parseUri( document
.URL
);
1338 if(mv_embed_path
.charAt(0)=='/'){
1339 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ mv_embed_path
;
1342 if(mv_embed_path
==''){
1343 mv_embed_path
= pURL
.protocol
+ '://' + pURL
.authority
+ pURL
.directory
+ mv_embed_path
;
1347 return mv_embed_path
;
1350 if (typeof DOMParser
== "undefined") {
1351 DOMParser = function () {}
1352 DOMParser
.prototype.parseFromString = function (str
, contentType
) {
1353 if (typeof ActiveXObject
!= "undefined") {
1354 var d
= new ActiveXObject("MSXML.DomDocument");
1357 } else if (typeof XMLHttpRequest
!= "undefined") {
1358 var req
= new XMLHttpRequest
;
1359 req
.open("GET", "data:" + (contentType
|| "application/xml") +
1360 ";charset=utf-8," + encodeURIComponent(str
), false);
1361 if (req
.overrideMimeType
) {
1362 req
.overrideMimeType(contentType
);
1365 return req
.responseXML
;
1370 * utility functions:
1372 function js_log(string
){
1373 if( window
.console
){
1374 window
.console
.log(string
);
1377 * IE and non-firebug debug:
1379 /*var log_elm = document.getElementById('mv_js_log');
1381 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1382 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1383 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1386 var log_elm = document.getElementById('mv_js_log');
1389 log_elm.value+=string+"\n";
1395 function js_error(string
){