bindings
6 months ago
commands
1 week ago
pro
1 week ago
_acf-compatibility.js
1 year ago
_acf-condition-types.js
7 months ago
_acf-condition.js
1 year ago
_acf-conditions.js
1 year ago
_acf-field-accordion.js
6 months ago
_acf-field-button-group.js
7 months ago
_acf-field-checkbox.js
1 month ago
_acf-field-color-picker.js
7 months ago
_acf-field-date-picker.js
1 month ago
_acf-field-date-time-picker.js
1 month ago
_acf-field-file.js
1 month ago
_acf-field-google-map.js
6 months ago
_acf-field-icon-picker.js
1 month ago
_acf-field-image.js
1 month ago
_acf-field-link.js
1 year ago
_acf-field-oembed.js
1 month ago
_acf-field-page-link.js
1 year ago
_acf-field-post-object.js
1 year ago
_acf-field-radio.js
1 month ago
_acf-field-range.js
1 year ago
_acf-field-relationship.js
1 month ago
_acf-field-select.js
1 month ago
_acf-field-tab.js
3 weeks ago
_acf-field-taxonomy.js
7 months ago
_acf-field-time-picker.js
1 month ago
_acf-field-true-false.js
1 month ago
_acf-field-url.js
1 year ago
_acf-field-user.js
1 year ago
_acf-field-wysiwyg.js
1 month ago
_acf-field.js
1 year ago
_acf-fields.js
1 year ago
_acf-helpers.js
1 year ago
_acf-hooks.js
1 year ago
_acf-internal-post-type.js
7 months ago
_acf-media.js
1 week ago
_acf-modal.js
1 year ago
_acf-model.js
1 year ago
_acf-notice.js
7 months ago
_acf-panel.js
1 year ago
_acf-popup.js
7 months ago
_acf-postbox.js
1 year ago
_acf-screen.js
10 months ago
_acf-select2.js
1 year ago
_acf-tinymce.js
6 months ago
_acf-tooltip.js
10 months ago
_acf-unload.js
1 year ago
_acf-validation.js
1 month ago
_acf.js
7 months ago
_browse-fields-modal.js
7 months ago
_field-group-compatibility.js
1 year ago
_field-group-conditions.js
1 year ago
_field-group-field.js
3 months ago
_field-group-fields.js
10 months ago
_field-group-locations.js
1 year ago
_field-group-settings.js
1 year ago
_field-group.js
10 months ago
acf-escaped-html-notice.js
1 year ago
acf-field-group.js
1 year ago
acf-input.js
1 year ago
acf-internal-post-type.js
1 year ago
acf.js
1 year ago
_field-group.js
400 lines
| 1 | ( function ( $, undefined ) { |
| 2 | /** |
| 3 | * fieldGroupManager |
| 4 | * |
| 5 | * Generic field group functionality |
| 6 | * |
| 7 | * @date 15/12/17 |
| 8 | * @since ACF 5.7.0 |
| 9 | * |
| 10 | * @param void |
| 11 | * @return void |
| 12 | */ |
| 13 | |
| 14 | var fieldGroupManager = new acf.Model( { |
| 15 | id: 'fieldGroupManager', |
| 16 | |
| 17 | events: { |
| 18 | 'submit #post': 'onSubmit', |
| 19 | 'click a[href="#"]': 'onClick', |
| 20 | 'click .acf-delete-field-group': 'onClickDeleteFieldGroup', |
| 21 | 'blur input#title': 'validateTitle', |
| 22 | 'input input#title': 'validateTitle', |
| 23 | }, |
| 24 | |
| 25 | filters: { |
| 26 | find_fields_args: 'filterFindFieldArgs', |
| 27 | find_fields_selector: 'filterFindFieldsSelector', |
| 28 | }, |
| 29 | |
| 30 | initialize: function () { |
| 31 | acf.addAction( 'prepare', this.maybeInitNewFieldGroup ); |
| 32 | acf.add_filter( 'select2_args', this.setBidirectionalSelect2Args ); |
| 33 | acf.add_filter( |
| 34 | 'select2_ajax_data', |
| 35 | this.setBidirectionalSelect2AjaxDataArgs |
| 36 | ); |
| 37 | }, |
| 38 | |
| 39 | setBidirectionalSelect2Args: function ( |
| 40 | args, |
| 41 | $select, |
| 42 | settings, |
| 43 | field, |
| 44 | instance |
| 45 | ) { |
| 46 | if ( field?.data?.( 'key' ) !== 'bidirectional_target' ) |
| 47 | return args; |
| 48 | |
| 49 | args.dropdownCssClass = 'field-type-select-results'; |
| 50 | |
| 51 | // Check for a full modern version of select2 like the one provided by ACF. |
| 52 | try { |
| 53 | $.fn.select2.amd.require( 'select2/compat/dropdownCss' ); |
| 54 | } catch ( err ) { |
| 55 | console.warn( |
| 56 | 'ACF was not able to load the full version of select2 due to a conflicting version provided by another plugin or theme taking precedence. Skipping styling of bidirectional settings.' |
| 57 | ); |
| 58 | delete args.dropdownCssClass; |
| 59 | } |
| 60 | |
| 61 | args.templateResult = function ( selection ) { |
| 62 | if ( 'undefined' !== typeof selection.element ) { |
| 63 | return selection; |
| 64 | } |
| 65 | |
| 66 | if ( selection.children ) { |
| 67 | return selection.text; |
| 68 | } |
| 69 | |
| 70 | if ( |
| 71 | selection.loading || |
| 72 | ( selection.element && |
| 73 | selection.element.nodeName === 'OPTGROUP' ) |
| 74 | ) { |
| 75 | var $selection = $( '<span class="acf-selection"></span>' ); |
| 76 | $selection.html( acf.strEscape( selection.text ) ); |
| 77 | return $selection; |
| 78 | } |
| 79 | |
| 80 | if ( |
| 81 | 'undefined' === typeof selection.human_field_type || |
| 82 | 'undefined' === typeof selection.field_type || |
| 83 | 'undefined' === typeof selection.this_field |
| 84 | ) { |
| 85 | return selection.text; |
| 86 | } |
| 87 | |
| 88 | var $selection = $( |
| 89 | '<i title="' + |
| 90 | acf.escAttr( selection.human_field_type ) + |
| 91 | '" class="field-type-icon field-type-icon-' + |
| 92 | acf.strEscape( |
| 93 | selection.field_type.replaceAll( '_', '-' ) |
| 94 | ) + |
| 95 | '"></i><span class="acf-selection has-icon">' + |
| 96 | acf.strEscape( selection.text ) + |
| 97 | '</span>' |
| 98 | ); |
| 99 | if ( selection.this_field ) { |
| 100 | $selection |
| 101 | .last() |
| 102 | .append( |
| 103 | '<span class="acf-select2-default-pill">' + |
| 104 | acf.__( 'This Field' ) + |
| 105 | '</span>' |
| 106 | ); |
| 107 | } |
| 108 | $selection.data( 'element', selection.element ); |
| 109 | return $selection; |
| 110 | }; |
| 111 | |
| 112 | return args; |
| 113 | }, |
| 114 | |
| 115 | setBidirectionalSelect2AjaxDataArgs: function ( |
| 116 | data, |
| 117 | args, |
| 118 | $input, |
| 119 | field, |
| 120 | instance |
| 121 | ) { |
| 122 | if ( data.field_key !== 'bidirectional_target' ) return data; |
| 123 | |
| 124 | const $fieldObject = acf.findFieldObjects( { child: field } ); |
| 125 | const fieldObject = acf.getFieldObject( $fieldObject ); |
| 126 | data.field_key = '_acf_bidirectional_target'; |
| 127 | data.parent_key = fieldObject.get( 'key' ); |
| 128 | data.field_type = fieldObject.get( 'type' ); |
| 129 | |
| 130 | // This might not be needed, but I wanted to figure out how to get a field setting in the JS API when the key isn't unique. |
| 131 | data.post_type = acf |
| 132 | .getField( |
| 133 | acf.findFields( { parent: $fieldObject, key: 'post_type' } ) |
| 134 | ) |
| 135 | .val(); |
| 136 | |
| 137 | return data; |
| 138 | }, |
| 139 | |
| 140 | maybeInitNewFieldGroup: function () { |
| 141 | let $field_list_wrapper = $( |
| 142 | '#acf-field-group-fields > .inside > .acf-field-list-wrap.acf-auto-add-field' |
| 143 | ); |
| 144 | |
| 145 | if ( $field_list_wrapper.length ) { |
| 146 | $( '.acf-headerbar-actions .add-field' ).trigger( 'click' ); |
| 147 | $( '.acf-title-wrap #title' ).trigger( 'focus' ); |
| 148 | } |
| 149 | }, |
| 150 | |
| 151 | onSubmit: function ( e, $el ) { |
| 152 | // vars |
| 153 | var $title = $( '.acf-title-wrap #title' ); |
| 154 | |
| 155 | // empty |
| 156 | if ( ! $title.val() ) { |
| 157 | // prevent default |
| 158 | e.preventDefault(); |
| 159 | |
| 160 | // unlock form |
| 161 | acf.unlockForm( $el ); |
| 162 | |
| 163 | // focus |
| 164 | $title.trigger( 'focus' ); |
| 165 | } |
| 166 | }, |
| 167 | |
| 168 | onClick: function ( e ) { |
| 169 | e.preventDefault(); |
| 170 | }, |
| 171 | |
| 172 | onClickDeleteFieldGroup: function ( e, $el ) { |
| 173 | e.preventDefault(); |
| 174 | $el.addClass( '-hover' ); |
| 175 | |
| 176 | // Add confirmation tooltip. |
| 177 | acf.newTooltip( { |
| 178 | confirm: true, |
| 179 | target: $el, |
| 180 | context: this, |
| 181 | text: acf.__( 'Move field group to trash?' ), |
| 182 | confirm: function () { |
| 183 | window.location.href = $el.attr( 'href' ); |
| 184 | }, |
| 185 | cancel: function () { |
| 186 | $el.removeClass( '-hover' ); |
| 187 | }, |
| 188 | } ); |
| 189 | }, |
| 190 | |
| 191 | validateTitle: function ( e, $el ) { |
| 192 | let $submitButton = $( '.acf-publish' ); |
| 193 | |
| 194 | if ( ! $el.val() ) { |
| 195 | $el.addClass( 'acf-input-error' ); |
| 196 | $submitButton.addClass( 'disabled' ); |
| 197 | $( '.acf-publish' ).addClass( 'disabled' ); |
| 198 | } else { |
| 199 | $el.removeClass( 'acf-input-error' ); |
| 200 | $submitButton.removeClass( 'disabled' ); |
| 201 | $( '.acf-publish' ).removeClass( 'disabled' ); |
| 202 | } |
| 203 | }, |
| 204 | |
| 205 | filterFindFieldArgs: function ( args ) { |
| 206 | args.visible = true; |
| 207 | |
| 208 | if ( |
| 209 | args.parent && |
| 210 | ( args.parent.hasClass( 'acf-field-object' ) || |
| 211 | args.parent.hasClass( 'acf-browse-fields-modal-wrap' ) || |
| 212 | args.parent.parents( '.acf-field-object' ).length ) |
| 213 | ) { |
| 214 | args.visible = false; |
| 215 | args.excludeSubFields = true; |
| 216 | } |
| 217 | |
| 218 | // If the field has any open subfields, don't exclude subfields as they're already being displayed. |
| 219 | if ( |
| 220 | args.parent && |
| 221 | args.parent.find( '.acf-field-object.open' ).length |
| 222 | ) { |
| 223 | args.excludeSubFields = false; |
| 224 | } |
| 225 | |
| 226 | return args; |
| 227 | }, |
| 228 | |
| 229 | filterFindFieldsSelector: function ( selector ) { |
| 230 | return selector + ', .acf-field-acf-field-group-settings-tabs'; |
| 231 | }, |
| 232 | } ); |
| 233 | |
| 234 | /** |
| 235 | * screenOptionsManager |
| 236 | * |
| 237 | * Screen options functionality |
| 238 | * |
| 239 | * @date 15/12/17 |
| 240 | * @since ACF 5.7.0 |
| 241 | * |
| 242 | * @param void |
| 243 | * @return void |
| 244 | */ |
| 245 | |
| 246 | var screenOptionsManager = new acf.Model( { |
| 247 | id: 'screenOptionsManager', |
| 248 | wait: 'prepare', |
| 249 | |
| 250 | events: { |
| 251 | 'change #acf-field-key-hide': 'onFieldKeysChange', |
| 252 | 'change #acf-field-settings-tabs': 'onFieldSettingsTabsChange', |
| 253 | 'change [name="screen_columns"]': 'render', |
| 254 | }, |
| 255 | |
| 256 | initialize: function () { |
| 257 | // vars |
| 258 | var $div = $( '#adv-settings' ); |
| 259 | var $append = $( '#acf-append-show-on-screen' ); |
| 260 | |
| 261 | // append |
| 262 | $div.find( '.metabox-prefs' ).append( $append.html() ); |
| 263 | $div.find( '.metabox-prefs br' ).remove(); |
| 264 | |
| 265 | // clean up |
| 266 | $append.remove(); |
| 267 | |
| 268 | // initialize |
| 269 | this.$el = $( '#screen-options-wrap' ); |
| 270 | |
| 271 | // render |
| 272 | this.render(); |
| 273 | }, |
| 274 | |
| 275 | isFieldKeysChecked: function () { |
| 276 | return this.$el.find( '#acf-field-key-hide' ).prop( 'checked' ); |
| 277 | }, |
| 278 | |
| 279 | isFieldSettingsTabsChecked: function () { |
| 280 | const $input = this.$el.find( '#acf-field-settings-tabs' ); |
| 281 | |
| 282 | // Screen option is hidden by filter. |
| 283 | if ( ! $input.length ) { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | return $input.prop( 'checked' ); |
| 288 | }, |
| 289 | |
| 290 | getSelectedColumnCount: function () { |
| 291 | return this.$el |
| 292 | .find( 'input[name="screen_columns"]:checked' ) |
| 293 | .val(); |
| 294 | }, |
| 295 | |
| 296 | onFieldKeysChange: function ( e, $el ) { |
| 297 | var val = this.isFieldKeysChecked() ? 1 : 0; |
| 298 | acf.updateUserSetting( 'show_field_keys', val ); |
| 299 | this.render(); |
| 300 | }, |
| 301 | |
| 302 | onFieldSettingsTabsChange: function () { |
| 303 | const val = this.isFieldSettingsTabsChecked() ? 1 : 0; |
| 304 | acf.updateUserSetting( 'show_field_settings_tabs', val ); |
| 305 | this.render(); |
| 306 | }, |
| 307 | |
| 308 | render: function () { |
| 309 | if ( this.isFieldKeysChecked() ) { |
| 310 | $( '#acf-field-group-fields' ).addClass( 'show-field-keys' ); |
| 311 | } else { |
| 312 | $( '#acf-field-group-fields' ).removeClass( 'show-field-keys' ); |
| 313 | } |
| 314 | |
| 315 | if ( ! this.isFieldSettingsTabsChecked() ) { |
| 316 | $( '#acf-field-group-fields' ).addClass( 'hide-tabs' ); |
| 317 | $( '.acf-field-settings-main' ) |
| 318 | .removeClass( 'acf-hidden' ) |
| 319 | .prop( 'hidden', false ); |
| 320 | } else { |
| 321 | $( '#acf-field-group-fields' ).removeClass( 'hide-tabs' ); |
| 322 | |
| 323 | $( '.acf-field-object' ).each( function () { |
| 324 | const tabFields = acf.getFields( { |
| 325 | type: 'tab', |
| 326 | parent: $( this ), |
| 327 | excludeSubFields: true, |
| 328 | limit: 1, |
| 329 | } ); |
| 330 | |
| 331 | if ( tabFields.length ) { |
| 332 | tabFields[ 0 ].tabs.set( 'initialized', false ); |
| 333 | } |
| 334 | |
| 335 | acf.doAction( 'show', $( this ) ); |
| 336 | } ); |
| 337 | } |
| 338 | |
| 339 | if ( this.getSelectedColumnCount() == 1 ) { |
| 340 | $( 'body' ).removeClass( 'columns-2' ); |
| 341 | $( 'body' ).addClass( 'columns-1' ); |
| 342 | } else { |
| 343 | $( 'body' ).removeClass( 'columns-1' ); |
| 344 | $( 'body' ).addClass( 'columns-2' ); |
| 345 | } |
| 346 | }, |
| 347 | } ); |
| 348 | |
| 349 | /** |
| 350 | * appendFieldManager |
| 351 | * |
| 352 | * Appends fields together |
| 353 | * |
| 354 | * @date 15/12/17 |
| 355 | * @since ACF 5.7.0 |
| 356 | * |
| 357 | * @param void |
| 358 | * @return void |
| 359 | */ |
| 360 | |
| 361 | var appendFieldManager = new acf.Model( { |
| 362 | actions: { |
| 363 | new_field: 'onNewField', |
| 364 | }, |
| 365 | |
| 366 | onNewField: function ( field ) { |
| 367 | // bail early if not append |
| 368 | if ( ! field.has( 'append' ) ) return; |
| 369 | |
| 370 | // vars |
| 371 | var append = field.get( 'append' ); |
| 372 | var $sibling = field.$el |
| 373 | .siblings( '[data-name="' + append + '"]' ) |
| 374 | .first(); |
| 375 | |
| 376 | // bail early if no sibling |
| 377 | if ( ! $sibling.length ) return; |
| 378 | |
| 379 | // ul |
| 380 | var $div = $sibling.children( '.acf-input' ); |
| 381 | var $ul = $div.children( 'ul' ); |
| 382 | |
| 383 | // create ul |
| 384 | if ( ! $ul.length ) { |
| 385 | $div.wrapInner( '<ul class="acf-hl"><li></li></ul>' ); |
| 386 | $ul = $div.children( 'ul' ); |
| 387 | } |
| 388 | |
| 389 | // li |
| 390 | var html = field.$( '.acf-input' ).html(); |
| 391 | var $li = $( '<li>' + html + '</li>' ); |
| 392 | $ul.append( $li ); |
| 393 | $ul.attr( 'data-cols', $ul.children().length ); |
| 394 | |
| 395 | // clean up |
| 396 | field.remove(); |
| 397 | }, |
| 398 | } ); |
| 399 | } )( jQuery ); |
| 400 |