diff --git a/searchroster/LICENSE b/searchroster/LICENSE new file mode 100644 index 0000000..c8d3f9e --- /dev/null +++ b/searchroster/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/searchroster/README.md b/searchroster/README.md new file mode 100644 index 0000000..533e301 --- /dev/null +++ b/searchroster/README.md @@ -0,0 +1,19 @@ +# Search Roster + +A plugin for Candy Chat to allow you to search the roster when using the StaticLobby plugin. + +## Dependencies + +Assumes you're using the StaticLobby plugin. + +## Usage +Include the JavaScript file: +```HTML + +``` + +To enable this plugin, add its `init` method after you `init` Candy: +```JavaScript +CandyShop.SearchRoster.init(); +Candy.connect(); +``` diff --git a/searchroster/searchroster.js b/searchroster/searchroster.js new file mode 100644 index 0000000..3d90da8 --- /dev/null +++ b/searchroster/searchroster.js @@ -0,0 +1,59 @@ +/** File: candy.js + * Candy - Chats are not dead yet. + * + * Authors: + * - Jason Deegan + * + * Copyright: + * (c) 2014 Power Home Remodeling Group. All rights reserved. + */ +var CandyShop = (function(self) { return self; }(CandyShop || {})); + +/** Class: CandyShop.SearchRoster + * Allows for completion of a name in the roster + */ +CandyShop.SearchRoster = (function(self, Candy, $) { + /** String: _selector + * The selector for the visible message box + */ + var _selector = '#search-roster-value'; + + /** String: _clearbtn + * The button for clearing the search input box + */ + var _clearbtn= '#search-roster-value-btn'; + + /** Function: init + * Initialize the SearchRoster plugin + * + * Parameters: + * None + */ + self.init = function() { + // initialize tooltip help + $(_selector).tooltip(); + + // listen for keyup when someone wants to search + $(document).on('keyup', _selector, function() { + var searchCriteria = $(this).val().toLowerCase(); + if (searchCriteria === ''){ + CandyShop.StaticLobby.GlobalRoster.Display(); + return; + } + $('.user').hide(); + $('.user').filter(function(i,el){ + return $(el).data('nick').toLowerCase().indexOf(searchCriteria) >= 0 || $(el).data('jid').toLowerCase().indexOf(searchCriteria) >= 0; + }).show(); + }); + + // on search 'Clear' button press do: Show all users, clear search field and give search field focus + $(document).on('click', _clearbtn, function() { + $('.user').show(); + $(this).closest('div').find( 'input' ).val(''); + $(this).closest('div').find( 'input' ).focus(); + CandyShop.StaticLobby.GlobalRoster.Display(); + }); + }; + + return self; +}(CandyShop.NameComplete || {}, Candy, jQuery));