PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.0
WP Coder – Insert & Manage Code Snippets v3.0
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
← All changes | assets/js/admin.js +221 -224 3.13.0 View file →
@@ -101,43 +101,9 @@
101 101 };
102 102
103 103 editorSettings.codemirror = _.extend({}, editorSettings.codemirror, codemirror_gen, codemirror_el,);
104 104
105 - const htmleditor = wp.codeEditor.initialize(html_code, editorSettings);
106 -
107 - const htmlNavigationMenu = document.getElementById("htmlNavigationMenu");
108 -
109 - htmleditor.codemirror.eachLine(function (line) {
110 - const text = line.text;
111 - if (text.startsWith("<!-- NAV:")) {
112 - let navItem = document.createElement("li");
113 - let navLink = document.createElement("a");
114 - navLink.href = "#";
115 - // navLink.innerText = text.replace("<!-- NAV:", "").trim();
116 - navLink.innerText = text.replace(/<!-- NAV:|-->|<!-- NAV: -->/g, '').trim();
117 - navLink.addEventListener("click", function (e) {
118 - e.preventDefault();
119 -
120 - // Remove existing highlights from the gutter
121 - htmleditor.codemirror.eachLine(function (l) {
122 - htmleditor.codemirror.removeLineClass(l, 'gutter', 'highlighted-gutter');
123 - });
124 -
125 - // Set cursor and scroll to line
126 - htmleditor.codemirror.setCursor(line.lineNo());
127 - let heightOfLine = htmleditor.codemirror.defaultTextHeight();
128 - let verticalPos = line.lineNo() * heightOfLine;
129 - htmleditor.codemirror.scrollTo(null, verticalPos);
130 -
131 - // Highlight the line number in the gutter
132 - htmleditor.codemirror.addLineClass(line.lineNo(), 'gutter', 'highlighted-gutter');
133 -
134 - htmleditor.codemirror.focus();
135 - });
136 - navItem.appendChild(navLink);
137 - htmlNavigationMenu.appendChild(navItem);
138 - }
139 - });
105 + wp.codeEditor.initialize(html_code, editorSettings);
140 106 }
141 107
142 108 const css_code = document.getElementById('css_code');
143 109 if (css_code) {
@@ -142,46 +108,12 @@
142 108 const css_code = document.getElementById('css_code');
143 109 if (css_code) {
144 110 let codemirror_el = {"mode": 'css',};
145 111 editorSettings.codemirror = _.extend({}, editorSettings.codemirror, codemirror_gen, codemirror_el,);
146 - // const tab = document.querySelector('[data-content="css-code"]');
147 - // tab.classList.add('tab-content-active');
148 - const csseditor = wp.codeEditor.initialize(css_code, editorSettings);
149 - // tab.classList.remove('tab-content-active');
150 -
151 - const cssNavigationMenu = document.getElementById("cssNavigationMenu");
152 -
153 - csseditor.codemirror.eachLine(function (line) {
154 - const text = line.text;
155 - if (text.startsWith("/* NAV:")) {
156 - let navItem = document.createElement("li");
157 - let navLink = document.createElement("a");
158 - navLink.href = "#";
159 - // navLink.innerText = text.replace("// NAV:", "").trim();
160 - navLink.innerText = text.replace(/\/\* NAV:|\*\/|\/\* NAV: \*\//g, '').trim();
161 - navLink.addEventListener("click", function (e) {
162 - e.preventDefault();
163 -
164 - // Remove existing highlights from the gutter
165 - csseditor.codemirror.eachLine(function (l) {
166 - csseditor.codemirror.removeLineClass(l, 'gutter', 'highlighted-gutter');
167 - });
168 -
169 - // Set cursor and scroll to line
170 - csseditor.codemirror.setCursor(line.lineNo());
171 - let heightOfLine = csseditor.codemirror.defaultTextHeight();
172 - let verticalPos = line.lineNo() * heightOfLine;
173 - csseditor.codemirror.scrollTo(null, verticalPos);
174 -
175 - // Highlight the line number in the gutter
176 - csseditor.codemirror.addLineClass(line.lineNo(), 'gutter', 'highlighted-gutter');
177 -
178 - csseditor.codemirror.focus();
179 - });
180 - navItem.appendChild(navLink);
181 - cssNavigationMenu.appendChild(navItem);
182 - }
183 - });
112 + const tab = document.querySelector('[data-content="css-code"]');
113 + tab.classList.add('tab-content-active');
114 + wp.codeEditor.initialize(css_code, editorSettings);
115 + tab.classList.remove('tab-content-active');
184 116 }
185 117
186 118 const js_code = document.getElementById('js_code');
187 119 if (js_code) {
@@ -210,191 +142,152 @@
210 142 },
211 143 "mode": 'javascript',
212 144 };
213 145 editorSettings.codemirror = _.extend({}, editorSettings.codemirror, codemirror_gen, codemirror_el,);
214 - // const tab = document.querySelector('[data-content="js-code"]');
215 - // tab.classList.add('tab-content-active');
216 - const jseditor = wp.codeEditor.initialize(js_code, editorSettings);
217 - // tab.classList.remove('tab-content-active');
146 + const tab = document.querySelector('[data-content="js-code"]');
147 + tab.classList.add('tab-content-active');
148 + wp.codeEditor.initialize(js_code, editorSettings);
149 + tab.classList.remove('tab-content-active');
150 + }
218 151
219 - const jsNavigationMenu = document.getElementById("jsNavigationMenu");
152 +}
220 153
221 - jseditor.codemirror.eachLine(function (line) {
222 - const text = line.text;
223 - if (text.startsWith("// NAV:")) {
224 - let navItem = document.createElement("li");
225 - let navLink = document.createElement("a");
226 - navLink.href = "#";
227 - navLink.innerText = text.replace("// NAV:", "").trim();
228 - navLink.addEventListener("click", function (e) {
229 - e.preventDefault();
154 +const cloneIncludes = function () {
230 155
231 - // Remove existing highlights from the gutter
232 - jseditor.codemirror.eachLine(function (l) {
233 - jseditor.codemirror.removeLineClass(l, 'gutter', 'highlighted-gutter');
234 - });
156 + const template = document.getElementById('clone-includes');
157 + if (!template) {
158 + return false;
159 + }
235 160
236 - // Set cursor and scroll to line
237 - jseditor.codemirror.setCursor(line.lineNo());
238 - let heightOfLine = jseditor.codemirror.defaultTextHeight();
239 - let verticalPos = line.lineNo() * heightOfLine;
240 - jseditor.codemirror.scrollTo(null, verticalPos);
241 -
242 - // Highlight the line number in the gutter
243 - jseditor.codemirror.addLineClass(line.lineNo(), 'gutter', 'highlighted-gutter');
244 -
245 - jseditor.codemirror.focus();
246 - });
247 - navItem.appendChild(navLink);
248 - jsNavigationMenu.appendChild(navItem);
249 - }
250 - });
161 + const addBtn = document.getElementById('add-include');
162 + if (!addBtn) {
163 + return false;
251 164 }
252 165
253 - const php_code = document.getElementById('php_code');
254 - if (php_code) {
255 - let codemirror_el = {
256 - mode: {
257 - name: 'php',
258 - startOpen: true
259 - }
260 - };
261 - editorSettings.codemirror = _.extend({}, editorSettings.codemirror, codemirror_gen, codemirror_el,);
262 - // const tab = document.querySelector('[data-content="php-code"]');
263 - // tab.classList.add('tab-content-active');
264 - const phpeditor = wp.codeEditor.initialize(php_code, editorSettings);
265 - // tab.classList.remove('tab-content-active');
166 + addBtn.addEventListener('click', (event) => {
167 + event.preventDefault();
168 + const clone = template.content.cloneNode(true);
169 + const targetElement = document.getElementById('includes-files');
170 + targetElement.appendChild(clone);
171 + });
266 172
267 - const phpNavigationMenu = document.getElementById("phpNavigationMenu");
173 +}
268 174
269 - phpeditor.codemirror.eachLine(function (line) {
270 - const text = line.text;
271 - if (text.startsWith("// NAV:")) {
272 - let navItem = document.createElement("li");
273 - let navLink = document.createElement("a");
274 - navLink.href = "#";
275 - navLink.innerText = text.replace("// NAV:", "").trim();
276 - navLink.addEventListener("click", function (e) {
277 - e.preventDefault();
175 +const removeLast = function () {
176 + const btn = document.getElementById('remove-include');
177 + if (!btn) {
178 + return false;
179 + }
278 180
279 - // Remove existing highlights from the gutter
280 - phpeditor.codemirror.eachLine(function (l) {
281 - phpeditor.codemirror.removeLineClass(l, 'gutter', 'highlighted-gutter');
282 - });
181 + btn.addEventListener('click', (event) => {
182 + event.preventDefault();
183 + const parentElement = document.getElementById('includes-files');
184 + const lastChild = parentElement.querySelector('.wowp-fields-group:last-child');
185 + if (lastChild) {
186 + lastChild.remove();
187 + }
188 + });
283 189
284 - // Set cursor and scroll to line
285 - phpeditor.codemirror.setCursor(line.lineNo());
286 - let heightOfLine = phpeditor.codemirror.defaultTextHeight();
287 - let verticalPos = line.lineNo() * heightOfLine;
288 - phpeditor.codemirror.scrollTo(null, verticalPos);
289 190
290 - // Highlight the line number in the gutter
291 - phpeditor.codemirror.addLineClass(line.lineNo(), 'gutter', 'highlighted-gutter');
191 +}
292 192
293 - phpeditor.codemirror.focus();
294 - });
295 - navItem.appendChild(navLink);
296 - phpNavigationMenu.appendChild(navItem);
297 - }
298 - });
193 +const changeIncludes = function () {
194 + const parentContainer = document.getElementById('includes-files');
195 + if (!parentContainer) {
196 + return false;
299 197 }
300 198
301 - const global_php = document.getElementById('wpcoder-global-php');
302 - if (global_php) {
303 - let codemirror_el = {
304 - mode: {
305 - name: 'php',
306 - startOpen: true,
199 + parentContainer.addEventListener('change', function (event) {
307 200
308 - },
309 - firstLineNumber: 4,
310 - };
311 - editorSettings.codemirror = _.extend({}, editorSettings.codemirror, codemirror_gen, codemirror_el,);
312 - const editor = wp.codeEditor.initialize(global_php, editorSettings);
201 + // Check if the clicked element matches the desired selector
202 + if (event.target.matches('[name^="param[include]"]')) {
203 + const el = event.target.value;
204 + const parent = event.target.closest('.wowp-fields-group');
205 + const el_js = parent.querySelector('.wowp-include-js');
206 + el_js.classList.toggle('is-hidden');
207 + }
208 + });
313 209
314 - const navigationMenu = document.getElementById("phpNavigationMenu");
210 +}
315 211
316 - editor.codemirror.eachLine(function (line) {
317 - const text = line.text;
318 - if (text.startsWith("// NAV:")) {
319 - let navItem = document.createElement("li");
320 - let navLink = document.createElement("a");
321 - navLink.href = "#";
322 - navLink.innerText = text.replace("// NAV:", "").trim();
323 - navLink.addEventListener("click", function (e) {
324 - e.preventDefault();
212 +const cloneDisplayRules = function () {
325 213
326 - // Remove existing highlights from the gutter
327 - editor.codemirror.eachLine(function (l) {
328 - editor.codemirror.removeLineClass(l, 'gutter', 'highlighted-gutter');
329 - });
214 + const template = document.getElementById('clone-display-rules');
215 + if (!template) {
216 + return false;
217 + }
330 218
331 - // Set cursor and scroll to line
332 - editor.codemirror.setCursor(line.lineNo());
333 - let heightOfLine = editor.codemirror.defaultTextHeight();
334 - let verticalPos = line.lineNo() * heightOfLine;
335 - editor.codemirror.scrollTo(null, verticalPos);
219 + const addBtn = document.getElementById('add-display');
220 + if (!addBtn) {
221 + return false;
222 + }
336 223
337 - // Highlight the line number in the gutter
338 - editor.codemirror.addLineClass(line.lineNo(), 'gutter', 'highlighted-gutter');
224 + addBtn.addEventListener('click', (event) => {
225 + event.preventDefault();
226 + const clone = template.content.cloneNode(true);
227 + const container = document.getElementById('display-rules');
228 + const targetElement = document.querySelector('#display-rules .wowp-btn-actions');
229 + container.insertBefore(clone, targetElement);
230 + });
339 231
340 - editor.codemirror.focus();
341 - });
342 - navItem.appendChild(navLink);
343 - navigationMenu.appendChild(navItem);
344 - }
345 - });
232 +}
346 233
234 +const removeDisplayRules = function () {
235 + const btn = document.getElementById('remove-display');
236 + if (!btn) {
237 + return false;
238 + }
347 239
348 - }
240 + btn.addEventListener('click', (event) => {
241 + event.preventDefault();
242 + const parentElement = document.getElementById('display-rules');
243 + const lastChild = parentElement.querySelector('.wowp-fields-group:not(:first-child):nth-last-child(2)');
244 + if (lastChild) {
245 + lastChild.remove();
246 + }
247 + });
349 248
350 249 }
351 250
352 -
353 -const changeTemplate = function () {
354 -
355 - const template = document.getElementById('template');
356 - if (!template) {
251 +const changeDisplayRules = function () {
252 + const parentContainer = document.getElementById('display-rules');
253 + if (!parentContainer) {
357 254 return false;
358 255 }
359 256
257 + parentContainer.addEventListener('change', function (event) {
360 258
361 - template.addEventListener('change', function (event) {
259 + // Check if the clicked element matches the desired selector
260 + if (event.target.matches('[name^="param[show]"]')) {
261 + let el = event.target.value;
262 + el = default_custom_post(el);
263 + const parent = event.target.closest('.wowp-fields-group');
264 + const elements = parent.querySelectorAll('.wowp-field');
265 + switch (el) {
266 + case 'shortcode':
267 + case 'everywhere':
268 + case 'post_all':
269 + case 'page_all':
270 + elements[1].classList.add('is-hidden');
271 + elements[2].classList.add('is-hidden');
272 + elements[3].classList.add('is-hidden');
273 + break;
274 + case 'post_selected':
275 + case 'post_category':
276 + case 'page_selected':
277 + elements[1].classList.remove('is-hidden');
278 + elements[2].classList.remove('is-hidden');
279 + elements[3].classList.add('is-hidden');
280 + break;
281 + case 'page_type':
282 + elements[1].classList.remove('is-hidden');
283 + elements[2].classList.add('is-hidden');
284 + elements[3].classList.remove('is-hidden');
285 + break;
362 286
363 - const parent = document.getElementById('wpcoder-template');
364 - let type = template.value;
365 - type = default_custom_post(type);
366 - const elements = parent.querySelectorAll('.wowp-field');
287 + }
367 288
368 - switch (type) {
369 - case 'post_all':
370 - case 'page_all':
371 - elements[1].classList.add('is-hidden');
372 - elements[2].classList.add('is-hidden');
373 - elements[3].classList.add('is-hidden');
374 - break;
375 - case 'post_selected':
376 - case 'post_in_category':
377 - case 'page_selected':
378 - case 'archive_category':
379 - case 'archive_tag':
380 - elements[1].classList.remove('is-hidden');
381 - elements[2].classList.remove('is-hidden');
382 - elements[3].classList.add('is-hidden');
383 - break;
384 - case 'page_type':
385 - elements[1].classList.remove('is-hidden');
386 - elements[2].classList.add('is-hidden');
387 - elements[3].classList.remove('is-hidden');
388 - break;
389 - default:
390 - elements[1].classList.add('is-hidden');
391 - elements[2].classList.add('is-hidden');
392 - elements[3].classList.add('is-hidden');
393 - break;
394 -
395 289 }
396 -
397 290 });
398 291
399 292 function default_custom_post(el) {
400 293 if (el.includes('custom_post_selected')) {
@@ -410,9 +303,101 @@
410 303 }
411 304
412 305 }
413 306
307 +const userRoles = function () {
308 + const user = document.getElementById('item_user');
309 + if (!user) {
310 + return false;
311 + }
312 + const parent = user.closest('fieldset');
414 313
314 + user.addEventListener('change', (el) => {
315 + const role = user.value;
316 + const roles = parent.querySelector('.wowp-users-roles');
317 + if (parseInt(role) === 2) {
318 + roles.classList.remove('is-hidden');
319 + } else {
320 + roles.classList.add('is-hidden');
321 + }
322 + })
323 +
324 + const checkboxes = parent.querySelectorAll('input[type="checkbox"]');
325 + const role_all = document.getElementById('user_role_all');
326 +
327 + role_all.addEventListener('change', () => {
328 + if (role_all.checked) {
329 + checkboxes.forEach(el => el.checked = true);
330 + } else {
331 + checkboxes.forEach(el => el.checked = false);
332 + }
333 + });
334 +}
335 +
336 +const languages = function () {
337 + const depending = document.getElementById('depending_language');
338 + if (!depending) {
339 + return false;
340 + }
341 + const parent = depending.closest('fieldset');
342 +
343 + depending.addEventListener('change', () => {
344 + if (depending.checked) {
345 + parent.querySelector('.wowp-languages').classList.remove('is-hidden');
346 + } else {
347 + parent.querySelector('.wowp-languages').classList.add('is-hidden');
348 + }
349 + });
350 +}
351 +
352 +const schedule = function () {
353 + const schedule = document.getElementById('schedule');
354 +
355 + if (!schedule) {
356 + return false;
357 + }
358 +
359 + const template = document.getElementById('clone-schedule');
360 + const addBtn = document.getElementById('add-schedule');
361 + const removeBtn = document.getElementById('remove-schedule');
362 +
363 + addBtn.addEventListener('click', (event) => {
364 + event.preventDefault();
365 + const clone = template.content.cloneNode(true);
366 + const container = document.getElementById('schedule');
367 + const targetElement = document.querySelector('#schedule .wowp-btn-actions');
368 + container.insertBefore(clone, targetElement);
369 + });
370 +
371 + removeBtn.addEventListener('click', (event) => {
372 + event.preventDefault();
373 + const parentElement = document.getElementById('schedule');
374 + const lastChild = parentElement.querySelector('.wowp-fields-group:nth-last-child(2)');
375 + if (lastChild) {
376 + lastChild.remove();
377 + }
378 + });
379 +
380 + schedule.addEventListener('change', function (event) {
381 + if (event.target.matches('[name^="param[dates]"]')) {
382 + const check_date = event.target;
383 + const parent = check_date.closest('.wowp-fields-group');
384 + const date_start = parent.querySelector('.wowp-field:nth-last-child(2)');
385 + const date_end = parent.querySelector('.wowp-field:nth-last-child(1)');
386 + if (check_date.checked) {
387 + date_start.classList.remove('is-hidden');
388 + date_end.classList.remove('is-hidden');
389 + } else {
390 + date_start.classList.add('is-hidden');
391 + date_end.classList.add('is-hidden');
392 + }
393 +
394 +
395 + }
396 + });
397 +
398 +}
399 +
415 400 const feature = function () {
416 401 const texts = document.querySelectorAll('.w_card-description');
417 402
418 403 if (!texts) {
@@ -428,8 +413,20 @@
428 413
429 414 document.addEventListener('DOMContentLoaded', function () {
430 415
431 416 new codeEditor;
417 + new cloneIncludes;
418 + new removeLast;
432 419 new settingTabs;
433 - new changeTemplate;
420 + new changeIncludes;
421 +
422 + new cloneDisplayRules;
423 + new removeDisplayRules;
424 + new changeDisplayRules;
425 +
426 + new userRoles;
427 + new languages;
428 +
429 + new schedule;
430 +
434 431 new feature;
435 432 })