|
/** |
|
* Carousel #2 |
|
* Pulls content from content server (/cs/idcplg), displays in a carousel. |
|
* |
|
* Targets an element with a data attribute: |
|
* <script data="COLLECTION_DISPLAY/999999999999025064"></script> |
|
* |
|
* circa 2013 |
|
*/ |
|
$(function(){ |
|
// get arguments to query |
|
var target = $('script[data^=COLLECTION_DISPLAY]'); |
|
if (!target.length) return; |
|
|
|
var data = target.attr('data').split('/'), |
|
type = data[0], |
|
id = data[1]; |
|
|
|
// query content server |
|
cs(type, id) |
|
.then(function(response){ |
|
var items = |
|
// interpret soapy result |
|
cs[type](response) |
|
// convert to HTML |
|
.map(function(item){ //console.warn(item); |
|
// interpolate values into template |
|
return ('<a '+ |
|
'id="dID_{{ dID }}"' + |
|
'title="{{ dDocTitle }}" '+ |
|
'href="{{ xSupplementalMarkings }}" '+ |
|
'data-xcomments="{{ xComments }}" '+ |
|
'data-dweburl="{{ dWebURL }}">'+ |
|
'<img src="/cs/idcplg?IdcService=GET_FILE&Rendition=Preview&'+ |
|
'dID={{ dID }}"></a>') |
|
|
|
.replace(/\{\{ *([a-zA-Z0-9_\$]+) *\}\}/g, function(token, property){ |
|
return item[property]; |
|
}); |
|
}).join(''), |
|
|
|
list = document.createElement('nav'); |
|
list.className = 'carousel'; |
|
list.id = [type, id].join('__'); |
|
list.innerHTML = items; |
|
// insert after [data] target |
|
target.after(list); |
|
|
|
// <rabble about scrollbars> |
|
$(list).closest('div').css({ overflow: 'hidden' }); |
|
|
|
// attach carousel |
|
$(list).carousel(); |
|
|
|
return list; |
|
}); |
|
}); |
|
|
|
/** |
|
* $.fn.carousel.js |
|
* |
|
* Carousel feature and autoscroll |
|
* |
|
* circa 2013 |
|
*/ |
|
$.fn.carousel = function(){ |
|
return this.each(function(i, carousel){ |
|
carousel = $(carousel) |
|
|
|
// CAROUSEL EVENTS |
|
.on({ 'select': function(e, target){ |
|
var j = target.prevAll().length; |
|
|
|
target.add('.carousel-feature figure:eq('+j+')') |
|
.addClass('feature') |
|
.siblings().removeClass('feature'); |
|
} }); |
|
|
|
if ('intrinsic space') |
|
carousel.closest('table').css('table-layout', 'fixed'); |
|
|
|
if ('add feature'){ |
|
var feature = $('<aside>', { 'class': 'carousel-feature' }) |
|
.insertAfter(carousel); |
|
$('> a', carousel) |
|
.each(function(j){ |
|
var target = $(this), |
|
id = target[0].id.replace(/^dID_/,''), |
|
title = target[0].title, |
|
href = target[0].href, |
|
url = target.data('dweburl'), |
|
content = target.data('xcomments'); |
|
|
|
$('<figure>', { title: title }) |
|
.append($('<img>', { src: url, alt: content })) |
|
.append($('<figcaption>', { text: content })) |
|
.appendTo('.carousel-feature'); |
|
}) |
|
// hover to select |
|
.on('mouseover', function(){ |
|
var item = $(this); |
|
setTimeout(function(){ |
|
if (item.is(':hover')) |
|
carousel.trigger('select', [item]); |
|
}, 1e3 /* 1s delay after hover */); |
|
}); |
|
} |
|
|
|
if ('auto cycle features') |
|
setInterval(function(){ |
|
if (carousel.is(':hover')) return; |
|
|
|
carousel.trigger('select', [ $('> a', carousel) |
|
// random |
|
.eq(new Date % carousel.children().length) ]); |
|
|
|
}, 3e4 /* 30s */); |
|
|
|
if ('auto select first') |
|
$('.carousel').trigger('select', [$('a:first', carousel)]); |
|
|
|
|
|
if ('parallax hover scroll') |
|
carousel.scrollex(); |
|
}); |
|
}; |
|
|
|
/** |
|
* $.fn.scrollex |
|
* |
|
* Parallax mousemove horizontal scrolling |
|
* |
|
* circa 2013 |
|
*/ |
|
$.fn.scrollex = function(){ |
|
return this |
|
.each(function(){ |
|
var viewport = $(this); |
|
viewport |
|
.off('.scrollex') |
|
.on('mousemove.scrollex', function(e){ |
|
requestAnimationFrame(function(t){ |
|
var x = e.clientX, |
|
left = viewport.offset().left, |
|
scrollWidth = viewport[0].scrollWidth, |
|
width = viewport.outerWidth(), |
|
displacement = (x - left)/width, |
|
tolerance = scrollWidth - width, |
|
goal = displacement * tolerance, |
|
current = viewport.scrollLeft(); |
|
|
|
viewport.scrollLeft(Math.sin(Math.PI/2 * displacement) * tolerance); |
|
}); |
|
}); |
|
|
|
}); |
|
}; |
Woot! Good to see your code again sir!