Skip to content

Commit

Permalink
Merge branch '0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
t4t5 committed Oct 21, 2014
2 parents b765d7b + 6412535 commit 5359ee6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 51 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h3>More examples</h3>
</div>
<pre>swal({
&nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
&nbsp;&nbsp;text: <span class="str">"Your will not be able to recover this imaginary file!"</span>,
&nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
&nbsp;&nbsp;type: <span class="str">"warning"</span>,
&nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
&nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
Expand All @@ -107,7 +107,7 @@ <h3>More examples</h3>
</div>
<pre>swal({
&nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
&nbsp;&nbsp;text: <span class="str">"Your will not be able to recover this imaginary file!"</span>,
&nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
&nbsp;&nbsp;type: <span class="str">"warning"</span>,
&nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
&nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions lib/sweet-alert.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
background-color: #b6b6b6; }
.sweet-alert button.cancel:focus {
box-shadow: rgba(197, 205, 211, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.0470588) 0px 0px 0px 1px inset !important; }
.sweet-alert button::-moz-focus-inner {
border: 0; }
.sweet-alert[data-has-cancel-button=false] button {
box-shadow: none !important; }
.sweet-alert .icon {
Expand Down Expand Up @@ -153,6 +155,7 @@
width: 60px;
height: 120px;
background: white;
-webkit-transform: rotate(45deg);
transform: rotate(45deg); }
.sweet-alert .icon.success::before {
border-radius: 120px 0 0 120px;
Expand Down
106 changes: 63 additions & 43 deletions lib/sweet-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@

var modalClass = '.sweet-alert',
overlayClass = '.sweet-overlay',
alertTypes = ['error', 'warning', 'info', 'success'];
alertTypes = ['error', 'warning', 'info', 'success'],
defaultParams = {
title: '',
text: '',
type: null,
allowOutsideClick: false,
showCancelButton: false,
closeOnConfirm: true,
closeOnCancel: true,
confirmButtonText: 'OK',
confirmButtonColor: '#AEDEF4',
cancelButtonText: 'Cancel',
imageUrl: null,
imageSize: null
};


/*
Expand Down Expand Up @@ -160,7 +174,7 @@
* Add modal + overlay to DOM
*/

function initialize() {
window.sweetAlertInitialize = function() {
var sweetHTML = '<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert" tabIndex="-1"><div class="icon error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="icon warning"> <span class="body"></span> <span class="dot"></span> </div> <div class="icon info"></div> <div class="icon success"> <span class="line tip"></span> <span class="line long"></span> <div class="placeholder"></div> <div class="fix"></div> </div> <div class="icon custom"></div> <h2>Title</h2><p>Text</p><button class="cancel" tabIndex="2">Cancel</button><button class="confirm" tabIndex="1">OK</button></div>',
sweetWrap = document.createElement('div');

Expand All @@ -171,43 +185,25 @@

// For development use only!
/*jQuery.ajax({
url: '../lib/sweet-alert.html', // Change path depending on file location
dataType: 'html'
})
.done(function(html) {
jQuery('body').append(html);
});*/
url: '../lib/sweet-alert.html', // Change path depending on file location
dataType: 'html'
})
.done(function(html) {
jQuery('body').append(html);
});*/
}



/*
* Global sweetAlert function
*/

window.sweetAlert = window.swal = function() {

// Default parameters
var params = {
title: '',
text: '',
type: null,
allowOutsideClick: false,
showCancelButton: false,
closeOnConfirm: true,
closeOnCancel: true,
confirmButtonText: 'OK',
confirmButtonColor: '#AEDEF4',
cancelButtonText: 'Cancel',
imageUrl: null,
imageSize: null
};

if (arguments[0] === undefined) {
window.console.error('sweetAlert expects at least 1 attribute!');
return false;
}

var params = extend({}, defaultParams);

switch (typeof arguments[0]) {

Expand All @@ -225,21 +221,21 @@
}

params.title = arguments[0].title;
params.text = arguments[0].text || params.text;
params.type = arguments[0].type || params.type;
params.allowOutsideClick = arguments[0].allowOutsideClick || params.allowOutsideClick;
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : params.showCancelButton;
params.closeOnConfirm = arguments[0].closeOnConfirm !== undefined ? arguments[0].closeOnConfirm : params.closeOnConfirm;
params.closeOnCancel = arguments[0].closeOnCancel !== undefined ? arguments[0].closeOnCancel : params.closeOnCancel;
params.text = arguments[0].text || defaultParams.text;
params.type = arguments[0].type || defaultParams.type;
params.allowOutsideClick = arguments[0].allowOutsideClick || defaultParams.allowOutsideClick;
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : defaultParams.showCancelButton;
params.closeOnConfirm = arguments[0].closeOnConfirm !== undefined ? arguments[0].closeOnConfirm : defaultParams.closeOnConfirm;
params.closeOnCancel = arguments[0].closeOnCancel !== undefined ? arguments[0].closeOnCancel : defaultParams.closeOnCancel;

// Show "Confirm" instead of "OK" if cancel button is visible
params.confirmButtonText = (params.showCancelButton) ? 'Confirm' : params.confirmButtonText;
params.confirmButtonText = (defaultParams.showCancelButton) ? 'Confirm' : defaultParams.confirmButtonText;

params.confirmButtonText = arguments[0].confirmButtonText || params.confirmButtonText;
params.confirmButtonColor = arguments[0].confirmButtonColor || params.confirmButtonColor;
params.cancelButtonText = arguments[0].cancelButtonText || params.cancelButtonText;
params.imageUrl = arguments[0].imageUrl || params.imageUrl;
params.imageSize = arguments[0].imageSize || params.imageSize;
params.confirmButtonText = arguments[0].confirmButtonText || defaultParams.confirmButtonText;
params.confirmButtonColor = arguments[0].confirmButtonColor || defaultParams.confirmButtonColor;
params.cancelButtonText = arguments[0].cancelButtonText || defaultParams.cancelButtonText;
params.imageUrl = arguments[0].imageUrl || defaultParams.imageUrl;
params.imageSize = arguments[0].imageSize || defaultParams.imageSize;
params.doneFunction = arguments[1] || null;

break;
Expand Down Expand Up @@ -464,6 +460,20 @@
};
};

/**
* Set default params for each popup
* @param {Object} userParams
*/
window.swal.setDefaults = function(userParams) {
if (!userParams) {
throw new Error('userParams is required');
}
if (typeof userParams !== 'object') {
throw new Error('userParams has to be a object');
}

extend(defaultParams, userParams);
};

/*
* Set type, text and actions on modal
Expand Down Expand Up @@ -606,6 +616,16 @@
return rgb;
}

function extend(a, b){
for (var key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
}
}

return a;
}

function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? parseInt(result[1], 16) + ', ' + parseInt(result[2], 16) + ', ' + parseInt(result[3], 16) : null;
Expand Down Expand Up @@ -692,19 +712,19 @@
*/

(function () {
if (document.readyState === "complete" || document.readyState === "interactive") {
initialize();
if (document.readyState === "complete" || document.readyState === "interactive" && document.body) {
sweetAlertInitialize();
} else {
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function factorial() {
document.removeEventListener('DOMContentLoaded', arguments.callee, false);
initialize();
sweetAlertInitialize();
}, false);
} else if (document.attachEvent) {
document.attachEvent('onreadystatechange', function() {
if (document.readyState === 'complete') {
document.detachEvent('onreadystatechange', arguments.callee);
initialize();
sweetAlertInitialize();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sweet-alert.min.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions lib/sweet-alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
box-shadow: rgba(197, 205, 211, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.0470588) 0px 0px 0px 1px inset !important;
}
}
// Removes selection outline in Firefox
&::-moz-focus-inner {
border: 0;
}
}

// Only show focus-style when there is multiple choice of actions
Expand Down Expand Up @@ -213,6 +217,7 @@
width: 60px;
height: 120px;
background: white;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
&::before {
Expand All @@ -221,7 +226,7 @@
left: -33px;

-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 60px 60px;
transform-origin: 60px 60px;
}
Expand Down Expand Up @@ -274,7 +279,7 @@

&.tip {
width: 25px;

left: 14px;
top: 46px;

Expand All @@ -283,7 +288,7 @@
}
&.long {
width: 47px;

right: 8px;
top: 38px;

Expand All @@ -303,8 +308,6 @@

}



/*
* Animations
*/
Expand Down

0 comments on commit 5359ee6

Please sign in to comment.