Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js |
— | — | @@ -847,6 +847,34 @@ |
848 | 848 | }); |
849 | 849 | var $providerSelection = $j( '<ul />' ).addClass( "ui-provider-selection" ); |
850 | 850 | |
| 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 | + |
851 | 879 | // Add enabled search providers. |
852 | 880 | for ( var providerName in this.content_providers ) { |
853 | 881 | var content_providers = this.content_providers; |
— | — | @@ -876,26 +904,6 @@ |
877 | 905 | } |
878 | 906 | } |
879 | 907 | |
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 | | - |
900 | 908 | $searchForm.append( $providerSelection ); |
901 | 909 | $searchForm.append( $searchBox ); |
902 | 910 | $searchForm.append( $searchButton ); |
— | — | @@ -1057,6 +1065,12 @@ |
1058 | 1066 | } |
1059 | 1067 | } |
1060 | 1068 | |
| 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 | + |
1061 | 1075 | // Set the content to loading while we do the search: |
1062 | 1076 | $j( '#rsd_results_container' ).html( mw.loading_spinner() ); |
1063 | 1077 | |
— | — | @@ -1190,14 +1204,14 @@ |
1191 | 1205 | _this.loadSearchLib( provider, function( provider ) { |
1192 | 1206 | var d = new Date(); |
1193 | 1207 | 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 ){ |
1196 | 1210 | //if( resultStatus == 'ok' ){ |
1197 | 1211 | _this.showResults(); |
1198 | 1212 | //}else{ |
1199 | 1213 | // _this.showFailure( resultStatus ) |
1200 | | - //} |
1201 | | - }); |
| 1214 | + //} |
| 1215 | + }); |
1202 | 1216 | |
1203 | 1217 | // Set a timeout of 20 seconds |
1204 | 1218 | setTimeout(function(){ |
— | — | @@ -1577,44 +1591,36 @@ |
1578 | 1592 | gM( 'rsd_resource_edit', resource.title ); |
1579 | 1593 | $j( _this.target_container ).dialog( 'option', 'title', dialogTitle ); |
1580 | 1594 | 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 | | - } ); |
1594 | 1595 | |
1595 | 1596 | // Try and keep aspect ratio for the thumbnail that we clicked: |
1596 | 1597 | var imageRatio = null; |
1597 | 1598 | try { |
1598 | 1599 | imageRatio = $j( rsdElement ).get(0).height / $j( rsdElement ).get(0).width; |
1599 | 1600 | } 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' ) ; |
1601 | 1602 | } |
1602 | 1603 | if ( !imageRatio ) { |
1603 | 1604 | var imageRatio = 1; // set ratio to 1 if tRatio did not work. |
1604 | 1605 | } |
1605 | 1606 | |
| 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 | + |
1606 | 1622 | mw.log( 'Set from ' + imageRatio + ' to init thumbimage to ' + |
1607 | 1623 | 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 | + |
1619 | 1625 | if ( mediaType == 'image' ) { |
1620 | 1626 | _this.loadHighQualityImage( |
1621 | 1627 | resource, |