PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
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
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
_acf-field-oembed.js
162 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 this.$search().val( val || '' );
42
43 if ( val ) {
44 this.maybeSearch();
45 } else {
46 this.$( '.canvas-media' ).html( '' );
47 }
48 },
49
50 showLoading: function ( show ) {
51 acf.showLoading( this.$( '.canvas' ) );
52 },
53
54 hideLoading: function () {
55 acf.hideLoading( this.$( '.canvas' ) );
56 },
57
58 maybeSearch: function () {
59 // vars
60 var prevUrl = this.val();
61 var url = this.getSearchVal();
62
63 // no value
64 if ( ! url ) {
65 return this.clear();
66 }
67
68 // fix missing 'http://' - causes the oembed code to error and fail
69 if ( url.substr( 0, 4 ) != 'http' ) {
70 url = 'http://' + url;
71 }
72
73 // bail early if no change
74 if ( url === prevUrl ) return;
75
76 // clear existing timeout
77 var timeout = this.get( 'timeout' );
78 if ( timeout ) {
79 clearTimeout( timeout );
80 }
81
82 // set new timeout
83 var callback = $.proxy( this.search, this, url );
84 this.set( 'timeout', setTimeout( callback, 300 ) );
85 },
86
87 search: function ( url ) {
88 const ajaxData = {
89 action: 'acf/fields/oembed/search',
90 s: url,
91 field_key: this.get( 'key' ),
92 nonce: this.get( 'nonce' ),
93 };
94
95 // clear existing timeout
96 let xhr = this.get( 'xhr' );
97 if ( xhr ) {
98 xhr.abort();
99 }
100
101 // loading
102 this.showLoading();
103
104 // query
105 xhr = $.ajax( {
106 url: acf.get( 'ajaxurl' ),
107 data: acf.prepareForAjax( ajaxData ),
108 type: 'post',
109 dataType: 'json',
110 context: this,
111 success: function ( json ) {
112 // error
113 if ( ! json || ! json.html ) {
114 json = {
115 url: false,
116 html: '',
117 };
118 }
119
120 // update vars
121 this.val( json.url );
122 this.$( '.canvas-media' ).html( json.html );
123 },
124 complete: function () {
125 this.hideLoading();
126 },
127 } );
128
129 this.set( 'xhr', xhr );
130 },
131
132 clear: function () {
133 this.val( '' );
134 this.$search().val( '' );
135 this.$( '.canvas-media' ).html( '' );
136 },
137
138 onClickClear: function ( e, $el ) {
139 this.clear();
140 },
141
142 onKeypressSearch: function ( e, $el ) {
143 if ( e.which == 13 ) {
144 e.preventDefault();
145 this.maybeSearch();
146 }
147 },
148
149 onKeyupSearch: function ( e, $el ) {
150 if ( $el.val() ) {
151 this.maybeSearch();
152 }
153 },
154
155 onChangeSearch: function ( e, $el ) {
156 this.maybeSearch();
157 },
158 } );
159
160 acf.registerFieldType( Field );
161 } )( jQuery );
162