mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
Merge pull request #455 from mgcrea/ios-actionsheet
Updated `iOS/ActionSheet` for Cordova-1.6.
This commit is contained in:
@@ -1,48 +1,45 @@
|
||||
//
|
||||
//
|
||||
// ActionSheet.js
|
||||
//
|
||||
// Created by Olivier Louvignes on 11/27/2011.
|
||||
// Added Cordova 1.5 support - @RandyMcMillan 2012
|
||||
//
|
||||
// Copyright 2011 Olivier Louvignes. All rights reserved.
|
||||
// MIT Licensed
|
||||
|
||||
function ActionSheet() {}
|
||||
|
||||
ActionSheet.prototype.create = function(title, items, fn, options) {
|
||||
ActionSheet.prototype.create = function(title, items, callback, options) {
|
||||
if(!options) options = {};
|
||||
var scope = options.scope || null;
|
||||
delete options.scope;
|
||||
|
||||
var service = 'ActionSheet',
|
||||
action = 'create',
|
||||
//callbackId = service + (PhoneGap.callbackId + 1);
|
||||
callbackId = service + (Cordova.callbackId + 1);
|
||||
callbackId = service + (cordova.callbackId + 1);
|
||||
|
||||
var config = {
|
||||
title : title+'' || '',
|
||||
title : title || '',
|
||||
items : items || ['Cancel'],
|
||||
callback : fn || function(){},
|
||||
scope: options.hasOwnProperty('scope') ? options.scope : null,
|
||||
style : options.hasOwnProperty('style') ? options.style+'' : 'default',
|
||||
destructiveButtonIndex : options.hasOwnProperty('destructiveButtonIndex') ? options.destructiveButtonIndex*1 : undefined,
|
||||
cancelButtonIndex : options.hasOwnProperty('cancelButtonIndex') ? options.cancelButtonIndex*1 : undefined
|
||||
style : options.style || 'default',
|
||||
destructiveButtonIndex : options.destructiveButtonIndex || undefined,
|
||||
cancelButtonIndex : options.cancelButtonIndex || undefined
|
||||
};
|
||||
|
||||
var callback = function(result) {
|
||||
var _callback = function(result) {
|
||||
var buttonValue = false, // value for cancelButton
|
||||
buttonIndex = result.buttonIndex;
|
||||
|
||||
if(!config.cancelButtonIndex || buttonIndex != config.cancelButtonIndex) {
|
||||
buttonValue = config.items[buttonIndex];
|
||||
}
|
||||
|
||||
config.callback.call(config.scope || null, buttonValue, buttonIndex);
|
||||
callback.call(scope, buttonValue, buttonIndex);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Cordova.exec(callback, callback, service, action, [config]);
|
||||
return cordova.exec(_callback, _callback, service, action, [config]);
|
||||
|
||||
};
|
||||
|
||||
Cordova.addConstructor(function() {
|
||||
if(!window.plugins) window.plugins = {};
|
||||
cordova.addConstructor(function() {
|
||||
if(!window.plugins) window.plugins = {};
|
||||
window.plugins.actionSheet = new ActionSheet();
|
||||
});
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
Added Cordova 1.5 support - @RandyMcMillan 2012
|
||||
|
||||
# PhoneGap ActionSheet Plugin #
|
||||
# Cordova ActionSheet Plugin #
|
||||
by `Olivier Louvignes`
|
||||
|
||||
## DESCRIPTION ##
|
||||
|
||||
* This plugin provides a simple way to use the `UIActionSheet` native component from IOS. It does comply with the latest (future-2.x) phonegap standards.
|
||||
* This plugin provides a simple way to use the `UIActionSheet` native component from IOS. It does comply with the latest (future-2.x) cordova standards.
|
||||
|
||||
* Compared to the `iPhone/NativeControls` plugin, it is more documented & simpler to understand (only handle actionSheets). It does also provide new options (style).
|
||||
|
||||
* There is a `Sencha Touch 2.0` plugin to easily leverage this plugin [here](https://github.com/mgcrea/sencha-touch-plugins/blob/master/PhonegapActionSheet.js)
|
||||
* There is a `Sencha Touch 2.0` plugin to easily leverage this plugin [here](https://github.com/mgcrea/sencha-touch-plugins/blob/master/CordovaActionSheet.js)
|
||||
|
||||
## SETUP ##
|
||||
|
||||
Using this plugin requires [iPhone PhoneGap](http://github.com/phonegap/phonegap-iphone).
|
||||
Using this plugin requires [Cordova iOS](https://github.com/apache/incubator-cordova-ios).
|
||||
|
||||
1. Make sure your PhoneGap Xcode project has been [updated for the iOS 4 SDK](http://wiki.phonegap.com/Upgrade-your-PhoneGap-Xcode-Template-for-iOS-4)
|
||||
1. Make sure your Xcode project has been [updated for Cordova](https://github.com/apache/incubator-cordova-ios/blob/master/guides/Cordova%20Upgrade%20Guide.md)
|
||||
2. Drag and drop the `ActionSheet` folder from Finder to your Plugins folder in XCode, using "Create groups for any added folders"
|
||||
3. Add the .js files to your `www` folder on disk, and add reference(s) to the .js files as <link> tags in your html file(s)
|
||||
4. Add new entry with key `ActionSheet` and value `ActionSheet` to `Plugins` in `PhoneGap.plist/Cordova.plist`
|
||||
3. Add the .js files to your `www` folder on disk, and add reference(s) to the .js files using <script> tags in your html file(s)
|
||||
|
||||
<script type="text/javascript" src="/js/plugins/ActionSheet.js"></script>
|
||||
|
||||
4. Add new entry with key `ActionSheet` and value `ActionSheet` to `Plugins` in `Cordova.plist/Cordova.plist`
|
||||
|
||||
## JAVASCRIPT INTERFACE ##
|
||||
|
||||
@@ -26,20 +27,24 @@ Using this plugin requires [iPhone PhoneGap](http://github.com/phonegap/phonegap
|
||||
var actionSheet = window.plugins.actionSheet;
|
||||
|
||||
// Basic with title
|
||||
actionSheet.create('Title', ['Foo', 'Bar'], function(buttonValue, buttonIndex) { console.warn('create', [this, arguments]); });
|
||||
actionSheet.create('Title', ['Foo', 'Bar'], function(buttonValue, buttonIndex) {
|
||||
console.warn('create(), arguments=' + Array.prototype.slice.call(arguments).join(', '));
|
||||
});
|
||||
|
||||
// Complex
|
||||
actionSheet.create(null, ['Add', 'Delete', 'Cancel'], function(buttonValue, buttonIndex) { console.warn('create', [this, arguments]); }, {destructiveButtonIndex: 1, cancelButtonIndex: 2});
|
||||
actionSheet.create(null, ['Add', 'Delete', 'Cancel'], function(buttonValue, buttonIndex) {
|
||||
console.warn('create(), arguments=' + Array.prototype.slice.call(arguments).join(', '));
|
||||
}, {destructiveButtonIndex: 1, cancelButtonIndex: 2});
|
||||
|
||||
* Check [source](http://github.com/mgcrea/phonegap-plugins/tree/master/iPhone/ActionSheet/ActionSheet.js) for additional configuration.
|
||||
* Check [source](http://github.com/mgcrea/phonegap-plugins/tree/master/iOS/ActionSheet/ActionSheet.js) for additional configuration.
|
||||
|
||||
## BUGS AND CONTRIBUTIONS ##
|
||||
|
||||
Patches welcome! Send a pull request. Since this is not a part of PhoneGap Core (which requires a CLA), this should be easier.
|
||||
Patches welcome! Send a pull request. Since this is not a part of Cordova Core (which requires a CLA), this should be easier.
|
||||
|
||||
Post issues on [Github](http://github.com/phonegap/phonegap-plugins/issues)
|
||||
Post issues on [Github](https://github.com/apache/incubator-cordova-ios/issues)
|
||||
|
||||
The latest code (my fork) will always be [here](http://github.com/mgcrea/phonegap-plugins/tree/master/iPhone/ActionSheet/)
|
||||
The latest code (my fork) will always be [here](http://github.com/mgcrea/phonegap-plugins/tree/master/iOS/ActionSheet)
|
||||
|
||||
## LICENSE ##
|
||||
|
||||
@@ -55,6 +60,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
## CREDITS ##
|
||||
|
||||
@RandyMcMillan - Added Initial Cordova 1.5 support - 2012
|
||||
|
||||
Inspired by :
|
||||
|
||||
* [NativeControls Phonegap plugin](https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/NativeControls)
|
||||
|
||||
Reference in New Issue
Block a user