UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1,506 lines (1,193 loc) 90.9 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(1213); /***/ }), /***/ 3: /***/ (function(module, exports) { module.exports = function() { throw new Error("define cannot be used indirect"); }; /***/ }), /***/ 1015: /***/ (function(module, exports) { module.exports = require("./kendo.data"); /***/ }), /***/ 1038: /***/ (function(module, exports) { module.exports = require("./kendo.popup"); /***/ }), /***/ 1213: /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(f, define){ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(1015), __webpack_require__(1038) ], __WEBPACK_AMD_DEFINE_FACTORY__ = (f), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); })(function(){ var __meta__ = { // jshint ignore:line id: "list", name: "List", category: "framework", depends: [ "data", "popup" ], hidden: true }; /*jshint evil: true*/ (function($, undefined) { var kendo = window.kendo, ui = kendo.ui, outerHeight = kendo._outerHeight, percentageUnitsRegex = /^\d+(\.\d+)?%$/i, Widget = ui.Widget, keys = kendo.keys, support = kendo.support, htmlEncode = kendo.htmlEncode, activeElement = kendo._activeElement, outerWidth = kendo._outerWidth, ObservableArray = kendo.data.ObservableArray, ID = "id", CHANGE = "change", FOCUSED = "k-state-focused", HOVER = "k-state-hover", LOADING = "k-i-loading", GROUPHEADER = ".k-group-header", ITEMSELECTOR = ".k-item", LABELIDPART = "_label", OPEN = "open", CLOSE = "close", CASCADE = "cascade", SELECT = "select", SELECTED = "selected", REQUESTSTART = "requestStart", REQUESTEND = "requestEnd", extend = $.extend, proxy = $.proxy, isArray = $.isArray, browser = support.browser, HIDDENCLASS = "k-hidden", WIDTH = "width", isIE = browser.msie, isIE8 = isIE && browser.version < 9, quotRegExp = /"/g, alternativeNames = { "ComboBox": "DropDownList", "DropDownList": "ComboBox" }; var List = kendo.ui.DataBoundWidget.extend({ init: function(element, options) { var that = this, ns = that.ns, id; Widget.fn.init.call(that, element, options); element = that.element; options = that.options; that._isSelect = element.is(SELECT); if (that._isSelect && that.element[0].length) { if (!options.dataSource) { options.dataTextField = options.dataTextField || "text"; options.dataValueField = options.dataValueField || "value"; } } that.ul = $('<ul unselectable="on" class="k-list k-reset"/>') .attr({ tabIndex: -1, "aria-hidden": true }); that.list = $("<div class='k-list-container'/>") .append(that.ul) .on("mousedown" + ns, proxy(that._listMousedown, that)); id = element.attr(ID); if (!id) { id = kendo.guid(); } that.list.attr(ID, id + "-list"); that.ul.attr(ID, id + "_listbox"); if (options.columns && options.columns.length) { that.ul.removeClass("k-list").addClass("k-grid-list"); that._columnsHeader(); } that._header(); that._noData(); that._footer(); that._accessors(); that._initValue(); }, options: { valuePrimitive: false, footerTemplate: "", headerTemplate: "", noDataTemplate: "No data found." }, setOptions: function(options) { Widget.fn.setOptions.call(this, options); if (options && options.enable !== undefined) { options.enabled = options.enable; } if (options.columns && options.columns.length) { this._columnsHeader(); } this._header(); this._noData(); this._footer(); this._renderFooter(); this._renderNoData(); }, focus: function() { this._focused.focus(); }, readonly: function(readonly) { this._editable({ readonly: readonly === undefined ? true : readonly, disable: false }); }, enable: function(enable) { this._editable({ readonly: false, disable: !(enable = enable === undefined ? true : enable) }); }, _header: function() { var list = this; var header = $(list.header); var template = list.options.headerTemplate; this._angularElement(header, "cleanup"); kendo.destroy(header); header.remove(); if (!template) { list.header = null; return; } var headerTemplate = typeof template !== "function" ? kendo.template(template) : template; header = $(headerTemplate({})); list.header = header[0] ? header : null; list.list.prepend(header); this._angularElement(list.header, "compile"); }, _columnsHeader: function() { var list = this; var columnsHeader = $(list.columnsHeader); this._angularElement(columnsHeader, "cleanup"); kendo.destroy(columnsHeader); columnsHeader.remove(); var header = "<div class='k-grid-header'><div class='k-grid-header-wrap'><table>"; var colGroup = "<colgroup>"; var row = "<tr>"; for (var idx = 0; idx < this.options.columns.length; idx++) { var currentColumn = this.options.columns[idx]; var title = currentColumn.title || currentColumn.field || ""; var template = currentColumn.headerTemplate || title; var columnsHeaderTemplate = typeof template !== "function" ? kendo.template(template) : template; var currentWidth = currentColumn.width; var currentWidthInt = parseInt(currentWidth, 10); var widthStyle = ''; if (currentWidth && !isNaN(currentWidthInt)) { widthStyle += "style='width:"; widthStyle += currentWidthInt; widthStyle += percentageUnitsRegex.test(currentWidth) ? "%" : "px"; widthStyle += ";'"; } colGroup += "<col " + widthStyle + "/>"; row += "<th class='k-header'>"; row += columnsHeaderTemplate(currentColumn); row += "</th>"; } colGroup += "</colgroup>"; row += "</tr>"; header += colGroup; header += row; header += "</table></div></div>"; list.columnsHeader = columnsHeader = $(header); list.list.prepend(columnsHeader); this._angularElement(list.columnsHeader, "compile"); }, _noData: function() { var list = this; var noData = $(list.noData); var template = list.options.noDataTemplate; list.angular("cleanup", function() { return { elements: noData }; }); kendo.destroy(noData); noData.remove(); if (!template) { list.noData = null; return; } list.noData = $('<div class="k-nodata" style="display:none"><div></div></div>').appendTo(list.list); list.noDataTemplate = typeof template !== "function" ? kendo.template(template) : template; }, _footer: function() { var list = this; var footer = $(list.footer); var template = list.options.footerTemplate; this._angularElement(footer, "cleanup"); kendo.destroy(footer); footer.remove(); if (!template) { list.footer = null; return; } list.footer = $('<div class="k-footer"></div>').appendTo(list.list); list.footerTemplate = typeof template !== "function" ? kendo.template(template) : template; }, _listOptions: function(options) { var that = this; var currentOptions = that.options; var virtual = currentOptions.virtual; var changeEventOption = {change: proxy(that._listChange, that)}; var listBoundHandler = proxy(that._listBound, that); virtual = typeof virtual === "object" ? virtual : {}; options = $.extend({ autoBind: false, selectable: true, dataSource: that.dataSource, click: proxy(that._click, that), activate: proxy(that._activateItem, that), columns: currentOptions.columns, deactivate: proxy(that._deactivateItem, that), dataBinding: function() { that.trigger("dataBinding"); }, dataBound: listBoundHandler, height: currentOptions.height, dataValueField: currentOptions.dataValueField, dataTextField: currentOptions.dataTextField, groupTemplate: currentOptions.groupTemplate, fixedGroupTemplate: currentOptions.fixedGroupTemplate, template: currentOptions.template }, options, virtual, changeEventOption); if (!options.template) { options.template = "#:" + kendo.expr(options.dataTextField, "data") + "#"; } if (currentOptions.$angular) { options.$angular = currentOptions.$angular; } return options; }, _initList: function() { var that = this; var listOptions = that._listOptions({ selectedItemChange: proxy(that._listChange, that) }); if (!that.options.virtual) { that.listView = new kendo.ui.StaticList(that.ul, listOptions); } else { that.listView = new kendo.ui.VirtualList(that.ul, listOptions); } that.listView.bind("listBound", proxy(that._listBound, that)); that._setListValue(); }, _setListValue: function(value) { value = value || this.options.value; if (value !== undefined) { this.listView.value(value) .done(proxy(this._updateSelectionState, this)); } }, _updateSelectionState: $.noop, _listMousedown: function(e) { if (!this.filterInput || this.filterInput[0] !== e.target) { e.preventDefault(); } }, _isFilterEnabled: function() { var filter = this.options.filter; return filter && filter !== "none"; }, _hideClear: function() { var list = this; if (list._clear) { list._clear.addClass(HIDDENCLASS); } }, _showClear: function() { if (this._clear) { this._clear.removeClass(HIDDENCLASS); } }, _clearValue: function() { this._clearText(); this._accessor(""); this.listView.value([]); if (this._isSelect) { this._customOption = undefined; } if (this._isFilterEnabled() && !this.options.enforceMinLength) { this._filter({word: "", open: false}); if (this.options.highlightFirst) { this.listView.focus(0); } } this._change(); }, _clearText: function() { this.text(""); }, _clearFilter: function() { if (!this.options.virtual) { this.listView.bound(false); } this._filterSource(); }, _filterSource: function(filter, force) { var that = this; var options = that.options; var isMultiColumnFiltering = options.filterFields && filter && filter.logic && filter.filters && filter.filters.length; var dataSource = that.dataSource; var expression = extend({}, dataSource.filter() || {}); var resetPageSettings = filter || (expression.filters && expression.filters.length && !filter); var removed = removeFiltersForField(expression, options.dataTextField); this._clearFilterExpressions(expression); if ((filter || removed) && that.trigger("filtering", { filter: filter })) { return; } var newExpression = { filters: [], logic: "and" }; if (isMultiColumnFiltering) { newExpression.filters.push(filter); } else { this._pushFilterExpression(newExpression, filter); } if (isValidFilterExpr(expression)) { if (newExpression.logic === expression.logic) { newExpression.filters = newExpression.filters.concat(expression.filters); } else { newExpression.filters.push(expression); } } if (that._cascading) { this.listView.setDSFilter(newExpression); } var dataSourceState = extend({}, { page: resetPageSettings ? 1 : dataSource.page(), pageSize: resetPageSettings ? dataSource.options.pageSize : dataSource.pageSize(), sort: dataSource.sort(), filter: dataSource.filter(), group: dataSource.group(), aggregate: dataSource.aggregate() }, { filter: newExpression }); return dataSource[force ? "read" : "query"](dataSource._mergeState(dataSourceState)); }, _pushFilterExpression: function (newExpression, filter) { if (isValidFilterExpr(filter) && filter.value !== "") { newExpression.filters.push(filter); } }, _clearFilterExpressions: function (expression) { if (!expression.filters) { return; } var filtersToRemove; for(var i = 0; i < expression.filters.length; i++) { if ("fromFilter" in expression.filters[i]) { filtersToRemove = i; } } if (!isNaN(filtersToRemove)){ expression.filters.splice(filtersToRemove, 1); } }, _angularElement: function(element, action) { if (!element) { return; } this.angular(action, function() { return { elements: element }; }); }, _renderNoData: function() { var list = this; var noData = list.noData; if (!noData) { return; } this._angularElement(noData, "cleanup"); noData.children(":first").html(list.noDataTemplate({ instance: list })); this._angularElement(noData, "compile"); }, _toggleNoData: function(show) { $(this.noData).toggle(show); }, _toggleHeader: function(show) { var groupHeader = this.listView.content.prev(GROUPHEADER); groupHeader.toggle(show); }, _renderFooter: function() { var list = this; var footer = list.footer; if (!footer) { return; } this._angularElement(footer, "cleanup"); footer.html(list.footerTemplate({ instance: list })); this._angularElement(footer, "compile"); }, _allowOpening: function() { return this.options.noDataTemplate || this.dataSource.flatView().length; }, _initValue: function() { var that = this, value = that.options.value; if (value !== null) { that.element.val(value); } else { value = that._accessor(); that.options.value = value; } that._old = value; }, _ignoreCase: function() { var that = this, model = that.dataSource.reader.model, field; if (model && model.fields) { field = model.fields[that.options.dataTextField]; if (field && field.type && field.type !== "string") { that.options.ignoreCase = false; } } }, _focus: function(candidate) { return this.listView.focus(candidate); }, _filter: function(options) { var that = this; var widgetOptions = that.options; var word = options.word; var filterFields = widgetOptions.filterFields; var field = widgetOptions.dataTextField; var expression; if (filterFields && filterFields.length) { expression = { logic: "or", filters: [], fromFilter: true }; for(var i = 0; i < filterFields.length; i++) { this._pushFilterExpression(expression, that._buildExpression(word, filterFields[i])); } } else { expression = that._buildExpression(word, field); } that._open = options.open; that._filterSource(expression); }, _buildExpression: function(value, field) { var that = this; var widgetOptions = that.options; var ignoreCase = widgetOptions.ignoreCase; var accentFoldingFiltering = that.dataSource.options.accentFoldingFiltering; return { value: ignoreCase ? (accentFoldingFiltering ? value.toLocaleLowerCase(accentFoldingFiltering) : value.toLowerCase()) : value, field: field, operator: widgetOptions.filter, ignoreCase: ignoreCase }; }, _clearButton: function() { var list = this; var clearTitle = (list.options.messages && list.options.messages.clear) ? list.options.messages.clear: "clear"; if (!list._clear){ list._clear = $('<span unselectable="on" class="k-icon k-clear-value k-i-close" title="' + clearTitle + '"></span>').attr({ "role": "button", "tabIndex": -1 }); } if (!list.options.clearButton) { list._clear.remove(); } this._hideClear(); }, search: function(word) { var options = this.options; word = typeof word === "string" ? word : this._inputValue(); clearTimeout(this._typingTimeout); if ((!options.enforceMinLength && !word.length) || word.length >= options.minLength) { this._state = "filter"; if (this.listView){ this.listView._emptySearch = !$.trim(word).length; } if (!this._isFilterEnabled()) { this._searchByWord(word); } else { this._filter({word: word, open: true}); } } }, current: function(candidate) { return this._focus(candidate); }, items: function() { return this.ul[0].children; }, destroy: function() { var that = this; var ns = that.ns; Widget.fn.destroy.call(that); that._unbindDataSource(); that.listView.destroy(); that.list.off(ns); that.popup.destroy(); if (that._form) { that._form.off("reset", that._resetHandler); } }, dataItem: function(index) { var that = this; if (index === undefined) { return that.listView.selectedDataItems()[0]; } if (typeof index !== "number") { if (that.options.virtual) { return that.dataSource.getByUid($(index).data("uid")); } index = $(that.items()).index(index); } return that.dataSource.flatView()[index]; }, _activateItem: function() { var current = this.listView.focus(); if (current) { this._focused.add(this.filterInput).attr("aria-activedescendant", current.attr("id")); } }, _deactivateItem: function() { this._focused.add(this.filterInput).removeAttr("aria-activedescendant"); }, _accessors: function() { var that = this; var element = that.element; var options = that.options; var getter = kendo.getter; var textField = element.attr(kendo.attr("text-field")); var valueField = element.attr(kendo.attr("value-field")); if (!options.dataTextField && textField) { options.dataTextField = textField; } if (!options.dataValueField && valueField) { options.dataValueField = valueField; } that._text = getter(options.dataTextField); that._value = getter(options.dataValueField); }, _aria: function(id) { var that = this, options = that.options, element = that._focused.add(that.filterInput); if (options.suggest !== undefined) { element.attr("aria-autocomplete", options.suggest ? "both" : "list"); } id = id ? id + " " + that.ul[0].id : that.ul[0].id; element.attr("aria-owns", id); that.ul.attr("aria-live", !that._isFilterEnabled() ? "off" : "polite"); that._ariaLabel(); }, _ariaLabel: function(){ var that = this; var focusedElm = that._focused; var inputElm = that.element; var inputId = inputElm.attr("id"); var labelElm = $("label[for=\"" + inputId + "\"]"); var ariaLabel = inputElm.attr("aria-label"); var ariaLabelledBy = inputElm.attr("aria-labelledby"); if (focusedElm === inputElm) { return; } if (ariaLabel) { focusedElm.attr("aria-label", ariaLabel); } else if (ariaLabelledBy){ focusedElm.attr("aria-labelledby", ariaLabelledBy); } else if (labelElm.length){ var labelId = labelElm.attr("id") || that._generateLabelId(labelElm, inputId || kendo.guid()); focusedElm.attr("aria-labelledby", labelId); } }, _generateLabelId: function(label, inputId){ var labelId = inputId + LABELIDPART; label.attr("id", labelId); return labelId; }, _blur: function() { var that = this; that._change(); that.close(); }, _change: function() { var that = this; var index = that.selectedIndex; var optionValue = that.options.value; var value = that.value(); var trigger; if (that._isSelect && !that.listView.bound() && optionValue) { value = optionValue; } if (value !== unifyType(that._old, typeof value) && value !== unifyType(that._oldText, typeof value)) { // _oldText should be compared for ComboBox when arbitrary text is added https://github.com/telerik/kendo-ui-core/issues/4496 trigger = true; } else if (that._valueBeforeCascade !== undefined && that._valueBeforeCascade !== unifyType(that._old, typeof that._valueBeforeCascade) && that._userTriggered) { trigger = true; } else if (index !== undefined && index !== that._oldIndex && !that.listView.isFiltered()) { trigger = true; } if (trigger) { if (that._old === null || that._old === "" || value === "") { that._valueBeforeCascade = that._old = value; } else { if (that.dataItem()) { that._valueBeforeCascade = that._old = that.options.dataValueField ? that.dataItem()[that.options.dataValueField] : that.dataItem(); } else { that._valueBeforeCascade = that._old = null; } } that._oldIndex = index; // _oldText should be compared for ComboBox when arbitrary text is added https://github.com/telerik/kendo-ui-core/issues/4496 that._oldText = that.text && that.text(); if (!that._typing) { // trigger the DOM change event so any subscriber gets notified that.element.trigger(CHANGE); } that.trigger(CHANGE); } that.typing = false; }, _data: function() { return this.dataSource.view(); }, _enable: function() { var that = this, options = that.options, disabled = that.element.is("[disabled]"); if (options.enable !== undefined) { options.enabled = options.enable; } if (!options.enabled || disabled) { that.enable(false); } else { that.readonly(that.element.is("[readonly]")); } }, _dataValue: function(dataItem) { var value = this._value(dataItem); if (value === undefined) { value = this._text(dataItem); } return value; }, _offsetHeight: function() { var offsetHeight = 0; var siblings = this.listView.content.prevAll(":visible"); siblings.each(function() { var element = $(this); offsetHeight += outerHeight(element, true); }); return offsetHeight; }, _height: function(length) { var that = this; var list = that.list; var height = that.options.height; var visible = that.popup.visible(); var offsetTop; var popups; var footerHeight; if (length || that.options.noDataTemplate) { popups = list.add(list.parent(".k-animation-container")).show(); if (!list.is(":visible")) { popups.hide(); return; } height = that.listView.content[0].scrollHeight > height ? height : "auto"; popups.height(height); if (height !== "auto") { offsetTop = that._offsetHeight(); footerHeight = outerHeight($(that.footer)) || 0; height = height - offsetTop - footerHeight; } that.listView.content.height(height); if (!visible) { popups.hide(); } } return height; }, _openHandler: function(e) { this._adjustListWidth(); if (this.trigger(OPEN)) { e.preventDefault(); } else { this._focused.attr("aria-expanded", true); this.ul.attr("aria-hidden", false); } }, _adjustListWidth: function() { var that = this, list = that.list, width = list[0].style.width, wrapper = that.wrapper, computedStyle, computedWidth; if (!list.data(WIDTH) && width) { return; } computedStyle = window.getComputedStyle ? window.getComputedStyle(wrapper[0], null) : 0; computedWidth = parseFloat(computedStyle && computedStyle.width) || outerWidth(wrapper); if (computedStyle && browser.msie) { // getComputedStyle returns different box in IE. computedWidth += parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight) + parseFloat(computedStyle.borderLeftWidth) + parseFloat(computedStyle.borderRightWidth); } if (list.css("box-sizing") !== "border-box") { width = computedWidth - (outerWidth(list) - list.width()); } else { width = computedWidth; } list.css({ fontFamily: wrapper.css("font-family"), width: that.options.autoWidth ? "auto" : width, minWidth: width, whiteSpace: that.options.autoWidth ? "nowrap" : "normal" }) .data(WIDTH, width); return true; }, _closeHandler: function(e) { if (this.trigger(CLOSE)) { e.preventDefault(); } else { this._focused.attr("aria-expanded", false); this.ul.attr("aria-hidden", true); } }, _focusItem: function() { var listView = this.listView; var noFocusedItem = !listView.focus(); var index = last(listView.select()); if (index === undefined && this.options.highlightFirst && noFocusedItem) { index = 0; } if (index !== undefined) { listView.focus(index); } else if (noFocusedItem) { listView.scrollToIndex(0); } }, _calculateGroupPadding: function(height) { var li = this.ul.children(".k-first:first"); var groupHeader = this.listView.content.prev(GROUPHEADER); var padding = 0; var direction = 'right'; if (groupHeader[0] && groupHeader[0].style.display !== "none") { if (height !== "auto") { padding = kendo.support.scrollbar(); } if(this.element.parents('.k-rtl').length) { direction = 'left'; } padding += parseFloat(li.css("border-" + direction + "-width"), 10) + parseFloat(li.children(".k-group").css("padding-" + direction), 10); groupHeader.css("padding-" + direction, padding); } }, _calculatePopupHeight: function(force) { var height = this._height(this.dataSource.flatView().length || force); this._calculateGroupPadding(height); this._calculateColumnsHeaderPadding(height); }, _calculateColumnsHeaderPadding: function(height){ if (this.options.columns && this.options.columns.length) { var list = this; var isRtl = support.isRtl(list.wrapper); var scrollbar = kendo.support.scrollbar(); list.columnsHeader.css((isRtl ? "padding-left" : "padding-right"), height !== "auto" ? scrollbar : 0); } }, _refreshScroll: function () { var listView = this.listView; var enableYScroll = listView.element.height() > listView.content.height(); if (this.options.autoWidth) { listView.content.css({ overflowX: "hidden", overflowY: enableYScroll ? "scroll" : "auto" }); } }, _resizePopup: function(force) { if (this.options.virtual) { return; } if (!this.popup.element.is(":visible")) { this.popup.one("open", (function(force) { return proxy(function() { this._calculatePopupHeight(force); }, this); }).call(this, force)); this.popup.one("activate", proxy(this._refreshScroll, this)); } else { this._calculatePopupHeight(force); } }, _popup: function() { var list = this; list.popup = new ui.Popup(list.list, extend({}, list.options.popup, { anchor: list.wrapper, open: proxy(list._openHandler, list), close: proxy(list._closeHandler, list), animation: list.options.animation, isRtl: support.isRtl(list.wrapper), autosize :list.options.autoWidth })); }, _makeUnselectable: function() { if (isIE8) { this.list.find("*").not(".k-textbox").attr("unselectable", "on"); } }, _toggleHover: function(e) { $(e.currentTarget).toggleClass(HOVER, e.type === "mouseenter"); }, _toggle: function(open, preventFocus) { var that = this; var touchEnabled = support.mobileOS && (support.touch || support.MSPointers || support.pointers); open = open !== undefined? open : !that.popup.visible(); if (!preventFocus && !touchEnabled && that._focused[0] !== activeElement()) { that._prevent = true; that._focused.focus(); that._prevent = false; } that[open ? OPEN : CLOSE](); }, _triggerCascade: function() { var that = this; if (!that._cascadeTriggered || that.value() !== unifyType(that._cascadedValue, typeof that.value())) { that._cascadedValue = that.value(); that._cascadeTriggered = true; that.trigger(CASCADE, { userTriggered: that._userTriggered }); } }, _triggerChange: function() { if (this._valueBeforeCascade !== this.value()) { this.trigger(CHANGE); } }, _unbindDataSource: function() { var that = this; that.dataSource.unbind(REQUESTSTART, that._requestStartHandler) .unbind(REQUESTEND, that._requestEndHandler) .unbind("error", that._errorHandler); }, requireValueMapper: function(options, value) { var hasValue = (options.value instanceof Array ? options.value.length : options.value) || (value instanceof Array ? value.length : value); if (hasValue && options.virtual && typeof options.virtual.valueMapper !== "function") { throw new Error("ValueMapper is not provided while the value is being set. See http://docs.telerik.com/kendo-ui/controls/editors/combobox/virtualization#the-valuemapper-function"); } } }); function unifyType(value, type) { if (value !== undefined && value !== "" && value !== null) { if (type === "boolean") { value = Boolean(value); } else if (type === "number") { value = Number(value); } else if (type === "string") { value = value.toString(); } } return value; } extend(List, { inArray: function(node, parentNode) { var idx, length, siblings = parentNode.children; if (!node || node.parentNode !== parentNode) { return -1; } for (idx = 0, length = siblings.length; idx < length; idx++) { if (node === siblings[idx]) { return idx; } } return -1; }, unifyType: unifyType }); kendo.ui.List = List; ui.Select = List.extend({ init: function(element, options) { List.fn.init.call(this, element, options); this._initial = this.element.val(); }, setDataSource: function(dataSource) { var that = this; var parent; that.options.dataSource = dataSource; that._dataSource(); if (that.listView.bound()) { that._initialIndex = null; that.listView._current = null; } that.listView.setDataSource(that.dataSource); if (that.options.autoBind) { that.dataSource.fetch(); } parent = that._parentWidget(); if (parent) { that._cascadeSelect(parent); } }, close: function() { this.popup.close(); }, select: function(candidate) { var that = this; if (candidate === undefined) { return that.selectedIndex; } else { return that._select(candidate).done(function() { that._cascadeValue = that._old = that._accessor(); that._oldIndex = that.selectedIndex; }); } }, _accessor: function(value, idx) { return this[this._isSelect ? "_accessorSelect" : "_accessorInput"](value, idx); }, _accessorInput: function(value) { var element = this.element[0]; if (value === undefined) { return element.value; } else { if (value === null) { value = ""; } element.value = value; } }, _accessorSelect: function(value, idx) { var element = this.element[0]; var hasValue; if (value === undefined) { return getSelectedOption(element).value || ""; } getSelectedOption(element).selected = false; if (idx === undefined) { idx = -1; } hasValue = (value !== null && value !== ""); if (hasValue && idx == -1) { this._custom(value); } else { if (value) { element.value = value; } else { element.selectedIndex = idx; } } }, _syncValueAndText: function () { return true; }, _custom: function(value) { var that = this; var element = that.element; var custom = that._customOption; if (!custom) { custom = $("<option/>"); that._customOption = custom; element.append(custom); } custom.text(value); custom[0].selected = true; }, _hideBusy: function () { var that = this; clearTimeout(that._busy); that._arrowIcon.removeClass(LOADING); that._focused.attr("aria-busy", false); that._busy = null; that._showClear(); }, _showBusy: function (e) { var that = this; if (e.isDefaultPrevented()) { return; } that._request = true; if (that._busy) { return; } that._busy = setTimeout(function () { if (that._arrowIcon) { //destroyed after request start that._focused.attr("aria-busy", true); that._arrowIcon.addClass(LOADING); that._hideClear(); } }, 100); }, _requestEnd: function() { this._request = false; this._hideBusy(); }, _dataSource: function() { var that = this, element = that.element, options = that.options, dataSource = options.dataSource || {}, idx; dataSource = $.isArray(dataSource) ? {data: dataSource} : dataSource; if (that._isSelect) { idx = element[0].selectedIndex; if (idx > -1) { options.index = idx; } dataSource.select = element; dataSource.fields = [{ field: options.dataTextField }, { field: options.dataValueField }]; } if (that.dataSource) { that._unbindDataSource(); } else { that._requestStartHandler = proxy(that._showBusy, that); that._requestEndHandler = proxy(that._requestEnd, that); that._errorHandler = proxy(that._hideBusy, that); } that.dataSource = kendo.data.DataSource.create(dataSource) .bind(REQUESTSTART, that._requestStartHandler) .bind(REQUESTEND, that._requestEndHandler) .bind("error", that._errorHandler); }, _firstItem: function() { this.listView.focusFirst(); }, _lastItem: function() { this.listView.focusLast(); }, _nextItem: function() { this.listView.focusNext(); }, _prevItem: function() { this.listView.focusPrev(); }, _move: function(e) { var that = this; var listView = that.listView; var key = e.keyCode; var down = key === keys.DOWN; var dataItem; var pressed; var current; if (key === keys.UP || down) { if (e.altKey) { that.toggle(down); } else { if (!listView.bound() && !that.ul[0].firstChild) { if (!that._fetch) { that.dataSource.one(CHANGE, function() { that._fetch = false; that._move(e); }); that._fetch = true; that._filterSource(); } e.preventDefault(); return true; //pressed } current = that._focus(); if (!that._fetch && (!current || current.hasClass("k-state-selected"))) { if (down) { that._nextItem(); if (!that._focus()) { that._lastItem(); } } else { that._prevItem(); if (!that._focus()) { that._firstItem(); } } } dataItem = listView.dataItemByIndex(listView.getElementIndex(that._focus())); if (that.trigger(SELECT, { dataItem: dataItem, item: that._focus() })) { that._focus(current); return; } that._select(that._focus(), true).done(function() { if (!that.popup.visible()) { that._blur(); } if (that._cascadedValue === null) { that._cascadedValue = that.value(); } else { that._cascadedValue = that.dataItem() ? that.dataItem()[that.options.dataValueField] || that.dataItem() : null; } }); } e.preventDefault(); pressed = true; } else if (key === keys.ENTER || key === keys.TAB) { if (that.popup.visible()) { e.preventDefault(); } current = that._focus(); dataItem = that.dataItem(); if (!that.popup.visible() && (!dataItem || that.text() !== that._text(dataItem))) { current = null; } var activeFilter = that.filterInput && that.filterInput[0] === activeElement(); var selection; if (current) { dataItem = listView.dataItemByIndex(listView.getElementIndex(current)); var shouldTrigger = true; if (dataItem) { shouldTrigger = that._value(dataItem) !== List.unifyType(that.value(), typeof that._value(dataItem)); } if (shouldTrigger && that.trigger(SELECT, { dataItem: dataItem, item: current })) { return; } selection = that._select(current); } else if (that.input) { if (that._syncValueAndText() || that._isSelect) { that._accessor(that.input.val()); } that.listView.value(that.input.val()); } if (that._focusElement) { that._focusElement(that.wrapper); } if (activeFilter && key === keys.TAB) { that.wrapper.focusout(); } else { if (selection && typeof selection.done === "function") { selection.done(function () { that._blur(); }); } else { that._blur(); } } that.close(); pressed = true; } else if (key === keys.ESC) { if (that.popup.visible