2322 * @param {string=} response.responseText Optional. Request response as text. |
2331 * @param {string=} response.responseText Optional. Request response as text. |
2323 * @param {string} action Type of action the response is referring to. Can be 'delete', |
2332 * @param {string} action Type of action the response is referring to. Can be 'delete', |
2324 * 'update' or 'install'. |
2333 * 'update' or 'install'. |
2325 */ |
2334 */ |
2326 wp.updates.isValidResponse = function( response, action ) { |
2335 wp.updates.isValidResponse = function( response, action ) { |
2327 var error = __( 'Something went wrong.' ), |
2336 var error = __( 'An error occurred during the update process. Please try again.' ), |
2328 errorMessage; |
2337 errorMessage; |
2329 |
2338 |
2330 // Make sure the response is a valid data object and not a Promise object. |
2339 // Make sure the response is a valid data object and not a Promise object. |
2331 if ( _.isObject( response ) && ! _.isFunction( response.always ) ) { |
2340 if ( _.isObject( response ) && ! _.isFunction( response.always ) ) { |
2332 return true; |
2341 return true; |
2821 return; |
2830 return; |
2822 } |
2831 } |
2823 |
2832 |
2824 // Bail if there were no items selected. |
2833 // Bail if there were no items selected. |
2825 if ( ! itemsSelected.length ) { |
2834 if ( ! itemsSelected.length ) { |
2826 event.preventDefault(); |
2835 bulkAction = false; |
2827 $( 'html, body' ).animate( { scrollTop: 0 } ); |
|
2828 |
|
2829 return wp.updates.addAdminNotice( { |
|
2830 id: 'no-items-selected', |
|
2831 className: 'notice-error is-dismissible', |
|
2832 message: __( 'Please select at least one item to perform this action on.' ) |
|
2833 } ); |
|
2834 } |
2836 } |
2835 |
2837 |
2836 // Determine the type of request we're dealing with. |
2838 // Determine the type of request we're dealing with. |
2837 switch ( bulkAction ) { |
2839 switch ( bulkAction ) { |
2838 case 'update-selected': |
2840 case 'update-selected': |
2975 |
2977 |
2976 if ( $pluginInstallSearch.length ) { |
2978 if ( $pluginInstallSearch.length ) { |
2977 $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' ); |
2979 $pluginInstallSearch.attr( 'aria-describedby', 'live-search-desc' ); |
2978 } |
2980 } |
2979 |
2981 |
|
2982 // Track the previous search string length. |
|
2983 var previousSearchStringLength = 0; |
|
2984 wp.updates.shouldSearch = function( searchStringLength ) { |
|
2985 var shouldSearch = searchStringLength >= wp.updates.searchMinCharacters || |
|
2986 previousSearchStringLength > wp.updates.searchMinCharacters; |
|
2987 previousSearchStringLength = searchStringLength; |
|
2988 return shouldSearch; |
|
2989 }; |
|
2990 |
2980 /** |
2991 /** |
2981 * Handles changes to the plugin search box on the new-plugin page, |
2992 * Handles changes to the plugin search box on the new-plugin page, |
2982 * searching the repository dynamically. |
2993 * searching the repository dynamically. |
2983 * |
2994 * |
2984 * @since 4.6.0 |
2995 * @since 4.6.0 |
2985 */ |
2996 */ |
2986 $pluginInstallSearch.on( 'keyup input', _.debounce( function( event, eventtype ) { |
2997 $pluginInstallSearch.on( 'keyup input', _.debounce( function( event, eventtype ) { |
2987 var $searchTab = $( '.plugin-install-search' ), data, searchLocation; |
2998 var $searchTab = $( '.plugin-install-search' ), data, searchLocation, |
|
2999 searchStringLength = $pluginInstallSearch.val().length; |
2988 |
3000 |
2989 data = { |
3001 data = { |
2990 _ajax_nonce: wp.updates.ajaxNonce, |
3002 _ajax_nonce: wp.updates.ajaxNonce, |
2991 s: encodeURIComponent( event.target.value ), |
3003 s: encodeURIComponent( event.target.value ), |
2992 tab: 'search', |
3004 tab: 'search', |
2993 type: $( '#typeselector' ).val(), |
3005 type: $( '#typeselector' ).val(), |
2994 pagenow: pagenow |
3006 pagenow: pagenow |
2995 }; |
3007 }; |
2996 searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ); |
3008 searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ); |
|
3009 |
|
3010 // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. |
|
3011 if ( wp.updates.shouldSearch( searchStringLength ) ) { |
|
3012 $pluginInstallSearch.attr( 'autocomplete', 'off' ); |
|
3013 } else { |
|
3014 $pluginInstallSearch.attr( 'autocomplete', 'on' ); |
|
3015 return; |
|
3016 } |
2997 |
3017 |
2998 // Clear on escape. |
3018 // Clear on escape. |
2999 if ( 'keyup' === event.type && 27 === event.which ) { |
3019 if ( 'keyup' === event.type && 27 === event.which ) { |
3000 event.target.value = ''; |
3020 event.target.value = ''; |
3001 } |
3021 } |
3067 _ajax_nonce: wp.updates.ajaxNonce, |
3088 _ajax_nonce: wp.updates.ajaxNonce, |
3068 s: encodeURIComponent( event.target.value ), |
3089 s: encodeURIComponent( event.target.value ), |
3069 pagenow: pagenow, |
3090 pagenow: pagenow, |
3070 plugin_status: 'all' |
3091 plugin_status: 'all' |
3071 }, |
3092 }, |
3072 queryArgs; |
3093 queryArgs, |
|
3094 searchStringLength = $pluginSearch.val().length; |
|
3095 |
|
3096 // Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. |
|
3097 if ( wp.updates.shouldSearch( searchStringLength ) ) { |
|
3098 $pluginSearch.attr( 'autocomplete', 'off' ); |
|
3099 } else { |
|
3100 $pluginSearch.attr( 'autocomplete', 'on' ); |
|
3101 return; |
|
3102 } |
3073 |
3103 |
3074 // Clear on escape. |
3104 // Clear on escape. |
3075 if ( 'keyup' === event.type && 27 === event.which ) { |
3105 if ( 'keyup' === event.type && 27 === event.which ) { |
3076 event.target.value = ''; |
3106 event.target.value = ''; |
3077 } |
3107 } |