Skip to content

Instantly share code, notes, and snippets.

@vodanh1213
Created June 1, 2015 05:16
Show Gist options
  • Save vodanh1213/8e5a023a8b685a534bc4 to your computer and use it in GitHub Desktop.
Save vodanh1213/8e5a023a8b685a534bc4 to your computer and use it in GitHub Desktop.
!function(){function t(t){"closed"===r?t._show()?(s=t,r="open"):e(t):u[u.length]=t}function e(){if(r="closed",s=null,u.length>0){var e=u.shift();t(e)}}function o(t,e,o){var n,p,d=0,r=i(window.location.toString()),u=i(document.referrer.toString()),s=null,c=function(e){s=jQuery.extend({},t),s.popup=e,a(s)};return void 0!==window.force_popover&&(d=window.force_popover.toString()),void 0!==e&&(d=e.toString()),t.ajax_data=t.ajax_data||{},p=jQuery.extend({},t.ajax_data),p.action="inc_popup",p["do"]=t["do"],p.thefrom=r,p.thereferrer=u,d&&(p.po_id=d),o&&(p.data=o),t.preview&&(p.preview=!0),n={url:t.ajaxurl,dataType:"jsonp",jsonpCallback:"po_data",data:p,success:function(t){c(t)},complete:function(){jQuery(document).trigger("popup-load-done",[s])}},jQuery.ajax(n)}function a(t){if(void 0!==t){var e=function(t){void 0!==t&&(void 0!==t.popup&&void 0!==t.popup.html&&(jQuery('<style type="text/css">'+t.popup.styles+"</style>").appendTo("head"),jQuery(t.popup.html).appendTo("body").hide()),window.inc_popup=new d(t),window.inc_popups[window.inc_popups.length]=window.inc_popup,jQuery(document).trigger("popup-initialized",[window.inc_popup]),t.noinit||t.preview||window.inc_popup.init())};if(t.popup instanceof Array)for(var o=0;o<t.popup.length;o+=1){var a=jQuery.extend({},t);a.popup=t.popup[o],e(a)}else t instanceof Object&&e(t)}}function i(t){for(var e=[],o=0;o<t.length;o++){if(o+1<t.length){var a=t.charCodeAt(o),i=t.charCodeAt(o+1);if(a>=55296&&56319>=a&&56320===(64512&i)||i>=768&&879>=i){e.unshift(t.substring(o,o+2)),o++;continue}}e.unshift(t[o])}return e.join("")}var n=[],p=!1,d=function(a){var i=this,d=jQuery(document),r=jQuery(window),u=null,s=null,c=null,l=null,h=null,f=null,m=null,_=null;return this.data={},this.have_popup=!1,this.ajax_data={},this.opened=0,this.close_forever=function(){var t=i.data.expiry||365;return i.close_popup(),a.preview?!1:(i.set_cookie("po_h",1,t),!1)},this.close_popup=function(){function t(){i.data.display_data.click_multi?(_.hide(),u.hide()):(_.remove(),u.remove(),i.have_popup=!1),d.trigger("popup-closed"),d.trigger("popover-closed")}return jQuery("html").removeClass("has-popup"),i.data.animation_out?(s.addClass(i.data.animation_out+" animated"),s.one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){s.removeClass("animated"),s.removeClass(i.data.animation_out),t()})):t(),e(i),!1},this.background_clicked=function(t){var e=jQuery(t.target);if(e.hasClass("wdpu-background")){if(!i.data.overlay_close)return;i.data.close_hide?i.close_forever():i.close_popup()}},this.move_popup=function(){var t,e,o,a=0,n=0;i.data.custom_size&&(i.data.height&&!isNaN(i.data.height)&&(f.data("reduce-height")&&(o=jQuery(f.data("reduce-height")),n=o.outerHeight()),e=i.data.height-n,100>e&&(e=100),f.height(e)),i.data.width&&!isNaN(i.data.width)&&(f.data("reduce-width")&&(o=jQuery(f.data("reduce-width")),a=o.outerWidth()),t=i.data.width-a,100>t&&(t=100),f.width(t)));var p=function(){if(!h.hasClass("no-move-x")){var t=r.width(),e=s.outerWidth(),o=(t-e)/2;10>o&&(o=10),h.css({left:o})}if(!h.hasClass("no-move-y")){var a=r.height(),i=s.outerHeight(),n=(a-i)/2;10>n&&(n=10),h.css({top:n})}if(m.length){var p,d,u=m.width(),c=m.height(),l=m.parent().width(),f=m.parent().height();u>l?(p=(l-u)/2,m.css({"margin-left":p})):m.css({"margin-left":0}),c>f?(d=(f-c)/2,m.css({"margin-top":d})):m.css({"margin-top":0})}};window.setTimeout(p,20),p()},this.reject=function(){i.have_popup=!1,i.data={}},this.prepare=function(){if(i.fetch_dom(),u.css({opacity:0,"z-index":-1,position:"fixed",left:-1e3,width:100,right:"auto",top:-1e3,height:100,bottom:"auto"}).show(),console.log(u),d.trigger("popup-init",[i,i.data]),i.have_popup)switch(i.data.display){case"scroll":r.on("scroll",i.show_at_position);break;case"anchor":r.on("scroll",i.show_at_element);break;case"delay":var e=1e3*i.data.display_data.delay;"m"===i.data.display_data.delay_type&&(e*=60),window.setTimeout(function(){t(i)},e);break;default:window.setTimeout(function(){"function"==typeof i.custom_handler&&i.custom_handler(i)},20)}},this.show_at_position=function(){var e,o,a=jQuery(this),n=a.scrollTop();"px"===i.data.display_data.scroll_type?n>=i.data.display_data.scroll&&(r.off("scroll",i.show_at_position),t(i)):(e=d.height()-r.height(),o=100*n/e,o>=i.data.display_data.scroll&&(r.off("scroll",i.show_at_position),t(i)))},this.show_at_element=function(){var e=jQuery(i.data.display_data.anchor),o=r.scrollTop(),a=o+r.height(),n=e.offset().top,p=a-n;p>10&&(r.off("scroll",i.show_at_element),t(i))},this.show_popup=function(){return t(i),!1},this._show=function(){var t;return u.length?(t=parseInt(i.get_cookie("po_c"),10),isNaN(t)&&(t=0),i.set_cookie("po_c",t+1,365),i.opened+=1,_.on("click",i.background_clicked),r.off("resize.popup").on("resize.popup",function(){i.move_popup(i.data)}),u.removeAttr("style").show(),_.show(),jQuery("html").addClass(i.data.scroll_body?"has-popup can-scroll":"has-popup no-scroll"),s.hide(),window.setTimeout(function(){s.show()},2),i.move_popup(i.data),i.setup_popup(),i.prepare_animation(),i.data.animation_in&&(s.addClass(i.data.animation_in+" animated"),s.one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){s.removeClass("animated"),s.removeClass(i.data.animation_in)})),!0):!1},this.prepare_animation=function(){var t=!1,e="Webkit Moz O ms Khtml".split(" ");if(void 0!==s[0].style.animationName&&(t=!0),t===!1)for(var o=0;o<e.length;o++)if(void 0!==s[0].style[e[o]+"AnimationName"]){t=!0;break}t||(i.data.animation_in="",i.data.animation_out="")},this.setup_popup=function(){l.off("click",i.close_forever).on("click",i.close_forever),i.data&&i.data.close_hide?(c.off("click",i.close_forever).on("click",i.close_forever),s.off("click",".close",i.close_forever).on("click",".close",i.close_forever)):(c.off("click",i.close_popup).on("click",i.close_popup),s.off("click",".close",i.close_popup).on("click",".close",i.close_popup)),s.hover(function(){jQuery(".claimbutton").removeClass("hide")},function(){jQuery(".claimbutton").addClass("hide")}),d.trigger("popup-displayed",[i.data,i]),d.trigger("popover-displayed",[i.data,i]),u.off("submit","form",i.form_submit).on("submit","form",i.form_submit)},this.fetch_dom=function(){u=jQuery("#"+i.data.html_id),u.length||i.reject(),f=u.find(".resize"),h=u.find(".move"),s=u.find(".wdpu-msg"),c=u.find(".wdpu-close-ex"),l=u.find(".wdpu-hide-forever"),m=u.find(".wdpu-image > img"),u.hasClass("wdpu-background")?_=u:(_=u.find(".wdpu-background"),_.length||(_=u.parents(".wdpu-background"))),h.length||(h=u),f.length||(f=u)},this.load_popup=function(t,e){void 0===t&&a.preview||(i.have_popup=!1,o(a,t,e))},this.form_submit=function(){function t(){var t=!1;"complete"!==u[0].contentDocument.readyState||p?(s+=1,s>200&&(d.trigger("popup-submit-timeout",[i,i.data]),t=!0)):t=!0,t&&(window.clearInterval(r),a())}function e(t){return void 0!==t&&(i.data.close_popup=t),n?(i.data.ajax_history=n,n.length&&(i.data.last_ajax=n[0])):(i.data.ajax_history=[],i.data.last_ajax={}),d.trigger("popup-submit-done",[i,i.data]),i.data.close_popup?(i.close_popup(),!0):!1}function o(t,o,a){var n=t,p=l.find(".wdpu-msg-inner"),r=l.find(".wdpu-title"),u=l.find(".wdpu-subtitle");n instanceof jQuery||(n=jQuery("<div></div>").html(t)),n instanceof jQuery&&(n.hasClass("wdpu-msg-inner")?p.replaceWith(n):p.find(".wdpu-content").empty().append(n)),void 0!==o&&r.html(o),void 0!==a&&u.html(a),i.move_popup(),i.setup_popup(),e(),i.fetch_dom(),i.setup_popup(),d.trigger("popup-init",[i,i.data])}function a(){var t,a,n,p,r;if(d.trigger("popup-submit-process",[u,i,i.data]),!i.data.form_submit)return!1;r="ignore"===i.data.form_submit?!1:!0;try{n=jQuery(m,u[0].contentDocument),p=i.data.did_ajax}catch(s){n=jQuery("<html></html>"),p=!0}i.data.close_popup=!1,h.removeClass("wdpu-loading"),t=n.find(".wdpu-msg-inner"),a=l.find(".wdpu-msg-inner"),jQuery("#wdpu-frame").remove(),i.data.last_ajax=void 0,"close"===i.data.form_submit?e(!0):i.data.new_content?o(i.data.new_content,i.data.new_title,i.data.new_subtitle):p?e(r):n.length&&n.html().length?a.length&&t.length&&t.text().length?o(t):e(r):e(!0)}var r,u,s,c=jQuery(this),l=c.parents(".wdpu-container").first(),h=l.find(".wdpu-msg"),f=jQuery('<input type="hidden" name="_po_method_" />'),m=".wdpu-"+i.data.popup_id;return l.length?("redirect"!==i.data.form_submit&&(u=jQuery('<iframe id="wdpu-frame" name="wdpu-frame"></iframe>').hide().appendTo("body"),c.attr("target","wdpu-frame"),f.appendTo(c).val("raw")),h.addClass("wdpu-loading"),"redirect"===i.data.form_submit?window.setTimeout(function(){i.close_popup()},10):p?(i.data.did_ajax=!0,s=0,r=window.setInterval(t,50)):(i.data.did_ajax=!1,u.load(a)),!0):!0},this.init=function(){a.popup?(i.have_popup=!0,i.data=a.popup,i.exec_scripts(),i.prepare()):i.load_popup()},this.exec_scripts=function(){var t;void 0!==i.data.script&&(t=new Function("me",i.data.script))(i)},this.get_cookie=function(t){var e,o,a,n=document.cookie.split(";");for(a=i.data&&i.data.popup_id?t+"-"+i.data.popup_id+"=":t+"=",e=0;e<n.length;e+=1){for(o=n[e];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(a))return o.substring(a.length,o.length)}return null},this.set_cookie=function(t,e,o){var n,p,d;a.preview||(isNaN(o)?p="":(n=new Date,n.setTime(n.getTime()+24*o*60*60*1e3),p="; expires="+n.toGMTString()),d=i.data&&i.data.popup_id?t+"-"+i.data.popup_id:t,document.cookie=d+"="+e+p+"; path=/")},{init:i.init,load:i.load_popup,extend:i}},r="closed",u=[],s=null;jQuery(document).ajaxStart(function(){p=!0}),jQuery(document).ajaxComplete(function(t,e){p=!1,n.unshift(e)}),jQuery(function(){window.inc_popups=[],a(_popup_data)})}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment