Added shortcut for submit
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 17:19:35 +0000 (19:19 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Aug 2016 17:19:40 +0000 (19:19 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index 5313e6d057e38446c50e2bb51213b7f2f3b4128f..6ec4ffc4ce8622568f9468ac957107a347cce6d5 100644 (file)
@@ -45,6 +45,50 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                
                                return mpOnTab.call(this, e, key);
                        }).bind(this);
+                       
+                       require(['Core', 'Environment'], (function (Core, Environment) {
+                               if (Environment.platform() !== 'desktop') {
+                                       // ignore mobile devices
+                                       return;
+                               }
+                               
+                               var container = this.$editor[0].closest('form, .message');
+                               if (container === null) return;
+                               
+                               var formSubmit = elBySel('.formSubmit', container);
+                               if (formSubmit === null) return;
+                               
+                               var submitButton = elBySel('input[type="submit"], button[data-type="save"], button[accesskey="s"]', formSubmit);
+                               if (submitButton) {
+                                       // remove access key
+                                       submitButton.removeAttribute('accesskey');
+                                       
+                                       // mimic the same behavior which will also work with more
+                                       // than one editor instance on the page
+                                       this.WoltLabEvent.register('keydown', (function (data) {
+                                               // 83 = [S]
+                                               if (data.event.which === 83) {
+                                                       var submit = false;
+                                                       
+                                                       if (window.navigator.platform.match(/^Mac/)) {
+                                                               if (data.event.ctrlKey && data.event.altKey) {
+                                                                       submit = true;
+                                                               }
+                                                       }
+                                                       else if (data.event.altKey && !data.event.ctrlKey) {
+                                                               submit = true;
+                                                       }
+                                                       
+                                                       if (submit) {
+                                                               data.cancel = true;
+                                                               
+                                                               Core.triggerEvent(submitButton, WCF_CLICK_EVENT);
+                                                       }
+                                               }
+                                       }).bind(this));
+                               }
+                       }).bind(this));
+                       
                },
                
                register: function (tag) {