{"version":3,"file":"kendo.menu.min.js","sources":["kendo.menu.js"],"sourcesContent":["(function(f, define) {\n define('kendo.menu',[ \"kendo.popup\", \"kendo.data\" ], f);\n})(function() {\n\nvar __meta__ = {\n id: \"menu\",\n name: \"Menu\",\n category: \"web\",\n description: \"The Menu widget displays hierarchical data as a multi-level menu.\",\n depends: [ \"popup\", \"data\", \"data.odata\" ]\n};\n\n(function($, undefined) {\n var kendo = window.kendo,\n ui = kendo.ui,\n activeElement = kendo._activeElement,\n touch = (kendo.support.touch && kendo.support.mobileOS),\n isArray = Array.isArray,\n HierarchicalDataSource = kendo.data.HierarchicalDataSource,\n MOUSEDOWN = \"mousedown\",\n CLICK = \"click\",\n DELAY = 30,\n SCROLLSPEED = 50,\n extend = $.extend,\n each = $.each,\n template = kendo.template,\n keys = kendo.keys,\n Widget = ui.Widget,\n excludedNodesRegExp = /^(ul|a|div)$/i,\n NS = \".kendoMenu\",\n IMG = \"img\",\n OPEN = \"open\",\n MENU = \"k-menu\",\n LINK = \"k-link k-menu-link\",\n LINK_SELECTOR = \".k-link\",\n ICON_SELECTOR = \".k-menu-expand-arrow-icon\",\n LAST = \"k-last\",\n CLOSE = \"close\",\n TIMER = \"timer\",\n FIRST = \"k-first\",\n IMAGE = \"k-image\",\n SELECT = \"select\",\n ZINDEX = \"zIndex\",\n ACTIVATE = \"activate\",\n DEACTIVATE = \"deactivate\",\n POINTERDOWN = \"touchstart\" + NS + \" MSPointerDown\" + NS + \" pointerdown\" + NS,\n pointers = kendo.support.pointers,\n msPointers = kendo.support.msPointers,\n allPointers = msPointers || pointers,\n CHANGE = \"change\",\n ERROR = \"error\",\n TOUCHSTART = kendo.support.touch ? \"touchstart\" : \"\",\n MOUSEENTER = pointers ? \"pointerover\" : (msPointers ? \"MSPointerOver\" : \"mouseenter\"),\n MOUSELEAVE = pointers ? \"pointerout\" : (msPointers ? \"MSPointerOut\" : \"mouseleave\"),\n MOUSEWHEEL = \"DOMMouseScroll\" + NS + \" mousewheel\" + NS,\n RESIZE = kendo.support.resize + NS,\n SCROLLWIDTH = \"scrollWidth\",\n SCROLLHEIGHT = \"scrollHeight\",\n OFFSETWIDTH = \"offsetWidth\",\n OFFSETHEIGHT = \"offsetHeight\",\n POPUP_ID_ATTR = \"group\",\n POPUP_OPENER_ATTR = \"groupparent\",\n DOCUMENT_ELEMENT = $(document.documentElement),\n KENDOPOPUP = \"kendoPopup\",\n HOVERSTATE = \"k-hover\",\n FOCUSEDSTATE = \"k-focus\",\n DISABLEDSTATE = \"k-disabled\",\n SELECTEDSTATE = \"k-selected\",\n menuSelector = \".k-menu\",\n groupSelector = \".k-menu-group\",\n animationContainerSelector = \".k-animation-container\",\n popupSelector = groupSelector + \",\" + animationContainerSelector,\n allItemsSelector = \":not(.k-list) > .k-item:not([role='treeitem'])\",\n disabledSelector = \".k-item.k-disabled\",\n itemSelector = \".k-item\",\n availableItemsSelector = \".k-item:not(.k-disabled)\",\n linkSelector = \".k-item:not(.k-disabled) > .k-link\",\n exclusionSelector = \":not(.k-item.k-separator)\",\n templateSelector = \"div:not(.k-animation-container,.k-list-container)\",\n scrollButtonSelector = \".k-menu-scroll-button\",\n touchPointerTypes = { \"2\": 1, \"touch\": 1 },\n STRING = \"string\",\n DATABOUND = \"dataBound\",\n ARIA_EXPANDED = \"aria-expanded\",\n ROLE = \"role\",\n\n bindings = {\n text: \"dataTextField\",\n url: \"dataUrlField\",\n spriteCssClass: \"dataSpriteCssClassField\",\n imageUrl: \"dataImageUrlField\",\n imageAttr: \"dataImageAttrField\",\n content: \"dataContentField\"\n },\n\n rendering = {\n wrapperCssClass: function(group, item) {\n var result = \"k-item k-menu-item\",\n index = item.index;\n\n if (item.enabled === false) {\n result += \" k-disabled\";\n }\n\n if (group.firstLevel && index === 0) {\n result += \" k-first\";\n }\n\n if (index == group.length - 1) {\n result += \" k-last\";\n }\n\n if (item.cssClass) {\n result += \" \" + item.cssClass;\n }\n\n if (item.attr && item.attr.hasOwnProperty(\"class\")) {\n result += \" \" + item.attr[\"class\"];\n }\n\n if (item.selected) {\n result += \" \" + SELECTEDSTATE;\n }\n\n return result;\n },\n\n itemCssAttributes: function(item) {\n var result = \"\";\n var attributes = item.attr || {};\n\n for (var attr in attributes) {\n if (attributes.hasOwnProperty(attr) && attr !== \"class\") {\n result += attr + \"=\\\"\" + attributes[attr] + \"\\\" \";\n }\n }\n\n return result;\n },\n\n imageCssAttributes: function(imgAttributes) {\n var result = \"\";\n var attributes = imgAttributes && imgAttributes.toJSON ? imgAttributes.toJSON() : {};\n\n if (!attributes['class']) {\n attributes['class'] = IMAGE;\n } else {\n attributes['class'] += \" \" + IMAGE;\n }\n\n for (var attr in attributes) {\n if (attributes.hasOwnProperty(attr)) {\n result += attr + \"=\\\"\" + attributes[attr] + \"\\\" \";\n }\n }\n\n return result;\n },\n\n contentCssAttributes: function(item) {\n var result = \"\";\n var attributes = item.contentAttr || {};\n var defaultClasses = \"k-content k-group k-menu-group k-menu-group-md\";\n\n if (!attributes['class']) {\n attributes['class'] = defaultClasses;\n } else {\n attributes['class'] += \" \" + defaultClasses;\n }\n\n for (var attr in attributes) {\n if (attributes.hasOwnProperty(attr)) {\n result += attr + \"=\\\"\" + attributes[attr] + \"\\\" \";\n }\n }\n\n return result;\n },\n\n textClass: function() {\n return LINK;\n },\n\n arrowClass: function(item, group) {\n var result = \"k-menu-expand-arrow-icon k-icon\";\n\n if (group.horizontal) {\n result += \" k-i-arrow-s\";\n } else {\n result += \" k-i-arrow-e\";\n }\n\n return result;\n },\n\n groupAttributes: function(group) {\n return group.expanded !== true ? \" style='display:none'\" : \"\";\n },\n\n groupCssClass: function() {\n return \"k-group k-menu-group k-menu-group-md\";\n },\n\n content: function(item) {\n return item.content ? item.content : \" \";\n }\n };\n\n function getEffectDirection(direction, root) {\n direction = direction.split(\" \")[!root + 0] || direction;\n return direction.replace(\"top\", \"up\").replace(\"bottom\", \"down\");\n }\n\n function parseDirection(direction, root, isRtl) {\n direction = direction.split(\" \")[!root + 0] || direction;\n var output = { origin: [\"bottom\", (isRtl ? \"right\" : \"left\")], position: [\"top\", (isRtl ? \"right\" : \"left\")] },\n horizontal = /left|right/.test(direction);\n\n if (horizontal) {\n output.origin = [ \"top\", direction ];\n output.position[1] = kendo.directions[direction].reverse;\n } else {\n output.origin[0] = direction;\n output.position[0] = kendo.directions[direction].reverse;\n }\n\n output.origin = output.origin.join(\" \");\n output.position = output.position.join(\" \");\n\n return output;\n }\n\n function contains(parent, child) {\n try {\n return $.contains(parent, child);\n } catch (e) {\n return false;\n }\n }\n\n function updateItemClasses(item) {\n item = $(item);\n var omitWrap = item.attr(kendo.attr(\"omit-wrap\"));\n\n if (omitWrap) {\n return;\n }\n\n item.addClass(\"k-item k-menu-item\")\n .children(IMG)\n .addClass(IMAGE);\n\n item\n .children(\"a\")\n .addClass(LINK)\n .children(IMG)\n .addClass(IMAGE);\n\n item\n .filter(\":not([disabled])\");\n\n item\n .filter(\".k-separator\")\n .removeClass(\"k-menu-item\")\n .addClass(\"k-menu-separator\")\n .empty()\n .append(\" \");\n\n item\n .filter(\"li[disabled]\")\n .addClass(DISABLEDSTATE)\n .prop(\"disabled\", false)\n .attr(\"aria-disabled\", true);\n\n if (!item.filter(\"[role]\").length) {\n item.attr(ROLE, \"menuitem\");\n }\n\n if (!item.children(LINK_SELECTOR).length) {\n item.contents() // exclude groups, real links, templates and empty text nodes\n .filter(function() { return (!this.nodeName.match(excludedNodesRegExp) && !(this.nodeType === 3 && !kendo.trim(this.nodeValue))); })\n .wrapAll(\"\")\n .filter(function(idx, elm) { return elm.nodeType === 3; })\n .wrap(\"\");\n }\n\n updateArrow(item);\n updateFirstLast(item);\n }\n\n function updateArrow(item) {\n item = $(item);\n\n item.find(\"> .k-link > .k-menu-expand-arrow > [class*=k-i-arrow]:not(.k-sprite)\").parent().remove();\n\n item.filter(\":has(.k-menu-group)\")\n .children(\".k-link:not(:has([class*=k-i-arrow]:not(.k-sprite)))\")\n .each(function() {\n var item = $(this),\n arrowCssClass = getArrowCssClass(item);\n\n item.append(\"
\").parent();\n if (isHorizontal) {\n removeSpacesBetweenItems(that.element);\n }\n\n backwardBtn = $(that.templates.scrollButton({ direction: isHorizontal ? \"left\" : \"up\" }));\n forwardBtn = $(that.templates.scrollButton({ direction: isHorizontal ? \"right\" : \"down\" }));\n backwardBtn.add(forwardBtn).appendTo(that._scrollWrapper);\n\n that._initScrolling(that.element, backwardBtn, forwardBtn, isHorizontal);\n\n var initialWidth = that.element.outerWidth();\n var initialCssWidth = that.element[0].style.width;\n initialCssWidth = initialCssWidth === \"auto\" ? \"\" : initialCssWidth;\n\n if (isHorizontal) {\n $(window).on(RESIZE, function() {\n setTimeout(function() {\n that._setOverflowWrapperWidth(initialWidth, initialCssWidth);\n that._toggleScrollButtons(that.element, backwardBtn, forwardBtn, isHorizontal);\n }, 300);\n });\n }\n\n that._setOverflowWrapperWidth(initialWidth, initialCssWidth);\n that._toggleScrollButtons(that.element, backwardBtn, forwardBtn, isHorizontal);\n }\n },\n\n _overflowWrapper: function() {\n return this._scrollWrapper || this._popupsWrapper;\n },\n\n _setOverflowWrapperWidth: function(initialWidth, initialCssWidth) {\n var that = this;\n var wrapperCssWidth = that._scrollWrapper.css(\"width\");\n\n that._scrollWrapper.css({ width: \"\" });\n var wrapperWidth = that._scrollWrapper.outerWidth();\n that._scrollWrapper.css({ width: wrapperCssWidth });\n\n var menuWidth = that.element.outerWidth();\n var borders = that.element[0].offsetWidth - that.element[0].clientWidth;\n\n if (menuWidth != wrapperWidth && wrapperWidth > 0) {\n var width = initialCssWidth ? Math.min(initialWidth, wrapperWidth) : wrapperWidth;\n that.element.width(width - borders);\n that._scrollWrapper.width(width);\n }\n },\n\n _reinitOverflow: function(options) {\n var that = this;\n var overflowChanged = ((options.scrollable && !that.options.scrollable) || (!options.scrollable && that.options.scrollable)) ||\n (options.scrollable && that.options.scrollable && options.scrollable.distance != that.options.scrollable.distance) ||\n options.orientation != that.options.orientation;\n\n if (overflowChanged) {\n that._detachMenuEventsHandlers();\n that._destroyOverflow();\n that._initOverflow(options);\n that._attachMenuEventsHandlers();\n }\n },\n\n _destroyOverflow: function() {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n if (overflowWrapper) {\n overflowWrapper.off(NS);\n overflowWrapper.find(scrollButtonSelector).off(NS).remove();\n overflowWrapper.children(animationContainerSelector).each(function(i, popupWrapper) {\n var ul = $(popupWrapper).children(groupSelector);\n ul.off(MOUSEWHEEL);\n var popupParentLi = popupParentItem(ul, overflowWrapper);\n if (popupParentLi.length) {\n popupParentLi.append(popupWrapper);\n }\n });\n\n overflowWrapper.find(popupOpenerSelector()).removeAttr(\"data-groupparent\");\n overflowWrapper.find(popupGroupSelector()).removeAttr(\"data-group\");\n that.element.off(MOUSEWHEEL);\n $(window).off(RESIZE);\n overflowWrapper.contents().unwrap();\n\n that._scrollWrapper = that._popupsWrapper = that._openedPopups = undefined;\n }\n },\n\n _initScrolling: function(scrollElement, backwardBtn, forwardBtn, isHorizontal) {\n var that = this;\n var scrollable = that.options.scrollable;\n var distance = that.isNumeric(scrollable.distance) ? scrollable.distance : SCROLLSPEED;\n var mouseWheelDistance = distance / 2;\n var backward = \"-=\" + distance;\n var forward = \"+=\" + distance;\n var backwardDouble = \"-=\" + distance * 2;\n var forwardDouble = \"+=\" + distance * 2;\n var scrolling = false;\n var touchEvents = false;\n\n var scroll = function(value) {\n var scrollValue = isHorizontal ? { \"scrollLeft\": value } : { \"scrollTop\": value };\n scrollElement.finish().animate(scrollValue, \"fast\", \"linear\", function() {\n if (scrolling) {\n scroll(value);\n }\n });\n that._toggleScrollButtons(scrollElement, backwardBtn, forwardBtn, isHorizontal);\n };\n\n var mouseenterHandler = function(e) {\n if (!scrolling && !touchEvents) {\n scroll(e.data.direction);\n scrolling = true;\n }\n };\n\n var mousedownHandler = function(e) {\n var scrollValue = isHorizontal ? { \"scrollLeft\": e.data.direction } : { \"scrollTop\": e.data.direction };\n touchEvents = isTouch(e) || isPointerTouch(e);\n scrollElement.stop().animate(scrollValue, \"fast\", \"linear\", function() {\n if (!touchEvents) {\n $(e.currentTarget).trigger(MOUSEENTER);\n } else {\n that._toggleScrollButtons(scrollElement, backwardBtn, forwardBtn, isHorizontal);\n scrolling = true;\n }\n });\n scrolling = false;\n\n e.stopPropagation();\n e.preventDefault();\n };\n\n backwardBtn.on(MOUSEENTER + NS, { direction: backward }, mouseenterHandler)\n .on(kendo.eventMap.down + NS, { direction: backwardDouble }, mousedownHandler);\n\n forwardBtn.on(MOUSEENTER + NS, { direction: forward }, mouseenterHandler)\n .on(kendo.eventMap.down + NS, { direction: forwardDouble }, mousedownHandler);\n\n backwardBtn.add(forwardBtn)\n .on(MOUSELEAVE + NS, function() {\n scrollElement.stop();\n scrolling = false;\n that._toggleScrollButtons(scrollElement, backwardBtn, forwardBtn, isHorizontal);\n });\n\n scrollElement.on(MOUSEWHEEL, function(e) {\n if (!e.ctrlKey && !e.shiftKey && !e.altKey) {\n var wheelDelta = mousewheelDelta(e.originalEvent);\n var scrollSpeed = Math.abs(wheelDelta) * mouseWheelDistance;\n var value = (wheelDelta > 0 ? \"+=\" : \"-=\") + scrollSpeed;\n var scrollValue = isHorizontal ? { \"scrollLeft\": value } : { \"scrollTop\": value };\n\n that._closeChildPopups(scrollElement);\n\n scrollElement.finish().animate(scrollValue, \"fast\", \"linear\", function() {\n that._toggleScrollButtons(scrollElement, backwardBtn, forwardBtn, isHorizontal);\n });\n e.preventDefault();\n }\n });\n },\n\n isNumeric: function(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n },\n\n _toggleScrollButtons: function(scrollElement, backwardBtn, forwardBtn, horizontal) {\n var currentScroll = horizontal ? kendo.scrollLeft(scrollElement) : scrollElement.scrollTop();\n var scrollSize = horizontal ? SCROLLWIDTH : SCROLLHEIGHT;\n var offset = horizontal ? OFFSETWIDTH : OFFSETHEIGHT;\n\n backwardBtn.toggle(currentScroll !== 0);\n forwardBtn.toggle(currentScroll < scrollElement[0][scrollSize] - scrollElement[0][offset] - 1);\n },\n\n setOptions: function(options) {\n var animation = this.options.animation;\n\n this._animations(options);\n\n options.animation = extend(true, animation, options.animation);\n\n if (\"dataSource\" in options) {\n this._dataSource(options);\n }\n\n this._updateClasses();\n this._reinitOverflow(options);\n\n Widget.fn.setOptions.call(this, options);\n },\n\n destroy: function() {\n var that = this;\n\n Widget.fn.destroy.call(that);\n\n that._detachMenuEventsHandlers();\n\n that._destroyOverflow();\n\n kendo.destroy(that.element);\n },\n\n enable: function(element, enable) {\n this._toggleDisabled(element, enable !== false);\n\n return this;\n },\n\n disable: function(element) {\n this._toggleDisabled(element, false);\n\n return this;\n },\n\n attemptGetItem: function(candidate) {\n candidate = candidate || this.element;\n var item = this.element.find(candidate);\n var overflowWrapper = this._overflowWrapper();\n\n if (item.length || candidate === this.element) {\n return item;\n } else if (overflowWrapper) {\n return overflowWrapper.find(candidate);\n } else {\n return $();\n }\n },\n\n append: function(item, referenceItem) {\n referenceItem = this.attemptGetItem(referenceItem);\n\n var inserted = this._insert(item, referenceItem, referenceItem.length ? this._childPopupElement(referenceItem) : null);\n\n each(inserted.items, function(i) {\n inserted.group.append(this);\n updateArrow(this);\n storeItemSelectEventHandler(this, item[i] || item);\n });\n\n updateArrow(referenceItem);\n updateFirstLast(inserted.group.find(\".k-first, .k-last\").add(inserted.items));\n updateHasAriaPopup(getParentLiItems(inserted.group));\n\n return this;\n },\n\n insertBefore: function(item, referenceItem) {\n referenceItem = this.attemptGetItem(referenceItem);\n\n var inserted = this._insert(item, referenceItem, referenceItem.parent());\n\n each(inserted.items, function(i) {\n referenceItem.before(this);\n updateArrow(this);\n updateFirstLast(this);\n storeItemSelectEventHandler(this, item[i] || item);\n });\n\n updateFirstLast(referenceItem);\n\n return this;\n },\n\n insertAfter: function(item, referenceItem) {\n referenceItem = this.attemptGetItem(referenceItem);\n\n var inserted = this._insert(item, referenceItem, referenceItem.parent());\n\n each(inserted.items, function(i) {\n referenceItem.after(this);\n updateArrow(this);\n updateFirstLast(this);\n storeItemSelectEventHandler(this, item[i] || item);\n });\n\n updateFirstLast(referenceItem);\n\n return this;\n },\n\n _insert: function(item, referenceItem, parent) {\n var that = this,\n items, groups;\n\n if (!referenceItem || !referenceItem.length) {\n parent = that.element;\n }\n\n var plain = $.isPlainObject(item) || item instanceof kendo.data.ObservableObject,\n groupData = {\n firstLevel: parent.hasClass(MENU),\n horizontal: parent.hasClass(MENU + \"-horizontal\"),\n expanded: true,\n length: parent.children().length\n };\n\n if (referenceItem && !parent.length) {\n parent = $(that.renderGroup({ group: groupData, options: that.options })).appendTo(referenceItem);\n }\n\n if (plain || isArray(item) || item instanceof kendo.data.ObservableArray) { // is JSON\n items = $($.map(plain ? [ item ] : item, function(value, idx) {\n if (typeof value === \"string\") {\n return $(value).get();\n } else {\n return $(that.renderItem({\n group: groupData,\n item: extend(value, { index: idx })\n })).get();\n }\n }));\n } else {\n if (typeof item == \"string\" && item.charAt(0) != \"<\") {\n items = that.element.find(item);\n } else {\n items = $(item);\n }\n\n groups = items.find(\"> ul\")\n .addClass(\"k-menu-group k-menu-group-md\")\n .attr(ROLE, \"menu\");\n\n items = items.filter(\"li\");\n\n items.add(groups.find(\"> li\")).each(function() {\n updateItemClasses(this);\n });\n }\n\n return { items: items, group: parent };\n },\n\n remove: function(element) {\n element = this.attemptGetItem(element);\n\n var that = this,\n parent = element.parentsUntil(that.element, allItemsSelector),\n group = element.parent(\"ul:not(.k-menu)\");\n\n element.remove();\n\n if (group && !group.children(allItemsSelector).length) {\n var parentItems = getParentLiItems(group);\n\n var container = group.parent(animationContainerSelector);\n\n if (container.length) {\n container.remove();\n } else {\n group.remove();\n }\n\n updateHasAriaPopup(parentItems);\n }\n\n if (parent.length) {\n parent = parent.eq(0);\n\n updateArrow(parent);\n updateFirstLast(parent);\n }\n\n return that;\n },\n\n _openAfterLoad: function(element, dataItem) {\n var that = this;\n if (dataItem.loaded()) {\n that.open(element);\n that._loading = false;\n } else {\n dataItem.one(CHANGE, function() {\n element.find(ICON_SELECTOR).removeClass(\"k-i-loading\");\n if (that._loading) {\n that.open(element);\n that._loading = false;\n }\n });\n }\n },\n\n open: function(element) {\n var that = this;\n var options = that.options;\n var horizontal = options.orientation == \"horizontal\";\n var direction = options.direction;\n var isRtl = kendo.support.isRtl(that.wrapper);\n var overflowWrapper = that._overflowWrapper();\n element = (overflowWrapper || that.element).find(element);\n\n var dataItem = that.dataSource && that.dataSource.getByUid(element.data(kendo.ns + \"uid\"));\n\n if (dataItem && dataItem.hasChildren && !dataItem.loaded() && !that._loading) {\n that._loading = true;\n element.find(ICON_SELECTOR).addClass(\"k-i-loading\");\n dataItem.load();\n that._openAfterLoad(element, dataItem);\n return;\n }\n\n if (/^(top|bottom|default)$/.test(direction)) {\n if (isRtl) {\n direction = horizontal ? (direction + \" left\").replace(\"default\", \"bottom\") : \"left\";\n } else {\n direction = horizontal ? (direction + \" right\").replace(\"default\", \"bottom\") : \"right\";\n }\n }\n\n var visiblePopups = \">.k-popup:visible,>.k-animation-container>.k-popup:visible\";\n var closePopup = function() {\n var popup = $(this).data(KENDOPOPUP);\n if (popup) {\n // Use the built-in close method to play the hoverDelay from the options\n that.close($(this).closest(\"li.k-item\"), true);\n }\n };\n\n element.siblings()\n .find(visiblePopups)\n .each(closePopup);\n\n if (overflowWrapper) {\n element.find(visiblePopups).each(closePopup);\n }\n\n if (that.options.openOnClick) {\n that.clicked = true;\n }\n\n element.each(function() {\n var li = $(this);\n\n clearTimeout(li.data(TIMER));\n\n li.data(TIMER, setTimeout(function() {\n var ul = li.find(\"> .k-menu-group, > .k-animation-container > .k-menu-group\").filter(\":hidden\").first();\n var popup;\n var overflowPopup;\n\n if (!ul[0] && overflowWrapper) {\n overflowPopup = that._getPopup(li);\n ul = overflowPopup && overflowPopup.element;\n }\n if (ul.is(\":visible\")) {\n return;\n }\n\n if (ul[0] && that._triggerEvent({ item: li[0], type: OPEN }) === false) {\n\n if (!ul.find(\".k-menu-group\")[0] && ul.children(\".k-item\").length > 1) {\n var windowHeight = $(window).height(),\n setScrolling = function() {\n ul.css({ maxHeight: windowHeight - (kendo._outerHeight(ul) - ul.height()) - kendo.getShadows(ul).bottom, overflow: \"auto\" });\n };\n\n setScrolling();\n } else {\n ul.css({ maxHeight: \"\", overflow: \"\" });\n }\n\n li.data(ZINDEX, li.css(ZINDEX));\n var nextZindex = that.nextItemZIndex++;\n li.css(ZINDEX, nextZindex);\n\n if (that.options.scrollable) {\n li.parent().siblings(scrollButtonSelector).css({ zIndex: ++nextZindex });\n }\n\n popup = ul.data(KENDOPOPUP);\n var root = li.parent().hasClass(MENU),\n parentHorizontal = root && horizontal,\n directions = parseDirection(direction, root, isRtl),\n effects = options.animation.open.effects,\n openEffects = effects !== undefined ? effects : \"slideIn:\" + getEffectDirection(direction, root);\n\n if (!popup) {\n popup = ul.kendoPopup({\n activate: function() { that._triggerEvent({ item: this.wrapper.parent(), type: ACTIVATE }); },\n deactivate: function(e) {\n that._closing = false;\n e.sender.element // Restore opacity after fade.\n .removeData(\"targetTransform\")\n .css({ opacity: \"\" });\n that._triggerEvent({ item: this.wrapper.parent(), type: DEACTIVATE });\n },\n origin: directions.origin,\n position: directions.position,\n collision: options.popupCollision !== undefined ? options.popupCollision : (parentHorizontal ? \"fit\" : \"fit flip\"),\n anchor: li,\n appendTo: overflowWrapper || li,\n animation: {\n open: extend(true, { effects: openEffects }, options.animation.open),\n close: options.animation.close\n },\n open: that._popupOpen.bind(that),\n close: function(e) {\n that._closing = e.sender.element;\n var li = e.sender.wrapper.parent();\n\n if (overflowWrapper) {\n var popupId = e.sender.element.data(POPUP_ID_ATTR);\n if (popupId) {\n li = (overflowWrapper || that.element).find(popupOpenerSelector(popupId));\n }\n e.sender.wrapper.children(scrollButtonSelector).hide();\n }\n\n if (!that._triggerEvent({ item: li[0], type: CLOSE })) {\n li.css(ZINDEX, li.data(ZINDEX));\n li.removeData(ZINDEX);\n\n if (that.options.scrollable) {\n li.parent().siblings(scrollButtonSelector).css({ zIndex: \"\" });\n }\n\n if (touch || allPointers || kendo.support.mouseAndTouchPresent) {\n li.removeClass(HOVERSTATE);\n that._removeHoverItem();\n }\n } else {\n e.preventDefault();\n }\n }\n }).data(KENDOPOPUP);\n\n ul.closest(animationContainerSelector).removeAttr(ROLE);\n } else {\n popup = ul.data(KENDOPOPUP);\n popup.options.origin = directions.origin;\n popup.options.position = directions.position;\n popup.options.animation.open.effects = openEffects;\n }\n ul.removeAttr(\"aria-hidden\");\n li.attr(ARIA_EXPANDED, true);\n\n that._configurePopupOverflow(popup, li);\n\n popup._hovered = true;\n popup.open();\n\n that._initPopupScrolling(popup);\n }\n\n }, that.options.hoverDelay));\n });\n\n return that;\n },\n\n _configurePopupOverflow: function(popup, popupOpener) {\n var that = this;\n if (that.options.scrollable) {\n that._wrapPopupElement(popup);\n if (!popupOpener.attr(\"data-groupparent\")) {\n var groupId = new Date().getTime();\n popupOpener.attr(\"data-groupparent\", groupId);\n popup.element.attr(\"data-group\", groupId);\n }\n }\n },\n\n _wrapPopupElement: function(popup) {\n if (!popup.element.parent().is(animationContainerSelector)) {\n popup.wrapper = kendo.wrap(popup.element, popup.options.autosize)\n .css({\n overflow: \"hidden\",\n display: \"block\",\n position: \"absolute\"\n });\n }\n },\n\n _initPopupScrolling: function(popup, isHorizontal, skipMouseEvents) {\n var that = this;\n\n if (that.options.scrollable && popup.element[0].scrollHeight > popup.element[0].offsetHeight) {\n that._initPopupScrollButtons(popup, isHorizontal, skipMouseEvents);\n }\n },\n\n _initPopupScrollButtons: function(popup, isHorizontal, skipMouseEvents) {\n var that = this;\n var scrollButtons = popup.wrapper.children(scrollButtonSelector);\n var animation = that.options.animation;\n var timeout = ((animation && animation.open && animation.open.duration) || 0) + DELAY;\n setTimeout(function() {\n if (!scrollButtons.length) {\n var backwardBtn = $(that.templates.scrollButton({ direction: isHorizontal ? \"left\" : \"up\" }));\n var forwardBtn = $(that.templates.scrollButton({ direction: isHorizontal ? \"right\" : \"down\" }));\n\n scrollButtons = backwardBtn.add(forwardBtn).appendTo(popup.wrapper);\n\n that._initScrolling(popup.element, backwardBtn, forwardBtn, isHorizontal);\n if (!skipMouseEvents) {\n scrollButtons.on(MOUSEENTER + NS, function() {\n var overflowWrapper = that._overflowWrapper();\n $(getChildPopups(popup.element, overflowWrapper)).each(function(i, p) {\n var popupOpener = overflowWrapper.find(popupOpenerSelector(p.data(POPUP_ID_ATTR)));\n that.close(popupOpener);\n });\n })\n .on(MOUSELEAVE + NS, function() {\n setTimeout(function() {\n if ($.isEmptyObject(that._openedPopups)) {\n that._closeParentPopups(popup.element);\n }\n }, DELAY);\n });\n }\n }\n that._toggleScrollButtons(popup.element, scrollButtons.first(), scrollButtons.last(), isHorizontal);\n }, timeout);\n },\n\n _popupOpen: function(e) {\n if (!this._keyTriggered) {\n e.sender.element.children(\".\" + FOCUSEDSTATE).removeClass(FOCUSEDSTATE);\n }\n if (this.options.scrollable) {\n this._setPopupHeight(e.sender);\n }\n },\n\n _setPopupHeight: function(popup, isFixed) {\n var popupElement = popup.element;\n var popups = popupElement.add(popupElement.parent(animationContainerSelector));\n\n popups.height((popupElement.hasClass(MENU) && this._initialHeight) || \"\");\n\n var location = popup._location(isFixed);\n var windowHeight = $(window).height();\n var popupOuterHeight = location.height;\n var popupOffsetTop = isFixed ? 0 : Math.max(location.top, 0);\n var scrollTop = isFixed ? 0 : parentsScroll(this._overflowWrapper()[0], \"scrollTop\");\n var bottomScrollbar = window.innerHeight - windowHeight;\n var maxHeight = windowHeight - kendo.getShadows(popupElement).bottom + bottomScrollbar;\n var canFit = maxHeight + scrollTop > popupOuterHeight + popupOffsetTop;\n\n if (!canFit) {\n var height = Math.min(maxHeight, maxHeight - popupOffsetTop + scrollTop);\n popups.css({ overflow: \"hidden\", height: height + \"px\" });\n }\n },\n\n close: function(items, dontClearClose) {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n var element = (overflowWrapper || that.element);\n\n items = element.find(items);\n\n if (!items.length) {\n items = element.find(\">.k-item\");\n }\n\n var hasChildPopupsHovered = function(currentPopup) {\n var result = false;\n if ($.isEmptyObject(that._openedPopups)) {\n return result;\n }\n $(getChildPopups(currentPopup, overflowWrapper)).each(function(i, popup) {\n result = !!that._openedPopups[popup.data(POPUP_ID_ATTR).toString()];\n return !result;\n });\n return result;\n };\n\n var isPopupMouseLeaved = function(opener) {\n var groupId = opener.data(POPUP_OPENER_ATTR);\n return (!overflowWrapper || !groupId || !that._openedPopups[groupId.toString()]);\n };\n\n items.each(function() {\n var li = $(this);\n\n li.attr(ARIA_EXPANDED, false);\n\n if (!dontClearClose && that._isRootItem(li)) {\n that.clicked = false;\n }\n\n clearTimeout(li.data(TIMER));\n\n li.data(TIMER, setTimeout(function() {\n var popup = that._getPopup(li);\n if (popup && (isPopupMouseLeaved(li) || that._forceClose)) {\n if (!that._forceClose && hasChildPopupsHovered(popup.element)) {\n return;\n }\n\n popup.close();\n popup.element.attr(\"aria-hidden\", true);\n\n if (overflowWrapper) {\n if (that._forceClose && items.last().is(li[0])) {\n delete that._forceClose;\n }\n }\n }\n }, that.options.hoverDelay));\n });\n\n return that;\n },\n\n _getPopup: function(li) {\n var that = this;\n var popup = li.find(\".k-menu-group:not(.k-list-container):not(.k-calendar-container):visible\").first().data(KENDOPOPUP);\n var overflowWrapper = that._overflowWrapper();\n\n if (!popup && overflowWrapper) {\n var groupId = li.data(POPUP_OPENER_ATTR);\n if (groupId) {\n var popupElement = overflowWrapper.find(popupGroupSelector(groupId));\n popup = popupElement.data(KENDOPOPUP);\n }\n }\n return popup;\n },\n\n _toggleDisabled: function(items, enable) {\n this.element.find(items).each(function() {\n $(this)\n .toggleClass(DISABLEDSTATE, !enable)\n .attr(\"aria-disabled\", !enable);\n });\n },\n\n _toggleHover: function(e) {\n var target = $(kendo.eventTarget(e) || e.target).closest(allItemsSelector),\n isEnter = e.type == MOUSEENTER || MOUSEDOWN.indexOf(e.type) !== -1;\n\n target.siblings().removeClass(HOVERSTATE);\n\n if (!target.parents(\"li.\" + DISABLEDSTATE).length) {\n target.toggleClass(HOVERSTATE, isEnter || e.type == \"mousedown\" || e.type == \"pointerover\" || e.type == TOUCHSTART);\n }\n\n this._removeHoverItem();\n },\n\n _preventClose: function() {\n if (!this.options.closeOnClick) {\n this._closurePrevented = true;\n }\n },\n\n _checkActiveElement: function(e) {\n var that = this,\n hoverItem = $(e ? e.currentTarget : this._hoverItem()),\n target = that._findRootParent(hoverItem)[0];\n\n if (!this._closurePrevented) {\n setTimeout(function() {\n if (!document.hasFocus() || (!contains(target, kendo._activeElement()) && e && !contains(target, e.currentTarget))) {\n that.close(target);\n }\n }, 0);\n }\n\n this._closurePrevented = false;\n },\n\n _removeHoverItem: function() {\n var oldHoverItem = this._hoverItem();\n\n if (oldHoverItem && oldHoverItem.hasClass(FOCUSEDSTATE)) {\n oldHoverItem.removeClass(FOCUSEDSTATE);\n this._oldHoverItem = null;\n }\n },\n\n _updateClasses: function() {\n var element = this.element,\n nonContentGroupsSelector = \".k-menu-init div ul\",\n items;\n\n element.removeClass(\"k-menu-horizontal k-menu-vertical\");\n element.addClass(\"k-widget k-reset k-menu-init \" + MENU).addClass(MENU + \"-\" + this.options.orientation);\n\n if (this.options.orientation === \"vertical\") {\n element.attr(\"aria-orientation\", \"vertical\");\n } else {\n element.attr(\"aria-orientation\", \"horizontal\");\n }\n\n element.find(\"li > ul\")\n .filter(function() {\n return !kendo.support.matchesSelector.call(this, nonContentGroupsSelector);\n })\n .addClass(\"k-group k-menu-group k-menu-group-md\")\n .attr(ROLE, \"menu\")\n .hide()\n .attr(\"aria-hidden\", element.is(\":visible\"))\n .parent(\"li\")\n .attr(\"aria-haspopup\", \"true\")\n .end()\n .find(\"li > div\")\n .addClass(\"k-content\")\n .attr(\"tabindex\", \"-1\"); // Capture the focus before the Menu\n\n element.find(\"li[aria-haspopup]\").attr(ARIA_EXPANDED, false);\n\n items = element.find(\"> li,.k-menu-group > li\");\n\n element.removeClass(\"k-menu-init\");\n\n items.each(function() {\n updateItemClasses(this);\n });\n },\n\n _mouseenter: function(e) {\n var that = this;\n var element = $(e.currentTarget);\n var hasChildren = that._itemHasChildren(element);\n var popupId = element.data(POPUP_OPENER_ATTR) || element.parent().data(POPUP_ID_ATTR);\n var pointerTouch = isPointerTouch(e);\n var isParentClosing = false;\n\n if (popupId) {\n that._openedPopups[popupId.toString()] = true;\n }\n\n if (that._closing) {\n isParentClosing = !!that._closing.find(element).length;\n }\n\n if (isParentClosing || (e.delegateTarget != element.parents(menuSelector)[0] && e.delegateTarget != element.parents(\".k-menu-scroll-wrapper,.k-popups-wrapper\")[0])) {\n return;\n }\n\n that._keyTriggered = false;\n\n if ((that.options.openOnClick.rootMenuItems && that._isRootItem(element.closest(allItemsSelector))) ||\n (that.options.openOnClick.subMenuItems && !that._isRootItem(element.closest(allItemsSelector)))) {\n return;\n }\n\n if ((that.options.openOnClick === false ||\n (that.options.openOnClick.rootMenuItems === false && that._isRootItem(element.closest(allItemsSelector))) ||\n (that.options.openOnClick.subMenuItems === false && !that._isRootItem(element.closest(allItemsSelector))) || that.clicked) && !touch &&\n !(pointerTouch && that._isRootItem(element.closest(allItemsSelector)))) {\n\n if (!contains(e.currentTarget, e.relatedTarget) && hasChildren) {\n that.open(element);\n }\n }\n\n if (that.options.openOnClick === true && that.clicked || touch) {\n element.siblings().each(function(_, sibling) {\n that.close(sibling, true);\n });\n }\n },\n\n _mousedown: function(e) {\n var that = this;\n var element = $(e.currentTarget);\n // needs to close subMenuItems\n if (that.options.openOnClick.subMenuItems && !that._isRootItem(element) || touch) {\n element.siblings().each(function(_, sibling) {\n that.close(sibling, true);\n });\n }\n },\n\n _mouseleave: function(e) {\n var that = this;\n var element = $(e.currentTarget);\n var popupOpener = element.data(POPUP_OPENER_ATTR);\n var hasChildren = (element.children(animationContainerSelector).length || element.children(groupSelector).length) || popupOpener;\n var $window = $(window);\n\n if (popupOpener) {\n delete that._openedPopups[popupOpener.toString()];\n }\n\n if (element.parentsUntil(animationContainerSelector, \".k-list-container,.k-calendar-container\")[0]) {\n e.stopImmediatePropagation();\n return;\n }\n\n if ((that.options.openOnClick === false || (!that.options.openOnClick.rootMenuItems && that._isRootItem(element)) ||\n (!that.options.openOnClick.subMenuItems && !that._isRootItem(element))) && !touch && !isPointerTouch(e) &&\n !contains(e.currentTarget, e.relatedTarget || e.target) && hasChildren &&\n !contains(e.currentTarget, kendo._activeElement())) {\n that.close(element, true);\n that._loading = false;\n return;\n }\n\n // Detect if cursor goes outside the viewport of the browser\n if ( (kendo.support.browser.msie && !e.toElement && !e.relatedTarget && !isPointerTouch(e)) ||\n e.clientX < 0 || e.clientY < 0 ||\n e.clientY > $window.height() ||\n e.clientX > $window.width()) {\n that.close(element);\n }\n },\n\n _mouseenterPopup: function(e) {\n var that = this;\n var popupElement = $(e.currentTarget);\n\n if (popupElement.parent().is(animationContainerSelector)) {\n return;\n }\n\n popupElement = popupElement.children(\"ul\");\n var popupId = popupElement.data(POPUP_ID_ATTR);\n\n if (popupId) {\n that._openedPopups[popupId.toString()] = true;\n }\n },\n\n _mouseleavePopup: function(e) {\n var that = this;\n var popupElement = $(e.currentTarget);\n\n if (!isPointerTouch(e) && popupElement.is(animationContainerSelector)) {\n that._closePopups(popupElement.children(\"ul\"));\n }\n },\n\n _closePopups: function(rootPopup) {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n var popupId = rootPopup.data(POPUP_ID_ATTR);\n\n if (popupId) {\n delete that._openedPopups[popupId.toString()];\n var groupParent = overflowWrapper.find(popupOpenerSelector(popupId));\n\n setTimeout(function() {\n if (that.options.openOnClick) {\n that._closeChildPopups(rootPopup);\n } else {\n if ($.isEmptyObject(that._openedPopups)) {\n var innerPopup = that._innerPopup(rootPopup);\n that._closeParentPopups(innerPopup);\n } else {\n that.close(groupParent, true);\n }\n }\n }, 0);\n }\n },\n\n _closeChildPopups: function(current) {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n $(getChildPopups(current, overflowWrapper)).each(function() {\n var popupOpener = overflowWrapper.find(popupOpenerSelector(this.data(POPUP_ID_ATTR)));\n that.close(popupOpener, true);\n });\n },\n\n _innerPopup: function(current) {\n var overflowWrapper = this._overflowWrapper();\n var popups = getChildPopups(current, overflowWrapper);\n return popups[popups.length - 1] || current;\n },\n\n _closeParentPopups: function(current) {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n var popupId = current.data(POPUP_ID_ATTR);\n var popupOpener = overflowWrapper.find(popupOpenerSelector(popupId));\n popupId = popupOpener.parent().data(POPUP_ID_ATTR);\n that.close(popupOpener, true);\n while (popupId && !that._openedPopups[popupId]) {\n if (popupOpener.parent().is(menuSelector)) {\n break;\n }\n popupOpener = overflowWrapper.find(popupOpenerSelector(popupId));\n that.close(popupOpener, true);\n popupId = popupOpener.parent().data(POPUP_ID_ATTR);\n }\n },\n\n _click: function(e) {\n var that = this, openHandle,\n options = that.options,\n target = $(kendo.eventTarget(e)),\n targetElement = target[0],\n nodeName = target[0] ? target[0].nodeName.toUpperCase() : \"\",\n formNode = (nodeName == \"INPUT\" || nodeName == \"SELECT\" || nodeName == \"BUTTON\" || nodeName == \"LABEL\"),\n link = target.closest(LINK_SELECTOR),\n element = target.closest(allItemsSelector),\n itemElement = element[0],\n href = link.attr(\"href\"), childGroup, childGroupVisible,\n targetHref = target.attr(\"href\"),\n sampleHref = $(\"\").attr(\"href\"),\n isLink = (!!href && href !== sampleHref),\n isLocalLink = isLink && !!href.match(/^#/),\n isTargetLink = (!!targetHref && targetHref !== sampleHref),\n overflowWrapper = that._overflowWrapper(),\n shouldCloseTheRootItem;\n\n if (targetElement && (!targetElement.parentNode || !itemElement)) {\n return;\n }\n\n if ($(target).hasClass('k-menu-expand-arrow-icon')) {\n this._lastClickedElement = itemElement;\n }\n\n while (targetElement && targetElement.parentNode != itemElement) {\n targetElement = targetElement.parentNode;\n }\n\n if ($(targetElement).is(templateSelector)) {\n return;\n }\n\n if (element.hasClass(DISABLEDSTATE)) {\n e.preventDefault();\n return;\n }\n\n if (!e.handled && that._triggerSelect(target, itemElement) && !formNode) { // We shouldn't stop propagation and shoudn't prevent form elements.\n e.preventDefault();\n }\n\n e.handled = true;\n\n childGroup = element.children(popupSelector);\n if (overflowWrapper) {\n var childPopupId = element.data(POPUP_OPENER_ATTR);\n if (childPopupId) {\n childGroup = overflowWrapper.find(popupGroupSelector(childPopupId));\n }\n }\n childGroupVisible = childGroup.is(\":visible\");\n shouldCloseTheRootItem = options.openOnClick && childGroupVisible && that._isRootItem(element);\n\n if (options.closeOnClick && (!isLink || isLocalLink) && (!childGroup.length || shouldCloseTheRootItem)) {\n element.removeClass(HOVERSTATE).css(\"height\"); // Force refresh for Chrome\n that._oldHoverItem = that._findRootParent(element);\n var item = that._parentsUntil(link, that.element, allItemsSelector);\n that._forceClose = !!overflowWrapper;\n that.close(item);\n that.clicked = false;\n if (\"MSPointerUp\".indexOf(e.type) != -1) {\n e.preventDefault();\n }\n return;\n }\n\n if (isLink && e.enterKey) {\n link[0].click();\n }\n\n if (((!that._isRootItem(element) || options.openOnClick === false) && !options.openOnClick.subMenuItems) && !kendo.support.touch && !(isPointerTouch(e) && that._isRootItem(element.closest(allItemsSelector)))) {\n return;\n }\n\n if (!isLink && !formNode && !isTargetLink) {\n e.preventDefault();\n }\n\n that.clicked = true;\n openHandle = childGroup.is(\":visible\") ? CLOSE : OPEN;\n if (!options.closeOnClick && openHandle == CLOSE) {\n return;\n }\n that[openHandle](element);\n },\n\n _parentsUntil: function(context, top, selector) {\n var overflowWrapper = this._overflowWrapper();\n if (!overflowWrapper) {\n return context.parentsUntil(top, selector);\n } else {\n var parents = overflowMenuParents(context, overflowWrapper);\n var result = [];\n $(parents).each(function() {\n var parent = $(this);\n if (parent.is(top)) {\n return false;\n }\n if (parent.is(selector)) {\n result.push(this);\n }\n });\n return $(result);\n }\n },\n\n _triggerSelect: function(target, itemElement) {\n target = target.is(\".k-link\") ? target : target.closest(\".k-link\");\n\n var selectHandler = target.data(\"selectHandler\"),\n itemSelectEventData;\n\n if (selectHandler) {\n itemSelectEventData = this._getEventData(target);\n selectHandler.call(this, itemSelectEventData);\n }\n\n var isSelectItemDefaultPrevented = itemSelectEventData && itemSelectEventData.isDefaultPrevented();\n var isSelectDefaultPrevented = this._triggerEvent({ item: itemElement, type: SELECT });\n return isSelectItemDefaultPrevented || isSelectDefaultPrevented;\n },\n\n _getEventData: function(target) {\n var eventData = {\n sender: this,\n target: target,\n _defaultPrevented: false,\n preventDefault: function() {\n this._defaultPrevented = true;\n },\n isDefaultPrevented: function() {\n return this._defaultPrevented;\n }\n };\n return eventData;\n },\n\n _documentClick: function(e) {\n var that = this;\n var target = $(e.target).hasClass('k-menu-expand-arrow-icon') ? that._lastClickedElement : e.target;\n\n if (contains((that._overflowWrapper() || that.element)[0], target)) {\n that._lastClickedElement = undefined;\n return;\n }\n\n that.clicked = false;\n },\n\n _focus: function(e) {\n var that = this,\n target = e.target,\n hoverItem = that._hoverItem(),\n active = activeElement();\n\n if (target != that.wrapper[0] && !$(target).is(\":kendoFocusable\")) {\n e.stopPropagation();\n $(target).closest(\".k-content\").closest(\".k-menu-group\").closest(\".k-item\").addClass(FOCUSEDSTATE);\n that.wrapper.trigger(\"focus\");\n return;\n }\n\n if (active === e.currentTarget) {\n if (hoverItem.length) {\n that._moveHover([], hoverItem);\n } else if (!that._oldHoverItem) {\n that._moveHover([], that.wrapper.children().first());\n }\n }\n },\n\n _keydown: function(e) {\n var that = this,\n key = e.keyCode,\n hoverItem = that._oldHoverItem,\n target,\n belongsToVertical,\n hasChildren,\n isRtl = kendo.support.isRtl(that.wrapper);\n\n if (e.target != e.currentTarget && key != keys.ESC) {\n return;\n }\n\n if (!hoverItem) {\n hoverItem = that._oldHoverItem = that._hoverItem();\n }\n\n belongsToVertical = that._itemBelongsToVertival(hoverItem);\n hasChildren = that._itemHasChildren(hoverItem);\n that._keyTriggered = true;\n\n if (key == keys.RIGHT) {\n target = that[isRtl ? \"_itemLeft\" : \"_itemRight\"](hoverItem, belongsToVertical, hasChildren);\n } else if (key == keys.LEFT) {\n target = that[isRtl ? \"_itemRight\" : \"_itemLeft\"](hoverItem, belongsToVertical, hasChildren);\n } else if (key == keys.DOWN) {\n target = that._itemDown(hoverItem, belongsToVertical, hasChildren);\n } else if (key == keys.UP) {\n target = that._itemUp(hoverItem, belongsToVertical, hasChildren);\n } else if (key == keys.HOME) {\n that._moveHover(hoverItem, hoverItem.parent().children().first());\n e.preventDefault();\n } else if (key == keys.END) {\n that._moveHover(hoverItem, hoverItem.parent().children().last());\n e.preventDefault();\n } else if (key == keys.ESC) {\n target = that._itemEsc(hoverItem, belongsToVertical);\n } else if (key == keys.ENTER || key == keys.SPACEBAR) {\n target = hoverItem.children(\".k-link\");\n if (target.length > 0) {\n that._click({ target: target[0], preventDefault: function() {}, enterKey: true });\n if (hasChildren && !hoverItem.hasClass(DISABLEDSTATE)) {\n that.open(hoverItem);\n that._moveHover(hoverItem, that._childPopupElement(hoverItem).children().first());\n } else if (hoverItem.is(\"li\") && hoverItem.attr(\"role\") === \"menuitemcheckbox\") {\n hoverItem.find(\".k-checkbox\").attr(\"checked\", true);\n } else {\n that._moveHoverToRoot(hoverItem, that._findRootParent(hoverItem));\n }\n }\n } else if (key == keys.TAB) {\n target = that._findRootParent(hoverItem);\n that._moveHover(hoverItem, target);\n that._checkActiveElement();\n return;\n }\n\n if (target && target[0]) {\n e.preventDefault();\n e.stopPropagation(); // needed to handle ESC in column menu only when a root item is focused\n }\n },\n\n _hoverItem: function() {\n return this.wrapper.find(\".k-item.k-hover,.k-item.k-focus\").filter(\":visible\");\n },\n\n _itemBelongsToVertival: function(item) {\n var menuIsVertical = this.wrapper.hasClass(\"k-menu-vertical\");\n\n if (!item.length) {\n return menuIsVertical;\n }\n return item.parent().hasClass(\"k-menu-group\") || menuIsVertical;\n },\n\n _itemHasChildren: function(item) {\n if (!item || !item.length || !item[0].nodeType) {\n return false;\n }\n return item.children(\".k-menu-group, div.k-animation-container\").length > 0 ||\n (!!item.data(POPUP_OPENER_ATTR) && !!this._overflowWrapper().children(popupGroupSelector(item.data(POPUP_OPENER_ATTR))));\n },\n\n _moveHover: function(item, nextItem) {\n var that = this,\n id = that._ariaId;\n\n if (item.length && nextItem.length) {\n item.removeClass(FOCUSEDSTATE);\n }\n\n if (nextItem.length) {\n if (nextItem[0].id) {\n id = nextItem[0].id;\n }\n\n nextItem.addClass(FOCUSEDSTATE);\n that._oldHoverItem = nextItem;\n\n if (id) {\n that.element.removeAttr(\"aria-activedescendant\");\n $(\"#\" + id).removeAttr(\"id\");\n nextItem.attr(\"id\", id);\n that.element.attr(\"aria-activedescendant\", id);\n }\n that._scrollToItem(nextItem);\n }\n },\n\n _moveHoverToRoot: function(item, nextItem) {\n this._moveHover(item, nextItem);\n },\n\n _findRootParent: function(item) {\n if (this._isRootItem(item)) {\n return item;\n } else {\n return this._parentsUntil(item, menuSelector, \"li.k-item\").last();\n }\n },\n\n _isRootItem: function(item) {\n return item.parent().hasClass(MENU);\n },\n\n _itemRight: function(item, belongsToVertical, hasChildren) {\n var that = this,\n nextItem,\n parentItem,\n overflowWrapper;\n\n if (!belongsToVertical) {\n nextItem = item.nextAll(itemSelector + exclusionSelector).eq(0);\n if (!nextItem.length) {\n nextItem = item.prevAll(itemSelector + exclusionSelector).last();\n }\n that.close(item);\n } else if (hasChildren && !item.hasClass(DISABLEDSTATE)) {\n that.open(item);\n nextItem = that._childPopupElement(item).children().first();\n } else if (that.options.orientation == \"horizontal\") {\n parentItem = that._findRootParent(item);\n overflowWrapper = that._overflowWrapper();\n if (overflowWrapper) {\n var rootPopup = itemPopup(parentItem, overflowWrapper);\n that._closeChildPopups(rootPopup);\n }\n that.close(parentItem);\n nextItem = parentItem.nextAll(itemSelector + exclusionSelector).eq(0);\n }\n\n if (nextItem && !nextItem.length) {\n nextItem = that.wrapper.children(\".k-item\").first();\n } else if (!nextItem) {\n nextItem = [];\n }\n\n that._moveHover(item, nextItem);\n return nextItem;\n },\n\n _itemLeft: function(item, belongsToVertical) {\n var that = this,\n nextItem,\n overflowWrapper;\n\n if (!belongsToVertical) {\n nextItem = item.prevAll(itemSelector + exclusionSelector).eq(0);\n if (!nextItem.length) {\n nextItem = item.nextAll(itemSelector + exclusionSelector).last();\n }\n that.close(item);\n } else {\n nextItem = item.parent().closest(\".k-item\");\n overflowWrapper = that._overflowWrapper();\n if (!nextItem.length && overflowWrapper) {\n nextItem = popupParentItem(item.parent(), overflowWrapper);\n }\n that.close(nextItem);\n if (that._isRootItem(nextItem) && that.options.orientation == \"horizontal\") {\n nextItem = nextItem.prevAll(itemSelector + exclusionSelector).eq(0);\n }\n }\n\n if (!nextItem.length) {\n nextItem = that.wrapper.children(\".k-item\").last();\n }\n\n that._moveHover(item, nextItem);\n return nextItem;\n },\n\n _itemDown: function(item, belongsToVertical, hasChildren) {\n var that = this,\n nextItem;\n\n if (!belongsToVertical) {\n if (!hasChildren || item.hasClass(DISABLEDSTATE)) {\n return;\n } else {\n that.open(item);\n nextItem = that._childPopupElement(item).children().first();\n }\n } else {\n nextItem = item.nextAll(itemSelector + exclusionSelector).eq(0);\n }\n\n if (!nextItem.length && item.length) {\n nextItem = item.parent().children().first();\n } else if (!item.length) {\n nextItem = that.wrapper.children(\".k-item\").first();\n }\n\n that._moveHover(item, nextItem);\n return nextItem;\n },\n\n _itemUp: function(item, belongsToVertical) {\n var that = this,\n nextItem;\n\n if (!belongsToVertical) {\n return;\n } else {\n nextItem = item.prevAll(itemSelector + exclusionSelector).eq(0);\n }\n\n if (!nextItem.length && item.length) {\n nextItem = item.parent().children().last();\n } else if (!item.length) {\n nextItem = that.wrapper.children(\".k-item\").last();\n }\n\n that._moveHover(item, nextItem);\n return nextItem;\n },\n\n _scrollToItem: function(item) {\n var that = this;\n if (that.options.scrollable && item && item.length) {\n var ul = item.parent();\n var isHorizontal = ul.hasClass(MENU) ? that.options.orientation == \"horizontal\" : false;\n var scrollDir = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n var getSize = isHorizontal ? kendo._outerWidth : kendo._outerHeight;\n var currentScrollOffset = ul[scrollDir]();\n var itemSize = getSize(item);\n var itemOffset = item[0][isHorizontal ? \"offsetLeft\" : \"offsetTop\"];\n var ulSize = getSize(ul);\n var scrollButtons = ul.siblings(scrollButtonSelector);\n var scrollButtonSize = scrollButtons.length ? getSize(scrollButtons.first()) : 0;\n var itemPosition;\n\n if (currentScrollOffset + ulSize < itemOffset + itemSize + scrollButtonSize) {\n itemPosition = itemOffset + itemSize - ulSize + scrollButtonSize;\n } else if (currentScrollOffset > itemOffset - scrollButtonSize) {\n itemPosition = itemOffset - scrollButtonSize;\n }\n\n if (!isNaN(itemPosition)) {\n var scrolling = {};\n scrolling[scrollDir] = itemPosition;\n ul.finish().animate(scrolling, \"fast\", \"linear\", function() {\n that._toggleScrollButtons(ul, scrollButtons.first(), scrollButtons.last(), isHorizontal);\n });\n }\n }\n },\n\n _itemEsc: function(item, belongsToVertical) {\n var that = this,\n nextItem, groupId;\n\n if (!belongsToVertical) {\n return item;\n } else {\n nextItem = item.parent().closest(\".k-item\");\n\n if (nextItem.length === 0) {\n groupId = item.closest(\".k-group\").data(\"group\");\n nextItem = that.wrapper.find(\".k-item[data-groupparent='\" + groupId + \"']\");\n }\n\n that.close(nextItem);\n that._moveHover(item, nextItem);\n }\n\n return nextItem;\n },\n\n _childPopupElement: function(item) {\n var popupElement = item.find(\".k-menu-group\");\n var wrapper = this._overflowWrapper();\n if (!popupElement.length && wrapper) {\n popupElement = itemPopup(item, wrapper);\n }\n return popupElement;\n },\n\n _triggerEvent: function(e) {\n var that = this;\n\n return that.trigger(e.type, { type: e.type, item: e.item });\n },\n\n _focusHandler: function(e) {\n var that = this,\n item = $(kendo.eventTarget(e)).closest(allItemsSelector);\n\n if (item.hasClass(DISABLEDSTATE)) {\n return;\n }\n\n setTimeout(function() {\n that._moveHover([], item);\n if (item.children(\".k-content\")[0]) {\n item.parent().closest(\".k-item\").removeClass(FOCUSEDSTATE);\n }\n }, 200);\n },\n\n _animations: function(options) {\n if (options && (\"animation\" in options) && !options.animation) {\n options.animation = { open: { effects: {} }, close: { hide: true, effects: {} } };\n }\n },\n _dataSource: function(options) {\n var that = this,\n dataSource = options ? options.dataSource : that.options.dataSource;\n\n if (!dataSource) {\n return;\n }\n\n dataSource = isArray(dataSource) ? { data: dataSource } : dataSource;\n\n that._unbindDataSource();\n\n if (!dataSource.fields) {\n dataSource.fields = [\n { field: \"uid\" },\n { field: \"text\" },\n { field: \"url\" },\n { field: \"cssClass\" },\n { field: \"spriteCssClass\" },\n { field: \"imageUrl\" },\n { field: \"imageAttr\" },\n { field: \"attr\" },\n { field: \"contentAttr\" },\n { field: \"content\" },\n { field: \"encoded\" },\n { field: \"items\" },\n { field: \"select\" }\n ];\n }\n\n that.dataSource = HierarchicalDataSource.create(dataSource);\n\n that._bindDataSource();\n\n that.dataSource.fetch();\n },\n\n _bindDataSource: function() {\n this._refreshHandler = this.refresh.bind(this);\n this._errorHandler = this._error.bind(this);\n\n this.dataSource.bind(CHANGE, this._refreshHandler);\n this.dataSource.bind(ERROR, this._errorHandler);\n },\n\n _unbindDataSource: function() {\n var dataSource = this.dataSource;\n\n if (dataSource) {\n dataSource.unbind(CHANGE, this._refreshHandler);\n dataSource.unbind(ERROR, this._errorHandler);\n }\n },\n\n _error: function() {\n\n },\n\n findByUid: function(uid) {\n var wrapperElement = this._overflowWrapper() || this.element;\n return wrapperElement.find(\"[\" + kendo.attr(\"uid\") + \"=\" + uid + \"]\");\n },\n\n refresh: function(ev) {\n var that = this;\n var node = ev.node;\n var action = ev.action;\n var parentElement = node ? that.findByUid(node.uid) : that.element;\n var itemsToUpdate = ev.items;\n var index = ev.index;\n var updateProxy = that._updateItem.bind(that);\n var removeProxy = that._removeItem.bind(that);\n\n if (action == \"add\") {\n that._appendItems(itemsToUpdate, index, parentElement);\n } else if (action == \"remove\") {\n itemsToUpdate.forEach(removeProxy);\n } else if (action == \"itemchange\") {\n itemsToUpdate.forEach(updateProxy);\n } else if (action === \"itemloaded\") {\n that.append(ev.items, parentElement);\n } else {\n this._initData();\n }\n\n this.trigger(DATABOUND, { item: parentElement, dataItem: node });\n },\n\n _appendItems: function(items, index, parent) {\n var that = this;\n var referenceItem = parent.find(itemSelector).eq(index);\n\n if (referenceItem.length) {\n that.insertBefore(items, referenceItem);\n } else {\n that.append(items, parent);\n }\n },\n\n _removeItem: function(item) {\n var that = this;\n var element = that.findByUid(item.uid);\n that.remove(element);\n },\n\n _updateItem: function(item) {\n var that = this;\n var element = that.findByUid(item.uid);\n var nextElement = element.next();\n var parentNode = item.parentNode();\n\n that.remove(element);\n\n if (nextElement.length) {\n that.insertBefore(item, nextElement);\n } else {\n that.append(item, parentNode && that.findByUid(parentNode.uid));\n }\n },\n\n _accessors: function() {\n var that = this,\n options = that.options,\n i, field, textField,\n element = that.element;\n\n for (i in bindings) {\n field = options[bindings[i]];\n textField = element.attr(kendo.attr(i + \"-field\"));\n\n if (!field && textField) {\n field = textField;\n }\n\n if (!field) {\n field = i;\n }\n\n if (!isArray(field)) {\n field = [field];\n }\n\n options[bindings[i]] = field;\n }\n },\n\n _fieldAccessor: function(fieldName) {\n var fieldBindings = this.options[bindings[fieldName]] || [],\n count = fieldBindings.length,\n result = \"(function(item) {\";\n\n if (count === 0) {\n result += \"return item['\" + fieldName + \"'];\";\n } else {\n result += \"var levels = [\" +\n $.map(fieldBindings, function(x) {\n return \"function(d){ return \" + kendo.expr(x) + \"}\";\n }).join(\",\") + \"];\";\n result += \"if(item.level){return levels[Math.min(item.level(), \" + count + \"-1)](item);}else\";\n result += \"{return levels[\" + count + \"-1](item)}\";\n }\n\n result += \"})\";\n\n return result;\n },\n\n _templates: function() {\n var that = this,\n options = that.options,\n fieldAccessor = that._fieldAccessor.bind(that);\n\n if (options.template && typeof options.template == STRING) {\n options.template = template(options.template);\n } else if (!options.template) {\n options.template = template(\n \" \");\n });\n }\n\n function getArrowCssClass(item) {\n var arrowCssClass,\n parent = item.parent().parent(),\n isRtl = kendo.support.isRtl(parent);\n\n if (parent.hasClass(MENU + \"-horizontal\")) {\n arrowCssClass = \"k-i-arrow-s\";\n } else {\n if (isRtl) {\n arrowCssClass = \"k-i-arrow-w\";\n }\n else {\n arrowCssClass = \"k-i-arrow-e\";\n }\n }\n return arrowCssClass;\n }\n\n function updateFirstLast(item) {\n item = $(item);\n\n item.filter(\".k-first:not(:first-child)\").removeClass(FIRST);\n item.filter(\".k-last:not(:last-child)\").removeClass(LAST);\n item.filter(\":first-child\").addClass(FIRST);\n item.filter(\":last-child\").addClass(LAST);\n }\n\n function updateHasAriaPopup(parents) {\n if (parents && parents.length) {\n for (var index in parents) {\n var parentLi = parents.eq(index);\n if (parentLi.find(\"ul\").length) {\n parentLi.attr(\"aria-haspopup\", true);\n } else {\n parentLi.removeAttr(\"aria-haspopup\");\n }\n }\n }\n }\n\n function getParentLiItems(group) {\n if (!group.hasClass(MENU)) {\n return group.parentsUntil(\".\" + MENU, \"li\");\n }\n }\n\n function storeItemSelectEventHandler(element, options) {\n var selectHandler = getItemSelectEventHandler(options);\n if (selectHandler) {\n setItemData(element, selectHandler);\n }\n\n if (options.items) {\n $(element).children(\"ul\").children(\"li\").each(function(i) {\n storeItemSelectEventHandler(this, options.items[i]);\n });\n }\n }\n\n function setItemData(element, selectHandler) {\n $(element).children(\".k-link\").data({\n selectHandler: selectHandler\n });\n }\n\n function getItemSelectEventHandler(options) {\n var selectHandler = options.select,\n isFunction = kendo.isFunction;\n\n if (selectHandler && isFunction(selectHandler)) {\n return selectHandler;\n }\n return null;\n }\n\n function popupOpenerSelector(id) {\n return id ? \"li[data-groupparent='\" + id + \"']\" : \"li[data-groupparent]\";\n }\n function popupGroupSelector(id) {\n var selector = id ? \"[data-group='\" + id + \"']\" : \"[data-group]\";\n return \"ul\" + selector + \",div\" + selector;\n }\n function getChildPopups(currentPopup, overflowWrapper) {\n var childPopupOpener = currentPopup.find(popupOpenerSelector());\n var result = [];\n childPopupOpener.each(function(i, opener) {\n opener = $(opener);\n var popupId = opener.data(POPUP_OPENER_ATTR);\n var popup = currentPopup;\n while (popupId) {\n popup = overflowWrapper.find(popupGroupSelector(popupId) + \":visible\");\n if (popup.length) {\n result.push(popup);\n }\n opener = popup.find(popupOpenerSelector());\n popupId = opener.data(POPUP_OPENER_ATTR);\n }\n });\n\n return result;\n }\n\n function popupParentItem(popupElement, overflowWrapper) {\n var popupId = popupElement.data(POPUP_ID_ATTR);\n return popupId ? overflowWrapper.find(popupOpenerSelector(popupId)) : $([]);\n }\n\n function itemPopup(item, overflowWrapper) {\n var popupId = item.data(POPUP_OPENER_ATTR);\n return popupId ? overflowWrapper.children(animationContainerSelector).children(popupGroupSelector(popupId)) : $([]);\n }\n\n function overflowMenuParents(current, overflowWrapper) {\n var parents = [];\n var getParents = function(item) {\n while (item.parentNode && !overflowWrapper.is(item.parentNode)) {\n parents.push(item.parentNode);\n item = item.parentNode;\n }\n };\n var elem = current[0] || current;\n getParents(elem);\n var last = parents[parents.length - 1];\n while ($(last).is(animationContainerSelector)) {\n var popupElement = $(last).children(\"ul\");\n elem = popupParentItem(popupElement, overflowWrapper)[0];\n if (!elem) {\n break;\n }\n parents.push(elem);\n getParents(elem);\n last = parents[parents.length - 1];\n }\n return parents;\n }\n\n function mousewheelDelta(e) {\n var delta = 0;\n\n if (e.wheelDelta) {\n delta = -e.wheelDelta / 120;\n delta = delta > 0 ? Math.ceil(delta) : Math.floor(delta);\n }\n\n if (e.detail) {\n delta = Math.round(e.detail / 3);\n }\n\n return delta;\n }\n\n function parentsScroll(current, scrollDirection) {\n var scroll = 0;\n var parent = current.parentNode;\n while (parent && !isNaN(parent[scrollDirection])) {\n scroll += parent[scrollDirection];\n parent = parent.parentNode;\n }\n return scroll;\n }\n\n function isPointerTouch(e) {\n return allPointers && e.originalEvent && e.originalEvent.pointerType in touchPointerTypes;\n }\n\n function isTouch(e) {\n var ev = e.originalEvent;\n return touch && /touch/i.test(ev.type || \"\");\n }\n\n function removeSpacesBetweenItems(ul) {\n ul.contents().filter(function() { return this.nodeName != \"LI\"; }).remove();\n }\n\n var Menu = kendo.ui.DataBoundWidget.extend({\n init: function(element, options) {\n var that = this;\n\n Widget.fn.init.call(that, element, options);\n\n element = that.wrapper = that.element;\n options = that.options;\n that._accessors();\n that._templates();\n that._dataSource();\n\n that._updateClasses();\n\n that._animations(options);\n\n that.nextItemZIndex = 100;\n\n that._tabindex();\n\n that._initOverflow(options);\n\n that._attachMenuEventsHandlers();\n\n if (options.openOnClick) {\n that.clicked = false;\n }\n\n element.attr(ROLE, \"menubar\");\n\n if (element[0].id) {\n that._ariaId = kendo.format(\"{0}_mn_active\", element[0].id);\n }\n\n kendo.notify(that);\n },\n\n events: [\n OPEN,\n CLOSE,\n ACTIVATE,\n DEACTIVATE,\n SELECT,\n DATABOUND\n ],\n\n options: {\n name: \"Menu\",\n animation: {\n open: {\n duration: 200\n },\n close: { // if close animation effects are defined, they will be used instead of open.reverse\n duration: 100\n }\n },\n orientation: \"horizontal\",\n direction: \"default\",\n openOnClick: false,\n closeOnClick: true,\n hoverDelay: 100,\n scrollable: false,\n popupCollision: undefined\n },\n\n _initData: function() {\n var that = this;\n\n if (that.dataSource) {\n that.angular(\"cleanup\", function() {\n return {\n elements: that.element.children()\n };\n });\n that.element.empty();\n\n that.append(that.dataSource.view(), that.element);\n that.angular(\"compile\", function() {\n return {\n elements: that.element.children()\n };\n });\n }\n },\n\n _attachMenuEventsHandlers: function() {\n var that = this;\n var element = that.element;\n var options = that.options;\n var overflowWrapper = that._overflowWrapper();\n\n that._checkActiveProxy = that._checkActiveElement.bind(that);\n\n (overflowWrapper || element).on(POINTERDOWN, itemSelector, that._focusHandler.bind(that))\n .on(CLICK + NS, disabledSelector, false)\n .on(CLICK + NS, itemSelector, that._click.bind(that))\n .on(POINTERDOWN + \" \" + MOUSEDOWN + NS, \".k-content\", that._preventClose.bind(that))\n .on(MOUSEENTER + NS, availableItemsSelector, that._mouseenter.bind(that))\n .on(MOUSELEAVE + NS, availableItemsSelector, that._mouseleave.bind(that))\n .on(MOUSEDOWN + NS, availableItemsSelector, that._mousedown.bind(that))\n .on(TOUCHSTART + NS + \" \" + MOUSEENTER + NS + \" \" + MOUSELEAVE + NS + \" \" +\n MOUSEDOWN + NS + \" \" + CLICK + NS, linkSelector, that._toggleHover.bind(that));\n\n element.on(\"keydown\" + NS, that._keydown.bind(that))\n .on(\"focus\" + NS, that._focus.bind(that))\n .on(\"focus\" + NS, \".k-content\", that._focus.bind(that))\n .on(\"blur\" + NS, that._removeHoverItem.bind(that))\n .on(\"blur\" + NS, \"[tabindex]\", that._checkActiveProxy);\n\n if (overflowWrapper) {\n overflowWrapper\n .on(MOUSELEAVE + NS, popupSelector, that._mouseleavePopup.bind(that))\n .on(MOUSEENTER + NS, popupSelector, that._mouseenterPopup.bind(that));\n }\n\n if (options.openOnClick) {\n that._documentClickHandler = that._documentClick.bind(that);\n $(document).on(\"click\", that._documentClickHandler);\n }\n },\n\n _detachMenuEventsHandlers: function() {\n var that = this;\n var overflowWrapper = that._overflowWrapper();\n\n if (overflowWrapper) {\n overflowWrapper.off(NS);\n }\n\n that.element.off(NS);\n\n if (that._documentClickHandler) {\n $(document).off(\"click\", that._documentClickHandler);\n }\n },\n\n _initOverflow: function(options) {\n var that = this;\n var isHorizontal = options.orientation == \"horizontal\";\n var backwardBtn, forwardBtn;\n\n if (options.scrollable) {\n that._openedPopups = {};\n that._scrollWrapper = that.element.wrap(\" \"\n );\n }\n\n that.templates = {\n content: template(\n \"#var contentHtml = \" + fieldAccessor(\"content\") + \"(item);#\" +\n \"