Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Add functionality from a private repo #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions favicon/candy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/** File: favicon.js
* Candy Plugin Favicon Notifier
* Author: John Rose <john.rose@powerhrg.com>
*
* Show a different favicon when there are unread notifications
*/

var CandyShop = (function(self) { return self; }(CandyShop || {}));

CandyShop.Favicon = (function(self, Candy, $) {

self.about = {
name: 'Candy Favicon Plugin',
version: '1.0'
};

self.init = function(){
self.$favicon = $('link[rel="shortcut icon"]');
self.standardFaviconUrl = self.$favicon.attr("href");
self.notificationsFaviconUrl = "/ui/favicons/favicon-notification-pending.ico";
self.faviconInterval = null;
self.maxBlinks = 5;
self.currentBlinks = 0;
self.faviconBlinkMs = 500;

// Override the renderUnreadMessages function in candy.bundle.js
Candy.View.Pane.Window.renderUnreadMessages = function(count) {
window.top.document.title = Candy.View.Template.Window.unreadmessages.replace("{{count}}", count).replace("{{title}}", Candy.View.Pane.Window._plainTitle);
if (count === 0) {
CandyShop.Favicon.clearUnreadMessages();
} else {
CandyShop.Favicon.showNotificationsFavicon();
CandyShop.Favicon.startFaviconBlink();
}
};

// Override the clearUnreadMessages function in candy.bundle.js
Candy.View.Pane.Window.clearUnreadMessages = function(count) {
Candy.View.Pane.Window._unreadMessagesCount = 0;
window.top.document.title = Candy.View.Pane.Window._plainTitle;
CandyShop.Favicon.clearUnreadMessages();
};
};

self.clearUnreadMessages = function() {
CandyShop.Favicon.stopFaviconBlink();
CandyShop.Favicon.showStandardFavicon();
};

self.startFaviconBlink = function() {
var csf = CandyShop.Favicon;
csf.stopFaviconBlink(); // just in case?
csf.currentBlinks = 0;
csf.faviconInterval = window.setInterval(function() { CandyShop.Favicon.faviconBlink(); }, csf.faviconBlinkMs );
};

self.stopFaviconBlink = function() {
window.clearInterval(CandyShop.Favicon.faviconInterval);
};

self.showNotificationsFavicon = function() {
CandyShop.Favicon.$favicon.attr("href", CandyShop.Favicon.notificationsFaviconUrl);
};

self.showStandardFavicon = function() {
CandyShop.Favicon.$favicon.attr("href", CandyShop.Favicon.standardFaviconUrl);
};

self.faviconBlink = function() {
var csf = CandyShop.Favicon;
if (csf.currentBlinks >= csf.maxBlinks) {
csf.showNotificationsFavicon();
csf.stopFaviconBlink();
return;
}
if (csf.$favicon.attr("href") === csf.standardFaviconUrl) {
csf.showNotificationsFavicon();
csf.currentBlinks += 1;
} else {
csf.showStandardFavicon();
}
};

return self;
}(CandyShop.Favicon || {}, Candy, jQuery));
52 changes: 52 additions & 0 deletions grouped-messages/candy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* grouped-messages
* @version 1.0
* @author Ben Klang <bklang@mojolingo.com>
*
* Visually group subsequent messages from the same sender
*/

var CandyShop = (function(self) { return self; }(CandyShop || {}));

CandyShop.GroupedMessages = (function(self, Candy, $) {

/**
* groupDelay: Amount of time (ms) after which subsequent messages should be in a different group. Default: 5 minutes (300,000)
*/
var _options = {
groupDelay: 300000,
};

/** Function: init
* Initializes the grouped-messages plugin with the default settings.
*/
self.init = function(options) {
// Apply the supplied options to the defaults specified
$.extend(true, _options, options);

$(Candy).on('candy:view.message.after-show', handleOnShow);
};

/** Function: handleOnShow
* Each time a message gets displayed, this method checks for possible
* image loaders (created by buildImageLoaderSource).
* If there is one, the image "behind" the loader gets loaded in the
* background. As soon as the image is loaded, the image loader gets
* replaced by proper scaled image.
*
* Parameters:
* (Array) args
*/
var handleOnShow = function(e, args) {
var sender = args.name;
var prev_message = args.element.prev();
var prev_sender = prev_message.attr('data-sender-name');
var prev_timestamp = new Date(prev_message.attr('data-timestamp'));
if (prev_sender === sender && Date.now() - prev_timestamp < _options.groupDelay) {
$(args.element).addClass('grouped');
$(args.element).prev().addClass('grouped-parent');
}
};

return self;
}(CandyShop.GroupedMessages || {}, Candy, jQuery));
238 changes: 238 additions & 0 deletions keyboardshortcuts/candy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
/** File: autojoininvites.js
* Candy Plugin Keyboard Shortcuts
* Author: Melissa Adamaitis <madamei@mojolingo.com>
*
* Optionally uses CandyShop.RoomBar for user invite modal.
*/

