2 * this file exposes some of the functionality of mwEmbed to wikis
3 * that do not yet have js2 enabled
6 var urlparts
= getRemoteEmbedPath();
7 var mwEmbedHostPath
= urlparts
[0];
8 var reqAguments
= urlparts
[1];
10 addOnloadHook( function(){
11 //only do rewrites if MV_EMBED / js2 is "off"
12 if( typeof MV_EMBED_VERSION
== 'undefined' ) {
13 doPageSpecificRewrite();
17 function doPageSpecificRewrite() {
19 if( wgAction
== 'edit' || wgAction
== 'submit' ) {
20 load_mv_embed( function() {
21 importScriptURI( mwEmbedHostPath
+ '/editPage.js' + reqAguments
);
25 // Firefogg integration
26 if( wgPageName
== "Special:Upload" ){
27 load_mv_embed( function() {
28 importScriptURI( mwEmbedHostPath
+ '/uploadPage.js' + reqAguments
);
32 // OggHandler rewrite for view pages:
34 var divs
= document
.getElementsByTagName( 'div' );
35 for( var i
= 0; i
< divs
.length
; i
++ ) {
36 if( divs
[i
].id
&& divs
[i
].id
.substring( 0, 11 ) == 'ogg_player_' ) {
37 vidIdList
.push( divs
[i
].getAttribute( "id" ) );
40 if( vidIdList
.length
> 0 ) {
41 load_mv_embed( function() {
42 mvJsLoader
.embedVideoCheck( function() {
43 // Do utility rewrite of OggHandler content:
44 rewrite_for_OggHandler( vidIdList
);
49 // will be deprecated in favor of updates to OggHandler
50 function rewrite_for_OggHandler( vidIdList
){
51 for( var i
= 0; i
< vidIdList
.length
; i
++ ) {
52 var vidId
= vidIdList
[i
];
53 // Grab the thumbnail and src of the video
54 var pimg
= $j( '#' + vidId
+ ' img' );
55 var poster_attr
= 'poster = "' + pimg
.attr( 'src' ) + '" ';
56 var pwidth
= pimg
.attr( 'width' );
57 var pheight
= pimg
.attr( 'height' );
61 if( pwidth
== '22' && pheight
== '22' ) {
64 type_attr
= 'type="audio/ogg"';
72 var re
= new RegExp( /videoUrl(":?\s*)*([^&]*)/ );
73 src
= re
.exec( $j( '#'+vidId
).html() )[2];
75 var re
= new RegExp( /length(":?\s*)*([^&]*)/ );
76 duration
= re
.exec( $j( '#'+vidId
).html() )[2];
78 var re
= new RegExp( /offset(":?\s*)*([^&]*)/ );
79 offset
= re
.exec( $j( '#'+vidId
).html() )[2];
80 var offset_attr
= offset
? 'startOffset="' + offset
+ '"' : '';
82 // Rewrite that video id (do async calls to avoid locking)
84 // Replace the top div with the mv_embed based player:
85 var vid_html
= '<video id="vid_' + i
+'" '+
86 'src="' + src
+ '" ' +
90 'duration="' + duration
+ '" ' +
91 'style="width:' + pwidth
+ 'px;height:' +
92 pheight
+ 'px;"></video>';
93 //set the video tag inner html and update the height
94 $j( '#' + vidId
).html( vid_html
)
95 .css('height', pheight
+ 20;
99 rewrite_by_id( 'vid_' + i
);
103 function getRemoteEmbedPath() {
104 for( var i
= 0; i
< document
.getElementsByTagName( 'script' ).length
; i
++ ) {
105 var s
= document
.getElementsByTagName( 'script' )[i
];
106 if( s
.src
.indexOf( 'remoteMwEmbed.js' ) != -1 ) {
109 if( s
.src
.indexOf( '?' ) != -1) {
110 reqStr
= s
.src
.substr( s
.src
.indexOf( '?' ) );
111 scriptPath
= s
.src
.substr( 0, s
.src
.indexOf( '?' ) ).replace( 'remoteMwEmbed.js', '' );
113 scriptPath
= s
.src
.replace( 'remoteMwEmbed.js', '' )
115 // Use the external_media_wizard path:
116 return [scriptPath
, reqStr
];
121 function load_mv_embed( callback
) {
122 // Inject mv_embed if needed
123 if( typeof mvEmbed
== 'undefined' ) {
124 importScriptURI( mwEmbedHostPath
+ '/mwEmbed/mv_embed.js' + reqAguments
);
125 check_for_mv_embed( callback
);
127 check_for_mv_embed( callback
);
131 function check_for_mv_embed( callback
) {
132 if( typeof MV_EMBED_VERSION
== 'undefined' ) {
133 setTimeout( function(){
134 check_for_mv_embed( callback
);