| 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 |
|