(function ($) { $.fn.ecwd_popup = function (opt) { //default params var default_options = { button: '', title: 'Event Details', body_id: '', body_class: '', container_class: '', fillhtml: false, only_open: false, get_ajax_data: function (el) { }, popup_close: function () { }, after_popup_show: function (el) { }, get_el_class: function (el) { } }; for (var key in default_options) { if (opt[key] == undefined) { opt[key] = default_options[key]; } } var params = opt; var el = $(this); el.hide(); params.button.on('click', function (e) { e.preventDefault(); var data = params.get_ajax_data($(this)); if (data) { if (params.fillhtml) { data.html = params.fillhtml.val(); } jQuery.post(ecwd.ajaxurl, data, function (response) { if (response != 0) { open_popup(response); show_gmap(); } }); } else if (params.fillhtml.length > 0 && params.fillhtml) { open_popup(params.fillhtml.val()); } else { open_popup(el.html()); } el.on('click', '.ecwd_close_popup', function () { el.hide(); jQuery('body').removeClass("body-ecwd_open_popup"); params.popup_close(el); }); $(document).keyup(function (e) { if (e.keyCode == 27) { // escape key maps to keycode `27` el.hide(); jQuery('body').removeClass("body-ecwd_open_popup"); params.popup_close(el); } }); }); function open_popup(html) { if (params.only_open == false) { add_popup(html); } jQuery('body').addClass("body-ecwd_open_popup"); el.show(); params.after_popup_show(el); el.addClass('ecwd_popup_el'); } function add_popup(html) { var head = get_popup_head(); var body = get_popup_body(html); var popup_html = "