').append(element.contents()));
element.attr('tabindex', attrs.tabindex || '0');
if (!hasDefinedValue(attrs)) {
element.attr('md-option-empty', '');
}
return postLink;
}
/**
* @param {Object} attrs list of attributes from the compile function
* @return {string|undefined|null} if defined and non-empty, return the value of the option's
* value attribute, otherwise return the value of the option's ng-value attribute.
*/
function hasDefinedValue(attrs) {
var value = attrs.value;
var ngValue = attrs.ngValue;
return value || ngValue;
}
function postLink(scope, element, attrs, ctrls) {
var optionCtrl = ctrls[0];
var selectMenuCtrl = ctrls[1];
$mdTheming(element);
if (selectMenuCtrl.isMultiple) {
element.addClass('md-checkbox-enabled');
if (!CHECKBOX_SELECTION_INDICATOR) {
var indicator = document.createElement('div');
indicator.className = 'md-container';
indicator.appendChild(document.createElement('div'));
indicator.firstChild.className = 'md-icon';
CHECKBOX_SELECTION_INDICATOR = angular.element(indicator);
}
element.prepend(CHECKBOX_SELECTION_INDICATOR.clone());
}
if (angular.isDefined(attrs.ngValue)) {
scope.$watch(attrs.ngValue, function (newValue, oldValue) {
setOptionValue(newValue, oldValue);
element.removeAttr('aria-checked');
});
} else if (angular.isDefined(attrs.value)) {
setOptionValue(attrs.value);
} else {
scope.$watch(function() {
return element.text().trim();
}, setOptionValue);
}
attrs.$observe('disabled', function(disabled) {
if (disabled) {
element.attr('tabindex', '-1');
} else {
element.attr('tabindex', '0');
}
});
scope.$$postDigest(function() {
attrs.$observe('selected', function(selected) {
if (!angular.isDefined(selected)) return;
if (typeof selected == 'string') selected = true;
if (selected) {
if (!selectMenuCtrl.isMultiple) {
selectMenuCtrl.deselect(Object.keys(selectMenuCtrl.selected)[0]);
}
selectMenuCtrl.select(optionCtrl.hashKey, optionCtrl.value);
} else {
selectMenuCtrl.deselect(optionCtrl.hashKey);
}
selectMenuCtrl.refreshViewValue();
});
});
$mdButtonInkRipple.attach(scope, element);
configureAria();
/**
* @param {*} newValue the option's new value
* @param {*=} oldValue the option's previous value
* @param {boolean=} prevAttempt true if this had to be attempted again due to an undefined
* hashGetter on the selectMenuCtrl, undefined otherwise.
*/
function setOptionValue(newValue, oldValue, prevAttempt) {
if (!selectMenuCtrl.hashGetter) {
if (!prevAttempt) {
scope.$$postDigest(function() {
setOptionValue(newValue, oldValue, true);
});
}
return;
}
var oldHashKey = selectMenuCtrl.hashGetter(oldValue, scope);
var newHashKey = selectMenuCtrl.hashGetter(newValue, scope);
optionCtrl.hashKey = newHashKey;
optionCtrl.value = newValue;
selectMenuCtrl.removeOption(oldHashKey, optionCtrl);
selectMenuCtrl.addOption(newHashKey, optionCtrl);
}
scope.$on('$destroy', function() {
selectMenuCtrl.removeOption(optionCtrl.hashKey, optionCtrl);
});
function configureAria() {
var ariaAttrs = {
'role': 'option'
};
// We explicitly omit the `aria-selected` attribute from single-selection, unselected
// options. Including the `aria-selected="false"` attributes adds a significant amount of
// noise to screen-reader users without providing useful information.
if (selectMenuCtrl.isMultiple) {
ariaAttrs['aria-selected'] = 'false';
}
if (!element[0].hasAttribute('id')) {
ariaAttrs.id = 'select_option_' + $mdUtil.nextUid();
}
element.attr(ariaAttrs);
}
}
}
/**
* @param {JQLite} $element
* @constructor
*/
function OptionController($element) {
/**
* @param {boolean} isSelected
* @param {boolean=} isMultiple
*/
this.setSelected = function(isSelected, isMultiple) {
if (isSelected) {
$element.attr({
'selected': 'true',
'aria-selected': 'true'
});
} else if (!isSelected) {
$element.removeAttr('selected');
if (isMultiple) {
$element.attr('aria-selected', 'false');
} else {
// We explicitly omit the `aria-selected` attribute from single-selection, unselected
// options. Including the `aria-selected="false"` attributes adds a significant amount of
// noise to screen-reader users without providing useful information.
$element.removeAttr('aria-selected');
}
}
};
}
/**
* @ngdoc directive
* @name mdOptgroup
* @restrict E
* @module material.components.select
*
* @description Displays a label separating groups of
*
md-option element directives in a
*
md-select box's dropdown menu.
*
* **Note:** When using `md-select-header` element directives within a `md-select`, the labels that
* would normally be added to the
md-optgroup directives
* are omitted, allowing the `md-select-header` to represent the option group label
* (and possibly more).
*
* @usage
* With label attributes
*
*
*
* Alabama
* Florida
*
*
* Alaska
* Massachusetts
*
*
*
*
* With label elements
*
*
*
* Southern
* Alabama
* Florida
*
*
* Northern
* Alaska
* Massachusetts
*
*
*
*
* @param {string=} label The option group's label.
*/
function OptgroupDirective() {
return {
restrict: 'E',
compile: compile
};
function compile(element, attrs) {
// If we have a select header element, we don't want to add the normal label
// header.
if (!hasSelectHeader()) {
setupLabelElement();
}
element.attr('role', 'group');
function hasSelectHeader() {
return element.parent().find('md-select-header').length;
}
function setupLabelElement() {
var labelElement = element.find('label');
if (!labelElement.length) {
labelElement = angular.element('
');
element.prepend(labelElement);
}
labelElement.addClass('md-container-ignore');
labelElement.attr('aria-hidden', 'true');
if (attrs.label) {
labelElement.text(attrs.label);
}
element.attr('aria-label', labelElement.text());
}
}
}
function SelectHeaderDirective() {
return {
restrict: 'E',
};
}
function SelectProvider($$interimElementProvider) {
return $$interimElementProvider('$mdSelect')
.setDefaults({
methods: ['target'],
options: selectDefaultOptions
});
/* @ngInject */
function selectDefaultOptions($mdSelect, $mdConstant, $mdUtil, $window, $q, $$rAF, $animateCss, $animate, $document) {
var ERROR_TARGET_EXPECTED = "$mdSelect.show() expected a target element in options.target but got '{0}'!";
var animator = $mdUtil.dom.animator;
var keyCodes = $mdConstant.KEY_CODE;
return {
parent: 'body',
themable: true,
onShow: onShow,
onRemove: onRemove,
hasBackdrop: true,
disableParentScroll: true
};
/**
* Interim-element onRemove logic....
*/
function onRemove(scope, element, opts) {
var animationRunner = null;
var destroyListener = scope.$on('$destroy', function() {
// Listen for the case where the element was destroyed while there was an
// ongoing close animation. If this happens, we need to end the animation
// manually.
animationRunner.end();
});
opts = opts || { };
opts.cleanupInteraction();
opts.cleanupResizing();
opts.hideBackdrop();
// For navigation $destroy events, do a quick, non-animated removal,
// but for normal closes (from clicks, etc) animate the removal
return (opts.$destroy === true) ? cleanElement() : animateRemoval().then(cleanElement);
/**
* For normal closes (eg clicks), animate the removal.
* For forced closes (like $destroy events from navigation),
* skip the animations.
*/
function animateRemoval() {
animationRunner = $animateCss(element, {addClass: 'md-leave'});
return animationRunner.start();
}
/**
* Restore the element to a closed state
*/
function cleanElement() {
destroyListener();
element
.removeClass('md-active')
.attr('aria-hidden', 'true')
.css({
'display': 'none',
'top': '',
'right': '',
'bottom': '',
'left': '',
'font-size': '',
'min-width': ''
});
announceClosed(opts);
if (!opts.$destroy) {
if (opts.restoreFocus) {
opts.target.focus();
} else {
// Make sure that the container's md-input-focused is removed on backdrop click.
$mdUtil.nextTick(function() {
opts.target.triggerHandler('blur');
}, true);
}
}
}
}
/**
* Interim-element onShow logic.
*/
function onShow(scope, element, opts) {
watchAsyncLoad();
sanitizeAndConfigure(scope, opts);
opts.hideBackdrop = showBackdrop(scope, element, opts);
return showDropDown(scope, element, opts)
.then(function(response) {
element.attr('aria-hidden', 'false');
opts.alreadyOpen = true;
opts.cleanupInteraction = activateInteraction();
opts.cleanupResizing = activateResizing();
opts.contentEl[0].focus();
return response;
}, opts.hideBackdrop);
// ************************************
// Closure Functions
// ************************************
/**
* Attach the select DOM element(s) and animate to the correct positions and scale.
*/
function showDropDown(scope, element, opts) {
if (opts.parent !== element.parent()) {
element.parent().attr('aria-owns', element.find('md-content').attr('id'));
}
opts.parent.append(element);
return $q(function(resolve, reject) {
try {
$animateCss(element, {removeClass: 'md-leave', duration: 0})
.start()
.then(positionAndFocusMenu)
.then(resolve);
} catch (e) {
reject(e);
}
});
}
/**
* Initialize container and dropDown menu positions/scale, then animate to show.
* @return {*} a Promise that resolves after the menu is animated in and an item is focused
*/
function positionAndFocusMenu() {
return $q(function(resolve) {
if (opts.isRemoved) return $q.reject(false);
var info = calculateMenuPositions(scope, element, opts);
info.container.element.css(animator.toCss(info.container.styles));
info.dropDown.element.css(animator.toCss(info.dropDown.styles));
$$rAF(function() {
element.addClass('md-active');
info.dropDown.element.css(animator.toCss({transform: ''}));
autoFocus(opts.focusedNode);
resolve();
});
});
}
/**
* Show modal backdrop element.
*/
function showBackdrop(scope, element, options) {
// If we are not within a dialog...
if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
// !! DO this before creating the backdrop; since disableScrollAround()
// configures the scroll offset; which is used by mdBackDrop postLink()
options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
} else {
options.disableParentScroll = false;
}
if (options.hasBackdrop) {
// Override duration to immediately show invisible backdrop
options.backdrop = $mdUtil.createBackdrop(scope, "md-select-backdrop md-click-catcher");
$animate.enter(options.backdrop, $document[0].body, null, {duration: 0});
}
/**
* Hide modal backdrop element...
*/
return function hideBackdrop() {
if (options.backdrop) options.backdrop.remove();
if (options.disableParentScroll) options.restoreScroll();
delete options.restoreScroll;
};
}
/**
* @param {Element|HTMLElement|null=} previousNode
* @param {Element|HTMLElement} node
* @param {SelectMenuController|Function|object=} menuController SelectMenuController instance
*/
function focusOptionNode(previousNode, node, menuController) {
var listboxContentNode = opts.contentEl[0];
if (node) {
if (previousNode) {
previousNode.classList.remove('md-focused');
}
node.classList.add('md-focused');
if (menuController && menuController.setActiveDescendant) {
menuController.setActiveDescendant(node.id);
}
// Scroll the node into view if needed.
if (listboxContentNode.scrollHeight > listboxContentNode.clientHeight) {
var scrollBottom = listboxContentNode.clientHeight + listboxContentNode.scrollTop;
var nodeBottom = node.offsetTop + node.offsetHeight;
if (nodeBottom > scrollBottom) {
listboxContentNode.scrollTop = nodeBottom - listboxContentNode.clientHeight;
} else if (node.offsetTop < listboxContentNode.scrollTop) {
listboxContentNode.scrollTop = node.offsetTop;
}
}
opts.focusedNode = node;
if (menuController && menuController.refreshViewValue) {
menuController.refreshViewValue();
}
}
}
/**
* @param {Element|HTMLElement} nodeToFocus
*/
function autoFocus(nodeToFocus) {
var selectMenuController;
if (nodeToFocus && !nodeToFocus.hasAttribute('disabled')) {
selectMenuController = opts.selectEl.controller('mdSelectMenu');
focusOptionNode(null, nodeToFocus, selectMenuController);
}
}
/**
* Check for valid opts and set some useful defaults
*/
function sanitizeAndConfigure(scope, options) {
var selectMenuElement = element.find('md-select-menu');
if (!options.target) {
throw new Error($mdUtil.supplant(ERROR_TARGET_EXPECTED, [options.target]));
}
angular.extend(options, {
isRemoved: false,
target: angular.element(options.target), // make sure it's not a naked DOM node
parent: angular.element(options.parent),
selectEl: selectMenuElement,
contentEl: element.find('md-content'),
optionNodes: selectMenuElement[0].getElementsByTagName('md-option')
});
}
/**
* Configure various resize listeners for screen changes
*/
function activateResizing() {
var debouncedOnResize = (function(scope, target, options) {
return function() {
if (options.isRemoved) return;
var updates = calculateMenuPositions(scope, target, options);
var container = updates.container;
var dropDown = updates.dropDown;
container.element.css(animator.toCss(container.styles));
dropDown.element.css(animator.toCss(dropDown.styles));
};
})(scope, element, opts);
var window = angular.element($window);
window.on('resize', debouncedOnResize);
window.on('orientationchange', debouncedOnResize);
// Publish deactivation closure...
return function deactivateResizing() {
// Disable resizing handlers
window.off('resize', debouncedOnResize);
window.off('orientationchange', debouncedOnResize);
};
}
/**
* If asynchronously loading, watch and update internal '$$loadingAsyncDone' flag.
*/
function watchAsyncLoad() {
if (opts.loadingAsync && !opts.isRemoved) {
scope.$$loadingAsyncDone = false;
$q.when(opts.loadingAsync)
.then(function() {
scope.$$loadingAsyncDone = true;
delete opts.loadingAsync;
}).then(function() {
$$rAF(positionAndFocusMenu);
});
}
}
function activateInteraction() {
if (opts.isRemoved) {
return;
}
var dropDown = opts.selectEl;
var selectMenuController = dropDown.controller('mdSelectMenu') || {};
element.addClass('md-clickable');
// Close on backdrop click
opts.backdrop && opts.backdrop.on('click', onBackdropClick);
// Escape to close
// Cycling of options, and closing on enter
dropDown.on('keydown', onMenuKeyDown);
dropDown.on('click', checkCloseMenu);
return function cleanupInteraction() {
opts.backdrop && opts.backdrop.off('click', onBackdropClick);
dropDown.off('keydown', onMenuKeyDown);
dropDown.off('click', checkCloseMenu);
element.removeClass('md-clickable');
opts.isRemoved = true;
};
// ************************************
// Closure Functions
// ************************************
function onBackdropClick(e) {
e.preventDefault();
e.stopPropagation();
opts.restoreFocus = false;
$mdUtil.nextTick($mdSelect.hide, true);
}
function onMenuKeyDown(ev) {
ev.preventDefault();
ev.stopPropagation();
switch (ev.keyCode) {
case keyCodes.UP_ARROW:
return focusPrevOption();
case keyCodes.DOWN_ARROW:
return focusNextOption();
case keyCodes.SPACE:
case keyCodes.ENTER:
if (opts.focusedNode) {
dropDown.triggerHandler({
type: 'click',
target: opts.focusedNode
});
ev.preventDefault();
}
checkCloseMenu(ev);
break;
case keyCodes.TAB:
case keyCodes.ESCAPE:
ev.stopPropagation();
ev.preventDefault();
opts.restoreFocus = true;
$mdUtil.nextTick($mdSelect.hide, true);
break;
default:
if (shouldHandleKey(ev, $mdConstant)) {
var optNode = selectMenuController.optNodeForKeyboardSearch(ev);
if (optNode && !optNode.hasAttribute('disabled')) {
focusOptionNode(opts.focusedNode, optNode, selectMenuController);
}
}
}
}
/**
* Change the focus to another option. If there is no focused option, focus the first
* option. If there is a focused option, then use the direction to determine if we should
* focus the previous or next option in the list.
* @param {'next'|'prev'} direction
*/
function focusOption(direction) {
var optionsArray = $mdUtil.nodesToArray(opts.optionNodes);
var index = optionsArray.indexOf(opts.focusedNode);
var prevOption = optionsArray[index];
var newOption;
do {
if (index === -1) {
// We lost the previously focused element, reset to first option
index = 0;
} else if (direction === 'next' && index < optionsArray.length - 1) {
index++;
} else if (direction === 'prev' && index > 0) {
index--;
}
newOption = optionsArray[index];
if (newOption.hasAttribute('disabled')) {
newOption = null;
}
} while (!newOption && index < optionsArray.length - 1 && index > 0);
focusOptionNode(prevOption, newOption, selectMenuController);
}
function focusNextOption() {
focusOption('next');
}
function focusPrevOption() {
focusOption('prev');
}
/**
* @param {KeyboardEvent|MouseEvent} event
*/
function checkCloseMenu(event) {
if (event && (event.type === 'click') && (event.currentTarget !== dropDown[0])) {
return;
}
if (mouseOnScrollbar()) {
return;
}
if (opts.focusedNode && opts.focusedNode.hasAttribute &&
!opts.focusedNode.hasAttribute('disabled')) {
event.preventDefault();
event.stopPropagation();
if (!selectMenuController.isMultiple) {
opts.restoreFocus = true;
$mdUtil.nextTick(function () {
$mdSelect.hide(selectMenuController.ngModel.$viewValue);
opts.focusedNode.classList.remove('md-focused');
}, true);
}
}
/**
* check if the mouseup event was on a scrollbar
*/
function mouseOnScrollbar() {
var clickOnScrollbar = false;
if (event && (event.currentTarget.children.length > 0)) {
var child = event.currentTarget.children[0];
var hasScrollbar = child.scrollHeight > child.clientHeight;
if (hasScrollbar && child.children.length > 0) {
var relPosX = event.pageX - event.currentTarget.getBoundingClientRect().left;
if (relPosX > child.querySelector('md-option').offsetWidth)
clickOnScrollbar = true;
}
}
return clickOnScrollbar;
}
}
}
}
/**
* To notify listeners that the Select menu has closed,
* trigger the [optional] user-defined expression
*/
function announceClosed(opts) {
var mdSelect = opts.selectCtrl;
if (mdSelect) {
var menuController = opts.selectEl.controller('mdSelectMenu');
mdSelect.setSelectValueText(menuController ? menuController.getSelectedLabels() : '');
mdSelect.triggerClose();
}
}
/**
* Calculate the menu positions after an event like options changing, screen resizing, or
* animations finishing.
* @param {Object} scope
* @param element
* @param opts
* @return {{container: {styles: {top: number, left: number, 'font-size': *, 'min-width': number}, element: Object}, dropDown: {styles: {transform: string, transformOrigin: string}, element: Object}}}
*/
function calculateMenuPositions(scope, element, opts) {
var
containerNode = element[0],
targetNode = opts.target[0].children[0], // target the label
parentNode = $document[0].body,
selectNode = opts.selectEl[0],
contentNode = opts.contentEl[0],
parentRect = parentNode.getBoundingClientRect(),
targetRect = targetNode.getBoundingClientRect(),
shouldOpenAroundTarget = false,
bounds = {
left: parentRect.left + SELECT_EDGE_MARGIN,
top: SELECT_EDGE_MARGIN,
bottom: parentRect.height - SELECT_EDGE_MARGIN,
right: parentRect.width - SELECT_EDGE_MARGIN - ($mdUtil.floatingScrollbars() ? 16 : 0)
},
spaceAvailable = {
top: targetRect.top - bounds.top,
left: targetRect.left - bounds.left,
right: bounds.right - (targetRect.left + targetRect.width),
bottom: bounds.bottom - (targetRect.top + targetRect.height)
},
maxWidth = parentRect.width - SELECT_EDGE_MARGIN * 2,
selectedNode = selectNode.querySelector('md-option[selected]'),
optionNodes = selectNode.getElementsByTagName('md-option'),
optgroupNodes = selectNode.getElementsByTagName('md-optgroup'),
isScrollable = calculateScrollable(element, contentNode),
centeredNode;
var loading = isPromiseLike(opts.loadingAsync);
if (!loading) {
// If a selected node, center around that
if (selectedNode) {
centeredNode = selectedNode;
// If there are option groups, center around the first option group
} else if (optgroupNodes.length) {
centeredNode = optgroupNodes[0];
// Otherwise - if we are not loading async - center around the first optionNode
} else if (optionNodes.length) {
centeredNode = optionNodes[0];
// In case there are no options, center on whatever's in there... (eg progress indicator)
} else {
centeredNode = contentNode.firstElementChild || contentNode;
}
} else {
// If loading, center on progress indicator
centeredNode = contentNode.firstElementChild || contentNode;
}
if (contentNode.offsetWidth > maxWidth) {
contentNode.style['max-width'] = maxWidth + 'px';
} else {
contentNode.style.maxWidth = null;
}
if (shouldOpenAroundTarget) {
contentNode.style['min-width'] = targetRect.width + 'px';
}
// Remove padding before we compute the position of the menu
if (isScrollable) {
selectNode.classList.add('md-overflow');
}
var focusedNode = centeredNode;
if ((focusedNode.tagName || '').toUpperCase() === 'MD-OPTGROUP') {
focusedNode = optionNodes[0] || contentNode.firstElementChild || contentNode;
centeredNode = focusedNode;
}
// Cache for autoFocus()
opts.focusedNode = focusedNode;
// Get the selectMenuRect *after* max-width is possibly set above
containerNode.style.display = 'block';
var selectMenuRect = selectNode.getBoundingClientRect();
var centeredRect = getOffsetRect(centeredNode);
if (centeredNode) {
var centeredStyle = $window.getComputedStyle(centeredNode);
centeredRect.paddingLeft = parseInt(centeredStyle.paddingLeft, 10) || 0;
centeredRect.paddingRight = parseInt(centeredStyle.paddingRight, 10) || 0;
}
if (isScrollable) {
var scrollBuffer = contentNode.offsetHeight / 2;
contentNode.scrollTop = centeredRect.top + centeredRect.height / 2 - scrollBuffer;
if (spaceAvailable.top < scrollBuffer) {
contentNode.scrollTop = Math.min(
centeredRect.top,
contentNode.scrollTop + scrollBuffer - spaceAvailable.top
);
} else if (spaceAvailable.bottom < scrollBuffer) {
contentNode.scrollTop = Math.max(
centeredRect.top + centeredRect.height - selectMenuRect.height,
contentNode.scrollTop - scrollBuffer + spaceAvailable.bottom
);
}
}
var left, top, transformOrigin, minWidth, fontSize;
if (shouldOpenAroundTarget) {
left = targetRect.left;
top = targetRect.top + targetRect.height;
transformOrigin = '50% 0';
if (top + selectMenuRect.height > bounds.bottom) {
top = targetRect.top - selectMenuRect.height;
transformOrigin = '50% 100%';
}
} else {
left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft);
top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
centeredRect.top + contentNode.scrollTop) + 2;
transformOrigin = (centeredRect.left + targetRect.width / 2) + 'px ' +
(centeredRect.top + centeredRect.height / 2 - contentNode.scrollTop) + 'px 0px';
minWidth = Math.min(targetRect.width + centeredRect.paddingLeft + centeredRect.paddingRight, maxWidth);
fontSize = window.getComputedStyle(targetNode)['font-size'];
}
// Keep left and top within the window
var containerRect = containerNode.getBoundingClientRect();
var scaleX = Math.round(100 * Math.min(targetRect.width / selectMenuRect.width, 1.0)) / 100;
var scaleY = Math.round(100 * Math.min(targetRect.height / selectMenuRect.height, 1.0)) / 100;
return {
container: {
element: angular.element(containerNode),
styles: {
left: Math.floor(clamp(bounds.left, left, bounds.right - minWidth)),
top: Math.floor(clamp(bounds.top, top, bounds.bottom - containerRect.height)),
'min-width': minWidth,
'font-size': fontSize
}
},
dropDown: {
element: angular.element(selectNode),
styles: {
transformOrigin: transformOrigin,
transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : ""
}
}
};
}
}
function isPromiseLike(obj) {
return obj && angular.isFunction(obj.then);
}
function clamp(min, n, max) {
return Math.max(min, Math.min(n, max));
}
function getOffsetRect(node) {
return node ? {
left: node.offsetLeft,
top: node.offsetTop,
width: node.offsetWidth,
height: node.offsetHeight
} : {left: 0, top: 0, width: 0, height: 0};
}
function calculateScrollable(element, contentNode) {
var isScrollable = false;
try {
var oldDisplay = element[0].style.display;
// Set the element's display to block so that this calculation is correct
element[0].style.display = 'block';
isScrollable = contentNode.scrollHeight > contentNode.offsetHeight;
// Reset it back afterwards
element[0].style.display = oldDisplay;
} finally {
// Nothing to do
}
return isScrollable;
}
}
function shouldHandleKey(ev, $mdConstant) {
var char = String.fromCharCode(ev.keyCode);
var isNonUsefulKey = (ev.keyCode <= 31);
return (char && char.length && !isNonUsefulKey &&
!$mdConstant.isMetaKey(ev) && !$mdConstant.isFnLockKey(ev) && !$mdConstant.hasModifierKey(ev));
}