1 2$(document).ready(function() { 3// 4 5//========= page=========== 6 7 8 9 10$('#btn-nav').click(function(){ 11 $('#nav').slideToggle('fast'); 12}); 13 14 15$(window).resize(function(){ 16 if ($(window).width() > 1220) 17 $('#nav').css('display', ''); 18}); 19 20 21/******************************************************************************** 22siMGallery 23********************************************************************************/ 24 25(function(win) 26{ 27 28 function Gallery(settings) 29 { 30 settings = settings || {}; 31 this._settings = 32 this.__extend( 33 { 34 preloader: true, 35 eventKeyup: true, 36 log: false 37 }, 38 settings 39 ); 40 this._elements = new Array(); 41 this._index = 1; 42 this._keyup = false; 43 44 this.__log('Settings init :'); 45 this.__log(this._settings); 46 if (this._settings.eventKeyup) this.__addEventKeyup(); 47 } 48 49 Gallery.prototype.__extend = function(a, b) 50 { 51 let c = {}; 52 for(let p in a) 53 c[p] = (b[p] == null) ? a[p] : b[p]; 54 return c; 55 } 56 57 Gallery.prototype.add = function(obj) 58 { 59 if ( 60 typeof obj === 'object' 61 && obj.hasOwnProperty('title') 62 && obj.hasOwnProperty('picture') 63 ) 64 { 65 this._elements.push( 66 { 67 'title' : obj.title || '', 68 'picture' : obj.picture || '', 69 'desc' : obj.desc || '', 70 'preloader' : false 71 } 72 ); 73 74 this.__log('Add object (' + this._elements.length + ') :'); 75 this.__log(obj); 76 77 return this._elements.length; 78 } 79 80 return 0; 81 } 82 83 Gallery.prototype.open = function(index) 84 { 85 if (!Number.isInteger(index)) 86 return 0; 87 88 this._index = index || 1; 89 if (this._settings.preloader) this.__preloader(this._index); 90 this.__build(); 91 this.__send(); 92 this._keyup = true; 93 } 94 95 Gallery.prototype.__build = function() 96 { 97 document.body.style.overflow = 'hidden'; 98 99 let modal = document.createElement('div'); 100 modal.setAttribute('class', 'si-mgallery'); 101 102 let header = document.createElement('div'); 103 header.setAttribute('class', 'si-mgallery__header'); 104 modal.appendChild(header); 105 106 let main = document.createElement('div'); 107 this._main = main; 108 main.setAttribute('class', 'si-mgallery__main'); 109 modal.appendChild(main); 110 111 let desc = document.createElement('div'); 112 this._desc = desc; 113 desc.setAttribute('class', 'si-mgallery__desc'); 114 modal.appendChild(desc); 115 116 let title = document.createElement('div'); 117 this._title = title; 118 title.setAttribute('class', 'si-mgallery__title'); 119 header.appendChild(title); 120 121 let nav = document.createElement('ul'); 122 nav.setAttribute('class', 'si-mgallery__nav'); 123 header.appendChild(nav); 124 125 let prev = document.createElement('li'); 126 prev.addEventListener('click', function() { this.__prev(); }.bind(this), false); 127 prev.setAttribute('class', 'si-mgallery__prev'); 128 nav.appendChild(prev); 129 130 let next = document.createElement('li'); 131 next.addEventListener('click', function() { this.__next(); }.bind(this), false); 132 next.setAttribute('class', 'si-mgallery__next'); 133 nav.appendChild(next); 134 135 let close = document.createElement('li'); 136 close.addEventListener('click', function() { this.__close(); }.bind(this), false); 137 close.setAttribute('class', 'si-mgallery__close'); 138 nav.appendChild(close); 139 140 document.body.appendChild(modal); 141 } 142 143 Gallery.prototype.__send = function() 144 { 145 if (this._index < 1 || this._index > this._elements.length) 146 { 147 alert('Error: Index no found!'); 148 return 0; 149 } 150 151 this.__log('Load objet : ' + this._index); 152 153 let data = this._elements[this._index - 1]; 154 this._title.textContent = data.title; 155 this._desc.textContent = data.desc; 156 157 this._main.textContent = ''; 158 if (data.picture) 159 { 160 161 let link = document.createElement('a'); 162 link.setAttribute('href', data.picture); 163 link.setAttribute('target', '_blank'); 164 let picture = new Image(); 165 link.appendChild(picture); 166 167 picture.onload = function(link) 168 { 169 this._main.appendChild(link); 170 }.bind(this,link); 171 picture.src = data.picture; 172 } 173 174 if (this._settings.preloader) 175 { 176 this.__preloader(this.__getPrevIndex()); 177 this.__preloader(this.__getNextIndex()); 178 } 179 } 180 181 Gallery.prototype.__close = function() 182 { 183 document.body.style.overflow = ''; 184 let element = document.querySelector( '.si-mgallery' ); 185 element.remove(); 186 this._keyup = false; 187 this.__log('Shutdown siMGallery') 188 } 189 190 Gallery.prototype.__getPrevIndex = function() 191 { 192 let index = this._index - 1; 193 if (index < 1) index = this._elements.length; 194 return index; 195 } 196 197 Gallery.prototype.__getNextIndex = function() 198 { 199 let index = this._index + 1; 200 if (index > this._elements.length) index = 1; 201 return index; 202 } 203 204 Gallery.prototype.__prev = function() 205 { 206 this._index = this.__getPrevIndex(); 207 this.__log('Update index : ' + this._index); 208 this.__send(); 209 } 210 211 Gallery.prototype.__next = function() 212 { 213 this._index = this.__getNextIndex(); 214 this.__log('Update index : ' + this._index); 215 this.__send(); 216 } 217 218 Gallery.prototype.__preloader = function(index) 219 { 220 if (index < 1 || index > this._elements.length) 221 { 222 alert('Error: Preloader index no found!'); 223 return 0; 224 } 225 226 let data = this._elements[index - 1]; 227 228 if (!data.preloader && data.picture) 229 { 230 let picture = new Image(); 231 picture.onload = function() 232 { 233 this.__log('Preload : ' + data.picture); 234 data.preloader = true; 235 }.bind(this); 236 picture.src = data.picture; 237 } 238 } 239 240 Gallery.prototype.__addEventKeyup = function() 241 { 242 document.addEventListener( 243 'keyup', 244 function(e) 245 { 246 if (!this._keyup) 247 return 0; 248 249 switch (e.which) 250 { 251 case 37: 252 this.__prev(); 253 break; 254 case 39: 255 this.__next(); 256 break; 257 case 27: 258 this.__close(); 259 break; 260 default: 261 return 0; 262 } 263 264 this.__log('Keyup event : ' + e.key + ' ('+e.which+')'); 265 266 }.bind(this), 267 false 268 ); 269 } 270 271 Gallery.prototype.__log = function(msg) 272 { 273 if (this._settings.log) console.log(msg); 274 } 275 276 win.siMGallery = Gallery; 277 278}(window)); 279 280 281/******************************************************************************** 282DOMLoaded 283********************************************************************************/ 284 285function DOMLoaded() 286{ 287 /** 288 * 289 * Exemple: 290 * on(document, "click", "div", function(e) { 291 * console.log('Hello word !'); 292 * }); 293 * 294 */ 295 let on = function(el, evt, sel, handler, bool) 296 { 297 bool = bool || true; 298 299 el.addEventListener 300 ( 301 evt, 302 function(event) 303 { 304 let t = event.target; 305 while (t && t !== this) 306 { 307 if (t.matches(sel)) 308 { 309 handler.call(t, event); 310 if (bool) break; 311 } 312 t = t.parentNode; 313 } 314 } 315 ); 316 }; 317 318 319 320 /* ***************** *\ 321 Init siMGallery 322 \* ***************** */ 323 324 (function() 325 { 326 327 let elements = document.querySelectorAll( '[data-event="si-mgallery"]' ); 328 if (elements.length >= 0) 329 { 330 var mg = new siMGallery(); 331
332 elements.forEach( 333 function(el) 334 { 335 let id = mg.add( 336 { 337 'title' : el.getAttribute('alt'), 338 'picture' : el.getAttribute('data-picture'), 339 'desc' : el.getAttribute('data-desc') 340 } 341 ); 342 if (id != 0) 343 { 344 el.addEventListener( 345 "click", 346 function(id) { mg.open(id); }.bind(mg, id), 347 false 348 ); 349 } 350 } 351 ); 352 } 353 })(); 354 355 356 /* ***************** *\ 357 Init data-event 358 \* ***************** */ 359 360 (function() 361 { 362 363 var handler = function() 364 { 365 366 let commande = this.getAttribute('data-event'); 367 368 switch (commande) 369 { 370 case 'accordion': 371 (new Accordion()).click(this); 372 break; 373 374 case 'si-mgallery': 375 break; 376 377 default: 378 console.log('Commande "' + commande + '" introuvable'); 379 } 380 } 381 382 on( document, 'click', '[data-event]', handler, true); 383 } 384 )(); 385 386 387} 388 389 390window.addEventListener("load", DOMLoaded, false); 391}); 392 393// 394 395//========= page===========
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.