2019-07-28 19:11:54 +00:00
|
|
|
/**
|
|
|
|
* --------------------------------------------
|
|
|
|
* AdminLTE DirectChat.js
|
|
|
|
* License MIT
|
|
|
|
* --------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
import $ from 'jquery'
|
2019-08-19 11:14:56 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
const NAME = 'DirectChat'
|
|
|
|
const DATA_KEY = 'lte.directchat'
|
2020-06-13 07:07:23 +00:00
|
|
|
const EVENT_KEY = `.${DATA_KEY}`
|
2020-06-02 13:23:22 +00:00
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-13 07:07:23 +00:00
|
|
|
const EVENT_TOGGLED = `toggled${EVENT_KEY}`
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
const SELECTOR_DATA_TOGGLE = '[data-widget="chat-pane-toggle"]'
|
|
|
|
const SELECTOR_DIRECT_CHAT = '.direct-chat'
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
const CLASS_NAME_DIRECT_CHAT_OPEN = 'direct-chat-contacts-open'
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
/**
|
|
|
|
* Class Definition
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
class DirectChat {
|
|
|
|
constructor(element) {
|
|
|
|
this._element = element
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle() {
|
2020-06-11 12:34:44 +00:00
|
|
|
$(this._element).parents(SELECTOR_DIRECT_CHAT).first().toggleClass(CLASS_NAME_DIRECT_CHAT_OPEN)
|
|
|
|
$(this._element).trigger($.Event(EVENT_TOGGLED))
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
// Static
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
static _jQueryInterface(config) {
|
|
|
|
return this.each(function () {
|
|
|
|
let data = $(this).data(DATA_KEY)
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
data = new DirectChat($(this))
|
|
|
|
$(this).data(DATA_KEY, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
data[config]()
|
|
|
|
})
|
2019-07-28 19:11:54 +00:00
|
|
|
}
|
2020-06-02 13:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Data Api implementation
|
|
|
|
* ====================================================
|
|
|
|
*/
|
2019-07-28 19:11:54 +00:00
|
|
|
|
2020-06-11 12:34:44 +00:00
|
|
|
$(document).on('click', SELECTOR_DATA_TOGGLE, function (event) {
|
2020-06-02 13:23:22 +00:00
|
|
|
if (event) {
|
|
|
|
event.preventDefault()
|
2019-07-28 19:11:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 13:23:22 +00:00
|
|
|
DirectChat._jQueryInterface.call($(this), 'toggle')
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery API
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
$.fn[NAME] = DirectChat._jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = DirectChat
|
|
|
|
$.fn[NAME].noConflict = function () {
|
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
|
|
return DirectChat._jQueryInterface
|
|
|
|
}
|
2019-07-28 19:11:54 +00:00
|
|
|
|
|
|
|
export default DirectChat
|