Changeset 2908643
- Timestamp:
- 05/05/2023 04:43:18 PM (3 years ago)
- Location:
- acf-hide-layout/trunk
- Files:
-
- 3 edited
-
acf-hide-layout.php (modified) (1 diff)
-
assets/js/script.js (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
acf-hide-layout/trunk/acf-hide-layout.php
r2813841 r2908643 5 5 * Description: Easily hide the layout of the flexible content on the frontend but still keep it in the backend. 6 6 * Tags: acf, advanced custom fields, flexible content, hide layout 7 * Version: 1. 17 * Version: 1.2 8 8 * Author: Bleech 9 9 * Author URI: https://bleech.de/ -
acf-hide-layout/trunk/assets/js/script.js
r2643346 r2908643 1 1 (function( $ ) { 2 'use strict';2 'use strict'; 3 3 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 }); 14 14 15 return hidden_layouts;16 };15 return hidden_layouts; 16 }; 17 17 18 // for each layout in the flexible field19 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; 28 28 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 } 35 32 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) 43 34 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 }); 46 41 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 }); 53 49 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 ); 60 52 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 }); 64 70 65 71 })( jQuery ); -
acf-hide-layout/trunk/readme.txt
r2813841 r2908643 3 3 Tags: acf, advanced custom fields, flexible content, hide layout 4 4 Requires at least: 4.7 5 Tested up to: 6. 16 Stable tag: 1. 15 Tested up to: 6.2 6 Stable tag: 1.2 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later … … 50 50 == Changelog == 51 51 52 = 1.2 = 53 * Fixed issue with nested flexible_content 54 52 55 = 1.1 = 53 56 * Fixed issue with cloning fields
Note: See TracChangeset
for help on using the changeset viewer.