aboutsummaryrefslogtreecommitdiffstats
path: root/webclient/lib/jquery.dialog.js
blob: 1a5679e3849d6a8c72410b4a22ff23c53c1d0e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * jQuery dialog plugin
 * 
 * <div id="dialogs">
 *   <div id="#dialog-overlay"></div>
 *   <div class="dialog" id="dialog1"></div>
 *   <div class="dialog" id="dialog2"></div>
 * </div>
 */
(function( $ ){

    var methods = {
        
        init: function(){
            this.data('dialog', {opened: []});
            this.find('#dialog-overlay').bind('click.dialog', function(){
                $(this).parent().dialog('hide');
            });
        },
            
        show: function(name){
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();
            var overlay = this.find('#dialog-overlay');
            overlay.css({'width':maskWidth,'height':maskHeight});
            var winH = $(window).height();
            var winW = $(window).width();
            var dialog = this.find('#'+name);
            dialog.css('top',  winH/2-dialog.height()/2);
            dialog.css('left', winW/2-dialog.width()/2);
            this.data('dialog').opened.push(name);
            overlay.show();
            dialog.show();
        },
    
        hide: function(){
            var name = this.data('dialog').opened.pop();
            var dialog = this.find('#'+name);
            var overlay = this.find('#dialog-overlay');
            dialog.hide();
            if (this.data('dialog').opened.length === 0){
                overlay.hide();
            }
        }
    };

    /*
     * Register the 'dialog' method to the jQuery objects
     * the first argument of this method is the submethod
     * you want to call
     */
    $.fn.dialog = function(method) {
        if ( methods[method] ) {
            return methods[method].apply(this, Array.prototype.slice
                                         .call(arguments, 1));
        } else if ( typeof method === 'object' || !method ) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.dialog');
        }
    };

})(jQuery);