|
1
|
|
|
/*global jQuery:false */ |
|
2
|
|
|
var DEBUG = false; |
|
3
|
|
|
|
|
4
|
|
|
(function ($) { |
|
5
|
|
|
'use strict'; |
|
6
|
|
|
|
|
7
|
|
|
// Reading WordPress Options |
|
8
|
|
|
var wpboStr, wpboObj; |
|
9
|
|
|
if (typeof wpbo !== 'undefined') { |
|
10
|
|
|
wpboStr = wpbo.replace(/"/g, '"'); |
|
11
|
|
|
wpboObj = $.parseJSON(wpboStr); |
|
12
|
|
|
if (DEBUG) { |
|
13
|
|
|
console.log(wpboObj); |
|
14
|
|
|
} |
|
15
|
|
|
} else { |
|
16
|
|
|
wpboObj = { |
|
17
|
|
|
close_overlay: true, |
|
18
|
|
|
close_esc: true, |
|
19
|
|
|
cookie_lifetime: '30', |
|
20
|
|
|
animation: 'bounceIn', |
|
21
|
|
|
popup_id: 'betterOpt', |
|
22
|
|
|
overlayOpacity: 0.5, |
|
23
|
|
|
overlayColor: '#000', |
|
24
|
|
|
credit: true |
|
25
|
|
|
}; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
///////////////////// |
|
29
|
|
|
// Document Ready // |
|
30
|
|
|
///////////////////// |
|
31
|
|
|
$(function () { |
|
32
|
|
|
|
|
33
|
|
|
// Define vars |
|
34
|
|
|
var wpboCookie = 'wpbo_' + wpboObj.popup_id, |
|
35
|
|
|
wpboModal = $('.wpbo-modal').hide(), |
|
36
|
|
|
wpboForm = wpboModal.parent('.optform'); |
|
37
|
|
|
|
|
38
|
|
|
// Preload images |
|
39
|
|
|
function preload(arrayOfImages) { |
|
40
|
|
|
$(arrayOfImages).each(function () { |
|
41
|
|
|
$('<img />').attr('src', this).appendTo('body').hide(); |
|
42
|
|
|
}); |
|
43
|
|
|
} |
|
44
|
|
|
if ($('.wpbo-featured-img').length) { |
|
45
|
|
|
var wpboImages = $('.wpbo-featured-img').attr('src'); |
|
46
|
|
|
if (DEBUG) { |
|
47
|
|
|
console.log(wpboImages); |
|
48
|
|
|
} |
|
49
|
|
|
preload([wpboImages]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
wpboModal.easyModal({ |
|
53
|
|
|
top: 200, |
|
54
|
|
|
overlayOpacity: wpboObj.overlay_opacity, |
|
55
|
|
|
overlayColor: wpboObj.overlay_color, |
|
56
|
|
|
overlayClose: wpboObj.close_overlay, |
|
57
|
|
|
transitionIn: 'animated ' + wpboObj.animation, |
|
58
|
|
|
updateZIndexOnOpen: false, |
|
59
|
|
|
closeOnEscape: wpboObj.close_esc, |
|
60
|
|
|
closeButtonClass: '.wpbo-close', |
|
61
|
|
|
onClose: function () { |
|
62
|
|
|
|
|
63
|
|
|
// Set Cookie |
|
64
|
|
|
// @NOTE: Does not work locally, see http://stackoverflow.com/questions/335244/why-does-chrome-ignore-local-jquery-cookies |
|
65
|
|
|
var d = new Date(); |
|
66
|
|
|
d = d.toDateString(); |
|
67
|
|
|
d = d.split(' ').join('_'); |
|
68
|
|
|
$.cookie(wpboCookie, 'closed_on_' + d, { |
|
69
|
|
|
expires: wpboObj.cookie_lifetime, |
|
70
|
|
|
path: '/' |
|
71
|
|
|
}); |
|
72
|
|
|
}, |
|
73
|
|
|
onOpen: function () { |
|
74
|
|
|
|
|
75
|
|
|
// Save impressions |
|
76
|
|
|
var data = { |
|
77
|
|
|
'action': 'wpbo_new_impression', |
|
78
|
|
|
'popup_id': wpboObj.popup_id |
|
79
|
|
|
}; |
|
80
|
|
|
$.post(wpboObj.ajaxurl, data); |
|
81
|
|
|
|
|
82
|
|
|
// Trigger matchHeight |
|
83
|
|
|
if (jQuery().matchHeight) { |
|
84
|
|
|
$('.wpbo-col').matchHeight('.wpbo-grid-no-gutter'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Focus on the first form input |
|
88
|
|
|
wpboForm.find('input:first').focus(); |
|
89
|
|
|
|
|
90
|
|
|
// Disable the submit button onSubmit |
|
91
|
|
|
wpboForm.submit(function () { |
|
92
|
|
|
wpboForm.find('[type=submit]').prop('disabled', true).text('Please wait...'); |
|
93
|
|
|
}); |
|
94
|
|
|
|
|
95
|
|
|
// Add Credit |
|
96
|
|
|
if (wpboObj.credit === true) { |
|
97
|
|
|
wpboModal.append('<a class="wpbo-credit" href="http://betteropt.in/?utm_source=plugin&utm_medium=credit&utm_term=organic&utm_campaign=betteroptin" target="_blank">Popup created with <strong>BetterOptin</strong></a>'); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
}); |
|
101
|
|
|
|
|
102
|
|
|
// If cookie is not set, show the modal |
|
103
|
|
|
if ($.cookie(wpboCookie) == null) { |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$(document).one('mouseleave', function (e) { |
|
106
|
|
|
e.preventDefault(); |
|
107
|
|
|
|
|
108
|
|
|
// Open the modal |
|
109
|
|
|
wpboModal.trigger('openModal').addClass('wpbo-modal-active'); |
|
110
|
|
|
|
|
111
|
|
|
// Click outside animates the modal |
|
112
|
|
|
if (wpboObj.wiggle === true) { |
|
113
|
|
|
$(document).on('click', '.lean-overlay:not(".wpbo-modal")', function () { |
|
114
|
|
|
wpboModal.addClass('wpbo-tada'); |
|
115
|
|
|
wpboModal.on('oanimationend animationend webkitAnimationEnd', function () { |
|
116
|
|
|
$(this).removeClass('wpbo-tada'); |
|
117
|
|
|
}); |
|
118
|
|
|
}); |
|
119
|
|
|
} |
|
120
|
|
|
}); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
// Trigger the modal manually |
|
124
|
|
|
$('.wpbo-trigger').on('click', function (e) { |
|
125
|
|
|
e.preventDefault(); |
|
126
|
|
|
wpboModal.trigger('openModal').addClass('wpbo-modal-active'); |
|
127
|
|
|
}); |
|
128
|
|
|
|
|
129
|
|
|
// Hide close icon if option is enabled |
|
130
|
|
|
if (wpboObj.hide_close_button) { |
|
131
|
|
|
$('.wpbo-close').hide(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
}); |
|
135
|
|
|
|
|
136
|
|
|
}(jQuery)); |
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.
Read more about comparison operations.