From f15b920850ae86af0d0f92cfd471d30f695931a1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 1 Jun 2012 19:53:24 +0200 Subject: [PATCH] Use localStorage.get/setItem in UI. --- 4chan_x.user.js | 8 +++----- script.coffee | 14 +++++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 3ff3fd31b..423f22987 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -199,12 +199,12 @@ UI = { dialog: function(id, position, html) { - var el, saved; + var el; el = d.createElement('div'); el.className = 'reply dialog'; el.innerHTML = html; el.id = id; - el.style.cssText = (saved = localStorage["" + Main.namespace + id + ".position"]) ? saved : position; + el.style.cssText = localStorage.getItem("" + Main.namespace + id + ".position") || position; el.querySelector('.move').addEventListener('mousedown', UI.dragstart, false); return el; }, @@ -233,9 +233,7 @@ return style.bottom = top === null ? '0px' : null; }, dragend: function() { - var el; - el = UI.el; - localStorage["" + Main.namespace + el.id + ".position"] = el.style.cssText; + localStorage.setItem("" + Main.namespace + UI.el.id + ".position", UI.el.style.cssText); d.removeEventListener('mousemove', UI.drag, false); d.removeEventListener('mouseup', UI.dragend, false); return delete UI.el; diff --git a/script.coffee b/script.coffee index 94ded600d..905762b04 100644 --- a/script.coffee +++ b/script.coffee @@ -164,15 +164,15 @@ UI = el = d.createElement 'div' el.className = 'reply dialog' el.innerHTML = html - el.id = id - el.style.cssText = if saved = localStorage["#{Main.namespace}#{id}.position"] then saved else position + el.id = id + el.style.cssText = localStorage.getItem("#{Main.namespace}#{id}.position") or position el.querySelector('.move').addEventListener 'mousedown', UI.dragstart, false el dragstart: (e) -> #prevent text selection e.preventDefault() UI.el = el = @parentNode - d.addEventListener 'mousemove', UI.drag, false + d.addEventListener 'mousemove', UI.drag, false d.addEventListener 'mouseup', UI.dragend, false #distance from pointer to el edge is constant; calculate it here. # XXX opera reports el.offsetLeft / el.offsetTop as 0 @@ -200,12 +200,8 @@ UI = style.right = if left is null then '0px' else null style.bottom = if top is null then '0px' else null dragend: -> - #$ coffee -bpe '{a} = {b} = c' - #var a, b; - #a = (b = c.b, c).a; - {el} = UI - localStorage["#{Main.namespace}#{el.id}.position"] = el.style.cssText - d.removeEventListener 'mousemove', UI.drag, false + localStorage.setItem "#{Main.namespace}#{UI.el.id}.position", UI.el.style.cssText + d.removeEventListener 'mousemove', UI.drag, false d.removeEventListener 'mouseup', UI.dragend, false delete UI.el hover: (e) ->