diff --git a/4chan_x.user.js b/4chan_x.user.js index 5502d2572..366f09911 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -199,23 +199,25 @@ }; ui = { dialog: function(id, position, html) { - var el, left, top, _ref, _ref2; + var el, left, saved, top; el = d.createElement('div'); el.className = 'reply dialog'; el.innerHTML = html; el.id = id; - left = position.left, top = position.top; - left = (_ref = localStorage["" + NAMESPACE + id + "Left"]) != null ? _ref : left; - top = (_ref2 = localStorage["" + NAMESPACE + id + "Top"]) != null ? _ref2 : top; - if (left) { - el.style.left = left; + if (saved = localStorage["" + NAMESPACE + id + ".position"]) { + el.style.cssText = saved; } else { - el.style.right = 0; - } - if (top) { - el.style.top = top; - } else { - el.style.bottom = 0; + left = position.left, top = position.top; + if (left) { + el.style.left = left; + } else { + el.style.right = 0; + } + if (top) { + el.style.top = top; + } else { + el.style.bottom = 0; + } } el.querySelector('div.move').addEventListener('mousedown', ui.dragstart, false); return el; @@ -259,8 +261,7 @@ var el, id; el = ui.el; id = el.id; - localStorage["" + NAMESPACE + id + "Left"] = el.style.left; - localStorage["" + NAMESPACE + id + "Top"] = el.style.top; + localStorage["" + NAMESPACE + id + ".position"] = el.style.cssText; d.removeEventListener('mousemove', ui.drag, false); return d.removeEventListener('mouseup', ui.dragend, false); }, diff --git a/script.coffee b/script.coffee index afbc0161c..e0ce98f59 100644 --- a/script.coffee +++ b/script.coffee @@ -126,11 +126,12 @@ ui = el.className = 'reply dialog' el.innerHTML = html el.id = id - {left, top} = position - left = localStorage["#{NAMESPACE}#{id}Left"] ? left - top = localStorage["#{NAMESPACE}#{id}Top"] ? top - if left then el.style.left = left else el.style.right = 0 - if top then el.style.top = top else el.style.bottom = 0 + if saved = localStorage["#{NAMESPACE}#{id}.position"] + el.style.cssText = saved + else + {left, top} = position + if left then el.style.left = left else el.style.right = 0 + if top then el.style.top = top else el.style.bottom = 0 el.querySelector('div.move').addEventListener 'mousedown', ui.dragstart, false el dragstart: (e) -> @@ -170,8 +171,7 @@ ui = #a = (b = c.b, c).a; {el} = ui {id} = el - localStorage["#{NAMESPACE}#{id}Left"] = el.style.left - localStorage["#{NAMESPACE}#{id}Top"] = el.style.top + localStorage["#{NAMESPACE}#{id}.position"] = el.style.cssText d.removeEventListener 'mousemove', ui.drag, false d.removeEventListener 'mouseup', ui.dragend, false hover: (e) ->