PageSourceSearch

https://akindo-sushiro.biz/shared/js/common/common.util.js

js akindo-sushiro.biz collected 2026-10-01 12:07:20 UTC 9,747 bytes, 384 lines download raw bytes

1;// Global Object
2var common = common || {};
3
4(function($){
5
6  /**
7   * @module util
8   */
9  var util = {};
10
11  util.mediaChange = function(callback){
12    var state = util.isOrientation();
13
14    $(window).on('resize.mediaChange', function(){
15      if(state !== util.isOrientation()){
16        if (callback) callback();
17        state = util.isOrientation();
18      }
19    }).trigger('resize.mediaChange');
20  };
21
22  util.isOrientation = function(){
23    var w = $(window).width(),
24        h = $(window).height();
25    return w < h ? 'portrait' : 'landscape';
26  };
27
28
29  util.isDisplayType = (function(){
30    var $head = $('head');
31    return function(type){
32      return $head.css('fontFamily') === type;
33    };
34  }());
35
36
37  /**
38   * アコーディオン
39   *
40   * @param  {[type]} $traget [description]
41   * @param  {[type]} options [description]
42   * @return {[type]}         [description]
43   */
44  util.accordion  = function($target, options){
45
46    var param = $.extend(true, {
47      $wrap: $target,
48      $trigger: $target.find('.acc-trigger'),
49      $target:  $target.find('.acc-trigger').attr('href'),
50      $targetH: $($target.find('.acc-trigger').attr('href')).outerHeight(),
51      hash:  location.hash,
52      isAnime :  false,
53      duration:  200,
54      easing  :  'ease-out',
55      callback: function(){}
56    }, options);
57
58    function Accordion(){
59      this.param = param;
60      this.init();
61    };
62
63    // prototype
64    var p = Accordion.prototype;
65
66    /**
67     * [init description]
68     * @return {[type]} [description]
69     */
70    p.init = function(){
71      var self = this;
72      param.$trigger.addClass('no-scroll');
73      self.setHeight();
74      self.setEvent();
75      self.setCurrent();
76      $(param.$target).css({'overflow':'hidden'});
77    };
78
79    /**
80     * [setEvent description]
81     * @return {[type]} [description]
82     */
83    p.setEvent = function(){
84      var self = this;
85      param.$trigger.click(function(){
86        self._controller();
87        return false;
88      });
89      //151111
90      //p.current();
91    };
92
93
94    /**
95     * [setEvent description]
96     * @return {[type]} [description]
97     */
98    p.setCurrent = function(){
99      var self = this;
100      if(!param.hash) return false;
101      var hash = param.hash.slice(1);
102      if(hash ==  param.$wrap.attr('id')){
103        //ターゲットとハッシュがマッチしたら処理を実行
104        self._controller();
105        $(window).scrollTop(param.$trigger.offset().top);
106      }
107    };
108
109    /**
110     * [setHeight description]
111     * @return {[type]} [description]
112     */
113    p.setHeight = function(){
114      var self = this;
115      if(!$(param.$target).hasClass('acc-open')){
116        $(param.$target).css({opacity: 0,height:'auto'});
117        param.$targetH = $(param.$target).height();
118        $(param.$target).css({height:'0',opacity: 1})
119      }else{
120        $(param.$target).css({height:'auto'});
121        param.$targetH = $(param.$target).height();
122        $(param.$target).css({height:param.$targetH})
123      }
124
125    };
126
127    /**
128     * [current description]
129     * @return {[type]} [description]
130     */
131    p.current = function(){
132      var self = this;
133      if(location.hash){
134        //ハッシュがついてる場合
135        param.thisNum  = location.hash;
136        this._controller();
137      }
138    }//_controller
139
140    /**
141     * [_controller description]
142     * @return {[type]} [description]
143     */
144
145    p._controller = function(){
146      var self = this;
147      if(param.isAnime) return false;
148      param.isAnime = true;
149      if(!$(param.$target).hasClass('acc-open')){
150        self.open(function(){
151          param.callback();
152          param.isAnime = false;
153        });
154      }else{
155        self.close(function(){
156          param.isAnime = false;
157          param.callback();
158        });
159      }
160    }//_controller
161
162    /**
163     * [open description]
164     * @return {[type]} [description]
165     */
166    p.open = function(callback){
167      var self = this;
168      $.sequence(function(){
169        param.$trigger.addClass('active');
170        $(param.$target).addClass('acc-open');
171        $(param.$target).addClass('acc-open');
172        return $(param.$target).velocity({
173          height:param.$targetH,
174          transitionProperty       : 'height',
175        },param.duration,param.easing);
176      },function(){
177        callback();
178      })//sequence
179    }//open
180
181    /**
182     * [close description]
183     * @return {[type]} [description]
184     */
185    p.close = function(callback){
186      var self = this;
187      $.sequence(function(){
188        param.$trigger.removeClass('active');
189        $(param.$target).removeClass('acc-open');
190        return $(param.$target).velocity({
191          height:'0',
192          transitionProperty       : 'height',
193        },param.duration,param.easing);
194      },function(){
195        $(param.$target).css({
196          'overflow':'hidden'
197        });
198        callback();
199      })
200    }//close
201
202    return new Accordion();
203  }
204
205  /**
206   * タブ
207   *
208   * @param  {[type]} $traget [description]
209   * @param  {[type]} options [description]
210   * @return {[type]}         [description]
211   */
212  util.tab = function($target, options){
213
214    var param = $.extend(true, {
215      $target   : $target,
216      $contWrap: $target.find('.tab-cont'),
217      $cont:     $target.find('.tab-sec'),
218      $navWrap:  $target.find('.nav'),
219      $trigger:  $target.find('.nav').find('li a'),
220      $thisTrigger: $target.find('.nav').find('li a'),
221      indexNum: $target.find('.nav').find('li a').eq(0).attr('href'),
222      hash:  location.hash,
223      isAnime :  false,
224      pcTabFlag   : false //PCでもタブ表示にする場合はtrueに
225    }, options);
226
227    function Tab(){
228      this.param = param;
229      this.init();
230    };
231
232    // prototype
233    var p = Tab.prototype;
234
235    /**
236     * [init description]
237     * @return {[type]} [description]
238     */
239    p.init = function(){
240      var self = this;
241       //ハッシュがマッチしていたら処理を実行
242      if(param.$cont.is(param.hash)){
243          self.current(param.hash);
244      }
245      this.set();
246      this.setEvent();
247      this.setHeight();
248      this._controller();
249
250  };
251
252
253    /**
254     * [set description]
255     * @return {[type]} [description]
256     */
257    p.set = function(){
258      var self = this;
259      param.$trigger.addClass('no-scroll');
260    };
261
262    /**
263     * [setEvent description]
264     * @return {[type]} [description]
265     */
266    p.setEvent = function(){
267      var self = this;
268      param.$trigger.click(function(){
269        var num = $(this).attr('href');
270        param.$thisTrigger = $(this);
271        param.indexNum  = num;
272        self._controller();
273        return false;
274      });
275
276      $(window).resize(function(){
277        self.setHeight();
278      })
279
280
281      Library.resizeStop(function(){
282        self.setHeight();
283    });
284
285      AMP.mediaquery.on('change', function(){
286        self.setMediaChange();
287      });//mediaquery
288    };
289
290    /**
291     * [_controller description]
292     * @return {[type]} [description]
293     */
294    p.current = function(num){
295      var self = this;
296
297      param.indexNum  = num;
298      this._controller();
299    }//current
300
301    /**
302     * [_controller description]
303     * @return {[type]} [description]
304     */
305    p._controller = function(){
306      var self = this;
307
308      if(!param.isAnime){
309        param.isAnime = true;
310        this.setHeight();
311        this.tween(function(){
312          param.isAnime = false;
313        });
314        this.navActive();
315      }
316    }//_controller
317
318    /**
319     * [setHeight description]
320     * @return {[type]} [description]
321     */
322    p.setHeight = function(){
323      var self = this;
324      var height = $(param.indexNum).outerHeight();
325      //pcTabFlagがfalseかつ表示がPCの場合、高さ指定しない
326      if(!param.pcTabFlag && !common.util.isDisplayType('sp')){
327        height = 'auto';
328      }
329      param.$contWrap.css({height: height});
330    };
331
332    /**
333     * [setHeight description]
334     * @return {[type]} [description]
335     */
336    p.setMediaChange = function(){
337      var self = this;
338      //pcTabFlagがfalseかつ表示がPCの場合、表示を変更
339      if(!param.pcTabFlag && !common.util.isDisplayType('sp')){
340        param.$cont.css({display:'block'});
341      }else if(param.pcTabFlag || common.util.isDisplayType('sp')){
342        this._controller();
343      }
344    };
345
346    /**
347     * [tween description]
348     * @return {[type]} [description]
349     */
350    p.tween = function(callback){
351      var self = this;
352
353      var wHeight = $("html,body").height();
354      var thisTop = $(window).scrollTop();
355      var $target = ($(param.indexNum));
356      param.$cont.css({display:'none'});
357      $target.css({display:'block'});
358      var targetHeight = $target.outerHeight();
359      $("html,body").animate({scrollTop:$("html,body").offset().top},300);
360      param.$contWrap.animate({height: targetHeight},300,function(){
361        callback();
362      });
363    };
364
365    /**
366     * [navActive description]
367     * @return {[type]} [description]
368     */
369    p.navActive = function(){
370      param.$trigger.removeClass('active');
371      $('a[href = '+ param.indexNum +']').addClass('active');
372    }
373
374    return new Tab();
375  };
376
377
378  /*--------------------------------------------------------------------------
379   export
380   --------------------------------------------------------------------------*/
381
382  common.util = util;
383
384}(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.