| 1 |
jQuery(document).ready(function($) { |
| 2 |
// Запрос экспорта сниппета |
| 3 |
$('#winp-snippet-sync').click(function() { |
| 4 |
if( $(this).hasClass('disabled') ) { |
| 5 |
return; |
| 6 |
} |
| 7 |
|
| 8 |
$('#winp-sync-snippet-name').val(''); |
| 9 |
$('#winp-sync-content').find('.winp-modal-error').css('visibility', 'hidden'); |
| 10 |
$('#winp-sync-modal').factoryBootstrap423_modal('show'); |
| 11 |
}); |
| 12 |
|
| 13 |
// Экспорт сниппета |
| 14 |
$('#winp-sync-save-button').click(function() { |
| 15 |
var self = $(this); |
| 16 |
|
| 17 |
if( $(this).hasClass('disabled') ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
if( $('#winp-sync-snippet-name').val() === '' ) { |
| 22 |
$('#winp-sync-snippet-name')[0].reportValidity(); |
| 23 |
|
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
$(this).addClass('disabled'); |
| 28 |
|
| 29 |
$('#winp-sync-save-button span').html('<img src="' + winp_snippet_sync.src_loader + '">'); |
| 30 |
|
| 31 |
$.post(ajaxurl, { |
| 32 |
action: 'winp_snippet_synchronization', |
| 33 |
snippet_id: $('#post_ID').val(), |
| 34 |
snippet_name: $('#winp-sync-snippet-name').val(), |
| 35 |
_wpnonce: self.data('nonce') |
| 36 |
}, |
| 37 |
function(data) { |
| 38 |
$('#winp-sync-save-button').removeClass('disabled'); |
| 39 |
$('#winp-sync-save-button span').html(winp_snippet_sync.save); |
| 40 |
|
| 41 |
if( true == data ) { |
| 42 |
$('.winp-sync-buttons').css('color', 'green'); |
| 43 |
$('#winp-snippet-sync').replaceWith('<span class="dashicons dashicons-plus-alt winp-green"></span> ' + winp_snippet_sync.saved); |
| 44 |
|
| 45 |
$('#winp-sync-modal').factoryBootstrap423_modal('hide'); |
| 46 |
} else { |
| 47 |
var error_text = winp_snippet_sync.export_failed; |
| 48 |
if( typeof data == 'string' ) { |
| 49 |
error_text = data; |
| 50 |
} |
| 51 |
$('#winp-sync-content').find('.winp-modal-error span.warning-text').text(error_text); |
| 52 |
$('#winp-sync-content').find('.winp-modal-error').css('visibility', 'visible'); |
| 53 |
} |
| 54 |
} |
| 55 |
); |
| 56 |
}); |
| 57 |
}); |
| 58 |
|
| 59 |
(function($) { |
| 60 |
window.wimp_snippet_list = { |
| 61 |
/** added method display |
| 62 |
* for getting first sets of data |
| 63 |
**/ |
| 64 |
display: function() { |
| 65 |
$.ajax({ |
| 66 |
url: ajaxurl, |
| 67 |
dataType: 'json', |
| 68 |
data: { |
| 69 |
winp_ajax_custom_list_nonce: $('#winp_ajax_custom_list_nonce').val(), |
| 70 |
action: 'winp_sts_display' |
| 71 |
}, |
| 72 |
success: function(response) { |
| 73 |
$('#winp-snippet-library-table').html(response.display); |
| 74 |
$('tbody').on('click', '.toggle-row', function(e) { |
| 75 |
e.preventDefault(); |
| 76 |
$(this).closest('tr').toggleClass('is-expanded'); |
| 77 |
}); |
| 78 |
window.wimp_snippet_list.init(); |
| 79 |
}, |
| 80 |
error: function(response) { |
| 81 |
alert(winp_snippet_sync.import_failed); |
| 82 |
} |
| 83 |
}); |
| 84 |
}, |
| 85 |
init: function() { |
| 86 |
var timer; |
| 87 |
var delay = 500; |
| 88 |
|
| 89 |
// Импортировать выбранный сниппет из списка сниппетов в модальном окне |
| 90 |
$('.wbcr-inp-enable-snippet-button').click(function() { |
| 91 |
if( confirm(winp_snippet_sync.import + '?') ) { |
| 92 |
$('#winp-snippet-library, #winp-snippet-sync').addClass('disabled'); |
| 93 |
$.post( |
| 94 |
ajaxurl, |
| 95 |
{ |
| 96 |
action: 'winp_snippet_create', |
| 97 |
snippet_id: $(this).data('snippet'), |
| 98 |
post_id: $('#auto_draft').length > 0 && $('#auto_draft').val() == 1 |
| 99 |
? 0 |
| 100 |
: $('#post_ID').val() |
| 101 |
}, |
| 102 |
function(data) { |
| 103 |
if( data ) { |
| 104 |
window.location = 'post.php?post=' + data + '&action=edit'; |
| 105 |
} else { |
| 106 |
$('#winp-snippet-library, #winp-snippet-sync').removeClass('disabled'); |
| 107 |
alert(winp_snippet_sync.import_failed); |
| 108 |
} |
| 109 |
} |
| 110 |
); |
| 111 |
|
| 112 |
//$('#winp-sync-modal').factoryBootstrap423_modal('hide'); |
| 113 |
} |
| 114 |
}); |
| 115 |
|
| 116 |
$('.tablenav-pages a, .manage-column.sortable a, .manage-column.sorted a').on('click', function(e) { |
| 117 |
e.preventDefault(); |
| 118 |
var query = this.search.substring(1); |
| 119 |
var data = { |
| 120 |
paged: window.wimp_snippet_list.__query(query, 'paged') || '1', |
| 121 |
order: window.wimp_snippet_list.__query(query, 'order') || 'asc', |
| 122 |
orderby: window.wimp_snippet_list.__query(query, 'orderby') || 'title' |
| 123 |
}; |
| 124 |
window.wimp_snippet_list.update(data); |
| 125 |
}); |
| 126 |
$('input[name=paged]').on('keyup', function(e) { |
| 127 |
if( 13 == e.which ) { |
| 128 |
e.preventDefault(); |
| 129 |
} |
| 130 |
var data = { |
| 131 |
paged: parseInt($('input[name=paged]').val()) || '1', |
| 132 |
order: $('input[name=order]').val() || 'asc', |
| 133 |
orderby: $('input[name=orderby]').val() || 'title' |
| 134 |
}; |
| 135 |
window.clearTimeout(timer); |
| 136 |
timer = window.setTimeout(function() { |
| 137 |
window.wimp_snippet_list.update(data); |
| 138 |
}, delay); |
| 139 |
}); |
| 140 |
$('#winp-snippet-library-list').on('submit', function(e) { |
| 141 |
e.preventDefault(); |
| 142 |
}); |
| 143 |
}, |
| 144 |
/** AJAX call |
| 145 |
* |
| 146 |
* Send the call and replace table parts with updated version! |
| 147 |
* |
| 148 |
* @param object data The data to pass through AJAX |
| 149 |
*/ |
| 150 |
update: function(data) { |
| 151 |
$.ajax({ |
| 152 |
url: ajaxurl, |
| 153 |
data: $.extend( |
| 154 |
{ |
| 155 |
winp_ajax_custom_list_nonce: $('#winp_ajax_custom_list_nonce').val(), |
| 156 |
action: 'winp_fetch_sts_history' |
| 157 |
}, |
| 158 |
data |
| 159 |
), |
| 160 |
success: function(response) { |
| 161 |
var response = $.parseJSON(response); |
| 162 |
if( response.rows.length ) { |
| 163 |
$('#the-list').html(response.rows); |
| 164 |
} |
| 165 |
if( response.column_headers.length ) { |
| 166 |
$('thead tr, tfoot tr').html(response.column_headers); |
| 167 |
} |
| 168 |
if( response.pagination.bottom.length ) { |
| 169 |
$('.tablenav.top .tablenav-pages').html($(response.pagination.top).html()); |
| 170 |
} |
| 171 |
if( response.pagination.top.length ) { |
| 172 |
$('.tablenav.bottom .tablenav-pages').html($(response.pagination.bottom).html()); |
| 173 |
} |
| 174 |
window.wimp_snippet_list.init(); |
| 175 |
}, |
| 176 |
error: function(response) { |
| 177 |
alert(winp_snippet_sync.import_failed); |
| 178 |
} |
| 179 |
}); |
| 180 |
}, |
| 181 |
/** |
| 182 |
* Filter the URL Query to extract variables |
| 183 |
* |
| 184 |
* @see http://css-tricks.com/snippets/javascript/get-url-variables/ |
| 185 |
* |
| 186 |
* @param string query The URL query part containing the variables |
| 187 |
* @param string variable Name of the variable we want to get |
| 188 |
* |
| 189 |
* @return string|boolean The variable value if available, false else. |
| 190 |
*/ |
| 191 |
__query: function(query, variable) { |
| 192 |
var vars = query.split('&'); |
| 193 |
for( var i = 0; i < vars.length; i++ ) { |
| 194 |
var pair = vars[i].split('='); |
| 195 |
if( pair[0] == variable ) { |
| 196 |
return pair[1]; |
| 197 |
} |
| 198 |
} |
| 199 |
return false; |
| 200 |
} |
| 201 |
}; |
| 202 |
})(jQuery); |