Skip to content

Commit

Permalink
update(plugin): Updated cordova to 2.2.0 & refactored JS interface #b…
Browse files Browse the repository at this point in the history
…reaking
  • Loading branch information
mgcrea committed Nov 3, 2012
1 parent d68b920 commit c3d75bd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cordova/cordova-ios
Submodule cordova-ios updated from cbee72 to 54efb8
7 changes: 4 additions & 3 deletions samples/ios/create.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
INFO="\033[32m\033[1m[INFO]\033[22m\033[39m"

echo -ne "Please enter plugin name: [MessageBox] "
echo -ne "$INFO Please enter plugin name: [MessageBox] "
read $pluginName;
if [[ -z $pluginName ]]; then pluginName="MessageBox"; fi;

Expand All @@ -10,7 +11,7 @@ fi;

path=samples/ios/$pluginName;
rm -rf $path
cordova/cordova-ios/bin/create $path org.apache.cordova.plugins.$pluginName $pluginName
cordova/cordova-ios/bin/create --shared $path org.apache.cordova.plugins.$pluginName $pluginName

cp www/*.js $path/www/js;
cp samples/ios/www/*.js $path/www/js;
Expand All @@ -19,4 +20,4 @@ cp samples/ios/www/*.html $path/www;
ln -s ./../../../../../src/ios $path/$pluginName/Plugins/$pluginName;
sed "/<key>Device<\/key>/i\ \t\t<key>$pluginName<\/key>\n\t\t<string>$pluginName<\/string>" -i $path/$pluginName/Cordova.plist

echo -ne "Drag \"Plugins/$pluginName\" folder to XCode then build/run.\n"
echo -ne "$INFO Drag \"Plugins/$pluginName\" folder to Xcode \"Plugins\" folder then build/run.\n"
2 changes: 1 addition & 1 deletion samples/ios/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h3>MessageBox Plugin</h3>
<a href="#" class="btn large" onclick="plugin.promptPassword();">promptPassword()</a>
</div>
</div>
<script type="text/javascript" src="cordova-2.1.0rc2.js"></script>
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/plugin.js"></script>
<script type="text/javascript" src="js/MessageBox.js"></script>
Expand Down
22 changes: 17 additions & 5 deletions samples/ios/www/plugin.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@

var plugin = {

alert: function() {
window.plugins.messageBox.alert('Title', 'Message', function(button) {
window.plugins.messageBox.alert({title: 'Title', message: 'Message'}, function(button) {
var args = Array.prototype.slice.call(arguments, 0);
console.log("messageBox.alert:" + JSON.stringify(args));
});
},

confirm: function() {
window.plugins.messageBox.confirm('Title', 'Message', function(button) {
window.plugins.messageBox.confirm({title: 'Title', message: 'Message'}, function(button) {
var args = Array.prototype.slice.call(arguments, 0);
console.log("messageBox.confirm:" + JSON.stringify(args));
});
},

prompt : function() {
window.plugins.messageBox.prompt('Title', 'Message', function(button, value) {
window.plugins.messageBox.prompt({title: 'Title', message: 'Message'}, function(button, value) {
var args = Array.prototype.slice.call(arguments, 0);
console.log("messageBox.prompt:" + JSON.stringify(args));
});
},

promptPassword : function() {
window.plugins.messageBox.prompt('Please enter your password', '', function(button, value) {

var options = {
title: 'Please enter your password',
placeholder: 'password',
type: 'password'
}

window.plugins.messageBox.prompt(options, function(button, value) {
var args = Array.prototype.slice.call(arguments, 0);
console.log("messageBox.prompt:" + JSON.stringify(args));
}, {placeholder: 'password', type: 'password'});
});
}

};
Empty file modified src/ios/MessageBox.h
100755 → 100644
Empty file.
Empty file modified src/ios/MessageBox.m
100755 → 100644
Empty file.
54 changes: 32 additions & 22 deletions www/MessageBox.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,61 @@

function MessageBox() {}

console.warn('in');
MessageBox.prototype.defaults = {
okButtonTitle: 'OK',
yesButtonTitle: 'Yes',
noButtonTitle: 'No',
cancelButtonTitle: 'Cancel'
};

MessageBox.prototype.alert = function(options, callback) {
options || (options = {});
var scope = options.scope || null;

MessageBox.prototype.alert = function(title, message, callback, options) {
if(!options) options = {};
var config = {
scope: options.scope || null,
okButtonTitle: options.okButtonTitle || 'OK'
title: options.title || '',
message: options.message || '',
okButtonTitle: options.okButtonTitle || this.defaults.okButtonTitle
};

var _callback = function(buttonIndex) {
var button = 'ok';
if(typeof callback == 'function') callback.call(config.scope, button);
if(typeof callback == 'function') callback.call(scope, button);
};

return navigator.notification.alert(message, _callback, title, config.okButtonTitle + '');
return navigator.notification.alert(config.message, _callback, config.title, config.okButtonTitle + '');
};

MessageBox.prototype.confirm = function(title, message, callback, options) {
if(!options) options = {};
MessageBox.prototype.confirm = function(options, callback) {
options || (options = {});
var scope = options.scope || null;

var config = {
scope: options.scope || null,
yesButtonTitle: options.yesButtonTitle || 'Yes',
noButtonTitle: options.noButtonTitle || 'No'
title: options.title || '',
message: options.message || '',
yesButtonTitle: options.yesButtonTitle || this.defaults.yesButtonTitle,
noButtonTitle: options.noButtonTitle || this.defaults.noButtonTitle
};

var _callback = function(buttonIndex) {
var button = (buttonIndex === 2) ? 'yes' : 'no';
if(typeof callback == 'function') callback.call(config.scope, button);
if(typeof callback == 'function') callback.call(scope, button);
};

return navigator.notification.confirm(message, _callback, title, config.noButtonTitle + ', ' + config.yesButtonTitle);
return navigator.notification.confirm(config.message, _callback, config.title, config.noButtonTitle + ', ' + config.yesButtonTitle);
};

MessageBox.prototype.prompt = function(title, message, callback, options) {
if(!options) options = {};
MessageBox.prototype.prompt = function(options, callback) {
options || (options = {});
var scope = options.scope || null;
delete options.scope;

var config = {
okButtonTitle: options.okButtonTitle || 'OK',
cancelButtonTitle: options.cancelButtonTitle || 'Cancel',
title : title || 'Prompt',
message : message || '',
title: options.title || '',
message: options.message || '',
type : options.type || 'text',
placeholder : options.placeholder || ''
placeholder : options.placeholder || '',
okButtonTitle: options.okButtonTitle || this.defaults.okButtonTitle,
cancelButtonTitle: options.cancelButtonTitle || this.defaults.cancelButtonTitle
};

var _callback = function(result) {
Expand Down

0 comments on commit c3d75bd

Please sign in to comment.