PageSourceSearch

https://totallywilduk.co.uk/wp-content/themes/goya/assets/js/vendor/sliding-menu.min.js?ver=0.2.0

js totallywilduk.co.uk collected 2026-10-02 06:38:58 UTC 10,155 bytes, 411 lines download raw bytes

1/*! =========================================================
2 * Sliding Menu v0.2.0
3 * http://github.danielcardoso.net/sliding-menu/
4 * ==========================================================
5 * Copyright (c) 2014-2015 DanielCardoso.net.
6 * Licensed under MIT.
7 * ======================================================== */
8if (typeof jQuery === 'undefined') {
9	throw new Error('Sliding Menu requires jQuery');
10}
11(function (factory) {
12	'use strict';
13	if (typeof define === 'function' && define.amd) {
14		define(['jquery'], factory);
15	} else {
16		factory(jQuery);
17	}
18}(function ($) {
19	'use strict';
20	var slidingMenuUsedIds, SlidingMenu;
21
22	slidingMenuUsedIds = [];
23
24	SlidingMenu = function (element, options) {
25		this.options = undefined;
26		this.$el = undefined;
27		this.currentPanel = undefined;
28
29		this.init(element, options);
30	};
31
32	SlidingMenu.NAME = 'Sliding Menu';
33
34	SlidingMenu.VERSION = '0.2.0';
35
36	SlidingMenu.MAIN_CLASS = 'sliding-menu';
37
38	SlidingMenu.PANEL_CLASS = SlidingMenu.MAIN_CLASS + '-panel';
39
40	SlidingMenu.ICON_CLASS = SlidingMenu.MAIN_CLASS + '-icon';
41
42	SlidingMenu.NAVIGATION_CLASS = SlidingMenu.MAIN_CLASS + '-nav';
43
44	SlidingMenu.SET_ICON_CLASS = 'sm-set-icon';
45
46	SlidingMenu.DEFAULTS = {
47		// Adicional class for menu element
48		className: '',
49		// Default slide animation speed
50		transitionDuration: 250,
51		// A JSON object to build the menu from. Check our JSON example.
52		dataJSON: false,
53		// The link to the selected panel. Set to false to use the root panel
54		initHref: false,
55		// Label for the back button. Set to true to use the link's own label
56		backLabel: 'Back'
57	};
58
59	SlidingMenu.prototype.init = function (element, options) {
60		this.$el = $(element);
61
62		if (this.$el.hasClass(SlidingMenu.MAIN_CLASS)) {
63			return;
64		}
65
66		this.options = this.getOptions(options);
67		this.events();
68		this.process();
69	};
70
71	SlidingMenu.prototype.$ = function (selector) {
72		return this.$el.find(selector);
73	};
74
75	SlidingMenu.prototype.events = function () {
76		this.$el.on('click', 'a', $.proxy(this._onClickItem, this));
77	};
78
79	SlidingMenu.prototype._onClickItem = function (event) {
80		var linker, targetPanel, movePanelTo;
81
82		linker = $(event.currentTarget);
83
84		if (linker.attr('data-id') !== undefined) {
85			event.preventDefault();
86
87			movePanelTo = linker.hasClass(SlidingMenu.MAIN_CLASS + '-back');
88			targetPanel = this.$('.' + SlidingMenu.PANEL_CLASS + '[data-id="' + linker.attr('data-id') + '"]');
89
90			if (this.currentPanel.attr('data-id') !== targetPanel.attr('data-id')) {
91				this.currentPanel.stop(true, true).animate({
92					left: movePanelTo ? '100%' : '-100%'
93				}, this.options.transitionDuration);
94
95				targetPanel.stop(true, true).css('left', movePanelTo ? '-100%' : '100%').animate({
96					left: 0
97				}, this.options.transitionDuration);
98
99				this.$el.stop(true, true).animate({
100					height: targetPanel.height()
101				}, this.options.transitionDuration);
102			} else {
103				targetPanel.css({
104					'left': 0
105				});
106				this.$el.height(targetPanel.height());
107			}
108
109			this.currentPanel = targetPanel;
110		}
111
112		if (!linker.hasClass(SlidingMenu.NAVIGATION_CLASS)) {
113			this.$('li.active').removeClass('active');
114			linker.closest('li').addClass('active');
115		}
116	};
117
118	SlidingMenu.prototype.process = function () {
119		var data;
120
121		if (this.options.dataJSON) {
122			data = this.processJSON(this.options.dataJSON);
123		} else {
124			data = this.processHTML();
125		}
126
127		this.setMenuContent(data);
128	};
129
130	SlidingMenu.prototype.setMenuContent = function (json) {
131		var rootPanel;
132
133		this.$el
134			.empty()
135			.addClass(SlidingMenu.MAIN_CLASS + ' ' + this.options.className);
136
137		$(json).each($.proxy(function (index, item) {
138			var panel;
139			panel = $('<ul/>');
140
141			if (item.root) {
142				rootPanel = '.' + SlidingMenu.PANEL_CLASS + '[data-id="' + item.id + '"]';
143			}
144
145			// panel.attr('id', item.id);
146			panel.attr('data-id', item.id);
147			panel.addClass(SlidingMenu.PANEL_CLASS);
148
149			$(item.children).each(function (index, item) {
150				var li, link, icon;
151
152				li = $('<li/>');
153
154				if (item.separator !== true) {
155					link = $('<a/>');
156
157					link.attr({
158						'class': item.styleClass,
159						'href': item.href
160					});
161
162					if (item.panelId) {
163						link.attr('data-id', item.panelId);
164					}
165
166					link.text(item.label);
167
168					if (item.tag) {
169						link.append(item.tag);
170					}
171
172					if (item.icon) {
173						icon = $('<i/>');
174						icon.addClass(SlidingMenu.ICON_CLASS + ' ' + item.icon);
175
176						link.prepend(icon);
177					}
178					li.append(link);
179				} else {
180					li.addClass(SlidingMenu.MAIN_CLASS + '-separator');
181				}
182
183				panel.append(li);
184			});
185
186			this.$el.append(panel);
187		}, this));
188
189		rootPanel = this.$(rootPanel);
190
191		rootPanel.addClass(SlidingMenu.PANEL_CLASS + '-root');
192		this.currentPanel = rootPanel;
193
194		if (this.options.initHref !== false) {
195			this.changeVisiblePanel();
196		} else {
197			this.currentPanel.css('left', 0);
198		}
199
200		this.$el.height(this.currentPanel.height());
201	};
202
203	SlidingMenu.prototype.changeVisiblePanel = function () {
204		var selectedLink, selectedPanel;
205
206		selectedLink = this.getHyperlinkByHref(this.options.initHref)
207
208		if (selectedLink.length !== 0) {
209			selectedLink.closest('li').addClass('active');
210			selectedPanel = this.getPanelByHref(this.options.initHref);
211			this.currentPanel = selectedPanel;
212		} else {
213			console.warn(SlidingMenu.NAME + ': the link "' + this.options.initHref + '" does not exists. Please ' +
214				'check the ' + (this.options.dataJSON !== false ? 'JSON object' : 'HTML structure') + '.');
215		}
216
217		this.options.initHref = false;
218		this.currentPanel.css('left', 0);
219	};
220
221	SlidingMenu.prototype.processHTML = function (parentElem, parentObj, backLabel) {
222		var root, panels;
223
224		root = {
225			id: SlidingMenu.PANEL_CLASS + '-' + this.getNewId(),
226			root: parentElem ? false : true,
227			children: []
228		};
229		panels = [];
230
231		if (parentElem !== undefined) {
232
233			root.children.push({
234				panelId: parentObj.id,
235				href: parentObj.id,
236				label: this.options.backLabel === true ? backLabel : this.options.backLabel,
237				styleClass: SlidingMenu.MAIN_CLASS + '-back ' + SlidingMenu.NAVIGATION_CLASS
238			});
239
240			var parentLabel = parentElem.parent().children('a'),
241					parentTag = parentLabel.find('.menu-label') || undefined;
242
243			if (parentTag !== undefined) {
244				parentLabel.find('.menu-label').remove();
245			}
246
247			root.children.push({
248				href: parentLabel.attr('href'),
249				label: this.trimWhiteSpaces(parentLabel.text()),
250				tag: parentTag,
251				styleClass: SlidingMenu.MAIN_CLASS + '-top '
252			});
253
254		} else {
255			parentElem = this.$el.children('ul');
256		}
257
258		parentElem.children('li').each($.proxy(function (key, item) {
259			var itemObj, itemLabel, panel, subPanel, itemTag;
260
261			item = $(item);
262
263			if (!item.hasClass('separator')) {
264				itemLabel = item.children('a');
265				itemTag = itemLabel.find('.menu-label') || undefined;
266
267				if (itemTag !== undefined) {
268					itemLabel.find('.menu-label').remove();
269				}
270
271				itemObj = {
272					icon: itemLabel.find('.' + SlidingMenu.SET_ICON_CLASS).attr('class') || undefined,
273					href: itemLabel.attr('href'),
274					tag: itemTag,
275					label: this.trimWhiteSpaces(itemLabel.text()),
276				};
277
278				if (itemObj.icon !== undefined) {
279					itemObj.icon = (itemObj.icon).replace(SlidingMenu.SET_ICON_CLASS, '');
280				}
281
282				subPanel = item.children('ul');
283				if (subPanel.length !== 0) {
284					panel = this.processHTML(subPanel, root, itemObj.label);
285
286					itemObj.panelId = panel[0].id;
287					itemObj.styleClass = SlidingMenu.NAVIGATION_CLASS;
288					panels = panels.concat(panel);
289				}
290			} else {
291				itemObj = {
292					separator: true
293				};
294			}
295
296			root.children.push(itemObj);
297		}, this));
298
299		return [root].concat(panels);
300	};
301
302	SlidingMenu.prototype.processJSON = function (data, parent, backLabel) {
303		var root, panels;
304
305		root = {
306			id: SlidingMenu.PANEL_CLASS + '-' + this.getNewId(),
307			root: parent ? false : true,
308			children: []
309		};
310		panels = [];
311
312		if (parent) {
313			root.children.push({
314				panelId: parent.id,
315				href: parent.id,
316				label: this.options.backLabel === true ? backLabel : this.options.backLabel,
317				styleClass: SlidingMenu.MAIN_CLASS + '-back ' + SlidingMenu.NAVIGATION_CLASS
318			});
319		}
320
321		$(data).each($.proxy(function (index, item) {
322			var panel;
323
324			root.children.push(item);
325
326			if (item.children) {
327				panel = this.processJSON(item.children, root, item.label);
328				item.panelId = panel[0].id;
329				item.styleClass = SlidingMenu.NAVIGATION_CLASS;
330				panels = panels.concat(panel);
331
332				// Delete all childrens
333				delete item.children;
334			}
335		}, this));
336
337		return [root].concat(panels);
338	};
339
340	SlidingMenu.prototype.trimWhiteSpaces = function (text) {
341		return text.trim();
342	};
343
344	SlidingMenu.prototype.getDefaults = function () {
345		return SlidingMenu.DEFAULTS;
346	};
347
348	SlidingMenu.prototype.getOptions = function (options) {
349		return $.extend({}, this.getDefaults(), this.$el.data(), options);
350	};
351
352	SlidingMenu.prototype.getHyperlinkByHref = function (href) {
353		return this.$('a[href="' + href + '"]') || undefined;
354	};
355
356	SlidingMenu.prototype.getPanelByHref = function (href) {
357		var linkElement = this.getHyperlinkByHref(href);
358		return linkElement !== undefined ? linkElement.closest('ul') : undefined;
359	};
360
361	/**
362	 * Create a new ID
363	 * @return {Number} New id generated
364	 */
365	SlidingMenu.prototype.getNewId = function () {
366		var id;
367
368		do {
369			id = Math.random().toString(36).substring(2, 9);
370		} while (slidingMenuUsedIds.indexOf(id) >= 0);
371
372		slidingMenuUsedIds.push(id);
373
374		return id;
375	};
376
377	// PLUGIN DEFINITION
378	// =======================
379	//
380	function Plugin(option) {
381		return this.each(function () {
382			var $this, data, options;
383
384			$this = $(this);
385			data = $this.data('dc.slidingMenu');
386			options = typeof option === 'object' && option;
387
388			if (!data && /destroy|hide/.test(option)) {
389				return;
390			}
391			if (!data) {
392				$this.data('dc.slidingMenu', (data = new SlidingMenu(this, options)));
393			}
394			if (typeof option === 'string') {
395				data[option]();
396			}
397		});
398	}
399
400	var old = $.fn.slidingMenu;
401	$.fn.slidingMenu = Plugin;
402	$.fn.slidingMenu.Constructor = SlidingMenu;
403
404	// SLIDINGMENU NO CONFLICT
405	// =================
406
407	$.fn.slidingMenu.noConflict = function () {
408		$.fn.slidingMenu = old;
409		return this;
410	};
411}));

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.