PageSourceSearch

https://www.esylux.com/_assets/581ae7819742031f221bb47d76589cd6/JavaScripts/bootstrap-toolkit.js?1750094461

js esylux.com collected 2026-10-04 13:23:13 UTC 7,594 bytes, 239 lines download raw bytes

1/*!
2 * Responsive Bootstrap Toolkit
3 * Author:    Maciej Gurban
4 * License:   MIT
5 * Version:   2.6.3 (2016-06-21)
6 * Origin:    https://github.com/maciej-gurban/responsive-bootstrap-toolkit
7 */
8var ResponsiveBootstrapToolkit = (function($){
9
10    // Internal methods
11    var internal = {
12
13        /**
14         * Breakpoint detection divs for each framework version
15         */
16        detectionDivs: {
17            // Bootstrap 4
18            bootstrap: {
19                'xs': $('<div class="d-block d-sm-none"></div>'),
20                'sm': $('<div class="d-none d-sm-block d-md-none"></div>'),
21                'md': $('<div class="d-none d-md-block d-lg-none"></div>'),
22                'lg': $('<div class="d-none d-lg-block d-xl-none"></div>'),
23                'xl': $('<div class="d-none d-xl-block"></div>')
24            },
25            // Foundation 5
26            foundation: {
27                'small':  $('<div class="device-xs show-for-small-only"></div>'),
28                'medium': $('<div class="device-sm show-for-medium-only"></div>'),
29                'large':  $('<div class="device-md show-for-large-only"></div>'),
30                'xlarge': $('<div class="device-lg show-for-xlarge-only"></div>')
31            }
32        },
33
34        /**
35         * Append visibility divs after DOM laoded
36         */
37        applyDetectionDivs: function() {
38            $(document).ready(function(){
39                $.each(self.breakpoints, function(alias){
40                    self.breakpoints[alias].appendTo('.responsive-bootstrap-toolkit');
41                });
42            });
43        },
44
45        /**
46         * Determines whether passed string is a parsable expression
47         */
48        isAnExpression: function( str ) {
49            return (str.charAt(0) == '<' || str.charAt(0) == '>');
50        },
51
52        /**
53         * Splits the expression in into <|> [=] alias
54         */
55        splitExpression: function( str ) {
56
57            // Used operator
58            var operator = str.charAt(0);
59            // Include breakpoint equal to alias?
60            var orEqual  = (str.charAt(1) == '=') ? true : false;
61
62            /**
63             * Index at which breakpoint name starts.
64             *
65             * For:  >sm, index = 1
66             * For: >=sm, index = 2
67             */
68            var index = 1 + (orEqual ? 1 : 0);
69
70            /**
71             * The remaining part of the expression, after the operator, will be treated as the
72             * breakpoint name to compare with
73             */
74            var breakpointName = str.slice(index);
75
76            return {
77                operator:       operator,
78                orEqual:        orEqual,
79                breakpointName: breakpointName
80            };
81        },
82
83        /**
84         * Returns true if currently active breakpoint matches the expression
85         */
86        isAnyActive: function( breakpoints ) {
87            var found = false;
88            $.each(breakpoints, function( index, alias ) {
89                // Once first breakpoint matches, return true and break out of the loop
90                if( self.breakpoints[ alias ].is(':visible') ) {
91                    found = true;
92                    return false;
93                }
94            });
95            return found;
96        },
97
98        /**
99         * Determines whether current breakpoint matches the expression given
100         */
101        isMatchingExpression: function( str ) {
102
103            var expression = internal.splitExpression( str );
104
105            // Get names of all breakpoints
106            var breakpointList = Object.keys(self.breakpoints);
107
108            // Get index of sought breakpoint in the list
109            var pos = breakpointList.indexOf( expression.breakpointName );
110
111            // Breakpoint found
112            if( pos !== -1 ) {
113
114                var start = 0;
115                var end   = 0;
116
117                /**
118                 * Parsing viewport.is('<=md') we interate from smallest breakpoint ('xs') and end
119                 * at 'md' breakpoint, indicated in the expression,
120                 * That makes: start = 0, end = 2 (index of 'md' breakpoint)
121                 *
122                 * Parsing viewport.is('<md') we start at index 'xs' breakpoint, and end at
123                 * 'sm' breakpoint, one before 'md'.
124                 * Which makes: start = 0, end = 1
125                 */
126                if( expression.operator == '<' ) {
127                    start = 0;
128                    end   = expression.orEqual ? ++pos : pos;
129                }
130                /**
131                 * Parsing viewport.is('>=sm') we interate from breakpoint 'sm' and end at the end
132                 * of breakpoint list.
133                 * That makes: start = 1, end = undefined
134                 *
135                 * Parsing viewport.is('>sm') we start at breakpoint 'md' and end at the end of
136                 * breakpoint list.
137                 * Which makes: start = 2, end = undefined
138                 */
139                if( expression.operator == '>' ) {
140                    start = expression.orEqual ? pos : ++pos;
141                    end   = undefined;
142                }
143
144                var acceptedBreakpoints = breakpointList.slice(start, end);
145
146                return internal.isAnyActive( acceptedBreakpoints );
147
148            }
149        }
150
151    };
152
153    // Public methods and properties
154    var self = {
155
156        /**
157         * Determines default debouncing interval of 'changed' method
158         */
159        interval: 300,
160
161        /**
162         *
163         */
164        framework: null,
165
166        /**
167         * Breakpoint aliases, listed from smallest to biggest
168         */
169        breakpoints: null,
170
171        /**
172         * Returns true if current breakpoint matches passed alias
173         */
174        is: function( str ) {
175            if( internal.isAnExpression( str ) ) {
176                return internal.isMatchingExpression( str );
177            }
178            return self.breakpoints[ str ] && self.breakpoints[ str ].is(':visible');
179        },
180
181        /**
182         * Determines which framework-specific breakpoint detection divs to use
183         */
184        use: function( frameworkName, breakpoints ) {
185            self.framework = frameworkName.toLowerCase();
186
187            if( self.framework === 'bootstrap' || self.framework === 'foundation') {
188                self.breakpoints = internal.detectionDivs[ self.framework ];
189            } else {
190                self.breakpoints = breakpoints;
191            }
192
193            internal.applyDetectionDivs();
194        },
195
196        /**
197         * Returns current breakpoint alias
198         */
199        current: function(){
200            var name = 'unrecognized';
201            $.each(self.breakpoints, function(alias){
202                if (self.is(alias)) {
203                    name = alias;
204                }
205            });
206            return name;
207        },
208
209        /*
210         * Waits specified number of miliseconds before executing a callback
211         */
212        changed: function(fn, ms) {
213            var timer;
214            return function(){
215                clearTimeout(timer);
216                timer = setTimeout(function(){
217                    fn();
218                }, ms || self.interval);
219            };
220        }
221
222    };
223
224    // Create a placeholder
225    $(document).ready(function(){
226        $('<div class="responsive-bootstrap-toolkit"></div>').appendTo('body');
227    });
228
229    if( self.framework === null ) {
230        self.use('bootstrap');
231    }
232
233    return self;
234
235})(jQuery);
236
237if (typeof module !== 'undefined' && module.exports) {
238    module.exports = ResponsiveBootstrapToolkit;
239}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.