diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2df442c..05aec690 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@
- BBCode plugin: update to version 2.0.4
- The HTML button is only displayed if inline HTML is allowed in BBCode. ([#867](https://github.com/flatpressblog/flatpress/pull/867))
- Optional new tab for URLs/links ([#960](https://github.com/flatpressblog/flatpress/pull/960), [#961](https://github.com/flatpressblog/flatpress/pull/961), [#962](https://github.com/flatpressblog/flatpress/pull/962))
+ - Shortcuts for Bold, Italic, Underline, and URLs ([#963](https://github.com/flatpressblog/flatpress/pull/963))
- jQuery plugin update to version 2.2.2 ([#896](https://github.com/flatpressblog/flatpress/pull/896))
Note: Edge Legacy, Internet Explorer 9–10, iOS 7+, and the Android browser on Android 4.0+ are no longer supported. If you need support for these legacy browsers, you must disable the jQuery plugin so that PhotoSwipe uses the older jQuery plugin 3.7.1 version.
- includes jQuery 4.0.0 and jQueryUI 1.14.2
- Archives plugin update to version 1.1.2 ([#896](https://github.com/flatpressblog/flatpress/pull/896))
diff --git a/fp-plugins/bbcode/lang/lang.cs-cz.php b/fp-plugins/bbcode/lang/lang.cs-cz.php
index f670a293..2b0810be 100644
--- a/fp-plugins/bbcode/lang/lang.cs-cz.php
+++ b/fp-plugins/bbcode/lang/lang.cs-cz.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Zvětšit výšku textového pole',
'reduce' => 'Zmenšit',
'reducetitle' => 'Zmenšit výšku textového pole',
- 'urltitle' => 'URL/ Odkaz',
+ 'urltitle' => 'URL/ Odkaz (Ctrl+K / ⌘K)',
'mailtitle' => 'E-mailová adresa',
- 'boldtitle' => 'Tučné',
- 'italictitle' => 'Kurzíva',
+ 'boldtitle' => 'Tučné (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Kurzíva (Ctrl+I / ⌘I)',
'headlinetitle' => 'Hlavička',
'fonttitle' => 'Písmo',
- 'underlinetitle' => 'Podtržené',
+ 'underlinetitle' => 'Podtržené (Ctrl+U / ⌘U)',
'crossouttitle' => 'Přeškrtnuto',
'unorderedlisttitle' => 'Netříděný seznam',
'orderedlisttitle' => 'Tříděný seznam',
diff --git a/fp-plugins/bbcode/lang/lang.da-dk.php b/fp-plugins/bbcode/lang/lang.da-dk.php
index 18160cdc..3a3e172c 100644
--- a/fp-plugins/bbcode/lang/lang.da-dk.php
+++ b/fp-plugins/bbcode/lang/lang.da-dk.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Forstør inputfeltet',
'reduce' => 'Reducer',
'reducetitle' => 'Reducer størrelsen på inputfeltet',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Ctrl+K / ⌘K)',
'mailtitle' => 'E-mail-adresse',
- 'boldtitle' => 'Fedt',
- 'italictitle' => 'Kursiv',
+ 'boldtitle' => 'Fedt (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Kursiv (Ctrl+I / ⌘I)',
'headlinetitle' => 'Overskrift',
'fonttitle' => 'Skrifttype',
- 'underlinetitle' => 'Understregning',
+ 'underlinetitle' => 'Understregning (Ctrl+U / ⌘U)',
'crossouttitle' => 'Streget ud',
'unorderedlisttitle' => 'Usorteret liste',
'orderedlisttitle' => 'Sorteret liste',
diff --git a/fp-plugins/bbcode/lang/lang.de-de.php b/fp-plugins/bbcode/lang/lang.de-de.php
index f04c6ce4..d76ae95c 100644
--- a/fp-plugins/bbcode/lang/lang.de-de.php
+++ b/fp-plugins/bbcode/lang/lang.de-de.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Das Eingabefeld vergrößern',
'reduce' => 'Verkleinern',
'reducetitle' => 'Das Eingabefeld verkleinern',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Strg+K / ⌘K)',
'mailtitle' => 'E-Mail-Adresse',
- 'boldtitle' => 'Fett',
- 'italictitle' => 'Kursiv',
+ 'boldtitle' => 'Fett (Strg+B / ⌘B)',
+ 'italictitle' => 'Kursiv (Strg+I / ⌘I)',
'headlinetitle' => 'Überschrift',
'fonttitle' => 'Schriftart',
- 'underlinetitle' => 'Unterstreichen',
+ 'underlinetitle' => 'Unterstreichen (Strg+U / ⌘U)',
'crossouttitle' => 'Durchgestrichen',
'unorderedlisttitle' => 'Unsortierte Liste',
'orderedlisttitle' => 'Sortierte Liste',
diff --git a/fp-plugins/bbcode/lang/lang.el-gr.php b/fp-plugins/bbcode/lang/lang.el-gr.php
index e80912cb..03c47dbd 100644
--- a/fp-plugins/bbcode/lang/lang.el-gr.php
+++ b/fp-plugins/bbcode/lang/lang.el-gr.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Επέκταση περιοχής κειμένου Ύψος',
'reduce' => 'Μειώστε το',
'reducetitle' => 'Μείωση ύψους περιοχής κειμένου',
- 'urltitle' => 'URL/ Σύνδεσμος',
+ 'urltitle' => 'URL/ Σύνδεσμος (Ctrl+K / ⌘K)',
'mailtitle' => 'Διεύθυνση ηλεκτρονικού ταχυδρομείου',
- 'boldtitle' => 'Έντονα',
- 'italictitle' => 'Πλάγια',
+ 'boldtitle' => 'Έντονα (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Πλάγια (Ctrl+I / ⌘I)',
'headlinetitle' => 'Επικεφαλής',
'fonttitle' => 'Γραμματοσειρά',
- 'underlinetitle' => 'Υπογραμμισμένα',
+ 'underlinetitle' => 'Υπογραμμισμένα (Ctrl+U / ⌘U)',
'crossouttitle' => 'Διαγραμμένο',
'unorderedlisttitle' => 'Μη ταξινομημένος κατάλογος',
'orderedlisttitle' => 'Ταξινομημένος κατάλογος',
diff --git a/fp-plugins/bbcode/lang/lang.en-us.php b/fp-plugins/bbcode/lang/lang.en-us.php
index 57720503..be9527a7 100644
--- a/fp-plugins/bbcode/lang/lang.en-us.php
+++ b/fp-plugins/bbcode/lang/lang.en-us.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Expand Textarea Height',
'reduce' => 'Reduce',
'reducetitle' => 'Reduce Textarea Height',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Ctrl+K / ⌘K)',
'mailtitle' => 'E-mail address',
- 'boldtitle' => 'Bold',
- 'italictitle' => 'Italic',
+ 'boldtitle' => 'Bold (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Italic (Ctrl+I / ⌘I)',
'headlinetitle' => 'Headline',
'fonttitle' => 'Font',
- 'underlinetitle' => 'Underline',
+ 'underlinetitle' => 'Underline (Ctrl+U / ⌘U)',
'crossouttitle' => 'Crossed out',
'unorderedlisttitle' => 'Unsorted list',
'orderedlisttitle' => 'Sorted list',
diff --git a/fp-plugins/bbcode/lang/lang.es-es.php b/fp-plugins/bbcode/lang/lang.es-es.php
index 9040a0a7..9e9cdd87 100644
--- a/fp-plugins/bbcode/lang/lang.es-es.php
+++ b/fp-plugins/bbcode/lang/lang.es-es.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Ampliar la altura del área de texto',
'reduce' => 'Reducir',
'reducetitle' => 'Reducir la altura del área de texto',
- 'urltitle' => 'URL/ Enlace',
+ 'urltitle' => 'URL/ Enlace (Ctrl+K / ⌘K)',
'mailtitle' => 'Correo electrónico',
- 'boldtitle' => 'Negrita',
- 'italictitle' => 'Itálica',
+ 'boldtitle' => 'Negrita (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Itálica (Ctrl+I / ⌘I)',
'headlinetitle' => 'Rúbrica',
'fonttitle' => 'Tipo de letra',
- 'underlinetitle' => 'Subrayada',
+ 'underlinetitle' => 'Subrayada (Ctrl+U / ⌘U)',
'crossouttitle' => 'Tachado',
'unorderedlisttitle' => 'Lista sin clasificar',
'orderedlisttitle' => 'Lista ordenada',
diff --git a/fp-plugins/bbcode/lang/lang.eu-es.php b/fp-plugins/bbcode/lang/lang.eu-es.php
index 5870f2ae..23cfde8e 100644
--- a/fp-plugins/bbcode/lang/lang.eu-es.php
+++ b/fp-plugins/bbcode/lang/lang.eu-es.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Handitu testu-eremuaren altuera',
'reduce' => 'Murriztu',
'reducetitle' => 'Murriztu testu-eremuaren altuera',
- 'urltitle' => 'URL / Esteka',
+ 'urltitle' => 'URL / Esteka (Ctrl+K / ⌘K)',
'mailtitle' => 'E-mail helbidea',
- 'boldtitle' => 'Lodia',
- 'italictitle' => 'Etzana',
+ 'boldtitle' => 'Lodia (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Etzana (Ctrl+I / ⌘I)',
'headlinetitle' => 'Izenburua',
'fonttitle' => 'Letra-tipoa',
- 'underlinetitle' => 'Azpimarratua',
+ 'underlinetitle' => 'Azpimarratua (Ctrl+U / ⌘U)',
'crossouttitle' => 'Marratua',
'unorderedlisttitle' => 'Ordenatu gabeko zerrenda',
'orderedlisttitle' => 'Zerrenda ordenatua',
diff --git a/fp-plugins/bbcode/lang/lang.fr-fr.php b/fp-plugins/bbcode/lang/lang.fr-fr.php
index cec79750..f4d2a768 100644
--- a/fp-plugins/bbcode/lang/lang.fr-fr.php
+++ b/fp-plugins/bbcode/lang/lang.fr-fr.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Élargir la hauteur de la zone de texte',
'reduce' => 'Réduire',
'reducetitle' => 'Réduire la hauteur de la zone de texte',
- 'urltitle' => 'URL/ lien',
+ 'urltitle' => 'URL/ lien (Ctrl+K / ⌘K)',
'mailtitle' => 'Adresse e-mail',
- 'boldtitle' => 'Gras',
- 'italictitle' => 'Italique',
+ 'boldtitle' => 'Gras (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Italique (Ctrl+I / ⌘I)',
'headlinetitle' => 'Titre',
'fonttitle' => 'Police de caractères',
- 'underlinetitle' => 'Souligné',
+ 'underlinetitle' => 'Souligné (Ctrl+U / ⌘U)',
'crossouttitle' => 'Barré',
'unorderedlisttitle' => 'Liste non triée',
'orderedlisttitle' => 'Liste triée',
diff --git a/fp-plugins/bbcode/lang/lang.it-it.php b/fp-plugins/bbcode/lang/lang.it-it.php
index 0bd543ec..aaae3274 100644
--- a/fp-plugins/bbcode/lang/lang.it-it.php
+++ b/fp-plugins/bbcode/lang/lang.it-it.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Espandi l\'altezza della casella di testo',
'reduce' => 'Riduci',
'reducetitle' => 'Riduci l\'altezza della casella di testo',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Ctrl+K / ⌘K)',
'mailtitle' => 'Indirizzo e-mail',
- 'boldtitle' => 'Grassetto',
- 'italictitle' => 'Corsivo',
+ 'boldtitle' => 'Grassetto (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Corsivo (Ctrl+I / ⌘I)',
'headlinetitle' => 'Intestazione',
'fonttitle' => 'Carattere tipografico',
- 'underlinetitle' => 'Sottolineato',
+ 'underlinetitle' => 'Sottolineato (Ctrl+U / ⌘U)',
'crossouttitle' => 'Cancellato',
'unorderedlisttitle' => 'Elenco non ordinato',
'orderedlisttitle' => 'Elenco ordinato',
diff --git a/fp-plugins/bbcode/lang/lang.ja-jp.php b/fp-plugins/bbcode/lang/lang.ja-jp.php
index 170bfe08..b6db2a58 100644
--- a/fp-plugins/bbcode/lang/lang.ja-jp.php
+++ b/fp-plugins/bbcode/lang/lang.ja-jp.php
@@ -38,13 +38,13 @@
'expandtitle' => 'テキストエリアの高さを増やします。',
'reduce' => '縮小',
'reducetitle' => 'テキストエリアの高さを減らします。',
- 'urltitle' => 'URL/リンク',
+ 'urltitle' => 'URL/リンク (Ctrl+K / ⌘K)',
'mailtitle' => 'Eメールアドレス',
- 'boldtitle' => 'ボールド体',
- 'italictitle' => 'イタリック体',
+ 'boldtitle' => 'ボールド体 (Ctrl+B / ⌘B)',
+ 'italictitle' => 'イタリック体 (Ctrl+I / ⌘I)',
'headlinetitle' => '見出し',
'fonttitle' => 'フォント',
- 'underlinetitle' => '下線',
+ 'underlinetitle' => '下線 (Ctrl+U / ⌘U)',
'crossouttitle' => '取り消し線',
'unorderedlisttitle' => '順序なしリスト',
'orderedlisttitle' => '順序付きリスト',
diff --git a/fp-plugins/bbcode/lang/lang.nl-nl.php b/fp-plugins/bbcode/lang/lang.nl-nl.php
index ebaa06a0..8b3e2f01 100644
--- a/fp-plugins/bbcode/lang/lang.nl-nl.php
+++ b/fp-plugins/bbcode/lang/lang.nl-nl.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Breid hoogte Textgebied uit',
'reduce' => 'Verminder',
'reducetitle' => 'Verminder hoogte Textgebied',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Ctrl+K / ⌘K)',
'mailtitle' => 'E-mailadres',
- 'boldtitle' => 'Bold',
- 'italictitle' => 'Italic',
+ 'boldtitle' => 'Bold (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Italic (Ctrl+I / ⌘I)',
'headlinetitle' => 'Rubriek',
'fonttitle' => 'Lettertype',
- 'underlinetitle' => 'Underlined',
+ 'underlinetitle' => 'Underlined (Ctrl+U / ⌘U)',
'crossouttitle' => 'Doorgestreept',
'unorderedlisttitle' => 'Ongesorteerde lijst',
'orderedlisttitle' => 'Gesorteerde lijst',
diff --git a/fp-plugins/bbcode/lang/lang.pt-br.php b/fp-plugins/bbcode/lang/lang.pt-br.php
index 51385ef7..70bee8f4 100644
--- a/fp-plugins/bbcode/lang/lang.pt-br.php
+++ b/fp-plugins/bbcode/lang/lang.pt-br.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Expandir altura da área de texto',
'reduce' => 'Reduzir',
'reducetitle' => 'Reduzir altura da área de texto',
- 'urltitle' => 'URL/ Link',
+ 'urltitle' => 'URL/ Link (Ctrl+K / ⌘K)',
'mailtitle' => 'Endereço de e-mail',
- 'boldtitle' => 'Negrito',
- 'italictitle' => 'Itálico',
+ 'boldtitle' => 'Negrito (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Itálico (Ctrl+I / ⌘I)',
'headlinetitle' => 'Título',
'fonttitle' => 'Fonte',
- 'underlinetitle' => 'Sublinhado',
+ 'underlinetitle' => 'Sublinhado (Ctrl+U / ⌘U)',
'crossouttitle' => 'Riscado',
'unorderedlisttitle' => 'Lista não classificada',
'orderedlisttitle' => 'Lista ordenada',
diff --git a/fp-plugins/bbcode/lang/lang.ru-ru.php b/fp-plugins/bbcode/lang/lang.ru-ru.php
index 0b064e76..6d3e0a90 100644
--- a/fp-plugins/bbcode/lang/lang.ru-ru.php
+++ b/fp-plugins/bbcode/lang/lang.ru-ru.php
@@ -37,13 +37,13 @@
'expandtitle' => 'Увеличить высоту текстовой области',
'reduce' => 'Уменьшить',
'reducetitle' => 'Уменьшить высоту текстовой области',
- 'urltitle' => 'URL/Ссылка',
+ 'urltitle' => 'URL/Ссылка (Ctrl+K / ⌘K)',
'mailtitle' => 'Адрес электронной почты',
- 'boldtitle' => 'Жирный',
- 'italictitle' => 'Курсив',
+ 'boldtitle' => 'Жирный (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Курсив (Ctrl+I / ⌘I)',
'headlinetitle' => 'Направление',
'fonttitle' => 'шрифт',
- 'underlinetitle' => 'Подчеркнутый',
+ 'underlinetitle' => 'Подчеркнутый (Ctrl+U / ⌘U)',
'crossouttitle' => 'Зачеркнуто',
'unorderedlisttitle' => 'Неотсортированный список',
'orderedlisttitle' => 'Сортированный список',
diff --git a/fp-plugins/bbcode/lang/lang.sl-si.php b/fp-plugins/bbcode/lang/lang.sl-si.php
index d3c86865..fa9911ce 100644
--- a/fp-plugins/bbcode/lang/lang.sl-si.php
+++ b/fp-plugins/bbcode/lang/lang.sl-si.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Razširi višino polja za besedilo',
'reduce' => 'Skrči',
'reducetitle' => 'Skrči višino polja za besedilo',
- 'urltitle' => 'URL/povezava',
+ 'urltitle' => 'URL/povezava (Ctrl+K / ⌘K)',
'mailtitle' => 'E-poštni naslov',
- 'boldtitle' => 'Krepko',
- 'italictitle' => 'Ležeče',
+ 'boldtitle' => 'Krepko (Ctrl+B / ⌘B)',
+ 'italictitle' => 'Ležeče (Ctrl+I / ⌘I)',
'headlinetitle' => 'Naslov',
'fonttitle' => 'Pisava',
- 'underlinetitle' => 'Podčrtano',
+ 'underlinetitle' => 'Podčrtano (Ctrl+U / ⌘U)',
'crossouttitle' => 'Prečrtano',
'unorderedlisttitle' => 'Nesortiran seznam',
'orderedlisttitle' => 'Razvrščeni seznam',
diff --git a/fp-plugins/bbcode/lang/lang.tr-tr.php b/fp-plugins/bbcode/lang/lang.tr-tr.php
index 91dc4f25..c8d27718 100644
--- a/fp-plugins/bbcode/lang/lang.tr-tr.php
+++ b/fp-plugins/bbcode/lang/lang.tr-tr.php
@@ -38,13 +38,13 @@
'expandtitle' => 'Metin Alanı Yüksekliğini Genişlet',
'reduce' => 'Küçült',
'reducetitle' => 'Metin Alanı Yüksekliğini Küçült',
- 'urltitle' => 'URL/ Bağlantı',
+ 'urltitle' => 'URL/ Bağlantı (Ctrl+K / ⌘K)',
'mailtitle' => 'E-posta adresi',
- 'boldtitle' => 'Kalın',
- 'italictitle' => 'İtalik',
+ 'boldtitle' => 'Kalın (Ctrl+B / ⌘B)',
+ 'italictitle' => 'İtalik (Ctrl+I / ⌘I)',
'headlinetitle' => 'Başlık',
'fonttitle' => 'Yazı Tipi',
- 'underlinetitle' => 'Altı Çizili',
+ 'underlinetitle' => 'Altı Çizili (Ctrl+U / ⌘U)',
'crossouttitle' => 'Üstü Çizili',
'unorderedlisttitle' => 'Sırasız liste',
'orderedlisttitle' => 'Sıralı liste',
diff --git a/fp-plugins/bbcode/lang/lang.zh-cn.php b/fp-plugins/bbcode/lang/lang.zh-cn.php
index ed092891..f9766ada 100644
--- a/fp-plugins/bbcode/lang/lang.zh-cn.php
+++ b/fp-plugins/bbcode/lang/lang.zh-cn.php
@@ -41,13 +41,13 @@
'expandtitle' => '展开文本区域高度。',
'reduce' => '缩小',
'reducetitle' => '减少文本区域的高度。',
- 'urltitle' => 'URL/链接',
+ 'urltitle' => 'URL/链接 (Ctrl+K / ⌘K)',
'mailtitle' => '电子邮件地址',
- 'boldtitle' => '粗体',
- 'italictitle' => '斜体',
+ 'boldtitle' => '粗体 (Ctrl+B / ⌘B)',
+ 'italictitle' => '斜体 (Ctrl+I / ⌘I)',
'headlinetitle' => '标题',
'fonttitle' => '字体',
- 'underlinetitle' => '下划线',
+ 'underlinetitle' => '下划线 (Ctrl+U / ⌘U)',
'crossouttitle' => '删除线',
'unorderedlisttitle' => '无序列表',
'orderedlisttitle' => '排序列表',
diff --git a/fp-plugins/bbcode/plugin.bbcode.php b/fp-plugins/bbcode/plugin.bbcode.php
index 28d4e067..2576b2c9 100644
--- a/fp-plugins/bbcode/plugin.bbcode.php
+++ b/fp-plugins/bbcode/plugin.bbcode.php
@@ -1,7 +1,7 @@
100) {
+ history.undo.shift();
+ }
+ history.redo = [];
+ }
+ history.current = next;
+}
+
+function bbcodeFallbackUndo(element, redo) {
+ var history = element.bbcodeHistory;
+ if (!history) {
+ return false;
+ }
+ var source = redo ? history.redo : history.undo;
+ var destination = redo ? history.undo : history.redo;
+ if (source.length) {
+ destination.push(bbcodeEditorSnapshot(element));
+ var previous = source.pop();
+ element.value = previous.value;
+ element.setSelectionRange(previous.start, previous.end);
+ history.current = previous;
+ element.dispatchEvent(new Event('input', { bubbles: true }));
+ }
+ return true;
+}
+
+function plugin_bbcode_shortcuts() {
+ var element = document.getElementById('content');
+ if (!element || element.tagName !== 'TEXTAREA' || element.dataset.bbcodeShortcuts) {
+ return;
+ }
+ // This script also loads on pages without the BBCode editor.
+ if (!document.getElementById('bb_b') || !document.getElementById('bb_url')) {
+ return;
+ }
+ element.dataset.bbcodeShortcuts = 'true';
+ element.addEventListener('input', function () {
+ bbcodeRememberFallbackEdit(element);
+ });
+ element.addEventListener('beforeinput', function (event) {
+ if (element.disabled || element.readOnly || event.isComposing || !event.cancelable) {
+ return;
+ }
+ if (element.bbcodeHistory) {
+ element.bbcodeHistory.current = bbcodeEditorSnapshot(element);
+ }
+ if ((event.inputType === 'historyUndo' || event.inputType === 'historyRedo') &&
+ bbcodeFallbackUndo(element, event.inputType === 'historyRedo')) {
+ event.preventDefault();
+ }
+ });
+ element.addEventListener('keydown', function (event) {
+ if (event.defaultPrevented || element.disabled || element.readOnly ||
+ event.isComposing || event.keyCode === 229 || event.altKey ||
+ (event.getModifierState && event.getModifierState('AltGraph')) ||
+ !(event.ctrlKey || event.metaKey) || (event.ctrlKey && event.metaKey)) {
+ return;
}
- element.focus(caretPos);
- } else if (element.selectionStart || element.selectionStart == '0') {
- // MOZILLA
- element.focus();
- var startPos = element.selectionStart;
- var endPos = element.selectionEnd;
- var preTxt = element.value.substring(0, startPos);
- var selTxt = element.value.substring(startPos, endPos) ;
- var follTxt = element.value.substring(endPos, element.value.length);
- var scrollPos = element.scrollTop;
- element.value = preTxt + start + selTxt + end + follTxt;
- if (element.setSelectionRange) {
- if (selTxt.length == 0) {
- element.setSelectionRange(startPos + start.length, startPos + start.length);
- } else {
- element.setSelectionRange(startPos, startPos + start.length + selTxt.length + end.length);
+ var key = (event.key || '').toLowerCase();
+ // Physical key fallback for non-Latin layouts and older keyboards.
+ if (!/^[a-z]$/.test(key)) {
+ key = /^Key[A-Z]$/.test(event.code || '') ? event.code.slice(3).toLowerCase() :
+ String.fromCharCode(event.keyCode || 0).toLowerCase();
+ }
+ if ((key === 'z' || key === 'y') && element.bbcodeHistory) {
+ if (key === 'z' || !event.shiftKey) {
+ event.preventDefault();
+ bbcodeFallbackUndo(element, key === 'y' || event.shiftKey);
}
- element.focus();
+ return;
}
- element.scrollTop = scrollPos;
- } else {
- element.value += start + end;
- }
+ var codes = { b: 'b', i: 'i', u: 'u', k: 'url' };
+ if (event.shiftKey || !Object.prototype.hasOwnProperty.call(codes, key)) {
+ return;
+ }
+ event.preventDefault();
+ if (!event.repeat) {
+ insBBCode(codes[key]);
+ }
+ });
+}
+
+if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', plugin_bbcode_shortcuts);
+} else {
+ plugin_bbcode_shortcuts();
}
// calling the function