fix bugs: autoReload and so on
@@ -6,18 +6,19 @@ | ||
6 | 6 | # - @target : target DIV element. |
7 | 7 | # - _public : a public object to bind variables and |
8 | 8 | # functions or to get them. |
9 | - constructor: (@target, _public) -> | |
10 | - @_ = _public | |
11 | - @setting = @_.setting | |
12 | - @tickerData = @_.tickerData | |
9 | + constructor: (@target, @_public) -> | |
10 | + @setting = @_public.setting | |
11 | + @tickerData = @_public.tickerData | |
13 | 12 | |
14 | 13 | # clean up child nodes of the target DIV element. |
15 | - cleanup: -> | |
16 | - nds = @target.childNodes | |
17 | - for nd in nds | |
14 | + cleanupScript: -> | |
15 | + for nd in @target.childNodes | |
18 | 16 | nm = if nd then nd.tagName else null |
19 | 17 | @target.removeChild nd if nm and (nm is 'script' or nm is 'SCRIPT') |
20 | 18 | |
19 | + cleanupAllTweetElement: -> | |
20 | + nds = @target.childNodes[0].innerHTML = '' | |
21 | + | |
21 | 22 | generateList: (errorMessage) -> |
22 | 23 | nodes = this._listNodes errorMessage |
23 | 24 | d = @target.childNodes[0] |
@@ -26,7 +27,7 @@ | ||
26 | 27 | else |
27 | 28 | for node in nodes |
28 | 29 | d.appendChild node |
29 | - @tickerData.animation = new TickerAnimation d, @target, @_ | |
30 | + @tickerData.animation = new TickerAnimation d, @target, @_public | |
30 | 31 | |
31 | 32 | _listNodes: (errorMessage) -> |
32 | 33 | nodes = null |
@@ -33,8 +34,8 @@ | ||
33 | 34 | if errorMessage |
34 | 35 | nodes = this._errorLine errorMessage |
35 | 36 | else |
36 | - showUser = checkSwitch @setting.displayUserID | |
37 | - showDate = checkSwitch @setting.displayDateTime | |
37 | + showUser = @setting.displayUserID | |
38 | + showDate = @setting.displayDateTime | |
38 | 39 | list = this._unitedList() |
39 | 40 | if list.length > 0 |
40 | 41 | nodes = this.makeupTweetLine list, showDate, showUser |
@@ -1,6 +1,6 @@ | ||
1 | 1 | class TickerSetting |
2 | 2 | constructor: (userSetting) -> |
3 | - s = this._mergeUserSetting userSetting | |
3 | + s = this._convSwitchIntoBool this._mergeUserSetting userSetting | |
4 | 4 | this[k] = v for k, v of s |
5 | 5 | |
6 | 6 | _mergeUserSetting: (setting) -> |
@@ -8,10 +8,23 @@ | ||
8 | 8 | setting[k] = setting[k] || s[k] for k, v of s |
9 | 9 | return setting |
10 | 10 | |
11 | + _convSwitchIntoBool: (setting) -> | |
12 | + bool = (value) -> | |
13 | + return value if typeof value is 'boolean' | |
14 | + v = value.toLowerCase() if typeof value is 'string' | |
15 | + if v and (v is 'on' or v is 'true') | |
16 | + return true | |
17 | + return false | |
18 | + | |
19 | + switchKeys = ['displayUserID', 'displayDateTime', 'autoReload'] | |
20 | + for key in switchKeys | |
21 | + setting[key] = bool setting[key] | |
22 | + return setting | |
23 | + | |
11 | 24 | TickerSetting.defaultSetting = |
12 | - users: null | |
25 | + users: null | |
13 | 26 | numberOfRecord: 5 |
14 | - interval: 100 | |
27 | + interval: 100 | |
15 | 28 | movingQuantity: 7 |
16 | 29 | dateFormat: 'YYYY/MM/DD hh:mm' |
17 | 30 | displayUserID: 'on' |
@@ -1,21 +1,21 @@ | ||
1 | 1 | class TweetCollector |
2 | - constructor: (@target, @_) -> | |
2 | + constructor: (@target, @_pub) -> | |
3 | 3 | |
4 | 4 | collect: -> |
5 | 5 | i = -1 |
6 | - num = @_.setting.numberOfRecord | |
7 | - for user in @_.tickerData.userList | |
6 | + num = @_pub.setting.numberOfRecord | |
7 | + for user in @_pub.tickerData.userList | |
8 | 8 | this.setCallerAndCallback ++i, num |
9 | 9 | |
10 | 10 | setCallerAndCallback: (index, numberOfRecord) -> |
11 | 11 | c = this._numberCode index |
12 | - _ = @_ | |
13 | - @_.tickerData.failure[c] = false | |
14 | - @_.callbacks[c] = (-> | |
12 | + _ = @_pub | |
13 | + @_pub.tickerData.failure[c] = false | |
14 | + @_pub.callbacks[c] = (-> | |
15 | 15 | p = c |
16 | 16 | return (r) -> |
17 | 17 | _.tweets r, p)(); |
18 | - this.setCaller @_.tickerData.userList[index], numberOfRecord, c | |
18 | + this.setCaller @_pub.tickerData.userList[index], numberOfRecord, c | |
19 | 19 | |
20 | 20 | setCaller: (account, numOfRec, numCode) -> |
21 | 21 | s = document.createElement 'script' |
@@ -1,7 +1,8 @@ | ||
1 | 1 | class TickerAnimation |
2 | - constructor: (@span, @target, @_) -> | |
3 | - @interval = @_.setting.interval | |
4 | - @movingQuantity = @_.setting.movingQuantity | |
2 | + constructor: (@span, @target, @_public) -> | |
3 | + @setting = @_public.setting | |
4 | + @interval = @setting.interval | |
5 | + @movingQuantity = @setting.movingQuantity | |
5 | 6 | @speeddown = 0 |
6 | 7 | @prepare = false |
7 | 8 | @timer = new TickerTimer this, 'move', @interval |
@@ -11,14 +12,16 @@ | ||
11 | 12 | w = @span.offsetWidth |
12 | 13 | @speeddown += @speeddown if @speeddown != 0 |
13 | 14 | v = @movingQuantity - @speeddown |
14 | - auto = checkSwitch @_.setting.autoReload | |
15 | + auto = @setting.autoReload | |
15 | 16 | if v > 0 |
16 | 17 | x -= v |
17 | 18 | if x < -w |
18 | 19 | x = if @target.style.width then parseInt(@target.style.width) else @target.offsetWidth |
19 | 20 | if @span.prepare |
21 | + @_public.tickerDomWriter.cleanupAllTweetElement() | |
20 | 22 | @span.appendChild node for node in @span.prepare |
21 | 23 | @span.prepare = false |
24 | + @prepare = false | |
22 | 25 | else if auto and ! @prepare and x < - w + 250 |
23 | 26 | this.getTweetsInBackground() |
24 | 27 | @span.style.left = x + (@span.measure || 'px') |
@@ -27,9 +30,10 @@ | ||
27 | 30 | @timer.abort() |
28 | 31 | |
29 | 32 | getTweetsInBackground: -> |
30 | - l = @_.tickerData.userList | |
31 | - n = @_.setting.numberOfRecord | |
33 | + l = @_public.tickerData.userList | |
34 | + n = @setting.numberOfRecord | |
32 | 35 | @prepare = true |
33 | - c = new TweetCollector @target, @_ | |
34 | - c.setCaller l[i], n, c._numberCode i for i in [0..l.length] | |
35 | - new ListManager l.length | |
36 | + @_public.tickerDomWriter.cleanupScript() | |
37 | + c = new TweetCollector @target, @_public | |
38 | + c.setCaller l[i], n, c._numberCode i for i in [0...l.length] | |
39 | + new ListManager l.length, @_public |
@@ -1,7 +1,7 @@ | ||
1 | 1 | _pub = null |
2 | 2 | |
3 | 3 | tweets = (result, code) -> |
4 | - d = _pub.tickerData | |
4 | + d = window.TsubuyakiTicker.tickerData | |
5 | 5 | r = result.results |
6 | 6 | if r.length > 0 |
7 | 7 | d.tweetList[r[0].from_user] = [] |
@@ -14,9 +14,6 @@ | ||
14 | 14 | else |
15 | 15 | d.failure[code] = true |
16 | 16 | |
17 | -checkSwitch = (value) -> | |
18 | - value.toLowerCase() isnt 'off' | |
19 | - | |
20 | 17 | run = -> |
21 | 18 | browser = new Browser() |
22 | 19 |
@@ -33,5 +33,5 @@ | ||
33 | 33 | else |
34 | 34 | @writer.generateList @setting.responseFailureMessage |
35 | 35 | else |
36 | - @writer.cleanup() | |
36 | + @writer.cleanupScript() | |
37 | 37 | @writer.generateList null |
@@ -1,15 +1,14 @@ | ||
1 | -### | |
2 | -TickerDomBuilder | |
3 | --------------------------------------------------- | |
4 | -A class to make up a DIV element for the tsubuyaki ticker. | |
5 | - | |
6 | -[usage] | |
7 | -STEP 1. get an instance. | |
8 | - b = new TickerDomBuilder element, browser | |
9 | - | |
10 | -STEP 2. add a span with the no-wrap style | |
11 | - b.addNoWrapElement() | |
12 | -### | |
1 | +# TickerDomBuilder | |
2 | +# -------------------------------------------------- | |
3 | +# A class to make up a DIV element for the tsubuyaki ticker. | |
4 | +# | |
5 | +# [usage] | |
6 | +# STEP 1. get an instance. | |
7 | +# b = new TickerDomBuilder element, browser | |
8 | +# | |
9 | +# STEP 2. add a span with the no-wrap style | |
10 | +# b.addNoWrapElement() | |
11 | +# | |
13 | 12 | class TickerDomBuilder |
14 | 13 | constructor: (@target, @browser) -> |
15 | 14 | @target.style.overflow = 'hidden' |
@@ -1,6 +1,6 @@ | ||
1 | 1 | class Tweet |
2 | 2 | constructor: (@user, text, @id, @date, @lang) -> |
3 | - @text = this._linkedText(text) | |
3 | + @text = (this._linkedText text).replace /[\r\n]/g, " " | |
4 | 4 | |
5 | 5 | _linkedText: (text) -> |
6 | 6 | keys = [] |
@@ -8,7 +8,7 @@ | ||
8 | 8 | replacer = new TweetTextReplacer |
9 | 9 | for k in keys |
10 | 10 | text = replacer[k](text) |
11 | - text | |
11 | + return text | |
12 | 12 | |
13 | 13 | |
14 | 14 | class TweetTextReplacer |
@@ -21,25 +21,15 @@ | ||
21 | 21 | link: (text) -> |
22 | 22 | text.replace @reg['link'], this.linkTag('$1', '$1') |
23 | 23 | |
24 | - account0: (text) -> | |
25 | - href = "http://twitter.com/$2" | |
26 | - text.replace @reg['account0'], "$1#{this.linkTag(href, '$2')}" | |
24 | + account: (text) -> | |
25 | + href = "http://twitter.com/$3" | |
26 | + text.replace @reg['account'], "$1#{this.linkTag(href, '$2')}" | |
27 | 27 | |
28 | - account1: (text) -> | |
29 | - href = "http://twitter.com/$1" | |
30 | - text.replace @reg['account1'], this.linkTag(href, '$1') | |
31 | - | |
32 | - hash0: (text) -> | |
28 | + hash: (text) -> | |
33 | 29 | href = "http://twitter.com/search?q=$2" |
34 | - text.replace @reg['hash0'], "$1#{this.linkTag(href, '$2')}" | |
30 | + text.replace @reg['hash'], "$1#{this.linkTag(href, '$2')}" | |
35 | 31 | |
36 | - hash1: (text) -> | |
37 | - href = "http://twitter.com/search?q=$1" | |
38 | - text.replace @reg['hash1'], this.linkTag(href, '$1') | |
39 | - | |
40 | 32 | TweetTextReplacer.REGEXPS = |
41 | 33 | link: /(http:\/\/[0-9A-Za-z\.\/_\?&\~\-\=\#\:%]+)/g |
42 | - account0: /(\s|[^a-zA-Z0-9])(@[a-zA-Z0-9_]+)/g | |
43 | - account1: /^(@[a-zA-Z0-9_]+)/ | |
44 | - hash0: /(\s)(\#[a-zA-Z0-9_]+)/g | |
45 | - hash1: /^(\#[a-zA-Z0-9_]+)/ | |
34 | + account: /(^|\s|[^a-zA-Z0-9])(@([a-zA-Z0-9_]+))/g | |
35 | + hash: /(^|\s)(\#[a-zA-Z0-9_]+)/g |