From 5dabf844e7ab3bd480821a891b7ff19d4cd93594 Mon Sep 17 00:00:00 2001 From: Melissa Noelle Date: Fri, 22 Aug 2014 19:55:05 -0400 Subject: [PATCH 1/2] Added roomanchors plugin. --- roomanchors/LICENSE | 20 +++++++++ roomanchors/README.md | 15 +++++++ roomanchors/roomanchors.js | 86 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 roomanchors/LICENSE create mode 100644 roomanchors/README.md create mode 100644 roomanchors/roomanchors.js diff --git a/roomanchors/LICENSE b/roomanchors/LICENSE new file mode 100644 index 0000000..c8d3f9e --- /dev/null +++ b/roomanchors/LICENSE @@ -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. diff --git a/roomanchors/README.md b/roomanchors/README.md new file mode 100644 index 0000000..5f12b38 --- /dev/null +++ b/roomanchors/README.md @@ -0,0 +1,15 @@ +# Room Anchors + +A plugin for Candy Chat to create and listen to anchors in the URL for rooms. + +## Usage +Include the JavaScript file: +```HTML + +``` + +To enable this plugin, add its `init` method after you `init` Candy: +```JavaScript +CandyShop.RoomAnchors.init(); +Candy.connect(); +``` diff --git a/roomanchors/roomanchors.js b/roomanchors/roomanchors.js new file mode 100644 index 0000000..515ee13 --- /dev/null +++ b/roomanchors/roomanchors.js @@ -0,0 +1,86 @@ +/** File: roomanchors.js + * Handling for joining rooms when included as part of the chat URL + * + * Authors: + * - Ben Klang + * + * Copyright: + * - (c) 2014 Mojo Lingo LLC. All rights reserved. + */ + +var CandyShop = (function(self) { return self; }(CandyShop || {})); + +CandyShop.RoomAnchors = (function(self, Candy, $) { + /** Object: about + * About RoomAnchors plugin + * + * Contains: + * (String) name - Candy Plugin RoomAnchors + * (Float) version - andy Plugin Available Rooms version + */ + self.about = { + name: 'Candy Plugin RoomAnchors', + version: '0.1.0' + }; + + /** Object: _options + * Options for this plugin's operation + * + * Options: + * (String) conferenceDomain - Domain suffix to be applied to the room name in the anchor + */ + var _options = { + conferenceDomain: null + }; + + /** Function: init + */ + self.init = function(options){ + // apply the supplied options to the defaults specified + $.extend(true, _options, options); + + if (_options.conferenceDomain === '' || _options.conferenceDomain === null) { + throw('You must configure the conference domain.'); + } + + // Ensure we have a leading "@" + if (_options.conferenceDomain.indexOf('@') === -1) { + _options.conferenceDomain = "@" + _options.conferenceDomain; + } + + $(Candy).on('candy:view.connection.status-5', self.refresh); + $(Candy).on('candy:view.connection.status-8', self.refresh); + + $(Candy).on('candy:view.room.after-show', function(ev, data) { + if ( + data.roomJid === CandyShop.StaticLobby.getLobbyFakeJid() || + data.roomJid.indexOf(_options.conferenceDomain) === -1 || // Is not a MUC JID + Strophe.getResourceFromJid(data.roomJid) // Is a MUC-based 1-on-1 + ) { + return false; + } + window.location.hash = '#' + data.roomJid.split('@')[0]; + }); + }; + + self.refresh = function() { + if (window.location.hash !== '') { + // Join, just in case we aren't already + Candy.Core.Action.Jabber.Room.Join(self.roomAnchorJid()); + // Show, just in case we were already in the room + try { + Candy.View.Pane.Room.show(self.roomAnchorJid()); + } catch(ex) { + // This may happen if we attempt to show right after a join, but the join hasn't + // yet finished (a race condition). Ignore it, since the act of joining + // will focus the room. + } + } + }; + + self.roomAnchorJid = function() { + return window.location.hash.substring(1) + _options.conferenceDomain; + }; + + return self; +}(CandyShop.RoomAnchors || {}, Candy, jQuery)); From 0a800ced63f2b9954b5c1b6a505d8def826b7cb3 Mon Sep 17 00:00:00 2001 From: Melissa Noelle Date: Sat, 23 Aug 2014 17:39:03 -0400 Subject: [PATCH 2/2] Updated readme with more specific usage information. --- roomanchors/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roomanchors/README.md b/roomanchors/README.md index 5f12b38..a5d3b51 100644 --- a/roomanchors/README.md +++ b/roomanchors/README.md @@ -13,3 +13,5 @@ To enable this plugin, add its `init` method after you `init` Candy: CandyShop.RoomAnchors.init(); Candy.connect(); ``` + +To use this plugin, simply add the name of a room to the end of the URL, like `mydomain.com/chat#room-name` and it will join that room if it exists or create it if it doesn't. When you change rooms, the name of the room you switch to will autopopulate into the address bar as well.