Extending jQuery UI Dialog
original: http://jsfiddle.net/addyosmani/GxVg2/
HTML
<link rel="stylesheet" href="http://static-stage.maklarpaket.se/admin/css/jquery-ui-custom.css">
<div id="header"></div>
<div id="body">
<h1>Extending jQuery UI Dialog</h1>
<h2>Alert dialog</h2>
<p>Alert replacement dialog</p>
<button class="alert">Alert</button>
CSS
@import url(http://fonts.googleapis.com/css?family=Ubuntu:300);
body, html {
font-family: Calibri,Verdana,Arial,sans-serif;
border: 0;
margin: 0;
padding: 0;
}
ul {
list-style: disc;
margin-left: 1.5em;
margin-top: .5em;
margin-bottom: .5em;
line-height: 1.4;
}
p {
line-height: 1.4;
margin-bottom: .5em;
}
h1,
h2,
h3 {
font-family: Ubuntu;
line-height: 1.5;
margin-bottom: .5em;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.3em;
}
a, input, button {
outline: 0;
}
#header {
height: 10px;
background: rgb(76,76,76); /* Old browsers */
background: -moz-linear-gradient(top, rgba(76,76,76,1) 1%, rgba(63,63,63,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,rgba(76,76,76,1)), color-stop(100%,rgba(63,63,63,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(76,76,76,1) 1%,rgba(63,63,63,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(76,76,76,1) 1%,rgba(63,63,63,1) 100%); /* Opera11.10+ */
background: -ms-linear-gradient(top, rgba(76,76,76,1) 1%,rgba(63,63,63,1) 100%); /* IE10+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#3f3f3f',GradientType=0 ); /* IE6-9 */
background: linear-gradient(top, rgba(76,76,76,1) 1%,rgba(63,63,63,1) 100%); /* W3C */
}
#body {
padding: 20px;
}
.ui-dialog-title {
font-family: Ubuntu;
font-weight: normal;
}
JavaScript
(function($, undefined) {
var _instances = 0;
var dialog = $.extend({}, $.ui.dialog.prototype),
_super = {
_create: dialog._create,
_destroy: dialog._destroy,
open: dialog.open,
close: dialog.close
};
dialog = $.extend(dialog, {
options: $.extend({}, dialog.options, {
modal: true,
autoOpen: false,
resizable: false,
fadeOverlay: true,
fancyAnimation: true,
beforeOpen: function(e, ui) {},
beforeClose: function(e, ui) {},
afterOpen: function(e, ui) {},
afterClose: function(e, ui) {},
hide: "fade"
}),
_fancyAnimation: null,
_create: function() {
_super._create.call(this);
},
_destroy: function() {
var self = this;
if (self.overlay && self.options.fadeOverlay) {
self.overlay.$el.hide("fade", 200, function() {
_super._destroy.call(self);
});
} else {
return _super._destroy.call(this);
}
},
open: function(e) {
var self = this;
// let's trigger beforeOpen
self.options.beforeOpen.call(self, e);
self = _super.open.call(self, e);
// get height and width of dialog
var height = self.uiDialog.outerHeight(true),
width = self.uiDialog.outerWidth(true);
// prepare fancy animation
if (self.options.fancyAnimation) {
self._fancyAnimation = {
animate: {
opacity: 1,
height: height,
width: width
},
options: {
duration: 150,
step: function() {
...