add optional Parameter to confirmOptions

This commit is contained in:
allipierre
2017-11-20 17:08:07 +01:00
parent 1558ac449a
commit 96df8480f9
5 changed files with 52 additions and 203 deletions
+3
View File
@@ -23,5 +23,8 @@
"devDependencies": {
"dtslint": "github:Microsoft/dtslint#production",
"types-publisher": "Microsoft/types-publisher#production"
},
"dependencies": {
"@types/jquery": "^3.2.16"
}
}
+4 -4
View File
@@ -5,10 +5,10 @@
interface JQueryStatic {
/**
* confirm Dialog
* confirm Dialog
* @param {confirmOptions} pOtions
*/
confirm( pOtions: options.confirmOptions | string, title?:string): boolean | void | any;
confirm( pOtions: options.confirmOptions | string, title?:string): boolean | void | HTMLElement | any;
/**
* confirm alert
@@ -29,7 +29,7 @@ interface JQuery {
* confirm Dialog
* @param {confirmOptions} pOtions
*/
confirm( pOtions: options.confirmOptions | string, title?:string): boolean | void | any;
confirm( pOtions: options.confirmOptions | string, title?:string): boolean | void | HTMLElement | any;
/**
* confirm alert
@@ -72,7 +72,7 @@ declare namespace options {
dragWindowBorder?: boolean,
dragWindowGap?: number,
contentLoaded?: Function,
autoClose?: String,
autoClose?: string,
backgroundDismiss?: boolean | Function | string,
backgroundDismissAnimation?: string,
escapeKey?: string | boolean,
+10 -195
View File
@@ -63,7 +63,7 @@ class Confirm implements server.Iperson {
text: 'Submit',
btnClass: 'btn-blue',
action: function() {
let name = this.$content.find('.name').val();
let name;
if (!name) {
$.alert('provide a valid name');
return false;
@@ -76,13 +76,7 @@ class Confirm implements server.Iperson {
},
},
onContentReady: function() {
// bind to events
var jc = this;
this.$content.find('form').on('submit', function(e) {
// if the user submits the form by pressing enter in the field.
e.preventDefault();
jc.$$formSubmit.trigger('click'); // reference the button and click it
});
}
});
@@ -128,11 +122,11 @@ class Confirm implements server.Iperson {
public confirm_5() {
$.confirm({
buttons: {
hello: function(helloButton) {
hello: function(helloButton:string) {
// shorthand method to define a button
// the button key will be used as button name
},
hey: function(heyButton) {
hey: function(heyButton:string) {
// access the button using jquery
this.$$hello.trigger('click'); // click the 'hello' button
this.$$hey.prop('disabled', true); // disable the current button using jquery method
@@ -150,7 +144,7 @@ class Confirm implements server.Iperson {
keys: ['enter', 'a'], // keyboard event for button
isHidden: false, // initially not hidden
isDisabled: false, // initially not disabled
action: function(heyThereButton) {
action: function(heyThereButton:string) {
// longhand method to define a button
// provides more features
}
@@ -205,21 +199,12 @@ class Confirm implements server.Iperson {
buttons: {
buttonA: {
text: 'button a',
action: function(buttonA) {
this.buttons.resetButton.setText('reset button!!!');
this.buttons.resetButton.disable();
this.buttons.resetButton.enable();
this.buttons.resetButton.hide();
this.buttons.resetButton.show();
this.buttons.resetButton.addClass('btn-red');
this.buttons.resetButton.removeClass('btn-red');
// or
this.$$resetButton // button's jquery element reference, go crazy
this.buttons.buttonA == buttonA // both are the same.
action: function(buttonA:HTMLElement) {
return false; // prevent the modal from closing
}
},
resetButton: function(resetButton) {}
resetButton: function(resetButton:HTMLElement) {}
}
});
}
@@ -340,133 +325,7 @@ class Confirm implements server.Iperson {
});
}
public ajaxLoading() {
$.confirm({
title: 'Title',
content: 'url:text.txt',
onContentReady: function() {
var self = this;
this.setContentPrepend('<div>Prepended text</div>');
setTimeout(function() {
self.setContentAppend('<div>Appended text after 2 seconds</div>');
}, 2000);
},
columnClass: 'medium',
});
$.confirm({
content: function() {
var self = this;
return $.ajax({
url: 'bower.json',
dataType: 'json',
method: 'get'
}).done(function(response) {
self.setContent('Description: ' + response.description);
self.setContentAppend('<br>Version: ' + response.version);
self.setTitle(response.name);
}).fail(function() {
self.setContent('Something went wrong.');
});
}
});
$.confirm({
content: 'url:text.txt',
contentLoaded: function(data, status, xhr) {
// data is already set in content
this.setContentAppend('<br>Status: ' + status);
}
});
$.confirm({
content: function() {
var self = this;
self.setContent('Checking callback flow');
return $.ajax({
url: 'bower.json',
dataType: 'json',
method: 'get'
}).done(function(response) {
self.setContentAppend('<div>Done!</div>');
}).fail(function() {
self.setContentAppend('<div>Fail!</div>');
}).always(function() {
self.setContentAppend('<div>Always!</div>');
});
},
contentLoaded: function(data, status, xhr) {
self.setContentAppend('<div>Content loaded!</div>');
},
onContentReady: function() {
this.setContentAppend('<div>Content ready!</div>');
}
});
}
public autoClose() {
$.confirm({
title: 'Delete user?',
content: 'This dialog will automatically trigger \'cancel\' in 6 seconds if you don\'t respond.',
autoClose: 'cancelAction|8000',
buttons: {
deleteUser: {
text: 'delete user',
action: function() {
$.alert('Deleted the user!');
}
},
cancelAction: function() {
$.alert('action is canceled');
}
}
});
$.confirm({
title: 'Logout?',
content: 'Your time is out, you will be automatically logged out in 10 seconds.',
autoClose: 'logoutUser|10000',
buttons: {
logoutUser: {
text: 'logout myself',
action: function() {
$.alert('The user was logged out');
}
},
cancel: function() {
$.alert('canceled');
}
}
});
}
public backgroundDismisse() {
$.confirm({
backgroundDismiss: true, // this will just close the modal
});
$.confirm({
backgroundDismiss: function() {
return false; // modal wont close.
},
});
$.confirm({
backgroundDismiss: function() {
return 'buttonName'; // the button will handle it
},
});
$.confirm({
backgroundDismiss: 'buttonName',
content: 'in here the backgroundDismiss action is handled by buttonName' +
'<div class="checkbox"><label><input type="checkbox" id="enableCheckbox"> Enable backgroundDismiss</label></div>',
buttons: {
buttonName: function() {
var $checkbox = this.$content.find('#enableCheckbox');
return $checkbox.prop('checked');
},
close: function() {}
}
});
}
public backgroundDismisseAnimation(){
$.confirm({
@@ -519,50 +378,7 @@ $.confirm({
}
public callBack(){
$.confirm({
title: false,
content: 'url:callback.html',
onContentReady: function () {
// when content is fetched & rendered in DOM
alert('onContentReady');
var self = this;
this.buttons.ok.disable();
this.$content.find('.btn').click(function(){
self.$content.find('input').val('Chuck norris');
self.buttons.ok.enable();
});
},
contentLoaded: function(data, status, xhr){
// when content is fetched
alert('contentLoaded: ' + status);
},
onOpenBefore: function () {
// before the modal is displayed.
alert('onOpenBefore');
},
onOpen: function () {
// after the modal is displayed.
alert('onOpen');
},
onClose: function () {
// before the modal is hidden.
alert('onClose');
},
onDestroy: function () {
// when the modal is removed from DOM
alert('onDestroy');
},
onAction: function (btnName) {
// when a button is clicked, with the button name
alert('onAction: ' + btnName);
},
buttons: {
ok: function(){
}
}
});
}
public globalSettings(){
jconfirm.defaults = {
title: 'Hello',
@@ -586,8 +402,7 @@ $.confirm({
}
},
},
contentLoaded: function(data, status, xhr){
},
icon: '',
lazyOpen: false,
bgOpacity: null,
+4 -3
View File
@@ -2,13 +2,14 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"baseUrl": "types",
"typeRoots": ["types"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
+31 -1
View File
@@ -1 +1,31 @@
{ "extends": "dtslint/dt.json" }
{
"rules": {
"max-line-length": {
"options": [
120
]
},
"new-parens": true,
"no-arg": true,
"no-bitwise": true,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": false,
"no-console": {
"options": [
"debug",
"info",
"log",
"time",
"timeEnd",
"trace"
]
}
},
"jsRules": {
"max-line-length": {
"options": [
120
]
}
}
}