|
1 | 1 | (function( $ ) {
|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 |
| - window.acf.addAction( 'ready_field/type=flexible_content', function( field ) { |
5 |
| - var hidden_layouts = window.acf_hide_layout_options.hidden_layouts[field.data.key]; |
6 |
| - |
7 |
| - // for each layout in the flexible field |
8 |
| - field.$el.find( '.layout' ).each(function( i, element ) { |
9 |
| - var $el = $( element ), |
10 |
| - $controls = $el.find( '.acf-fc-layout-controls' ), |
11 |
| - index = $el.attr( 'data-id' ), |
12 |
| - name = 'acf[' + field.data.key + '][' + index + '][acf_hide_layout]', |
13 |
| - in_array = -1 !== $.inArray( index, hidden_layouts ), |
14 |
| - is_hidden = in_array && 'acfcloneindex' !== index; |
15 |
| - |
16 |
| - var $input = $( '<input>', { |
17 |
| - type: 'hidden', |
18 |
| - name: name, |
19 |
| - class: 'acf-hide-layout', |
20 |
| - value: is_hidden ? '1' : '0', |
| 4 | + if ( window.acf ) { |
| 5 | + window.acf.addAction( 'ready_field/type=flexible_content', function( field ) { |
| 6 | + var hidden_layouts = window.acf_hide_layout_options.hidden_layouts[field.data.key]; |
| 7 | + |
| 8 | + // for each layout in the flexible field |
| 9 | + field.$el.find( '.layout' ).each(function( i, element ) { |
| 10 | + var $el = $( element ), |
| 11 | + $controls = $el.find( '.acf-fc-layout-controls' ), |
| 12 | + index = $el.attr( 'data-id' ), |
| 13 | + name = 'acf[' + field.data.key + '][' + index + '][acf_hide_layout]', |
| 14 | + in_array = -1 !== $.inArray( index, hidden_layouts ), |
| 15 | + is_hidden = in_array && 'acfcloneindex' !== index; |
| 16 | + |
| 17 | + var $input = $( '<input>', { |
| 18 | + type: 'hidden', |
| 19 | + name: name, |
| 20 | + class: 'acf-hide-layout', |
| 21 | + value: is_hidden ? '1' : '0', |
| 22 | + }); |
| 23 | + |
| 24 | + var $action = $( '<a>', { |
| 25 | + 'data-index': index, |
| 26 | + 'data-name': 'hide-layout', |
| 27 | + href: '#', |
| 28 | + title: window.acf_hide_layout_options.i18n.hide_layout, |
| 29 | + class: 'acf-icon dashicons acf-hide-layout small light acf-js-tooltip', |
| 30 | + }); |
| 31 | + |
| 32 | + $action.prepend( $input ); |
| 33 | + $controls.prepend( $action ); |
| 34 | + |
| 35 | + if ( is_hidden ) { |
| 36 | + $el.addClass( 'acf-layout-hidden' ); |
| 37 | + } |
21 | 38 | });
|
22 |
| - |
23 |
| - var $action = $( '<a>', { |
24 |
| - 'data-index': index, |
25 |
| - 'data-name': 'hide-layout', |
26 |
| - href: '#', |
27 |
| - title: window.acf_hide_layout_options.i18n.hide_layout, |
28 |
| - class: 'acf-icon dashicons acf-hide-layout small light acf-js-tooltip', |
29 |
| - }); |
30 |
| - |
31 |
| - $action.prepend( $input ); |
32 |
| - $controls.prepend( $action ); |
33 |
| - |
34 |
| - if ( is_hidden ) { |
35 |
| - $el.addClass( 'acf-layout-hidden' ); |
36 |
| - } |
37 | 39 | });
|
38 |
| - }); |
| 40 | + } |
39 | 41 |
|
40 | 42 | $( document ).on( 'click', '.acf-hide-layout', function() {
|
41 | 43 | var $el = $( this ),
|
|
0 commit comments