| 1 |
// ticketyboo Ticker |
// ticketyboo Ticker object |
| 2 |
|
function ticker(delta, id, direction, count, distance, interval, transition_events, transition_distance, pause_events, offset) { |
| 3 |
var ticketyboo = new Array(); |
// ticker parameters |
| 4 |
var ticketyseconds = new Array(); |
this.delta = delta; // block delta from Drupal |
| 5 |
var ticketynodes = new Array(); |
this.id = id; // id of the moving element |
| 6 |
var ticketytop = new Array(); |
this.direction = direction; // direction of movement |
| 7 |
var ticketytimer = new Array(); |
this.count = count; // number of items in the ticker |
| 8 |
var ticketypause = new Array(); |
this.distance = distance; // distance to move each item |
| 9 |
var ticketylast = new Array(); |
this.interval = interval; // ticker interval |
| 10 |
var ticketydir = new Array(); |
this.transition_events = transition_events; // number of ticks to move the item |
| 11 |
|
this.transition_distance = transition_distance; // amount to move the item each tick |
| 12 |
// initialise a ticker |
this.pause_events = pause_events; // number of ticks in the pause event |
| 13 |
function ticketyboo_init(id, seconds, nodes, direction) { |
this.offset = offset; // initial starting point for ticker |
| 14 |
// initial values |
// current status of the ticker |
| 15 |
ticketyboo[id] = 0; |
this.wrapper = id+'_wrapper'; |
| 16 |
ticketylast[id] = 0; |
this.item = 0; // the current item being displayed |
| 17 |
ticketyseconds[id] = seconds; |
this.status = 'initpause'; // initpause, pause, initmove, move |
| 18 |
ticketynodes[id] = nodes; |
this.events = 0; // number of events to go in the current status |
| 19 |
ticketypause[id] = false; |
this.position = 0 // current position in ticker |
| 20 |
ticketydir[id] = direction; |
ticketypause[delta] = false; |
| 21 |
|
window.setInterval('tickevent('+delta+')', interval); |
|
// activate the first content |
|
|
var key = "ticketyboo_" + id + "_" + ticketyboo[id]; |
|
|
// document.getElementById(key).style.display = "block"; |
|
|
ticketyboo_tick(id); |
|
|
|
|
|
// add the timer |
|
|
window.setInterval('ticketyboo_tick(' + id + ')', seconds * 1000); |
|
| 22 |
} |
} |
| 23 |
|
|
| 24 |
// perform the tick |
// array of tickers |
| 25 |
function ticketyboo_tick(id) { |
var tick = new Array(); |
| 26 |
if (!ticketypause[id]) { |
var ticketypause = new Array(); |
|
|
|
|
var last = ticketyboo[id]; |
|
|
var next = 1 + last; |
|
|
if(next > ticketynodes[id]) { next = 1;} |
|
|
|
|
|
var key = "ticketyboo_" + id + "_" + next; |
|
|
|
|
|
ticketyboo[id] = next; |
|
|
ticketylast[id] = last; |
|
|
|
|
|
ticketytop[id] = 75; |
|
|
ticketytimer[id] = window.setInterval('ticketyboo_slide(' + id + ')', 40); |
|
| 27 |
|
|
| 28 |
|
// perform the tick event |
| 29 |
|
function tickevent(delta) { |
| 30 |
|
if (!ticketypause[delta]) { |
| 31 |
|
t = tick[delta]; |
| 32 |
|
switch (t.status) { |
| 33 |
|
case 'initpause': |
| 34 |
|
tick[delta].events = t.pause_events; |
| 35 |
|
tick[delta].status = 'pause'; |
| 36 |
|
tick[delta].position = t.item * t.distance; |
| 37 |
|
tickpos(delta); |
| 38 |
|
break; |
| 39 |
|
case 'pause': |
| 40 |
|
tick[delta].events = tick[delta].events - 1; |
| 41 |
|
if (tick[delta].events == 0) { |
| 42 |
|
tick[delta].status = 'initmove'; |
| 43 |
|
} |
| 44 |
|
break; |
| 45 |
|
case 'initmove': |
| 46 |
|
tick[delta].events = t.transition_events; |
| 47 |
|
tick[delta].status = 'move'; |
| 48 |
|
break; |
| 49 |
|
case 'move': |
| 50 |
|
tick[delta].position = tick[delta].position + t.transition_distance |
| 51 |
|
tick[delta].events = tick[delta].events - 1; |
| 52 |
|
tickpos(delta); |
| 53 |
|
if (tick[delta].events == 0) { |
| 54 |
|
tick[delta].status = 'initpause'; |
| 55 |
|
tick[delta].item = tick[delta].item + 1; |
| 56 |
|
if (tick[delta].item == tick[delta].count) { |
| 57 |
|
tick[delta].item = 0; |
| 58 |
|
} |
| 59 |
|
} |
| 60 |
|
break; |
| 61 |
|
} |
| 62 |
} |
} |
| 63 |
} |
} |
| 64 |
|
|
| 65 |
// animate the change |
// position the element |
| 66 |
function ticketyboo_slide(id) { |
function tickpos(delta) { |
| 67 |
var top = +ticketytop[id]-2; |
t = tick[delta]; |
| 68 |
ticketytop[id] = top; |
pos = 0 + tick[delta].position-tick[delta].offset; |
| 69 |
var next = ticketyboo[id]; |
pos = 0 - pos; |
| 70 |
var last = ticketylast[id]; |
if (t.direction == 'horizontal') { |
| 71 |
var dir = ticketydir[id]; |
document.getElementById(t.wrapper).style.marginLeft = pos + 'px'; |
| 72 |
|
} else { |
| 73 |
if (last != 0) { |
document.getElementById(t.wrapper).style.marginTop = pos + 'px'; |
|
var key = "ticketyboo_" + id + "_" + last; |
|
|
document.getElementById(key).style.display = "none"; |
|
| 74 |
} |
} |
|
|
|
|
key = "ticketyboo_" + id + "_" + next; |
|
|
if (dir == 'vertical' || dir == 'diagonal') { |
|
|
document.getElementById(key).style.marginTop = top + "%"; |
|
|
} |
|
|
if (dir == 'horizontal' || dir == 'diagonal') { |
|
|
document.getElementById(key).style.marginLeft = top + "%"; |
|
|
} |
|
|
document.getElementById(key).style.display = "block"; |
|
|
|
|
|
if (top <= 0) { |
|
|
window.clearInterval(ticketytimer[id]); |
|
|
} |
|
|
|
|
| 75 |
} |
} |