r62677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62676‎ | r62677 | r62678 >
Date:19:39, 18 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* added jQuery build-out of interface components ( just for mvpcf skin so far )
* still have to merge bindings.
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js
@@ -72,17 +72,16 @@
7373 embedPlayer.$interface.find('.control-bar').remove();
7474
7575 // Add some space to control_wrap for the control bar:
76 - embedPlayer.$interface.css({
 76+ embedPlayer.$interface.css( {
7777 'height' : parseInt( embedPlayer.height ) + parseInt( this.height)
78 - });
 78+ } );
7979 embedPlayer.$interface.append(
8080 $j('<div>')
8181 .addClass( 'ui-state-default ui-widget-header ui-helper-clearfix control-bar' )
82 - .html(
83 - this.buildControls()
84 - )
8582 .css('display', 'block')
86 - );
 83+ );
 84+ //Add the Controls with their bindings
 85+ this.addControlComponents();
8786 // Add hooks once Controls are in DOM
8887 this.addControlHooks();
8988 },
@@ -91,12 +90,15 @@
9291 * Builds the interface controls
9392 * @returns the interface html string
9493 */
95 - buildControls: function(){
 94+ addControlComponents: function( ) {
9695 var _this = this;
9796 mw.log( 'f:controlsBuilder:: opt:' + this.options );
9897 // Set up local pointer to the embedPlayer
9998 var embedPlayer = this.embedPlayer;
10099
 100+ //Set up local var to control container:
 101+ var $controlBar = embedPlayer.$interface.find( '.control-bar' );
 102+
101103 this.available_width = embedPlayer.getPlayerWidth();
102104
103105 // Make pointer to the embedPlayer
@@ -113,45 +115,47 @@
114116 if ( this.external_options && $j( '#mv_vid_options_' + this.id ).length == 0 ){
115117 $j( 'body' ).append( this.components[ 'options_menu' ].o( this ) );
116118 }
117 -
118 - var s = '';
119119
120120 // Build component output:
121 - for ( var i in this.components ) {
 121+ for ( var component_id in this.components ) {
122122 // Make sure the given components is supported:
123 - if ( this.supportedComponets[ i ] ) {
124 - if ( this.available_width > this.components[i].w ) {
125 - // Special case with playhead don't add unless we have 50px
126 - if ( i == 'play_head' && this.available_width < 30 )
 123+ if ( this.supportedComponets[ component_id ] ) {
 124+ if ( this.available_width > this.components[ component_id ].w ) {
 125+ // Special case with playhead don't add unless we have 30px
 126+ if ( component_id == 'play_head' && this.available_width < 30 ){
127127 continue;
128 - s += this.components[i].o( this );
129 - this.available_width -= this.components[i].w;
 128+ }
 129+ // Append the component
 130+ $controlBar.append(
 131+ _this.getComponent( component_id )
 132+ );
 133+
 134+ this.available_width -= this.components[ component_id ].w;
130135 } else {
131 - mw.log( 'not enough space for control component:' + i );
 136+ mw.log( 'Not enough space for control component:' + component_id );
132137 }
133138 }
134139 }
135 - return s;
136140 },
137 -
 141+
138142 /**
139143 * Get minimal width for interface overlay
140144 */
141 - getOverlayWidth: function(){
 145+ getOverlayWidth: function( ) {
142146 return ( this.embedPlayer.getPlayerWidth() < 300 )? 300 : this.embedPlayer.getPlayerWidth();
143147 },
144148
145149 /**
146150 * Get minimal height for interface overlay
147151 */
148 - getOverlayHeight: function(){
 152+ getOverlayHeight: function( ) {
149153 return ( this.embedPlayer.getPlayerHeight() < 200 )? 200 : this.embedPlayer.getPlayerHeight();
150154 },
151155
152156 /**
153157 * Get the control bar height:
154158 */
155 - getControlBarHeight: function(){
 159+ getControlBarHeight: function( ) {
156160 return this.height;
157161 },
158162
@@ -159,7 +163,7 @@
160164 * addControlHooks
161165 * Adds control hooks once controls are in the DOM
162166 */
163 - addControlHooks:function( ) {
 167+ addControlHooks: function( ) {
164168 // Set up local pointer to the embedPlayer
165169 var embedPlayer = this.embedPlayer;
166170 var _this = this;
@@ -167,77 +171,11 @@
168172 // Setup target shortcut to control-bar
169173 $target = embedPlayer.$interface;
170174
171 - // Add play hook:
172 - $target.find( '.play-btn,.play-btn-large' ).unbind().buttonHover().click( function() {
173 - embedPlayer.play();
174 - } );
 175+
175176
176177 // Add recommend firefox if we have non-native playback:
177 - if ( _this.doNativeWarningCheck() ) {
178 - $j( '#dc_' + embedPlayer.id ).hover(
179 - function() {
180 - if ( $j( '#gnp_' + embedPlayer.id ).length == 0 ) {
181 - var toppos = ( embedPlayer.instanceOf == 'mvPlayList' ) ? 25 : 10;
182 -
183 - $j( this ).append(
184 - $j('<div />')
185 - .attr({
186 - 'id': "gnp_" + embedPlayer.id
187 - })
188 - .addClass( 'ui-state-highlight ui-corner-all' )
189 - .css({
190 - 'position':'absolute',
191 - 'display':'none',
192 - 'background':'#FFF',
193 - 'color':'#111',
194 - 'top' : toppos + 'px',
195 - 'left' : '10px',
196 - 'right' : '10px'
197 - })
198 - .html( gM( 'mwe-for_best_experience' ) )
199 - );
200 - $target_warning = $j( '#gnp_' + embedPlayer.id );
201 -
202 - $target_warning.append(
203 - $j('<br />')
204 - );
205 -
206 -
207 - $target_warning.append(
208 - $j( '<input />' )
209 - .attr({
210 - 'id' : 'ffwarn_' + embedPlayer.id,
211 - 'type' : "checkbox",
212 - 'name' : 'ffwarn_' + embedPlayer.id
213 - })
214 - .click( function() {
215 - if ( $j( this ).is( ':checked' ) ) {
216 - // Set up a cookie for 7 days:
217 - $j.cookie( 'show_player_warning', false, { expires: 7 } );
218 - // Set the current instance
219 - mw.setConfig( 'show_player_warning', false );
220 - $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
221 - } else {
222 - mw.setConfig( 'show_player_warning', true );
223 - $j.cookie( 'show_player_warning', true );
224 - }
225 - } )
226 - );
227 - $target_warning.append(
228 - $j('<span />')
229 - .text( gM( 'mwe-do_not_warn_again' ) )
230 - )
231 - }
232 -
233 - // Only show the warning if cookie and config are true
234 - if ( mw.getConfig( 'show_player_warning' ) === true ){
235 - $j( '#gnp_' + embedPlayer.id ).fadeIn( 'slow' );
236 - }
237 - },
238 - function() {
239 - $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
240 - }
241 - );
 178+ if ( _this.checkNativeWarning( ) ) {
 179+ _this.doNativeWarning();
242180 }
243181
244182 if ( $j.browser.msie && $j.browser.version <= 6 ) {
@@ -354,12 +292,13 @@
355293 } );
356294 return false; // onclick action return false
357295 },
 296+
358297 /**
359 - * check if a warning should be issued to non-native playback systems
 298+ * Check if a warning should be issued to non-native playback systems
360299 *
361300 * dependent on mediaElement being setup
362301 */
363 - doNativeWarningCheck: function( ) {
 302+ checkNativeWarning: function( ) {
364303 // Check cookie to see if user requested to hide it
365304 if ( $j.cookie( 'show_player_warning' ) == 'false' ) {
366305 return false;
@@ -395,9 +334,83 @@
396335 },
397336
398337 /**
 338+ * Does a native warning check binding to the player on mouse over.
 339+ */
 340+ doNativeWarning: function( ) {
 341+ // Set up local pointer to the embedPlayer
 342+ var embedPlayer = this.embedPlayer;
 343+ var _this = this;
 344+
 345+ $j( '#dc_' + embedPlayer.id ).hover(
 346+ function() {
 347+ if ( $j( '#gnp_' + embedPlayer.id ).length == 0 ) {
 348+ var toppos = ( embedPlayer.instanceOf == 'mvPlayList' ) ? 25 : 10;
 349+
 350+ $j( this ).append(
 351+ $j('<div />')
 352+ .attr({
 353+ 'id': "gnp_" + embedPlayer.id
 354+ })
 355+ .addClass( 'ui-state-highlight ui-corner-all' )
 356+ .css({
 357+ 'position':'absolute',
 358+ 'display':'none',
 359+ 'background':'#FFF',
 360+ 'color':'#111',
 361+ 'top' : toppos + 'px',
 362+ 'left' : '10px',
 363+ 'right' : '10px'
 364+ })
 365+ .html( gM( 'mwe-for_best_experience' ) )
 366+ );
 367+ $target_warning = $j( '#gnp_' + embedPlayer.id );
 368+
 369+ $target_warning.append(
 370+ $j('<br />')
 371+ );
 372+
 373+
 374+ $target_warning.append(
 375+ $j( '<input />' )
 376+ .attr({
 377+ 'id' : 'ffwarn_' + embedPlayer.id,
 378+ 'type' : "checkbox",
 379+ 'name' : 'ffwarn_' + embedPlayer.id
 380+ })
 381+ .click( function() {
 382+ if ( $j( this ).is( ':checked' ) ) {
 383+ // Set up a cookie for 7 days:
 384+ $j.cookie( 'show_player_warning', false, { expires: 7 } );
 385+ // Set the current instance
 386+ mw.setConfig( 'show_player_warning', false );
 387+ $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
 388+ } else {
 389+ mw.setConfig( 'show_player_warning', true );
 390+ $j.cookie( 'show_player_warning', true );
 391+ }
 392+ } )
 393+ );
 394+ $target_warning.append(
 395+ $j('<span />')
 396+ .text( gM( 'mwe-do_not_warn_again' ) )
 397+ )
 398+ }
 399+
 400+ // Only show the warning if cookie and config are true
 401+ if ( mw.getConfig( 'show_player_warning' ) === true ){
 402+ $j( '#gnp_' + embedPlayer.id ).fadeIn( 'slow' );
 403+ }
 404+ },
 405+ function() {
 406+ $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
 407+ }
 408+ );
 409+ },
 410+
 411+ /**
399412 * Binds the volume controls
400413 */
401 - doVolumeBinding:function() {
 414+ doVolumeBinding: function( ) {
402415 var embedPlayer = this.embedPlayer;
403416 var _this = this;
404417 embedPlayer.$interface.find( '.volume_control' ).unbind().buttonHover().click( function() {
@@ -454,8 +467,9 @@
455468 }
456469 }
457470
458 - if ( this.volume_layout == 'vertical' )
 471+ if ( this.volume_layout == 'vertical' ) {
459472 sliderConf[ 'orientation' ] = "vertical";
 473+ }
460474
461475 embedPlayer.$interface.find( '.volume-slider' ).slider( sliderConf );
462476 },
@@ -474,9 +488,9 @@
475489 *
476490 * @param {String} component Component key to grab html output
477491 */
478 - getComponent:function( component ) {
479 - if ( this.components[ component ] ) {
480 - return this.components[ component ].o( this );
 492+ getComponent: function( component_id ) {
 493+ if ( this.components[ component_id ] ) {
 494+ return this.components[ component_id ].o( this );
481495 } else {
482496 return false;
483497 }
@@ -484,29 +498,38 @@
485499
486500 /**
487501 * Components Object
488 - * Take in the embedPlayer and return some html for the given component.
 502+ * Take in the embedPlayer and return some html for the given component.
489503 *
490504 * components can be overwritten by skin javascript
 505+ *
 506+ * Component JSON structure is as follows:
 507+ * 'o' Function to return a binded jQuery object ( accepts the ctrlObject as a parameter )
 508+ * 'w' The width of the component
 509+ * 'h' The height of the component ( if height is undefined the height of the control bar is used )
491510 */
492511 components: {
493 - /*
 512+ /**
494513 * The large play button in center of the player
495514 */
496515 'play-btn-large': {
497516 'w' : 130,
498517 'h' : 96,
499 - 'o':function( ctrlObj ) {
 518+ 'o' : function( ctrlObj ) {
500519 // Get dynamic position for big play button
501 - return $j( '<div/>' ).attr( {
502 - 'title' : gM( 'mwe-play_clip' ),
503 - 'class' : "ui-state-default play-btn-large"
504 - } )
505 - .css( {
506 - 'left' : ( ( ctrlObj.embedPlayer.getPlayerWidth() - this.w ) / 2 ),
507 - 'top' : ( ( ctrlObj.embedPlayer.getPlayerHeight() - this.h ) / 2 )
508 - } )
509 - .wrap( '<div/>' ).parent().html();
510 - }
 520+ return $j( '<div/>' )
 521+ .attr( {
 522+ 'title' : gM( 'mwe-play_clip' ),
 523+ 'class' : "ui-state-default play-btn-large"
 524+ } )
 525+ .css( {
 526+ 'left' : ( ( ctrlObj.embedPlayer.getPlayerWidth() - this.w ) / 2 ),
 527+ 'top' : ( ( ctrlObj.embedPlayer.getPlayerHeight() - this.h ) / 2 )
 528+ } )
 529+ // Add play hook:
 530+ .buttonHover().click( function() {
 531+ ctrlObj.embedPlayer.play();
 532+ } );
 533+ }
511534 },
512535
513536 /**
@@ -514,8 +537,8 @@
515538 * download, and share options
516539 */
517540 'options_menu': {
518 - 'w':0,
519 - 'o':function( ctrlObj ) {
 541+ 'w' : 0,
 542+ 'o' : function( ctrlObj ) {
520543 var o = '<div id="mv_vid_options_' + ctrlObj.embedPlayer.id + '" class="videoOptions">' +
521544 '<div class="videoOptionsTop"></div>' +
522545 '<div class="videoOptionsBox">' +
@@ -543,11 +566,15 @@
544567 * The options button, invokes display of the options menu
545568 */
546569 'options': {
547 - 'w':28,
548 - 'o':function( ctrlObj ) {
549 - return '<div title="' + gM( 'mwe-player_options' ) + '" class="ui-state-default ui-corner-all ui-icon_link rButton options-btn">' +
550 - '<span class="ui-icon ui-icon-wrench"></span>' +
551 - '</div>';
 570+ 'w': 28,
 571+ 'o': function( ctrlObj ) {
 572+ return $j( '<div />' )
 573+ .attr( 'title', gM( 'mwe-player_options' ) )
 574+ .addClass( 'ui-state-default ui-corner-all ui-icon_link rButton options-btn' )
 575+ .append(
 576+ $j('<span />')
 577+ .addClass( 'ui-icon ui-icon-wrench' )
 578+ )
552579 }
553580 },
554581
@@ -555,59 +582,91 @@
556583 * The fullscreen button for displaying the video fullscreen
557584 */
558585 'fullscreen': {
559 - 'w':28,
560 - 'o':function( ctrlObj ) {
561 - return '<div title="' + gM( 'mwe-player_fullscreen' ) + '" class="ui-state-default ui-corner-all ui-icon_link rButton fullscreen-btn">' +
562 - '<span class="ui-icon ui-icon-arrow-4-diag"></span>' +
563 - '</div>'
 586+ 'w': 28,
 587+ 'o': function( ctrlObj ) {
 588+ return $j( '<div />' )
 589+ .attr( 'title', gM( 'mwe-player_fullscreen' ) )
 590+ .addClass( "ui-state-default ui-corner-all ui-icon_link rButton fullscreen-btn" )
 591+ .append(
 592+ $j( '<span />' )
 593+ .addClass( "ui-icon ui-icon-arrow-4-diag" )
 594+ )
564595 }
565596 },
566597
567598
568599 /**
569 - * The pause button
 600+ * The pause / play button
570601 */
571602 'pause': {
572 - 'w':28,
573 - 'o':function( ctrlObj ) {
574 - return '<div title="' + gM( 'mwe-play_clip' ) + '" class="ui-state-default ui-corner-all ui-icon_link lButton play-btn">' +
575 - '<span class="ui-icon ui-icon-play"/>' +
576 - '</div>';
 603+ 'w': 28,
 604+ 'o': function( ctrlObj ) {
 605+ return $j( '<div />' )
 606+ .attr( 'title', gM( 'mwe-play_clip' ) )
 607+ .addClass ( "ui-state-default ui-corner-all ui-icon_link lButton play-btn" )
 608+ .append(
 609+ $j( '<span />' )
 610+ .addClass( "ui-icon ui-icon-play" )
 611+ )
577612 }
578613 },
579614
580 - /*
 615+ /**
581616 * The closed captions button
582617 */
583618 'timed_text': {
584 - 'w':28,
585 - 'o':function( ctrlObj ) {
586 - return '<div title="' + gM( 'mwe-timed_text' ) + '" class="ui-state-default ui-corner-all ui-icon_link rButton timed-text">' +
587 - '<span class="ui-icon ui-icon-comment"></span>' +
588 - '</div>'
 619+ 'w': 28,
 620+ 'o': function( ctrlObj ) {
 621+ return $j( '<div />' )
 622+ .attr( 'title', gM( 'mwe-timed_text' ) )
 623+ .addClass( "ui-state-default ui-corner-all ui-icon_link rButton timed-text" )
 624+ .append(
 625+ $j( '<span />' )
 626+ .addClass( "ui-icon ui-icon-comment" )
 627+ )
589628 }
590629 },
591630
592 - /*
 631+ /**
593632 * The volume control interface html
594633 */
595634 'volume_control': {
596 - 'w':28,
597 - 'o':function( ctrlObj ) {
598 - var o = '';
599 - if ( ctrlObj.volume_layout == 'horizontal' )
600 - o += '<div class="ui-slider ui-slider-horizontal rButton volume-slider"></div>';
601 -
602 - o += '<div title="' + gM( 'mwe-volume_control' ) + '" class="ui-state-default ui-corner-all ui-icon_link rButton volume_control">' +
603 - '<span class="ui-icon ui-icon-volume-on"></span>';
 635+ 'w' : 28,
 636+ 'o' : function( ctrlObj ) {
 637+ $volumeOut = $j( '<div />' );
 638+ if ( ctrlObj.volume_layout == 'horizontal' ) {
 639+ $volumeOut.append(
 640+ $j( '<div />' )
 641+ .addClass( "ui-slider ui-slider-horizontal rButton volume-slider" )
 642+ );
 643+ }
 644+ // Add the volume control icon
 645+ $volumeOut.append(
 646+ $j('<div />')
 647+ .attr( 'title', gM( 'mwe-volume_control' ) )
 648+ .addClass( "ui-state-default ui-corner-all ui-icon_link rButton volume_control" )
 649+ .append(
 650+ $j( '<span />' )
 651+ .addClass( "ui-icon ui-icon-volume-on" )
 652+ )
 653+ );
604654
605655 if ( ctrlObj.volume_layout == 'vertical' ) {
606 - o += '<div style="position:absolute;display:none;left:0px;" class="vol_container ui-corner-all">' +
607 - '<div class="volume-slider" ></div>' +
608 - '</div>';
609 - }
610 - o += '</div>';
611 - return o;
 656+ $volumeOut.append(
 657+ $j( '<div />' )
 658+ .css( {
 659+ 'position' : 'absolute',
 660+ 'display' : 'none',
 661+ 'left' : '0px;'
 662+ })
 663+ .addClass( "vol_container ui-corner-all" )
 664+ .append(
 665+ $j( '<div />' )
 666+ .addClass ( "volume-slider" )
 667+ )
 668+ );
 669+ }
 670+ return $volumeOut;
612671 }
613672 },
614673
@@ -617,7 +676,12 @@
618677 'time_display': {
619678 'w':90,
620679 'o':function( ctrlObj ) {
621 - return '<div class="ui-widget time-disp">' + ctrlObj.embedPlayer.getTimeRange() + '</div>';
 680+ return $j( '<div />' )
 681+ .addClass( "ui-widget time-disp" )
 682+ .append(
 683+ ctrlObj.embedPlayer.getTimeRange()
 684+ )
 685+
622686 }
623687 },
624688 /*
@@ -626,7 +690,9 @@
627691 'play_head': {
628692 'w':0, // special case (takes up remaining space)
629693 'o':function( ctrlObj ) {
630 - return '<div class="play_head" style="width: ' + ( ctrlObj.available_width - 20 ) + 'px;"></div>';
 694+ return $j( '<div />' )
 695+ .addClass ( "play_head" )
 696+ .css( "width", parseInt( ctrlObj.available_width - 20 ) + 'px' )
631697 }
632698 }
633699 }
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/loader.js
@@ -2,7 +2,7 @@
33 * Loader for libAddMedia module:
44 */
55
6 -// Scope everythign in "mw" ( keeps the global namespace clean )
 6+// Scope everything in "mw" ( keeps the global namespace clean )
77 ( function( mw ) {
88
99 mw.addMessages( {
@@ -86,7 +86,8 @@
8787 *
8888 * Includes both firefogg & firefogg "GUI" which share some loading logic:
8989 */
90 -
 90+
 91+ // Clone the baseUploadlibs array
9192 var mwBaseFirefoggReq = baseUploadlibs.slice( 0 )
9293 mwBaseFirefoggReq[0].push('mw.Firefogg');
9394
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1807,7 +1807,6 @@
18081808 * Wrapper for jQuery getScript,
18091809 * Uses the scriptLoader if enabled
18101810 *
1811 - * If jQuery is not ready load it.
18121811 *
18131812 * @param {String} scriptRequest The requested path or classNames for the scriptLoader
18141813 * @param {Function} callback Function to call once script is loaded
@@ -1817,13 +1816,15 @@
18181817 // Set the base url based scriptLoader availability & type of scriptRequest
18191818 // ( presently script loader only handles "classes" not relative urls:
18201819 var slpath = mw.getScriptLoaderPath();
1821 - // Check if its a relative path name, ( ie does not start with "/" and does not include ://
1822 - var isRelativePath = ( scriptRequest.indexOf('://') == -1 && scriptRequest.indexOf('/') !== 0 )? true : false;
1823 - if( slpath && isRelativePath ) {
 1820+
 1821+ // Check if its a class name, ( ie does not start with "/" and does not include ://
 1822+ var isClassName = ( scriptRequest.indexOf('://') == -1 && scriptRequest.indexOf('/') !== 0 )? true : false;
 1823+
 1824+ if( slpath && isClassName ) {
18241825 url = slpath + '?class=' + scriptRequest;
18251826 }else{
18261827 // Add the mwEmbed path if a relative path request
1827 - url = ( isRelativePath )? mw.getMwEmbedPath() : '';
 1828+ url = ( isClassName ) ? mw.getMwEmbedPath() : '';
18281829 url+= scriptRequest;
18291830 }
18301831
@@ -1835,7 +1836,7 @@
18361837 mw.log( 'mw.getScript: ' + url );
18371838 // If jQuery is available and debug is off load the scirpt via jQuery
18381839 //( will use XHR if on same domain )
1839 - if( mw.isset( 'window.jQuery' ) && mw.getConfig( 'debug' ) === false ) {
 1840+ if( mw.isset( 'window.jQuery' ) && mw.getConfig( 'debug' ) === false ) {
18401841 $j.getScript( url, function(){
18411842 if( callback )
18421843 callback( scriptRequest );
@@ -2126,7 +2127,6 @@
21272128
21282129 // If we're in debug mode, get a fresh unique request key and pass on "debug" param
21292130 if ( mw.parseUri( mwEmbedSrc ).queryKey['debug'] == 'true' ) {
2130 -
21312131 mw.setConfig( 'debug', true );
21322132 var d = new Date();
21332133 req_param += 'urid=' + d.getTime() + '&debug=true';

Status & tagging log