Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/MultipleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './utils/index.js'

class MultipleSelect {

constructor ($el, options) {
this.$el = $el
this.options = $.extend({}, Constants.DEFAULTS, options)
Expand All @@ -23,7 +24,7 @@ class MultipleSelect {
this.initFilter()
this.initDrop()
this.initView()
this.options.onAfterCreate()
this.trigger('after-create')
}

initLocale () {
Expand Down Expand Up @@ -246,9 +247,9 @@ class MultipleSelect {

if (!ignoreTrigger) {
if (this.allSelected) {
this.options.onCheckAll()
this.trigger('check-all')
} else if (selectedTotal === 0) {
this.options.onUncheckAll()
this.trigger('uncheck-all')
}
}
}
Expand Down Expand Up @@ -502,8 +503,8 @@ class MultipleSelect {
}

this.$choice.off('click').on('click', toggleOpen)
.off('focus').on('focus', this.options.onFocus)
.off('blur').on('blur', this.options.onBlur)
.off('focus').on('focus', this.trigger('focus'))
.off('blur').on('blur', this.trigger('blur'))

this.$parent.off('keydown').on('keydown', e => {
// esc key
Expand Down Expand Up @@ -560,7 +561,7 @@ class MultipleSelect {
const group = findByParam(this.data, '_key', $this.data('key'))

this._checkGroup(group, checked)
this.options.onOptgroupClick(removeUndefined({
this.trigger('onOptgroupClick', removeUndefined({
label: group.label,
selected: group.selected,
data: group._data,
Expand All @@ -582,7 +583,7 @@ class MultipleSelect {
const option = findByParam(this.data, '_key', $this.data('key'))

this._check(option, checked)
this.options.onClick(removeUndefined({
this.trigger('click', removeUndefined({
text: option.text,
value: option.value,
selected: option.selected,
Expand Down Expand Up @@ -656,7 +657,7 @@ class MultipleSelect {
this.$searchInput.focus()
this.filter(true)
}
this.options.onOpen()
this.trigger('open')
}

close () {
Expand All @@ -671,7 +672,7 @@ class MultipleSelect {
'left': 'auto'
})
}
this.options.onClose()
this.trigger('close')
}

animateMethod (method) {
Expand Down Expand Up @@ -988,7 +989,7 @@ class MultipleSelect {
this.updateSelected()

if (!ignoreTrigger) {
this.options.onFilter(text)
this.trigger('filter', text)
}
}

Expand All @@ -1009,6 +1010,13 @@ class MultipleSelect {
this.fromHtml = false
}
}

trigger (_name, ...args) {
const name = `${_name}.bs.select`

this.options[Constants.EVENTS[name]](...[...args, this])
this.$el.trigger($.Event(name, { sender: this }), args)
}
}

export default MultipleSelect
15 changes: 15 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ const METHODS = [
'refresh', 'destroy'
]

const EVENTS = {
'open.bs.select': 'onOpen',
'close.bs.select': 'onClose',
'check-all.bs.select': 'onCheckAll',
'uncheck-all.bs.select': 'onUncheckAll',
'focus.bs.select': 'onFocus',
'blur.bs.select': 'onBlur',
'opt-group-click.bs.select': 'onOptgroupClick',
'click.bs.select': 'onClick',
'filter.bs.select': 'onFilter',
'after-create.bs.select': 'onAfterCreate',
}

Object.assign(DEFAULTS, EN)

const Constants = {
Expand All @@ -128,6 +141,8 @@ const Constants = {

METHODS,

EVENTS,

LOCALES: {
en: EN,
'en-US': EN
Expand Down