/wp-content/plugins/out-of-the-box/includes/integrations/wpforms/WPForms.js

https://github.com/livinglab/openlab · JavaScript · 85 lines · 84 code · 0 blank · 1 comment · 0 complexity · ba62fb1f576bfd0783c99ed200cd02f3 MD5 · raw file

  1. (function ($) {
  2. /* Shortcode Builder Popup */
  3. $('#wpforms-builder').on('click', '.outofthebox.open-shortcode-builder', function () {
  4. var input_field = $(this).prev();
  5. var shortcode = input_field.val().replace('[outofthebox ', '').replace('"]', '');
  6. window.addEventListener("message", callback_handler)
  7. openShortcodeBuilder(shortcode)
  8. $('.thickbox_data').removeClass('thickbox_data');
  9. input_field.addClass('thickbox_data');
  10. });
  11. function callback_handler(event) {
  12. if (event.origin !== window.parent.location.origin) {
  13. return;
  14. }
  15. if (typeof event.data !== 'object' || event.data === null || typeof event.data.action === 'undefined' || typeof event.data.shortcode === 'undefined') {
  16. return;
  17. }
  18. if (event.data.action !== 'wpcp-shortcode') {
  19. return;
  20. }
  21. if (event.data.slug !== 'outofthebox') {
  22. return;
  23. }
  24. $('.thickbox_data').val(event.data.shortcode).trigger('keyup change');
  25. window.modal_action.close();
  26. $('#outofthebox-modal-action').remove();
  27. window.removeEventListener("message", callback_handler)
  28. }
  29. function openShortcodeBuilder(shortcode) {
  30. if ($('#outofthebox-modal-action').length > 0) {
  31. window.modal_action.close();
  32. $('#outofthebox-modal-action').remove();
  33. }
  34. /* Build the Dialog */
  35. var modalbuttons = '';
  36. var modalheader = $('<a tabindex="0" class="close-button" title="" onclick="modal_action.close();"><i class="eva eva-close eva-lg" aria-hidden="true"></i></a></div>');
  37. var modalbody = $('<div class="outofthebox-modal-body" tabindex="0" style="display:none;padding:0!important;"></div>');
  38. var modaldialog = $('<div id="outofthebox-modal-action" class="OutoftheBox outofthebox-modal outofthebox-modal80 light"><div class="modal-dialog"><div class="modal-content" style="padding:40px 0 0 0!important"><div class="loading"><div class="loader-beat"></div></div></div></div></div>');
  39. $('body').append(modaldialog);
  40. var query = encodeURIComponent(shortcode).split('%3D%22').join('=').split('%22%20').join('&');
  41. var $iframe_template = $("<iframe src='" + window.ajaxurl + "?action=outofthebox-getpopup&type=shortcodebuilder&asuploadbox=1&" + query + "' width='100%' height='600' tabindex='-1' frameborder='0'></iframe>");
  42. var $iframe = $iframe_template.appendTo(modalbody);
  43. $('#outofthebox-modal-action .modal-content').append(modalheader, modalbody);
  44. $iframe.on('load', function () {
  45. $('.outofthebox-modal-body').fadeIn();
  46. $('.outofthebox-modal-footer').fadeIn();
  47. $('.modal-content .loading:first').fadeOut();
  48. });
  49. /* Open the Dialog */
  50. var modal_action = new RModal(document.getElementById('outofthebox-modal-action'), {
  51. bodyClass: 'rmodal-open',
  52. dialogOpenClass: 'animated slideInDown',
  53. dialogCloseClass: 'animated slideOutUp',
  54. escapeClose: true,
  55. afterClose() {
  56. window.removeEventListener("message", callback_handler)
  57. },
  58. });
  59. document.addEventListener('keydown', function (ev) {
  60. modal_action.keydown(ev);
  61. }, false);
  62. modal_action.open();
  63. window.modal_action = modal_action;
  64. }
  65. })(jQuery);