PageSourceSearch

https://foresthillsgardensfoundation.org/wp-content/themes/ForestH…/js/libs/slidebars/slidebars.js?ver=021026

js foresthillsgardensfoundation.org collected 2026-10-03 02:01:20 UTC 10,835 bytes, 460 lines download raw bytes

1/*!
2 * Slidebars - A jQuery Framework for Off-Canvas Menus and Sidebars
3 * Version: 2.0
vendor: 10,748 bytes, lines 3-460
3
4 * Url: http://www.adchsm.com/slidebars/
5 * Author: Adam Charles Smith
6 * Author url: http://www.adchsm.com/
7 * License: MIT
8 * License url: http://www.adchsm.com/slidebars/license/
9 */
10
11var slidebars = function () {
12
13	/**
14	 * Setup
15	 */
16
17	// Cache all canvas elements
18	var canvas = $( '[canvas]' ),
19
20	// Object of Slidebars
21	offCanvas = {},
22
23	// Variables, permitted sides and styles
24	init = false,
25	registered = false,
26	sides = [ 'top', 'right', 'bottom', 'left' ],
27	styles = [ 'reveal', 'push', 'overlay', 'shift' ],
28
29	/**
30	 * Get Animation Properties
31	 */
32
33	getAnimationProperties = function ( id ) {
34		// Variables
35		var elements = $(),
36		amount = '0px, 0px',
37		duration = parseFloat( offCanvas[ id ].element.css( 'transitionDuration' ), 10 ) * 1000;
38
39		// Elements to animate
40		if ( offCanvas[ id ].style === 'reveal' || offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'shift' ) {
41			elements = elements.add( canvas );
42		}
43
44		if ( offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'overlay' || offCanvas[ id ].style === 'shift' ) {
45			elements = elements.add( offCanvas[ id ].element );
46		}
47
48		// Amount to animate
49		if ( offCanvas[ id ].active ) {
50			if ( offCanvas[ id ].side === 'top' ) {
51				amount = '0px, ' + offCanvas[ id ].element.css( 'height' );
52			} else if ( offCanvas[ id ].side === 'right' ) {
53				amount = '-' + offCanvas[ id ].element.css( 'width' ) + ', 0px';
54			} else if ( offCanvas[ id ].side === 'bottom' ) {
55				amount = '0px, -' + offCanvas[ id ].element.css( 'height' );
56			} else if ( offCanvas[ id ].side === 'left' ) {
57				amount = offCanvas[ id ].element.css( 'width' ) + ', 0px';
58			}
59		}
60
61		// Return animation properties
62		return { 'elements': elements, 'amount': amount, 'duration': duration };
63	},
64
65	/**
66	 * Slidebars Registration
67	 */
68
69	registerSlidebar = function ( id, side, style, element ) {
70		// Check if Slidebar is registered
71		if ( isRegisteredSlidebar( id ) ) {
72			throw "Error registering Slidebar, a Slidebar with id '" + id + "' already exists.";
73		}
74
75		// Register the Slidebar
76		offCanvas[ id ] = {
77			'id': id,
78			'side': side,
79			'style': style,
80			'element': element,
81			'active': false
82		};
83	},
84
85	isRegisteredSlidebar = function ( id ) {
86		// Return if Slidebar is registered
87		if ( offCanvas.hasOwnProperty( id ) ) {
88			return true;
89		} else {
90			return false;
91		}
92	};
93
94	/**
95	 * Initialization
96	 */
97
98	this.init = function ( callback ) {
99		// Check if Slidebars has been initialized
100		if ( init ) {
101			throw "Slidebars has already been initialized.";
102		}
103
104		// Loop through and register Slidebars
105		if ( ! registered ) {
106			$( '[off-canvas]' ).each( function () {
107				// Get Slidebar parameters
108				var parameters = $( this ).attr( 'off-canvas' ).split( ' ', 3 );
109
110				// Make sure a valid id, side and style are specified
111				if ( ! parameters || ! parameters[ 0 ] || sides.indexOf( parameters[ 1 ] ) === -1 || styles.indexOf( parameters[ 2 ] ) === -1 ) {
112					throw "Error registering Slidebar, please specifiy a valid id, side and style'.";
113				}
114
115				// Register Slidebar
116				registerSlidebar( parameters[ 0 ], parameters[ 1 ], parameters[ 2 ], $( this ) );
117			} );
118
119			// Set registered variable
120			registered = true;
121		}
122
123		// Set initialized variable
124		init = true;
125
126		// Set CSS
127		this.css();
128
129		// Trigger event
130		$( events ).trigger( 'init' );
131
132		// Run callback
133		if ( typeof callback === 'function' ) {
134			callback();
135		}
136	};
137
138	this.exit = function ( callback ) {
139		// Check if Slidebars has been initialized
140		if ( ! init ) {
141			throw "Slidebars hasn't been initialized.";
142		}
143
144		// Exit
145		var exit = function () {
146			// Set init variable
147			init = false;
148
149			// Trigger event
150			$( events ).trigger( 'exit' );
151
152			// Run callback
153			if ( typeof callback === 'function' ) {
154				callback();
155			}
156		};
157
158		// Call exit, close open Slidebar if active
159		if ( this.getActiveSlidebar() ) {
160			this.close( exit );
161		} else {
162			exit();
163		}
164	};
165
166	/**
167	 * CSS
168	 */
169
170	this.css = function ( callback ) {
171		// Check if Slidebars has been initialized
172		if ( ! init ) {
173			throw "Slidebars hasn't been initialized.";
174		}
175
176		// Loop through Slidebars to set negative margins
177		for ( var id in offCanvas ) {
178			// Check if Slidebar is registered
179			if ( isRegisteredSlidebar( id ) ) {
180				// Calculate offset
181				var offset;
182
183				if ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) {
184					offset = offCanvas[ id ].element.css( 'height' );
185				} else {
186					offset = offCanvas[ id ].element.css( 'width' );
187				}
188
189				// Apply negative margins
190				if ( offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'overlay' || offCanvas[ id ].style === 'shift' ) {
191					offCanvas[ id ].element.css( 'margin-' + offCanvas[ id ].side, '-' + offset );
192				}
193			}
194		}
195
196		// Reposition open Slidebars
197		if ( this.getActiveSlidebar() ) {
198			this.open( this.getActiveSlidebar() );
199		}
200
201		// Trigger event
202		$( events ).trigger( 'css' );
203
204		// Run callback
205		if ( typeof callback === 'function' ) {
206			callback();
207		}
208	};
209
210	/**
211	 * Controls
212	 */
213
214	this.open = function ( id, callback ) {
215		// Check if Slidebars has been initialized
216		if ( ! init ) {
217			throw "Slidebars hasn't been initialized.";
218		}
219
220		// Check if id wasn't passed or if Slidebar isn't registered
221		if ( ! id || ! isRegisteredSlidebar( id ) ) {
222			throw "Error opening Slidebar, there is no Slidebar with id '" + id + "'.";
223		}
224
225		// Open
226		var open = function () {
227			// Set active state to true
228			offCanvas[ id ].active = true;
229
230			// Display the Slidebar
231			offCanvas[ id ].element.css( 'display', 'block' );
232
233			// Trigger event
234			$( events ).trigger( 'opening', [ offCanvas[ id ].id ] );
235
236			// Get animation properties
237			var animationProperties = getAnimationProperties( id );
238
239			// Apply css
240			animationProperties.elements.css( {
241				'transition-duration': animationProperties.duration + 'ms',
242				'transform': 'translate(' + animationProperties.amount + ')'
243			} );
244
245			// Transition completed
246			setTimeout( function () {
247				// Trigger event
248				$( events ).trigger( 'opened', [ offCanvas[ id ].id ] );
249
250				// Run callback
251				if ( typeof callback === 'function' ) {
252					callback();
253				}
254			}, animationProperties.duration );
255		};
256
257		// Call open, close open Slidebar if active
258		if ( this.getActiveSlidebar() && this.getActiveSlidebar() !== id ) {
259			this.close( open );
260		} else {
261			open();
262		}
263	};
264
265	this.close = function ( id, callback ) {
266		// Shift callback arguments
267		if ( typeof id === 'function' ) {
268			callback = id;
269			id = null;
270		}
271
272		// Check if Slidebars has been initialized
273		if ( ! init ) {
274			throw "Slidebars hasn't been initialized.";
275		}
276
277		// Check if id was passed but isn't a registered Slidebar
278		if ( id && ! isRegisteredSlidebar( id ) ) {
279			throw "Error closing Slidebar, there is no Slidebar with id '" + id + "'.";
280		}
281
282		// If no id was passed, get the active Slidebar
283		if ( ! id ) {
284			id = this.getActiveSlidebar();
285		}
286
287		// Close a Slidebar
288		if ( id && offCanvas[ id ].active ) {
289			// Set active state to false
290			offCanvas[ id ].active = false;
291
292			// Trigger event
293			$( events ).trigger( 'closing', [ offCanvas[ id ].id ] );
294
295			// Get animation properties
296			var animationProperties = getAnimationProperties( id );
297
298			// Apply css
299			animationProperties.elements.css( 'transform', '' );
300
301			// Transition completetion
302			setTimeout( function () {
303				// Remove transition duration
304				animationProperties.elements.css( 'transition-duration', '' );
305
306				// Hide the Slidebar
307				offCanvas[ id ].element.css( 'display', '' );
308
309				// Trigger event
310				$( events ).trigger( 'closed', [ offCanvas[ id ].id ] );
311
312				// Run callback
313				if ( typeof callback === 'function' ) {
314					callback();
315				}
316			}, animationProperties.duration );
317		}
318	};
319
320	this.toggle = function ( id, callback ) {
321		// Check if Slidebars has been initialized
322		if ( ! init ) {
323			throw "Slidebars hasn't been initialized.";
324		}
325
326		// Check if id wasn't passed or if Slidebar isn't registered
327		if ( ! id || ! isRegisteredSlidebar( id ) ) {
328			throw "Error toggling Slidebar, there is no Slidebar with id '" + id + "'.";
329		}
330
331		// Check Slidebar state
332		if ( offCanvas[ id ].active ) {
333			// It's open, close it
334			this.close( id, function () {
335				// Run callback
336				if ( typeof callback === 'function' ) {
337					callback();
338				}
339			} );
340		} else {
341			// It's closed, open it
342			this.open( id, function () {
343				// Run callback
344				if ( typeof callback === 'function' ) {
345					callback();
346				}
347			} );
348		}
349	};
350
351	/**
352	 * Active States
353	 */
354
355	this.isActive = function ( id ) {
356		// Return init state
357		return init;
358	};
359
360	this.isActiveSlidebar = function ( id ) {
361		// Check if Slidebars has been initialized
362		if ( ! init ) {
363			throw "Slidebars hasn't been initialized.";
364		}
365
366		// Check if id wasn't passed
367		if ( ! id ) {
368			throw "You must provide a Slidebar id.";
369		}
370
371		// Check if Slidebar is registered
372		if ( ! isRegisteredSlidebar( id ) ) {
373			throw "Error retrieving Slidebar, there is no Slidebar with id '" + id + "'.";
374		}
375
376		// Return the active state
377		return offCanvas[ id ].active;
378	};
379
380	this.getActiveSlidebar = function () {
381		// Check if Slidebars has been initialized
382		if ( ! init ) {
383			throw "Slidebars hasn't been initialized.";
384		}
385
386		// Variable to return
387		var active = false;
388
389		// Loop through Slidebars
390		for ( var id in offCanvas ) {
391			// Check if Slidebar is registered
392			if ( isRegisteredSlidebar( id ) ) {
393				// Check if it's active
394				if ( offCanvas[ id ].active ) {
395					// Set the active id
396					active = offCanvas[ id ].id;
397					break;
398				}
399			}
400		}
401
402		// Return
403		return active;
404	};
405
406	this.getSlidebars = function () {
407		// Check if Slidebars has been initialized
408		if ( ! init ) {
409			throw "Slidebars hasn't been initialized.";
410		}
411
412		// Create an array for the Slidebars
413		var slidebarsArray = [];
414
415		// Loop through Slidebars
416		for ( var id in offCanvas ) {
417			// Check if Slidebar is registered
418			if ( isRegisteredSlidebar( id ) ) {
419				// Add Slidebar id to array
420				slidebarsArray.push( offCanvas[ id ].id );
421			}
422		}
423
424		// Return
425		return slidebarsArray;
426	};
427
428	this.getSlidebar = function ( id ) {
429		// Check if Slidebars has been initialized
430		if ( ! init ) {
431			throw "Slidebars hasn't been initialized.";
432		}
433
434		// Check if id wasn't passed
435		if ( ! id ) {
436			throw "You must pass a Slidebar id.";
437		}
438
439		// Check if Slidebar is registered
440		if ( ! id || ! isRegisteredSlidebar( id ) ) {
441			throw "Error retrieving Slidebar, there is no Slidebar with id '" + id + "'.";
442		}
443
444		// Return the Slidebar's properties
445		return offCanvas[ id ];
446	};
447
448	/**
449	 * Events
450	 */
451
452	this.events = {};
453	var events = this.events;
454
455	/**
456	 * Resizes
457	 */
458
459	$( window ).on( 'resize', this.css.bind( this ) );
460};

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.