PageSourceSearch

https://member.fukuoka-leapup.jp/front/js/drawer.js

js fukuoka-leapup.jp collected 2026-09-24 23:19:18 UTC 4,819 bytes, 173 lines download raw bytes

1;(function umd(factory) {
2  'use strict';
3  if (typeof define === 'function' && define.amd) {
4    define(['jquery'], factory);
5  } else if (typeof exports === 'object') {
6    module.exports = factory(require('jquery'));
7  } else {
8    factory(jQuery);
9  }
10}(function Drawer($) {
11  'use strict';
12  var namespace = 'drawer';
13  var touches = typeof document.ontouchstart != 'undefined';
14  var __ = {
15    init: function init(options) {
16      options = $.extend({
17        iscroll: {
18          mouseWheel: true,
19          preventDefault: false
20        },
21        showOverlay: true
22      }, options);
23
24      __.settings = {
25        state: false,
26        events: {
27          opened: 'drawer.opened',
28          closed: 'drawer.closed'
29        },
30        dropdownEvents: {
31          opened: 'shown.bs.dropdown',
32          closed: 'hidden.bs.dropdown'
33        }
34      };
35
36      __.settings.class = $.extend({
37        nav: 'drawer-nav',
38        toggle: 'drawer-toggle',
39        overlay: 'drawer-overlay',
40        open: 'drawer-open',
41        close: 'drawer-close',
42        dropdown: 'drawer-dropdown'
43      }, options.class);
44
45      return this.each(function instantiateDrawer() {
46        var _this = this;
47        var $this = $(this);
48        var data = $this.data(namespace);
49
50        if (!data) {
51          options = $.extend({}, options);
52          $this.data(namespace, { options: options });
53
54          __.refresh.call(_this);
55
56          if (options.showOverlay) {
57            __.addOverlay.call(_this);
58          }
59
60          $('.' + __.settings.class.toggle).on('click.' + namespace, function toggle() {
61            __.toggle.call(_this);
62            return _this.iScroll.refresh();
63          });
64
65          $(window).on('resize.' + namespace, function close() {
66 //           __.close.call(_this);
67            return _this.iScroll.refresh();
68          });
69
70          $('.' + __.settings.class.dropdown)
71            .on(__.settings.dropdownEvents.opened + ' ' + __.settings.dropdownEvents.closed, function onOpenedOrClosed() {
72              return _this.iScroll.refresh();
73            });
74        }
75
76      }); // end each
77    },
78
79    refresh: function refresh() {
80      this.iScroll = new IScroll(
81        '.' + __.settings.class.nav,
82        $(this).data(namespace).options.iscroll
83      );
84    },
85
86    addOverlay: function addOverlay() {
87      var $this = $(this);
88      var $overlay = $('<div>').addClass(__.settings.class.overlay + ' ' + __.settings.class.toggle);
89
90      return $this.append($overlay);
91    },
92
93    toggle: function toggle() {
94      var _this = this;
95
96      if (__.settings.state) {
97        return __.close.call(_this);
98      } else {
99        return __.open.call(_this);
100      }
101    },
102
103    open: function open() {
104      var $this = $(this);
105
106      if (touches) {
107        $this.on('touchmove.' + namespace, function disableTouch(event) {
108          event.preventDefault();
109        });
110      }
111
112      return $this
113        .removeClass(__.settings.class.close)
114        .addClass(__.settings.class.open)
115        .drawerCallback(function triggerOpenedListeners() {
116          __.settings.state = true;
117          $this.trigger(__.settings.events.opened);
118        });
119    },
120
121    close: function close() {
122      var $this = $(this);
123
124      if (touches) $this.off('touchmove.' + namespace);
125
126      return $this
127        .removeClass(__.settings.class.open)
128        .addClass(__.settings.class.close)
129        .drawerCallback(function triggerClosedListeners() {
130          __.settings.state = false;
131          $this.trigger(__.settings.events.closed);
132        });
133    },
134
135    destroy: function destroy() {
136      return this.each(function destroyEach() {
137        var _this = this;
138        var $this = $(this);
139        $('.' + __.settings.class.toggle).off('click.' + namespace);
140        $(window).off('resize.' + namespace);
141        $('.' + __.settings.class.dropdown).off(__.settings.dropdownEvents.opened + ' ' + __.settings.dropdownEvents.closed);
142        _this.iScroll.destroy();
143        $this
144          .removeData(namespace)
145          .find('.' + __.settings.class.overlay)
146          .remove();
147      });
148    }
149
150  };
151
152  $.fn.drawerCallback = function drawerCallback(callback) {
153    var end = 'transitionend webkitTransitionEnd';
154    return this.each(function setAnimationEndHandler() {
155      var $this = $(this);
156      $this.on(end, function invokeCallbackOnAnimationEnd() {
157        $this.off(end);
158        return callback.call(this);
159      });
160    });
161  };
162
163  $.fn.drawer = function drawer(method) {
164    if (__[method]) {
165      return __[method].apply(this, Array.prototype.slice.call(arguments, 1));
166    } else if (typeof method === 'object' || !method) {
167      return __.init.apply(this, arguments);
168    } else {
169      $.error('Method ' + method + ' does not exist on jQuery.' + namespace);
170    }
171  };
172
173}));

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.