DirectChat.js 1.5 KB

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