var CandyShop = (function(self) { return self; }(CandyShop || {}));

CandyShop.KeyboardShortcuts = (function(self, Candy, $) {
/** Object: self._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.
*/
self._options = {
inviteUserToRoom: {
name: 'Invite a user to the current room',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 73 // 'i'
},
joinNewRoom: {
name: 'Join a new room',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 78 // 'n'
},
toggleSound: {
name: 'Toggle sound',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 83 // 's'
},
changeTopic: {
name: 'Change room topic',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 84 // 't'
},
closeCurrentTab: {
name: 'Close current tab',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 87 // 'w'
},
nextTab: {
name: 'Next tab',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 40, // down arrow
specialKeyDisplay: 'Down Arrow'
},
previousTab: {
name: 'Previous tab',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 38, // up arrow
specialKeyDisplay: 'Up Arrow'
},
helpScreen: {
name: 'Show the help screen',
altKey: true,
ctrlKey: false,
shiftKey: false,
keyCode: 191, // '/'
specialKeyDisplay: '/'
}
};

/** 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, self._options, options);

$(window).keydown(function(ev) {
var keystrokes = {
altKey: ev.altKey,
ctrlKey: ev.ctrlKey,
shiftKey: ev.shiftKey,
keyCode: ev.keyCode
};
for (var option in self._options) {
if (self.isEquivalent(self._options[option], keystrokes)) {
window['CandyShop']['KeyboardShortcuts'][option]();
ev.preventDefault();
}
};
});
};

self.addShortcut = function(name, shortcut) {
self._options[name] = shortcut;
}

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>';

for (var shortcut in self._options) {
shortcut = self._options[shortcut];
var shortcutString = '';

if (shortcut.ctrlKey) {
shortcutString += 'Ctrl + ';
}

if (shortcut.altKey) {
shortcutString += 'Alt/Option + ';
}

if (shortcut.shiftKey) {
shortcutString += 'Shift + ';
}

shortcutString += shortcut.specialKeyDisplay || String.fromCharCode(shortcut.keyCode);

html += Mustache.to_html(self.Template.listItem, {
name: shortcut.name,
shortcut: shortcutString
});

}

html += '</ul>';

Candy.View.Pane.Chat.Modal.show(html, true, false);
};

self.inviteUserToRoom = function() {
// Only show the invite modal if we have access to it via CandyShop.RoomBar and if we are in a groupchat.
if (CandyShop.RoomBar && Candy.Core.getRoom(Candy.View.getCurrent().roomJid)) {
CandyShop.RoomBar.showInviteUsersModal(Candy.View.getCurrent().roomJid);
}
};

// Used to find and show room pane relative to current.
self.showPane = function(number) {
var rooms = Candy.Core.getRooms(),
room_names = Object.keys(rooms);

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(options, incoming) {
// Create arrays of property names
var optionsProps = Object.getOwnPropertyNames(options);

for (var i = 0; i < optionsProps.length; i++) {
var propName = optionsProps[i];

// If values of same property are not equal, objects are not equivalent
if (propName !== 'name' && propName !== 'specialKeyDisplay' && options[propName] !== incoming[propName]) {
return false;
}
}
// If we made it this far, objects are considered equivalent
return true;
};

self.Template = {
listItem: '<li><h5>{{name}}</h5>{{shortcut}}</li>'
};

return self;
}(CandyShop.KeyboardShortcuts || {}, Candy, jQuery));
Loading