Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions js/angular/service/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
//DEPRECATED: notify the promise with an object with a close method
popup.responseDeferred.notify({ close: popup.responseDeferred.close });

// if any keypress handlers were requested, go ahead and assign them now
// options.keyPressHandlers is the user-generated assoc: keycode => function()
// popup.keyPressHandlers is a list of event-listener handles returned by addEventListener()
// and is used to unbind these event listeners when the popup is closing ("then" block below)
popup.element[0].keyPressHandlers = options.keyPressHandlers ? options.keyPressHandlers : {};
popup.keylistener = window.addEventListener('keypress', function (keyEvent) {
var userfunc = popup.element[0].keyPressHandlers[keyEvent.keyCode];
if (userfunc) userfunc(popup);
});

doShow();

return popup.responseDeferred.promise;
Expand All @@ -405,6 +415,8 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
popupStack.splice(index, 1);
}

window.removeEventListener('keypress', popup.keylistener);

popup.remove();

if (popupStack.length > 0) {
Expand Down Expand Up @@ -438,7 +450,23 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
}

function showAlert(opts) {
var keyPressHandlers = {
"13": function (popup) { // 13 = Enter = OK
var button = popup.scope.buttons[0];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
},
"27": function (popup) { // 27 = Esc = Cancel
var button = popup.scope.buttons[0];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
}
};

return showPopup(extend({
keyPressHandlers: keyPressHandlers,
buttons: [{
text: opts.okText || 'OK',
type: opts.okType || 'button-positive',
Expand All @@ -450,7 +478,23 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
}

function showConfirm(opts) {
var keyPressHandlers = {
"13": function (popup) { // 13 = Enter = OK
var button = popup.scope.buttons[1];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
},
"27": function (popup) { // 27 = Esc = Cancel
var button = popup.scope.buttons[0];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
}
};

return showPopup(extend({
keyPressHandlers: keyPressHandlers,
buttons: [{
text: opts.cancelText || 'Cancel',
type: opts.cancelType || 'button-default',
Expand All @@ -470,12 +514,30 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
scope.data.response = opts.defaultText ? opts.defaultText : '';
scope.data.placeholder = opts.inputPlaceholder ? opts.inputPlaceholder : '';
scope.data.maxlength = opts.maxLength ? parseInt(opts.maxLength) : '';

var text = '';
if (opts.template && /<[a-z][\s\S]*>/i.test(opts.template) === false) {
text = '<span>' + opts.template + '</span>';
delete opts.template;
}

var keyPressHandlers = {
"13": function (popup) { // 13 = Enter = OK
var button = popup.scope.buttons[1];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
},
"27": function (popup) { // 27 = Esc = Cancel
var button = popup.scope.buttons[0];
var tapper = popup.scope.$buttonTapped;
var fclick = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true });
tapper(button, fclick);
}
};

return showPopup(extend({
keyPressHandlers: keyPressHandlers,
template: text + '<input ng-model="data.response" '
+ 'type="{{ data.fieldtype }}"'
+ 'maxlength="{{ data.maxlength }}"'
Expand Down