pro
1 year ago
_acf-compatibility.js
1 year ago
_acf-condition-types.js
1 year ago
_acf-condition.js
1 year ago
_acf-conditions.js
1 year ago
_acf-field-accordion.js
1 year ago
_acf-field-button-group.js
1 year ago
_acf-field-checkbox.js
1 year ago
_acf-field-color-picker.js
1 year ago
_acf-field-date-picker.js
1 year ago
_acf-field-date-time-picker.js
1 year ago
_acf-field-file.js
1 year ago
_acf-field-google-map.js
1 year ago
_acf-field-icon-picker.js
1 year ago
_acf-field-image.js
1 year ago
_acf-field-link.js
1 year ago
_acf-field-oembed.js
1 year ago
_acf-field-page-link.js
1 year ago
_acf-field-post-object.js
1 year ago
_acf-field-radio.js
1 year ago
_acf-field-range.js
1 year ago
_acf-field-relationship.js
1 year ago
_acf-field-select.js
1 year ago
_acf-field-tab.js
1 year ago
_acf-field-taxonomy.js
1 year ago
_acf-field-time-picker.js
1 year ago
_acf-field-true-false.js
1 year ago
_acf-field-url.js
1 year ago
_acf-field-user.js
1 year ago
_acf-field-wysiwyg.js
1 year 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
1 year ago
_acf-media.js
1 year ago
_acf-modal.js
1 year ago
_acf-model.js
1 year ago
_acf-notice.js
1 year ago
_acf-panel.js
1 year ago
_acf-popup.js
1 year ago
_acf-postbox.js
1 year ago
_acf-screen.js
1 year ago
_acf-select2.js
1 year ago
_acf-tinymce.js
1 year ago
_acf-tooltip.js
1 year ago
_acf-unload.js
1 year ago
_acf-validation.js
1 year ago
_acf.js
1 year ago
_browse-fields-modal.js
1 year ago
_field-group-compatibility.js
1 year ago
_field-group-conditions.js
1 year ago
_field-group-field.js
1 year ago
_field-group-fields.js
1 year ago
_field-group-locations.js
1 year ago
_field-group-settings.js
1 year ago
_field-group.js
1 year 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-popup.js
164 lines
| 1 | ( function ( $, undefined ) { |
| 2 | acf.models.Popup = acf.Model.extend( { |
| 3 | data: { |
| 4 | title: '', |
| 5 | content: '', |
| 6 | width: 0, |
| 7 | height: 0, |
| 8 | loading: false, |
| 9 | openedBy: null, |
| 10 | }, |
| 11 | |
| 12 | events: { |
| 13 | 'click [data-event="close"]': 'onClickClose', |
| 14 | 'click .acf-close-popup': 'onClickClose', |
| 15 | 'keydown': 'onPressEscapeClose', |
| 16 | }, |
| 17 | |
| 18 | setup: function ( props ) { |
| 19 | $.extend( this.data, props ); |
| 20 | this.$el = $( this.tmpl() ); |
| 21 | }, |
| 22 | |
| 23 | initialize: function () { |
| 24 | this.render(); |
| 25 | this.open(); |
| 26 | this.focus(); |
| 27 | this.lockFocusToPopup( true ); |
| 28 | }, |
| 29 | |
| 30 | tmpl: function () { |
| 31 | return [ |
| 32 | '<div id="acf-popup" role="dialog" tabindex="-1">', |
| 33 | '<div class="acf-popup-box acf-box">', |
| 34 | '<div class="title"><h3></h3><a href="#" class="acf-icon -cancel grey" data-event="close" aria-label="' + acf.__('Close modal') + '"></a></div>', |
| 35 | '<div class="inner"></div>', |
| 36 | '<div class="loading"><i class="acf-loading"></i></div>', |
| 37 | '</div>', |
| 38 | '<div class="bg" data-event="close"></div>', |
| 39 | '</div>', |
| 40 | ].join( '' ); |
| 41 | }, |
| 42 | |
| 43 | render: function () { |
| 44 | // Extract Vars. |
| 45 | var title = this.get( 'title' ); |
| 46 | var content = this.get( 'content' ); |
| 47 | var loading = this.get( 'loading' ); |
| 48 | var width = this.get( 'width' ); |
| 49 | var height = this.get( 'height' ); |
| 50 | |
| 51 | // Update. |
| 52 | this.title( title ); |
| 53 | this.content( content ); |
| 54 | if ( width ) { |
| 55 | this.$( '.acf-popup-box' ).css( 'width', width ); |
| 56 | } |
| 57 | if ( height ) { |
| 58 | this.$( '.acf-popup-box' ).css( 'min-height', height ); |
| 59 | } |
| 60 | this.loading( loading ); |
| 61 | |
| 62 | // Trigger action. |
| 63 | acf.doAction( 'append', this.$el ); |
| 64 | }, |
| 65 | |
| 66 | /** |
| 67 | * Places focus within the popup. |
| 68 | */ |
| 69 | focus: function() { |
| 70 | this.$el.find( '.acf-icon' ).first().trigger( 'focus' ); |
| 71 | }, |
| 72 | |
| 73 | /** |
| 74 | * Locks focus within the popup. |
| 75 | * |
| 76 | * @param {boolean} locked True to lock focus, false to unlock. |
| 77 | */ |
| 78 | lockFocusToPopup: function( locked ) { |
| 79 | let inertElement = $( '#wpwrap' ); |
| 80 | |
| 81 | if ( ! inertElement.length ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | inertElement[ 0 ].inert = locked; |
| 86 | inertElement.attr( 'aria-hidden', locked ); |
| 87 | }, |
| 88 | |
| 89 | update: function ( props ) { |
| 90 | this.data = acf.parseArgs( props, this.data ); |
| 91 | this.render(); |
| 92 | }, |
| 93 | |
| 94 | title: function ( title ) { |
| 95 | this.$( '.title:first h3' ).html( title ); |
| 96 | }, |
| 97 | |
| 98 | content: function ( content ) { |
| 99 | this.$( '.inner:first' ).html( content ); |
| 100 | }, |
| 101 | |
| 102 | loading: function ( show ) { |
| 103 | var $loading = this.$( '.loading:first' ); |
| 104 | show ? $loading.show() : $loading.hide(); |
| 105 | }, |
| 106 | |
| 107 | open: function () { |
| 108 | $( 'body' ).append( this.$el ); |
| 109 | }, |
| 110 | |
| 111 | close: function () { |
| 112 | this.lockFocusToPopup( false ); |
| 113 | this.returnFocusToOrigin(); |
| 114 | this.remove(); |
| 115 | }, |
| 116 | |
| 117 | onClickClose: function ( e, $el ) { |
| 118 | e.preventDefault(); |
| 119 | this.close(); |
| 120 | }, |
| 121 | |
| 122 | /** |
| 123 | * Closes the popup when the escape key is pressed. |
| 124 | * |
| 125 | * @param {KeyboardEvent} e |
| 126 | */ |
| 127 | onPressEscapeClose: function( e ) { |
| 128 | if ( e.key === 'Escape' ) { |
| 129 | this.close(); |
| 130 | } |
| 131 | }, |
| 132 | |
| 133 | /** |
| 134 | * Returns focus to the element that opened the popup |
| 135 | * if it still exists in the DOM. |
| 136 | */ |
| 137 | returnFocusToOrigin: function() { |
| 138 | if ( |
| 139 | this.data.openedBy instanceof $ |
| 140 | && this.data.openedBy.closest( 'body' ).length > 0 |
| 141 | ) { |
| 142 | this.data.openedBy.trigger( 'focus' ); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | } ); |
| 147 | |
| 148 | /** |
| 149 | * newPopup |
| 150 | * |
| 151 | * Creates a new Popup with the supplied props |
| 152 | * |
| 153 | * @date 17/12/17 |
| 154 | * @since ACF 5.6.5 |
| 155 | * |
| 156 | * @param object props |
| 157 | * @return object |
| 158 | */ |
| 159 | |
| 160 | acf.newPopup = function ( props ) { |
| 161 | return new acf.models.Popup( props ); |
| 162 | }; |
| 163 | } )( jQuery ); |
| 164 |