UNPKG

platform-project

Version:

平台项目

56 lines (53 loc) 1.52 kB
function MultiSelect(options) { this.node = options.node; this.group = this.node.find('.group'); this.callback = options.callback; } MultiSelect.prototype = { constructor: MultiSelect, trigger: function () { if (!this.node || !this.node.length) { return; } this.bindEvent(); }, bindEvent: function () { var _this = this; // _this.node.on('click', _this.handleClickNode()); _this.group.on('click', 'a', _this.handleClickItem()); _this.group.hover(function () { _this.isEnter = true; }, function () { _this.isEnter = false; }); _this.node.hover(function () { _this.node.toggleClass('on'); }, function () { if (_this.isEnter) { return; } _this.node.toggleClass('on'); }); }, handleClickItem: function(){ var _this = this; return function (e) { e.stopPropagation(); var $li = $(this).parent(); $li.toggleClass('selected'); if (_this.callback) { _this.callback($li); } } } } $.fn.multiSelect = function (callback) { if (!$(this).length) { return } $(this).each(function () { new MultiSelect({ node: $(this), callback: callback }).trigger(); }); } module.exports = MultiSelect;