From 26895046622eef1bb47282ceabaac31d9a773496 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 11 Apr 2013 13:33:18 -0700 Subject: [PATCH] Rewrite custom board titles --- appchan-x.user.js | 69 ++++++++++++++++++++++++++++++---------------- src/appchan.coffee | 58 ++++++++++++++++++++++++-------------- src/config.coffee | 4 +++ 3 files changed, 86 insertions(+), 45 deletions(-) diff --git a/appchan-x.user.js b/appchan-x.user.js index f3d5914c5..88a7020f1 100644 --- a/appchan-x.user.js +++ b/appchan-x.user.js @@ -150,6 +150,7 @@ 'Announcements': ['slideout', 'The style of announcements and the ability to hide them.', ['4chan default', 'slideout', 'hide']], 'Board Title': ['at sidebar top', 'The positioning of the board\'s logo and subtitle.', ['at sidebar top', 'at sidebar bottom', 'at top', 'under post form', 'hide']], 'Custom Board Titles': [false, 'Customize Board Titles by shift-clicking the board title or subtitle.'], + 'Persistent Custom Board Titles': [false, 'Forces custom board titles to be persistent, even if moot updates the board titles.'], 'Board Subtitle': [true, 'Show the board subtitle.'], '4chan Banner': ['at sidebar top', 'The positioning of 4chan\'s image banner.', ['at sidebar top', 'at sidebar bottom', 'under post form', 'at top', 'hide']], '4chan Banner Reflection': [false, 'Adds reflection effects to 4chan\'s image banner.'], @@ -3713,7 +3714,7 @@ }); }, ready: function() { - var banner, cachedTest, child, children, i, nodes, title; + var banner, child, children, i, nodes, title; banner = $(".boardBanner"); title = $.el("div", { @@ -3729,34 +3730,54 @@ continue; } if (Conf['Custom Board Titles']) { - cachedTest = child.innerHTML; - if (!Conf['Persistent Custom Board Titles'] || cachedTest === $.get("" + g.BOARD + "." + child.className + ".orig", cachedTest)) { - child.innerHTML = $.get("" + g.BOARD + "." + child.className, cachedTest); - } else { - $.set("" + g.BOARD + "." + child.className + ".orig", cachedTest); - $.set("" + g.BOARD + "." + child.className, cachedTest); - } - $.on(child, 'click', function(e) { - if (e.shiftKey) { - return this.contentEditable = true; - } - }); - $.on(child, 'keydown', function(e) { - return e.stopPropagation(); - }); - $.on(child, 'focus', function() { - return this.textContent = this.innerHTML; - }); - $.on(child, 'blur', function() { - $.set("" + g.BOARD + "." + this.className, this.textContent); - this.innerHTML = this.textContent; - return this.contentEditable = false; - }); + Banner.custom(child); } nodes.push(child); } $.add(title, nodes.reverse()); $.after(banner, title); + }, + cb: { + click: function(e) { + if (e.shiftKey) { + return this.contentEditable = true; + } + }, + keydown: function(e) { + return e.stopPropagation(); + }, + focus: function() { + return this.textContent = this.innerHTML; + }, + blur: function() { + $.set("" + g.BOARD + "." + this.className, this.textContent); + $.set("" + g.BOARD + "." + child.className + ".orig", cachedTest); + this.innerHTML = this.textContent; + return this.contentEditable = false; + } + }, + custom: function(child) { + var cachedTest; + + cachedTest = child.innerHTML; + $.get("" + g.BOARD + "." + child.className, cachedTest, function(item) { + if (Conf['Persistent Custom Board Titles']) { + return child.innerHTML = item["" + g.BOARD + "." + child.className]; + } else { + return $.get("" + g.BOARD + "." + child.className + ".orig", cachedTest, function(itemb) { + if (cachedTest === itemb["" + g.BOARD + "." + child.className + ".orig"]) { + return child.innerHTML = item["" + g.BOARD + "." + child.className]; + } else { + $.set("" + g.BOARD + "." + child.className + ".orig", cachedTest); + return $.set("" + g.BOARD + "." + child.className, cachedTest); + } + }); + } + }); + $.on(child, 'click', Banner.cb.click); + $.on(child, 'keydown', Banner.cb.keydown); + $.on(child, 'focus', Banner.cb.focus); + return $.on(child, 'blur', Banner.cb.blur); } }; diff --git a/src/appchan.coffee b/src/appchan.coffee index f97562efa..b578b8713 100644 --- a/src/appchan.coffee +++ b/src/appchan.coffee @@ -480,27 +480,7 @@ Banner = continue if Conf['Custom Board Titles'] - cachedTest = child.innerHTML - if not Conf['Persistent Custom Board Titles'] or cachedTest is $.get "#{g.BOARD}.#{child.className}.orig", cachedTest - child.innerHTML = $.get "#{g.BOARD}.#{child.className}", cachedTest - else - $.set "#{g.BOARD}.#{child.className}.orig", cachedTest - $.set "#{g.BOARD}.#{child.className}", cachedTest - - $.on child, 'click', (e) -> - if e.shiftKey - @contentEditable = true - - $.on child, 'keydown', (e) -> - e.stopPropagation() - - $.on child, 'focus', -> - @textContent = @innerHTML - - $.on child, 'blur', -> - $.set "#{g.BOARD}.#{@className}", @textContent - @innerHTML = @textContent - @contentEditable = false + Banner.custom child nodes.push child @@ -508,6 +488,42 @@ Banner = $.after banner, title return + cb: + click: (e) -> + if e.shiftKey + @contentEditable = true + + keydown: (e) -> + e.stopPropagation() + + focus: -> + @textContent = @innerHTML + + blur: -> + $.set "#{g.BOARD}.#{@className}", @textContent + $.set "#{g.BOARD}.#{child.className}.orig", cachedTest + @innerHTML = @textContent + @contentEditable = false + + custom: (child) -> + cachedTest = child.innerHTML + + $.get "#{g.BOARD}.#{child.className}", cachedTest, (item) -> + if Conf['Persistent Custom Board Titles'] + child.innerHTML = item["#{g.BOARD}.#{child.className}"] + else + $.get "#{g.BOARD}.#{child.className}.orig", cachedTest, (itemb) -> + if cachedTest is itemb["#{g.BOARD}.#{child.className}.orig"] + child.innerHTML = item["#{g.BOARD}.#{child.className}"] + else + $.set "#{g.BOARD}.#{child.className}.orig", cachedTest + $.set "#{g.BOARD}.#{child.className}", cachedTest + + $.on child, 'click', Banner.cb.click + $.on child, 'keydown', Banner.cb.keydown + $.on child, 'focus', Banner.cb.focus + $.on child, 'blur', Banner.cb.blur + GlobalMessage = init: -> $.asap (-> d.body), -> diff --git a/src/config.coffee b/src/config.coffee index 83c082306..bb408bc64 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -348,6 +348,10 @@ Config = false 'Customize Board Titles by shift-clicking the board title or subtitle.' ] + 'Persistent Custom Board Titles': [ + false + 'Forces custom board titles to be persistent, even if moot updates the board titles.' + ] 'Board Subtitle': [ true 'Show the board subtitle.'