1/** 2 * ModalWindow wrapper. 3 * 4 * @author Htmlstream 5 * @version 1.0 6 * @requires appear.js (v1.0.3), custombox.js (v4.0.1) 7 * 8 */ 9;(function($){ 10 'use strict'; 11 12 $.HSCore.components.HSModalWindow = { 13 14 /** 15 * 16 * 17 * @var Object _baseConfig 18 */ 19 _baseConfig : { 20 bounds: 100, 21 debounce: 50, 22 overlayOpacity: .48, 23 overlayColor: '#000000', 24 speed: 400, 25 type: 'onscroll', // onscroll, beforeunload, hashlink, ontarget, aftersometime 26 effect: 'fadein', 27 onOpen: function() {}, 28 onClose: function() {}, 29 onComplete: function() {}, 30 }, 31 32 /** 33 * 34 * 35 * @var jQuery _pageCollection 36 */ 37 _pageCollection : $(), 38 39 /** 40 * Initialization of ModalWindow wrapper. 41 * 42 * @param String selector (optional) 43 * @param Object config (optional) 44 * 45 * @return jQuery - collection of initialized items. 46 */ 47 init: function(selector, config) { 48 49 var collection = $(selector); 50 if(!collection.length) return; 51 52 config = config && $.isPlainObject(config) ? $.extend({}, this._baseConfig, config) : this._baseConfig; 53 config.selector = selector; 54 55 this._pageCollection = this._pageCollection.add( collection.not(this._pageCollection) ); 56 57 if(config.autonomous) { 58 59 return this.initAutonomousModalWindows(collection, config); 60 61 } 62 63 return this.initBaseModalWindows(collection, config); 64 65 }, 66 67 /** 68 * Initialization of each Autonomous Modal Window of the page. 69 * 70 * @param jQuery collection 71 * @param Object config 72 * 73 * @return jQuery collection 74 */ 75 initBaseModalWindows: function(collection, config){ 76 77 return collection.on('click', function(e){ 78 79 if(!('Custombox' in window)) return; 80 81 var $this = $(this), 82 target = $this.data('modal-target'), 83 effect = $this.data('modal-effect') || config['effect']; 84 85 if(!target || !$(target).length) return; 86 87 new Custombox.modal( 88 { 89 content: { 90 target: target, 91 effect: effect, 92 onOpen: function() { 93 config['onOpen'].call($(target)); 94 Custombox.modal.closeAll(); 95 }, 96 onClose: function() { 97 config['onClose'].call($(target)); 98 }, 99 onComplete: function() { 100 config['onComplete'].call($(target)); 101 } 102 }, 103 overlay: { 104 color: $this.data('overlay-color') || config['overlayColor'], 105 opacity: $this.data('overlay-opacity') || config['overlayOpacity'], 106 speedIn: $this.data('speed') || config['speed'], 107 speedOut: $this.data('speed') || config['speed'] 108 } 109 } 110 ).open(); 111 112 e.preventDefault(); 113 114 }); 115 116 }, 117 118 /** 119 * Initialization of each Autonomous Modal Window of the page. 120 * 121 * @param jQuery collection 122 * @param Object config 123 * 124 * @return jQuery collection 125 */ 126 initAutonomousModalWindows: function(collection, config) { 127 128 var self = this; 129 130 return collection.each(function(i, el) { 131 132 var $this = $(el), 133 type = $this.data('modal-type'); 134 135 switch(type) { 136 137 case 'hashlink' : 138 139 self.initHashLinkPopup($this, config); 140 141 break; 142 143 case 'onscroll' : 144 145 self.initOnScrollPopup($this, config); 146 147 break; 148 149 case 'beforeunload' : 150 151 self.initBeforeUnloadPopup($this, config); 152 153 break; 154 155 case 'ontarget' : 156 157 self.initOnTargetPopup($this, config); 158 159 break; 160 161 case 'aftersometime' : 162 163 self.initAfterSomeTimePopup($this, config); 164 165 break; 166 167 } 168 169 }); 170 171 }, 172 173 /** 174 * 175 * 176 * @param jQuery popup 177 * 178 * @return undefined 179 */ 180 initHashLinkPopup: function(popup, config) { 181 182 var self = this, 183 hashItem = $(window.location.hash), 184 target = $('#' + popup.attr('id')); 185 186 if(hashItem.length && hashItem.attr('id') == popup.attr('id')){ 187 188 new Custombox.modal( 189 { 190 content: { 191 target: '#' + popup.attr('id'), 192 effect: popup.data('effect') || config['effect'], 193 onOpen: function() { 194 config['onOpen'].call($(target)); 195 }, 196 onClose: function() { 197 config['onClose'].call($(target)); 198 }, 199 onComplete: function() { 200 config['onComplete'].call($(target)); 201 } 202 }, 203 overlay: { 204 color: popup.data('overlay-color') || config['overlayColor'], 205 opacity: popup.data('overlay-opacity') || config['overlayOpacity'], 206 speedIn: popup.data('speed') || config['speed'], 207 speedOut: popup.data('speed') || config['speed'] 208 } 209 } 210 ).open(); 211 212 } 213 214 }, 215 216 /** 217 * 218 * 219 * @param jQuery popup 220 * 221 * @return undefined 222 */ 223 initOnScrollPopup: function(popup, config) { 224 225 var self = this, 226 $window = $(window), 227 breakpoint = popup.data('breakpoint') ? popup.data('breakpoint') : 0, 228 target = $('#' + popup.attr('id')); 229 230 231 $window.on('scroll.popup', function() { 232 233 var scrolled = $window.scrollTop() + $window.height(); 234 235 if(scrolled >= breakpoint) { 236 237 new Custombox.modal( 238 { 239 content: { 240 target: '#' + popup.attr('id'), 241 effect: popup.data('effect') || config['effect'], 242 onOpen: function() { 243 config['onOpen'].call($(target)); 244 }, 245 onClose: function() { 246 config['onClose'].call($(target)); 247 }, 248 onComplete: function() { 249 config['onComplete'].call($(target)); 250 } 251 }, 252 overlay: { 253 color: popup.data('overlay-color') || config['overlayColor'], 254 opacity: popup.data('overlay-opacity') || config['overlayOpacity'], 255 speedIn: popup.data('speed') || config['speed'], 256 speedOut: popup.data('speed') || config['speed'] 257 } 258 } 259 ).open(); 260 261 $window.off('scroll.popup'); 262 263 } 264 265 }); 266 267 $window.trigger('scroll.popup'); 268 269 }, 270 271 /** 272 * 273 * 274 * @param jQuery popup 275 * 276 * @return undefined 277 */ 278 initBeforeUnloadPopup: function(popup, config) { 279 280 var self = this, 281 count = 0, 282 target = $('#' + popup.attr('id')), 283 timeoutId; 284 285 window.addEventListener('mousemove', function(e) { 286 287 if(timeoutId) clearTimeout(timeoutId); 288 289 timeoutId = setTimeout(function() { 290 291 if (e.clientY < 10 && !count) { 292 293 count++; 294 295 new Custombox.modal( 296 { 297 content: { 298 target: '#' + popup.attr('id'), 299 effect: popup.data('effect') || config['effect'], 300 onOpen: function() { 301 config['onOpen'].call($(target)); 302 }, 303 onClose: function() { 304 config['onClose'].call($(target)); 305 }, 306 onComplete: function() { 307 config['onComplete'].call($(target)); 308 } 309 }, 310 overlay: { 311 color: popup.data('overlay-color') || config['overlayColor'], 312 opacity: popup.data('overlay-opacity') || config['overlayOpacity'], 313 speedIn: popup.data('speed') || config['speed'], 314 speedOut: popup.data('speed') || config['speed'] 315 } 316 } 317 ).open(); 318 319 } 320 321 }, 10); 322 323 }); 324 325 326 }, 327 328 /** 329 * 330 * 331 * @param jQuery popup 332 * 333 * @return undefined 334 */ 335 initOnTargetPopup: function(popup, config) { 336 337 var self = this, 338 target = popup.data('target'); 339 340 if(!target || !$(target).length) return; 341 342 appear({
343 bounds: config['bounds'], 344 debounce: config['debounce'], 345 elements: function() { 346 return document.querySelectorAll(target); 347 }, 348 appear: function(element) { 349 350 new Custombox.modal( 351 { 352 content: { 353 target: '#' + popup.attr('id'), 354 effect: popup.data('effect') || config['effect'], 355 onOpen: function() { 356 config['onOpen'].call($(target)); 357 }, 358 onClose: function() { 359 config['onClose'].call($(target)); 360 }, 361 onComplete: function() { 362 config['onComplete'].call($(target)); 363 } 364 }, 365 overlay: { 366 color: popup.data('overlay-color') || config['overlayColor'], 367 opacity: popup.data('overlay-opacity') || config['overlayOpacity'], 368 speedIn: popup.data('speed') || config['speed'], 369 speedOut: popup.data('speed') || config['speed'] 370 } 371 } 372 ).open(); 373 374 } 375 }); 376 377 }, 378 379 /** 380 * 381 * 382 * @param jQuery popup 383 * 384 * @return undefined 385 */ 386 initAfterSomeTimePopup: function(popup, config) { 387 388 var self = this, 389 target = $('#' + popup.attr('id')); 390 391 setTimeout(function() { 392 393 new Custombox.modal( 394 { 395 content: { 396 target: '#' + popup.attr('id'), 397 effect: popup.data('effect') || config['effect'], 398 onOpen: function() { 399 config['onOpen'].call($(target)); 400 }, 401 onClose: function() { 402 config['onClose'].call($(target)); 403 }, 404 onComplete: function() { 405 config['onComplete'].call($(target)); 406 } 407 }, 408 overlay: { 409 color: popup.data('overlay-color') || config['overlayColor'], 410 opacity: popup.data('overlay-opacity') || config['overlayOpacity'], 411 speedIn: popup.data('speed') || config['speed'], 412 speedOut: popup.data('speed') || config['speed'] 413 } 414 } 415 ).open(); 416 417 }, popup.data('delay') ? popup.data('delay') : 10) 418 419 } 420 421 }; 422 423})(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.