diff options
author | Yorhel <git@yorhel.nl> | 2020-04-22 11:23:39 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-04-22 11:23:42 +0200 |
commit | ec04cb3940d47589e087d6b59490ca7a1466bfeb (patch) | |
tree | cac6bd8c40d315aa1aea669e5fb7be03fe34aac0 /elm | |
parent | 57afeaf2320722dfa5e2f61411cecc273fe349e4 (diff) |
v2rw/VN::Page: Add character summary + mainbox summarization
Didn't see a better way to keep the height of the character summary
in check, so re-added the mainbox summarization.
Spoiler hiding now follows user preferences - this fixes a correctness
issue with characters being assigned the wrong role if they have
spoilerous release-specific roles and is also just a lot easier.
Replaced the spoiler options with a link to the full character list
instead.
Diffstat (limited to 'elm')
-rw-r--r-- | elm/mainbox-summarize.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/elm/mainbox-summarize.js b/elm/mainbox-summarize.js new file mode 100644 index 00000000..5f940ed5 --- /dev/null +++ b/elm/mainbox-summarize.js @@ -0,0 +1,33 @@ +// Adds a "more"/"less" link to the bottom of a mainbox depending on the +// height of its contents. +// +// Usage: +// +// <div class="mainbox" data-mainbox-summarize="200"> .. </div> + +function set(d, h) { + var expanded = true; + var a = document.createElement('a'); + a.href = '#'; + + var toggle = function() { + expanded = !expanded; + d.style.maxHeight = expanded ? null : h+'px'; + d.style.overflowY = expanded ? null : 'hidden'; + a.textContent = expanded ? '⇑ less ⇑' : '⇓ more ⇓'; + return false; + }; + + a.onclick = toggle; + var t = document.createElement('div'); + t.className = 'summarize_more'; + t.appendChild(a); + d.parentNode.insertBefore(t, d.nextSibling); + toggle(); +} + +document.querySelectorAll('.mainbox[data-mainbox-summarize]').forEach(function(d) { + var h = Math.floor(d.getAttribute('data-mainbox-summarize')); + if(d.offsetHeight > h+100) + set(d, h) +}); |