This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Added keyboard shortcut plugin. #110
Open
malakada
wants to merge
3
commits into
master
Choose a base branch
from
feature/keyboardshortcuts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (C) 2014 Mojo Lingo LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Keyboard Shortcuts | ||
|
||
A plugin for Candy Chat to allow keyboard shortcuts for interacting with Candy. | ||
|
||
## Usage | ||
|
||
Include the JavaScript file: | ||
|
||
```HTML | ||
<script type="text/javascript" src="candyshop/keyboardshortcuts/keyboardshortcuts.js"></script> | ||
``` | ||
|
||
To enable this plugin, add its `init` method after you `init` Candy, but before `Candy.connect()`: | ||
|
||
```JavaScript | ||
CandyShop.KeyboardShortcuts.init(); | ||
``` | ||
|
||
You could also pass in your own keyboard shortcuts: | ||
|
||
```JavaScript | ||
var options = { | ||
uniqueShortcutName: { | ||
altKey: (boolean), | ||
ctrlKey: (boolean), | ||
shiftKey: (boolean), | ||
keyCode: (integer) | ||
} | ||
} | ||
``` | ||
|
||
The plugin will then match the name of the `uniqueShortcutName` provided as the key to an identically named function inside itself, so you'll need to add a matching function inside the plugin itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** File: autojoininvites.js | ||
* Candy Plugin Keyboard Shortcuts | ||
* Author: Melissa Adamaitis <[email protected]> | ||
*/ | ||
|
||
var CandyShop = (function(self) { return self; }(CandyShop || {})); | ||
|
||
CandyShop.KeyboardShortcuts = (function(self, Candy, $) { | ||
/** Object: _options | ||
* Options for this plugin's operation | ||
* | ||
* Options: | ||
* (Boolean) notifyNormalMessage - Notification on normalmessage. Defaults to false | ||
* (Boolean) notifyPersonalMessage - Notification for private messages. Defaults to true | ||
* (Boolean) notifyMention - Notification for mentions. Defaults to true | ||
* (Integer) closeTime - Time until closing the Notification. (0 = Don't close) Defaults to 3000 | ||
* (String) title - Title to be used in notification popup. Set to null to use the contact's name. | ||
* (String) icon - Path to use for image/icon for notification popup. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This options block from what I think is notifyMe plugin doesn't really sound right here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was so sure I had removed that already. Weird. Thanks. |
||
*/ | ||
var _options = { | ||
joinNewRoom: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 78 // 'n' | ||
}, | ||
toggleSound: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 83 // 's' | ||
}, | ||
changeTopic: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 84 // 't' | ||
}, | ||
closeCurrentTab: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 87 // 'w' | ||
}, | ||
nextTab: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 40 // down arrow | ||
}, | ||
previousTab: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 38 // up arrow | ||
}, | ||
helpScreen: { | ||
altKey: true, | ||
ctrlKey: false, | ||
shiftKey: false, | ||
keyCode: 191 // '/' | ||
} | ||
}; | ||
|
||
/** Object: about | ||
* | ||
* Contains: | ||
* (String) name - Candy Plugin Keyboard Shortcuts | ||
* (Float) version - Candy Plugin Keyboard Shortcuts | ||
*/ | ||
self.about = { | ||
name: 'Candy Plugin Keyboard Shortcuts', | ||
version: '1.0' | ||
}; | ||
|
||
/** | ||
* Initializes the KeyboardShortcuts plugin with the default settings. | ||
*/ | ||
self.init = function(options){ | ||
// apply the supplied options to the defaults specified | ||
$.extend(true, _options, options); | ||
|
||
$(window).keydown(function(ev) { | ||
var keystrokes = { | ||
altKey: ev.altKey, | ||
ctrlKey: ev.ctrlKey, | ||
shiftKey: ev.shiftKey, | ||
keyCode: ev.keyCode | ||
}; | ||
for (var option in _options) { | ||
if (self.isEquivalent(_options[option], keystrokes)) { | ||
window['CandyShop']['KeyboardShortcuts'][option](); | ||
ev.preventDefault(); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
self.closeCurrentTab = function() { | ||
Candy.View.Pane.Room.close(Candy.View.getCurrent().roomJid); | ||
}; | ||
|
||
self.joinNewRoom = function() { | ||
CandyShop.CreateRoom.showModal(); | ||
}; | ||
|
||
self.toggleSound = function() { | ||
Candy.View.Pane.Chat.Toolbar.onSoundControlClick(); | ||
}; | ||
|
||
self.changeTopic = function() { | ||
var currentJid = Candy.View.getCurrent().roomJid, | ||
element = Candy.View.Pane.Room.getPane(Candy.View.getCurrent().roomJid), | ||
currentTopic = element.find('.roombar .topic').html(); | ||
CandyShop.RoomBar.updateRoomTopic(currentJid, $(element).attr('id'), currentTopic); | ||
}; | ||
|
||
self.nextTab = function() { | ||
this.showPane('+1'); | ||
}; | ||
|
||
self.previousTab = function() { | ||
this.showPane('-1'); | ||
}; | ||
|
||
self.helpScreen = function() { | ||
var html = "<h4>Keyboard Shortcuts</h4><ul><li><h6>Join new room:</h6> alt/option + n</li>" + | ||
"<li><h6>Toggle sound:</h6> alt/option + s</li><li><h6>Change topic:</h6> alt/option + t</li>" + | ||
"<li><h6>Close current tab:</h6> alt/option + w</li><li><h6>Next tab:</h6> alt/option + down arrow</li>" + | ||
"<li><h6>Previous tab:</h6> alt/option + up arrow</li><li><h6>Help screen:</h6> alt/option + ?</li></ul>"; | ||
Candy.View.Pane.Chat.Modal.show(html, true, false); | ||
}; | ||
|
||
// Used to find and show room pane relative to current. | ||
self.showPane = function(number) { | ||
var rooms = Candy.Core.getRooms(), | ||
room_names = Object.keys(rooms); | ||
|
||
// Push the lobby to the front of the room_names. | ||
room_names.unshift(CandyShop.StaticLobby.getLobbyFakeJid()); | ||
|
||
var currentIndex = room_names.indexOf(Candy.View.getCurrent().roomJid), | ||
newIndex = currentIndex; | ||
|
||
if (number === '+1') { | ||
if ((currentIndex + 1) < room_names.length) { | ||
newIndex = currentIndex + 1; | ||
} else { | ||
newIndex = 0; | ||
} | ||
} else if (number === '-1') { | ||
if ((currentIndex - 1) >= 0) { | ||
newIndex = currentIndex - 1; | ||
} else { | ||
newIndex = room_names.length - 1; | ||
} | ||
} else { | ||
newIndex = number; | ||
} | ||
|
||
Candy.View.Pane.Room.show(room_names[newIndex]); | ||
}; | ||
|
||
// Used to help JavaScript determine if two objects are identical. | ||
self.isEquivalent = function(a, b) { | ||
// Create arrays of property names | ||
var aProps = Object.getOwnPropertyNames(a), | ||
bProps = Object.getOwnPropertyNames(b); | ||
|
||
// If number of properties is different, objects are not equivalent | ||
if (aProps.length !== bProps.length) { | ||
return false; | ||
} | ||
|
||
for (var i = 0; i < aProps.length; i++) { | ||
var propName = aProps[i]; | ||
|
||
// If values of same property are not equal, objects are not equivalent | ||
if (a[propName] !== b[propName]) { | ||
return false; | ||
} | ||
} | ||
|
||
// If we made it this far, objects are considered equivalent | ||
return true; | ||
}; | ||
|
||
return self; | ||
}(CandyShop.KeyboardShortcuts || {}, Candy, jQuery)); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autojoininvites header doesn't really sound right here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAHAHAHAHA.
Agreed. :)