diff --git a/src/components/actionSheet/actionSheet.js b/src/components/actionSheet/actionSheet.js index 0d9f65a31a..95857035e5 100644 --- a/src/components/actionSheet/actionSheet.js +++ b/src/components/actionSheet/actionSheet.js @@ -11,362 +11,357 @@ import 'listViewStyle'; function getOffsets(elems) { - var doc = document; - var results = []; + var doc = document; + var results = []; - if (!doc) { - return results; - } + if (!doc) { + return results; + } - var box; - var elem; + var box; + var elem; - for (var i = 0, length = elems.length; i < length; i++) { + 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 }; - } + 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, - width: box.width, - height: box.height - }; - } + results[i] = { + top: box.top, + left: box.left, + width: box.width, + height: box.height + }; + } - return results; + return results; } function getPosition(options, dlg) { - var windowSize = dom.getWindowSize(); - var windowHeight = windowSize.innerHeight; - var windowWidth = windowSize.innerWidth; + var windowSize = dom.getWindowSize(); + var windowHeight = windowSize.innerHeight; + var windowWidth = windowSize.innerWidth; - var pos = getOffsets([options.positionTo])[0]; + var pos = getOffsets([options.positionTo])[0]; - if (options.positionY !== 'top') { - pos.top += (pos.height || 0) / 2; - } + if (options.positionY !== 'top') { + pos.top += (pos.height || 0) / 2; + } - pos.left += (pos.width || 0) / 2; + pos.left += (pos.width || 0) / 2; - var height = dlg.offsetHeight || 300; - var width = dlg.offsetWidth || 160; + var height = dlg.offsetHeight || 300; + var width = dlg.offsetWidth || 160; - // Account for popup size - pos.top -= height / 2; - pos.left -= width / 2; + // Account for popup size + pos.top -= height / 2; + pos.left -= width / 2; - // Avoid showing too close to the bottom - var overflowX = pos.left + width - windowWidth; - var overflowY = pos.top + height - windowHeight; + // Avoid showing too close to the bottom + var overflowX = pos.left + width - windowWidth; + var overflowY = pos.top + height - windowHeight; - if (overflowX > 0) { - pos.left -= (overflowX + 20); - } - if (overflowY > 0) { - pos.top -= (overflowY + 20); - } + if (overflowX > 0) { + pos.left -= (overflowX + 20); + } + if (overflowY > 0) { + pos.top -= (overflowY + 20); + } - pos.top += (options.offsetTop || 0); - pos.left += (options.offsetLeft || 0); + pos.top += (options.offsetTop || 0); + pos.left += (options.offsetLeft || 0); - // Do some boundary checking - pos.top = Math.max(pos.top, 10); - pos.left = Math.max(pos.left, 10); + // Do some boundary checking + pos.top = Math.max(pos.top, 10); + pos.left = Math.max(pos.left, 10); - return pos; + return pos; } function centerFocus(elem, horiz, on) { - require(['scrollHelper'], function (scrollHelper) { - var fn = on ? 'on' : 'off'; - scrollHelper.centerFocus[fn](elem, horiz); - }); + require(['scrollHelper'], function (scrollHelper) { + var fn = on ? 'on' : 'off'; + scrollHelper.centerFocus[fn](elem, horiz); + }); } export function show(options) { - // items - // positionTo - // showCancel - // title - var dialogOptions = { - removeOnClose: true, - enableHistory: options.enableHistory, - scrollY: false - }; - - var backButton = false; - var isFullscreen; - - if (layoutManager.tv) { - dialogOptions.size = 'fullscreen'; - isFullscreen = true; - backButton = true; - dialogOptions.autoFocus = true; - } else { - - dialogOptions.modal = false; - dialogOptions.entryAnimation = options.entryAnimation; - dialogOptions.exitAnimation = options.exitAnimation; - dialogOptions.entryAnimationDuration = options.entryAnimationDuration || 140; - dialogOptions.exitAnimationDuration = options.exitAnimationDuration || 100; - dialogOptions.autoFocus = false; - } - - var dlg = dialogHelper.createDialog(dialogOptions); - - if (isFullscreen) { - dlg.classList.add('actionsheet-fullscreen'); - } else { - dlg.classList.add('actionsheet-not-fullscreen'); - } - - dlg.classList.add('actionSheet'); - - if (options.dialogClass) { - dlg.classList.add(options.dialogClass); - } - - var html = ''; - - var scrollClassName = layoutManager.tv ? 'scrollY smoothScrollY hiddenScrollY' : 'scrollY'; - var style = ''; + // items + // positionTo + // showCancel + // title + var dialogOptions = { + removeOnClose: true, + enableHistory: options.enableHistory, + scrollY: false + }; + + var backButton = false; + var isFullscreen; + + if (layoutManager.tv) { + dialogOptions.size = 'fullscreen'; + isFullscreen = true; + backButton = true; + dialogOptions.autoFocus = true; + } else { + + dialogOptions.modal = false; + dialogOptions.entryAnimation = options.entryAnimation; + dialogOptions.exitAnimation = options.exitAnimation; + dialogOptions.entryAnimationDuration = options.entryAnimationDuration || 140; + dialogOptions.exitAnimationDuration = options.exitAnimationDuration || 100; + dialogOptions.autoFocus = false; + } + + var dlg = dialogHelper.createDialog(dialogOptions); + + if (isFullscreen) { + dlg.classList.add('actionsheet-fullscreen'); + } else { + dlg.classList.add('actionsheet-not-fullscreen'); + } + + dlg.classList.add('actionSheet'); + + if (options.dialogClass) { + dlg.classList.add(options.dialogClass); + } + + var html = ''; + + var scrollClassName = layoutManager.tv ? 'scrollY smoothScrollY hiddenScrollY' : 'scrollY'; + var style = ''; - // Admittedly a hack but right now the scrollbar is being factored into the width which is causing truncation - if (options.items.length > 20) { - var minWidth = dom.getWindowSize().innerWidth >= 300 ? 240 : 200; - style += "min-width:" + minWidth + "px;"; - } - - var i; - var length; - var option; - var renderIcon = false; - var icons = []; - var itemIcon; - for (i = 0, length = options.items.length; i < length; i++) { - - option = options.items[i]; - - itemIcon = option.icon || (option.selected ? 'check' : null); - - if (itemIcon) { - renderIcon = true; - } - icons.push(itemIcon || ''); - } - - if (layoutManager.tv) { - html += ''; - } - - // If any items have an icon, give them all an icon just to make sure they're all lined up evenly - var center = options.title && (!renderIcon /*|| itemsWithIcons.length != options.items.length*/); - - if (center || layoutManager.tv) { - html += '
'; - html += options.text; - html += '
'; - } - - var scrollerClassName = 'actionSheetScroller'; - if (layoutManager.tv) { - scrollerClassName += ' actionSheetScroller-tv focuscontainer-x focuscontainer-y'; - } - html += ''; + html += options.text; + html += '
'; + } + + var scrollerClassName = 'actionSheetScroller'; + if (layoutManager.tv) { + scrollerClassName += ' actionSheetScroller-tv focuscontainer-x focuscontainer-y'; + } + html += '