|
8 | 8 | this.origHtmlMargin = parseFloat($('html').css('margin-top')); // Get the original margin-top of the HTML element so we can take that into account |
9 | 9 | this.options = $.extend({}, $.smartbanner.defaults, options); |
10 | 10 |
|
11 | | - var standalone = navigator.standalone // Check if it's already a standalone web app or running within a webui view of an app (not mobile safari) |
12 | | - , UA = navigator.userAgent; |
| 11 | + var standalone = navigator.standalone; // Check if it's already a standalone web app or running within a webui view of an app (not mobile safari) |
| 12 | + var UA = navigator.userAgent; |
13 | 13 |
|
14 | 14 | // Detect banner type (iOS or Android) |
15 | 15 | if (this.options.force) { |
16 | 16 | this.type = this.options.force; |
17 | | - } else if (UA.match(/Windows Phone 8/i) != null && UA.match(/Touch/i) !== null) { |
| 17 | + } else if (UA.match(/Windows Phone 8/i) !== null && UA.match(/Touch/i) !== null) { |
18 | 18 | this.type = 'windows'; |
19 | | - } else if (UA.match(/iPhone|iPod/i) != null || (UA.match(/iPad/) && this.options.iOSUniversalApp)) { |
20 | | - if (UA.match(/Safari/i) != null && |
21 | | - (UA.match(/CriOS/i) != null || |
| 19 | + } else if (UA.match(/iPhone|iPod/i) !== null || (UA.match(/iPad/) && this.options.iOSUniversalApp)) { |
| 20 | + if (UA.match(/Safari/i) !== null && |
| 21 | + (UA.match(/CriOS/i) !== null || |
22 | 22 | window.Number(UA.substr(UA.indexOf('OS ') + 3, 3).replace('_', '.')) < 6)) this.type = 'ios'; // Check webview and native smart banner support (iOS 6+) |
23 | 23 | } else if (UA.match(/\bSilk\/(.*\bMobile Safari\b)?/) || UA.match(/\bKF\w/) || UA.match('Kindle Fire')) { |
24 | 24 | this.type = 'kindle'; |
25 | | - } else if (UA.match(/Android/i) != null) { |
| 25 | + } else if (UA.match(/Android/i) !== null) { |
26 | 26 | this.type = 'android'; |
27 | 27 | } |
28 | 28 |
|
|
39 | 39 | var meta = $(this.type == 'android' ? 'meta[name="google-play-app"]' : |
40 | 40 | this.type == 'ios' ? 'meta[name="apple-itunes-app"]' : |
41 | 41 | this.type == 'kindle' ? 'meta[name="kindle-fire-app"]' : 'meta[name="msApplication-ID"]'); |
42 | | - if (meta.length == 0) return; |
| 42 | + if (meta.length === 0) return; |
43 | 43 |
|
44 | 44 | // For Windows Store apps, get the PackageFamilyName for protocol launch |
45 | 45 | if (this.type == 'windows') { |
|
68 | 68 |
|
69 | 69 | SmartBanner.prototype = { |
70 | 70 |
|
71 | | - constructor: SmartBanner |
| 71 | + constructor: SmartBanner, |
72 | 72 |
|
73 | | - , create: function() { |
74 | | - var iconURL |
75 | | - , link=(this.options.url ? this.options.url : (this.type == 'windows' ? 'ms-windows-store:navigate?appid=' : (this.type == 'android' ? 'market://details?id=' : (this.type == 'kindle' ? 'amzn://apps/android?asin=' : 'https://itunes.apple.com/' + this.options.appStoreLanguage + '/app/id'))) + this.appId) |
76 | | - , price = this.price || this.options.price |
77 | | - , inStore=price ? price + ' - ' + (this.type == 'android' ? this.options.inGooglePlay : this.type == 'kindle' ? this.options.inAmazonAppStore : this.type == 'ios' ? this.options.inAppStore : this.options.inWindowsStore) : '' |
78 | | - , gloss=this.options.iconGloss === null ? (this.type=='ios') : this.options.iconGloss; |
| 73 | + create: function() { |
| 74 | + var iconURL; |
| 75 | + var link=(this.options.url ? this.options.url : (this.type == 'windows' ? 'ms-windows-store:navigate?appid=' : (this.type == 'android' ? 'market://details?id=' : (this.type == 'kindle' ? 'amzn://apps/android?asin=' : 'https://itunes.apple.com/' + this.options.appStoreLanguage + '/app/id'))) + this.appId); |
| 76 | + var price = this.price || this.options.price; |
| 77 | + var inStore=price ? price + ' - ' + (this.type == 'android' ? this.options.inGooglePlay : this.type == 'kindle' ? this.options.inAmazonAppStore : this.type == 'ios' ? this.options.inAppStore : this.options.inWindowsStore) : ''; |
| 78 | + var gloss=this.options.iconGloss === null ? (this.type=='ios') : this.options.iconGloss; |
79 | 79 |
|
80 | 80 | if (this.type == 'android' && this.options.GooglePlayParams) { |
81 | 81 | link = link + '&referrer=' + this.options.GooglePlayParams; |
|
120 | 120 | .css('width', $(window).width() / this.scale); |
121 | 121 | } |
122 | 122 | $('#smartbanner').css('position', (this.options.layer) ? 'absolute' : 'static'); |
123 | | - } |
| 123 | + }, |
124 | 124 |
|
125 | | - , listen: function () { |
| 125 | + listen: function () { |
126 | 126 | $('#smartbanner .sb-close').on('click',$.proxy(this.close, this)); |
127 | 127 | $('#smartbanner .sb-button').on('click',$.proxy(this.install, this)); |
128 | | - } |
| 128 | + }, |
129 | 129 |
|
130 | | - , show: function(callback) { |
| 130 | + show: function(callback) { |
131 | 131 | var banner = $('#smartbanner'); |
132 | 132 | banner.stop(); |
133 | 133 |
|
|
148 | 148 | banner.slideDown(this.options.speedIn).addClass('shown'); |
149 | 149 | } |
150 | 150 | } |
151 | | - } |
| 151 | + }, |
152 | 152 |
|
153 | | - , hide: function(callback) { |
| 153 | + hide: function(callback) { |
154 | 154 | var banner = $('#smartbanner'); |
155 | 155 | banner.stop(); |
156 | 156 |
|
|
171 | 171 | banner.slideUp(this.options.speedOut).removeClass('shown'); |
172 | 172 | } |
173 | 173 | } |
174 | | - } |
| 174 | + }, |
175 | 175 |
|
176 | | - , close: function(e) { |
| 176 | + close: function(e) { |
177 | 177 | e.preventDefault(); |
178 | 178 | this.hide(); |
179 | 179 | this.setCookie('sb-closed','true',this.options.daysHidden); |
180 | | - } |
| 180 | + }, |
181 | 181 |
|
182 | | - , install: function(e) { |
| 182 | + install: function(e) { |
183 | 183 | if (this.options.hideOnInstall) { |
184 | 184 | this.hide(); |
185 | 185 | } |
186 | 186 | this.setCookie('sb-installed','true',this.options.daysReminder); |
187 | | - } |
| 187 | + }, |
188 | 188 |
|
189 | | - , setCookie: function(name, value, exdays) { |
| 189 | + setCookie: function(name, value, exdays) { |
190 | 190 | var exdate = new Date(); |
191 | 191 | exdate.setDate(exdate.getDate()+exdays); |
192 | | - value=encodeURI(value)+((exdays==null)?'':'; expires='+exdate.toUTCString()); |
| 192 | + value=encodeURI(value)+((exdays===null)?'':'; expires='+exdate.toUTCString()); |
193 | 193 | document.cookie=name+'='+value+'; path=/;'; |
194 | | - } |
| 194 | + }, |
195 | 195 |
|
196 | | - , getCookie: function(name) { |
| 196 | + getCookie: function(name) { |
197 | 197 | var i,x,y,ARRcookies = document.cookie.split(";"); |
198 | 198 | for(i=0;i<ARRcookies.length;i++) { |
199 | 199 | x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | return null; |
207 | | - } |
| 207 | + }, |
208 | 208 |
|
209 | 209 | // Demo only |
210 | | - , switchType: function() { |
| 210 | + switchType: function() { |
211 | 211 | var that = this; |
212 | 212 |
|
213 | 213 | this.hide(function () { |
|
223 | 223 | }; |
224 | 224 |
|
225 | 225 | $.smartbanner = function (option) { |
226 | | - var $window = $(window) |
227 | | - , data = $window.data('smartbanner') |
228 | | - , options = typeof option == 'object' && option; |
| 226 | + var $window = $(window); |
| 227 | + var data = $window.data('smartbanner'); |
| 228 | + var options = typeof option == 'object' && option; |
229 | 229 | if (!data) $window.data('smartbanner', (data = new SmartBanner(options))); |
230 | 230 | if (typeof option == 'string') data[option](); |
231 | 231 | }; |
|
0 commit comments