define(['dialogHelper', 'layoutManager', 'dialogText', 'paper-button', 'css!./actionsheet'], function (dialogHelper, layoutManager, dialogText) { function parentWithClass(elem, className) { while (!elem.classList || !elem.classList.contains(className)) { elem = elem.parentNode; if (!elem) { return null; } } return elem; } function getOffsets(elems) { var doc = document; var results = []; if (!doc) { return results; } var box; var elem; for (var i = 0, length = elems.length; i < length; i++) { elem = elems[i]; // Support: BlackBerry 5, iOS 3 (original iPhone) // If we don't have gBCR, just use 0,0 rather than error if (elem.getBoundingClientRect) { box = elem.getBoundingClientRect(); } else { box = { top: 0, left: 0 }; } results[i] = { top: box.top, left: box.left }; } return results; } function getPosition(options, dlg) { var windowHeight = window.innerHeight; if (windowHeight < 540) { return null; } var pos = getOffsets([options.positionTo])[0]; pos.top += options.positionTo.offsetHeight / 2; pos.left += options.positionTo.offsetWidth / 2; // Account for popup size pos.top -= ((dlg.offsetHeight || 300) / 2); pos.left -= ((dlg.offsetWidth || 160) / 2); // Avoid showing too close to the bottom pos.top = Math.min(pos.top, windowHeight - 300); pos.left = Math.min(pos.left, window.innerWidth - 300); // Do some boundary checking pos.top = Math.max(pos.top, 10); pos.left = Math.max(pos.left, 10); return pos; } function addCenterFocus(dlg) { require(['scrollHelper'], function (scrollHelper) { scrollHelper.centerFocus.on(dlg.querySelector('.actionSheetScroller'), false); }); } function show(options) { // items // positionTo // showCancel // title var dialogOptions = { removeOnClose: true, enableHistory: options.enableHistory }; var backButton = false; if (layoutManager.tv) { dialogOptions.size = 'fullscreen'; backButton = true; dialogOptions.autoFocus = true; } else { dialogOptions.modal = false; dialogOptions.entryAnimationDuration = 160; dialogOptions.exitAnimationDuration = 200; dialogOptions.autoFocus = false; } var dlg = dialogHelper.createDialog(dialogOptions); if (!layoutManager.tv) { dlg.classList.add('extraSpacing'); } dlg.classList.add('actionSheet'); var html = ''; html += '