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-field-link.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 2 weeks ago pro 2 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 2 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-field-link.js
189 lines
1 ( function ( $, undefined ) {
2 var Field = acf.Field.extend( {
3 type: 'link',
4
5 events: {
6 'click a[data-name="add"]': 'onClickEdit',
7 'click a[data-name="edit"]': 'onClickEdit',
8 'click a[data-name="remove"]': 'onClickRemove',
9 'change .link-node': 'onChange',
10 },
11
12 $control: function () {
13 return this.$( '.acf-link' );
14 },
15
16 $node: function () {
17 return this.$( '.link-node' );
18 },
19
20 getValue: function () {
21 // vars
22 var $node = this.$node();
23
24 // return false if empty
25 if ( ! $node.attr( 'href' ) ) {
26 return false;
27 }
28
29 // return
30 return {
31 title: $node.html(),
32 url: $node.attr( 'href' ),
33 target: $node.attr( 'target' ),
34 };
35 },
36
37 setValue: function ( val ) {
38 // default
39 val = acf.parseArgs( val, {
40 title: '',
41 url: '',
42 target: '',
43 } );
44
45 // vars
46 var $div = this.$control();
47 var $node = this.$node();
48
49 // remove class
50 $div.removeClass( '-value -external' );
51
52 // add class
53 if ( val.url ) $div.addClass( '-value' );
54 if ( val.target === '_blank' ) $div.addClass( '-external' );
55
56 // update text
57 this.$( '.link-title' ).html( val.title );
58 this.$( '.link-url' ).attr( 'href', val.url ).text( val.url );
59
60 // update node
61 $node.html( val.title );
62 $node.attr( 'href', val.url );
63 $node.attr( 'target', val.target );
64
65 // update inputs
66 this.$( '.input-title' ).val( val.title );
67 this.$( '.input-target' ).val( val.target );
68 this.$( '.input-url' ).val( val.url ).trigger( 'change' );
69 },
70
71 onClickEdit: function ( e, $el ) {
72 acf.wpLink.open( this.$node() );
73 },
74
75 onClickRemove: function ( e, $el ) {
76 this.setValue( false );
77 },
78
79 onChange: function ( e, $el ) {
80 // get the changed value
81 var val = this.getValue();
82
83 // update inputs
84 this.setValue( val );
85 },
86 } );
87
88 acf.registerFieldType( Field );
89
90 // manager
91 acf.wpLink = new acf.Model( {
92 getNodeValue: function () {
93 var $node = this.get( 'node' );
94 return {
95 title: acf.decode( $node.html() ),
96 url: $node.attr( 'href' ),
97 target: $node.attr( 'target' ),
98 };
99 },
100
101 setNodeValue: function ( val ) {
102 var $node = this.get( 'node' );
103 $node.text( val.title );
104 $node.attr( 'href', val.url );
105 $node.attr( 'target', val.target );
106 $node.trigger( 'change' );
107 },
108
109 getInputValue: function () {
110 return {
111 title: $( '#wp-link-text' ).val(),
112 url: $( '#wp-link-url' ).val(),
113 target: $( '#wp-link-target' ).prop( 'checked' )
114 ? '_blank'
115 : '',
116 };
117 },
118
119 setInputValue: function ( val ) {
120 $( '#wp-link-text' ).val( val.title );
121 $( '#wp-link-url' ).val( val.url );
122 $( '#wp-link-target' ).prop( 'checked', val.target === '_blank' );
123 },
124
125 open: function ( $node ) {
126 // add events
127 this.on( 'wplink-open', 'onOpen' );
128 this.on( 'wplink-close', 'onClose' );
129
130 // set node
131 this.set( 'node', $node );
132
133 // create textarea
134 var $textarea = $(
135 '<textarea id="acf-link-textarea" style="display:none;"></textarea>'
136 );
137 $( 'body' ).append( $textarea );
138
139 // vars
140 var val = this.getNodeValue();
141
142 // open popup
143 wpLink.open( 'acf-link-textarea', val.url, val.title, null );
144 },
145
146 onOpen: function () {
147 // always show title (WP will hide title if empty)
148 $( '#wp-link-wrap' ).addClass( 'has-text-field' );
149
150 // set inputs
151 var val = this.getNodeValue();
152 this.setInputValue( val );
153
154 // Update button text.
155 if ( val.url && wpLinkL10n ) {
156 $( '#wp-link-submit' ).val( wpLinkL10n.update );
157 }
158 },
159
160 close: function () {
161 wpLink.close();
162 },
163
164 onClose: function () {
165 // Bail early if no node.
166 // Needed due to WP triggering this event twice.
167 if ( ! this.has( 'node' ) ) {
168 return false;
169 }
170
171 // Determine context.
172 var $submit = $( '#wp-link-submit' );
173 var isSubmit = $submit.is( ':hover' ) || $submit.is( ':focus' );
174
175 // Set value
176 if ( isSubmit ) {
177 var val = this.getInputValue();
178 this.setNodeValue( val );
179 }
180
181 // Cleanup.
182 this.off( 'wplink-open' );
183 this.off( 'wplink-close' );
184 $( '#acf-link-textarea' ).remove();
185 this.set( 'node', null );
186 },
187 } );
188 } )( jQuery );
189