r61247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61246‎ | r61247 | r61248 >
Date:13:53, 19 January 2010
Author:shmichael
Status:ok (Comments)
Tags:
Comment:
* Basic handling for empty search query
* More delicate transition into image editor
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -847,6 +847,34 @@
848848 });
849849 var $providerSelection = $j( '<ul />' ).addClass( "ui-provider-selection" );
850850
 851+ var $searchButton = $j.button({
 852+ icon_id: 'search',
 853+ text: gM( 'mwe-media_search' ) })
 854+ .addClass( 'rsd_search_button' )
 855+ .buttonHover()
 856+ .click(function (){
 857+ _this.showSearchTab( _this.current_provider, true );
 858+ });
 859+ var $searchBox = $j( '<input />' ).addClass( 'ui-widget-content ui-corner-all' ).attr({
 860+ type: "text",
 861+ tabindex: 1,
 862+ value: this.getDefaultQuery(),
 863+ maxlength: 512,
 864+ id: "rsd_q",
 865+ name: "rsd_q",
 866+ size: 20,
 867+ autocomplete: "off"
 868+ })
 869+ // Prevent searching for empty input.
 870+ .keyup(function () {
 871+ if ( $searchBox.val().length == 0 ) {
 872+ $searchButton.addClass('ui-button-disabled');
 873+ }
 874+ else {
 875+ $searchButton.removeClass("ui-button-disabled");
 876+ }
 877+ });
 878+
851879 // Add enabled search providers.
852880 for ( var providerName in this.content_providers ) {
853881 var content_providers = this.content_providers;
@@ -876,26 +904,6 @@
877905 }
878906 }
879907
880 - var $searchBox = $j( '<input />' ).addClass( 'ui-widget-content ui-corner-all' ).attr({
881 - type: "text",
882 - tabindex: 1,
883 - value: this.getDefaultQuery(),
884 - maxlength: 512,
885 - id: "rsd_q",
886 - name: "rsd_q",
887 - size: 20,
888 - autocomplete: "off"
889 - });
890 - var $searchButton = $j.button({
891 - icon_id: 'search',
892 - text: gM('mwe-media_search') })
893 - .addClass( 'rsd_search_button' )
894 - .buttonHover()
895 - .click(function (){
896 - //TODO: Add search provider call.
897 - _this.showSearchTab( _this.current_provider, true );
898 - });
899 -
900908 $searchForm.append( $providerSelection );
901909 $searchForm.append( $searchBox );
902910 $searchForm.append( $searchButton );
@@ -1057,6 +1065,12 @@
10581066 }
10591067 }
10601068
 1069+ if ( $j ( '#rsd_q' ).val().length == 0 ) {
 1070+ $j( '#rsd_results_container' ).empty()
 1071+ $j( '#rsd_results_container' ).text( 'Please insert a search string above.' );
 1072+ return;
 1073+ }
 1074+
10611075 // Set the content to loading while we do the search:
10621076 $j( '#rsd_results_container' ).html( mw.loading_spinner() );
10631077
@@ -1190,14 +1204,14 @@
11911205 _this.loadSearchLib( provider, function( provider ) {
11921206 var d = new Date();
11931207 var searchTime = d.getMilliseconds();
1194 - // Do the search:
1195 - provider.sObj.getSearchResults( $j( '#rsd_q' ).val() , function( resultStatus ){
 1208+ // Do the search:
 1209+ provider.sObj.getSearchResults( $j( '#rsd_q' ).val() , function( resultStatus ){
11961210 //if( resultStatus == 'ok' ){
11971211 _this.showResults();
11981212 //}else{
11991213 // _this.showFailure( resultStatus )
1200 - //}
1201 - });
 1214+ //}
 1215+ });
12021216
12031217 // Set a timeout of 20 seconds
12041218 setTimeout(function(){
@@ -1577,44 +1591,36 @@
15781592 gM( 'rsd_resource_edit', resource.title );
15791593 $j( _this.target_container ).dialog( 'option', 'title', dialogTitle );
15801594 mw.log( 'did append to: ' + _this.target_container );
1581 -
1582 - // Left side holds the image right size the controls
1583 - $j( rsdElement )
1584 - .clone()
1585 - .attr( 'id', 'rsd_edit_img' )
1586 - .appendTo( '#clip_edit_disp' )
1587 - .css( {
1588 - 'position':'absolute',
1589 - 'top':'40%',
1590 - 'left':'20%',
1591 - 'cursor':'default',
1592 - 'opacity':0
1593 - } );
15941595
15951596 // Try and keep aspect ratio for the thumbnail that we clicked:
15961597 var imageRatio = null;
15971598 try {
15981599 imageRatio = $j( rsdElement ).get(0).height / $j( rsdElement ).get(0).width;
15991600 } catch( e ) {
1600 - mw.log( 'Errro: browser could not read height or width attribute' ) ;
 1601+ mw.log( 'Error: browser could not read height or width attribute' ) ;
16011602 }
16021603 if ( !imageRatio ) {
16031604 var imageRatio = 1; // set ratio to 1 if tRatio did not work.
16041605 }
16051606
 1607+ $j( rsdElement )
 1608+ .clone()
 1609+ .attr( { id : 'rsd_edit_img' } )
 1610+ .appendTo( '#clip_edit_disp' )
 1611+ .css( {
 1612+ 'position':'absolute',
 1613+ 'top': '5px',
 1614+ 'left': '5px',
 1615+ 'cursor': 'default',
 1616+ 'opacity': 1,
 1617+ 'width': maxWidth + 'px',
 1618+ 'height': parseInt( imageRatio * maxWidth ) + 'px'
 1619+ } );
 1620+
 1621+
16061622 mw.log( 'Set from ' + imageRatio + ' to init thumbimage to ' +
16071623 maxWidth + ' x ' + parseInt( imageRatio * maxWidth ) );
1608 - // Scale up image and to swap with high res version
1609 - $j( '#rsd_edit_img' ).animate(
1610 - {
1611 - 'opacity': 1,
1612 - 'top': '5px',
1613 - 'left': '5px',
1614 - 'width': maxWidth + 'px',
1615 - 'height': parseInt( imageRatio * maxWidth ) + 'px'
1616 - },
1617 - "slow" ); // Do it slow to give it a chance to finish loading the high quality version
1618 -
 1624+
16191625 if ( mediaType == 'image' ) {
16201626 _this.loadHighQualityImage(
16211627 resource,

Comments

#Comment by Mdale (talk | contribs)   20:33, 19 January 2010

In terms of "More delicate transition into image editor" perhaps a fade in or something to not display the low resolution thumbnail so large for so much time? Or you could just put a spinner and fade in high res once its ready?

#Comment by Spamsplace (talk | contribs)   22:30, 19 January 2010

I think the spinner is a favorable option. I'll get to it next Sunday, and hopefully add some extra design by yaron, the web designer over here.

Status & tagging log