1/* =========================================================== 2 * jquery-subscribe-better.js v1 3 * =========================================================== 4 * Copyright 2014 Pete Rojwongsuriya. 5 * http://www.thepetedesign.com 6 * 7 * Create a better, highly customizable subscription modal or 8 * newsletter signup window with jQuery Subscribe Better 9 * 10 * https://github.com/peachananr/subscribe-better 11 * 12 * ========================================================== */ 13 14!function($){ 15 16 var defaults = { 17 trigger: "atendpage", // atendpage | onload | onidle 18 animation: "fade", // fade | flyInRight | flyInLeft | flyInUp | flyInDown 19 delay: 0, 20 showOnce: true, 21 autoClose: false, 22 scrollableModal: false 23 }; 24 25 $.fn.subscribeBetter = function(options){ 26 var settings = $.extend({}, defaults, options), 27 el = $(this), 28 shown = false, 29 animating = false; 30 31 el.addClass("sb"); 32 33 $.fn.openWindow = function() { 34 var el = $(this); 35 if(el.is(":hidden") && shown == false && animating == false) { 36 animating = true; 37 38 setTimeout(function() { 39 if (settings.scrollableModal == true) { 40 if($(".sb-overlay").length < 1) { 41 $("body").append("<div class='sb-overlay'><div class='sb-close-backdrop'></div><div class='sb sb-withoverlay'>" + $(".sb").html() + "</div></div>"); 42 $(".sb-close-backdrop, .sb-close-btn").one("click", function() { 43 $(".sb.sb-withoverlay").closeWindow(); 44 return false; 45 }); 46 $(".sb.sb-withoverlay").removeClass("sb-animation-" + settings.animation.replace('In', 'Out')).addClass("sb-animation-" + settings.animation); 47 setTimeout(function(){ 48 $(".sb.sb-withoverlay").show(); 49 $("body").addClass("sb-open sb-open-with-overlay"); 50 }, 300); 51 } 52 } else { 53 if ($(".sb-overlay").length < 1) { 54 $("body").append("<div class='sb-overlay'><div class='sb-close-backdrop'></div></div>"); 55 $(".sb").removeClass("sb-animation-" + settings.animation.replace('In', 'Out')).addClass("sb-animation-" + settings.animation); 56 $(".sb-close-backdrop, .sb-close-btn").one("click", function() { 57 $(".sb").closeWindow(); 58 return false; 59 }); 60 setTimeout(function(){ 61 $(".sb").show(); 62 $("body").addClass("sb-open"); 63 }, 300); 64 } 65 66 } 67 if (settings.showOnce == true) shown = true; 68 animating = false; 69 }, settings.delay); 70 } 71 } 72 73 $.fn.closeWindow = function() { 74 var el = $(this); 75 if(el.is(":visible") && animating == false) { 76 animating = true; 77 if (settings.scrollableModal == true) { 78 79 $(".sb.sb-withoverlay").removeClass("sb-animation-" + settings.animation).addClass("sb-animation-" + settings.animation.replace('In', 'Out')); 80 81 setTimeout(function(){ 82 $(".sb.sb-withoverlay").hide(); 83 $("body").removeClass("sb-open sb-open-with-overlay"); 84 setTimeout(function() { 85 $(".sb-overlay").remove(); 86 }, 300); 87 }, 300); 88 89 } else { 90 91 $(".sb").removeClass("sb-animation-" + settings.animation).addClass("sb-animation-" + settings.animation.replace('In', 'Out')); 92 setTimeout(function(){ 93 $(".sb").hide(); 94 $("body").removeClass("sb-open"); 95 setTimeout(function() { 96 $(".sb-overlay").remove(); 97 }, 300); 98 }, 300); 99 } 100 animating = false; 101 } 102 } 103 104 $.fn.scrollDetection = function (trigger, onDone) { 105 var t, l = (new Date()).getTime(); 106 107 $(window).scroll(function(){ 108 var now = (new Date()).getTime(); 109 110 if(now - l > 400){ 111 $(this).trigger('scrollStart'); 112 l = now; 113 } 114 115 clearTimeout(t); 116 t = setTimeout(function(){ 117 $(window).trigger('scrollEnd'); 118 }, 300); 119 }); 120 if (trigger == "scrollStart") { 121 $(window).bind('scrollStart', function(){ 122 $(window).unbind('scrollEnd'); 123 onDone(); 124 }); 125 } 126 127 if (trigger == "scrollEnd") { 128 $(window).bind('scrollEnd', function(){ 129 $(window).unbind('scrollStart'); 130 onDone(); 131 }); 132 } 133 } 134 135 switch(settings.trigger) { 136 case "atendpage": 137 $(window).scroll(function(){ 138 var yPos = $(window).scrollTop(); 139 if (yPos >= ($(document).height() - $(window).height()) ) { 140 el.openWindow(); 141 } else { 142 if (yPos + 300 < ($(document).height() - $(window).height()) ) { 143 if(settings.autoClose == true) { 144 el.closeWindow(); 145 } 146 } 147 } 148 149 }); 150 break; 151 case "onload": 152 153 $(window).load(function(){ 154 el.openWindow(); 155 if(settings.autoClose == true) { 156 el.scrollDetection("scrollStart", function() { 157 el.closeWindow(); 158 }); 159 160 } 161 }); 162 163 break; 164 case "onidle": 165 166 $(window).load(function(){ 167 el.scrollDetection("scrollEnd", function() { 168 el.openWindow(); 169 }); 170 171 if(settings.autoClose == true) { 172 el.scrollDetection("scrollStart", function() { 173 el.closeWindow(); 174 }); 175 } 176 }); 177 178 break; 179 } 180 181 182 } 183 184}(window.jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.