From 9f0cfd8e249fda275296ca0434d1fc0df4145f64 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 3 Feb 2015 16:59:05 -0800 Subject: [PATCH] Show WebM title on mouseover. --- src/General/css/style.css | 24 +++++++++++++++++++- src/Images/Metadata.coffee | 46 ++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/General/css/style.css b/src/General/css/style.css index 8a0f7e78f..5788455cf 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -928,9 +928,31 @@ span.hide-announcement { .fileThumb > .warning { clear: both; } -a.webm-title.ready { +/* WEBM Metadata */ +.webm-title > a::before { + content: "title"; text-decoration: underline; } +.webm-title.loading > a::after { + content: "..."; +} +.webm-title.error > a:hover::before, +.webm-title.error > a:focus::before { + content: "error"; + text-decoration: none; +} +.webm-title > span { + cursor: text; +} +.webm-title.not-found > span::before { + content: "not found"; +} +.webm-title:not(:hover):not(:focus) > span, +.webm-title:hover > span + a, +.webm-title:focus > span + a { + display: none; +} +/* Volume control */ input[name="Default Volume"] { width: 4em; height: 1ex; diff --git a/src/Images/Metadata.coffee b/src/Images/Metadata.coffee index cfc75223b..f5f89b180 100644 --- a/src/Images/Metadata.coffee +++ b/src/Images/Metadata.coffee @@ -9,26 +9,32 @@ Metadata = node: -> return unless @file and /webm$/i.test @file.URL if @isClone - link = $ '.webm-title', @file.text + el = $ '.webm-title', @file.text else - link = $.el 'a', - className: 'webm-title ready' - href: 'javascript:;' - textContent: 'title' - $.add @file.text, [$.tn('\u00A0'), link] - $.on link, 'click', Metadata[if link.dataset.title? then 'toggle' else 'load'] + el = $.el 'span', + className: 'webm-title' + $.extend el, + <%= html('') %> + $.add @file.text, [$.tn('\u00A0'), el] + $.one el.lastElementChild, 'mouseover focus', Metadata.load if el.children.length is 1 load: -> - $.off @, 'click', Metadata.load - $.rmClass @, 'ready' - @textContent = '...' + $.rmClass @parentNode, 'error' + $.addClass @parentNode, 'loading' CrossOrigin.binary Get.postFromNode(@).file.URL, (data) => + $.rmClass @parentNode, 'loading' if data? - Metadata.parse.call @, data - $.on @, 'click', Metadata.toggle + title = Metadata.parse data + output = $.el 'span', + textContent: title or '' + $.addClass @parentNode, 'not-found' unless title? + $.before @, output + @parentNode.tabIndex = 0 + @parentNode.focus() if d.activeElement is @ + @tabIndex = -1 else - @textContent = 'error' - $.on @, 'click', Metadata.load + $.addClass @parentNode, 'error' + $.one @, 'click', Metadata.load , Range: 'bytes=0-9999' @@ -50,15 +56,7 @@ Metadata = title = '' while size-- and i < data.length title += String.fromCharCode data[i++] - @textContent = @dataset.title = decodeURIComponent escape title # UTF-8 decoding - return + return decodeURIComponent escape title # UTF-8 decoding else unless element in [0x8538067, 0x549A966] # Segment, Info i += size - @textContent = 'not found' - - toggle: -> - @textContent = if $.hasClass @, 'ready' - @dataset.title or 'not found' - else - 'title' - $.toggleClass @, 'ready' + null