| 1 |
/*
|
| 2 |
$Id$
|
| 3 |
News ticker plugin (BBC news style)
|
| 4 |
Bryan Gullan,2007
|
| 5 |
version 1.1.1
|
| 6 |
http://www.makemineatriple.com/jquery
|
| 7 |
Use and distrubute freely with this header
|
| 8 |
*/
|
| 9 |
|
| 10 |
(function($) {
|
| 11 |
|
| 12 |
function runTicker(settings) {
|
| 13 |
if(settings.firstRun == 1){
|
| 14 |
currentLength = settings.currentLength;
|
| 15 |
currentItem = settings.currentItem;
|
| 16 |
settings.firstRun = 0;
|
| 17 |
}
|
| 18 |
if(currentItem == settings.newsItemCounter + 1){
|
| 19 |
currentItem = 0;
|
| 20 |
}
|
| 21 |
|
| 22 |
if(currentLength == 0) {
|
| 23 |
$(settings.newsList).empty().append('<li><a href="'+ settings.newsLinks[currentItem] +'"></a></li>');
|
| 24 |
}
|
| 25 |
|
| 26 |
if( currentLength % 2 == 0) {
|
| 27 |
placeHolder = settings.placeHolder1;
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
placeHolder = settings.placeHolder2;
|
| 31 |
}
|
| 32 |
|
| 33 |
if( currentLength <= settings.newsItems[currentItem].length + 1) {
|
| 34 |
var tickerText = settings.newsItems[currentItem].substring(0,currentLength);
|
| 35 |
$(settings.newsList + ' li a').text(tickerText + placeHolder);
|
| 36 |
currentLength ++;
|
| 37 |
setTimeout(function(){runTicker(settings); settings = null;},settings.tickerRate);
|
| 38 |
}
|
| 39 |
else {
|
| 40 |
$(settings.newsList + ' li a').text(settings.newsItems[currentItem]);
|
| 41 |
currentLength = 0;
|
| 42 |
currentItem ++;
|
| 43 |
setTimeout(function(){runTicker(settings); settings = null;},settings.loopDelay);
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
$.fn.extend({
|
| 48 |
newsTicker: function(settings) {
|
| 49 |
settings = jQuery.extend({
|
| 50 |
newsList: "#news",
|
| 51 |
tickerRate: 80,
|
| 52 |
startDelay: 100,
|
| 53 |
loopDelay: 3000,
|
| 54 |
placeHolder1: " |",
|
| 55 |
placeHolder2: "_"
|
| 56 |
}, settings);
|
| 57 |
|
| 58 |
var newsItems = new Array();
|
| 59 |
var newsLinks = new Array();
|
| 60 |
var newsItemCounter = 0;
|
| 61 |
|
| 62 |
$(settings.newsList + ' li a').each(function(){
|
| 63 |
newsItems[newsItemCounter] = $(this).text();
|
| 64 |
newsLinks[newsItemCounter] = $(this).attr('href');
|
| 65 |
newsItemCounter ++;
|
| 66 |
});
|
| 67 |
|
| 68 |
settings = jQuery.extend(settings,{
|
| 69 |
newsItems: newsItems,
|
| 70 |
newsLinks: newsLinks,
|
| 71 |
newsItemCounter: newsItemCounter - 1,
|
| 72 |
currentItem: 0,
|
| 73 |
currentLength: 0,
|
| 74 |
firstRun:1
|
| 75 |
});
|
| 76 |
|
| 77 |
setTimeout(function(){runTicker(settings); settings = null;},settings.startDelay);
|
| 78 |
}
|
| 79 |
|
| 80 |
});
|
| 81 |
|
| 82 |
|
| 83 |
})(jQuery);
|