From 8b08f066a5affa43c568bbc3188e7df4cc14c14c Mon Sep 17 00:00:00 2001 From: Matthias Mees Date: Sat, 8 Mar 2014 00:38:12 +0100 Subject: [PATCH] Added details JS polyfill for Firefox and IE --- .../2k11/admin/serendipity_editor.js.tpl | 105 ++++++++++++++++++ templates/2k11/admin/style.css | 18 +++ 2 files changed, 123 insertions(+) diff --git a/templates/2k11/admin/serendipity_editor.js.tpl b/templates/2k11/admin/serendipity_editor.js.tpl index c0dbfd75..68272858 100644 --- a/templates/2k11/admin/serendipity_editor.js.tpl +++ b/templates/2k11/admin/serendipity_editor.js.tpl @@ -708,6 +708,107 @@ var AccessifyHTML5 = function (defaults, more_fixes) { } }; +// mths.be/details +; +(function(a, f) { + var e = f.fn, + d, c = Object.prototype.toString.call(window.opera) == '[object Opera]', + g = (function(l) { + var j = l.createElement('details'), + i, h, k; + if (!('open' in j)) { + return false + } + h = l.body || (function() { + var m = l.documentElement; + i = true; + return m.insertBefore(l.createElement('body'), m.firstElementChild || m.firstChild) + }()); + j.innerHTML = 'ab'; + j.style.display = 'block'; + h.appendChild(j); + k = j.offsetHeight; + j.open = true; + k = k != j.offsetHeight; + h.removeChild(j); + if (i) { + h.parentNode.removeChild(h) + } + return k + }(a)), + b = function(i, l, k, h) { + var j = i.prop('open'), + m = j && h || !j && !h; + if (m) { + i.removeClass('open').prop('open', false).triggerHandler('close.details'); + l.attr('aria-expanded', false); + k.hide() + } else { + i.addClass('open').prop('open', true).triggerHandler('open.details'); + l.attr('aria-expanded', true); + k.show() + } + }; + e.noSelect = function() { + var h = 'none'; + return this.bind('selectstart dragstart mousedown', function() { + return false + }).css({ + MozUserSelect: h, + msUserSelect: h, + webkitUserSelect: h, + userSelect: h + }) + }; + if (g) { + d = e.details = function() { + return this.each(function() { + var i = f(this), + h = f('summary', i).first(); + h.attr({ + role: 'button', + 'aria-expanded': i.prop('open') + }).on('click', function() { + var j = i.prop('open'); + h.attr('aria-expanded', !j); + i.triggerHandler((j ? 'close' : 'open') + '.details') + }) + }) + }; + d.support = g + } else { + d = e.details = function() { + return this.each(function() { + var h = f(this), + j = f('summary', h).first(), + i = h.children(':not(summary)'), + k = h.contents(':not(summary)'); + if (!j.length) { + j = f('').text('Details').prependTo(h) + } + if (i.length != k.length) { + k.filter(function() { + return this.nodeType == 3 && /[^ \t\n\f\r]/.test(this.data) + }).wrap(''); + i = h.children(':not(summary)') + } + h.prop('open', typeof h.attr('open') == 'string'); + b(h, j, i); + j.attr('role', 'button').noSelect().prop('tabIndex', 0).on('click', function() { + j.focus(); + b(h, j, i, true) + }).keyup(function(l) { + if (32 == l.keyCode || (13 == l.keyCode && !c)) { + l.preventDefault(); + j.click() + } + }) + }) + }; + d.support = g + } +}(document, jQuery)); + (function($) { // Fire responsive nav if($('body').has('#main_menu').size() > 0) { @@ -725,6 +826,10 @@ var AccessifyHTML5 = function (defaults, more_fixes) { }); } + // Fire details polyfill + $('html').addClass($.fn.details.support ? 'details' : 'no-details'); + $('details').details(); + // Fire WYSIWYG editor(s) serendipity.spawn(); diff --git a/templates/2k11/admin/style.css b/templates/2k11/admin/style.css index 0bc6d9e1..25be1c6c 100644 --- a/templates/2k11/admin/style.css +++ b/templates/2k11/admin/style.css @@ -300,6 +300,24 @@ nav ol { padding: 0; } +/* details polyfill */ +.no-details details > * { + display: none; +} + +.no-details details > summary:before { + content: '\25BA '; + float: left; + width: 20px; +} + +.no-details details.open > summary:before { + content: '\25BC '; +} + +.no-details details summary { + display: block; +} /* HELPER CLASSES */ /* Hide visually, available for screenreaders */