|
2 | 2 | * Responsive Bootstrap Toolkit |
3 | 3 | * Author: Maciej Gurban |
4 | 4 | * License: MIT |
5 | | - * Version: 2.4.1 (2015-04-19) |
| 5 | + * Version: 2.4.2 (2015-05-09) |
6 | 6 | * Origin: https://github.com/maciej-gurban/responsive-bootstrap-toolkit |
7 | 7 | */ |
8 | 8 | ;var ResponsiveBootstrapToolkit = (function($){ |
|
24 | 24 |
|
25 | 25 | // Used operator |
26 | 26 | var operator = str.charAt(0); |
27 | | - // Include breakpoint equal to alias? |
| 27 | + // Include breakpoint equal to alias? |
28 | 28 | var orEqual = (str.charAt(1) == '=') ? true : false |
29 | 29 |
|
30 | 30 | /** |
|
54 | 54 | isAnyActive: function( breakpoints ) { |
55 | 55 | var found = false; |
56 | 56 | $.each(breakpoints, function( index, alias ) { |
57 | | - // Once first breakpoint matches, return true and break the out of the loop |
| 57 | + // Once first breakpoint matches, return true and break out of the loop |
58 | 58 | if( self.breakpoints[ alias ].is(':visible') ) { |
59 | 59 | found = true; |
60 | 60 | return false; |
|
87 | 87 | * at 'md' breakpoint, indicated in the expression, |
88 | 88 | * That makes: start = 0, end = 2 (index of 'md' breakpoint) |
89 | 89 | * |
90 | | - * Parsing viewport.is('<md') we start at index 'xs' breakpoint, and end at |
| 90 | + * Parsing viewport.is('<md') we start at index 'xs' breakpoint, and end at |
91 | 91 | * 'sm' breakpoint, one before 'md'. |
92 | 92 | * Which makes: start = 0, end = 1 |
93 | 93 | */ |
|
100 | 100 | * of breakpoint list. |
101 | 101 | * That makes: start = 1, end = undefined |
102 | 102 | * |
103 | | - * Parsing viewport.is('>sm') we start at breakpoint 'md' and end at the end of |
| 103 | + * Parsing viewport.is('>sm') we start at breakpoint 'md' and end at the end of |
104 | 104 | * breakpoint list. |
105 | 105 | * Which makes: start = 2, end = undefined |
106 | 106 | */ |
|
111 | 111 |
|
112 | 112 | var acceptedBreakpoints = breakpointList.slice(start, end); |
113 | 113 |
|
114 | | - return internal.isAnyActive( acceptedBreakpoints ); |
| 114 | + return internal.isAnyActive( acceptedBreakpoints ); |
115 | 115 |
|
116 | 116 | } |
117 | 117 | } |
|
122 | 122 | var self = { |
123 | 123 |
|
124 | 124 | /** |
125 | | - * Determines default interval between firing 'changed' method |
| 125 | + * Determines default debouncing interval of 'changed' method |
126 | 126 | */ |
127 | 127 | interval: 300, |
128 | 128 |
|
129 | 129 | /** |
130 | 130 | * Breakpoint aliases, listed from smallest to biggest |
131 | 131 | */ |
132 | 132 | breakpoints: { |
133 | | - 'xs': $('<div class="device-xs visible-xs visible-xs-block"></div>').appendTo('body'), |
134 | | - 'sm': $('<div class="device-sm visible-sm visible-sm-block"></div>').appendTo('body'), |
135 | | - 'md': $('<div class="device-md visible-md visible-md-block"></div>').appendTo('body'), |
136 | | - 'lg': $('<div class="device-lg visible-lg visible-lg-block"></div>').appendTo('body') |
| 133 | + 'xs': $.parseHTML('<div class="device-xs visible-xs visible-xs-block"></div>'), |
| 134 | + 'sm': $.parseHTML('<div class="device-sm visible-sm visible-sm-block"></div>'), |
| 135 | + 'md': $.parseHTML('<div class="device-md visible-md visible-md-block"></div>'), |
| 136 | + 'lg': $.parseHTML('<div class="device-lg visible-lg visible-lg-block"></div>') |
137 | 137 | }, |
138 | 138 |
|
139 | | - /** |
140 | | - * Debouncing helper |
141 | | - * |
142 | | - * Used to calculate intervals between consecutive function executions |
143 | | - */ |
144 | | - timer: new Date(), |
145 | | - |
146 | 139 | /** |
147 | 140 | * Returns true if current breakpoint matches passed alias |
148 | 141 | */ |
|
170 | 163 |
|
171 | 164 | /* |
172 | 165 | * Waits specified number of miliseconds before executing a callback |
173 | | - * Source: http://stackoverflow.com/a/4541963/2066118 |
174 | 166 | */ |
175 | | - changed: function() { |
176 | | - var timers = {}; |
177 | | - return function(callback, ms) { |
178 | | - // Get unique timer ID |
179 | | - var uID = (!uID) ? self.timer.getTime() : null; |
180 | | - |
181 | | - if (timers[uID]) { |
182 | | - clearTimeout(timers[uID]); |
183 | | - } |
184 | | - |
185 | | - // Uses default interval if none specified |
186 | | - if (typeof ms === "undefined") { |
187 | | - var ms = self.interval; |
188 | | - } |
189 | | - timers[uID] = setTimeout(callback, ms); |
| 167 | + changed: function(fn, ms) { |
| 168 | + var timer; |
| 169 | + return function(){ |
| 170 | + clearTimeout(timer); |
| 171 | + timer = setTimeout(function(){ |
| 172 | + fn(); |
| 173 | + }, ms || self.interval); |
190 | 174 | }; |
191 | | - }() |
| 175 | + } |
| 176 | + |
| 177 | + }; |
192 | 178 |
|
193 | | - } |
| 179 | + /** |
| 180 | + * Append visibility divs to <body> only after DOM laoded |
| 181 | + */ |
| 182 | + $(document).ready(function(){ |
| 183 | + $.each(self.breakpoints, function(alias){ |
| 184 | + self.breakpoints[alias].appendTo('body'); |
| 185 | + }); |
| 186 | + }); |
194 | 187 |
|
195 | 188 | return self; |
196 | 189 |
|
|
0 commit comments