Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GNURub committed Oct 18, 2014
1 parent 1d8b861 commit a533d4f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#<x-swal> element </x-swal>

An awesome replacement for JavaScript's alert.

[See it in action!](http://tristanedwards.me/sweetalert)

![A success modal](https://raw.github.com/t4t5/sweetalert/master/sweetalert.gif)

#Usage

You can install x-swal through bower:

```bash
bower install x-swall
```

Download the package and reference the Component file:

```html
<link rel="import" href="../x-swal/x-swal.html">
```
29 changes: 9 additions & 20 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h3>More examples</h3>
<div class="ui">
<p>... and by passing a parameter, you can execute something else for "Cancel".</p>
<button>Try me!</button>
<x-swal id="6" type="warning" showCancelButton="true" closeOnConfirm="false" closeOnCancel="false" >
<x-swal id="6" type="warning" showCancelButton="true" closeOnConfirm="false" closeOnCancel="false" >
<title>Are you sure?</title>
<text>Your will not be able to recover this imaginary file!</text>
<confirm>Yes, delete it!</confirm>
Expand Down Expand Up @@ -400,32 +400,21 @@ <h3>Contribute</h3>

document.querySelector('ul.examples li.warning.confirm button').onclick = function(){
var alert = document.querySelector('ul.examples li.warning.confirm x-swal');
alert.active();
alert.addEventListener('confirmation', function(){
alert.title = "Deleted!";
alert.text = "Your imaginary file has been deleted!";
alert.type = "success";
alert.active();
}, false);
alert.active(function(){

});
};

document.querySelector('ul.examples li.warning.cancel button').onclick = function(){

var alert = document.querySelector('ul.examples li.warning.cancel x-swal');
alert.active();
alert.addEventListener('confirmation', function(isConfirm){
console.log(isConfirm);
if (isConfirm){
alert.title = "Deleted!";
alert.text = "Your imaginary file has been deleted!";
alert.type = "success";
alert.active(function(status){
if (status) {

}else{
alert.title = "Cancelled";
alert.text = "Your imaginary file is safe :)";
alert.type = "error";

}
alert.active();
}, false);
});
};

document.querySelector('ul.examples li.custom-icon button').onclick = function(){
Expand Down
15 changes: 10 additions & 5 deletions x-swal.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
*
* @method active
*/
active: function() {
active: function(cb) {
swal({
title: this.title || '',
text: this.text || '',
Expand All @@ -115,10 +115,15 @@
closeOnCancel: this.closeOnCancel,
imageUrl: this.img || ''
}, function(isConfirm){
console.log(isConfirm);
setTimeout(function(){
this.fire('confirmation', isConfirm);
}.bind(this), 500);
this.fire('confirmation', isConfirm);
if(cb && typeof cb === "function"){
return cb(isConfirm);
}
return;
// console.log(isConfirm);
// setTimeout(function(){
// this.fire('confirmation', isConfirm);
// }.bind(this), 500);
}.bind(this));
}
});
Expand Down

0 comments on commit a533d4f

Please sign in to comment.