DirectChat.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* DirectChat()
  2. * ===============
  3. * Toggles the state of the control sidebar
  4. *
  5. * @Usage: $('#my-chat-box').directChat()
  6. * or add [data-widget="direct-chat"] to the trigger
  7. */
  8. +function ($) {
  9. 'use strict'
  10. var DataKey = 'lte.directchat'
  11. var Selector = {
  12. data: '[data-widget="chat-pane-toggle"]',
  13. box : '.direct-chat'
  14. }
  15. var ClassName = {
  16. open: 'direct-chat-contacts-open'
  17. }
  18. // DirectChat Class Definition
  19. // ===========================
  20. var DirectChat = function (element) {
  21. this.element = element
  22. }
  23. DirectChat.prototype.toggle = function ($trigger) {
  24. $trigger.parents(Selector.box).first().toggleClass(ClassName.open)
  25. }
  26. // Plugin Definition
  27. // =================
  28. function Plugin(option) {
  29. return this.each(function () {
  30. var $this = $(this)
  31. var data = $this.data(DataKey)
  32. if (!data) {
  33. $this.data(DataKey, (data = new DirectChat($this)))
  34. }
  35. if (typeof option == 'string') data.toggle($this)
  36. })
  37. }
  38. var old = $.fn.directChat
  39. $.fn.directChat = Plugin
  40. $.fn.directChat.Constructor = DirectChat
  41. // No Conflict Mode
  42. // ================
  43. $.fn.directChat.noConflict = function () {
  44. $.fn.directChat = old
  45. return this
  46. }
  47. // DirectChat Data API
  48. // ===================
  49. $(document).on('click', Selector.data, function (event) {
  50. if (event) event.preventDefault()
  51. Plugin.call($(this), 'toggle')
  52. })
  53. }(jQuery)