Plugin Directory

Changeset 2908643


Ignore:
Timestamp:
05/05/2023 04:43:18 PM (3 years ago)
Author:
bleechberlin
Message:

Tagging version 1.2

Location:
acf-hide-layout/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • acf-hide-layout/trunk/acf-hide-layout.php

    r2813841 r2908643  
    55 * Description: Easily hide the layout of the flexible content on the frontend but still keep it in the backend.
    66 * Tags: acf, advanced custom fields, flexible content, hide layout
    7  * Version: 1.1
     7 * Version: 1.2
    88 * Author: Bleech
    99 * Author URI: https://bleech.de/
  • acf-hide-layout/trunk/assets/js/script.js

    r2643346 r2908643  
    11(function( $ ) {
    2     'use strict';
     2  'use strict';
    33
    4     if ( window.acf ) {
    5         window.acf.addAction( 'ready_field/type=flexible_content', function( field ) {
    6             var get_hidden_layouts = function ( field_name ) {
    7                 var hidden_layouts = [];
    8                 $.each( window.acf_hide_layout_options.hidden_layouts, function( key, layouts ) {
    9                     if ( -1 !== field_name.indexOf( key ) ) {
    10                         hidden_layouts = layouts;
    11                         return false;
    12                     }
    13                 });
     4  if ( window.acf ) {
     5      window.acf.addAction( 'ready_field/type=flexible_content', function( field ) {
     6          var get_hidden_layouts = function ( field_name ) {
     7              var hidden_layouts = [];
     8              $.each( window.acf_hide_layout_options.hidden_layouts, function( key, layouts ) {
     9                  if ( -1 !== field_name.indexOf( key ) ) {
     10                      hidden_layouts = layouts;
     11                      return false;
     12                  }
     13              });
    1414
    15                 return hidden_layouts;
    16             };
     15              return hidden_layouts;
     16          };
    1717
    18             // for each layout in the flexible field
    19             field.$el.find( '.layout' ).each(function( i, element ) {
    20                 var $el = $( element ),
    21                     $controls = $el.find( '.acf-fc-layout-controls' ),
    22                     $input = $el.find( 'input[type="hidden"]' ).first(),
    23                     index = $el.attr( 'data-id' ),
    24                     name = $input.attr( 'name' ).replace( 'acf_fc_layout', 'acf_hide_layout' ),
    25                     hidden_layouts = get_hidden_layouts( name ),
    26                     in_array = -1 !== $.inArray( index, hidden_layouts ),
    27                     is_hidden = in_array && 'acfcloneindex' !== index;
     18          // for each layout in the flexible field
     19          field.$el.find( '.layout' ).each(function( i, element ) {
     20              var $el = $( element ),
     21                  $controls = $el.find( '.acf-fc-layout-controls' ).first(),
     22                  $input = $el.find( 'input[type="hidden"]' ).first(),
     23                  index = $el.attr( 'data-id' ),
     24                  name = $input.attr( 'name' ).replace( 'acf_fc_layout', 'acf_hide_layout' ),
     25                  hidden_layouts = get_hidden_layouts( name ),
     26                  in_array = -1 !== $.inArray( index, hidden_layouts ),
     27                  is_hidden = in_array && 'acfcloneindex' !== index;
    2828
    29                 var $input = $( '<input>', {
    30                     type: 'hidden',
    31                     name: name,
    32                     class: 'acf-hide-layout',
    33                     value: is_hidden ? '1' : '0',
    34                 });
     29              if ($el.data('has-acf-hide-layout')) {
     30                  return;
     31              }
    3532
    36                 var $action = $( '<a>', {
    37                     'data-index': index,
    38                     'data-name': 'hide-layout',
    39                     href: '#',
    40                     title: window.acf_hide_layout_options.i18n.hide_layout,
    41                     class: 'acf-icon dashicons acf-hide-layout small light acf-js-tooltip',
    42                 });
     33              $el.attr('data-has-acf-hide-layout', true)
    4334
    44                 $action.prepend( $input );
    45                 $controls.prepend( $action );
     35              var $input = $( '<input>', {
     36                  type: 'hidden',
     37                  name: name,
     38                  class: 'acf-hide-layout',
     39                  value: is_hidden ? '1' : '0',
     40              });
    4641
    47                 if ( is_hidden ) {
    48                     $el.addClass( 'acf-layout-hidden' );
    49                 }
    50             });
    51         });
    52     }
     42              var $action = $( '<a>', {
     43                  'data-index': index,
     44                  'data-name': 'hide-layout',
     45                  href: '#',
     46                  title: window.acf_hide_layout_options.i18n.hide_layout,
     47                  class: 'acf-icon dashicons acf-hide-layout small light acf-js-tooltip',
     48              });
    5349
    54     $( document ).on( 'click', '.acf-hide-layout', function() {
    55         var $el = $( this ),
    56             $layout = $el.parents( '.layout' ),
    57             $input = $el.find( '.acf-hide-layout' ),
    58             value = $input.val(),
    59             newValue = value === '1' ? '0' : '1';
     50              $action.prepend( $input );
     51              $controls.prepend( $action );
    6052
    61         $input.val(newValue);
    62         $layout.toggleClass( 'acf-layout-hidden', newValue );
    63     });
     53              if ( is_hidden ) {
     54                  $el.addClass( 'acf-layout-hidden' );
     55              }
     56          });
     57      });
     58  }
     59
     60  $( document ).on( 'click', '.acf-hide-layout', function() {
     61      var $el = $( this ),
     62          $layout = $el.closest( '.layout' ),
     63          $input = $el.find( '.acf-hide-layout' ),
     64          value = $input.val(),
     65          newValue = value === '1' ? '0' : '1';
     66
     67      $input.val(newValue);
     68      $layout.toggleClass( 'acf-layout-hidden', newValue );
     69  });
    6470
    6571})( jQuery );
  • acf-hide-layout/trunk/readme.txt

    r2813841 r2908643  
    33Tags: acf, advanced custom fields, flexible content, hide layout
    44Requires at least: 4.7
    5 Tested up to: 6.1
    6 Stable tag: 1.1
     5Tested up to: 6.2
     6Stable tag: 1.2
    77Requires PHP: 5.6
    88License: GPLv2 or later
     
    5050== Changelog ==
    5151
     52= 1.2 =
     53* Fixed issue with nested flexible_content
     54
    5255= 1.1 =
    5356* Fixed issue with cloning fields
Note: See TracChangeset for help on using the changeset viewer.