PageSourceSearch

https://vestnik-rm.ru/js/greedynav.js

js vestnik-rm.ru collected 2026-10-02 08:34:47 UTC 3,895 bytes, 143 lines download raw bytes

1/*
2GreedyNav.js - http://lukejacksonn.com/actuate
3Licensed under the MIT license - http://opensource.org/licenses/MIT
4Copyright (c) 2015 Luke Jackson
5*/
6
7$(function() {
8  var $btn = $('nav.greedy .menu_btn');
9  var $vlinks = $('nav.greedy .sf-menu');
10  var $hlinks = $('.hidden-links');
11  var numOfItems = 0;
12  var totalSpace = 0;
13  var closingTime = 1000;
14  var breakWidths = [];
15  var max_width = 768;
16  
17  // sf-vertical 
18	var $menu_btn_v = $('.menu_btn_v');
19	var $menu = $('.sf-vertical');
20	
21    	$menu_btn_v.on('click', function() {
22			$menu_btn_v.toggleClass('active');
23			$menu.toggle();
24		});
25
26  // - изначально display:none (в css для menu_btn_v)
27	$(window).on('resize', function(e){
28       var w = $(window).width();
29        	if(w <= max_width ) { 
30				$menu_btn_v.show();
31			}
32			else $menu_btn_v.hide();
33	});
34	  //!тут возможно что-то не так , но работает
35		var w = $(window).width();
36	        if(w <= max_width ) { 
37				$menu_btn_v.show();
38			}
39			else $menu_btn_v.hide();
40			
41//////////////////////////////
42	
43  // Get initial state
44  $vlinks.children().outerWidth(function(i, w) {
45    totalSpace += w;
46    numOfItems += 1;
47    breakWidths.push(totalSpace);
48  });
49  var availableSpace, numOfVisibleItems, requiredSpace, timer;
50  function check() {
51
52    // Get instant state
53    availableSpace = $vlinks.width() - 10;
54    numOfVisibleItems = $vlinks.children().length;
55    requiredSpace = breakWidths[numOfVisibleItems - 1];
56
57    // There is not enought space
58    if (requiredSpace > availableSpace) {
59      $vlinks.children().last().prependTo($hlinks);
60      numOfVisibleItems -= 1;
61      check();
62      // There is more than enough space
63    } else if (availableSpace > breakWidths[numOfVisibleItems]) {
64      $hlinks.children().first().appendTo($vlinks);
65      numOfVisibleItems += 1;
66      check();
67    }
68    // Update the button accordingly
69    $btn.attr("count", numOfItems - numOfVisibleItems);
70		if (numOfVisibleItems === numOfItems) {	
71			$btn.addClass('hidden');
72		} 
73		else $btn.removeClass('hidden'); 
74  }
75$(window).load(function() { //add
76 check();
77});
78  // Window listeners
79  $(window).resize(function() {
80    check();
81  });
82
83  $btn.on('click', function() {  
84 	$btn.toggleClass('active');
85    $hlinks.toggleClass('hidden');
86	clearTimeout(timer);
87  });
88  
89//закрытие по таймауту
90  $hlinks.on('mouseleave', function() {
91    // Mouse has left, start the timer
92		timer = setTimeout(function() {
93			$btn.removeClass('active');
94			$hlinks.addClass('hidden');
95		}, closingTime);
96  }).on('mouseenter', function() {
97    // Mouse is back, cancel the timer
98		clearTimeout(timer);
99  })
100
101   $menu.on('mouseleave', function() {
102	    var w = $(window).width();
103	   if(w <= max_width ) { 
104			timer = setTimeout(function() {
105			$menu_btn_v.removeClass('active')
106			$menu.hide();
107			}, closingTime);
108		}		
109	})	
110  .on('mouseenter', function() {
111		clearTimeout(timer);
112  })
113
114   //  в исходное состояние
115  	$(window).on('resize', function(e){
116       var w = $(window).width();
117        	if(w > max_width ) {
118				$hlinks.addClass('hidden');
119				$btn.removeClass('active');
120				$menu.attr('style', '');
121				$menu_btn_v.removeClass('active');
122			}
123	});
124
125// событие клика по веб-документу
126  $(document).mouseup(function (e){
127		if (!$btn.is(e.target)
128		    && $btn.has(e.target).length === 0) {
129			$btn.removeClass('active');
130			$hlinks.addClass('hidden');
131		}
132
133// кнопка menu_btn_v = active (при ширине w <= max_width )
134 var w = $(window).width();
135		if (w <= max_width && !$menu_btn_v.is(e.target)
136		    && $menu_btn_v.has(e.target).length === 0) {
137			$menu_btn_v.removeClass('active');
138			$menu.hide();
139		}
140	});
141  check();
142  
143});

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.