| 1 |
jQuery(document).ready( function($) { |
| 2 |
// Show premium upsell modal for locked snippets |
| 3 |
$(document).on('click', '.wbcr-inp-premium-snippet-button', function() { |
| 4 |
$('#winp-premium-snippet-modal').show(); |
| 5 |
}); |
| 6 |
|
| 7 |
// Импортировать выбранный сниппет из списка |
| 8 |
$( '.wbcr-inp-enable-snippet-button' ).click( function() { |
| 9 |
if ( confirm(winp_snippet_library.is_import) ) { |
| 10 |
if ($(this).hasClass('disabled')) return; |
| 11 |
|
| 12 |
$(this).addClass('disabled'); |
| 13 |
|
| 14 |
$.post( |
| 15 |
ajaxurl, |
| 16 |
{ |
| 17 |
action: 'winp_snippet_create', |
| 18 |
winp_ajax_custom_list_nonce: $('#winp_ajax_custom_list_nonce').val(), |
| 19 |
snippet_id: $(this).data('snippet'), |
| 20 |
common: $(this).data('common') |
| 21 |
}, |
| 22 |
function(data) { |
| 23 |
if (data) { |
| 24 |
window.location = 'post.php?post=' + data + '&action=edit'; |
| 25 |
} else { |
| 26 |
$( '.wbcr-inp-enable-snippet-button' ).removeClass('disabled'); |
| 27 |
alert(winp_snippet_library.import_failed); |
| 28 |
} |
| 29 |
} |
| 30 |
); |
| 31 |
} |
| 32 |
}); |
| 33 |
|
| 34 |
// Close premium modal |
| 35 |
$(document).on('click', '#winp-modal-close', function(e) { |
| 36 |
e.preventDefault(); |
| 37 |
e.stopPropagation(); |
| 38 |
$('#winp-premium-snippet-modal').hide(); |
| 39 |
}); |
| 40 |
|
| 41 |
$(document).on('click', '#winp-premium-snippet-modal', function(e) { |
| 42 |
if (e.target === this) { |
| 43 |
e.preventDefault(); |
| 44 |
$('#winp-premium-snippet-modal').hide(); |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
// Удалить выбранный сниппет из списка |
| 49 |
$( '.wbcr-inp-delete-snippet-button' ).click( function() { |
| 50 |
if ( confirm(winp_snippet_library.is_delete) ) { |
| 51 |
if ($(this).hasClass('disabled')) return; |
| 52 |
|
| 53 |
$(this).addClass('disabled'); |
| 54 |
var snippet_id = $(this).data('snippet'); |
| 55 |
|
| 56 |
$.post( |
| 57 |
ajaxurl, |
| 58 |
{ |
| 59 |
action: 'winp_snippet_delete', |
| 60 |
winp_ajax_snippet_delete_nonce: $('#winp_ajax_snippet_delete_' + snippet_id).val(), |
| 61 |
snippet_id: snippet_id |
| 62 |
}, |
| 63 |
function(data) { |
| 64 |
if (data) { |
| 65 |
window.location.reload(); |
| 66 |
} else { |
| 67 |
$( '.wbcr-inp-enable-snippet-button' ).removeClass('disabled'); |
| 68 |
alert(winp_snippet_library.delete_failed); |
| 69 |
} |
| 70 |
} |
| 71 |
); |
| 72 |
} |
| 73 |
}); |
| 74 |
}); |