| @@ -1,63 +1,132 @@ | ||
| 1 | -jQuery(document).ready(function ($) { | |
| 2 | - //Export page | |
| 3 | - //$('#bulk-action-selector-top option[value="exportsnp"]').css('color', '#999').prop('disabled', true); | |
| 4 | - | |
| 5 | - // | |
| 6 | - $("a#winp-snippet-status-switch").on('click', function (e) { | |
| 7 | - e.preventDefault(); | |
| 8 | - var href = $(this); | |
| 9 | - href.addClass('winp-snippet-switch-loader'); | |
| 10 | - jQuery.post(ajaxurl, { | |
| 11 | - action: 'change_snippet_status', | |
| 12 | - snippet_id: href.data('snippet-id'), | |
| 13 | - _ajax_nonce: winp_ajax.nonce, | |
| 14 | - }).done(function (result) { | |
| 15 | - href.removeClass('winp-snippet-switch-loader'); | |
| 16 | - if (result.error_message) { | |
| 17 | - if (result.alert) { | |
| 18 | - alert(result.error_message); | |
| 19 | - } | |
| 20 | - console.error(result.error_message); | |
| 21 | - | |
| 22 | - href.removeClass('winp-snippet-switch-loader'); | |
| 23 | - } else { | |
| 24 | - console.log(result.message); | |
| 25 | - href.toggleClass('winp-inactive'); | |
| 26 | - } | |
| 27 | - }); | |
| 28 | - }); | |
| 29 | - | |
| 30 | - $("input.wbcr_inp_input_priority").on('change', function (e) { | |
| 31 | - var previous = e.currentTarget.defaultValue; | |
| 32 | - var input = $(this); | |
| 33 | - input.attr('disabled', true); | |
| 34 | - input.addClass('winp-loader'); | |
| 35 | - jQuery.post(ajaxurl, { | |
| 36 | - action: 'change_priority', | |
| 37 | - snippet_id: input.data('snippet-id'), | |
| 38 | - priority: input.val(), | |
| 39 | - _ajax_nonce: winp_ajax.nonce, | |
| 40 | - }).done(function (result) { | |
| 41 | - //console.log(result); | |
| 42 | - if (result.error_message) { | |
| 43 | - console.error(result.error_message); | |
| 44 | - input.val(previous); | |
| 45 | - } else { | |
| 46 | - console.log(result.message); | |
| 47 | - } | |
| 48 | - input.removeAttr('disabled'); | |
| 49 | - input.removeClass('winp-loader'); | |
| 50 | - }); | |
| 51 | - }); | |
| 52 | - | |
| 53 | - $("input.wbcr_inp_input_priority").on('keydown', stop_enter); | |
| 54 | - $("input.wbcr_inp_input_priority").on('keyup', stop_enter); | |
| 55 | - $("input.wbcr_inp_input_priority").on('keypress', stop_enter); | |
| 56 | -}); | |
| 57 | - | |
| 58 | -function stop_enter(e) { | |
| 59 | - if (e.keyCode === 13) { | |
| 60 | - e.preventDefault(); | |
| 61 | - jQuery(this).blur(); | |
| 62 | - } | |
| 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 | + } | |
| 63 | 132 | } |