/* * Title: Timeliner (jQuery plugin) * Author: Berend de Jong, Frique * Author URI: http://www.frique.me/ * Version: 1.2 (20110725.1) */ (function($) { jQuery.fn.timeliner = function(n) { var o = $.extend({ containerwidth: 450, containerheight: 100, showpauseplay: true, showprevnext: true, controls_always_visible: true, timelinewidth: 420, timelineheight: 8, timelinehorizontalmargin: 'auto', timelineverticalmargin: 22, timelineposition: 'bottom', showtimedisplay: false, timedisplayposition: 'below', showtotaltime: false, showtooltip: true, showtooltiptime: false, tooltipposition: 'below', interval: 1, repeat: false, autoplay: false, keyboard: true, transition: 'slide' }, n); $(this).each(function() { function getdisplaytime(a) { var b = Math.floor(a / 60); a = (a - (b * 60)); if (a < 10) { a = '0' + a } return b + ':' + a } var c, prenodepos = [0], nodepos = [0, 0], nodesec = [0, 0], nodeinterval = [0], targetpos, x = 1, activenode = 1, seconds = 0, timeinterval, totaltime = 0, playing = false, started = false, timeremaining, animationtime, $container = $(this).show(), $slides = $container.find('> li'), $timeline = $('
  • ').prependTo($container), $innertimeline = $('
     
    ').prependTo($timeline), nodes = $slides.length; if (o.showtimedisplay) { var d = $('
    0:00
    ').prependTo($timeline); if (o.showtotaltime) { d.append(' / 0:00') } var f = Math.round(d.outerWidth(true) / 2) } if (o.showpauseplay) { var g = $('
  • ').prependTo($container).animate({ opacity: 0 }, 0); if (o.showprevnext) { var h = $('').prependTo($container).animate({ opacity: 0 }, 0); var i = $('').prependTo($container).animate({ opacity: 0 }, 0) } } $slides.each(function() { var a = $(this); a.addClass('slide').addClass('slide' + x).data('title', a.attr('title')).removeAttr('title').animate({ opacity: 0 }, 0); if (x < nodes || o.repeat) { if (a.attr('lang')) { nodeinterval[x] = parseInt(a.attr('lang'), 10) } else { nodeinterval[x] = o.interval } totaltime = +totaltime + nodeinterval[x] } else { nodeinterval[x] = 0 } nodesec[x] = +nodesec[(x - 1)] + nodeinterval[(x - 1)]; x++ }); x = 1; if (o.timelinehorizontalmargin == 'auto') { c = (o.containerwidth - o.timelinewidth) / 2 } else { c = o.timelinehorizontalmargin } var j = getdisplaytime(totaltime); for (x = 1; x < (nodes + 1); x++) { $('
    ').appendTo($timeline).data('id', x) } var k = $timeline.find('.node'); x = 1; var l = k.outerWidth(true), nodeheight = k.outerHeight(true), halfnodewidth = Math.round(l / 2); k.each(function() { var a = $(this); prenodepos[x] = ((nodeinterval[(x - 1)] / totaltime) * 100).toFixed(4); nodepos[x] = +nodepos[(x - 1)] + Math.round(o.timelinewidth * (prenodepos[x] / 100)); a.css({ left: (nodepos[x] - halfnodewidth), top: -(Math.round(nodeheight / 2) - Math.round(o.timelineheight / 2)) }); if (o.showtooltip) { var b = $container.find('.slide' + x).data('title'); if (b) { a.prepend('
    ' + b + '
    ') } } if (o.showtooltiptime) { a.find('.tooltip1').prepend('
    ') } x++ }); if (o.showtooltip) { var m = $container.find('.tooltip1') } $container.css({ width: o.containerwidth, height: o.containerheight }); if (o.transition == 'slide' || o.transition == 'reveal' || o.transition == 'cover') { $container.css({ overflow: 'hidden' }) } $slides.css({ width: o.containerwidth, height: o.containerheight }); $timeline.css({ width: o.timelinewidth, height: o.timelineheight, margin: 15, marginTop: o.timelineverticalmargin, marginBottom: o.timelineverticalmargin }).css(o.timelineposition, 0); $innertimeline.css({ height: o.timelineheight }); if (o.showtimedisplay && o.timedisplayposition == 'below') { d.css({ top: (o.timelineheight + 5), left: -f }) } else if (o.showtimedisplay) { d.css({ bottom: (o.timelineheight + 5), left: -f }) } if (o.showtooltip) { if (o.tooltipposition == 'below') { m.css({ top: nodeheight + 5 }) } else { m.css({ bottom: nodeheight + 5 }) } m.each(function() { var a = $(this); a.css({ left: -(Math.round(a.outerWidth(true) / 2) - halfnodewidth) }) }) } if (o.showpauseplay) { g.css({ top: 10, left: (Math.round(o.containerwidth / 2) - Math.round(g.outerWidth(true) / 2))+3 }); if (o.showprevnext) { h.css({ //top: (Math.round(o.containerheight / 2) - Math.round(h.outerHeight(true) / 2)), right: (Math.round(o.containerwidth / 2) + Math.round(g.outerWidth(true) / 2))+10, }); i.css({ //top: (Math.round(o.containerheight / 2) - Math.round(i.outerHeight(true) / 2)), left: (Math.round(o.containerwidth / 2) + Math.round(g.outerWidth(true) / 2))+8 }) } } $slides.each(function() { var a = $(this); if (a.outerWidth() > o.containerwidth) { a.width((a.width() - parseInt(a.css('paddingLeft'), 10) - parseInt(a.css('paddingRight'), 10))) } if (a.outerHeight() > o.containerheight) { a.height((a.height() - parseInt(a.css('paddingTop'), 10) - parseInt(a.css('paddingBottom'), 10))) } }); function dtime(a) { d.html(getdisplaytime(a)); if (o.showtotaltime) { d.append(' / ' + j) } } function time_start(a) { dtime(a); timeinterval = setInterval(function() { seconds++; dtime(seconds) }, 1000) } function time_stop() { clearInterval(timeinterval) } function stop() { $innertimeline.stop(); if (o.showtimedisplay) { time_stop(); d.stop() } playing = false; if (o.showpauseplay) { g.attr('class', 'play') } } function start(a, b) { // alert(a+"--"+b+"--"+o.times[a-1].name); var lay=o.times; for ( var y = 0; y 0 && x < nodes) { if ((nodepos[x] < a) && (nodepos[( + x + 1)] > a)) { b = x } } } if (a > nodepos[nodes]) { b = nodes } if (a < 0) { b = 1 } if (b != activenode) { $timeline.find('.node' + b).click() } }); $slides.click(function() { the_click_callback() }); if (o.keyboard) { $(document).keydown(function(e) { if (e.keyCode == 32) { e.preventDefault(); g.click() } }) } $container.find('.slide1').animate({ opacity: 1 }, 0).css({ 'z-index': 1 }); if (o.autoplay) { start(1) } }) } })(jQuery);