From 180a0fdac55678e1c37ae6642a9baf5009c767ca Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 13 Apr 2020 03:28:48 -0700 Subject: [PATCH] Add data-icon attribute to parent, using underscore instead of hyphen. #2395 Also fix alt text not showing up for Catalog Settings button. --- src/Filtering/PostHiding.coffee | 5 +++-- src/Filtering/ThreadHiding.coffee | 3 ++- src/General/Header.coffee | 4 ++-- src/General/Index.coffee | 2 +- src/General/Settings.coffee | 2 +- src/General/Settings/Settings.html | 2 +- src/Icons/Icon.coffee | 8 ++++++++ src/Images/Gallery.coffee | 2 +- src/Images/ImageExpand.coffee | 6 +++--- src/Images/ImageLoader.coffee | 2 +- src/Menu/Menu.coffee | 2 +- src/Miscellaneous/FileInfo.coffee | 4 ++-- src/Miscellaneous/PSAHiding.coffee | 2 +- src/Monitoring/ThreadWatcher.coffee | 6 +++--- src/Monitoring/ThreadWatcher/ThreadWatcher.html | 4 ++-- src/Posting/QR.coffee | 2 +- src/Posting/QR.post.coffee | 2 +- src/Posting/QR/QuickReply.html | 12 ++++++------ src/classes/Notice.coffee | 2 +- 19 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 src/Icons/Icon.coffee diff --git a/src/Filtering/PostHiding.coffee b/src/Filtering/PostHiding.coffee index 41d69be9c2..1aad2bce51 100644 --- a/src/Filtering/PostHiding.coffee +++ b/src/Filtering/PostHiding.coffee @@ -158,8 +158,9 @@ PostHiding = makeButton: (post, type) -> span = $.el 'span', - className: "fourchan-x--icon icon--small" - $.extend span, `<%= html('&{type === "hide" ? Icons.minus_square_o : Icons.plus_square_o}') %>` + className: 'fourchan-x--icon icon--small' + icon = (if type is 'hide' then 'minus_square_o' else 'plus_square_o') + Icon.set span, icon a = $.el 'a', className: "#{type}-reply-button" href: 'javascript:;' diff --git a/src/Filtering/ThreadHiding.coffee b/src/Filtering/ThreadHiding.coffee index dad1db3d35..a2e1d52a16 100644 --- a/src/Filtering/ThreadHiding.coffee +++ b/src/Filtering/ThreadHiding.coffee @@ -139,7 +139,8 @@ ThreadHiding = a = $.el 'a', className: "#{type}-thread-button" href: 'javascript:;' - $.extend a, `<%= html('&{type === "hide" ? Icons.minus_square : Icons.plus_square}') %>` + icon = (if type is 'hide' then 'minus_square' else 'plus_square') + $.extend a, `<%= html('&{$.getOwn(Icons, icon)}') %>` a.dataset.fullID = thread.fullID $.on a, 'click', ThreadHiding.toggle a diff --git a/src/General/Header.coffee b/src/General/Header.coffee index 48803e8d31..df8835a24c 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -113,9 +113,9 @@ Header = if g.SITE.software is 'yotsuba' and (g.VIEW is 'catalog' or !Conf['Disable Native Extension']) cs = $.el 'a', href: 'javascript:;' if g.VIEW is 'catalog' - cs.title = cs.textContent = 'Catalog Settings' + cs.title = 'Catalog Settings' cs.className = 'fourchan-x--icon icon--large' - $.extend cs, `<%= html('&{Icons.book}') %>` + Icon.set cs, 'book', 'Catalog Settings' else cs.title = cs.textContent = '4chan Settings' cs.className = 'native-settings' diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 10058a6f81..7779491c56 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -46,7 +46,7 @@ Index = className: 'fourchan-x--icon icon--large' title: 'Refresh' href: 'javascript:;' - $.extend @button, `<%= html('Refresh Index&{Icons.refresh}') %>` + Icon.set @button, 'refresh', 'Refresh Index' $.on @button, 'click', -> Index.update() Header.addShortcut 'index-refresh', @button, 590 diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index ac99e61ec3..a340e22f52 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -5,7 +5,7 @@ Settings = className: 'settings-link fourchan-x--icon icon--large' title: '<%= meta.name %> Settings' href: 'javascript:;' - $.extend link, `<%= html('Settings&{Icons.wrench}') %>` + Icon.set link, 'wrench', 'Settings' $.on link, 'click', Settings.open Header.addShortcut 'settings', link, 820 diff --git a/src/General/Settings/Settings.html b/src/General/Settings/Settings.html index f8a32a6a0a..577e47df5d 100644 --- a/src/General/Settings/Settings.html +++ b/src/General/Settings/Settings.html @@ -10,7 +10,7 @@ <%= meta.name %> |  ${g.VERSION} |  Issues |  - &{Icons.close} + &{Icons.close}
diff --git a/src/Icons/Icon.coffee b/src/Icons/Icon.coffee new file mode 100644 index 0000000000..1de371d91b --- /dev/null +++ b/src/Icons/Icon.coffee @@ -0,0 +1,8 @@ +Icon = + set: (node, name, altText) -> + node.dataset.icon = name + html = $.getOwn(Icons, name) + if altText + $.extend node, `<%= html('${altText}&{html}') %>` + else + $.extend node, html diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 0c00424c8e..bbe2c08cdb 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -8,7 +8,7 @@ Gallery = href: 'javascript:;' title: 'Gallery' className: 'fourchan-x--icon icon--large' - $.extend el, `<%= html('Gallery&{Icons.picture_o}') %>` + Icon.set el, 'picture_o', 'Gallery' $.on el, 'click', @cb.toggle diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index b308da78d0..14b07a847f 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -6,7 +6,7 @@ ImageExpand = className: 'expand-all-shortcut fourchan-x--icon icon--large' title: 'Expand All Images' href: 'javascript:;' - $.extend @EAI, `<%= html('EAI&{Icons.expand}') %>` + Icon.set @EAI, 'expand', 'EAI' $.on @EAI, 'click', @cb.toggleAll Header.addShortcut 'expand-all', @EAI, 520 @@ -68,12 +68,12 @@ ImageExpand = if ImageExpand.on = $.hasClass ImageExpand.EAI, 'expand-all-shortcut' ImageExpand.EAI.className = 'contract-all-shortcut fourchan-x--icon icon--large' ImageExpand.EAI.title = 'Contract All Images' - $.extend ImageExpand.EAI, `<%= html('CAI&{Icons.compress}') %>` + Icon.set ImageExpand.EAI, 'compress', 'CAI' func = ImageExpand.expand else ImageExpand.EAI.className = 'expand-all-shortcut fourchan-x--icon icon--large' ImageExpand.EAI.title = 'Expand All Images' - $.extend ImageExpand.EAI, `<%= html('EAI&{Icons.expand}') %>` + Icon.set ImageExpand.EAI, 'expand', 'EAI' func = ImageExpand.contract g.posts.forEach (post) -> diff --git a/src/Images/ImageLoader.coffee b/src/Images/ImageLoader.coffee index cc8c5c36b4..c40587b5b4 100644 --- a/src/Images/ImageLoader.coffee +++ b/src/Images/ImageLoader.coffee @@ -21,7 +21,7 @@ ImageLoader = href: 'javascript:;' title: 'Prefetch Images' className: 'fourchan-x--icon icon--large disabled' - $.extend el, `<%= html('Prefetch&{Icons.bolt}') %>` + Icon.set el, 'bolt', 'Prefetch' $.on el, 'click', @toggle diff --git a/src/Menu/Menu.coffee b/src/Menu/Menu.coffee index 1120cd5e36..bc20702526 100644 --- a/src/Menu/Menu.coffee +++ b/src/Menu/Menu.coffee @@ -6,7 +6,7 @@ Menu = className: 'menu-button fourchan-x--icon icon--small' href: 'javascript:;' - $.extend @button, `<%= html('&{Icons.angle_down}') %>` + Icon.set @button, 'angle_down' @menu = new UI.Menu 'post' Callbacks.Post.push diff --git a/src/Miscellaneous/FileInfo.coffee b/src/Miscellaneous/FileInfo.coffee index f5aeb47c82..5dfe4e693c 100644 --- a/src/Miscellaneous/FileInfo.coffee +++ b/src/Miscellaneous/FileInfo.coffee @@ -51,8 +51,8 @@ FileInfo = else `<%= html('${shortname}${fullname}') %>` N: -> `<%= html('${this.file.name}') %>` - d: -> `<%= html('&{Icons.download}') %>` - f: -> `<%= html('&{Icons.close}') %>` + d: -> `<%= html('&{Icons.download}') %>` + f: -> `<%= html('&{Icons.close}') %>` p: -> `<%= html('?{this.file.isSpoiler}{Spoiler, }') %>` s: -> `<%= html('${this.file.size}') %>` B: -> `<%= html('${Math.round(this.file.sizeInBytes)} Bytes') %>` diff --git a/src/Miscellaneous/PSAHiding.coffee b/src/Miscellaneous/PSAHiding.coffee index 78962b1e01..34710f0da7 100644 --- a/src/Miscellaneous/PSAHiding.coffee +++ b/src/Miscellaneous/PSAHiding.coffee @@ -27,7 +27,7 @@ PSAHiding = title: 'Mark announcement as read and hide.' className: 'hide-announcement-button fourchan-x--icon' href: 'javascript:;' - $.extend btn, `<%= html('&{Icons.minus_square}') %>` + Icon.set btn, 'minus_square' $.on btn, 'click', PSAHiding.toggle if psa.firstChild?.tagName is 'HR' $.after psa.firstChild, btn diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index bc5277ea69..e5822e7216 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -7,7 +7,7 @@ ThreadWatcher = title: 'Thread Watcher' href: 'javascript:;' className: 'fourchan-x--icon icon--large ' - $.extend sc, `<%= html('Watcher&{Icons.eye}') %>` + Icon.set sc, 'eye', 'Watcher' @db = new DataBoard 'watchedThreads', @refresh, true @dbLM = new DataBoard 'watcherLastModified', null, true @@ -92,7 +92,7 @@ ThreadWatcher = toggler = $.el 'a', href: 'javascript:;' className: 'watch-thread-link fourchan-x--icon icon--large' - $.extend toggler, `<%= html('&{Icons.heart}') %>` + Icon.set toggler, 'heart' $.before $('input', @nodes.info), toggler siteID = g.SITE.ID boardID = @board.ID @@ -403,7 +403,7 @@ ThreadWatcher = x = $.el 'a', className: 'fourchan-x--icon' href: 'javascript:;' - $.extend x, `<%= html('&{Icons.close}') %>` + Icon.set x, 'close' $.on x, 'click', ThreadWatcher.cb.rm {excerpt, isArchived} = data diff --git a/src/Monitoring/ThreadWatcher/ThreadWatcher.html b/src/Monitoring/ThreadWatcher/ThreadWatcher.html index 55a50439c8..5d1c33f4a7 100644 --- a/src/Monitoring/ThreadWatcher/ThreadWatcher.html +++ b/src/Monitoring/ThreadWatcher/ThreadWatcher.html @@ -1,7 +1,7 @@
- Thread Watcher &{Icons.refresh} + Thread Watcher &{Icons.refresh} - &{Icons.angle_down} + &{Icons.angle_down} ×
diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 8922e8b2c3..dbda37e7b7 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -38,7 +38,7 @@ QR = className: 'fourchan-x--icon icon--large disabled' title: 'Quick Reply' href: 'javascript:;' - $.extend sc, `<%= html('QR&{Icons.comment_o}') %>` + Icon.set sc, 'comment_o', 'QR' $.on sc, 'click', -> return unless QR.postingIsEnabled if Conf['Persistent QR'] or !QR.nodes or QR.nodes.el.hidden diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index 5ee39faab4..a8db37998c 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -4,7 +4,7 @@ QR.post = class className: 'qr-preview' draggable: true href: 'javascript:;' - $.extend el, `<%= html('&{Icons.times_circle}') %>` + $.extend el, `<%= html('&{Icons.times_circle}') %>` @nodes = el: el diff --git a/src/Posting/QR/QuickReply.html b/src/Posting/QR/QuickReply.html index 678375abc4..c8367b0a45 100644 --- a/src/Posting/QR/QuickReply.html +++ b/src/Posting/QR/QuickReply.html @@ -40,12 +40,12 @@ S - &{Icons.edit} - &{Icons.times_circle} - &{Icons.link} - - &{Icons.clock_o} - &{Icons.plus_square} + &{Icons.edit} + &{Icons.times_circle} + &{Icons.link} + + &{Icons.clock_o} + &{Icons.plus_square} diff --git a/src/classes/Notice.coffee b/src/classes/Notice.coffee index e701094aed..7780349311 100644 --- a/src/classes/Notice.coffee +++ b/src/classes/Notice.coffee @@ -1,7 +1,7 @@ class Notice constructor: (type, content, @timeout, @onclose) -> @el = $.el 'div', - `<%= html('&{Icons.close}
') %>` + `<%= html('&{Icons.close}
') %>` @el.style.opacity = 0 @setType type $.on @el.firstElementChild, 'click', @close