Plugin Directory

Changeset 1723652


Ignore:
Timestamp:
09/02/2017 01:15:13 PM (9 years ago)
Author:
bravokeyl
Message:

Add support for category pages, change splus minus icons and use localStorage instead of jquery.cookie

Location:
admin-collapse-subpages/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • admin-collapse-subpages/trunk/admin_collapse_subpages.php

    r1022208 r1723652  
    22/*
    33    Plugin Name: Admin Collapse Subpages
    4     Plugin URI: http://cloudspier.com/admin-collapse-subpages/
     4    Plugin URI: https://bravokeyl.com/admin-collapse-subpages/
    55    Description: Using this plugin one can easily collapse/expand pages / custom post types with children and grand children.
    66    Author: Alex Chalupka
    7     Author URI: http://cloudspier.com
    8     Version: 2.3
     7    Author URI: https://bravokeyl.com
     8    Version: 2.4
    99    Text Domain: admin-collapse-subpages
    1010    Domain Path: /languages
     
    1616    the Free Software Foundation, either version 2 of the License, or
    1717    any later version.
    18      
     18
    1919    Admin Collapse Subpages is distributed in the hope that it will be useful,
    2020    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2121    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2222    GNU General Public License for more details.
    23      
     23
    2424    You should have received a copy of the GNU General Public License
    2525    along with Admin Collapse Subpages. If not, see http://www.gnu.org/licenses/gpl-2.0.html.
     
    3030
    3131    class Admin_Collapse_Subpages {
    32        
     32
    3333    function __construct() {
    34        
     34
    3535        function acs_textdomain() {
    3636            load_plugin_textdomain( 'admin-collapse-subpages', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
    3737        }
    3838        add_action( 'plugins_loaded', 'acs_textdomain' );
    39        
     39
    4040        function acs_scripts(){
    4141                 global $pagenow;
    4242
    43                     if(isset($_GET['post_type']) ) {                   
    44                         $post_type = $_GET['post_type'];
    45                         if(is_post_type_hierarchical($post_type)) {
    46                             add_filter( 'admin_body_class', 'acs_admin_body_class' );
    47                         }
    48 
    49                         function acs_admin_body_class( $classes )
    50                         {
     43                    if(isset($_GET['post_type']) || isset($_GET['taxonomy'])) {
     44                        if(isset($_GET['post_type'])) {
     45                            $post_type = $_GET['post_type'];
     46                            if(is_post_type_hierarchical($post_type)) {
     47                                add_filter( 'admin_body_class', 'acs_admin_body_class' );
     48                            }
     49                        }
     50                        if(isset($_GET['taxonomy']) && isset($_GET['taxonomy']) == 'category') {
     51                            add_filter( 'admin_body_class', 'acs_admin_body_class' );
     52                        }
     53                        function acs_admin_body_class( $classes ) {
    5154                            $classes .= ' ' .'acs-hier';
    5255                            return $classes;
    5356                        }
     57                    }
    5458
    55                     }
    56                    
    57                     if ( is_admin() && isset($_GET['post_type']) && $pagenow =='edit.php' ) {
    58                        
     59                    if ( is_admin() && ( (isset($_GET['post_type']) && $pagenow =='edit.php') || $pagenow =='edit-tags.php' ) ) {
     60
    5961                            //make sure jquery is loaded
    6062                            wp_enqueue_script('jquery');
    61                            
    62                             //cookie script for saving collapse states
    63                             wp_enqueue_script('jquery-cookie', plugins_url('js/jquery.cookie.js', __FILE__ ), 'jquery', '1.4.0');
    64                            
     63
    6564                            //main collapse pages script
    66                             wp_enqueue_script('acs-js',plugins_url('js/admin_collapse_subpages.js', __FILE__ ), false, '2.0');
    67                        
     65                            wp_enqueue_script('acs-js',plugins_url('js/acs.js', __FILE__ ), array('jquery'), '2.0');
     66
    6867                            //Load Styles
    6968                            wp_enqueue_style('acs-css', plugins_url('css/style.css', __FILE__ ), false, '2.0', 'screen');
     
    8079
    8180    }
    82    
     81
    8382    global $collapsePages;
    8483    $collapsePages = new Admin_Collapse_Subpages();
    8584}
    86 
    87 ?>
  • admin-collapse-subpages/trunk/css/style.css

    r874297 r1723652  
    1 /* simple styles for  +/- links */
    2 
    3 .expand_link a{
    4     display:inline-block;
    5     width: 16px;
    6     height: 16px;
    7     margin:0 0 0 10px;
    8     text-indent: -9999px;
    9     background: url(../images/plus.png) no-repeat top left transparent;
    10     padding:2px;
     1.expand_link a {
     2    display: inline-block;
     3        font-family: dashicons;
     4        font-size: 16px;
     5    line-height: 1;
     6        height: 16px;
     7        width: 16px;
     8    margin: 0 0 0 10px;
     9        vertical-align: middle;
    1110}
    12 
    13 .expand_link a.minus{
    14     background: url(../images/minus.png) no-repeat top left transparent;
     11.expand_link a:before {
     12        content: "\f132";
    1513}
     14.expand_link a.minus:before {
     15    content: "\f460";
     16}
  • admin-collapse-subpages/trunk/js/admin_collapse_subpages.js

    r1022208 r1723652  
    22 * Collapse Sub Pages
    33 */
    4  
     4
    55jQuery().ready(function($){
    66
     
    1010     * Add Expand/Collapse ALL Links to DOM (has to be first for listeners)
    1111     */
    12     jQuery(' .acs-hier .subsubsub').append(links); 
     12    jQuery(' .acs-hier .subsubsub').append(links);
    1313
    1414    /*
    1515     * Initial loading
    1616     */
    17     initial_collapse_work();
    18     reset_listeners();
    19    
     17    //initial_collapse_work();
     18    //reset_listeners();
     19
    2020    /*
    2121     * Does all initial stuff (adding plus/minus buttons, adding top links, perform initial collapse)
    22      */ 
     22     */
    2323    function initial_collapse_work(){
    2424
    2525        /*
    2626         * Loop through to add parent and post-id data
    27          */ 
    28 
    29         jQuery('.pages #the-list tr').each(function(){
    30            
     27         */
     28
     29        jQuery('.pages #the-list tr').each(function(){
     30
    3131            var parent = jQuery(this).find('.post_parent').html();
    3232            var id = jQuery(this).find('[name="post[]"]').attr('value');
    33    
     33
    3434            jQuery(this).attr('data-parent', parent);
    3535            jQuery(this).attr('data-post-id', id);
    3636            jQuery(this).attr('data-collapsed', 0);
    37            
    38         });
    39        
     37
     38        });
     39
    4040        /*
    4141         * Loop through again to add +/- as needed
    4242         */
    4343        jQuery('.pages #the-list tr').each(function(){
    44            
     44
    4545            var id = jQuery(this).find('[name="post[]"]').attr('value');
    46    
    47             if(jQuery('#the-list').find('[data-parent="' + id + '"]').size() > 0)
    48                 jQuery(this).find('.page-title strong').append('<span class="expand_link"><a href="javascript:void(0);" class="minus">[children]</a></span>');         
    49         });
    50        
     46
     47            if(jQuery('#the-list').find('[data-parent="' + id + '"]').length > 0)
     48                jQuery(this).find('.page-title strong').append('<span class="expand_link"><a href="javascript:void(0);" class="minus">[children]</a></span>');
     49        });
     50
    5151        /*
    5252         * Collapse from cookie to start with
    5353         */
    5454        collapse_from_cookie();
    55        
    56        
    57     }
    58    
     55
     56
     57    }
     58
    5959    function reset_listeners()
    6060    {
    6161        /*
    6262         * Called on click, expands and contracts pages by calling functions below
    63          */ 
     63         */
    6464        jQuery('.expand_link').click(function(){
    65            
    66             var row = jQuery(this).closest('tr');       
     65
     66            var row = jQuery(this).closest('tr');
    6767            var post_id = row.attr('data-post-id');
    68                
    69             jQuery(this).children('a').toggleClass('minus');   
    70                
     68
     69            jQuery(this).children('a').toggleClass('minus');
     70
    7171            if(row.attr('data-collapsed') == 0)
    72             {   
     72            {
    7373                //make cookie here
    74                 add_to_cookie(post_id);     
    75            
     74                add_to_cookie(post_id);
     75
    7676                collapse_subpages(post_id);
    7777                row.attr('data-collapsed', 1);
    7878            }
    7979            else
    80             {   
     80            {
    8181                //remove from cookie if exists
    8282                remove_from_cookie(post_id);
    83            
     83
    8484                expand_subpages(post_id);
    8585                row.attr('data-collapsed', 0);
    86             }       
    87         });
    88    
     86            }
     87        });
     88
    8989        /*
    9090         * Called on click when "Quick Update" is used
    91          */     
     91         */
    9292        jQuery('.inline-edit-save .save').click(function(){
    93            
     93
    9494            /*
    95              * delay before reset, allows WordPress to finish reseting rows 
     95             * delay before reset, allows WordPress to finish reseting rows
    9696             * (not ideal, but the "Quick Edit" is a little wonky to begin with)
    9797             */
    9898            setTimeout(function(){
    99            
     99
    100100                //console.log(jQuery('#the-list tr'));
    101        
     101
    102102                jQuery('#the-list tr').show();
    103103                jQuery('.expand_link').remove();
    104                        
     104
    105105                //redo collapses
    106                 initial_collapse_work();   
     106                initial_collapse_work();
    107107                reset_listeners();
    108108
    109             }, 1000); 
    110                    
    111         }); 
    112        
     109            }, 1000);
     110
     111        });
     112
    113113        /*
    114114         * Expand and collapse all links
    115          */     
     115         */
    116116        jQuery('.expand_all_link a').click(function(){
    117117            expand_all();
    118         });         
     118        });
    119119        jQuery('.collapse_all_link a').click(function(){
    120120            collapse_all();
    121         });     
    122     }
    123    
     121        });
     122    }
     123
    124124    function collapse_all()
    125     {   
    126         jQuery('.pages #the-list tr').each(function(){
    127        
    128             var post_id = jQuery(this).attr('data-post-id');       
    129        
     125    {
     126        jQuery('.pages #the-list tr').each(function(){
     127
     128            var post_id = jQuery(this).attr('data-post-id');
     129
    130130            if(jQuery(this).attr('data-collapsed') == 0)
    131             {               
     131            {
    132132                //make cookie here
    133                 add_to_cookie(post_id);     
    134            
     133                add_to_cookie(post_id);
     134
    135135                collapse_subpages(post_id);
    136136                jQuery(this).attr('data-collapsed', 1).find('.expand_link a').toggleClass('minus');
    137                
    138             }                   
    139         });
    140     }   
     137
     138            }
     139        });
     140    }
    141141    function expand_all()
    142142    {
    143143        jQuery('.pages #the-list tr').each(function(){
    144        
    145             var post_id = jQuery(this).attr('data-post-id');       
    146                        
     144
     145            var post_id = jQuery(this).attr('data-post-id');
     146
    147147            if(jQuery(this).attr('data-collapsed') == 1)
    148             {   
     148            {
    149149                //remove from cookie if exists
    150150                remove_from_cookie(post_id);
    151            
     151
    152152                expand_subpages(post_id);
    153153                jQuery(this).attr('data-collapsed', 0).find('.expand_link a').toggleClass('minus');
    154             }   
    155         }); 
    156     }
    157    
     154            }
     155        });
     156    }
     157
    158158    /*
    159159     * Two recursive functions that show/hide the table rows
    160      */ 
     160     */
    161161    function collapse_subpages(parent_id)
    162     {       
     162    {
    163163        jQuery('#the-list').find('[data-parent="' + parent_id + '"]').each(function(){
    164            
     164
    165165            jQuery(this).hide();
    166            
    167             collapse_subpages(jQuery(this).attr('data-post-id'));       
    168         });
    169     }   
     166
     167            collapse_subpages(jQuery(this).attr('data-post-id'));
     168        });
     169    }
    170170    function expand_subpages(parent_id)
    171     {       
     171    {
    172172        jQuery('#the-list').find('[data-parent="' + parent_id + '"]').each(function(){
    173            
     173
    174174            jQuery(this).show();
    175            
     175
    176176            //does not unhide rows if group was previously hidden
    177177            if(jQuery(this).attr('data-collapsed') == 0)
    178178                expand_subpages(jQuery(this).attr('data-post-id'));
    179179        });
    180     }   
     180    }
    181181
    182182    /*
    183183     * Add value to cookie
    184      */ 
     184     */
    185185     function add_to_cookie(row_id)
    186186     {
    187187        var cookie = $.cookie('collapsed');
    188188        var values;
    189        
    190         if(cookie){     
     189
     190        if(cookie){
    191191            values = cookie.split(',');
    192192            if(jQuery.inArray(row_id, values) == -1)
    193                 values.push(row_id);   
    194         }else{         
    195             values = new Array(row_id);     
    196         }       
    197        
     193                values.push(row_id);
     194        }else{
     195            values = new Array(row_id);
     196        }
     197
    198198        $.cookie('collapsed',values);
    199        
     199
    200200     }
    201201
    202202    /*
    203203     * Remove value from cookie
    204      */     
     204     */
    205205     function remove_from_cookie(row_id)
    206206     {
    207207        var cookie = $.cookie('collapsed');
    208208        var values;
    209        
    210         if(cookie){     
     209
     210        if(cookie){
    211211            values = cookie.split(',');
    212212
    213213            values = jQuery.grep(values, function(value) {
    214214                return value != row_id;
    215             }); 
    216            
     215            });
     216
    217217            $.cookie('collapsed',values);
    218                    
    219         }     
     218
     219        }
    220220     }
    221      
     221
    222222    /*
    223223     * Read cookie and expand pages as needed
    224      */         
     224     */
    225225    function collapse_from_cookie()
    226226    {
    227227        var cookie = $.cookie('collapsed');
    228228        var values;
    229        
    230         if(cookie){     
     229
     230        if(cookie){
    231231            values = cookie.split(',');
    232232
    233233            jQuery.each(values,function(index, value){
    234234                jQuery('#the-list').find('[data-post-id="' + value + '"]').attr('data-collapsed', 1).find('.expand_link a').toggleClass('minus');
    235             }); 
     235            });
    236236
    237237            jQuery.each(values,function(index, value){
    238238                collapse_subpages(value);
    239             });         
    240         }   
     239            });
     240        }
    241241    }
    242242
  • admin-collapse-subpages/trunk/readme.txt

    r1532930 r1723652  
    11=== Admin Collapse Subpages ===
    2 Contributors: lupka , bravokeyl
    3 Donate link: http://alexchalupka.com/donate
     2Contributors: bravokeyl, lupka
     3Donate link: https://bravokeyl.com/contact/
    44Tags: page, post, links,pages, admin , link ,plugin, random, posts, widget, categories, date, date range, timeframe, excerpt, randomize, sidebar, category
    5 Requires at least: 3.0
    6 Tested up to: 4.6.1
     5Requires at least: 4.6
     6Tested up to: 4.8.1
    77Stable tag: trunk
    88License: GPLv2 or later
     
    1515Simple plugin that allows you to collapse subpages in the Pages admin list also for custom post types that are heirarchial. Especially helpful if you have a ton of pages /cpt's with heiararchial set to true. It uses a cookie to save the expand/collapse status of your pages.
    1616
    17 This is loosely based on Collapse Sub-Pages by Dan Dietz, which broke with the 3.0 upgrade due to UI changes and hasn't been updated. I've had to rewrite the jQuery to make it work with 3.x versions. 
     17This is loosely based on Collapse Sub-Pages by Dan Dietz, which broke with the 3.0 upgrade due to UI changes and hasn't been updated. I've had to rewrite the jQuery to make it work with 3.x versions.
    1818
    1919Because this is a jQuery, it's possible that they could make additional changes that would break it. I'll do my best to stay on top of it, but let me know if it stops working.
     
    2323From version 2.3 our plugin supports internationalization, which means you can have plugin in your specified language.
    2424
    25 It's currently available in US English ,UK Englih, Chinese, Telugu , Serbian.
     25It's currently available in US English ,UK English, Chinese, Telugu , Serbian.
    2626
    2727<h3>Support us by Translating</h3>
     
    5959== Changelog ==
    6060
    61 = 1.0 =
    62 * Initial version of the plugin
     61= 2.4 =
     62
     63** New
     64
     65* Added support for category pages
     66
     67** Changed
     68
     69* Used localStorage instead of jquery.cookie
     70* Used dashicons for plus/minus instead of images
     71
     72= 2.1 =
     73* Added support custom post types which are hierarchical
    6374
    6475= 2.0 =
    6576* Fixed bug - Adding expand/collapse links to all list tables
    6677* Updated jquery.cookie.js to 1.4.0
    67 * Enhanced loading of scripts and styles
    68 = 2.1 =
    69 * Added support custom post types which are hieararchial
     78* Enhanced loading of scripts and styles
     79
     80= 1.0 =
     81* Initial version of the plugin
     82
    7083== Upgrade Notice ==
    7184
    72 = 1.0 =
    73 * N/A
    74 = 2.0 =
    75 * Enjoy !!
    76 = 2.1 =
    77 * Added support custom post types which are hieararchial
    78 = 2.1 =
    79 * Added support custom post types which are hieararchial
    80 = 2.3 =
    81 * Internationalizing the plugin
     85* Nothing to worry
Note: See TracChangeset for help on using the changeset viewer.