bindings
6 months ago
commands
2 weeks ago
pro
2 weeks 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
2 weeks 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
_acf-modal.js
125 lines
| 1 | ( function ( $, undefined ) { |
| 2 | acf.models.Modal = acf.Model.extend( { |
| 3 | data: { |
| 4 | title: '', |
| 5 | content: '', |
| 6 | toolbar: '', |
| 7 | }, |
| 8 | events: { |
| 9 | 'click .acf-modal-close': 'onClickClose', |
| 10 | }, |
| 11 | setup: function ( props ) { |
| 12 | $.extend( this.data, props ); |
| 13 | this.$el = $(); |
| 14 | this.render(); |
| 15 | }, |
| 16 | initialize: function () { |
| 17 | this.open(); |
| 18 | }, |
| 19 | render: function () { |
| 20 | // Extract vars. |
| 21 | var title = this.get( 'title' ); |
| 22 | var content = this.get( 'content' ); |
| 23 | var toolbar = this.get( 'toolbar' ); |
| 24 | |
| 25 | // Create element. |
| 26 | var $el = $( |
| 27 | [ |
| 28 | '<div>', |
| 29 | '<div class="acf-modal">', |
| 30 | '<div class="acf-modal-title">', |
| 31 | '<h2>' + title + '</h2>', |
| 32 | '<button class="acf-modal-close" type="button"><span class="dashicons dashicons-no"></span></button>', |
| 33 | '</div>', |
| 34 | '<div class="acf-modal-content">' + content + '</div>', |
| 35 | '<div class="acf-modal-toolbar">' + toolbar + '</div>', |
| 36 | '</div>', |
| 37 | '<div class="acf-modal-backdrop acf-modal-close"></div>', |
| 38 | '</div>', |
| 39 | ].join( '' ) |
| 40 | ); |
| 41 | |
| 42 | // Update DOM. |
| 43 | if ( this.$el ) { |
| 44 | this.$el.replaceWith( $el ); |
| 45 | } |
| 46 | this.$el = $el; |
| 47 | |
| 48 | // Trigger action. |
| 49 | acf.doAction( 'append', $el ); |
| 50 | }, |
| 51 | update: function ( props ) { |
| 52 | this.data = acf.parseArgs( props, this.data ); |
| 53 | this.render(); |
| 54 | }, |
| 55 | title: function ( title ) { |
| 56 | this.$( '.acf-modal-title h2' ).html( title ); |
| 57 | }, |
| 58 | content: function ( content ) { |
| 59 | this.$( '.acf-modal-content' ).html( content ); |
| 60 | }, |
| 61 | toolbar: function ( toolbar ) { |
| 62 | this.$( '.acf-modal-toolbar' ).html( toolbar ); |
| 63 | }, |
| 64 | open: function () { |
| 65 | $( 'body' ).append( this.$el ); |
| 66 | }, |
| 67 | close: function () { |
| 68 | this.remove(); |
| 69 | }, |
| 70 | onClickClose: function ( e, $el ) { |
| 71 | e.preventDefault(); |
| 72 | this.close(); |
| 73 | }, |
| 74 | |
| 75 | /** |
| 76 | * Places focus within the popup. |
| 77 | */ |
| 78 | focus: function() { |
| 79 | this.$el.find( '.acf-icon' ).first().trigger( 'focus' ); |
| 80 | }, |
| 81 | |
| 82 | /** |
| 83 | * Locks focus within the modal. |
| 84 | * |
| 85 | * @param {boolean} locked True to lock focus, false to unlock. |
| 86 | */ |
| 87 | lockFocusToModal: function( locked ) { |
| 88 | let inertElement = $( '#wpwrap' ); |
| 89 | |
| 90 | if ( ! inertElement.length ) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | inertElement[ 0 ].inert = locked; |
| 95 | inertElement.attr( 'aria-hidden', locked ); |
| 96 | }, |
| 97 | |
| 98 | /** |
| 99 | * Returns focus to the element that opened the popup |
| 100 | * if it still exists in the DOM. |
| 101 | */ |
| 102 | returnFocusToOrigin: function() { |
| 103 | if ( |
| 104 | this.data.openedBy instanceof $ |
| 105 | && this.data.openedBy.closest( 'body' ).length > 0 |
| 106 | ) { |
| 107 | this.data.openedBy.trigger( 'focus' ); |
| 108 | } |
| 109 | } |
| 110 | } ); |
| 111 | |
| 112 | /** |
| 113 | * Returns a new modal. |
| 114 | * |
| 115 | * @date 21/4/20 |
| 116 | * @since ACF 5.9.0 |
| 117 | * |
| 118 | * @param object props The modal props. |
| 119 | * @return object |
| 120 | */ |
| 121 | acf.newModal = function ( props ) { |
| 122 | return new acf.models.Modal( props ); |
| 123 | }; |
| 124 | } )( jQuery ); |
| 125 |