;
(function ($) {
'use strict';
function noop() { }
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
// 上次执行时间点
var previous = 0;
if (!options) options = {};
// 延迟执行函数
var later = function () {
// 若设定了开始边界不执行选项,上次执行时间始终为0
previous = options.leading === false ? 0 : new Date().getTime();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = new Date().getTime();
// 首次执行时,如果设定了开始边界不执行选项,将上次执行时间设定为当前时间。
if (!previous && options.leading === false) previous = now;
// 延迟执行时间间隔
var remaining = wait - (now - previous);
context = this;
args = arguments;
// 延迟时间间隔remaining小于等于0,表示上次执行至此所间隔时间已经超过一个时间窗口
// remaining大于时间窗口wait,表示客户端系统时间被调整过
if (remaining <= 0 || remaining > wait) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
//如果延迟执行不存在,且没有设定结尾边界不执行选项
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
}
var isSafari = function () {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') !== -1) {
return ua.indexOf('chrome') > -1 ? false : true;
}
}();
var settings = {
readonly: false,
minCount: 0,
minCountErrorMessage: '',
limitCount: Infinity,
limitCountErrorMessage: '',
input: '',
data: [],
searchable: true,
searchNoData: '
No Results.',
init: noop,
choice: noop,
extendProps: []
};
var KEY_CODE = {
up: 38,
down: 40,
enter: 13
};
var EVENT_SPACE = {
click: 'click.iui-dropdown',
focus: 'focus.iui-dropdown',
keydown: 'keydown.iui-dropdown',
keyup: 'keyup.iui-dropdown'
};
var ALERT_TIMEOUT_PERIOD = 1000;
// 创建模板
function createTemplate() {
var isLabelMode = this.isLabelMode;
var searchable = this.config.searchable;
var templateSearch = searchable ? '' + this.config.input + '' : '';
return isLabelMode ? '{{ul}}
' : '\xD7' + templateSearch + '{{ul}}
';
}
// 小于minCount提示的元素
function minItemsAlert() {
var _dropdown = this;
var _config = _dropdown.config;
var $el = _dropdown.$el;
var $alert = $el.find('.dropdown-minItem-alert');
var alertMessage = _config.minCountErrorMessage;
clearTimeout(_dropdown.itemCountAlertTimer);
if ($alert.length === 0) {
if (!alertMessage) {
alertMessage = '\u6700\u4f4e\u9009\u62e9' + _config.minCount + '\u4E2A';
}
$alert = $('' + alertMessage + '
');
}
$el.append($alert);
_dropdown.itemCountAlertTimer = setTimeout(function () {
$el.find('.dropdown-minItem-alert').remove();
}, ALERT_TIMEOUT_PERIOD);
}
// 超出限制提示
function maxItemAlert() {
var _dropdown = this;
var _config = _dropdown.config;
var $el = _dropdown.$el;
var $alert = $el.find('.dropdown-maxItem-alert');
var alertMessage = _config.limitCountErrorMessage;
clearTimeout(_dropdown.itemLimitAlertTimer);
if ($alert.length === 0) {
if (!alertMessage) {
alertMessage = '\u6700\u591A\u53EF\u9009\u62E9' + _config.limitCount + '\u4E2A';
}
$alert = $('' + alertMessage + '
');
}
$el.append($alert);
_dropdown.itemLimitAlertTimer = setTimeout(function () {
$el.find('.dropdown-maxItem-alert').remove();
}, ALERT_TIMEOUT_PERIOD);
}
// select-option 转 ul-li
function selectToDiv(str) {
var result = str || '';
// 移除select标签
result = result.replace(/', '');
// 移除 optgroup 结束标签
result = result.replace(/<\/optgroup>/gi, '');
result = result.replace(/