Cdnfsd_BunnyCdn_Page_View.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * File: Cdnfsd_BunnyCdn_Page_View.js
  3. *
  4. * @since 2.6.0
  5. * @package W3TC
  6. */
  7. jQuery(function($) {
  8. /**
  9. * Resize the popup modal.
  10. *
  11. * @param object o W3tc_Lightbox object.
  12. */
  13. function w3tc_bunnycdn_resize(o) {
  14. o.resize();
  15. }
  16. // Add event handlers.
  17. $('body')
  18. // Load the authorization form.
  19. .on('click', '.w3tc_cdn_bunnycdn_fsd_authorize', function() {
  20. W3tc_Lightbox.open({
  21. id:'w3tc-overlay',
  22. close: '',
  23. width: 800,
  24. height: 300,
  25. url: ajaxurl +
  26. '?action=w3tc_ajax&_wpnonce=' +
  27. w3tc_nonce +
  28. '&w3tc_action=cdn_bunnycdn_fsd_intro',
  29. callback: w3tc_bunnycdn_resize
  30. });
  31. })
  32. // Sanitize the account API key input value.
  33. .on('change', '#w3tc-account-api-key', function() {
  34. var $this = $(this);
  35. $this.val($.trim($this.val().replace(/[^a-z0-9-]/g, '')));
  36. })
  37. // Load the pull zone selection form.
  38. .on('click', '.w3tc_cdn_bunnycdn_fsd_list_pull_zones', function() {
  39. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  40. '&w3tc_action=cdn_bunnycdn_fsd_list_pull_zones';
  41. W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_fsd_form', w3tc_bunnycdn_resize);
  42. })
  43. // Enable/disable (readonly) add pull zone form fields based on selection.
  44. .on('change', '#w3tc-pull-zone-id', function() {
  45. var $selected_option = $(this).find(':selected'),
  46. $origin = $('#w3tc-origin-url'),
  47. $name = $('#w3tc-pull-zone-name'),
  48. $hostnames = $('#w3tc-custom-hostnames');
  49. if ($(this).find(':selected').val() === '') {
  50. // Enable the add pull zone fields with suggested or entered values.
  51. $origin.val($origin.data('suggested')).prop('readonly', false);
  52. $name.val($name.data('suggested')).prop('readonly', false);
  53. $hostnames.val($hostnames.data('suggested')).prop('readonly', false);
  54. } else {
  55. // Disable the add pull zone fields and change values using the selected option.
  56. $origin.prop('readonly', true).val($selected_option.data('origin'));
  57. $name.prop('readonly', true).val($selected_option.data('name'));
  58. $hostnames.prop('readonly', true).val($selected_option.data('custom-hostnames'));
  59. }
  60. // Update the hidden input field for the selected pull zone id from the select option value.
  61. $('[name="pull_zone_id"]').val($selected_option.val());
  62. // Update the hidden input field for the selected pull zone CDN hostname from the select option value.
  63. $('[name="cdn_hostname"]').val($selected_option.data('cdn-hostname'));
  64. })
  65. // Sanitize the origin URL/IP input value.
  66. .on('change', '#w3tc-origin-url', function() {
  67. var $this = $(this);
  68. $this.val($.trim($this.val().replace(/[^a-z0-9\.:\/-]/g, '')));
  69. })
  70. // Sanitize the pull zone name input value.
  71. .on('change', '#w3tc-pull-zone-name', function() {
  72. var $this = $(this);
  73. $this.val($.trim($this.val().replace(/[^a-z0-9-]/g, '')));
  74. })
  75. // Configure pull zone.
  76. .on('click', '.w3tc_cdn_bunnycdn_fsd_configure_pull_zone', function() {
  77. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  78. '&w3tc_action=cdn_bunnycdn_fsd_configure_pull_zone';
  79. W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_fsd_form', w3tc_bunnycdn_resize);
  80. })
  81. // Close the popup success modal.
  82. .on('click', '.w3tc_cdn_bunnycdn_fsd_done', function() {
  83. window.location = window.location + '&';
  84. })
  85. // Load the deauthorize form.
  86. .on('click', '.w3tc_cdn_bunnycdn_fsd_deauthorization', function() {
  87. W3tc_Lightbox.open({
  88. id:'w3tc-overlay',
  89. close: '',
  90. width: 800,
  91. height: 300,
  92. url: ajaxurl +
  93. '?action=w3tc_ajax&_wpnonce=' +
  94. w3tc_nonce +
  95. '&w3tc_action=cdn_bunnycdn_fsd_deauthorization',
  96. callback: w3tc_bunnycdn_resize
  97. });
  98. })
  99. // Deauthorize and optionally delete the pull zone.
  100. .on('click', '.w3tc_cdn_bunnycdn_fsd_deauthorize', function() {
  101. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  102. '&w3tc_action=cdn_bunnycdn_fsd_deauthorize';
  103. W3tc_Lightbox.load_form(url, '.w3tc_cdn_bunnycdn_fsd_form', w3tc_bunnycdn_resize);
  104. });
  105. });