From 16b3a8cbd94d3d766fc7dff2b8f3fb75a0d86ff4 Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 23 Aug 2011 02:33:08 -0700 Subject: [PATCH] refactor --- 4chan_x.user.js | 24 +++++++++++++----------- script.coffee | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8480bb589..4a16884ed 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -226,7 +226,7 @@ return ui.height = d.body.clientHeight - el.offsetHeight; }, drag: function(e) { - var bottom, el, left, right, top; + var bottom, el, left, right, style, top; el = ui.el; left = e.clientX - ui.dx; if (left < 10) { @@ -242,10 +242,11 @@ top = null; } bottom = top ? null : 0; - el.style.top = top; - el.style.right = right; - el.style.bottom = bottom; - return el.style.left = left; + style = el.style; + style.top = top; + style.right = right; + style.bottom = bottom; + return style.left = left; }, dragend: function() { var el, id; @@ -257,19 +258,20 @@ return d.removeEventListener('mouseup', ui.dragend, false); }, hover: function(e) { - var clientHeight, clientWidth, clientX, clientY, el, height, top, _ref; + var clientHeight, clientWidth, clientX, clientY, el, height, style, top, _ref; clientX = e.clientX, clientY = e.clientY; el = ui.el; + style = el.style; _ref = d.body, clientHeight = _ref.clientHeight, clientWidth = _ref.clientWidth; height = el.offsetHeight; top = clientY - 120; - el.style.top = clientHeight < height || top < 0 ? 0 : top + height > clientHeight ? clientHeight - height : top; + style.top = clientHeight < height || top < 0 ? 0 : top + height > clientHeight ? clientHeight - height : top; if (clientX < clientWidth - 400) { - el.style.left = clientX + 45; - return el.style.right = null; + style.left = clientX + 45; + return style.right = null; } else { - el.style.left = null; - return el.style.right = clientWidth - clientX + 45; + style.left = null; + return style.right = clientWidth - clientX + 45; } }, hoverend: function(e) { diff --git a/script.coffee b/script.coffee index 7cff549ce..c6aa1decb 100644 --- a/script.coffee +++ b/script.coffee @@ -153,10 +153,11 @@ ui = bottom = if top then null else 0 #using null instead of '' is 4% faster #these 4 statements are 40% faster than 1 style.cssText - el.style.top = top - el.style.right = right - el.style.bottom = bottom - el.style.left = left + {style} = el + style.top = top + style.right = right + style.bottom = bottom + style.left = left dragend: -> #$ coffee -bpe '{a} = {b} = c' #var a, b; @@ -170,11 +171,12 @@ ui = hover: (e) -> {clientX, clientY} = e {el} = ui + {style} = el {clientHeight, clientWidth} = d.body height = el.offsetHeight top = clientY - 120 - el.style.top = + style.top = if clientHeight < height or top < 0 0 else if top + height > clientHeight @@ -183,11 +185,11 @@ ui = top if clientX < clientWidth - 400 - el.style.left = clientX + 45 - el.style.right = null + style.left = clientX + 45 + style.right = null else - el.style.left = null - el.style.right = clientWidth - clientX + 45 + style.left = null + style.right = clientWidth - clientX + 45 hoverend: (e) -> ui.el.parentNode.removeChild ui.el