permalink-manager-admin.css
4 years ago
permalink-manager-admin.js
4 years ago
permalink-manager-gutenberg.js
4 years ago
permalink-manager-plugins.css
4 years ago
permalink-manager-plugins.js
4 years ago
permalink-manager-admin.js
645 lines
| 1 | jQuery(document).ready(function() { |
| 2 | |
| 3 | /** |
| 4 | * "(Un)select all" checkboxes |
| 5 | */ |
| 6 | var checkbox_actions = ['select_all', 'unselect_all']; |
| 7 | checkbox_actions.forEach(function(element) { |
| 8 | jQuery('#permalink-manager .' + element).on('click', function() { |
| 9 | jQuery(this).parents('.field-container').find('.checkboxes input[type="checkbox"]').each(function() { |
| 10 | var action = (element == 'select_all') ? true : false; |
| 11 | jQuery(this).prop('checked', action); |
| 12 | }); |
| 13 | |
| 14 | return false; |
| 15 | }); |
| 16 | }); |
| 17 | |
| 18 | jQuery('#permalink-manager .checkboxes label, #permalink-manager .single_checkbox label').not('input').on('click', function(ev) { |
| 19 | var input = jQuery(this).find("input"); |
| 20 | if(!jQuery(ev.target).is("input")) { |
| 21 | input.prop('checked', !(input.prop("checked"))); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | /** |
| 26 | * Confirm action |
| 27 | */ |
| 28 | jQuery('.pm-confirm-action').on('click', function () { |
| 29 | return confirm(permalink_manager.confirm); |
| 30 | }); |
| 31 | |
| 32 | /** |
| 33 | * Filter by dates + Search in URI Editor |
| 34 | */ |
| 35 | jQuery('#permalink-manager #months-filter-button, #permalink-manager #search-submit').on('click', function(e) { |
| 36 | var search_value = jQuery('#permalink-manager input[name="s"]').val(); |
| 37 | var filter_value = jQuery("#months-filter-select").val(); |
| 38 | |
| 39 | var filter_url = window.location.href; |
| 40 | |
| 41 | // Date filter |
| 42 | if(filter_url.indexOf('month=') > 1) { |
| 43 | filter_url = filter_url.replace(/month=([^&]+)/gm, 'month=' + filter_value); |
| 44 | } else if(filter_value != '') { |
| 45 | filter_url = filter_url + '&month=' + filter_value; |
| 46 | } |
| 47 | |
| 48 | // Search query |
| 49 | if(filter_url.indexOf('s=') > 1) { |
| 50 | filter_url = filter_url.replace(/s=([^&]+)/gm, 's=' + search_value); |
| 51 | } else if(search_value != '') { |
| 52 | filter_url = filter_url + '&s=' + search_value; |
| 53 | } |
| 54 | |
| 55 | window.location.href = filter_url; |
| 56 | |
| 57 | e.preventDefault(); |
| 58 | return false; |
| 59 | }); |
| 60 | |
| 61 | jQuery('#permalink-manager #uri_editor form input[name="s"]').on('keydown keypress keyup', function(e){ |
| 62 | if(e.keyCode == 13) { |
| 63 | jQuery('#permalink-manager #search-submit').trigger('click'); |
| 64 | |
| 65 | e.preventDefault(); |
| 66 | return false; |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | /** |
| 71 | * Filter by content types in "Tools" |
| 72 | */ |
| 73 | jQuery('#permalink-manager *[data-field="content_type"] select').on('change', function() { |
| 74 | var content_type = jQuery(this).val(); |
| 75 | if(content_type == 'post_types') { |
| 76 | jQuery(this).parents('.form-table').find('*[data-field="post_types"],*[data-field="post_statuses"]').removeClass('hidden'); |
| 77 | jQuery(this).parents('.form-table').find('*[data-field="taxonomies"]').addClass('hidden'); |
| 78 | } else { |
| 79 | jQuery(this).parents('.form-table').find('*[data-field="post_types"],*[data-field="post_statuses"]').addClass('hidden'); |
| 80 | jQuery(this).parents('.form-table').find('*[data-field="taxonomies"]').removeClass('hidden'); |
| 81 | } |
| 82 | }).trigger("change"); |
| 83 | |
| 84 | /** |
| 85 | * Toggle "Edit URI" box |
| 86 | */ |
| 87 | jQuery('#permalink-manager-toggle, .permalink-manager-edit-uri-box .close-button').on('click', function() { |
| 88 | jQuery('.permalink-manager-edit-uri-box').slideToggle(); |
| 89 | |
| 90 | return false; |
| 91 | }); |
| 92 | |
| 93 | /** |
| 94 | * Toggle "Edit Redirects" box |
| 95 | */ |
| 96 | jQuery('#permalink-manager').on('click', '#toggle-redirect-panel', function() { |
| 97 | jQuery('#redirect-panel-inside').slideToggle(); |
| 98 | |
| 99 | return false; |
| 100 | }); |
| 101 | |
| 102 | jQuery('#permalink-manager').on('click', '.permalink-manager.redirects-panel #permalink-manager-new-redirect', function() { |
| 103 | // Find the table |
| 104 | var table = jQuery(this).parents('.redirects-panel').find('table'); |
| 105 | |
| 106 | // Copy the row from the sample |
| 107 | var new_row = jQuery(this).parents('.redirects-panel').find('.sample-row').clone().removeClass('sample-row'); |
| 108 | |
| 109 | // Adjust the array key |
| 110 | var last_key = jQuery(table).find("tr:last-of-type input[data-index]").data("index") + 1; |
| 111 | jQuery("input[data-index]", new_row).attr("data-index", last_key).attr("name", function(){ return jQuery(this).attr("name") + "[" + last_key + "]" }); |
| 112 | |
| 113 | // Append the new row |
| 114 | jQuery(table).append(new_row); |
| 115 | |
| 116 | return false; |
| 117 | }); |
| 118 | |
| 119 | jQuery('#permalink-manager').on('click', '.remove-redirect', function() { |
| 120 | var table = jQuery(this).closest('tr').remove(); |
| 121 | return false; |
| 122 | }); |
| 123 | |
| 124 | /** |
| 125 | * Synchronize "Edit URI" input field with the sample permalink |
| 126 | */ |
| 127 | var custom_uri_input = jQuery('.permalink-manager-edit-uri-box input[name="custom_uri"]'); |
| 128 | jQuery(custom_uri_input).on('keyup change', function() { |
| 129 | jQuery('.sample-permalink-span .editable').text(jQuery(this).val()); |
| 130 | }); |
| 131 | |
| 132 | /** |
| 133 | * Synchronize "Coupon URI" input field with the final permalink |
| 134 | */ |
| 135 | jQuery('#permalink-manager-coupon-url input[name="custom_uri"]').on('keyup change', function() { |
| 136 | var uri = jQuery(this).val(); |
| 137 | jQuery('#permalink-manager-coupon-url code span').text(uri); |
| 138 | |
| 139 | if(!uri) { |
| 140 | jQuery('#permalink-manager-coupon-url .coupon-full-url').addClass("hidden"); |
| 141 | } else { |
| 142 | jQuery('#permalink-manager-coupon-url .coupon-full-url').removeClass("hidden"); |
| 143 | } |
| 144 | }); |
| 145 | |
| 146 | function permalink_manager_duplicate_check(custom_uri_input, multi) { |
| 147 | // Set default values |
| 148 | custom_uri_input = typeof custom_uri_input !== 'undefined' ? custom_uri_input : false; |
| 149 | multi = typeof multi !== 'undefined' ? multi : false; |
| 150 | |
| 151 | var all_custom_uris_values = {}; |
| 152 | |
| 153 | if(custom_uri_input) { |
| 154 | var custom_uri = jQuery(custom_uri_input).val(); |
| 155 | var element_id = jQuery(custom_uri_input).attr("data-element-id"); |
| 156 | |
| 157 | all_custom_uris_values[element_id] = custom_uri; |
| 158 | } else { |
| 159 | jQuery('.custom_uri').each(function(i, obj) { |
| 160 | var field_name = jQuery(obj).attr('data-element-id'); |
| 161 | all_custom_uris_values[field_name] = jQuery(obj).val(); |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | if(all_custom_uris_values) { |
| 166 | jQuery.ajax(permalink_manager.ajax_url, { |
| 167 | type: 'POST', |
| 168 | async: true, |
| 169 | data: { |
| 170 | action: 'pm_detect_duplicates', |
| 171 | custom_uris: all_custom_uris_values |
| 172 | }, |
| 173 | success: function(data) { |
| 174 | if(data.length > 5) { |
| 175 | try { |
| 176 | var results = JSON.parse(data); |
| 177 | } catch (e) { |
| 178 | console.log(e); |
| 179 | console.log(data); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | // Loop through results |
| 184 | jQuery.each(results, function(key, is_duplicate) { |
| 185 | var alert_container = jQuery('.custom_uri[data-element-id="' + key + '"]').parents('.custom_uri_container').find('.duplicated_uri_alert'); |
| 186 | |
| 187 | if(is_duplicate) { |
| 188 | jQuery(alert_container).text(is_duplicate); |
| 189 | } else { |
| 190 | jQuery(alert_container).empty(); |
| 191 | } |
| 192 | }); |
| 193 | } |
| 194 | } |
| 195 | }); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Check if a single custom URI is not duplicated |
| 201 | */ |
| 202 | var custom_uri_check_timeout = null; |
| 203 | jQuery('.custom_uri_container input[name="custom_uri"], .custom_uri_container input.custom_uri').each(function() { |
| 204 | var input = this; |
| 205 | |
| 206 | jQuery(this).on('keyup change', function() { |
| 207 | clearTimeout(custom_uri_check_timeout); |
| 208 | |
| 209 | // Wait until user finishes typing |
| 210 | custom_uri_check_timeout = setTimeout(function() { |
| 211 | permalink_manager_duplicate_check(input); |
| 212 | }, 500); |
| 213 | }); |
| 214 | |
| 215 | }); |
| 216 | |
| 217 | /** |
| 218 | * Check if any of displayed custom URIs is not duplicated |
| 219 | */ |
| 220 | if(jQuery('#uri_editor .custom_uri').length > 0) { |
| 221 | permalink_manager_duplicate_check(false, true); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Disable "Edit URI" input if URI should be updated automatically |
| 226 | */ |
| 227 | jQuery('#permalink-manager').on('change', 'select[name="auto_update_uri"]', function() { |
| 228 | var selected = jQuery(this).find('option:selected'); |
| 229 | var auto_update_status = jQuery(selected).data('auto-update'); |
| 230 | var container = jQuery(this).parents('#permalink-manager'); |
| 231 | |
| 232 | if(auto_update_status == 1) { |
| 233 | jQuery(container).find('input[name="custom_uri"]').attr("readonly", true); |
| 234 | jQuery(container).find('.uri_locked').removeClass("hidden"); |
| 235 | } else { |
| 236 | jQuery(container).find('input[name="custom_uri"]').removeAttr("readonly", true); |
| 237 | jQuery(container).find('.uri_locked').addClass("hidden"); |
| 238 | } |
| 239 | }); |
| 240 | jQuery('select[name="auto_update_uri"]').trigger("change"); |
| 241 | |
| 242 | /** |
| 243 | * Restore "Default URI" |
| 244 | */ |
| 245 | jQuery('#permalink-manager').on('click', '.restore-default', function() { |
| 246 | var input = jQuery(this).parents('.field-container, .permalink-manager-edit-uri-box, #permalink-manager .inside').find('input.custom_uri, input.permastruct-field'); |
| 247 | var default_uri = jQuery(input).attr('data-default'); |
| 248 | |
| 249 | jQuery(input).val(default_uri).trigger('keyup'); |
| 250 | |
| 251 | return false; |
| 252 | }); |
| 253 | |
| 254 | /** |
| 255 | * Dispaly additional permastructure settings |
| 256 | */ |
| 257 | jQuery('#permalink-manager').on('click', '.permastruct-toggle-button a', function() { |
| 258 | jQuery(this).parents('.field-container').find('.permastruct-toggle').slideToggle(); |
| 259 | |
| 260 | return false; |
| 261 | }); |
| 262 | |
| 263 | /** |
| 264 | * Settings tabs |
| 265 | */ |
| 266 | jQuery('#permalink-manager').on('click', '.settings-tabs .subsubsub a', function() { |
| 267 | var tab_id = jQuery(this).attr('data-tab'); |
| 268 | |
| 269 | jQuery('#permalink-manager .settings-tabs .subsubsub a').removeClass('current'); |
| 270 | jQuery(this).addClass('current'); |
| 271 | |
| 272 | jQuery('#permalink-manager .settings-tabs form > div').hide().removeClass('active-tab'); |
| 273 | jQuery('#permalink-manager .settings-tabs form > div#pm_' + tab_id).show().addClass('active-tab'); |
| 274 | |
| 275 | jQuery('#permalink-manager .settings-tabs form input[name="pm_active_tab"]').val(tab_id); |
| 276 | |
| 277 | return false; |
| 278 | }); |
| 279 | |
| 280 | /** |
| 281 | * Conditional fields in Permalink Manager settings |
| 282 | */ |
| 283 | jQuery('#permalink-manager .settings-tabs #extra_redirects input[type="checkbox"]').on('change', function() { |
| 284 | var is_checked = jQuery(this).is(':checked'); |
| 285 | var rel_field_container = jQuery('#permalink-manager .settings-tabs #setup_redirects'); |
| 286 | |
| 287 | if(is_checked == true) { |
| 288 | rel_field_container.removeClass('hidden'); |
| 289 | } else { |
| 290 | rel_field_container.addClass('hidden'); |
| 291 | } |
| 292 | |
| 293 | console.log(is_checked); |
| 294 | }).trigger("change"); |
| 295 | |
| 296 | /** |
| 297 | * Hide global admin notices |
| 298 | */ |
| 299 | jQuery(document).on('click', '.permalink-manager-notice.is-dismissible .notice-dismiss', function() { |
| 300 | var alert_id = jQuery(this).closest('.permalink-manager-notice').data('alert_id'); |
| 301 | |
| 302 | jQuery.ajax(permalink_manager.ajax_url, { |
| 303 | type: 'POST', |
| 304 | data: { |
| 305 | action: 'dismissed_notice_handler', |
| 306 | alert_id: alert_id, |
| 307 | } |
| 308 | }); |
| 309 | }); |
| 310 | |
| 311 | /** |
| 312 | * Save permalinks from Gutenberg with AJAX |
| 313 | */ |
| 314 | jQuery('#permalink-manager .save-row.hidden').removeClass('hidden'); |
| 315 | jQuery('#permalink-manager').on('click', '#permalink-manager-save-button', function() { |
| 316 | pm_reload_gutenberg_uri_editor(); |
| 317 | return false; |
| 318 | }); |
| 319 | |
| 320 | var pm_reload_pending = false; |
| 321 | function pm_reload_gutenberg_uri_editor() { |
| 322 | var pm_container = jQuery('#permalink-manager.postbox'); |
| 323 | var pm_fields = jQuery(pm_container).find("input, select"); |
| 324 | var pm_data = jQuery(pm_fields).serialize() + '&action=' + 'pm_save_permalink'; |
| 325 | |
| 326 | // Do not duplicate AJAX requests |
| 327 | if(!pm_reload_pending) { |
| 328 | // console.log(pm_data); |
| 329 | |
| 330 | jQuery.ajax({ |
| 331 | type: 'POST', |
| 332 | url: permalink_manager.ajax_url, |
| 333 | data: pm_data, |
| 334 | beforeSend: function() { |
| 335 | pm_reload_pending = true; |
| 336 | |
| 337 | jQuery(pm_container).LoadingOverlay("show", { |
| 338 | background : "rgba(0, 0, 0, 0.1)", |
| 339 | }); |
| 340 | }, |
| 341 | success: function(html) { |
| 342 | jQuery(pm_container).find('.permalink-manager-gutenberg').replaceWith(html); |
| 343 | jQuery(pm_container).LoadingOverlay("hide"); |
| 344 | |
| 345 | jQuery(pm_container).find('select[name="auto_update_uri"]').trigger("change"); |
| 346 | pm_help_tooltips(); |
| 347 | |
| 348 | if(wp && wp.data !== 'undefined') { |
| 349 | wp.data.dispatch('core/editor').savePost(); |
| 350 | } |
| 351 | |
| 352 | pm_reload_pending = false; |
| 353 | } |
| 354 | }); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Reload the URI Editor in Gutenberg after the post is published or the title/slug is changed |
| 360 | */ |
| 361 | if(typeof wp !== 'undefined' && typeof wp.data !== 'undefined' && typeof wp.data.select !== 'undefined' && typeof wp.blocks !== 'undefined' && typeof wp.data.subscribe !== 'undefined' && wp.data.select('core/editor') !== 'undefined' && wp.data.select('core/editor') !== null) { |
| 362 | wp.data.subscribe(function() { |
| 363 | var isSavingPost = wp.data.select('core/editor').isSavingPost(); |
| 364 | var isAutosavingPost = wp.data.select('core/editor').isAutosavingPost(); |
| 365 | |
| 366 | if(isSavingPost && !isAutosavingPost) { |
| 367 | old_status = wp.data.select('core/editor').getCurrentPostAttribute('status'); |
| 368 | new_status = wp.data.select('core/editor').getEditedPostAttribute('status'); |
| 369 | |
| 370 | old_title = wp.data.select('core/editor').getCurrentPostAttribute('title'); |
| 371 | new_title = wp.data.select('core/editor').getEditedPostAttribute('title'); |
| 372 | |
| 373 | old_slug = wp.data.select('core/editor').getCurrentPostAttribute('slug'); |
| 374 | new_slug = wp.data.select('core/editor').getEditedPostAttribute('slug'); |
| 375 | |
| 376 | if((old_status !== new_status && new_status == 'publish') || (old_title !== new_title) || (old_slug !== new_slug)) { |
| 377 | setTimeout(function() { |
| 378 | pm_reload_gutenberg_uri_editor(); |
| 379 | }, 1500); |
| 380 | } |
| 381 | } |
| 382 | }); |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Help tooltips |
| 387 | */ |
| 388 | function pm_help_tooltips() { |
| 389 | if(jQuery('#permalink-manager .help_tooltip').length > 0) { |
| 390 | tippy('#permalink-manager .help_tooltip', { |
| 391 | position: 'top-start', |
| 392 | arrow: true, |
| 393 | theme: 'tippy-pm', |
| 394 | distance: 20, |
| 395 | }); |
| 396 | } |
| 397 | } |
| 398 | pm_help_tooltips(); |
| 399 | |
| 400 | |
| 401 | /** |
| 402 | * Check expiration date |
| 403 | */ |
| 404 | jQuery(document).on('click', '#pm_get_exp_date', function() { |
| 405 | jQuery.ajax(permalink_manager.ajax_url, { |
| 406 | type: 'POST', |
| 407 | data: { |
| 408 | action: 'pm_get_exp_date', |
| 409 | licence: { |
| 410 | licence_key: jQuery('#permalink-manager #settings #licence_key input[type="text"]').val() |
| 411 | } |
| 412 | }, |
| 413 | beforeSend: function() { |
| 414 | var spinner = '<img src="' + permalink_manager.spinners + '/wpspin_light-2x.gif" width="16" height="16">'; |
| 415 | jQuery('#permalink-manager .licence-info').html(spinner); |
| 416 | }, |
| 417 | success: function(data) { |
| 418 | jQuery('#permalink-manager .licence-info').html(data); |
| 419 | } |
| 420 | }); |
| 421 | |
| 422 | return false; |
| 423 | }); |
| 424 | |
| 425 | /** |
| 426 | * Bulk tools |
| 427 | */ |
| 428 | function pm_show_progress(elem, progress) { |
| 429 | if(progress) { |
| 430 | jQuery(elem).LoadingOverlay("text", progress + "%"); |
| 431 | } else { |
| 432 | jQuery(elem).LoadingOverlay("show", { |
| 433 | background : "rgba(0, 0, 0, 0.1)", |
| 434 | text: '0%' |
| 435 | }); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | jQuery('#permalink-manager #tools form.form-ajax').on('submit', function() { |
| 440 | var data = jQuery(this).serialize() + '&action=' + 'pm_bulk_tools'; |
| 441 | var form = jQuery(this); |
| 442 | var updated_count = total = progress = 0; |
| 443 | |
| 444 | // Hide alert & results table |
| 445 | jQuery('#permalink-manager .updated-slugs-table, .permalink-manager-notice.updated_slugs, #permalink-manager #updated-list').remove(); |
| 446 | |
| 447 | jQuery.ajax({ |
| 448 | type: 'POST', |
| 449 | url: permalink_manager.ajax_url, |
| 450 | data: data, |
| 451 | beforeSend: function() { |
| 452 | // Show progress overlay |
| 453 | pm_show_progress("#permalink-manager #tools", progress); |
| 454 | }, |
| 455 | success: function(data) { |
| 456 | var table_dom = jQuery('#permalink-manager .updated-slugs-table'); |
| 457 | // console.log(data); |
| 458 | |
| 459 | // Display the table |
| 460 | if(data.hasOwnProperty('html')) { |
| 461 | var table = jQuery(data.html); |
| 462 | |
| 463 | if(table_dom.length == 0) { |
| 464 | jQuery('#permalink-manager #tools').after(data.html); |
| 465 | } else { |
| 466 | jQuery(table_dom).append(jQuery(table).find('tbody').html()); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // Hide error message |
| 471 | jQuery('.permalink-manager-notice.updated_slugs.error').remove(); |
| 472 | |
| 473 | // Display the alert (should be hidden at first) |
| 474 | if(data.hasOwnProperty('alert') && jQuery('.permalink-manager-notice.updated_slugs .updated_count').length == 0) { |
| 475 | var alert = jQuery(data.alert).hide(); |
| 476 | jQuery('#plugin-name-heading').after(alert); |
| 477 | } |
| 478 | |
| 479 | // Increase updated count |
| 480 | if(data.hasOwnProperty('updated_count')) { |
| 481 | if(jQuery(form).attr("data-updated_count")) { |
| 482 | updated_count = parseInt(jQuery(form).attr("data-updated_count")) + parseInt(data.updated_count); |
| 483 | } else { |
| 484 | updated_count = parseInt(data.updated_count); |
| 485 | } |
| 486 | |
| 487 | jQuery(form).attr("data-updated_count", updated_count); |
| 488 | jQuery('.permalink-manager-notice.updated_slugs .updated_count').text(updated_count); |
| 489 | } |
| 490 | |
| 491 | // Show total |
| 492 | if(data.hasOwnProperty('total')) { |
| 493 | total = parseInt(data.total); |
| 494 | |
| 495 | jQuery(form).attr("data-total", total); |
| 496 | } |
| 497 | |
| 498 | // Trigger again |
| 499 | if(data.hasOwnProperty('left_chunks') && (typeof total !== "undefined" && data.progress < total)) { |
| 500 | jQuery.ajax(this); |
| 501 | |
| 502 | // Update progress |
| 503 | if(data.hasOwnProperty('progress')) { |
| 504 | progress = Math.floor((data.progress / total) * 100) |
| 505 | console.log(data.progress + "/" + total + " = " + progress + "%"); |
| 506 | } |
| 507 | } else { |
| 508 | // Display results |
| 509 | jQuery('.permalink-manager-notice.updated_slugs').fadeIn(); |
| 510 | jQuery('#permalink-manager #tools').LoadingOverlay("hide", true); |
| 511 | |
| 512 | if(table_dom.length > 0) { |
| 513 | jQuery('html, body').animate({ |
| 514 | scrollTop: table_dom.offset().top - 100 |
| 515 | }, 2000); |
| 516 | } |
| 517 | |
| 518 | // Reset progress & updated count |
| 519 | progress = updated_count = 0; |
| 520 | jQuery(form).attr("data-updated_count", 0); |
| 521 | } |
| 522 | }, |
| 523 | error: function(xhr, status, error_data) { |
| 524 | alert('Tthere was a problem running this tool and the process could not be completed. You can find more details in browser\'s console log.') |
| 525 | console.log('Status: ' + status); |
| 526 | console.log('Please send the debug data to contact@permalinkmanager.pro:\n\n' + xhr.responseText); |
| 527 | |
| 528 | jQuery('#permalink-manager #tools').LoadingOverlay("hide", true); |
| 529 | } |
| 530 | }); |
| 531 | |
| 532 | return false; |
| 533 | }); |
| 534 | |
| 535 | /** |
| 536 | * Stop-words |
| 537 | */ |
| 538 | var stop_words_input = '#permalink-manager .field-container textarea.stop_words'; |
| 539 | |
| 540 | if(jQuery(stop_words_input).length > 0) { |
| 541 | var stop_words = new TIB(document.querySelector(stop_words_input), { |
| 542 | alert: false, |
| 543 | //escape: null, |
| 544 | escape: [','], |
| 545 | classes: ['tags words-editor', 'tag', 'tags-input', 'tags-output', 'tags-view'], |
| 546 | }); |
| 547 | jQuery('.tags-output').hide(); |
| 548 | |
| 549 | // Force lowercase |
| 550 | stop_words.filter = function(text) { |
| 551 | return text.toLowerCase(); |
| 552 | }; |
| 553 | |
| 554 | // Remove all words |
| 555 | jQuery('#permalink-manager .field-container .clear_all_words').on('click', function() { |
| 556 | stop_words.reset(); |
| 557 | }); |
| 558 | |
| 559 | // Load stop-words list |
| 560 | jQuery('#permalink-manager #load_stop_words_button').on('click', function() { |
| 561 | var lang = jQuery( ".load_stop_words option:selected" ).val(); |
| 562 | if(lang) { |
| 563 | var json_url = permalink_manager.url + "/includes/ext/stopwords-json/dist/" + lang + ".json"; |
| 564 | |
| 565 | // Load JSON with words list |
| 566 | jQuery.getJSON(json_url, function(data) { |
| 567 | var new_words = []; |
| 568 | |
| 569 | jQuery.each(data, function(key, val) { |
| 570 | new_words.push(val); |
| 571 | }); |
| 572 | |
| 573 | stop_words.update(new_words); |
| 574 | }); |
| 575 | } |
| 576 | |
| 577 | return false; |
| 578 | }); |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Quick Edit |
| 583 | */ |
| 584 | if(typeof inlineEditPost !== "undefined") { |
| 585 | var inline_post_editor = inlineEditPost.edit; |
| 586 | inlineEditPost.edit = function(id) { |
| 587 | inline_post_editor.apply(this, arguments); |
| 588 | |
| 589 | // Get the Post ID |
| 590 | var post_id = 0; |
| 591 | if(typeof(id) == 'object') { |
| 592 | post_id = parseInt(this.getId(id)); |
| 593 | } |
| 594 | |
| 595 | if(post_id != 0) { |
| 596 | // Get the row & "Custom URI" field |
| 597 | custom_uri_field = jQuery('#edit-' + post_id).find('.custom_uri'); |
| 598 | |
| 599 | // Prepare the Custom URI |
| 600 | custom_uri = jQuery("#post-" + post_id).find(".column-permalink-manager-col").text(); |
| 601 | |
| 602 | // Fill with the Custom URI |
| 603 | custom_uri_field.val(custom_uri); |
| 604 | |
| 605 | // Get auto-update settings |
| 606 | auto_update = jQuery("#post-" + post_id).find(".permalink-manager-col-uri").attr('data-auto_update'); |
| 607 | if(typeof auto_update !== "undefined" && auto_update == 1) { |
| 608 | custom_uri_field.attr('readonly', 'readonly'); |
| 609 | } |
| 610 | |
| 611 | // Set the element ID |
| 612 | jQuery('#edit-' + post_id).find('.permalink-manager-edit-uri-element-id').val(post_id); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | if(typeof inlineEditTax !== "undefined") { |
| 618 | var inline_tax_editor = inlineEditTax.edit; |
| 619 | inlineEditTax.edit = function(id) { |
| 620 | inline_tax_editor.apply(this, arguments); |
| 621 | |
| 622 | // Get the Post ID |
| 623 | var term_id = 0; |
| 624 | if(typeof(id) == 'object') { |
| 625 | term_id = parseInt(this.getId(id)); |
| 626 | } |
| 627 | |
| 628 | if(term_id != 0) { |
| 629 | // Get the row & "Custom URI" field |
| 630 | custom_uri_field = jQuery('#edit-' + term_id).find('.custom_uri'); |
| 631 | |
| 632 | // Prepare the Custom URI |
| 633 | custom_uri = jQuery("#tag-" + term_id).find(".column-permalink-manager-col").text(); |
| 634 | |
| 635 | // Fill with the Custom URI |
| 636 | custom_uri_field.val(custom_uri); |
| 637 | |
| 638 | // Set the element ID |
| 639 | jQuery('#edit-' + term_id).find('.permalink-manager-edit-uri-element-id').val("tax-" + term_id); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | }); |
| 645 |