PageSourceSearch

https://admarginem.ru/wp-content/themes/admarginem/js/navigation.js?ver=20151215

js admarginem.ru collected 2026-10-02 04:05:26 UTC 5,621 bytes, 216 lines download raw bytes

1/**
2 * File navigation.js.
3 *
4 * Handles toggling the navigation menu for small screens and enables TAB key
5 * navigation support for dropdown menus.
6 */
7( function() {
8	var container, button, menu, links, i, len;
9
10	container = document.getElementById( 'site-navigation' );
11	if ( ! container ) {
12		return;
13	}
14
15	button = container.getElementsByTagName( 'button' )[0];
16	if ( 'undefined' === typeof button ) {
17		return;
18	}
19
20	menu = container.getElementsByTagName( 'ul' )[0];
21
22	// Hide menu toggle button if menu is empty and return early.
23	if ( 'undefined' === typeof menu ) {
24		button.style.display = 'none';
25		return;
26	}
27
28	menu.setAttribute( 'aria-expanded', 'false' );
29	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
30		menu.className += ' nav-menu';
31	}
32
33	button.onclick = function() {
34		if ( -1 !== container.className.indexOf( 'toggled' ) ) {
35			container.className = container.className.replace( ' toggled', '' );
36			button.setAttribute( 'aria-expanded', 'false' );
37			menu.setAttribute( 'aria-expanded', 'false' );
38		} else {
39			container.className += ' toggled';
40			button.setAttribute( 'aria-expanded', 'true' );
41			menu.setAttribute( 'aria-expanded', 'true' );
42		}
43	};
44
45	// Get all the link elements within the menu.
46	links    = menu.getElementsByTagName( 'a' );
47
48	// Each time a menu link is focused or blurred, toggle focus.
49	for ( i = 0, len = links.length; i < len; i++ ) {
50		links[i].addEventListener( 'focus', toggleFocus, true );
51		links[i].addEventListener( 'blur', toggleFocus, true );
52	}
53
54	/**
55	 * Sets or removes .focus class on an element.
56	 */
57	function toggleFocus() {
58		var self = this;
59
60		// Move up through the ancestors of the current link until we hit .nav-menu.
61		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
62
63			// On li elements toggle the class .focus.
64			if ( 'li' === self.tagName.toLowerCase() ) {
65				if ( -1 !== self.className.indexOf( 'focus' ) ) {
66					self.className = self.className.replace( ' focus', '' );
67				} else {
68					self.className += ' focus';
69				}
70			}
71
72			self = self.parentElement;
73		}
74	}
75
76	/**
77	 * Toggles `focus` class to allow submenu access on tablets.
78	 */
79	( function( container ) {
80		var touchStartFn, i,
81			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
82
83		if ( 'ontouchstart' in window ) {
84			touchStartFn = function( e ) {
85				var menuItem = this.parentNode, i;
86
87				if ( ! menuItem.classList.contains( 'focus' ) ) {
88					e.preventDefault();
89					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
90						if ( menuItem === menuItem.parentNode.children[i] ) {
91							continue;
92						}
93						menuItem.parentNode.children[i].classList.remove( 'focus' );
94					}
95					menuItem.classList.add( 'focus' );
96				} else {
97					menuItem.classList.remove( 'focus' );
98				}
99			};
100
101			for ( i = 0; i < parentLink.length; ++i ) {
102				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
103			}
104		}
105	}( container ) );
106} )();
107
108
109
110/*
111auto update cart
112*/
113function enable_update_cart() {
114    jQuery('[name="update_cart"]').removeAttr('disabled');
115}
116
117function quantity_step_btn() {
118    var timeoutPlus;
119    jQuery('.quantity .plus').one().on('click', function() {
120        $input = jQuery(this).prev('input.qty');
121        var val = parseInt($input.val());
122        var step = $input.attr('step');
123        step = 'undefined' !== typeof(step) ? parseInt(step) : 1;
124        $input.val( val + step ).change();
125
126        if( timeoutPlus != undefined ) {
127            clearTimeout(timeoutPlus)
128        }
129        timeoutPlus = setTimeout(function(){
130            jQuery('[name="update_cart"]').trigger('click');
131        }, 1000);
132    });
133
134    var timeoutMinus;
135    jQuery('.quantity .minus').one().on('click', function() {
136        $input = jQuery(this).next('input.qty');
137        var val = parseInt($input.val());
138        var step = $input.attr('step');
139        step = 'undefined' !== typeof(step) ? parseInt(step) : 1;
140        if (val > 1) {
141            $input.val( val - step ).change();
142        }
143
144        if( timeoutMinus != undefined ) {
145            clearTimeout(timeoutMinus)
146        }
147        timeoutMinus = setTimeout(function(){
148            jQuery('[name="update_cart"]').trigger('click');
149        }, 1000);
150    });
151
152    var timeoutInput;
153    jQuery('div.woocommerce').on('change', '.qty', function(){
154        if( timeoutInput != undefined ) {
155            clearTimeout(timeoutInput)
156        }
157        timeoutInput = setTimeout(function(){
158            jQuery('[name="update_cart"]').trigger('click');
159        }, 1000);
160    });
161}
162
163jQuery(document).ready(function() {
164    enable_update_cart();
165    quantity_step_btn();
166});
167
168jQuery( document ).on( 'updated_cart_totals', function() {
169    enable_update_cart();
170    quantity_step_btn();
171});
172
173
174(function($) {
175
176  if(!$) {
177    return;
178  }
179
180  ////////////
181  // Plugin //
182  ////////////
183
184  $.fn.headroom = function(option) {
185    return this.each(function() {
186      var $this   = $(this),
187        data      = $this.data('headroom'),
188        options   = typeof option === 'object' && option;
189
190      options = $.extend(true, {}, Headroom.options, options);
191
192      if (!data) {
193        data = new Headroom(this, options);
194        data.init();
195        $this.data('headroom', data);
196      }
197      if (typeof option === 'string') {
198        data[option]();
199
200        if(option === 'destroy'){
201          $this.removeData('headroom');
202        }
203      }
204    });
205  };
206
207  //////////////
208  // Data API //
209  //////////////
210
211  $('[data-headroom]').each(function() {
212    var $this = $(this);
213    $this.headroom($this.data());
214  });
215
216}(window.Zepto || window.jQuery));

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.