From be68f4c78a44c9e232dec9e23eac7a99c77b393d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 15 Apr 2013 19:44:01 +0200 Subject: [PATCH] Get rid of $.engine. --- lib/$.coffee | 1 - src/features.coffee | 23 ++++++++++++++--------- src/main.coffee | 2 +- src/qr.coffee | 10 +++++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/$.coffee b/lib/$.coffee index 454e2c62b..46befcb64 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -16,7 +16,6 @@ $.extend $, MINUTE: 1000 * 60 HOUR : 1000 * 60 * 60 DAY : 1000 * 60 * 60 * 24 - engine: '<% if (type === 'crx') { %>webkit<% } else if (type === 'userjs') { %>presto<% } else { %>gecko<% } %>' id: (id) -> d.getElementById id ready: (fc) -> diff --git a/src/features.coffee b/src/features.coffee index 412eef272..8288228b2 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -167,7 +167,7 @@ Header = unless Conf['Bottom header'] headRect = Header.toggle.getBoundingClientRect() top += - headRect.top - headRect.height - (if $.engine is 'webkit' then d.body else doc).scrollTop += top + <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %>.scrollTop += top toggleBarVisibility: (e) -> return if e.type is 'mousedown' and e.button isnt 0 # not LMB hide = if @nodeName is 'INPUT' @@ -439,13 +439,14 @@ Settings = download: "<%= meta.name %> v#{g.VERSION}-#{now}.json" href: "data:application/json;base64,#{btoa unescape encodeURIComponent JSON.stringify data, null, 2}" target: '_blank' - if $.engine isnt 'gecko' - a.click() - return + <% if (type === 'userscript') { %> # XXX Firefox won't let us download automatically. p = $ '.imp-exp-result', Settings.dialog $.rmAll p $.add p, a + <% } else { %> + a.click() + <% } %> import: -> @nextElementSibling.click() onImport: -> @@ -1695,11 +1696,15 @@ DeleteLink = DownloadLink = init: -> + <% if (type === 'userscript') { %> + # Firefox won't let us download cross-domain content. + return + <% } %> return if g.VIEW is 'catalog' or !Conf['Menu'] or !Conf['Download Link'] - # Firefox won't let us download cross-domain content. # Test for download feature support. - return if $.engine is 'gecko' or $.el('a').download is undefined + return unless 'download' of $.el 'a' + a = $.el 'a', className: 'download-link' textContent: 'Download file' @@ -3305,7 +3310,7 @@ ImageExpand = unless Conf['Bottom header'] headRect = Header.toggle.getBoundingClientRect() top += - headRect.top - headRect.height - root = if $.engine is 'webkit' then d.body else doc + root = <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %> root.scrollTop += top if rect.top < 0 root.scrollLeft = 0 if rect.left < 0 @@ -3347,7 +3352,7 @@ ImageExpand = $.addClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' return unless prev.top + prev.height <= 0 - root = if $.engine is 'webkit' then d.body else doc + root = <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %> curr = post.nodes.root.getBoundingClientRect() root.scrollTop += curr.height - prev.height + curr.top - prev.top @@ -4206,7 +4211,7 @@ ThreadUpdater = $.add ThreadUpdater.root, nodes if scroll if Conf['Bottom Scroll'] - (if $.engine is 'webkit' then d.body else doc).scrollTop = d.body.clientHeight + <% if (type === 'crx') { %>d.body<% } else { %>doc<% } %>.scrollTop = d.body.clientHeight else Header.scrollToPost nodes[0] diff --git a/src/main.coffee b/src/main.coffee index 68c95f7b2..79a724537 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -397,7 +397,7 @@ Main = return unless Main.isThisPageLegit() # disable the mobile layout $('link[href*=mobile]', d.head)?.disabled = true - $.addClass doc, $.engine + $.addClass doc, '<% if (type === 'crx') { %>webkit<% } else if (type === 'userjs') { %>presto<% } else { %>gecko<% } %>' $.addClass doc, 'fourchan-x' $.addStyle Main.css diff --git a/src/qr.coffee b/src/qr.coffee index e1ca69e06..c1aa9bbfa 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -28,8 +28,9 @@ QR = QR.nodes.com.focus() Header.addShortcut sc - if $.engine is 'webkit' - $.on d, 'paste', QR.paste + <% if (type === 'crx') { %> + $.on d, 'paste', QR.paste + <% } %> $.on d, 'dragover', QR.dragOver $.on d, 'drop', QR.dropFile $.on d, 'dragstart dragend', QR.drag @@ -781,7 +782,10 @@ QR = # Add empty mimeType to avoid errors with URLs selected in Window's file dialog. QR.mimeTypes.push '' nodes.fileInput.max = $('input[name=MAX_FILE_SIZE]').value - nodes.fileInput.accept = "text/*, #{mimeTypes}" if $.engine isnt 'presto' # Opera's accept attribute is fucked up + <% if (type !== 'userjs') { %> + # Opera's accept attribute is fucked up + nodes.fileInput.accept = "text/*, #{mimeTypes}" + <% } %> QR.spoiler = !!$ 'input[name=spoiler]' nodes.spoiler.hidden = !QR.spoiler