WordPress.org

Make WordPress Core

Ticket #19815: 19815.4.diff

File 19815.4.diff, 8.2 KB (added by helenyhou, 17 months ago)

Enables use on theme-install.php

  • wp-admin/includes/class-wp-theme-install-list-table.php

     
    99 */ 
    1010class WP_Theme_Install_List_Table extends WP_List_Table { 
    1111 
     12        function __construct() { 
     13                parent::__construct( array( 
     14                        'ajax' => true, 
     15                ) ); 
     16        } 
     17 
    1218        function ajax_user_can() { 
    1319                return current_user_can('install_themes'); 
    1420        } 
     
    128134 
    129135        function display() { 
    130136 
    131                 // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 
     137                wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 
    132138?> 
    133139                <div class="tablenav top themes"> 
    134140                        <div class="alignleft actions"> 
  • wp-admin/includes/class-wp-themes-list-table.php

     
    1111 
    1212        var $search = array(); 
    1313        var $features = array(); 
     14         
     15        function __construct() { 
     16                parent::__construct( array( 
     17                        'ajax' => true, 
     18                ) ); 
     19        } 
    1420 
    1521        function ajax_user_can() { 
    1622                // Do not check edit_theme_options here. AJAX calls for available themes require switch_themes. 
     
    101107        } 
    102108 
    103109        function display() { 
    104                 // wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 
     110                wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); 
    105111?> 
    106112                <?php $this->tablenav( 'top' ); ?> 
    107113 
  • wp-admin/theme-install.php

     
    3434add_thickbox(); 
    3535wp_enqueue_script( 'theme-preview' ); 
    3636 
     37if ( 'search' == $tab ) 
     38        wp_enqueue_script( 'wp-themes' ); 
     39 
    3740$body_id = $tab; 
    3841 
    3942do_action('install_themes_pre_' . $tab); //Used to override the general interface, Eg, install or theme information. 
  • wp-admin/themes.php

     
    6969add_thickbox(); 
    7070wp_enqueue_script( 'theme-preview' ); 
    7171wp_enqueue_script( 'theme' ); 
     72wp_enqueue_script( 'wp-themes' ); 
    7273 
    7374endif; 
    7475 
  • wp-includes/js/wp-themes.dev.js

     
     1var wpThemes; 
     2 
     3(function($){ 
     4        var inputs = {}, Query; 
     5 
     6        wpThemes = { 
     7                timeToTriggerQuery: 150, 
     8                minQueryAJAXDuration: 200, 
     9                outListBottomThreshold: 200, 
     10                noMoreResults: false, 
     11                 
     12                init : function() { 
     13                        inputs.nonce = $('#_ajax_fetch_list_nonce').val(); 
     14         
     15                        // Parse Query 
     16                        inputs.queryString = window.location.search;                     
     17                        inputs.queryArray = wpThemes.parseQuery( inputs.queryString.substring( 1 ) ); 
     18 
     19                        // Handle Inputs from Query 
     20                        inputs.search = inputs.queryArray['s']; 
     21                        inputs.features = inputs.queryArray['features']; 
     22                        inputs.startPage = parseInt( inputs.queryArray['paged'] ); 
     23                        inputs.tab = inputs.queryArray['tab']; 
     24                        inputs.type = inputs.queryArray['type']; 
     25 
     26                        if ( isNaN( inputs.startPage ) ) 
     27                                inputs.startPage = 2; 
     28                        else 
     29                                inputs.startPage++; 
     30 
     31                        // FIXME: Debug Features Array 
     32                        // console.log("Features:" + inputs.features); 
     33 
     34                        // Link to output and start polling 
     35                        inputs.outList = $('#availablethemes'); 
     36 
     37                        // Generate Query 
     38                        wpThemes.query = new Query(); 
     39 
     40                        // Start Polling 
     41                        $(window).scroll( function(){ wpThemes.maybeLoad(); }); 
     42                }, 
     43                delayedCallback : function( func, delay ) { 
     44                        var timeoutTriggered, funcTriggered, funcArgs, funcContext; 
     45 
     46                        if ( ! delay ) 
     47                                return func; 
     48 
     49                        setTimeout( function() { 
     50                                if ( funcTriggered ) 
     51                                        return func.apply( funcContext, funcArgs ); 
     52                                // Otherwise, wait. 
     53                                timeoutTriggered = true; 
     54                        }, delay); 
     55 
     56                        return function() { 
     57                                if ( timeoutTriggered ) 
     58                                        return func.apply( this, arguments ); 
     59                                // Otherwise, wait. 
     60                                funcArgs = arguments; 
     61                                funcContext = this; 
     62                                funcTriggered = true; 
     63                        }; 
     64                }, 
     65                ajax: function( callback ) { 
     66                        var self = this, 
     67                                response = wpThemes.delayedCallback( function( results, params ) { 
     68                                        self.process( results, params ); 
     69                                        if ( callback ) 
     70                                                callback( results, params ); 
     71                                }, wpThemes.minQueryAJAXDuration ); 
     72 
     73                        this.query.ajax( response ); 
     74                }, 
     75                process: function( results, params ) { 
     76                        // If no Results, for now, mark as no Matches, and bail. 
     77                        // Alternately: inputs.outList.append(wpThemesL10n.noMatchesFound); 
     78                        if ( ( results === undefined ) || 
     79                                 ( results.rows.indexOf( "no-items" ) != -1 ) ) { 
     80                                this.noMoreResults = true; 
     81                        } else { 
     82                                inputs.outList.append(results.rows); 
     83                        } 
     84                }, 
     85                maybeLoad: function() { 
     86                        var self = this, 
     87                                el = $(document), 
     88                                bottom = el.scrollTop() + $(window).innerHeight(); 
     89 
     90                        /* // FIXME: Debug scroll trigger. 
     91                        console.log('scrollTop:'+ el.scrollTop() +  
     92                                '; scrollBottom:' + bottom + 
     93                                '; height:' + el.height() + 
     94                                '; checkVal:' + (el.height() - wpThemes.outListBottomThreshold)); 
     95                        */ 
     96 
     97                        if ( this.noMoreResults || 
     98                                 !this.query.ready() ||  
     99                                 ( bottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) ) 
     100                                return; 
     101 
     102                        setTimeout( function() { 
     103                                var newTop = el.scrollTop(), 
     104                                        newBottom = newTop + $(window).innerHeight(); 
     105 
     106                                if ( !self.query.ready() || 
     107                                         ( newBottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) ) 
     108                                        return; 
     109 
     110                                /* FIXME: Create/Add Spinner. 
     111                                self.waiting.show(); // Show Spinner 
     112                                el.scrollTop( newTop + self.waiting.outerHeight() ); // Scroll down? 
     113                                self.ajax( function() { self.waiting.hide(); }); // Hide Spinner 
     114                                */ 
     115                                self.ajax(); 
     116                        }, wpThemes.timeToTriggerQuery ); 
     117                }, 
     118                parseQuery: function( query ) { 
     119                        var Params = {}; 
     120                        if ( ! query ) {return Params;}// return empty object 
     121                        var Pairs = query.split(/[;&]/); 
     122                        for ( var i = 0; i < Pairs.length; i++ ) { 
     123                                var KeyVal = Pairs[i].split('='); 
     124                                if ( ! KeyVal || KeyVal.length != 2 ) {continue;} 
     125                                var key = unescape( KeyVal[0] ); 
     126                                var val = unescape( KeyVal[1] ); 
     127                                val = val.replace(/\+/g, ' '); 
     128                                key = key.replace(/\[.*\]$/g, ''); 
     129         
     130                                if ( Params[key] === undefined ) { 
     131                                        Params[key] = val; 
     132                                } else { 
     133                                        var oldVal = Params[key]; 
     134                                        if ( ! jQuery.isArray( Params[key] ) ) 
     135                                                Params[key] = new Array( oldVal, val ); 
     136                                        else 
     137                                                Params[key].push( val ); 
     138                                } 
     139                        } 
     140                        return Params; 
     141                } 
     142        } 
     143 
     144        Query = function() { 
     145                this.failedRequest = false; 
     146                this.querying = false; 
     147                this.page = inputs.startPage; 
     148        } 
     149         
     150        $.extend( Query.prototype, { 
     151                ready: function() { 
     152                        return !( this.querying || this.failedRequest ); 
     153                }, 
     154                ajax: function( callback ) { 
     155                        var self = this, 
     156                        query = { 
     157                                action: 'fetch-list', 
     158                                paged: this.page, 
     159                                s: inputs.search, 
     160                                'features[]': inputs.features, 
     161                                'list_args': list_args, 
     162                                'tab': inputs.tab, 
     163                                'type': inputs.type, 
     164                                '_ajax_fetch_list_nonce': inputs.nonce 
     165                        }; 
     166 
     167                        this.querying = true; 
     168                        $.get( ajaxurl, query, function(r) { 
     169                                self.page++; 
     170                                self.querying = false; 
     171                                self.failedRequest = !r; 
     172                                callback( r, query ); 
     173                        }, "json" ); 
     174                } 
     175        }); 
     176 
     177        $(document).ready( wpThemes.init ); 
     178 
     179})(jQuery); 
  • wp-includes/script-loader.php

     
    271271                'noMatchesFound' => __('No matches found.') 
    272272        ) ); 
    273273 
     274        $scripts->add( 'wp-themes', "/wp-includes/js/wp-themes$suffix.js", array( 'jquery' ), false, 1 ); 
     275        $scripts->localize( 'wp-themes', 'wpThemesL10n', array( 
     276                'noMatchesFound' => __('No matches found.') 
     277        ) );         
     278 
    274279        $scripts->add( 'wpdialogs', "/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), false, 1 ); 
    275280 
    276281        $scripts->add( 'wpdialogs-popup', "/wp-includes/js/tinymce/plugins/wpdialogs/js/popup$suffix.js", array( 'wpdialogs' ), false, 1 );