AdminLTE/build/js/DirectChat.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-03-04 18:13:04 +01:00
/* DirectChat()
* ===============
* Toggles the state of the control sidebar
*
2017-03-04 18:20:23 +01:00
* @Usage: $('#my-chat-box').directChat()
2017-03-04 18:13:04 +01:00
* or add [data-widget="direct-chat"] to the trigger
*/
+function ($) {
2017-10-26 22:53:11 +02:00
'use strict';
2017-03-04 18:13:04 +01:00
2017-10-26 22:53:11 +02:00
var DataKey = 'lte.directchat';
2017-03-04 18:13:04 +01:00
var Selector = {
data: '[data-widget="chat-pane-toggle"]',
box : '.direct-chat'
2017-10-26 22:53:11 +02:00
};
2017-03-04 18:13:04 +01:00
var ClassName = {
open: 'direct-chat-contacts-open'
2017-10-26 22:53:11 +02:00
};
2017-03-04 18:13:04 +01:00
// DirectChat Class Definition
// ===========================
var DirectChat = function (element) {
2017-10-26 22:53:11 +02:00
this.element = element;
};
2017-03-04 18:13:04 +01:00
2017-03-04 18:19:22 +01:00
DirectChat.prototype.toggle = function ($trigger) {
2017-10-26 22:53:11 +02:00
$trigger.parents(Selector.box).first().toggleClass(ClassName.open);
};
2017-03-04 18:13:04 +01:00
// Plugin Definition
// =================
function Plugin(option) {
return this.each(function () {
2017-10-26 22:53:11 +02:00
var $this = $(this);
var data = $this.data(DataKey);
2017-03-04 18:13:04 +01:00
if (!data) {
2017-10-26 22:53:11 +02:00
$this.data(DataKey, (data = new DirectChat($this)));
2017-03-04 18:13:04 +01:00
}
2017-10-26 22:53:11 +02:00
if (typeof option == 'string') data.toggle($this);
});
2017-03-04 18:13:04 +01:00
}
2017-10-26 22:53:11 +02:00
var old = $.fn.directChat;
2017-03-04 18:13:04 +01:00
2017-10-26 22:53:11 +02:00
$.fn.directChat = Plugin;
$.fn.directChat.Constructor = DirectChat;
2017-03-04 18:13:04 +01:00
// No Conflict Mode
// ================
$.fn.directChat.noConflict = function () {
2017-10-26 22:53:11 +02:00
$.fn.directChat = old;
return this;
};
2017-03-04 18:13:04 +01:00
// DirectChat Data API
// ===================
$(document).on('click', Selector.data, function (event) {
2017-10-26 22:53:11 +02:00
if (event) event.preventDefault();
Plugin.call($(this), 'toggle');
});
2017-03-04 18:13:04 +01:00
2017-10-26 22:53:11 +02:00
}(jQuery);