Modernizing Practice Settings page (#633)
[openemr.git] / public / assets / bootstrap-sidebar-0-2-2 / dist / js / sidebar.js
blobbbc84e2f7324dd4c91819f226eef1ecf9dc6d78b
1 /* ========================================================================
2  * Bootstrap: sidebar.js v0.1
3  * ========================================================================
4  * Copyright 2011-2014 Asyraf Abdul Rahman
5  * Licensed under MIT
6  * ======================================================================== */
8 +function ($) {
9   'use strict';
11   // SIDEBAR PUBLIC CLASS DEFINITION
12   // ================================
14   var Sidebar = function (element, options) {
15     this.$element      = $(element)
16     this.options       = $.extend({}, Sidebar.DEFAULTS, options)
17     this.transitioning = null
19     if (this.options.parent) this.$parent = $(this.options.parent)
20     if (this.options.toggle) this.toggle()
21   }
23   Sidebar.DEFAULTS = {
24     toggle: true
25   }
27   Sidebar.prototype.show = function () {
28     if (this.transitioning || this.$element.hasClass('sidebar-open')) return
31     var startEvent = $.Event('show.bs.sidebar')
32     this.$element.trigger(startEvent);
33     if (startEvent.isDefaultPrevented()) return
35     this.$element
36       .addClass('sidebar-open')
38     this.transitioning = 1
40     var complete = function () {
41       this.$element
42       this.transitioning = 0
43       this.$element.trigger('shown.bs.sidebar')
44     }
46     if(!$.support.transition) return complete.call(this)
48     this.$element
49       .one($.support.transition.end, $.proxy(complete, this))
50       .emulateTransitionEnd(400)
51   }
53   Sidebar.prototype.hide = function () {
54     if (this.transitioning || !this.$element.hasClass('sidebar-open')) return
56     var startEvent = $.Event('hide.bs.sidebar')
57     this.$element.trigger(startEvent)
58     if(startEvent.isDefaultPrevented()) return
60     this.$element
61       .removeClass('sidebar-open')
63     this.transitioning = 1
65     var complete = function () {
66       this.transitioning = 0
67       this.$element
68         .trigger('hidden.bs.sidebar')
69     }
71     if (!$.support.transition) return complete.call(this)
73     this.$element
74       .one($.support.transition.end, $.proxy(complete, this))
75       .emulateTransitionEnd(400)
76   }
78   Sidebar.prototype.toggle = function () {
79     this[this.$element.hasClass('sidebar-open') ? 'hide' : 'show']()
80   }
82   var old = $.fn.sidebar
84   $.fn.sidebar = function (option) {
85     return this.each(function (){
86       var $this = $(this)
87       var data = $this.data('bs.sidebar')
88       var options = $.extend({}, Sidebar.DEFAULTS, $this.data(), typeof options == 'object' && option)
90       if (!data && options.toggle && option == 'show') option = !option
91       if (!data) $this.data('bs.sidebar', (data = new Sidebar(this, options)))
92       if (typeof option == 'string') data[option]()
93     })
94   }
96   $.fn.sidebar.Constructor = Sidebar
98   $.fn.sidebar.noConflict = function () {
99     $.fn.sidebar = old
100     return this
101   }
103   $(document).on('click.bs.sidebar.data-api', '[data-toggle="sidebar"]', function (e) {
104     var $this = $(this), href
105     var target = $this.attr('data-target')
106         || e.preventDefault()
107         || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
108     var $target = $(target)
109     var data = $target.data('bs.sidebar')
110     var option = data ? 'toggle' : $this.data()
112     $target.sidebar(option)
113   })
115   $('html').on('click.bs.sidebar.autohide', function(event){
116     var $this = $(event.target);
117     var isButtonOrSidebar = $this.is('.sidebar, [data-toggle="sidebar"]') || $this.parents('.sidebar, [data-toggle="sidebar"]').length;
118     if (isButtonOrSidebar) {
119       return;
120     } else {
121       var $target = $('.sidebar');
122       $target.each(function(i, trgt) {
123         var $trgt = $(trgt);
124         if($trgt.data('bs.sidebar') && $trgt.hasClass('sidebar-open')) {
125             $trgt.sidebar('hide');
126         }
127       })
128     }
129   });
130 }(jQuery);