jellyfin-web/dashboard-ui/cordova/actionsheet.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-06-19 09:36:51 -07:00
(function () {
function show(options) {
// items
// positionTo
// showCancel
// title
2015-07-20 21:22:46 -07:00
// If any items have an icon, give them all an icon just to make sure they're all lined up evenly
var renderIcon = options.items.filter(function (o) {
2015-07-28 20:42:03 -07:00
return o.ironIcon == 'check';
2015-07-20 21:22:46 -07:00
}).length;
if (renderIcon) {
2015-07-28 20:42:03 -07:00
for (var i = 0, length = options.items.length; i < length; i++) {
2015-07-20 21:22:46 -07:00
2015-07-28 20:42:03 -07:00
var option = options.items[i];
2015-07-20 21:22:46 -07:00
2015-07-28 20:42:03 -07:00
switch (option.ironIcon) {
2015-07-20 21:22:46 -07:00
2015-07-28 20:42:03 -07:00
case 'check':
option.name = '• ' + option.name;
break;
default:
option.name = ' ' + option.name;
break;
2015-07-20 21:22:46 -07:00
}
}
}
2015-06-19 09:36:51 -07:00
var innerOptions = {
'title': options.title,
'buttonLabels': options.items.map(function (i) {
return i.name;
})
};
2015-06-19 15:01:47 -07:00
// Show cancel unless the caller explicitly set it to false
if (options.showCancel !== false) {
2015-06-19 09:36:51 -07:00
innerOptions.addCancelButtonWithLabel = Globalize.translate('ButtonCancel');
}
// Depending on the buttonIndex, you can now call shareViaFacebook or shareViaTwitter
// of the SocialSharing plugin (https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin)
window.plugins.actionsheet.show(innerOptions, function (index) {
if (options.callback) {
2015-07-06 19:25:23 -07:00
// Results are 1-based
if (index >= 1 && options.items.length >= index) {
2015-07-20 21:22:46 -07:00
2015-06-19 09:36:51 -07:00
options.callback(options.items[index - 1].id);
}
}
});
}
window.ActionSheetElement = {
show: show
};
})();