WordPress.org

Plugin Directory

Changeset 1657399


Ignore:
Timestamp:
05/15/17 05:08:42 (6 weeks ago)
Author:
aaronrutley
Message:

version 1.5.0

Location:
advanced-custom-field-repeater-collapser/trunk
Files:
12 added
6 edited

Legend:

Unmodified
Added
Removed
  • advanced-custom-field-repeater-collapser/trunk/acf_repeater_collapser.php

    r1266721 r1657399  
    11<?php 
    22/** 
    3  * Plugin Name: Advanced Custom Fields Repeater Collapser 
     3 * Plugin Name: Advanced Custom Fields: Repeater Collapser 
    44 * Plugin URI:  https://github.com/mrwweb/ACF-Repeater-Collapser 
    55 * Description: Provides a way to collapse and expand repeater field instances in order to enable better sorting. 
    6  * Version:     1.4.3 
    7  * Author:      Mark Root-Wiley 
    8  * Author URI:  http://mrwweb.com 
     6 * Version:     1.5.0 
     7 * Author:      Aaron Rutley 
     8 * Author URI:  https://hookturn.io 
    99 * Text Domain: advanced-custom-field-repeater-collapser 
    1010 */ 
    1111 
    12 define( 'ACF_REPEATER_COLLAPSER_VERSION', '1.4.3' ); 
     12define( 'ACF_REPEATER_COLLAPSER_VERSION', '1.5.0' ); 
    1313 
    1414/** 
     
    3535    $uri     = plugin_dir_url( __FILE__ ); 
    3636    $version = ACF_REPEATER_COLLAPSER_VERSION; 
    37     $prefix  = version_compare( $acf_version, '5.0', '>=' ) ? 'acf5' : 'acf4'; 
     37    $prefix  = version_compare( $acf_version, '5.3.1', '>=' ) ? 'acf5' : 'acf4'; 
    3838 
    3939    wp_enqueue_script( 
     
    4848        'expandRows' => esc_html__( 'Expand All Rows', 'advanced-custom-field-repeater-collapser' ), 
    4949        'expandRow' => esc_html__( 'Expand Row', 'advanced-custom-field-repeater-collapser' ), 
     50        'expandAll' => esc_html__( 'Expand All', 'advanced-custom-field-repeater-collapser' ), 
     51        'collapseAll' => esc_html__( 'Collapse All', 'advanced-custom-field-repeater-collapser' ), 
    5052    ) ); 
    5153 
     
    5759    ); 
    5860} 
    59  
    60 add_action( 'plugins_loaded', 'acf_repeater_collapser_acf5_compat' ); 
    61 function acf_repeater_collapser_acf5_compat() { 
    62     if( ! class_exists( 'acf' ) ) { 
    63         return; 
    64     } 
    65      
    66     $acf_version = acf()->settings['version']; 
    67     if( version_compare( $acf_version, '5.0', '>=' ) ) { 
    68         add_filter( 'acf/compatibility/field_wrapper_class', '__return_true' ); 
    69     } 
    70 } 
  • advanced-custom-field-repeater-collapser/trunk/css/acf4_repeater_collapser_admin.css

    r966566 r1657399  
    3737} 
    3838 
    39 .field-repeater-toggle::before { 
    40     content: "\f506"; 
     39.button.field-repeater-toggle-single { 
    4140    display: inline; 
    4241    -webkit-font-smoothing: antialiased; 
     
    4443    vertical-align: text-bottom; 
    4544    color: #777; 
     45    background: url(../images/icon--collapse.svg); 
     46    background-size: 10px; 
     47    width: 20px; 
     48    height: 20px; 
     49    background-repeat: no-repeat; 
     50    background-position: center center; 
     51    box-shadow: none; 
     52    border:1px solid #d1d1d1; 
     53} 
     54 
     55.button.field-repeater-toggle-single:focus {  
     56    background: url(../images/icon--collapse.svg) center center no-repeat #FFF; 
     57    background-size: 10px; 
     58    box-shadow: none; 
     59    border:1px solid #d1d1d1; 
    4660} 
    4761.field-repeater-toggle-all::before { 
    4862    margin: 3px 5px 0 0; 
    4963} 
     64.button.field-repeater-toggle-single:hover { 
     65    border:1px solid #d1d1d1; 
     66    background: url(../images/icon--collapse.svg) center center no-repeat #FFF; 
     67    background-size: 10px; 
     68} 
    5069 
    51 .collapsed-repeater .field-repeater-toggle-all::before, 
    52 .collapsed-row .field-repeater-toggle-single::before { 
    53     content: "\f211"; 
     70.layout.collapsed-row .button.field-repeater-toggle-single, 
     71.row.collapsed-row .button.field-repeater-toggle-single {  
     72    background: url(../images/icon--expand.svg) center center no-repeat; 
     73    background-size: 10px; 
    5474} 
     75 
     76.layout.collapsed-row .button.field-repeater-toggle-single:hover, 
     77.row.collapsed-row .button.field-repeater-toggle-single:hover {  
     78    border:1px solid #d1d1d1; 
     79    background: url(../images/icon--expand.svg) center center no-repeat #FFF; 
     80    background-size: 10px; 
     81} 
     82 
     83 
     84 
     85 
    5586 
    5687.acf_flexible_content, 
     
    83114    background: linear-gradient( rgba( 244, 244, 244, .2 ), rgba( 244, 244, 244, 1 ) ); 
    84115} 
     116 
     117/* 2017 button styles */ 
     118.button.field-repeater-toggle-all {  
     119    box-sizing: border-box; 
     120    position: relative; 
     121    border:1px solid #d1d1d1; 
     122    background:#FFF; 
     123    color:#e5e5e5; 
     124    float:right;  
     125    font-weight:normal; 
     126    color:#6a6f74; 
     127    padding:1px 10px 1px 30px; 
     128    text-align: right; 
     129    min-width: 114px; 
     130    transition: all 100ms ease-in-out; 
     131    background-color: rgba(249, 249, 249, 0.50); 
     132    user-select: none; 
     133    box-shadow: none; 
     134} 
     135 
     136.button.field-repeater-toggle-all:before {  
     137    position: absolute; 
     138    top:0; 
     139    left:3px; 
     140    content: ""; 
     141    background: url(../images/icon--collapse.svg); 
     142    background-size: 10px; 
     143    width: 20px; 
     144    height: 20px; 
     145    background-repeat: no-repeat; 
     146    background-position: center center; 
     147} 
     148 
     149.button.field-repeater-toggle-all.collapse:hover {  
     150    border:1px solid #d1d1d1; 
     151    background-color: #FFF; 
     152    color:#b0a9a8; 
     153} 
     154 
     155.button.field-repeater-toggle-all:focus {  
     156    outline: none; 
     157    box-shadow: none; 
     158    border:1px solid #d1d1d1; 
     159    color:#6a6f74; 
     160} 
     161 
     162div.field_type-flexible_content.collapsed-repeater .button.field-repeater-toggle-all:before, 
     163div.field_type-repeater.collapsed-repeater .button.field-repeater-toggle-all:before {  
     164    background: url(../images/icon--expand.svg); 
     165    background-size: 10px; 
     166    width: 20px; 
     167    height: 20px; 
     168    background-repeat: no-repeat; 
     169    background-position: center center; 
     170} 
  • advanced-custom-field-repeater-collapser/trunk/css/acf5_repeater_collapser_admin.css

    r1029030 r1657399  
    1 /* Expand / Collapse Buttons */ 
    2 .field-repeater-toggle-all { 
    3     float:right; 
    4     margin: -5px 0 15px !important; 
     1.collapse {  
     2    box-sizing: border-box; 
     3    position: absolute; 
     4    top:15px; 
     5    right:12px; 
     6    border:1px solid #d1d1d1; 
     7    background:#FFF; 
     8    font-weight:normal; 
     9    color:#6a6f74; 
     10    padding:1px 10px 1px 30px; 
     11    text-align: right; 
     12    min-width: 114px; 
     13    transition: all 100ms ease-in-out; 
     14    background-color: rgba(249, 249, 249, 0.50); 
     15    user-select: none; 
     16} 
     17.collapse:hover {  
     18    border:1px solid #6a6f74; 
     19    background-color: #FFF; 
     20    cursor: pointer; 
     21} 
     22.collapse:focus {  
     23    background-color: #FFF; 
     24    box-shadow: none; 
     25    outline:none; 
     26} 
     27.collapse:before {  
     28    position: absolute; 
     29    top:0; 
     30    left:3px; 
     31    content: ""; 
     32    background: url(../images/icon--collapse.svg); 
     33    background-size: 10px; 
     34    width: 20px; 
     35    height: 20px; 
     36    background-repeat: no-repeat; 
     37    background-position: center center; 
    538} 
    639 
    7 .button.field-repeater-toggle-single { 
    8     padding: 1px 1px 0 1px; 
     40.collapse--active {  
     41 
    942} 
    10 .layout .field-repeater-toggle-single { 
    11     margin: 0 5px 0 -5px; 
    12 } 
    13 .repeater-button-cell { 
    14     background: #f9f9f9 !important; 
    15     padding: 0 !important; 
    16     vertical-align: middle !important; 
    17     text-align: center !important; 
    18     border-right-color: #e1e1e1 !important; 
    19     width: 30px !important; 
    20     /* Sorry 'bout the !importants. They are gross. Sadly, so are the ACF selectors I have to battle. */ 
    21 } 
    22 /* Grossness: http://css-tricks.com/absolutely-position-element-within-a-table-cell/ */ 
    23 .repeater-button-cell-div { 
    24     position: relative; 
     43.collapse--active:before {  
     44    background: url(../images/icon--expand.svg); 
     45    background-size: 10px; 
     46    width: 20px; 
     47    height: 20px; 
     48    background-repeat: no-repeat; 
     49    background-position: center center; 
    2550} 
    2651 
    27 .field_type-flexible_content .layout.row-layout { 
    28     padding-left: 30px; 
    29     background: transparent; 
     52.flexi-label {  
     53    font-style: italic; 
     54    padding-left: 5px; 
     55    font-size: 12px; 
     56    color:#999; 
    3057} 
    3158 
    32 .field_type-flexible_content .field-repeater-toggle-single { 
    33     position: absolute; 
    34     top: 50%; 
    35     margin-top: -15px; 
    36     left: 5px; 
     59 
     60 
     61/*.acf-flexible-content .layout .acf-fc-layout-handle:hover {  
     62    background: #f9f9f9; 
     63}*/ 
     64 
     65.acf-flexible-content .layout .acf-fc-layout-handle {  
     66    background: rgba(249, 249, 249, 0.50); 
    3767} 
    38 /* Weird positioning exception */ 
    39 .field_type-flexible_content .field_type-repeater .field-repeater-toggle-single { 
    40     left: 8px; 
     68/*.acf-flexible-content .layout .acf-fc-layout-handle:hover .acf-fc-layout-order, 
     69.acf-flexible-content .layout.-collapsed .acf-fc-layout-order {  
     70    background: #FFF; 
     71}*/ 
     72 
     73 
     74 
     75.acf-fields.-left .collapse{  
     76    position: relative; 
     77    left:0; 
     78    top:0; 
    4179} 
    42  
    43 .field_type-flexible_content .acf-fc-layout-handle { 
    44     background: #fff; 
    45 } 
    46  
    47 .field-repeater-toggle::before { 
    48     content: "\f506"; 
    49     display: inline; 
    50     -webkit-font-smoothing: antialiased; 
    51     font: normal 20px/1 'dashicons'; 
    52     vertical-align: text-bottom; 
    53     color: #777; 
    54 } 
    55 .field-repeater-toggle-all::before { 
    56     margin: 3px 5px 0 0; 
    57 } 
    58  
    59 .collapsed-repeater .field-repeater-toggle-all::before, 
    60 .collapsed-row .field-repeater-toggle-single::before { 
    61     content: "\f211"; 
    62 } 
    63  
    64 .acf_flexible_content, 
    65 .repeater { 
    66   clear: both; 
    67 } 
    68  
    69 .acf-table { 
    70     position: relative; 
    71 } 
    72  
    73 .collapsed-row .acf-table tr { 
    74     display: none; 
    75 } 
    76  
    77 .collapsed-row .acf-table tr:first-child { 
    78     display: table-row; 
    79 } 
    80  
    81 /* "Masks" the first field in order to prevent clicking on it */ 
    82 .collapsed-row .acf-table tr::after { 
    83     position: absolute; 
    84     top: 0; bottom: 0; left: 0px; right: 0; 
    85     display: block; 
    86     content: ' '; 
    87     background: -webkit-gradient(linear, left top, left bottom, from(rgba( 244, 244, 244, .2 )), to(rgba( 244, 244, 244, 1 ))); 
    88     background: -o-linear-gradient( rgba( 244, 244, 244, .2 ), rgba( 244, 244, 244, 1 ) ); 
    89     background: -moz-linear-gradient( rgba( 244, 244, 244, .2 ), rgba( 244, 244, 244, 1 ) ); 
    90     background: -webkit-linear-gradient( rgba( 244, 244, 244, .2 ), rgba( 244, 244, 244, 1 ) ); 
    91     background: linear-gradient( rgba( 244, 244, 244, .2 ), rgba( 244, 244, 244, 1 ) ); 
    92 } 
  • advanced-custom-field-repeater-collapser/trunk/js/acf4_repeater_collapser_admin.js

    r1240006 r1657399  
    88        // HTML to put above each repeater instance 
    99        var i = 1, 
    10             $collapseAllButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-all">Collapse All Rows</button>', 
    11             $collapseSingleButtonTable = '<td class="repeater-button-cell"><button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">Collapse Row</span></button></td>', 
    12             $collapseSingleButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">Collapse Row</span></button>'; 
     10            $collapseAllButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-all">' + acfrcL10n.collapseRows + '</button>', 
     11            $collapseSingleButtonTable = '<td class="repeater-button-cell"><div class="repeater-button-cell-div"><button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">' + acfrcL10n.collapseRow + '</span></button></div></td>', 
     12            $collapseSingleButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">' + acfrcL10n.collapseRow + '</span></button>'; 
    1313 
    1414        // find each repeater & flexible instance, add the button if the field uses the row layout 
     
    9494            .data('acf-row-collapsed', true) 
    9595            .attr('aria-expanded', false); 
    96         $rowButtonText.text('Expand Row'); 
     96        $rowButtonText.text(acfrcL10n.expandRow); 
    9797    } 
    9898 
     
    105105            .data('acf-row-collapsed', false) 
    106106            .attr('aria-expanded', true); 
    107         $rowButtonText.text('Collapse Row'); 
     107        $rowButtonText.text(acfrcL10n.collapseRow); 
    108108    } 
    109109 
     
    115115 
    116116        $wrapper.removeClass('collapsed-repeater').data('acf-rowset-collapsed', false); 
    117         $button.text('Collapse All Rows'); 
     117        $button.text(acfrcL10n.collapseRows); 
    118118    } 
    119119 
     
    126126        $wrapper.addClass('collapsed-repeater') 
    127127            .data('acf-rowset-collapsed', true); 
    128         $button.text('Expand All Rows'); 
     128        $button.text(acfrcL10n.expandRows); 
    129129    } 
    130130 
  • advanced-custom-field-repeater-collapser/trunk/js/acf5_repeater_collapser_admin.js

    r1240006 r1657399  
    1 jQuery(document).ready(function($) { 
    2     'use strict'; 
     1(function($){ 
    32 
    4     /** 
    5      * set up the buttons on the entire form 
    6      */ 
    7     function acfRepeaterCollapserInit() { 
    8         // HTML to put above each repeater instance 
    9         var i = 1, 
    10             $collapseAllButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-all">Collapse All Rows</button>', 
    11             $collapseSingleButtonTable = '<td class="repeater-button-cell"><div class="repeater-button-cell-div"><button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">Collapse Row</span></button></div></td>', 
    12             $collapseSingleButton = '<button type="button" role="button" class="button field-repeater-toggle field-repeater-toggle-single"><span class="screen-reader-text">Collapse Row</span></button>'; 
     3    // Exists function  
     4    $.fn.exists = function(){ return this.length > 0; } 
    135 
    14         // find each repeater & flexible instance, add the button if the field uses the row layout 
    15         $('.field_type-repeater, .field_type-flexible_content').each( function() { 
    16             var $repeater = $(this); 
     6    // Check if we should show the repeter collapse button  
     7    $.fn.repeaterShowcollapse = function() {  
    178 
    18             // only use this on row layout 
    19             if( $( '.acf-input-table', $repeater ).hasClass('row-layout') ) { 
    20                 $repeater.find('.layout').addClass('row-layout'); 
    21                 $repeater.data('acf-rowset-collapsed', false).attr('aria-expanded', false); 
     9        // If we can find at the acf icon to collapse the fields - show (or remove) 
     10        if ( $(this).find('a.-collapse').exists() ) { 
     11            //$(this).find('.collapse').show(); 
     12            //console.log('collapse exists'); 
     13        } else {  
     14             
     15            // If we can't find a collapse button 
     16            // The user hasn't set the collapsed target, so lets set one 
     17            $(this).find('.acf-row').each(function( index ) { 
     18                $(this).find('.acf-field').first().addClass('-collapsed-target'); 
     19            }); 
     20             
     21        } 
     22         
     23        // If the repeater is empty - hide (target the first repeater to support nested repeaters) 
     24        if( $(this).find('.acf-repeater').first().is('.-empty')) {  
     25            $(this).find('.collapse').hide(); 
     26        } else {  
     27            $(this).find('.collapse').show(); 
     28        } 
     29         
     30    } 
    2231 
    23                 // first: nested, second: parent 
    24                 if( $repeater.is( 'tr' ) ) { 
    25                     $( '.acf-repeater', $repeater ).first().prepend( $collapseAllButton ); 
    26                     $repeater 
    27                         .data('acf-rowset-collapsed', false) 
    28                         .data('acf-repeater-nested', true); 
    29                     $('.acf-row,.acf-row.clone', $repeater ).data('acf-repeater-nested', true); 
    30                 } else { 
    31                     $repeater.prepend( $collapseAllButton ) 
    32                         .data('acf-rowset-collapsed', false); 
    33                 } 
     32    // Check if we should show or hide the flexi collapse button  
     33    $.fn.flexiShowcollapse = function() {  
     34        if( $(this).find('.acf-flexible-content').is('.empty')) {  
     35            $(this).find('.collapse').first().hide(); 
     36        } else {  
     37            $(this).find('.collapse').first().show(); 
     38        } 
     39    } 
     40 
     41    /**  
     42    Doc Ready 
     43    **/  
     44    $(document).ready(function(){ 
     45 
     46        /**  
     47        Repeater Functionality  
     48        **/      
     49         
     50        // Open all fields on page load  
     51        $('.acf-row').removeClass('-collapsed'); 
     52         
     53        // Append the collapse button   
     54        $( ".acf-field-repeater > .acf-label" ).append('<button class="collapse">' + acfrcL10n.collapseAll + '</button>'); 
     55 
     56        // Check if we should show the button  
     57        $( ".acf-field-repeater" ).each(function( index ) { 
     58            $(this).repeaterShowcollapse(); 
     59        }); 
     60         
     61        // On the click of the repeater toggle  
     62        $('body').on('click','.acf-field-repeater .collapse', function( event ) { 
     63             
     64            event.preventDefault(); 
     65             
     66            var active = $(this).hasClass('collapse--active'); 
     67             
     68            // open all the things  
     69            if( active ) {  
     70                $(this).closest('.acf-field').find('.acf-row').removeClass('-collapsed'); 
     71                $(this).removeClass('collapse--active'); 
     72                $(this).html( acfrcL10n.collapseAll ); 
     73 
     74            // close all the things  
     75            } else {  
     76                $(this).closest('.acf-field').find('.acf-row').addClass('-collapsed'); 
     77                $(this).addClass('collapse--active'); 
     78                $(this).html( acfrcL10n.expandAll ); 
    3479            } 
     80             
     81         
    3582        }); 
    3683 
    37         // append single repeater collapse to each row of repeater field 
    38         $('.field_type-repeater .row-layout > tbody > .acf-row,.field_type-repeater > tbody > .row-layout .acf-row.clone').each( function() { 
    39             var id    = 'acf-repeater-' + i, 
    40                 $that = $(this); 
    4184 
    42             $that.prepend( $collapseSingleButtonTable ) 
    43                 .data('acf-row-collapsed', false) 
    44                 .attr('aria-expanded', true) 
    45                 .attr('id','acf-repeater-' + i) 
    46                 .attr('aria-live','off'); 
    47             $('.field-repeater-toggle-single', $that).first() 
    48                 .attr('aria-controls',id); 
     85        /**  
     86        Flexi Functionality 
     87        **/ 
     88         
     89        // Append the collapse button 
     90        $(this).find('.acf-field-flexible-content > .acf-label label').append('<button class="collapse collapse--flexi">' + acfrcL10n.collapseAll + '</button>');            
    4991 
    50             i++; 
     92        // On the click of the toggle  
     93        $('.acf-field-flexible-content').find('.collapse').first().click(function( event ) { 
     94             
     95            event.preventDefault(); 
     96             
     97            var active = $(this).hasClass('collapse--active'); 
     98             
     99            // open all the things  
     100            if( active ) {  
     101                $(this).removeClass('collapse--active'); 
     102                $(this).html( acfrcL10n.collapseAll); 
     103                $(this).closest('.acf-fields').each(function( index ) { 
     104                    $(this).find('.layout').removeClass('-collapsed'); 
     105                }); 
     106            // close all the things  
     107            } else {  
     108                $(this).addClass('collapse--active'); 
     109                $(this).html( acfrcL10n.expandAll ); 
     110                $(this).closest('.acf-fields').each(function( index ) { 
     111                    $(this).find('.layout').addClass('-collapsed'); 
     112                }); 
     113            } 
     114             
     115             
     116         
     117        }); 
     118         
     119        // Hide the button if the field is empty  
     120        $( ".acf-field-flexible-content" ).each(function( index ) { 
     121            $(this).flexiShowcollapse(); 
    51122        }); 
    52123 
    53         // append single repeater collapse to flex fields 
    54         $('.field_type-flexible_content .layout').each( function() { 
    55             var $that = $(this), 
    56                 id; 
     124    }); // Doc ready  
    57125 
    58             if( $('.acf-input-table', $that).hasClass('row-layout') ) { 
    59                 id = 'acf-repeater-' + i; 
    60                 i++; 
    61126 
    62                 $that.prepend( $collapseSingleButton ) 
    63                     .data('acf-row-collapsed', false) 
    64                     .attr('aria-expanded', true) 
    65                     .attr('id','acf-repeater-' + i) 
    66                     .attr('aria-live','off'); 
     127    /**  
     128    AJAX Complete  
     129    This runs after a row has been added / removed or a single row collapsed / collapseed 
     130    **/ 
    67131 
    68                 $('.field-repeater-toggle-single', $that).first().attr('aria-controls',id); 
    69             } 
     132    $(document).ajaxComplete(function() { 
     133         
     134        // Check if we should show the button on each repeater field  
     135        $( ".acf-field-repeater" ).each(function( index ) { 
     136            $(this).repeaterShowcollapse(); 
     137        });  
     138 
     139        // Check if we should show the button on each flexi field  
     140        $( ".acf-field-flexible-content" ).each(function( index ) { 
     141            $(this).flexiShowcollapse(); 
    70142        }); 
     143             
     144    }); 
    71145 
    72         // Bind click events to the toggle functions 
    73         // delegated to higher DOM element to handle dynamically added repeaters 
    74         $( '.field_type-repeater, .field_type-flexible_content' ).on( 
    75             'click', 
    76             '.field-repeater-toggle-all', 
    77             acfRepeaterToggleAll 
    78         ); 
    79         $( '.field_type-repeater .row-layout,.field_type-flexible_content' ).on( 
    80             'click', 
    81             '.field-repeater-toggle-single', 
    82             acfRepeaterToggleSingle 
    83         ); 
    84146 
    85         // prevent default flexible field collapsing for clarity 
    86         $('.field_type-flexible_content').on( 
    87             'click', 
    88             '.acf-fc-layout-handle', 
    89             false 
    90         ); 
    91     } 
    92  
    93     /** 
    94      * Collapse a row or rows 
    95      */ 
    96     function acfRepeaterCollapseRow( $rows ) { 
    97         var $rowButtonText = $('.screen-reader-text', $rows); 
    98         $rows.addClass('collapsed-row') 
    99             .data('acf-row-collapsed', true) 
    100             .attr('aria-expanded', false); 
    101         $rowButtonText.text('Expand Row'); 
    102     } 
    103  
    104     /** 
    105      * Expand a row or rows 
    106      */ 
    107     function acfRepeaterExpandRow( $rows ) { 
    108         var $rowButtonText = $('.screen-reader-text', $rows); 
    109         $rows.removeClass('collapsed-row') 
    110             .data('acf-row-collapsed', false) 
    111             .attr('aria-expanded', true); 
    112         $rowButtonText.text('Collapse Row'); 
    113     } 
    114  
    115     /** 
    116      * Indicate a collapsed rowset 
    117      */ 
    118     function acfRepeaterExpandRowset( $wrapper ) { 
    119         var $button = $('.field-repeater-toggle-all', $wrapper).first(); 
    120  
    121         $wrapper.removeClass('collapsed-repeater') 
    122             .data('acf-rowset-collapsed', false); 
    123         $button.text('Collapse All Rows'); 
    124     } 
    125  
    126     /** 
    127      * Indicate an expanded rowset 
    128      */ 
    129     function acfRepeaterCollapseRowset( $wrapper ) { 
    130         var $button = $('.field-repeater-toggle-all', $wrapper).first(); 
    131  
    132         $wrapper.addClass('collapsed-repeater') 
    133             .data('acf-rowset-collapsed', true); 
    134         $button.text('Expand All Rows'); 
    135     } 
    136  
    137     /** 
    138      * toggles set of repeater rows or flexible fields 
    139      */ 
    140     function acfRepeaterToggleAll(event) { 
    141         var $rows, 
    142             $that = $(this), 
    143             $rowsetButton  = $that, 
    144             $rowsetWrapper = $that.closest('.acf-field'); 
    145  
    146         // select either nested or unnested repeater rows, not both 
    147         if( true === $rowsetWrapper.data('acf-repeater-nested') ) { 
    148             $rows = $('.acf-row:data(acf-repeater-nested),.layout', $rowsetWrapper); 
    149         } else { 
    150             $rows = $('.acf-row,.layout', $rowsetWrapper).not(':data(acf-repeater-nested)'); 
    151         } 
    152  
    153         // toggle repeater state and all rows 
    154         if( true !== $rowsetWrapper.data('acf-rowset-collapsed') ) { 
    155             acfRepeaterCollapseRowset( $rowsetWrapper ); 
    156             acfRepeaterCollapseRow( $rows ); 
    157         } else { 
    158             acfRepeaterExpandRowset( $rowsetWrapper ); 
    159             acfRepeaterExpandRow( $rows ); 
    160         } 
    161  
    162         // prevent bubbling up to parent repeater rowset 
    163         event.stopPropagation(); 
    164     } 
    165  
    166     /** 
    167      * toggles single repeater row or flexible field 
    168      */ 
    169     function acfRepeaterToggleSingle(event) { 
    170         var $rowButton     = $(this), 
    171             $rowButtonText = $('.screen-reader-text', $rowButton), 
    172             $row           = $rowButton.closest('.acf-row,.layout'), 
    173             $rowsetWrapper = $rowButton.closest('.acf-field'); 
    174  
    175         // toggle the row state and button text 
    176         if( true !== $row.data('acf-row-collapsed') ) { 
    177             acfRepeaterCollapseRow( $row ); 
    178         } else { 
    179             acfRepeaterExpandRow( $row ); 
    180         } 
    181  
    182         if( true === acfRepeaterAllCollapsed( $rowsetWrapper ) ) { 
    183             acfRepeaterCollapseRowset( $rowsetWrapper ); 
    184         } else { 
    185             acfRepeaterExpandRowset( $rowsetWrapper ); 
    186         } 
    187  
    188         // prevent bubbling up to parent row button 
    189         event.stopPropagation(); 
    190     } 
    191  
    192     /** 
    193      * check to see if all rows in a rowset are collapsed 
    194      * @param  obj $rowsetWrapper jquery object 
    195      * @return bool                 true if all rows in rowset are collapsed 
    196      */ 
    197     function acfRepeaterAllCollapsed( $rowsetWrapper ) { 
    198         var $rows, 
    199             rowStates = [], 
    200             allCollapsed; 
    201         // select either nested or unnested repeater rows, not both 
    202         if( true === $rowsetWrapper.data('acf-repeater-nested') ) { 
    203             $rows = $('.acf-row:data(acf-repeater-nested),.layout:data(acf-repeater-nested)', $rowsetWrapper).not('.clone'); 
    204         } else { 
    205             $rows = $('.acf-row,.values .layout', $rowsetWrapper).not(':data(acf-repeater-nested)').not('.clone'); 
    206         } 
    207  
    208         // store every row collapsed state in an array 
    209         $rows.each( function() { 
    210             rowStates.push( $(this).data('acf-row-collapsed') ); 
    211         }); 
    212  
    213         // check if any rows are expanded 
    214         allCollapsed = 0 > $.inArray( false, rowStates ); 
    215  
    216         return allCollapsed; 
    217     } 
    218  
    219     // Initiatilize the plugin 
    220     acfRepeaterCollapserInit(); 
    221 }); 
     147})(jQuery); 
  • advanced-custom-field-repeater-collapser/trunk/readme.txt

    r1611418 r1657399  
    33Tags: advanced custom fields, acf, repeater 
    44Requires at least: 3.0.0 
    5 Donate link: https://www.networkforgood.org/donation/MakeDonation.aspx?ORGID2=522061398 
    65Tested up to: 4.3 
    7 Stable tag: 1.4.3 
     6Stable tag: 1.5.0 
    87License: GPLv2 or later 
    98License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    1312== Description == 
    1413 
    15 > <strong>8 March 2017</strong>: Good news! [Aaron Rutley](https://profiles.wordpress.org/aaronrutley) has adopted this plugin. Aaron has significant experience with ACF and is a user of this plugin, making him an excellent candidate for maintaining this plugin moving forward. [Mark Root-Wiley](https://profiles.wordpress.org/mrwweb) will no longer be an active contributor or providing support. Aaron has worked up a new version of the plugin that improves the interface, fixes ACF5 support, and continues ACF4 support. It will be available soon and is [available for beta testing](https://github.com/mrwweb/ACF-Repeater-Collapser/archive/develop.zip). 
    16  
    1714The Repeater and Flexible Content Field features make ACF really powerful, but if you have more than a few fields with either, they becomes unwieldy to sort. This plugin collapses each instance of the repeated fields—**only for the "Row" layout**—to allow for easy sorting. 
    1815 
    1916*To help identify each repeater field group when collapsed, the first field of each repeated field group is shown. See the [screenshots](https://wordpress.org/plugins/advanced-custom-field-repeater-collapser/screenshots/) for an example.* 
    20  
    21 **Want support for the table layout? Sponsor an update!** [Contact me](https://mrwweb.com/contact/) about sponsoring this feature if you're interested. 
    2217 
    2318------------------------------------------------ 
     
    3126------------------------------------------------ 
    3227 
    33 Contribute to [this plugin on GitHub](https://github.com/mrwweb/ACF-Repeater-Collapser). 
    34  
    3528**Other contributors:** 
    3629 
     30* [mrwweb](https://github.com/mrwweb) 
    3731* [brasofilo](https://profiles.wordpress.org/brasofilo/) 
    3832* [weskoop](https://profiles.wordpress.org/weskoop/) 
    3933* [philiphetue](https://github.com/philiphetue) 
    4034* [robneu](https://github.com/robneu) 
    41  
    42 This plugin began as a [support forum thread](http://support.advancedcustomfields.com/discussion/comment/16239) on the ACF site. 
    4335 
    4436== Frequently Asked Questions == 
     
    5547Now you can, as of version 1.3.0. 
    5648 
    57 = What exactly is the "Collapse All Rows" button behavior = 
     49= What exactly is the "Collapse All Rows" button behaviour = 
    5850With the addition of the ability to collapse single rows, the button now is always in "Collapse" mode unless all rows are collapsed. Then it's "Expand." 
    5951 
     
    7466 
    7567== Changelog == 
     68 
     69= 1.5.0 = 
     70* [ACF v4] - Style fixes and new icons 
     71* [ACF v5] - New JS so Collapse All & Expand All now works again 
    7672 
    7773= 1 June 2016 = 
Note: See TracChangeset for help on using the changeset viewer.