dot graph map
[kismet-logviewer.git] / logviewer / static / js / pushmenu.js
1 ;(function($, window, document, undefined) {
2
3         function pushMenu (elem, options) {
4                 this.$body = $("body");
5                 this.$elem = $(elem);
6                 this.options = $.extend({}, this.config, options);
7                 this.$toggler = this.$body.find(this.options.button || '.open');
8                 this.initialize();
9         }
10
11         pushMenu.prototype.classes = {
12                 show : "pm_show",
13                 hide : "pm_hide",
14                 overlay : "pm_overlay",
15                 open : "pm_open"
16         }
17
18         pushMenu.prototype.initialize = function(){
19
20                 var _this = this;
21                 _this.initializeEvents();
22
23                 if(this.$body.find("."+this.classes.overlay).length < 1){
24                         var overlay = $("<div>").addClass(this.classes.overlay+" "+this.classes.hide);
25                         this.$body.append(overlay);
26                 }
27         }
28
29         pushMenu.prototype.initializeEvents = function(){
30
31                 var _this = this;
32
33                 this.$toggler.on('click', function(){
34                         _this.toggleMenu("show");
35                 });
36
37                 this.$body.on('click','.'+_this.classes.overlay, function(){
38                         _this.toggleMenu("hide");
39                 });
40         }
41
42         pushMenu.prototype.toggleMenu = function(status){
43                 var method = status == "show" ? "addClass" : "removeClass";
44         // hack to remove initial hidden status - dragorn
45         if (status === "show")
46             this.$elem.removeClass("pm_initial");
47                 this.$elem[method](this.classes.open);
48                 this.toggleOverlay(status);
49         }
50
51         pushMenu.prototype.toggleOverlay = function(status){
52                 var _this = this;
53                 var overlay = _this.$body.find("."+_this.classes.overlay);
54                 if(status == "show"){
55                         overlay.addClass(_this.classes.show).removeClass(_this.classes.hide);
56                 }
57                 else{
58                         overlay.removeClass(this.classes.show);
59                         setTimeout(function(){
60                                 overlay.addClass(_this.classes.hide);
61                         },500);
62                 }
63         }
64
65         $.fn.pushmenu = function(options){
66                 
67                 return this.each(function(){
68                         
69                         new pushMenu(this, options);
70                         
71                 });
72                 
73         };
74         
75 })(jQuery, window, document);