PageSourceSearch

https://motoyama-e.com/nishicho/wp/wp-content/themes/nishicho/js/common.js

js motoyama-e.com collected 2026-10-08 13:17:36 UTC 6,104 bytes, 250 lines download raw bytes

1/* common.js */
2
3var BRK = 768;
4var usr;
5var screenH = screen.height * 1.2;//スクリーン高(≠ウィンドウ高)
6var w, y=0, spmenu_bg_y, menuState, navIsOpen;;
7
8$(function () {
9
10  usr = uaCall(BRK);
11  
12  //スマホナビ
13  if (usr === 'sp') {
14    spNavi();
15  }
16  
17  //デバイス判定(PCは電話リンク不要)
18  if(deviceCall() === "other"){
19    $("a.tellink").css({"pointer-events": "none"});
20  }
21  
22  var timer = false;
23  var $bp;
24  var id = $('.wrapper').attr("id");
25  
26  $(window).on('load resize',function(){
27    if (timer !== false) {
28      clearTimeout(timer);
29    }    
30    timer = setTimeout(function () {
31      var w = window.innerWidth;
32      if (usr === 'pc') {
33        if (id === 'home') {
34        }else{
35          $(".outer_breadcrumbs").css({"padding-top":$('.area_gnavi').innerHeight()});
36        }        
37      }else{
38        $("#gnavi_sp_menu").css({"height":window.innerHeight - $('.gnavi_sp .top').innerHeight()});
39      }
40      
41      if ((usr === 'pc' && w <= BRK) || (usr === 'sp' && w > BRK)) {     
42        location.reload();
43      }      
44    }, 100);
45  });  
46
47  $(window).on('load scroll', function() {
48    y = window.pageYOffset;
49      if (y > 100) {
50        $("#pagetop").addClass('on');
51      } else {
52        $("#pagetop").removeClass('on');
53      }   
54    
55      if (y > 5) {
56        $('#gnavi').addClass("on");
57      }else{
58        $('#gnavi').removeClass("on");
59      }
60  });
61  
62  //anchor
63  $('a[href^="#"],area[href^="#"]').on('click', function() {
64      var speed = 500;
65      var href= $(this).attr("href");
66      var target = $(href === "#" || href === "" ? 'html' : href);
67      var position = target.offset().top;
68      if(href !== "#top"){
69        if(usr === 'sp'){
70          position = position - $(".gnavi_sp").innerHeight() - 20;
71        }else{
72         position = position - $("#gnavi").innerHeight() - 20;
73        }
74      }
75      $('body,html').animate({scrollTop:position}, speed, 'swing');
76      return false;
77  });
78  
79  window.addEventListener('load', function () {
80    var urlHash = location.hash;
81    if(urlHash){
82      var position = $(urlHash).offset().top;
83      if(usr === 'sp'){
84        position = position - $(".gnavi_sp").innerHeight() - 20;
85      }else{
86        position = position - $("#gnavi").innerHeight() - 20;
87      }
88      $('body,html').animate({scrollTop:position},500);
89    }
90  });  
91  
92  //ページ判定&ステイ表示など
93  if (usr === 'pc') {
94    //ページ判定&ステイ表示
95    $("#gnavi ul li."+id).addClass("active");
96    
97    if(id === "information" || id === "faculty" || id === "admission"){
98      var nav = $("main").attr("id");
99      $(".box_submenu ul li."+nav).addClass("active");
100      $(".section_link ul li."+nav).addClass("active");
101    }
102  }
103
104  //アコーディオン
105  $(".box_accordion > dl").children("dt").on('click', function () {
106    $(this).toggleClass('on');
107    $(this).next("dd").slideToggle();
108    return false;
109  });  
110  
111  //heder gnav
112  var $self_child;
113  var spd = 300;
114  var $gn_item = $('#gnavi_pc > li');
115  var $child = $gn_item.find('.box_sub');
116  
117  var delayTime = 100;
118  var moveTimer = 0;
119
120  $gn_item.on('mousemove', function () {
121    var $this = $(this);
122    if (usr === 'pc' && deviceCall() === "other") {
123      clearTimeout(moveTimer);
124      moveTimer = setTimeout(function(){
125        $self_child = $this.find('.box_sub');
126        //reset
127        $child.stop().attr({
128          'aria-hidden': "true"
129        }).fadeOut(spd);
130        //Menu:Open
131        $self_child.stop().attr({
132          'aria-hidden': "false"
133        }).fadeIn(spd);
134      }, delayTime);      
135    }
136  }).on('mouseleave', function () {
137    if (usr === 'pc' && deviceCall() === "other") {
138      clearTimeout(moveTimer);
139      //Menu:Close
140      $child.stop().attr({
141        'aria-hidden': "true"
142      }).fadeOut(spd);
143    }
144  });
145
146  
147});
148
149
150/*スクリーン判定
151------------------------------------------------------*/
152function uaCall(BRK) {
153  var w = window.innerWidth;
154  if (w > BRK) {
155    return 'pc';
156  } else {
157    return 'sp';
158  }
159}
160
161/*端末判定
162------------------------------------------------------*/
163function deviceCall() {
164    var ua = navigator.userAgent;
165    if (ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) {
166        return 'sp';
167    } else if (ua.indexOf('iPad') > 0 || ua.indexOf('Android') > 0) {
168        return 'tablet';
169    } else {
170        return 'other';
171    }
172}
173
174/*スマホメニュー
175------------------------------------------------------*/
176var y=0, spmenu_bg_y, navIsOpen = false;
177var scrollpos;  
178var $btn = $(".menu-trigger");
179var $gn = $('#gnavi_sp_menu');
180
181function spNavi() {
182  usr = uaCall(BRK);
183  
184    //メニュー開く
185    $btn.on('click', function () {
186      if(!navIsOpen){
187        scrollpos = $(window).scrollTop();
188        stopScroll(scrollpos);  
189        //$gn.css({height:$(window).height()});
190        $gn.fadeIn("200");
191        $btn.addClass('active');
192        navIsOpen = true;
193        return false;
194      }else{
195        spClose();  
196      }
197    });
198    //閉じる
199    $('#menu.active').on('click', function () {
200      spClose();
201    });
202  
203  //アコーディオン
204  $(".accordion",$gn).find(".ico").on('click', function () {
205    $(this).closest("li").toggleClass('on');
206    $(this).parent("a").next("ul").slideToggle();
207    return false;
208  });  
209  $(".accordion .anclink").on('click', function () {
210    spClose();
211  });   
212}
213
214//bodyスクロール禁止
215function stopScroll(posY){
216  var h = window.innerHeight;
217  $('body').addClass('fixed').css({'top': -posY,"height":h,"overflow-y":'hidden'});
218  $('html').css({"overflow":"hidden"});
219}
220
221//bodyスクロール解禁
222function allowScroll(posY){
223  $('body').removeClass('fixed').css({'top': 0,"height":"auto","overflow-y": "auto"});
224  $('html').css({"overflow":"auto"});
225  window.scrollTo( 0, posY );
226}
227
228//スマホメニューを閉じる
229function spClose() {
230  if (navIsOpen) {
231    allowScroll(scrollpos);
232    $gn.fadeOut(200, function () {
233      $btn.removeClass('active');
234      navIsOpen = false;
235    });
236    return false;
237  }
238}
239
240
241
242
243
244
245
246
247
248
249
250

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.