1/* 2 Inspired by the lightbox plugin adapted to jquery by Leandro Vieira Pinho (http://leandrovieira.com) 3 4 @author : Nicolas Turlais : nicolas-at-insipi.de 5 @version : V0.3.1 - June 2012 6 @license : Licensed under CCAttribution-ShareAlike 7 @website : http://chocolat.insipi.de 8 9*/ 10(function($) { 11 images = []; 12 var calls = 0; 13 $.fn.Chocolat = function(settings) { 14 settings = $.extend({ 15 container : $('body'), 16 displayAsALink : false, 17 linkImages : true, 18 linksContainer : 'Choco_links_container', 19 overlayOpacity : 0.9, 20 overlayColor : '#fff', 21 fadeInOverlayduration : 500, 22 fadeInImageduration : 500, 23 fadeOutImageduration : 500, 24 vache : true, 25 separator1 : ' | ', 26 separator2 : '/', 27 leftImg : 'img/left.png', 28 rightImg : 'img/right.png', 29 closeImg : 'img/close.png', 30 loadingImg : 'img/loading.gif', 31 currentImage : 0, 32 setIndex : 0, 33 setTitle : '', 34 lastImage : 0 35 },settings); 36 37 calls++; 38 settings.setIndex = calls; 39 images[settings.setIndex] = []; 40 41 //images: 42 this.each(function(index){ 43 if(index == 0 && settings.linkImages && settings.setTitle == ''){ 44 settings.setTitle = isSet($(this).attr('rel'), ' '); 45 } 46 $(this).each(function() { 47 images[settings.setIndex]['displayAsALink'] = settings.displayAsALink; 48 images[settings.setIndex][index] = []; 49 images[settings.setIndex][index]['adress'] = isSet($(this).attr('href'), ' '); 50 images[settings.setIndex][index]['caption'] = isSet($(this).attr('title'), ' '); 51 if(!settings.displayAsALink){ 52 $(this).unbind('click').bind('click', { 53 id : settings.setIndex, 54 nom : settings.setTitle, 55 i : index 56 }, _initialise); 57 } 58 }) 59 }); 60 61 //setIndex: 62 for(var i = 0; i < images[settings.setIndex].length; i++) 63 { 64 if(images[settings.setIndex]['displayAsALink']){ 65 if($('#'+settings.linksContainer).size() == 0){ 66 this.filter(":first").before('<ul id="'+settings.linksContainer+'"></ul>'); 67 } 68 $('#'+settings.linksContainer).append('<li><a href="#" id="Choco_numsetIndex_'+settings.setIndex+'" class="Choco_link">'+settings.setTitle+'</a></li>'); 69 e = this.parent(); 70 $(this).remove(); 71 if($.trim(e.html()) == ""){//If parent empty : remove it 72 e.remove(); 73 } 74 return $('#Choco_numsetIndex_'+settings.setIndex).unbind('click').bind('click', {id: settings.setIndex, nom : settings.setTitle, i : settings.currentImage}, _initialise); 75 } 76 } 77 78 function _initialise(event) { 79 80 settings.currentImage = event.data.i; 81 settings.setIndex = event.data.id; 82 settings.setTitle = event.data.nom; 83 settings.lastImage = images[settings.setIndex].length - 1; 84 showChocolat(); 85 return false; 86 } 87 function _interface(){ 88 //html 89 clear(); 90 settings.container.append('<div id="Choco_overlay"></div><div id="Choco_content"><div id="Choco_close"></div><div id="Choco_loading"></div><div id="Choco_container_photo"><img id="Choco_bigImage" src="" /></div><div id="Choco_container_description"><span id="Choco_container_title"></span><span id="Choco_container_via"></span></div><div id="Choco_left_arrow" class="Choco_arrows"></div><div id="Choco_right_arrow" class="Choco_arrows"></div></div>'); 91 $('#Choco_left_arrow').css('background-image', 'url('+settings.leftImg+')'); 92 $('#Choco_right_arrow').css('background-image', 'url('+settings.rightImg+')'); 93 $('#Choco_close').css('background-image', 'url('+settings.closeImg+')'); 94 $('#Choco_loading').css('background-image', 'url('+settings.loadingImg+')'); 95 if(settings.container.get(0).nodeName.toLowerCase() !== 'body'){ 96 settings.container.css({'position':'relative','overflow':'hidden','line-height':'normal'});//yes, yes 97 $('#Choco_content').css('position','relative'); 98 $('#Choco_overlay').css('position', 'absolute'); 99 } 100 //events 101 $(document).unbind('keydown').bind('keydown', function(e){ 102 switch(e.keyCode){ 103 case 37: 104 changePageChocolat(-1); 105 break; 106 case 39: 107 changePageChocolat(1); 108 break; 109 case 27: 110 close(); 111 break; 112 }; 113 }); 114 if(settings.vache){ 115 $('#Choco_overlay').click(function(){ 116 close(); 117 return false;
118 }); 119 } 120 $('#Choco_left_arrow').unbind().bind('click', function(){ 121 changePageChocolat(-1); 122 return false; 123 }); 124 $('#Choco_right_arrow').unbind().bind('click', function(){ 125 changePageChocolat(1); 126 return false; 127 }); 128 $('#Choco_close').unbind().bind('click', function(){ 129 close(); 130 return false; 131 }); 132 $(window).resize(function() { 133 load(settings.currentImage,true); 134 }); 135 136 } 137 function showChocolat(){ 138 _interface(); 139 load(settings.currentImage, false); 140 $('#Choco_overlay') 141 .css({ 142 'background-color' : settings.overlayColor, 143 'opacity' : settings.overlayOpacity 144 }) 145 .fadeIn(settings.fadeInOverlayduration); 146 $('#Choco_content').fadeIn(settings.fadeInImageduration,function(){}); 147 148 } 149 function load(image,resize){ 150 settings.currentImage = image; 151 $('#Choco_loading').fadeIn(settings.fadeInImageduration); 152 var imgPreloader = new Image(); 153 imgPreloader.onload = function(){ 154 $('#Choco_bigImage').attr('src',images[settings.setIndex][settings.currentImage]['adress']); 155 var ajustees = iWantThePerfectImageSize(imgPreloader.height,imgPreloader.width); 156 ChoColat(ajustees['hauteur'],ajustees['largeur'],resize); 157 $('#Choco_loading').stop().fadeOut(settings.fadeOutImageduration); 158 }; 159 imgPreloader.src = images[settings.setIndex][settings.currentImage]['adress']; 160 preload(); 161 upadteDescription(); 162 } 163 function changePageChocolat(signe){ 164 if(!settings.linkImages || (settings.currentImage == 0 && signe == -1) || (settings.currentImage == settings.lastImage && signe == 1)) 165 { 166 return false; 167 } 168 else{ 169 //$('#Choco_container_description').fadeTo(settings.fadeOutImageduration,0); making a weird bug with firefox 17 170 $('#Choco_container_description').css('visibility','hidden'); 171 $('#Choco_bigImage').fadeTo(settings.fadeOutImageduration, 0, function(){ 172 load(settings.currentImage + parseInt(signe), false); 173 }); 174 } 175 } 176 function ChoColat(hauteur_image,largeur_image,resize){ 177 178 if(resize){ 179 $('#Choco_container_photo, #Choco_content, #Choco_bigImage').stop(true,false).css({'overflow':'visible'}); 180 $('#Choco_bigImage').animate({ 181 'height' : hauteur_image+'px', 182 'width' : largeur_image+'px' 183 },settings.fadeInImageduration); 184 } 185 $('#Choco_container_photo').animate({ 186 'height' : hauteur_image, 187 'width' : largeur_image 188 },settings.fadeInImageduration); 189 $('#Choco_content').animate({ 190 'height' : hauteur_image, 191 'width' : largeur_image, 192 'marginLeft' : -largeur_image/2, 193 'marginTop' : -(hauteur_image)/2 194 },settings.fadeInImageduration, 'swing', function(){ 195 $('#Choco_bigImage').fadeTo(settings.fadeInImageduration, 1).height(hauteur_image).width(largeur_image); 196 if(!resize) 197 { 198 arrowsManaging(); 199 //$('#Choco_container_description').fadeTo(settings.fadeInImageduration,1); making a weird bug with firefox 17 200 $('#Choco_container_description').css('visibility','visible'); 201 $('#Choco_close').fadeIn(settings.fadeInImageduration); 202 } 203 }). 204 css('overflow', 'visible'); 205 } 206 function arrowsManaging(){ 207 if(settings.linkImages){ 208 var what = ['Choco_right_arrow','Choco_left_arrow']; 209 for(var i=0; i < what.length; i++){ 210 hide = false;
211 if(what[i] == 'Choco_right_arrow' && settings.currentImage == settings.lastImage){ 212 hide = true; 213 $('#'+what[i]).fadeOut(300); 214 } 215 else if(what[i] == 'Choco_left_arrow' && settings.currentImage == 0){ 216 hide = true; 217 $('#'+what[i]).fadeOut(300); 218 } 219 if(!hide){ 220 $('#'+what[i]).fadeIn(settings.fadeOutImageduration); 221 } 222 } 223 } 224 } 225 function preload(){ 226 if(settings.currentImage !== settings.lastImage){ 227 i = new Image; 228 z = settings.currentImage + 1; 229 i.src = images[settings.setIndex][z]['adress']; 230 } 231 } 232 function upadteDescription(){ 233 var current = settings.currentImage + 1; 234 var last = settings.lastImage + 1; 235 $('#Choco_container_title').html(images[settings.setIndex][settings.currentImage]['caption']); 236 $('#Choco_container_via').html(settings.setTitle+settings.separator1+current +settings.separator2+last); 237 } 238 function isSet(variable,defaultValue){ 239 // return variable === undefined ? defaultValue : variable; ? 240 if (variable === undefined) { 241 return defaultValue; 242 } 243 else{ 244 return variable; 245 } 246 } 247 function iWantThePerfectImageSize(himg,limg){ 248 //28% = 14% + 14% margin 249 var lblock = limg + (limg*28/100); 250 var heightDescAndClose = $('#Choco_container_description').height()+$('#Choco_close').height(); 251 var hblock = himg + heightDescAndClose; 252 var k = limg/himg; 253 var kk = himg/limg; 254 if(settings.container.get(0).nodeName.toLowerCase() == 'body'){ 255 windowHeight = $(window).height(); 256 windowWidth = $(window).width(); 257 } 258 else{ 259 windowHeight = settings.container.height(); 260 windowWidth = settings.container.width(); 261 } 262 notFitting = true; 263 while (notFitting){ 264 var lblock = limg + (limg*28/100); 265 var hblock = himg + heightDescAndClose; 266 if(lblock > windowWidth){ 267 limg = windowWidth*100/128; 268 269 himg = kk * limg; 270 }else if(hblock > windowHeight){ 271 himg = (windowHeight - heightDescAndClose); 272 limg = k * himg; 273 }else{ 274 notFitting = false; 275 }; 276 }; 277 return { 278 largeur:limg, 279 hauteur:himg 280 }; 281 282 } 283 function clear(){ 284 $('#Choco_overlay').remove(); 285 $('#Choco_content').remove(); 286 } 287 function close(){ 288 $('#Choco_overlay').fadeOut(900, function(){$('#Choco_overlay').remove()}); 289 $('#Choco_content').fadeOut(500, function(){$('#Choco_content').remove()}); 290 settings.currentImage = 0; 291 } 292 293}; 294})(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.