DirectChat.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 () {
  25. var box = $(this).parents(Selector.box).first();
  26. box.toggleClass(ClassName.open);
  27. }
  28. // Plugin Definition
  29. // =================
  30. function Plugin(option) {
  31. return this.each(function () {
  32. var $this = $(this)
  33. var data = $this.data(DataKey)
  34. if (!data) {
  35. $this.data(DataKey, (data = new DirectChat($this)))
  36. }
  37. if (typeof option == 'string') data.toggle()
  38. })
  39. }
  40. var old = $.fn.directChat
  41. $.fn.directChat = Plugin
  42. $.fn.directChat.Constructor = DirectChat
  43. // No Conflict Mode
  44. // ================
  45. $.fn.directChat.noConflict = function () {
  46. $.fn.directChat = old
  47. return this
  48. }
  49. // DirectChat Data API
  50. // ===================
  51. $(document).on('click', Selector.data, function (event) {
  52. if (event) event.preventDefault()
  53. Plugin.call($(this), 'toggle')
  54. })
  55. }(jQuery)