| 1 |
(function($){ |
| 2 |
$(document).on( 'click', '.winp-enable-php-btn', function(e) { |
| 3 |
e.preventDefault(); |
| 4 |
var icon = $(this).children('i'), |
| 5 |
label = $(this).children('.winp-btn-title'), |
| 6 |
input = $(this).children('.winp-with-php'); |
| 7 |
|
| 8 |
$(this).toggleClass('winp-active'); |
| 9 |
|
| 10 |
if( $(this).hasClass('winp-active') ) { |
| 11 |
icon.attr( 'class', 'dashicons dashicons-edit' ); |
| 12 |
label.text( $(this).data( 'disable-text' ) ); |
| 13 |
input.val('enabled'); |
| 14 |
$('body').addClass( 'winp-snippet-enabled' ); |
| 15 |
} else { |
| 16 |
icon.attr( 'class', 'dashicons dashicons-editor-code' ); |
| 17 |
label.text( $(this).data( 'enable-text' ) ); |
| 18 |
input.val(''); |
| 19 |
$('body').removeClass( 'winp-snippet-enabled' ); |
| 20 |
} |
| 21 |
}); |
| 22 |
|
| 23 |
})(jQuery); |
| 24 |
|
| 25 |
jQuery(document).ready( function($) { |
| 26 |
// Permalink slug |
| 27 |
$( '#titlediv' ).on( 'click', '.winp-edit-slug', function() { |
| 28 |
var i, |
| 29 |
$el, revert_e, |
| 30 |
c = 0, |
| 31 |
slug_value = $('#editable-post-name').html(), |
| 32 |
real_slug = $('#post_name'), |
| 33 |
revert_slug = real_slug.val(), |
| 34 |
permalink = $( '#sample-permalink' ), |
| 35 |
permalinkOrig = permalink.html(), |
| 36 |
permalinkInner = $( '#sample-permalink a' ).html(), |
| 37 |
permalinkHref = $('#sample-permalink a').attr('href'), |
| 38 |
buttons = $('#winp-edit-slug-buttons'), |
| 39 |
buttonsOrig = buttons.html(), |
| 40 |
full = $('#editable-post-name-full'); |
| 41 |
|
| 42 |
// Deal with Twemoji in the post-name. |
| 43 |
full.find( 'img' ).replaceWith( function() { return this.alt; } ); |
| 44 |
full = full.html(); |
| 45 |
|
| 46 |
permalink.html( permalinkInner ); |
| 47 |
|
| 48 |
// Save current content to revert to when cancelling. |
| 49 |
$el = $( '#editable-post-name' ); |
| 50 |
revert_e = $el.html(); |
| 51 |
|
| 52 |
buttons.html( '<button type="button" class="save button button-small">' |
| 53 |
+ postL10n.ok + '</button> <button type="button" class="cancel button- link">' |
| 54 |
+ postL10n.cancel + '</button>' ); |
| 55 |
|
| 56 |
|
| 57 |
// Save permalink changes. |
| 58 |
buttons.children( '.save' ).click( function() { |
| 59 |
var new_slug = $el.children( 'input' ).val(); |
| 60 |
|
| 61 |
if ( new_slug == $('#editable-post-name-full').text() ) { |
| 62 |
buttons.children('.cancel').click(); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
$.post( |
| 67 |
ajaxurl, |
| 68 |
{ |
| 69 |
action: 'winp_permalink', |
| 70 |
code_id: $('#post_ID').val(), |
| 71 |
filetype: $('#wbcr_inp_snippet_type').val(), |
| 72 |
new_slug: new_slug, |
| 73 |
permalink: permalinkHref, |
| 74 |
winp_permalink_nonce: $('#winp-permalink-nonce').val() |
| 75 |
}, |
| 76 |
function(data) { |
| 77 |
var box = $('#edit-slug-box'); |
| 78 |
box.html(data); |
| 79 |
if (box.hasClass('hidden')) { |
| 80 |
box.fadeIn('fast', function () { |
| 81 |
box.removeClass('hidden'); |
| 82 |
}); |
| 83 |
} |
| 84 |
} |
| 85 |
); |
| 86 |
}); |
| 87 |
|
| 88 |
// Cancel editing of permalink. |
| 89 |
buttons.children( '.cancel' ).click( function() { |
| 90 |
$('#view-post-btn').show(); |
| 91 |
$el.html(revert_e); |
| 92 |
buttons.html(buttonsOrig); |
| 93 |
permalink.html(permalinkOrig); |
| 94 |
real_slug.val(revert_slug); |
| 95 |
$( '.winp-edit-slug' ).focus(); |
| 96 |
}); |
| 97 |
|
| 98 |
$el.html( '<input type="text" name="new_slug" id="new-post-slug" value="' |
| 99 |
+ slug_value + '" autocomplete="off" />' ) |
| 100 |
.children( 'input' ) |
| 101 |
.keydown( function( e ) { |
| 102 |
var key = e.which; |
| 103 |
// On [enter], just save the new slug, don't save the post. |
| 104 |
if ( 13 === key ) { |
| 105 |
e.preventDefault(); |
| 106 |
buttons.children( '.save' ).click(); |
| 107 |
} |
| 108 |
// On [esc] cancel the editing. |
| 109 |
if ( 27 === key ) { |
| 110 |
buttons.children( '.cancel' ).click(); |
| 111 |
} |
| 112 |
} ).keyup( function() { |
| 113 |
real_slug.val( this.value ); |
| 114 |
}).focus(); |
| 115 |
}); |
| 116 |
|
| 117 |
if ($('.winp-field-premium-element').length > 0) { |
| 118 |
$('.winp-field-premium-element').wrap('<div class="winp-field-premium-icon"></div>'); |
| 119 |
} |
| 120 |
|
| 121 |
// Handle click on shortcode input to copy to clipboard |
| 122 |
$('input.wbcr_inp_shortcode_input').on('click', function (e) { |
| 123 |
var input = $(this); |
| 124 |
var value = input.val(); |
| 125 |
|
| 126 |
// Select the text |
| 127 |
this.setSelectionRange(0, this.value.length); |
| 128 |
|
| 129 |
// Copy to clipboard |
| 130 |
if (navigator.clipboard && navigator.clipboard.writeText) { |
| 131 |
// Modern clipboard API |
| 132 |
navigator.clipboard.writeText(value).then(function() { |
| 133 |
showCopyNotice(input); |
| 134 |
}).catch(function(err) { |
| 135 |
console.error('Failed to copy:', err); |
| 136 |
fallbackCopy(input); |
| 137 |
}); |
| 138 |
} else { |
| 139 |
// Fallback for older browsers |
| 140 |
fallbackCopy(input); |
| 141 |
} |
| 142 |
}); |
| 143 |
|
| 144 |
function fallbackCopy(input) { |
| 145 |
try { |
| 146 |
input[0].select(); |
| 147 |
var successful = document.execCommand('copy'); |
| 148 |
if (successful) { |
| 149 |
showCopyNotice(input); |
| 150 |
} |
| 151 |
} catch (err) { |
| 152 |
console.error('Failed to copy:', err); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
function showCopyNotice(input) { |
| 157 |
// Remove any existing notices |
| 158 |
$('.winp-copy-notice').remove(); |
| 159 |
|
| 160 |
// Create and show notice |
| 161 |
var notice = $('<div class="winp-copy-notice"><span>Copied to clipboard!</span></div>'); |
| 162 |
input.after(notice); |
| 163 |
|
| 164 |
// Position the notice |
| 165 |
notice.css({ |
| 166 |
position: 'absolute', |
| 167 |
background: '#6366f1', |
| 168 |
color: '#fff', |
| 169 |
borderRadius: '3px', |
| 170 |
fontSize: '12px', |
| 171 |
zIndex: 1000, |
| 172 |
whiteSpace: 'nowrap', |
| 173 |
boxShadow: '0 2px 5px rgba(0,0,0,0.2)', |
| 174 |
height: '38px', |
| 175 |
width: '100%', |
| 176 |
marginTop: '-10px', |
| 177 |
}); |
| 178 |
|
| 179 |
// Style the span |
| 180 |
notice.find('span').css({ |
| 181 |
display: 'flex', |
| 182 |
justifyContent: 'center', |
| 183 |
alignItems: 'center', |
| 184 |
height: '100%' |
| 185 |
}); |
| 186 |
|
| 187 |
// Fade out and remove after 2 seconds |
| 188 |
setTimeout(function() { |
| 189 |
notice.fadeOut(300, function() { |
| 190 |
notice.remove(); |
| 191 |
}); |
| 192 |
}, 2000); |
| 193 |
} |
| 194 |
}); |
| 195 |
|