mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 06:40:09 +08:00
DEV: Remove the <details> polyfill (#10260)
Per the linked site (http://mths.be/details) and https://caniuse.com/#feat=details the <details> element is supported since Chrome 12/Safari 6/Firefox 49/Edge 79. IE 11 doesn't handle them, but we dropped the support for that browser.
This commit is contained in:
parent
5f3dfce4eb
commit
8f2f9e6afa
@ -1,58 +0,0 @@
|
|||||||
(function(document, $) {
|
|
||||||
|
|
||||||
// cf. http://mths.be/details
|
|
||||||
var hasNativeSupport = (function(doc) {
|
|
||||||
var fake, el = doc.createElement("details");
|
|
||||||
// fail-fast
|
|
||||||
if (!("open" in el)) { return false; }
|
|
||||||
// figure out a root node
|
|
||||||
var root = doc.body || (function() {
|
|
||||||
var de = doc.documentElement;
|
|
||||||
fake = true;
|
|
||||||
return de.insertBefore(doc.createElement("body"), de.firstElementChild || de.firstChild);
|
|
||||||
})();
|
|
||||||
// setup test element
|
|
||||||
el.innerHTML = "<summary>a</summary>b";
|
|
||||||
el.style.display = "block";
|
|
||||||
// add test element to the root node
|
|
||||||
root.appendChild(el);
|
|
||||||
// can we open it?
|
|
||||||
var diff = el.offsetHeight;
|
|
||||||
el.open = true;
|
|
||||||
diff = diff !== el.offsetHeight;
|
|
||||||
// cleanup
|
|
||||||
root.removeChild(el);
|
|
||||||
if (fake) { root.parentNode.removeChild(root); }
|
|
||||||
// return the result
|
|
||||||
return diff;
|
|
||||||
})(document);
|
|
||||||
|
|
||||||
function toggleOpen($details) {
|
|
||||||
$details.toggleClass("open");
|
|
||||||
}
|
|
||||||
|
|
||||||
$.fn.details = function() {
|
|
||||||
if (hasNativeSupport) { return this; }
|
|
||||||
|
|
||||||
return this.each(function() {
|
|
||||||
var $details = $(this),
|
|
||||||
$firstSummary = $("summary", $details).first();
|
|
||||||
|
|
||||||
$firstSummary.prop("tabIndex", 0);
|
|
||||||
|
|
||||||
$firstSummary.on("keydown", function(event) {
|
|
||||||
if (event.keyCode === 32 /* SPACE */ || event.keyCode === 13 /* ENTER */) {
|
|
||||||
toggleOpen($details);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$firstSummary.on("click", function() {
|
|
||||||
$firstSummary.focus();
|
|
||||||
toggleOpen($details);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
})(document, jQuery);
|
|
@ -2,7 +2,7 @@ import I18n from "I18n";
|
|||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
|
|
||||||
function initializeDetails(api) {
|
function initializeDetails(api) {
|
||||||
api.decorateCooked($elem => $("details", $elem).details(), {
|
api.decorateCooked($elem => $("details", $elem), {
|
||||||
id: "discourse-details"
|
id: "discourse-details"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
enabled_site_setting :details_enabled
|
enabled_site_setting :details_enabled
|
||||||
hide_plugin if self.respond_to?(:hide_plugin)
|
hide_plugin if self.respond_to?(:hide_plugin)
|
||||||
|
|
||||||
register_asset "javascripts/details.js"
|
|
||||||
register_asset "stylesheets/details.scss"
|
register_asset "stylesheets/details.scss"
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user