1 2jQuery(function ($) { 3 'use strict'; 4 5 function dataAttrBool($element, name, default_value) { 6 var value = $element.attr('data-gallerie-' + name); 7 if (typeof value === 'undefined') { 8 return !!default_value; 9 } 10 if (value === 'false' || value === '0' || value === '' || !!value === false) { 11 return false; 12 } 13 return true; 14 } 15 16 function dataAttrInt($element, name, default_value) { 17 var value = $element.attr('data-gallerie-' + name); 18 if (typeof value !== 'undefined' && value.match(/^-?[0-9]+$/)) { 19 return parseInt(value, 10); 20 } 21 return default_value; 22 } 23 24 function escapeHtml(string) { 25 return String(string).replace(/[&<>"]/g, function (s) { 26 return { '&': '&', '<': '<', '>': '>', '"': '"' }[s]; 27 }); 28 } 29 30 function arrow(btnClass, iconClass, label) { 31 return '<button type="button" class="' + escapeHtml(btnClass) + 32 '" tabindex="0" data-role="none" role="button" aria-label="' + 33 escapeHtml(label) + '"><span class="' + escapeHtml(iconClass) + 34 '"></span><span class="sr-only">' + escapeHtml(label) + 35 '</span></button>'; 36 } 37 38 function precise_element_width(element) { 39 var compStyle = window.getComputedStyle(element), width; 40 41 if (typeof compStyle.width !== 'undefined') { 42 width = compStyle.width; 43 if (width.match(/^[0-9]+(\.[0-9]+)?px$/)) { 44 return parseFloat(width); 45 } 46 } 47 48 return (element).width(); // fallback... 49 } 50 51 function do_squarify_thumbs($thumbs, listWidth, slidesToShow) { 52 var window_width = $(window).width(), 53 size; 54 55 if (window_width < 480) { 56 slidesToShow = slidesToShow > 2 ? Math.max(2, Math.round(slidesToShow / Math.LN10)) : slidesToShow; 57 } else if (window_width < 768) { 58 slidesToShow = slidesToShow > 2 ? Math.max(2, Math.round(slidesToShow / Math.LOG2E)) : slidesToShow; 59 } 60 61 size = listWidth / slidesToShow; 62 63 $thumbs.children().each(function (i) { 64 var $outer = $(this), 65 $link = $outer, 66 $inner, 67 gutter = $outer.outerWidth(true) - $outer.width(), 68 width = size - (gutter || 0), 69 inner_w, 70 inner_h; 71 72 if (!$outer.hasClass('udem-gallerie-thumb')) { 73 $link = $outer.find('.udem-gallerie-thumb'); 74 } 75 76 $inner = $link.first().children(); 77 78 $link.css({ 79 overflow: 'hidden', 80 position: 'relative', 81 width: width + 'px', 82 height: width + 'px' 83 }); 84 85 if ($link.hasClass('udem-gallerie-icon-thumb')) { 86 // icon 87 $inner.css({ 88 lineHeight: 2, 89 fontSize: (width / 2) + 'px' 90 }); 91 } else { 92 // image 93 $inner.css({ 94 position: 'absolute', 95 width: 'auto', 96 height: 'auto', 97 minWidth: 'none', 98 minHeight: 'none', 99 maxWidth: 'none', 100 maxHeight: 'none' 101 }); 102 103 inner_w = $inner.width(); 104 inner_h = $inner.height(); 105 106 if (inner_w === 0 || inner_h === 0) { 107 return; 108 } 109 110 if (inner_w > inner_h) { 111 // landscape 112 if ($inner.is('img')) { 113 $inner.css({ 114 top: 0, 115 height: width + 'px', 116 width: 'auto', 117 left: (width * (1 - (inner_w / inner_h)) / 2) + 'px' 118 }); 119 } else { 120 $inner.css({ 121 top: ((width - inner_h) / 2) + 'px', 122 left: 0 123 }); 124 } 125 } else { 126 // portrait 127 if ($inner.is('img')) { 128 $inner.css({ 129 width: width + 'px', 130 left: 0, 131 height: 'auto', 132 top: width * (1 - (inner_h / inner_w)) / 2 133 }); 134 } else { 135 $inner.css({ 136 top: 0, 137 left: ((width - inner_h) / 2) + 'px' 138 }); 139 } 140 } 141 } 142 }); 143 } 144
145 function do_equalize_thumbs_heights(slick) { 146 var slidesToShow = slick.options.slidesToShow, 147 listWidth = slick.listWidth, 148 avg_size = listWidth / slidesToShow, 149 $slideTrack_items = slick.$slideTrack.children(), 150 ratios = [], 151 ratios_sum, 152 index, 153 $outer, 154 $link, 155 gutter, 156 loop_from, 157 loop_stop, 158 width, 159 targetheight, 160 currentSlide_index, 161 i; 162 163 if (listWidth < 1) { 164 return; 165 } 166 167 $slideTrack_items.each(function (i) { 168 var $outer = $(this), 169 $link = $outer.find('.udem-gallerie-thumb').first(), 170 $inner = $link.children().first(), 171 gutter = $outer.outerWidth(true) - $outer.width(), 172 w, 173 h; 174 175 if ($link.hasClass('udem-gallerie-icon-thumb')) { 176 // icon 177 h = avg_size; 178 w = avg_size + (gutter || 0); 179 180 $link.css({ 181 overflow: 'hidden', 182 width: avg_size + 'px', 183 height: avg_size + 'px' 184 }); 185 $inner.css({ 186 lineHeight: 2, 187 fontSize: (avg_size / 2) + 'px' 188 }); 189 ratios.push(w / h); 190 } else { 191 // image 192 // (may not be loaded yet. Assume square if dimensions are not available) 193 194 // Slick replace the width of our container with percentage value. Replace it by the stored value. 195 if ($link[0].style.width.slice(-1) === '%' && $link.data('width')) { 196 $link.css('width', $link.data('width') + 'px'); 197 }; 198 199 h = $inner.height() || avg_size; 200 w = $inner.width() || avg_size; 201 202 w += gutter || 0; 203 204 ratios.push(w / h); 205 } 206 }); 207 208 currentSlide_index = slick.currentSlide; 209 for (i = 0; i < $slideTrack_items.length; i++) { 210 if ($($slideTrack_items.get(i)).hasClass('slick-current')) { 211 currentSlide_index = i; 212 break; 213 } 214 } 215 216 if (slidesToShow > $slideTrack_items.length) { 217 loop_from = 0; 218 loop_stop = $slideTrack_items.length; 219 } else { 220 loop_from = currentSlide_index; 221 loop_stop = currentSlide_index + slidesToShow; 222 } 223 224 ratios_sum = ratios.slice(loop_from, loop_stop).reduce(function (s, v) { return s + v; }, 0); 225 226 for (index = loop_from; index < loop_stop; index++) { 227 $outer = $($slideTrack_items.get(index)); 228 $link = $outer.find('.udem-gallerie-thumb').first(); 229 if ($outer.length === 0) { 230 break; 231 } 232 233 gutter = $outer.outerWidth(true) - $outer.width(); 234 gutter = gutter || 0; 235 236 width = (listWidth + gutter) * ratios[index] / ratios_sum; 237 238 if (gutter) { 239 width -= gutter; 240 } 241 242 if ($link.hasClass('udem-gallerie-icon-thumb')) { 243 // icon 244 $link.css({ 245 width: width + 'px', 246 height: width + 'px' 247 }); 248 $link.children().first().css({ 249 lineHeight: 2, 250 fontSize: (width / 2) + 'px' 251 }); 252 } else { 253 // image 254 $link.css({ 255 width: width + 'px' 256 }); 257 } 258 } 259 260 // In some case, need to reajust slide offset 261 slick.animateSlide(slick.getLeft(slick.currentSlide)); 262 263 targetheight = Math.ceil($(slick.$slides.get(slick.currentSlide)).outerHeight(true)); 264 if (targetheight < 72) { 265 slick.$list.css({ height: 72, paddingTop: ((72 - targetheight) / 2) + 'px' }); 266 } else { 267 slick.$list.css({ height: targetheight, paddingTop: 0 }); 268 } 269 } 270 271 function is_video_item($item) { 272 var $c = $item.children('.content-container').first(); 273 return $c.hasClass('CType-udembootstrap_video') || ($c.hasClass('CType-shortcut') && $c.children('.content-container').first().hasClass('CType-udembootstrap_video')); 274 } 275 276 $('.udem-gallerie').each(function () { 277 var $container = $(this), 278 $items = $container.children('.udem-gallerie-item'), 279 $thumbs, 280 lang = $('html').attr('lang') === 'en' ? 'en' : 'fr', 281 l10n_precedent = lang === 'en' ? 'Previous' : 'Précédent', 282 l10n_suivant = lang === 'en' ? 'Next' : 'Suivant', 283 thumbs_per_row, 284 with_slick = typeof $container.slick === 'function'; 285 286 if ($items.length < 2) { 287 return; 288 } 289 290 thumbs_per_row = dataAttrInt($container, 'thumbs-per-row', 5); 291 if (thumbs_per_row < 1) { 292 thumbs_per_row = 5; 293 } 294 295 // Used to "justify"... Should we implement as an option? 296 // if (thumbs_per_row > $items.length) { 297 // thumbs_per_row = $items.length; 298 // } 299 300 $thumbs = $('<div></div>').addClass('udem-gallerie-thumbs').insertAfter($container); 301 302 $items.each(function () { 303 var $item = $(this), 304 item_id = $item.children().first().attr('id') || '', 305 $thumb = $('<a></a>').addClass('udem-gallerie-thumb').attr('href', '#' + item_id), 306 $img = $item.find('img').first(), 307 width; 308 309 if ($img.length) { 310 // image 311 $img = $img.clone(false); 312 $img.css({ 313 width: '100%' 314 }); 315 $img.appendTo($thumb); 316 317 if (is_video_item($item)) { 318 $thumb.addClass('udem-gallerie-video-img'); 319 } 320 } else { 321 // icon 322 $thumb.addClass('udem-gallerie-icon-thumb'); 323 if ($item.children().first().hasClass('CType-udembootstrap_video')) { 324 $('<span></span>').addClass('glyphicon').addClass('glyphicon-facetime-video').appendTo($thumb); 325 } else { 326 $('<span></span>').addClass('glyphicon').addClass('glyphicon-picture').appendTo($thumb); 327 } 328 } 329 330 width = $thumbs.width() / thumbs_per_row; 331 332 $thumb.css({ 333 float: 'left', 334 width: width + 'px' 335 }); 336 337 $thumb.appendTo($thumbs); 338 339 if (with_slick) { 340 // This value will be replaced by slick. Store it to be replaced later. 341 $thumb.data('width', width); 342 343 $thumb.on('click', function (event) { 344 event.preventDefault(); 345 }); 346 } else { 347 $items.first().addClass('udem-gallerie-item--active'); 348 $thumbs.children().first().addClass('udem-gallerie-thumb--active'); 349 350 $thumb.on('click', function (event) { 351 event.preventDefault(); 352 $container.children(':visible').not($item.get(0)).removeClass('udem-gallerie-item--active'); 353 $item.addClass('udem-gallerie-item--active'); 354 355 $thumbs.children(':visible').not($thumb.get(0)).removeClass('udem-gallerie-thumb--active'); 356 $thumb.addClass('udem-gallerie-thumb--active'); 357 }); 358 } 359 }); 360 361 function do_fix_heights() { 362 var $items = $container.children('.udem-gallerie-item'), 363 max_portrait_height = 0, 364 max_landscape_height = 0, 365 container_height; 366 367 $items.each(function (i) { 368 var $item = $(this), 369 h = $item.height(), 370 w = $item.width(); 371 372 if (h > w) { 373 if (h > max_portrait_height) { 374 max_portrait_height = h; 375 } 376 } else { 377 if (h > max_landscape_height) { 378 max_landscape_height = h; 379 } 380 } 381 }); 382 383 if (max_landscape_height === 0) { 384 // no landscape! 385 max_landscape_height = max_portrait_height; 386 } 387 388 $container.css({ 389 position: 'relative', 390 height: max_landscape_height + 'px', 391 overflow: 'hidden' 392 }); 393 394 $items.css({ 395 position: 'absolute', 396 bottom: 0, 397 left: 0, 398 height: 'auto', 399 width: '100%' 400 }); 401 402 container_height = $container.height(); 403 404 $items.each(function (i) { 405 var $item = $(this), 406 h = $item.height(), 407 w = $item.width(), 408 scale_ratio, 409 scale_offset = 0; 410 411 scale_ratio = container_height / h; 412 scale_offset = ((h * scale_ratio) - h) / 2; 413 414 if (h > w) { 415 $item.css({ 416 transform: 'scale(' + scale_ratio + ')', 417 margin: scale_offset + 'px 0' 418 }); 419 } else { 420 $item.css({ 421 transform: 'none', 422 margin: scale_offset + 'px 0' 423 }); 424 } 425 }); 426 } 427 428 if (!with_slick && !dataAttrBool($container, 'adaptive-height', false)) { 429 do_fix_heights(); 430 $(window).on('load resize', function () { 431 do_fix_heights(); 432 }); 433 } 434 435 if (with_slick) { 436 $thumbs.on('setPosition', function (event, slick) { 437 var squarify_thumbs = dataAttrBool($container, 'squarify-thumbs', false); 438 439 if (squarify_thumbs) { 440 do_squarify_thumbs(slick.$slideTrack, slick.listWidth, slick.options.slidesToShow); 441 // In some case, need to reajust slide offset 442 slick.animateSlide(slick.getLeft(slick.currentSlide)); 443 } else {
444 do_equalize_thumbs_heights(slick); 445 } 446 }); 447 448 $container.slick({ 449 slidesToShow: 1, 450 slidesToScroll: 1, 451 arrows: false, 452 adaptiveHeight: dataAttrBool($container, 'adaptive-height', false), 453 fade: true, 454 455 asNavFor: $thumbs 456 }); 457 458 $thumbs.slick({ 459 slidesToShow: thumbs_per_row, 460 slidesToScroll: 1, 461 dots: false, 462 focusOnSelect: true, 463 variableWidth: true, 464 adaptiveHeight: true, 465 infinite: true, 466 467 arrows: true, 468 prevArrow: arrow('slick-prev', 'udem-icon-ico-chevron-left', l10n_precedent), 469 nextArrow: arrow('slick-next', 'udem-icon-ico-chevron-right', l10n_suivant), 470 asNavFor: $container, 471 472 responsive: [ 473 { 474 breakpoint: 768, 475 settings: { 476 slidesToShow: thumbs_per_row > 2 ? Math.max(2, Math.round(thumbs_per_row / Math.LOG2E)) : thumbs_per_row 477 } 478 }, 479 { 480 breakpoint: 480, 481 settings: { 482 slidesToShow: thumbs_per_row > 2 ? Math.max(2, Math.round(thumbs_per_row / Math.LN10)) : thumbs_per_row 483 } 484 } 485 ] 486 }); 487 } else { 488 $container.addClass('without-slick'); 489 do_squarify_thumbs($thumbs, precise_element_width($thumbs.get(0)), thumbs_per_row); 490 $(window).on('resize load', function () { 491 do_squarify_thumbs($thumbs, precise_element_width($thumbs.get(0)), thumbs_per_row); 492 }); 493 } 494 }); 495});
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.