From f098f19a11be83c353914a1c2f13356fcbae8d02 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 14 Apr 2013 13:10:42 -0700 Subject: [PATCH] Erm, some of that was unnecessary. --- builds/4chan-X.js | 15 ++++++++------- builds/4chan-X.user.js | 15 ++++++++------- builds/crx/script.js | 15 ++++++++------- lib/ui.coffee | 19 +++++++------------ 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 9a5994b84..4808b20b3 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -236,7 +236,9 @@ innerHTML: html, id: id }); - el.style.cssText = localStorage.getItem("" + g.NAMESPACE + id + ".position") || position; + $.get("" + id + ".position", position, function(item) { + return el.style.cssText = item["" + id + ".position"]; + }); move = $('.move', el); $.on(move, 'touchstart mousedown', dragstart); _ref = move.children; @@ -571,18 +573,17 @@ $.off(d, 'mousemove', this.move); $.off(d, 'mouseup', this.up); } - return localStorage.setItem("" + g.NAMESPACE + this.id + ".position", this.style.cssText); + return $.set("" + this.id + ".position", this.style.cssText); }; hoverstart = function(_arg) { - var asapTest, cb, close, el, endEvents, latestEvent, o, root; + var asapTest, cb, el, endEvents, latestEvent, o, root; - root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb, close = _arg.close; + root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb; o = { root: root, el: el, style: el.style, cb: cb, - close: close, endEvents: endEvents, latestEvent: latestEvent, clientHeight: doc.clientHeight, @@ -606,9 +607,9 @@ this.latestEvent = e; height = this.el.offsetHeight; clientX = e.clientX, clientY = e.clientY; - top = clientY + (close ? 0 : -120); + top = clientY - 120; top = this.clientHeight <= height || top <= 0 ? 0 : top + height >= this.clientHeight ? this.clientHeight - height : top; - _ref = clientX <= this.clientWidth - 400 ? [clientX + (this.close ? 15 : 45) + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; + _ref = clientX <= this.clientWidth - 400 ? [clientX + 45 + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; style = this.style; style.top = top + 'px'; style.left = left; diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 53aa8e0b2..e19634182 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -233,7 +233,9 @@ innerHTML: html, id: id }); - el.style.cssText = localStorage.getItem("" + g.NAMESPACE + id + ".position") || position; + $.get("" + id + ".position", position, function(item) { + return el.style.cssText = item["" + id + ".position"]; + }); move = $('.move', el); $.on(move, 'touchstart mousedown', dragstart); _ref = move.children; @@ -568,18 +570,17 @@ $.off(d, 'mousemove', this.move); $.off(d, 'mouseup', this.up); } - return localStorage.setItem("" + g.NAMESPACE + this.id + ".position", this.style.cssText); + return $.set("" + this.id + ".position", this.style.cssText); }; hoverstart = function(_arg) { - var asapTest, cb, close, el, endEvents, latestEvent, o, root; + var asapTest, cb, el, endEvents, latestEvent, o, root; - root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb, close = _arg.close; + root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb; o = { root: root, el: el, style: el.style, cb: cb, - close: close, endEvents: endEvents, latestEvent: latestEvent, clientHeight: doc.clientHeight, @@ -603,9 +604,9 @@ this.latestEvent = e; height = this.el.offsetHeight; clientX = e.clientX, clientY = e.clientY; - top = clientY + (close ? 0 : -120); + top = clientY - 120; top = this.clientHeight <= height || top <= 0 ? 0 : top + height >= this.clientHeight ? this.clientHeight - height : top; - _ref = clientX <= this.clientWidth - 400 ? [clientX + (this.close ? 15 : 45) + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; + _ref = clientX <= this.clientWidth - 400 ? [clientX + 45 + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; style = this.style; style.top = top + 'px'; style.left = left; diff --git a/builds/crx/script.js b/builds/crx/script.js index 953518632..e84675638 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -210,7 +210,9 @@ innerHTML: html, id: id }); - el.style.cssText = localStorage.getItem("" + g.NAMESPACE + id + ".position") || position; + $.get("" + id + ".position", position, function(item) { + return el.style.cssText = item["" + id + ".position"]; + }); move = $('.move', el); $.on(move, 'touchstart mousedown', dragstart); _ref = move.children; @@ -545,18 +547,17 @@ $.off(d, 'mousemove', this.move); $.off(d, 'mouseup', this.up); } - return localStorage.setItem("" + g.NAMESPACE + this.id + ".position", this.style.cssText); + return $.set("" + this.id + ".position", this.style.cssText); }; hoverstart = function(_arg) { - var asapTest, cb, close, el, endEvents, latestEvent, o, root; + var asapTest, cb, el, endEvents, latestEvent, o, root; - root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb, close = _arg.close; + root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb; o = { root: root, el: el, style: el.style, cb: cb, - close: close, endEvents: endEvents, latestEvent: latestEvent, clientHeight: doc.clientHeight, @@ -580,9 +581,9 @@ this.latestEvent = e; height = this.el.offsetHeight; clientX = e.clientX, clientY = e.clientY; - top = clientY + (close ? 0 : -120); + top = clientY - 120; top = this.clientHeight <= height || top <= 0 ? 0 : top + height >= this.clientHeight ? this.clientHeight - height : top; - _ref = clientX <= this.clientWidth - 400 ? [clientX + (this.close ? 15 : 45) + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; + _ref = clientX <= this.clientWidth - 400 ? [clientX + 45 + 'px', null] : [null, this.clientWidth - clientX + 45 + 'px'], left = _ref[0], right = _ref[1]; style = this.style; style.top = top + 'px'; style.left = left; diff --git a/lib/ui.coffee b/lib/ui.coffee index b0ad1e3fc..ac53a6258 100644 --- a/lib/ui.coffee +++ b/lib/ui.coffee @@ -4,7 +4,8 @@ UI = do -> className: 'dialog' innerHTML: html id: id - el.style.cssText = localStorage.getItem("#{g.NAMESPACE}#{id}.position") or position + $.get "#{id}.position", position, (item) -> + el.style.cssText = item["#{id}.position"] move = $ '.move', el $.on move, 'touchstart mousedown', dragstart for child in move.children @@ -192,6 +193,7 @@ UI = do -> @parseEntry subEntry return + dragstart = (e) -> return if e.type is 'mousedown' and e.button isnt 0 # not LMB # prevent text selection @@ -225,13 +227,11 @@ UI = do -> o.up = dragend.bind o $.on d, 'mousemove', o.move $.on d, 'mouseup', o.up - touchmove = (e) -> for touch in e.changedTouches if touch.identifier is @identifier drag.call @, touch return - drag = (e) -> {clientX, clientY} = e @@ -265,13 +265,11 @@ UI = do -> style.right = right style.top = top style.bottom = bottom - touchend = (e) -> for touch in e.changedTouches if touch.identifier is @identifier dragend.call @ return - dragend = -> if @isTouching $.off d, 'touchmove', @move @@ -279,15 +277,14 @@ UI = do -> else # mouseup $.off d, 'mousemove', @move $.off d, 'mouseup', @up - localStorage.setItem "#{g.NAMESPACE}#{@id}.position", @style.cssText + $.set "#{@id}.position", @style.cssText - hoverstart = ({root, el, latestEvent, endEvents, asapTest, cb, close}) -> + hoverstart = ({root, el, latestEvent, endEvents, asapTest, cb}) -> o = { root: root el: el style: el.style cb: cb - close: close endEvents: endEvents latestEvent: latestEvent clientHeight: doc.clientHeight @@ -303,13 +300,12 @@ UI = do -> $.on root, endEvents, o.hoverend $.on root, 'mousemove', o.hover - hover = (e) -> @latestEvent = e height = @el.offsetHeight {clientX, clientY} = e - top = clientY + (if close then 0 else -120) + top = clientY - 120 top = if @clientHeight <= height or top <= 0 0 else if top + height >= @clientHeight @@ -318,7 +314,7 @@ UI = do -> top [left, right] = if clientX <= @clientWidth - 400 - [clientX + (if @close then 15 else 45) + 'px', null] + [clientX + 45 + 'px', null] else [null, @clientWidth - clientX + 45 + 'px'] @@ -326,7 +322,6 @@ UI = do -> style.top = top + 'px' style.left = left style.right = right - hoverend = -> $.rm @el $.off @root, @endEvents, @hoverend