PageSourceSearch

https://golf-for-all.de/templates/easyTemplate360/js/bootstrap-toolkit.js?v=2.0.60

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

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.