1/* 2 * VenoBox - jQuery Plugin 3 * version: 1.6.0 4 * @requires jQuery 5 * 6 * Examples at http://lab.veno.it/venobox/ 7 * License: MIT License 8 * License URI: https://github.com/nicolafranchini/VenoBox/blob/master/LICENSE 9 * Copyright 2013-2015 Nicola Franchini - @nicolafranchini 10 * 11 */ 12(function($){ 13 14 var autoplay, bgcolor, blocknum, blocktitle, border, core, container, content, dest, 15 evitacontent, evitanext, evitaprev, extraCss, figliall, framewidth, frameheight, 16 infinigall, items, keyNavigationDisabled, margine, numeratio, overlayColor, overlay, 17 prima, title, thisgall, thenext, theprev, type, 18 finH, sonH, nextok, prevok; 19 20 $.fn.extend({ 21 //plugin name - venobox 22 venobox: function(options) { 23 24 // default option 25 var defaults = { 26 framewidth: '', 27 frameheight: '', 28 border: '0', 29 bgcolor: '#fff', 30 titleattr: 'title', // specific attribute to get a title (e.g. [data-title]) - thanx @mendezcode 31 numeratio: false, 32 infinigall: false, 33 overlayclose: true // disable overlay click-close - thanx @martybalandis 34 }; 35 36 var option = $.extend(defaults, options); 37 38 return this.each(function() { 39 var obj = $(this); 40 41 // Prevent double initialization - thanx @matthistuff 42 if(obj.data('venobox')) { 43 return true; 44 } 45 46 obj.addClass('vbox-item'); 47 obj.data('framewidth', option.framewidth); 48 obj.data('frameheight', option.frameheight); 49 obj.data('border', option.border); 50 obj.data('bgcolor', option.bgcolor); 51 obj.data('numeratio', option.numeratio); 52 obj.data('infinigall', option.infinigall); 53 obj.data('overlayclose', option.overlayclose); 54 obj.data('venobox', true); 55 56 obj.click(function(e){ 57 e.stopPropagation(); 58 e.preventDefault(); 59 obj = $(this); 60 overlayColor = obj.data('overlay'); 61 framewidth = obj.data('framewidth'); 62 frameheight = obj.data('frameheight'); 63 // set data-autoplay="true" for vimeo and youtube videos - thanx @zehfernandes 64 autoplay = obj.data('autoplay') || false; 65 border = obj.data('border'); 66 bgcolor = obj.data('bgcolor'); 67 nextok = false; 68 prevok = false; 69 keyNavigationDisabled = false; 70 71 // set a different url to be loaded via ajax using data-href="" - thanx @pixeline 72 dest = obj.data('href') || obj.attr('href'); 73 extraCss = obj.data( 'css' ) || ""; 74 75 $('body').addClass('vbox-open'); 76 core = '<div class="vbox-overlay ' + extraCss + '" style="background:'+ overlayColor +'"><div class="vbox-preloader">Loading...</div><div class="vbox-container"><div class="vbox-content"></div></div><div class="vbox-title"></div><div class="vbox-num">0/0</div><div class="vbox-close">X</div><div class="vbox-next">next</div><div class="vbox-prev">prev</div></div>'; 77 78 $('body').append(core); 79 80 overlay = $('.vbox-overlay'); 81 container = $('.vbox-container'); 82 content = $('.vbox-content'); 83 blocknum = $('.vbox-num'); 84 blocktitle = $('.vbox-title'); 85 86 content.html(''); 87 content.css('opacity', '0'); 88 89 checknav(); 90 91 overlay.css('min-height', $(window).outerHeight()); 92 93 // fade in overlay 94 overlay.animate({opacity:1}, 250, function(){ 95 96 if(obj.data('type') == 'iframe'){ 97 loadIframe(); 98 }else if (obj.data('type') == 'inline'){ 99 loadInline(); 100 }else if (obj.data('type') == 'ajax'){ 101 loadAjax(); 102 }else if (obj.data('type') == 'vimeo'){ 103 loadVimeo(autoplay); 104 }else if (obj.data('type') == 'youtube'){ 105 loadYoutube(autoplay); 106 } else { 107 content.html('<img src="'+dest+'">'); 108 preloadFirst(); 109 } 110 }); 111 112 /* -------- CHECK NEXT / PREV -------- */ 113 function checknav(){ 114 115 thisgall = obj.data('gall'); 116 numeratio = obj.data('numeratio'); 117 infinigall = obj.data('infinigall'); 118 119 items = $('.vbox-item[data-gall="' + thisgall + '"]'); 120 121 if(items.length > 1 && numeratio === true){ 122 blocknum.html(items.index(obj)+1 + ' / ' + items.length); 123 blocknum.show(); 124 }else{ 125 blocknum.hide(); 126 } 127 128 thenext = items.eq( items.index(obj) + 1 ); 129 theprev = items.eq( items.index(obj) - 1 ); 130 131 if(obj.attr(option.titleattr)){ 132 title = obj.attr(option.titleattr); 133 blocktitle.show(); 134 }else{ 135 title = ''; 136 blocktitle.hide(); 137 } 138 139 if (items.length > 1 && infinigall === true) { 140 141 nextok = true; 142 prevok = true; 143 144 if(thenext.length < 1 ){ 145 thenext = items.eq(0); 146 } 147 if(items.index(obj) < 1 ){ 148 theprev = items.eq( items.index(items.length) ); 149 } 150 151 } else { 152 153 if(thenext.length > 0 ){ 154 $('.vbox-next').css('display', 'block'); 155 nextok = true; 156 }else{ 157 $('.vbox-next').css('display', 'none'); 158 nextok = false;
159 } 160 if(items.index(obj) > 0 ){ 161 $('.vbox-prev').css('display', 'block'); 162 prevok = true; 163 }else{ 164 $('.vbox-prev').css('display', 'none'); 165 prevok = false; 166 } 167 } 168 } 169 170 /* -------- NAVIGATION CODE -------- */ 171 var gallnav = { 172 173 prev: function() { 174 175 if (keyNavigationDisabled) { 176 return; 177 } else { 178 keyNavigationDisabled = true; 179 } 180 181 overlayColor = theprev.data('overlay'); 182 183 framewidth = theprev.data('framewidth'); 184 frameheight = theprev.data('frameheight'); 185 border = theprev.data('border'); 186 bgcolor = theprev.data('bgcolor'); 187 dest = theprev.data('href') || theprev.attr('href'); 188 189 autoplay = theprev.data('autoplay'); 190 191 if(theprev.attr(option.titleattr)){ 192 title = theprev.attr(option.titleattr); 193 }else{ 194 title = ''; 195 } 196 197 if (overlayColor === undefined ) { 198 overlayColor = ""; 199 } 200 201 content.animate({ opacity:0}, 500, function(){ 202 203 overlay.css('background',overlayColor); 204 205 if (theprev.data('type') == 'iframe') { 206 loadIframe(); 207 } else if (theprev.data('type') == 'inline'){ 208 loadInline(); 209 } else if (theprev.data('type') == 'ajax'){ 210 loadAjax(); 211 } else if (theprev.data('type') == 'youtube'){ 212 loadYoutube(autoplay); 213 } else if (theprev.data('type') == 'vimeo'){ 214 loadVimeo(autoplay); 215 }else{ 216 content.html('<img src="'+dest+'">'); 217 preloadFirst(); 218 } 219 obj = theprev; 220 checknav(); 221 keyNavigationDisabled = false; 222 }); 223 224 }, 225 226 next: function() { 227 228 if (keyNavigationDisabled) { 229 return; 230 } else { 231 keyNavigationDisabled = true; 232 } 233 234 overlayColor = thenext.data('overlay'); 235 236 framewidth = thenext.data('framewidth'); 237 frameheight = thenext.data('frameheight'); 238 border = thenext.data('border'); 239 bgcolor = thenext.data('bgcolor'); 240 dest = thenext.data('href') || thenext.attr('href'); 241 autoplay = thenext.data('autoplay'); 242 243 if(thenext.attr(option.titleattr)){ 244 title = thenext.attr(option.titleattr); 245 }else{ 246 title = ''; 247 } 248 249 if (overlayColor === undefined ) { 250 overlayColor = ""; 251 } 252 253 content.animate({ opacity:0}, 500, function(){ 254 255 overlay.css('background',overlayColor); 256 257 if (thenext.data('type') == 'iframe') { 258 loadIframe(); 259 } else if (thenext.data('type') == 'inline'){ 260 loadInline(); 261 } else if (thenext.data('type') == 'ajax'){ 262 loadAjax(); 263 } else if (thenext.data('type') == 'youtube'){ 264 loadYoutube(autoplay); 265 } else if (thenext.data('type') == 'vimeo'){ 266 loadVimeo(autoplay); 267 }else{ 268 content.html('<img src="'+dest+'">'); 269 preloadFirst(); 270 } 271 obj = thenext; 272 checknav(); 273 keyNavigationDisabled = false;
274 }); 275 276 } 277 278 }; 279 280 /* -------- NAVIGATE WITH ARROW KEYS -------- */ 281 $('body').keydown(function(e) { 282 283 if(e.keyCode == 37 && prevok == true) { // left 284 gallnav.prev(); 285 } 286 287 if(e.keyCode == 39 && nextok == true) { // right 288 gallnav.next(); 289 } 290 291 }); 292 293 /* -------- PREVGALL -------- */ 294 $('.vbox-prev').click(function(){ 295 gallnav.prev(); 296 }); 297 298 /* -------- NEXTGALL -------- */ 299 $('.vbox-next').click(function(){ 300 gallnav.next(); 301 }); 302 303 /* -------- ESCAPE HANDLER -------- */ 304 function escapeHandler(e) { 305 if(e.keyCode === 27) { 306 closeVbox(); 307 } 308 } 309 310 /* -------- CLOSE VBOX -------- */ 311 312 function closeVbox(){ 313 314 $('body').removeClass('vbox-open'); 315 $('body').unbind('keydown', escapeHandler); 316 317 overlay.animate({opacity:0}
317, 500, function(){ 318 overlay.remove(); 319 keyNavigationDisabled = false; 320 obj.focus(); 321 }); 322 } 323 324 /* -------- CLOSE CLICK -------- */ 325 var closeclickclass = '.vbox-close, .vbox-overlay'; 326 if(!obj.data('overlayclose')){ 327 closeclickclass = '.vbox-close'; // close only on X 328 } 329 330 $(closeclickclass).click(function(e){ 331 evitacontent = '.figlio'; 332 evitaprev = '.vbox-prev'; 333 evitanext = '.vbox-next'; 334 figliall = '.figlio *'; 335 if(!$(e.target).is(evitacontent) && !$(e.target).is(evitanext) && !$(e.target).is(evitaprev)&& !$(e.target).is(figliall)){ 336 closeVbox(); 337 } 338 }); 339 $('body').keydown(escapeHandler); 340 return false; 341 }); 342 }); 343 } 344 }); 345 346 /* -------- LOAD AJAX -------- */ 347 function loadAjax(){ 348 $.ajax({ 349 url: dest, 350 cache: false 351 }).done(function( msg ) { 352 content.html('<div class="vbox-inline">'+ msg +'</div>'); 353 updateoverlay(true); 354 355 }).fail(function() { 356 content.html('<div class="vbox-inline"><p>Error retrieving contents, please retry</div>'); 357 updateoverlay(true); 358 }) 359 } 360 361 /* -------- LOAD IFRAME -------- */ 362 function loadIframe(){ 363 content.html('<iframe class="venoframe" src="'+dest+'"></iframe>'); 364 // $('.venoframe').load(function(){ // valid only for iFrames in same domain 365 updateoverlay(); 366 // }); 367 } 368 369 /* -------- LOAD VIMEO -------- */ 370 function loadVimeo(autoplay){ 371 var pezzi = dest.split('/'); 372 var videoid = pezzi[pezzi.length-1]; 373 var stringAutoplay = autoplay ? "?autoplay=1" : ""; 374 content.html('<iframe class="venoframe" webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder="0" src="//player.vimeo.com/video/'+videoid+stringAutoplay+'"></iframe>'); 375 updateoverlay(); 376 } 377 378 /* -------- LOAD YOUTUBE -------- */ 379 function loadYoutube(autoplay){ 380 var pezzi = dest.split('/'); 381 var videoid = pezzi[pezzi.length-1]; 382 var stringAutoplay = autoplay ? "?autoplay=1" : ""; 383 content.html('<iframe class="venoframe" webkitallowfullscreen mozallowfullscreen allowfullscreen src="//www.youtube.com/embed/'+videoid+stringAutoplay+'"></iframe>'); 384 updateoverlay(); 385 } 386 387 /* -------- LOAD INLINE -------- */ 388 function loadInline(){ 389 content.html('<div class="vbox-inline">'+$(dest).html()+'</div>'); 390 updateoverlay(); 391 } 392 393 /* -------- PRELOAD IMAGE -------- */ 394 function preloadFirst(){ 395 prima = $('.vbox-content').find('img'); 396 prima.one('load', function() { 397 updateoverlay(); 398 }).each(function() { 399 if(this.complete) $(this).load(); 400 }); 401 } 402 403 /* -------- CENTER ON LOAD -------- */ 404 function updateoverlay(){ 405 406 blocktitle.html(title); 407 content.find(">:first-child").addClass('figlio'); 408 $('.figlio').css('width', framewidth).css('height', frameheight).css('padding', border).css('background', bgcolor); 409 410 sonH = content.outerHeight(); 411 finH = $(window).height(); 412 413 if(sonH+80 < finH){ 414 margine = (finH - sonH)/2; 415 content.css('margin-top', margine); 416 content.css('margin-bottom', margine); 417 418 }else{ 419 content.css('margin-top', '40px'); 420 content.css('margin-bottom', '40px'); 421 } 422 content.animate({ 423 'opacity': '1' 424 },'slow'); 425 } 426 427 /* -------- CENTER ON RESIZE -------- */ 428 function updateoverlayresize(){ 429 if($('.vbox-content').length){ 430 sonH = content.height(); 431 finH = $(window).height(); 432 433 if(sonH+80 < finH){ 434 margine = (finH - sonH)/2; 435 content.css('margin-top', margine); 436 content.css('margin-bottom', margine); 437 }else{ 438 content.css('margin-top', '40px'); 439 content.css('margin-bottom', '40px'); 440 } 441 } 442 } 443 444 $(window).resize(function(){ 445 updateoverlayresize(); 446 }); 447 448})(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.