From 3d447e43e8616138fe05056751bb638fb33b37d7 Mon Sep 17 00:00:00 2001 From: Hannes Mannerheim Date: Wed, 7 Sep 2016 17:56:29 +0200 Subject: [PATCH] implement #61 --- actions/qvitter.php | 27 +++++++++++++++++++++++++-- actions/qvittersettings.php | 24 ++++++++++++++++++++++-- css/qvitter.css | 4 ++++ doc/de/shortcuts.html | 3 +++ doc/en/shortcuts.html | 3 +++ doc/io/shortcuts.html | 3 +++ doc/nb/shortcuts.html | 3 +++ doc/sv/shortcuts.html | 3 +++ js/misc-functions.js | 8 ++++---- js/qvitter.js | 17 +++++++++++++++++ 10 files changed, 87 insertions(+), 8 deletions(-) diff --git a/actions/qvitter.php b/actions/qvitter.php index 3d93785..a907a86 100644 --- a/actions/qvitter.php +++ b/actions/qvitter.php @@ -374,6 +374,21 @@ class QvitterAction extends ApiAction print 'window.qvitterProfilePrefs = false;'; } } + + // keyboard shortcuts can be disabled + $disable_keyboard_shortcuts = false; + if($logged_in_user) { + try { + $disable_keyboard_shortcuts = Profile_prefs::getData($logged_in_user->getProfile(), 'qvitter', 'disable_keyboard_shortcuts'); + if($disable_keyboard_shortcuts == '1' || $disable_keyboard_shortcuts == 1) { + $disable_keyboard_shortcuts = true; + } + } catch (Exception $e) { + // + } + } + print 'window.disableKeyboardShortcuts = '.var_export($disable_keyboard_shortcuts, true).';'; + ?> // available language files and their last update time @@ -485,8 +500,16 @@ class QvitterAction extends ApiAction
  • -
  • - + '; + } + else { + print '
  • '; + } + + if (common_config('invite', 'enabled') && !common_config('site', 'closed')) { ?>
  • diff --git a/actions/qvittersettings.php b/actions/qvittersettings.php index 6ab35b9..a3ee5a9 100644 --- a/actions/qvittersettings.php +++ b/actions/qvittersettings.php @@ -93,7 +93,13 @@ class QvitterSettingsAction extends SettingsAction $hide_replies_prefs = false; } - $form = new QvitterPrefsForm($this, $disable_enable_prefs, $hide_replies_prefs); + try { + $disable_keyboard_shortcuts = Profile_prefs::getData($user->getProfile(), 'qvitter', 'disable_keyboard_shortcuts'); + } catch (NoResultException $e) { + $disable_keyboard_shortcuts = false; + } + + $form = new QvitterPrefsForm($this, $disable_enable_prefs, $hide_replies_prefs, $disable_keyboard_shortcuts); $form->show(); } @@ -119,6 +125,8 @@ class QvitterSettingsAction extends SettingsAction Profile_prefs::setData($user->getProfile(), 'qvitter', 'hide_replies', $this->boolean('hide_replies')); + Profile_prefs::setData($user->getProfile(), 'qvitter', 'disable_keyboard_shortcuts', $this->boolean('disable_keyboard_shortcuts')); + // TRANS: Confirmation shown when user profile settings are saved. $this->showForm(_('Settings saved.'), true); @@ -130,12 +138,14 @@ class QvitterPrefsForm extends Form { var $disable_enable_prefs; var $hide_replies_prefs; + var $disable_keyboard_shortcuts; - function __construct($out, $disable_enable_prefs, $hide_replies_prefs) + function __construct($out, $disable_enable_prefs, $hide_replies_prefs, $disable_keyboard_shortcuts) { parent::__construct($out); $this->disable_enable_prefs = $disable_enable_prefs; $this->hide_replies_prefs = $hide_replies_prefs; + $this->disable_keyboard_shortcuts = $disable_keyboard_shortcuts; } /** @@ -177,6 +187,16 @@ class QvitterPrefsForm extends Form $this->elementEnd('li'); $this->elementEnd('ul'); $this->elementEnd('fieldset'); + + $this->elementStart('fieldset'); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('disable_keyboard_shortcuts', + _('Disable keyboard shortcuts'), + (!empty($this->disable_keyboard_shortcuts))); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); } /** diff --git a/css/qvitter.css b/css/qvitter.css index 5a25c03..0c26c85 100644 --- a/css/qvitter.css +++ b/css/qvitter.css @@ -5343,6 +5343,10 @@ content:"\f068"; /* Keyboard shortcuts -----------*/ +#shortcuts-link.disabled { + color:#eee; + } + #popup-shortcuts #shortcuts-container { padding:0 20px 20px 20px; font-size:13px; diff --git a/doc/de/shortcuts.html b/doc/de/shortcuts.html index 0c9715a..3e157e4 100644 --- a/doc/de/shortcuts.html +++ b/doc/de/shortcuts.html @@ -11,3 +11,6 @@

    ?Dieses Menu

    jNächster Queet

    kVorheriger Queet

    + +

    Disable

    +

    Keyboard shortcuts can be turned off on the Qvitter settings page.

    diff --git a/doc/en/shortcuts.html b/doc/en/shortcuts.html index afd4ec4..e0067ce 100644 --- a/doc/en/shortcuts.html +++ b/doc/en/shortcuts.html @@ -11,3 +11,6 @@

    ?This menu

    jNext Queet

    kPrevious Queet

    + +

    Disable

    +

    Keyboard shortcuts can be turned off on the Qvitter settings page.

    diff --git a/doc/io/shortcuts.html b/doc/io/shortcuts.html index 62e92a2..9b8689e 100644 --- a/doc/io/shortcuts.html +++ b/doc/io/shortcuts.html @@ -11,3 +11,6 @@

    ?Ica menuo

    jSequanta mesajo

    kPreiranta mesajo

    + +

    Disable

    +

    Keyboard shortcuts can be turned off on the Qvitter settings page.

    diff --git a/doc/nb/shortcuts.html b/doc/nb/shortcuts.html index eac8c0b..636de69 100644 --- a/doc/nb/shortcuts.html +++ b/doc/nb/shortcuts.html @@ -11,3 +11,6 @@

    ?Denne menyen

    jNeste melding

    kForrige melding

    + +

    Disable

    +

    Keyboard shortcuts can be turned off on the Qvitter settings page.

    diff --git a/doc/sv/shortcuts.html b/doc/sv/shortcuts.html index 5065983..326648b 100644 --- a/doc/sv/shortcuts.html +++ b/doc/sv/shortcuts.html @@ -11,3 +11,6 @@

    ?Denna meny

    jNästa qvitter

    kFöregående qvitter

    + +

    Stäng av

    +

    Kortkommandon kan avaktiveras på Qvitters inställningssida.

    diff --git a/js/misc-functions.js b/js/misc-functions.js index 9163b5f..730babd 100644 --- a/js/misc-functions.js +++ b/js/misc-functions.js @@ -47,11 +47,11 @@ · · · · · · · · · */ function triggerClickOnInputFile(inputFile) { - if(bowser != 'undefined') { + if(typeof bowser != 'undefined') { var bowserIntVersion = parseInt(bowser.version,10); - if(bowser.chrome != 'undefined' && bowser.chrome === true && bowserIntVersion < 53 - || bowser.opera != 'undefined' && bowser.opera === true && bowserIntVersion < 39 - || bowser.safari != 'undefined' && bowser.safari === true && bowserIntVersion < 9) { + if(typeof bowser.chrome != 'undefined' && bowser.chrome === true && bowserIntVersion < 53 + || typeof bowser.opera != 'undefined' && bowser.opera === true && bowserIntVersion < 39 + || typeof bowser.safari != 'undefined' && bowser.safari === true && bowserIntVersion < 9) { var evt = document.createEvent("HTMLEvents"); evt.initEvent("click", true, true); inputFile[0].dispatchEvent(evt); diff --git a/js/qvitter.js b/js/qvitter.js index 02a4bb2..3db4271 100644 --- a/js/qvitter.js +++ b/js/qvitter.js @@ -3475,6 +3475,12 @@ $('body').on('keyup', 'div.queet-box-syntax', function(e) { // menu $('#shortcuts-link').click(function(){ + + // not if disabled + if($(this).hasClass('disabled')) { + return true; + } + popUpAction('popup-shortcuts', window.sL.keyboardShortcuts,'
    ',false); getDoc('shortcuts',function(html){ $('#shortcuts-container').html(html); @@ -3484,6 +3490,12 @@ $('#shortcuts-link').click(function(){ // send queet on ctrl+enter or ⌘+enter (mac) $('body').on('keydown','.queet-box-syntax',function (e) { + + // do nothing if shortcuts are disabled + if(window.disableKeyboardShortcuts === true) { + return true; + } + if((e.ctrlKey && e.which == 13) || (e.metaKey && e.which == 13)) { e.preventDefault(); @@ -3495,6 +3507,11 @@ $('body').on('keydown','.queet-box-syntax',function (e) { $('body').keyup(function (e) { + // do nothing if shortcuts are disabled + if(window.disableKeyboardShortcuts === true) { + return true; + } + // only if queetbox is blurred, and we're not typing in any input, and we're logged in if($('.queet-box-syntax[contenteditable="true"]').length == 0 && $(":focus").length == 0