PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _acf-popup.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 3 weeks ago pro 3 weeks ago _acf-compatibility.js 1 year ago _acf-condition-types.js 8 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 8 months ago _acf-field-checkbox.js 1 month ago _acf-field-color-picker.js 8 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 1 month ago _acf-field-taxonomy.js 8 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 8 months ago _acf-media.js 3 weeks ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 8 months ago _acf-panel.js 1 year ago _acf-popup.js 8 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 8 months ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 4 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-popup.js
264 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 confirmRemove: false,
11 },
12
13 events: {
14 'click [data-event="close"]': 'onClickClose',
15 'click .acf-close-popup': 'onClickClose',
16 keydown: 'onPressEscapeClose',
17 },
18
19 setup: function ( props ) {
20 $.extend( this.data, props );
21 this.$el = $( this.tmpl() );
22 },
23
24 initialize: function () {
25 this.render();
26 this.open();
27 this.focus();
28 this.lockFocusToPopup( true );
29 },
30
31 tmpl: function () {
32 return [
33 '<div id="acf-popup" role="dialog" tabindex="-1">',
34 '<div class="acf-popup-box acf-box">',
35 '<div class="title"><h3></h3><a href="#" class="acf-icon -cancel grey" data-event="close" aria-label="' +
36 acf.__( 'Close modal' ) +
37 '"></a></div>',
38 '<div class="inner"></div>',
39 '<div class="loading"><i class="acf-loading"></i></div>',
40 '</div>',
41 '<div class="bg" data-event="close"></div>',
42 '</div>',
43 ].join( '' );
44 },
45
46 render: function () {
47 // Extract Vars.
48 var title = this.get( 'title' );
49 var content = this.get( 'content' );
50 var loading = this.get( 'loading' );
51 var width = this.get( 'width' );
52 var height = this.get( 'height' );
53
54 // Update.
55 this.title( title );
56 this.content( content );
57 if ( width ) {
58 this.$( '.acf-popup-box' ).css( 'width', width );
59 }
60 if ( height ) {
61 this.$( '.acf-popup-box' ).css( 'min-height', height );
62 }
63 this.loading( loading );
64
65 // Trigger action.
66 acf.doAction( 'append', this.$el );
67 },
68
69 /**
70 * Places focus within the popup.
71 */
72 focus: function () {
73 this.$el.find( '.acf-icon' ).first().trigger( 'focus' );
74 },
75
76 /**
77 * Locks focus within the popup.
78 *
79 * @param {boolean} locked True to lock focus, false to unlock.
80 */
81 lockFocusToPopup: function ( locked ) {
82 let inertElement = $( '#wpwrap' );
83
84 if ( ! inertElement.length ) {
85 return;
86 }
87
88 inertElement[ 0 ].inert = locked;
89 inertElement.attr( 'aria-hidden', locked );
90 },
91
92 update: function ( props ) {
93 this.data = acf.parseArgs( props, this.data );
94 this.render();
95 },
96
97 title: function ( title ) {
98 this.$( '.title:first h3' ).html( title );
99 },
100
101 content: function ( content ) {
102 this.$( '.inner:first' ).html( content );
103 },
104
105 loading: function ( show ) {
106 var $loading = this.$( '.loading:first' );
107 show ? $loading.show() : $loading.hide();
108 },
109
110 open: function () {
111 $( 'body' ).append( this.$el );
112 },
113
114 close: function () {
115 this.lockFocusToPopup( false );
116 this.returnFocusToOrigin();
117 this.remove();
118 },
119
120 onClickClose: function ( e, $el ) {
121 e.preventDefault();
122 this.close();
123 },
124
125 /**
126 * Closes the popup when the escape key is pressed.
127 *
128 * @param {KeyboardEvent} e
129 */
130 onPressEscapeClose: function ( e ) {
131 if ( e.key === 'Escape' ) {
132 this.close();
133 }
134 },
135
136 /**
137 * Returns focus to the element that opened the popup
138 * if it still exists in the DOM.
139 */
140 returnFocusToOrigin: function () {
141 if (
142 this.data.openedBy instanceof $ &&
143 this.data.openedBy.closest( 'body' ).length > 0
144 ) {
145 this.data.openedBy.trigger( 'focus' );
146 }
147 },
148 } );
149
150 /**
151 * PopupConfirm
152 *
153 * Extends the Popup model to provide confirmation functionality
154 *
155 * @date 17/12/17
156 * @since ACF 5.6.5
157 */
158
159 acf.models.PopupConfirm = acf.models.Popup.extend( {
160 data: {
161 text: '',
162 textConfirm: '',
163 textCancel: '',
164 context: false,
165 confirm: function () {},
166 cancel: function () {},
167 },
168
169 events: {
170 'click [data-event="close"]': 'onCancel',
171 'click .acf-close-popup': 'onClickClose',
172 keydown: 'onPressEscapeClose',
173 'click [data-event="confirm"]': 'onConfirm',
174 },
175
176 tmpl: function () {
177 return `
178 <div id="acf-popup" role="dialog" tabindex="-1">
179 <div class="acf-popup-box acf-box acf-confirm-popup">
180 <div class="title">
181 <h3>${ this.get( 'title' ) }</h3>
182 <a href="#" data-event="close" aria-label="${ acf.__(
183 'Close modal'
184 ) }">
185 <i class="acf-icon -close"></i>
186 </a>
187 </div>
188 <div class="inner">
189 <p>${ acf.escHtml( this.get( 'text' ) ) }</p>
190 <div class="acf-actions">
191 <button tabindex="0" type="button" data-event="close" class="acf-btn acf-btn-secondary acf-close-popup">${ acf.strEscape(
192 this.get( 'textCancel' )
193 ) }</button>
194 <button tabindex="0" type="submit" data-event="confirm" class="acf-btn acf-btn-primary acf-confirm">${ acf.strEscape(
195 this.get( 'textConfirm' )
196 ) }</button>
197 </div>
198 </div>
199 </div>
200 <div class="bg" data-event="close"></div>
201 </div>`;
202 },
203
204 render: function () {
205 const loading = this.get( 'loading' );
206 const width = this.get( 'width' );
207 const height = this.get( 'height' );
208 const self = this;
209
210 if ( width ) {
211 this.$( '.acf-popup-box' ).css( 'width', width );
212 }
213 if ( height ) {
214 this.$( '.acf-popup-box' ).css( 'min-height', height );
215 }
216
217 this.loading( loading );
218 acf.doAction( 'append', this.$el );
219
220 setTimeout( function () {
221 self.$el.find( '.acf-close-popup' ).trigger( 'focus' );
222 }, 1 );
223 },
224
225 onConfirm: function ( e, $el ) {
226 e.preventDefault();
227 e.stopPropagation();
228 this.close();
229
230 const confirm = this.get( 'confirm' );
231 const context = this.get( 'context' ) || this;
232 confirm.apply( context, arguments );
233 },
234
235 onCancel: function ( e, $el ) {
236 e.preventDefault();
237 e.stopPropagation();
238 this.close();
239
240 const cancel = this.get( 'cancel' );
241 const context = this.get( 'context' ) || this;
242 cancel.apply( context, arguments );
243 },
244 } );
245
246 /**
247 * newPopup
248 *
249 * Creates a new Popup with the supplied props
250 *
251 * @date 17/12/17
252 * @since ACF 5.6.5
253 *
254 * @param object props
255 * @return object
256 */
257
258 acf.newPopup = function ( props ) {
259 return props.confirmRemove
260 ? new acf.models.PopupConfirm( props )
261 : new acf.models.Popup( props );
262 };
263 } )( jQuery );
264