Extending jQuery UI Dialog

by Akram kamal

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>
<p>This plugin extends jQuery UI Dialog with the following features:</p>
<ul>
    <li>Fancier animation ala colorbox</li>
    <li>Replacements for alert and confirm</li>
    <li>Callbacks for before and after open/close</li>
    <li>Fading overlay</li>
    <li>Dynamically centered</li>
    <li>Wizard-like dialog</li>
</ul>


<h2>Alert dialog</h2>
<p>Alert replacement dialog</p>
<button class="alert">Alert</button>
<br><br>

<h2>Confirm dialog</h2>
<p>Confirm replacement dialog</p>
<button class="confirm">Confirm</button>
<p class="answer">Answer: Not answered yet</p>
<br>

<h2>Wizard dialog</h2>

<button class="wizard">Wizard</button>


<div id="wizard" title="This is a wizard">
    
    <ul class="steps">
        <li class="current">
            Step 1
            <p>Fill out the stuff</p>
        </li>
        <li>
            Step 2
            <p>Fill out the stuff</p>
        </li>
        <li>
            Step 3
            <p>Fill out the stuff</p>
        </li>
        <li>
            Done!
        </li>
    </ul>

    <div class="step">
        <h3>Step 1</h3>
    </div>
    
    <div class="step">
        <h3>Step 2</h3>
    </div>
    
    <div class="step">
        <h3>Step 3</h3>
    </div>
    
    <div class="step">
        <h3>Done!</h3>
    </div>
    
</div>
    
</div>
<div id="footer"></div>

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-wizard .steps {
    width: 100px;
    float: left;
    border-right: 1px solid #ccc;
    padding: 0em 1em;
    margin-right: 1em;
}

.ui-dialog-wizard .steps li {
    font-weight: bold;
    color: #666;
    margin-bottom: .5em;
}

.ui-dialog-wizard .steps li p {
    display: block;
    font-weight: normal;
    font-style: italic;
}


.ui-dialog-wizard .steps li.current,
.ui-dialog-wizard .steps li.finished {
    color: #000;
}

.ui-dialog-wizard h3 {
    font-family: Ubuntu;
    font-size: 2em; 
    font-weight:...

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() {
                           ...