Improve mobile editing
This commit is contained in:
+22
-1
@@ -142,6 +142,8 @@
|
||||
|
||||
var actions = {
|
||||
save: function () { form.requestSubmit(); },
|
||||
undo: function () { CM.undo(view); view.focus(); },
|
||||
redo: function () { CM.redo(view); view.focus(); },
|
||||
bold: function () { wrap('**', '**', 'bold text'); },
|
||||
italic: function () { wrap('*', '*', 'italic text'); },
|
||||
h1: function () { linePrefix('# '); },
|
||||
@@ -214,5 +216,24 @@
|
||||
|
||||
// --- Dropdowns ---
|
||||
|
||||
document.querySelectorAll('.dropdown-toggle').forEach(wireDropdown);
|
||||
// The toolbar scrolls horizontally on mobile, which makes it an overflow
|
||||
// container that would clip its absolutely-positioned dropdown menus. Pin an
|
||||
// open menu to the viewport under its trigger so it escapes the clip.
|
||||
var toolbar = document.querySelector('.editor-toolbar');
|
||||
function pinMenu(toggle, menu) {
|
||||
if (!menu.classList.contains('is-open')) return;
|
||||
var r = toggle.getBoundingClientRect();
|
||||
menu.style.position = 'fixed';
|
||||
menu.style.top = r.bottom + 'px';
|
||||
var left = Math.min(r.left, document.documentElement.clientWidth - menu.offsetWidth - 4);
|
||||
menu.style.left = Math.max(4, left) + 'px';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.dropdown-toggle').forEach(function (toggle) {
|
||||
wireDropdown(toggle);
|
||||
var menu = toggle.parentElement.querySelector('.dropdown-menu');
|
||||
if (!menu || !toolbar || !toolbar.contains(toggle)) return;
|
||||
// Runs after wireDropdown's own click handler has toggled is-open.
|
||||
toggle.addEventListener('click', function () { pinMenu(toggle, menu); });
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user