Skip to content

Instantly share code, notes, and snippets.

@shynome
Created March 16, 2017 03:33
Show Gist options
  • Save shynome/77eaaecba9b34bd17c9f94f2918c849f to your computer and use it in GitHub Desktop.
Save shynome/77eaaecba9b34bd17c9f94f2918c849f to your computer and use it in GitHub Desktop.
fancybox
void function fancybox(){
var x = $('.fancybox')
, y = $('.fancybox-thumb')
$(document).on('click.clear','a.fancybox,a.fancybox-thumb',function(e){e.preventDefault()})
if(!$('.fancybox,.fancybox-ajax,.fancybox-thumb,.fancybox-thumb-ajax').length)return;
var deps = $.when()
var deps_thumb = $.when()
var options = {
helpers : {
thumbs : {
width : 80,
height : 120
}
}
}
if( $('.fancybox,.fancybox-ajax').length ){
deps = deps.then(function(){
return $.Deferred(function(p){
require.async(['fancybox','fancybox.css'],p.resolve)
})
})
}
if( $('.fancybox-thumb,.fancybox-thumb-ajax').length ){
deps_thumb = deps_thumb.then(function(){
return $.Deferred(function(p){
require.async(['fancybox','fancybox.css'],p.resolve)
})
}).then(function(){
return $.Deferred(function(p){
require.async(['fancybox-thumbs','fancybox-thumbs.css'],p.resolve)
})
})
}
$(document).on('click.clear','a.fancybox,a.fancybox-thumb',function(e){
var self = $(this)
var rel = self.attr('rel')
var group = $('[rel='+rel+']')
/**@type {JQueryDeferred} */
var _deps
if(self.hasClass('fancybox')){
_deps = deps
}
if(self.hasClass('fancybox-thumb')){
_deps = deps_thumb
}
_deps.then(function(){
$.fancybox.open(
group,
options
)
})
})
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment