-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.jstockticker-1.1.js
103 lines (75 loc) · 2.35 KB
/
jquery.jstockticker-1.1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Horizontal Stock Ticker for jQuery.
*
* @package jStockTicker
* @author Peter Halasz <skinner@gmail.com>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPL v3.0
* @copyright (c) 2009, Peter Halasz all rights reserved.
*/
( function($) {
$.fn.jStockTicker = function(options) {
if (typeof (options) == 'undefined') {
options = {};
}
var settings = $.extend( {}, $.fn.jStockTicker.defaults, options);
var $ticker = $(this);
settings.tickerID = $ticker[0].id;
$.fn.jStockTicker.settings[settings.tickerID] = {};
var $wrap = null;
if ($ticker.parent().get(0).className != 'wrap') {
$wrap = $ticker.wrap("<div class='wrap'></div>");
}
var $tickerContainer = null;
if ($ticker.parent().parent().get(0).className != 'container') {
$tickerContainer = $ticker.parent().wrap(
"<div class='container'></div>");
}
var node = $ticker[0].firstChild;
var next;
while(node) {
next = node.nextSibling;
if(node.NodeType == 3) {
$ticker[0].removeChild(node);
}
node = next;
}
var shiftLeftAt = $ticker.children().get(0).offsetWidth;
$.fn.jStockTicker.settings[settings.tickerID].shiftLeftAt = shiftLeftAt;
$.fn.jStockTicker.settings[settings.tickerID].left = 0;
$.fn.jStockTicker.settings[settings.tickerID].runid = null;
$ticker.width(2 * screen.availWidth);
function startTicker() {
stopTicker();
var params = $.fn.jStockTicker.settings[settings.tickerID];
params.left -= settings.speed;
if(params.left <= params.shiftLeftAt * -1) {
params.left = 0;
$ticker.append($ticker.children().get(0));
params.shiftLeftAt = $ticker.children().get(0).offsetWidth;
}
$ticker.css('left', params.left + 'px');
params.runId = setTimeout(arguments.callee, settings.interval);
$.fn.jStockTicker.settings[settings.tickerID] = params;
}
function stopTicker() {
var params = $.fn.jStockTicker.settings[settings.tickerID];
if (params.runId)
clearTimeout(params.runId);
params.runId = null;
$.fn.jStockTicker.settings[settings.tickerID] = params;
}
function updateTicker() {
stopTicker();
startTicker();
}
$ticker.hover(stopTicker,startTicker);
startTicker();
};
$.fn.jStockTicker.settings = {};
$.fn.jStockTicker.defaults = {
tickerID :null,
url :null,
speed :1,
interval :20
};
})(jQuery);