PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.5.1
WP Coder – Insert & Manage Code Snippets v3.5.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / assets / js / admin-jquery.js

admin-jquery.js in WP Coder – Insert & Manage Code Snippets 3.5.1, at assets/js/admin-jquery.js

284 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 jQuery(function ($) {
4
5
6 // All checkboxes
7 $('.wowp-settings').on('click', 'input:checkbox', function () {
8 checkboxchecked(this);
9 });
10
11 function checkboxchecked(el) {
12 if ($(el).prop('checked')) {
13 $(el).next('input[type="hidden"]').val('1');
14 } else {
15 $(el).next('input[type="hidden"]').val('');
16 }
17 }
18
19 // Languages options
20 $('[data-option="depending_language"] input[type="checkbox"]').each(languageOn);
21 $('[data-option="depending_language"] input[type="checkbox"]').on('click', languageOn);
22
23 function languageOn() {
24 const languages = $(this).parents('.wowp-field').siblings('.wowp-field');
25 if ($(this).is(':checked')) {
26 $(languages).removeClass('is-hidden');
27 } else {
28 $(languages).addClass('is-hidden');
29 }
30 }
31
32 // Users
33 $('[name="param[item_user]"]').each(usersRule);
34 $('[name="param[item_user]"]').on('change', usersRule);
35
36 function usersRule() {
37 const user = $(this).val();
38 const parent = $(this).closest('fieldset');
39 const boxRoles = $(parent).find('.wowp-users-roles');
40 $(boxRoles).addClass('is-hidden');
41 if (user === '2') {
42 $(boxRoles).removeClass('is-hidden');
43 }
44 }
45
46 $('.wowp-users-roles .wowp-field:first input:first').each(checkAllRoles);
47 $('.wowp-users-roles .wowp-field:first input:first').on('change', checkAllRoles);
48
49 function checkAllRoles() {
50 const checkboxes = $('.wowp-users-roles input[type="checkbox"]');
51 if ($(this).is(':checked')) {
52 $(checkboxes).prop('checked', true);
53 }
54 }
55
56 // Schedule options
57 $('.wowp-dates input[type="checkbox"]').each(datesSchedule);
58 $('#schedule').on('click', '.wowp-dates input', datesSchedule);
59
60 function datesSchedule() {
61 const parent = $(this).closest('.wowp-fields-group');
62 if ($(this).is(':checked')) {
63 $(parent).find('.wowp-date-input').removeClass('is-hidden');
64 } else {
65 $(parent).find('.wowp-date-input').addClass('is-hidden');
66 }
67 }
68
69 $('#add-schedule').on('click', function (e) {
70 e.preventDefault();
71
72 const temlate = $('#clone-schedule').clone().html();
73
74 $(temlate).insertBefore('#schedule .wowp-btn-actions');
75 $('.wowp-dates input[type="checkbox"]').each(datesSchedule);
76 });
77
78 $('#schedule').on('click', '.dashicons-trash', function () {
79 const parent = $(this).closest('.wowp-fields-group');
80 $(parent).remove();
81 });
82
83 // Display rules
84 $('#add_display').on('click', function (e) {
85 e.preventDefault();
86
87 const temlate = $('#template-display').clone().html();
88
89 $(temlate).insertBefore('#display-rules .btn-add-display');
90 $('#display-rules .display-option select').each(displayRules);
91 });
92
93 $('#display-rules').on('click', '.dashicons-trash', function () {
94 const parent = $(this).closest('.wowp-fields-group');
95 $(parent).remove();
96 });
97
98 $('#display-rules .display-option select').each(displayRules);
99 $('#display-rules').on('change', '.display-option select', displayRules);
100
101 function displayRules() {
102 let type = $(this).val();
103 const parent = $(this).closest('.wowp-fields-group');
104 $(parent).find('.display-operator, .display-ids, .display-pages').addClass('is-hidden');
105 if (type.indexOf('custom_post_selected') !== -1) {
106 type = 'post_selected';
107 }
108 if (type.indexOf('custom_post_tax') !== -1) {
109 type = 'post_category';
110 }
111 switch (type) {
112 case 'post_selected':
113 case 'post_category':
114 case 'page_selected':
115 $(parent).find('.display-operator, .display-ids').removeClass('is-hidden');
116 break;
117 case 'page_type':
118 $(parent).find('.display-operator, .display-pages').removeClass('is-hidden');
119 break;
120 }
121
122 }
123
124 // Includes Assets files
125 $('#add-include').on('click', function (e) {
126 e.preventDefault();
127
128 const temlate = $('#clone-includes').clone().html();
129
130 $(temlate).insertBefore('#includes-files .btn-add-display');
131 $('#includes-files .display-option select').each(includeFiles);
132 });
133
134 $('#includes-files').on('click', '.dashicons-trash', function () {
135 const parent = $(this).closest('.wowp-fields-group');
136 $(parent).remove();
137 });
138
139 $('#includes-files .display-option select').each(includeFiles);
140 $('#includes-files').on('change', '.display-option select', includeFiles);
141
142 function includeFiles() {
143 let type = $(this).val();
144 const parent = $(this).closest('.wowp-fields-group');
145 $(parent).find('.js-attr').addClass('is-hidden');
146
147 console.log(type);
148
149 switch (type) {
150 case 'css':
151 $(parent).find('.js-attr').addClass('is-hidden');
152 break;
153 case 'js':
154 $(parent).find('.js-attr').removeClass('is-hidden');
155 break;
156 }
157
158 }
159
160 // Dequeue Assets files
161 $('#add-dequeue').on('click', function (e) {
162 e.preventDefault();
163
164 const temlate = $('#clone-dequeue').clone().html();
165
166 $(temlate).insertBefore('#dequeue .btn-add-display');
167 });
168
169 $('#dequeue').on('click', '.dashicons-trash', function () {
170 const parent = $(this).closest('.wowp-fields-group');
171 $(parent).remove();
172 });
173
174 // Add shortcode attributes
175 $('#add-attribute').on('click', function (e) {
176 e.preventDefault();
177 const temlate = $('#clone-attributes').clone().html();
178 $(temlate).insertBefore('#code-attributes .btn-add-display');
179 });
180
181 $('#code-attributes').on('click', '.dashicons-trash', function () {
182 const parent = $(this).closest('.wowp-fields-group');
183 $(parent).remove();
184 });
185
186 $('.button-add-img').on('click', function (event) {
187 event.preventDefault();
188 var upload_button = $(this);
189 var img = $(this).data('img');
190 var frame;
191 event.preventDefault();
192 if (frame) {
193 frame.open();
194 return;
195 }
196 frame = wp.media();
197 frame.on('select', function () {
198 // Grab the selected attachment.
199 const attachment = frame.state().get('selection').first();
200 let url = attachment.attributes.url;
201 url = url.replace('-scaled.', '.');
202 let alt = attachment.attributes.alt;
203 let title = attachment.attributes.title;
204 let height = attachment.attributes.height;
205 let width = attachment.attributes.width;
206 let img = `<img src="${url}" alt="${alt}" loading="lazy" width="${width}" height="${height}">`;
207 frame.close();
208 const editorElement = $('[data-content="html-code"]').find('.CodeMirror')[0];
209 const editor = editorElement.CodeMirror;
210 const doc = editor.getDoc();
211 const cursor = doc.getCursor();
212 doc.replaceRange(img, cursor);
213 editor.focus();
214
215 });
216 frame.open();
217
218 });
219
220 $('.button-editor').not('#phpglobalnav').on('click', function (event) {
221 event.preventDefault();
222 const parent = $(this).closest('.tab-content');
223 const id = $(this).attr('id');
224 let comment;
225 switch (id) {
226 case 'jsnav':
227 case 'phpnav':
228 comment = '// NAV: ';
229 break;
230 case 'htmlnav':
231 comment = '<!-- NAV: -->';
232 break;
233 case 'cssnav':
234 comment = '/* NAV: */';
235 break;
236 }
237
238 const editorElement = $(parent).find('.CodeMirror')[0];
239 const editor = editorElement.CodeMirror;
240 const doc = editor.getDoc();
241 const cursor = doc.getCursor();
242 doc.replaceRange(comment, cursor);
243 editor.focus();
244 });
245
246 $('#phpglobalnav').on('click', function (event) {
247 event.preventDefault();
248 const parent = $(this).closest('fieldset');
249 let comment = '// NAV: ';
250 const editorElement = $(parent).find('.CodeMirror')[0];
251 const editor = editorElement.CodeMirror;
252 const doc = editor.getDoc();
253 const cursor = doc.getCursor();
254 doc.replaceRange(comment, cursor);
255 editor.focus();
256 });
257
258 $('.wowp-copy').on('click', function () {
259 const copyText = $(this).closest('.wowp-input-group').find('input')[0];
260
261 copyText.select();
262 copyText.setSelectionRange(0, 99999); // For mobile devices
263
264 // Copy the text inside the text field
265 navigator.clipboard.writeText(copyText.value);
266
267 // Alert the copied text
268 alert("Copied the shortcode: " + copyText.value);
269 });
270
271 $('.wowp-shortcode-copy').on('click', function () {
272 const copyText = $(this).closest('.wowp-field').find('input')[0];
273
274 copyText.select();
275 copyText.setSelectionRange(0, 99999); // For mobile devices
276
277 // Copy the text inside the text field
278 navigator.clipboard.writeText(copyText.value);
279
280 // Alert the copied text
281 alert("Copied the shortcode: " + copyText.value);
282 });
283
284 });