PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.8
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.8
2.7.9 2.7.8 2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 All 30 releases
insert-php / admin / assets / js / snippet-list.js

snippet-list.js in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.8, at admin/assets/js/snippet-list.js

132 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 $("a#winp-snippet-status-switch").on('click', function (e) {
3 e.preventDefault();
4 var href = $(this);
5 href.addClass('winp-snippet-switch-loader');
6 jQuery.post(ajaxurl, {
7 action: 'change_snippet_status',
8 snippet_id: href.data('snippet-id'),
9 _ajax_nonce: winp_ajax.nonce,
10 }).done(function (result) {
11 href.removeClass('winp-snippet-switch-loader');
12 if (result.error_message) {
13 if (result.alert) {
14 alert(result.error_message);
15 }
16 console.error(result.error_message);
17
18 href.removeClass('winp-snippet-switch-loader');
19 } else {
20 console.log(result.message);
21 href.toggleClass('winp-inactive');
22 }
23 });
24 });
25
26 $("input.wbcr_inp_input_priority").on('change', function (e) {
27 var previous = e.currentTarget.defaultValue;
28 var input = $(this);
29 input.attr('disabled', true);
30 input.addClass('winp-loader');
31 jQuery.post(ajaxurl, {
32 action: 'change_priority',
33 snippet_id: input.data('snippet-id'),
34 priority: input.val(),
35 _ajax_nonce: winp_ajax.nonce,
36 }).done(function (result) {
37 //console.log(result);
38 if (result.error_message) {
39 console.error(result.error_message);
40 input.val(previous);
41 } else {
42 console.log(result.message);
43 }
44 input.removeAttr('disabled');
45 input.removeClass('winp-loader');
46 });
47 });
48
49 $("input.wbcr_inp_input_priority").on('keydown', stop_enter);
50 $("input.wbcr_inp_input_priority").on('keyup', stop_enter);
51 $("input.wbcr_inp_input_priority").on('keypress', stop_enter);
52
53 // Handle click on shortcode input to copy to clipboard
54 $("input.wbcr_inp_shortcode_input").on('click', function (e) {
55 var input = $(this);
56 var value = input.val();
57
58 // Select the text
59 this.setSelectionRange(0, this.value.length);
60
61 // Copy to clipboard
62 if (navigator.clipboard && navigator.clipboard.writeText) {
63 // Modern clipboard API
64 navigator.clipboard.writeText(value).then(function() {
65 showCopyNotice(input);
66 }).catch(function(err) {
67 console.error('Failed to copy:', err);
68 fallbackCopy(input);
69 });
70 } else {
71 // Fallback for older browsers
72 fallbackCopy(input);
73 }
74 });
75
76 function fallbackCopy(input) {
77 try {
78 input[0].select();
79 var successful = document.execCommand('copy');
80 if (successful) {
81 showCopyNotice(input);
82 }
83 } catch (err) {
84 console.error('Failed to copy:', err);
85 }
86 }
87
88 function showCopyNotice(input) {
89 // Remove any existing notices
90 $('.winp-copy-notice').remove();
91
92 // Create and show notice
93 var notice = $('<div class="winp-copy-notice"><span>Copied to clipboard!</span></div>');
94 input.after(notice);
95
96 // Position the notice
97 notice.css({
98 position: 'absolute',
99 background: '#6366f1',
100 color: '#fff',
101 borderRadius: '3px',
102 fontSize: '12px',
103 zIndex: 1000,
104 whiteSpace: 'nowrap',
105 boxShadow: '0 2px 5px rgba(0,0,0,0.2)',
106 height: '100%',
107 width: '100%'
108 });
109
110 // Style the span
111 notice.find('span').css({
112 display: 'flex',
113 justifyContent: 'center',
114 alignItems: 'center',
115 height: '100%'
116 });
117
118 // Fade out and remove after 2 seconds
119 setTimeout(function() {
120 notice.fadeOut(300, function() {
121 notice.remove();
122 });
123 }, 2000);
124 }
125 });
126
127 function stop_enter(e) {
128 if (e.keyCode === 13) {
129 e.preventDefault();
130 jQuery(this).blur();
131 }
132 }