PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.2
Secure Custom Fields v6.4.2
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-field-oembed.js
secure-custom-fields / assets / src / js Last commit date
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-field-oembed.js
155 lines
1 ( function ( $, undefined ) {
2 var Field = acf.Field.extend( {
3 type: 'oembed',
4
5 events: {
6 'click [data-name="clear-button"]': 'onClickClear',
7 'keypress .input-search': 'onKeypressSearch',
8 'keyup .input-search': 'onKeyupSearch',
9 'change .input-search': 'onChangeSearch',
10 },
11
12 $control: function () {
13 return this.$( '.acf-oembed' );
14 },
15
16 $input: function () {
17 return this.$( '.input-value' );
18 },
19
20 $search: function () {
21 return this.$( '.input-search' );
22 },
23
24 getValue: function () {
25 return this.$input().val();
26 },
27
28 getSearchVal: function () {
29 return this.$search().val();
30 },
31
32 setValue: function ( val ) {
33 // class
34 if ( val ) {
35 this.$control().addClass( 'has-value' );
36 } else {
37 this.$control().removeClass( 'has-value' );
38 }
39
40 acf.val( this.$input(), val );
41 },
42
43 showLoading: function ( show ) {
44 acf.showLoading( this.$( '.canvas' ) );
45 },
46
47 hideLoading: function () {
48 acf.hideLoading( this.$( '.canvas' ) );
49 },
50
51 maybeSearch: function () {
52 // vars
53 var prevUrl = this.val();
54 var url = this.getSearchVal();
55
56 // no value
57 if ( ! url ) {
58 return this.clear();
59 }
60
61 // fix missing 'http://' - causes the oembed code to error and fail
62 if ( url.substr( 0, 4 ) != 'http' ) {
63 url = 'http://' + url;
64 }
65
66 // bail early if no change
67 if ( url === prevUrl ) return;
68
69 // clear existing timeout
70 var timeout = this.get( 'timeout' );
71 if ( timeout ) {
72 clearTimeout( timeout );
73 }
74
75 // set new timeout
76 var callback = $.proxy( this.search, this, url );
77 this.set( 'timeout', setTimeout( callback, 300 ) );
78 },
79
80 search: function ( url ) {
81 const ajaxData = {
82 action: 'acf/fields/oembed/search',
83 s: url,
84 field_key: this.get( 'key' ),
85 nonce: this.get( 'nonce' ),
86 };
87
88 // clear existing timeout
89 let xhr = this.get( 'xhr' );
90 if ( xhr ) {
91 xhr.abort();
92 }
93
94 // loading
95 this.showLoading();
96
97 // query
98 xhr = $.ajax( {
99 url: acf.get( 'ajaxurl' ),
100 data: acf.prepareForAjax( ajaxData ),
101 type: 'post',
102 dataType: 'json',
103 context: this,
104 success: function ( json ) {
105 // error
106 if ( ! json || ! json.html ) {
107 json = {
108 url: false,
109 html: '',
110 };
111 }
112
113 // update vars
114 this.val( json.url );
115 this.$( '.canvas-media' ).html( json.html );
116 },
117 complete: function () {
118 this.hideLoading();
119 },
120 } );
121
122 this.set( 'xhr', xhr );
123 },
124
125 clear: function () {
126 this.val( '' );
127 this.$search().val( '' );
128 this.$( '.canvas-media' ).html( '' );
129 },
130
131 onClickClear: function ( e, $el ) {
132 this.clear();
133 },
134
135 onKeypressSearch: function ( e, $el ) {
136 if ( e.which == 13 ) {
137 e.preventDefault();
138 this.maybeSearch();
139 }
140 },
141
142 onKeyupSearch: function ( e, $el ) {
143 if ( $el.val() ) {
144 this.maybeSearch();
145 }
146 },
147
148 onChangeSearch: function ( e, $el ) {
149 this.maybeSearch();
150 },
151 } );
152
153 acf.registerFieldType( Field );
154 } )( jQuery );
155