materialize-sass 0.100.2.1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +18 -42
  3. data/Rakefile +17 -17
  4. data/{app/assets → assets}/javascripts/materialize-sprockets.js +8 -12
  5. data/assets/javascripts/materialize.js +11877 -0
  6. data/assets/javascripts/materialize/autocomplete.js +420 -0
  7. data/assets/javascripts/materialize/buttons.js +388 -0
  8. data/assets/javascripts/materialize/cards.js +28 -0
  9. data/assets/javascripts/materialize/carousel.js +791 -0
  10. data/assets/javascripts/materialize/cash.js +992 -0
  11. data/assets/javascripts/materialize/characterCounter.js +180 -0
  12. data/assets/javascripts/materialize/chips.js +555 -0
  13. data/assets/javascripts/materialize/collapsible.js +275 -0
  14. data/assets/javascripts/materialize/datepicker.js +898 -0
  15. data/assets/javascripts/materialize/dropdown.js +530 -0
  16. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.js +1 -1
  17. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.min.js +1 -1
  18. data/assets/javascripts/materialize/forms.js +223 -0
  19. data/assets/javascripts/materialize/global.js +353 -0
  20. data/assets/javascripts/materialize/materialbox.js +432 -0
  21. data/{app/assets → assets}/javascripts/materialize/modal.js +82 -113
  22. data/assets/javascripts/materialize/parallax.js +135 -0
  23. data/assets/javascripts/materialize/pushpin.js +158 -0
  24. data/assets/javascripts/materialize/range.js +305 -0
  25. data/assets/javascripts/materialize/scrollspy.js +322 -0
  26. data/assets/javascripts/materialize/select.js +426 -0
  27. data/assets/javascripts/materialize/sidenav.js +584 -0
  28. data/assets/javascripts/materialize/slider.js +383 -0
  29. data/assets/javascripts/materialize/tabs.js +460 -0
  30. data/assets/javascripts/materialize/tapTarget.js +347 -0
  31. data/assets/javascripts/materialize/timepicker.js +616 -0
  32. data/{app/assets → assets}/javascripts/materialize/toasts.js +42 -46
  33. data/assets/javascripts/materialize/tooltip.js +325 -0
  34. data/assets/javascripts/materialize/velocity.min.js +782 -0
  35. data/{app/assets → assets}/javascripts/materialize/waves.js +0 -0
  36. data/{app/assets → assets}/stylesheets/materialize.scss +5 -6
  37. data/{app/assets → assets}/stylesheets/materialize/components/_badges.scss +1 -1
  38. data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +34 -2
  39. data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +0 -0
  40. data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +1 -1
  41. data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +6 -5
  42. data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +3 -3
  43. data/{app/assets → assets}/stylesheets/materialize/components/_color.scss +0 -0
  44. data/assets/stylesheets/materialize/components/_datepicker.scss +180 -0
  45. data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +16 -15
  46. data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +49 -14
  47. data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +1 -1
  48. data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
  49. data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +0 -0
  50. data/assets/stylesheets/materialize/components/_mixins.scss +5 -0
  51. data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +1 -1
  52. data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +0 -0
  53. data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
  54. data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +0 -0
  55. data/{app/assets → assets}/stylesheets/materialize/components/_pulse.scss +0 -0
  56. data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +23 -21
  57. data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
  58. data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +3 -3
  59. data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +2 -2
  60. data/{app/assets → assets}/stylesheets/materialize/components/_tapTarget.scss +0 -0
  61. data/assets/stylesheets/materialize/components/_timepicker.scss +182 -0
  62. data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +0 -0
  63. data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +1 -0
  64. data/{app/assets → assets}/stylesheets/materialize/components/_transitions.scss +0 -0
  65. data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -8
  66. data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +42 -44
  67. data/{app/assets → assets}/stylesheets/materialize/components/_waves.scss +0 -0
  68. data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +24 -24
  69. data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +0 -0
  70. data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
  71. data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +49 -35
  72. data/{app/assets → assets}/stylesheets/materialize/components/forms/_radio-buttons.scss +29 -29
  73. data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +32 -31
  74. data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +20 -11
  75. data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +0 -0
  76. data/{app/assets → assets}/stylesheets/materialize/extras/nouislider.css +1 -1
  77. data/lib/materialize-sass.rb +13 -23
  78. data/lib/materialize-sass/engine.rb +6 -9
  79. data/lib/materialize-sass/version.rb +1 -1
  80. data/materialize-sass.gemspec +2 -1
  81. metadata +97 -97
  82. data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
  83. data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
  84. data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
  85. data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
  86. data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
  87. data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
  88. data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
  89. data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
  90. data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
  91. data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
  92. data/app/assets/javascripts/materialize.js +0 -10021
  93. data/app/assets/javascripts/materialize/animation.js +0 -7
  94. data/app/assets/javascripts/materialize/buttons.js +0 -253
  95. data/app/assets/javascripts/materialize/cards.js +0 -28
  96. data/app/assets/javascripts/materialize/carousel.js +0 -543
  97. data/app/assets/javascripts/materialize/character_counter.js +0 -64
  98. data/app/assets/javascripts/materialize/chips.js +0 -315
  99. data/app/assets/javascripts/materialize/collapsible.js +0 -178
  100. data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1399
  101. data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1196
  102. data/app/assets/javascripts/materialize/date_picker/picker.time.js +0 -646
  103. data/app/assets/javascripts/materialize/dropdown.js +0 -257
  104. data/app/assets/javascripts/materialize/forms.js +0 -806
  105. data/app/assets/javascripts/materialize/global.js +0 -170
  106. data/app/assets/javascripts/materialize/hammer.min.js +0 -424
  107. data/app/assets/javascripts/materialize/initial.js +0 -10
  108. data/app/assets/javascripts/materialize/jquery.easing.1.4.js +0 -144
  109. data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
  110. data/app/assets/javascripts/materialize/materialbox.js +0 -263
  111. data/app/assets/javascripts/materialize/parallax.js +0 -54
  112. data/app/assets/javascripts/materialize/pushpin.js +0 -68
  113. data/app/assets/javascripts/materialize/scrollFire.js +0 -49
  114. data/app/assets/javascripts/materialize/scrollspy.js +0 -230
  115. data/app/assets/javascripts/materialize/sideNav.js +0 -395
  116. data/app/assets/javascripts/materialize/slider.js +0 -295
  117. data/app/assets/javascripts/materialize/tabs.js +0 -244
  118. data/app/assets/javascripts/materialize/tapTarget.js +0 -184
  119. data/app/assets/javascripts/materialize/tooltip.js +0 -227
  120. data/app/assets/javascripts/materialize/transitions.js +0 -163
  121. data/app/assets/javascripts/materialize/velocity.min.js +0 -626
  122. data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
  123. data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -39
  124. data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -469
  125. data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -216
  126. data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -267
@@ -1,54 +0,0 @@
1
- (function ($) {
2
-
3
- $.fn.parallax = function () {
4
- var window_width = $(window).width();
5
- // Parallax Scripts
6
- return this.each(function (i) {
7
- var $this = $(this);
8
- $this.addClass('parallax');
9
-
10
- function updateParallax(initial) {
11
- var container_height;
12
- if (window_width < 601) {
13
- container_height = $this.height() > 0 ? $this.height() : $this.children("img").height();
14
- } else {
15
- container_height = $this.height() > 0 ? $this.height() : 500;
16
- }
17
- var $img = $this.children("img").first();
18
- var img_height = $img.height();
19
- var parallax_dist = img_height - container_height;
20
- var bottom = $this.offset().top + container_height;
21
- var top = $this.offset().top;
22
- var scrollTop = $(window).scrollTop();
23
- var windowHeight = window.innerHeight;
24
- var windowBottom = scrollTop + windowHeight;
25
- var percentScrolled = (windowBottom - top) / (container_height + windowHeight);
26
- var parallax = Math.round(parallax_dist * percentScrolled);
27
-
28
- if (initial) {
29
- $img.css('display', 'block');
30
- }
31
- if (bottom > scrollTop && top < scrollTop + windowHeight) {
32
- $img.css('transform', "translate3D(-50%," + parallax + "px, 0)");
33
- }
34
- }
35
-
36
- // Wait for image load
37
- $this.children("img").one("load", function () {
38
- updateParallax(true);
39
- }).each(function () {
40
- if (this.complete) $(this).trigger("load");
41
- });
42
-
43
- $(window).scroll(function () {
44
- window_width = $(window).width();
45
- updateParallax(false);
46
- });
47
-
48
- $(window).resize(function () {
49
- window_width = $(window).width();
50
- updateParallax(false);
51
- });
52
- });
53
- };
54
- })(jQuery);
@@ -1,68 +0,0 @@
1
- (function ($) {
2
- $.fn.pushpin = function (options) {
3
- // Defaults
4
- var defaults = {
5
- top: 0,
6
- bottom: Infinity,
7
- offset: 0
8
- };
9
-
10
- // Remove pushpin event and classes
11
- if (options === "remove") {
12
- this.each(function () {
13
- if (id = $(this).data('pushpin-id')) {
14
- $(window).off('scroll.' + id);
15
- $(this).removeData('pushpin-id').removeClass('pin-top pinned pin-bottom').removeAttr('style');
16
- }
17
- });
18
- return false;
19
- }
20
-
21
- options = $.extend(defaults, options);
22
-
23
- $index = 0;
24
- return this.each(function () {
25
- var $uniqueId = Materialize.guid(),
26
- $this = $(this),
27
- $original_offset = $(this).offset().top;
28
-
29
- function removePinClasses(object) {
30
- object.removeClass('pin-top');
31
- object.removeClass('pinned');
32
- object.removeClass('pin-bottom');
33
- }
34
-
35
- function updateElements(objects, scrolled) {
36
- objects.each(function () {
37
- // Add position fixed (because its between top and bottom)
38
- if (options.top <= scrolled && options.bottom >= scrolled && !$(this).hasClass('pinned')) {
39
- removePinClasses($(this));
40
- $(this).css('top', options.offset);
41
- $(this).addClass('pinned');
42
- }
43
-
44
- // Add pin-top (when scrolled position is above top)
45
- if (scrolled < options.top && !$(this).hasClass('pin-top')) {
46
- removePinClasses($(this));
47
- $(this).css('top', 0);
48
- $(this).addClass('pin-top');
49
- }
50
-
51
- // Add pin-bottom (when scrolled position is below bottom)
52
- if (scrolled > options.bottom && !$(this).hasClass('pin-bottom')) {
53
- removePinClasses($(this));
54
- $(this).addClass('pin-bottom');
55
- $(this).css('top', options.bottom - $original_offset);
56
- }
57
- });
58
- }
59
-
60
- $(this).data('pushpin-id', $uniqueId);
61
- updateElements($this, $(window).scrollTop());
62
- $(window).on('scroll.' + $uniqueId, function () {
63
- var $scrolled = $(window).scrollTop() + options.offset;
64
- updateElements($this, $scrolled);
65
- });
66
- });
67
- };
68
- })(jQuery);
@@ -1,49 +0,0 @@
1
- (function ($) {
2
-
3
- var scrollFireEventsHandled = false;
4
-
5
- // Input: Array of JSON objects {selector, offset, callback}
6
- Materialize.scrollFire = function (options) {
7
- var onScroll = function () {
8
- var windowScroll = window.pageYOffset + window.innerHeight;
9
-
10
- for (var i = 0; i < options.length; i++) {
11
- // Get options from each line
12
- var value = options[i];
13
- var selector = value.selector,
14
- offset = value.offset,
15
- callback = value.callback;
16
-
17
- var currentElement = document.querySelector(selector);
18
- if (currentElement !== null) {
19
- var elementOffset = currentElement.getBoundingClientRect().top + window.pageYOffset;
20
-
21
- if (windowScroll > elementOffset + offset) {
22
- if (value.done !== true) {
23
- if (typeof callback === 'function') {
24
- callback.call(this, currentElement);
25
- } else if (typeof callback === 'string') {
26
- var callbackFunc = new Function(callback);
27
- callbackFunc(currentElement);
28
- }
29
- value.done = true;
30
- }
31
- }
32
- }
33
- }
34
- };
35
-
36
- var throttledScroll = Materialize.throttle(function () {
37
- onScroll();
38
- }, options.throttle || 100);
39
-
40
- if (!scrollFireEventsHandled) {
41
- window.addEventListener("scroll", throttledScroll);
42
- window.addEventListener("resize", throttledScroll);
43
- scrollFireEventsHandled = true;
44
- }
45
-
46
- // perform a scan once, after current execution context, and after dom is ready
47
- setTimeout(throttledScroll, 0);
48
- };
49
- })(jQuery);
@@ -1,230 +0,0 @@
1
- /**
2
- * Extend jquery with a scrollspy plugin.
3
- * This watches the window scroll and fires events when elements are scrolled into viewport.
4
- *
5
- * throttle() and getTime() taken from Underscore.js
6
- * https://github.com/jashkenas/underscore
7
- *
8
- * @author Copyright 2013 John Smart
9
- * @license https://raw.github.com/thesmart/jquery-scrollspy/master/LICENSE
10
- * @see https://github.com/thesmart
11
- * @version 0.1.2
12
- */
13
- (function ($) {
14
-
15
- var jWindow = $(window);
16
- var elements = [];
17
- var elementsInView = [];
18
- var isSpying = false;
19
- var ticks = 0;
20
- var unique_id = 1;
21
- var offset = {
22
- top: 0,
23
- right: 0,
24
- bottom: 0,
25
- left: 0
26
-
27
- /**
28
- * Find elements that are within the boundary
29
- * @param {number} top
30
- * @param {number} right
31
- * @param {number} bottom
32
- * @param {number} left
33
- * @return {jQuery} A collection of elements
34
- */
35
- };function findElements(top, right, bottom, left) {
36
- var hits = $();
37
- $.each(elements, function (i, element) {
38
- if (element.height() > 0) {
39
- var elTop = element.offset().top,
40
- elLeft = element.offset().left,
41
- elRight = elLeft + element.width(),
42
- elBottom = elTop + element.height();
43
-
44
- var isIntersect = !(elLeft > right || elRight < left || elTop > bottom || elBottom < top);
45
-
46
- if (isIntersect) {
47
- hits.push(element);
48
- }
49
- }
50
- });
51
-
52
- return hits;
53
- }
54
-
55
- /**
56
- * Called when the user scrolls the window
57
- */
58
- function onScroll(scrollOffset) {
59
- // unique tick id
60
- ++ticks;
61
-
62
- // viewport rectangle
63
- var top = jWindow.scrollTop(),
64
- left = jWindow.scrollLeft(),
65
- right = left + jWindow.width(),
66
- bottom = top + jWindow.height();
67
-
68
- // determine which elements are in view
69
- var intersections = findElements(top + offset.top + scrollOffset || 200, right + offset.right, bottom + offset.bottom, left + offset.left);
70
- $.each(intersections, function (i, element) {
71
-
72
- var lastTick = element.data('scrollSpy:ticks');
73
- if (typeof lastTick != 'number') {
74
- // entered into view
75
- element.triggerHandler('scrollSpy:enter');
76
- }
77
-
78
- // update tick id
79
- element.data('scrollSpy:ticks', ticks);
80
- });
81
-
82
- // determine which elements are no longer in view
83
- $.each(elementsInView, function (i, element) {
84
- var lastTick = element.data('scrollSpy:ticks');
85
- if (typeof lastTick == 'number' && lastTick !== ticks) {
86
- // exited from view
87
- element.triggerHandler('scrollSpy:exit');
88
- element.data('scrollSpy:ticks', null);
89
- }
90
- });
91
-
92
- // remember elements in view for next tick
93
- elementsInView = intersections;
94
- }
95
-
96
- /**
97
- * Called when window is resized
98
- */
99
- function onWinSize() {
100
- jWindow.trigger('scrollSpy:winSize');
101
- }
102
-
103
- /**
104
- * Enables ScrollSpy using a selector
105
- * @param {jQuery|string} selector The elements collection, or a selector
106
- * @param {Object=} options Optional.
107
- throttle : number -> scrollspy throttling. Default: 100 ms
108
- offsetTop : number -> offset from top. Default: 0
109
- offsetRight : number -> offset from right. Default: 0
110
- offsetBottom : number -> offset from bottom. Default: 0
111
- offsetLeft : number -> offset from left. Default: 0
112
- activeClass : string -> Class name to be added to the active link. Default: active
113
- * @returns {jQuery}
114
- */
115
- $.scrollSpy = function (selector, options) {
116
- var defaults = {
117
- throttle: 100,
118
- scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
119
- activeClass: 'active',
120
- getActiveElement: function (id) {
121
- return 'a[href="#' + id + '"]';
122
- }
123
- };
124
- options = $.extend(defaults, options);
125
-
126
- var visible = [];
127
- selector = $(selector);
128
- selector.each(function (i, element) {
129
- elements.push($(element));
130
- $(element).data("scrollSpy:id", i);
131
- // Smooth scroll to section
132
- $('a[href="#' + $(element).attr('id') + '"]').click(function (e) {
133
- e.preventDefault();
134
- var offset = $(Materialize.escapeHash(this.hash)).offset().top + 1;
135
- $('html, body').animate({ scrollTop: offset - options.scrollOffset }, { duration: 400, queue: false, easing: 'easeOutCubic' });
136
- });
137
- });
138
-
139
- offset.top = options.offsetTop || 0;
140
- offset.right = options.offsetRight || 0;
141
- offset.bottom = options.offsetBottom || 0;
142
- offset.left = options.offsetLeft || 0;
143
-
144
- var throttledScroll = Materialize.throttle(function () {
145
- onScroll(options.scrollOffset);
146
- }, options.throttle || 100);
147
- var readyScroll = function () {
148
- $(document).on('ready turbolinks:load', throttledScroll);
149
- };
150
-
151
- if (!isSpying) {
152
- jWindow.on('scroll', readyScroll);
153
- jWindow.on('resize', readyScroll);
154
- isSpying = true;
155
- }
156
-
157
- // perform a scan once, after current execution context, and after dom is ready
158
- setTimeout(readyScroll, 0);
159
-
160
- selector.on('scrollSpy:enter', function () {
161
- visible = $.grep(visible, function (value) {
162
- return value.height() != 0;
163
- });
164
-
165
- var $this = $(this);
166
-
167
- if (visible[0]) {
168
- $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass);
169
- if ($this.data('scrollSpy:id') < visible[0].data('scrollSpy:id')) {
170
- visible.unshift($(this));
171
- } else {
172
- visible.push($(this));
173
- }
174
- } else {
175
- visible.push($(this));
176
- }
177
-
178
- $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass);
179
- });
180
- selector.on('scrollSpy:exit', function () {
181
- visible = $.grep(visible, function (value) {
182
- return value.height() != 0;
183
- });
184
-
185
- if (visible[0]) {
186
- $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass);
187
- var $this = $(this);
188
- visible = $.grep(visible, function (value) {
189
- return value.attr('id') != $this.attr('id');
190
- });
191
- if (visible[0]) {
192
- // Check if empty
193
- $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass);
194
- }
195
- }
196
- });
197
-
198
- return selector;
199
- };
200
-
201
- /**
202
- * Listen for window resize events
203
- * @param {Object=} options Optional. Set { throttle: number } to change throttling. Default: 100 ms
204
- * @returns {jQuery} $(window)
205
- */
206
- $.winSizeSpy = function (options) {
207
- $.winSizeSpy = function () {
208
- return jWindow;
209
- }; // lock from multiple calls
210
- options = options || {
211
- throttle: 100
212
- };
213
- return jWindow.on('resize', Materialize.throttle(onWinSize, options.throttle || 100));
214
- };
215
-
216
- /**
217
- * Enables ScrollSpy on a collection of elements
218
- * e.g. $('.scrollSpy').scrollSpy()
219
- * @param {Object=} options Optional.
220
- throttle : number -> scrollspy throttling. Default: 100 ms
221
- offsetTop : number -> offset from top. Default: 0
222
- offsetRight : number -> offset from right. Default: 0
223
- offsetBottom : number -> offset from bottom. Default: 0
224
- offsetLeft : number -> offset from left. Default: 0
225
- * @returns {jQuery}
226
- */
227
- $.fn.scrollSpy = function (options) {
228
- return $.scrollSpy($(this), options);
229
- };
230
- })(jQuery);
@@ -1,395 +0,0 @@
1
- (function ($) {
2
-
3
- var methods = {
4
- init: function (options) {
5
- var defaults = {
6
- menuWidth: 300,
7
- edge: 'left',
8
- closeOnClick: false,
9
- draggable: true,
10
- onOpen: null,
11
- onClose: null
12
- };
13
- options = $.extend(defaults, options);
14
-
15
- $(this).each(function () {
16
- var $this = $(this);
17
- var menuId = $this.attr('data-activates');
18
- var menu = $("#" + menuId);
19
-
20
- // Set to width
21
- if (options.menuWidth != 300) {
22
- menu.css('width', options.menuWidth);
23
- }
24
-
25
- // Add Touch Area
26
- var $dragTarget = $('.drag-target[data-sidenav="' + menuId + '"]');
27
- if (options.draggable) {
28
- // Regenerate dragTarget
29
- if ($dragTarget.length) {
30
- $dragTarget.remove();
31
- }
32
-
33
- $dragTarget = $('<div class="drag-target"></div>').attr('data-sidenav', menuId);
34
- $('body').append($dragTarget);
35
- } else {
36
- $dragTarget = $();
37
- }
38
-
39
- if (options.edge == 'left') {
40
- menu.css('transform', 'translateX(-100%)');
41
- $dragTarget.css({ 'left': 0 }); // Add Touch Area
42
- } else {
43
- menu.addClass('right-aligned') // Change text-alignment to right
44
- .css('transform', 'translateX(100%)');
45
- $dragTarget.css({ 'right': 0 }); // Add Touch Area
46
- }
47
-
48
- // If fixed sidenav, bring menu out
49
- if (menu.hasClass('fixed')) {
50
- if (window.innerWidth > 992) {
51
- menu.css('transform', 'translateX(0)');
52
- }
53
- }
54
-
55
- // Window resize to reset on large screens fixed
56
- if (menu.hasClass('fixed')) {
57
- $(window).resize(function () {
58
- if (window.innerWidth > 992) {
59
- // Close menu if window is resized bigger than 992 and user has fixed sidenav
60
- if ($('#sidenav-overlay').length !== 0 && menuOut) {
61
- removeMenu(true);
62
- } else {
63
- // menu.removeAttr('style');
64
- menu.css('transform', 'translateX(0%)');
65
- // menu.css('width', options.menuWidth);
66
- }
67
- } else if (menuOut === false) {
68
- if (options.edge === 'left') {
69
- menu.css('transform', 'translateX(-100%)');
70
- } else {
71
- menu.css('transform', 'translateX(100%)');
72
- }
73
- }
74
- });
75
- }
76
-
77
- // if closeOnClick, then add close event for all a tags in side sideNav
78
- if (options.closeOnClick === true) {
79
- menu.on("click.itemclick", "a:not(.collapsible-header)", function () {
80
- if (!(window.innerWidth > 992 && menu.hasClass('fixed'))) {
81
- removeMenu();
82
- }
83
- });
84
- }
85
-
86
- var removeMenu = function (restoreNav) {
87
- panning = false;
88
- menuOut = false;
89
- // Reenable scrolling
90
- $('body').css({
91
- overflow: '',
92
- width: ''
93
- });
94
-
95
- $('#sidenav-overlay').velocity({ opacity: 0 }, { duration: 200,
96
- queue: false, easing: 'easeOutQuad',
97
- complete: function () {
98
- $(this).remove();
99
- } });
100
- if (options.edge === 'left') {
101
- // Reset phantom div
102
- $dragTarget.css({ width: '', right: '', left: '0' });
103
- menu.velocity({ 'translateX': '-100%' }, { duration: 200,
104
- queue: false,
105
- easing: 'easeOutCubic',
106
- complete: function () {
107
- if (restoreNav === true) {
108
- // Restore Fixed sidenav
109
- menu.removeAttr('style');
110
- menu.css('width', options.menuWidth);
111
- }
112
- }
113
-
114
- });
115
- } else {
116
- // Reset phantom div
117
- $dragTarget.css({ width: '', right: '0', left: '' });
118
- menu.velocity({ 'translateX': '100%' }, { duration: 200,
119
- queue: false,
120
- easing: 'easeOutCubic',
121
- complete: function () {
122
- if (restoreNav === true) {
123
- // Restore Fixed sidenav
124
- menu.removeAttr('style');
125
- menu.css('width', options.menuWidth);
126
- }
127
- }
128
- });
129
- }
130
-
131
- // Callback
132
- if (typeof options.onClose === 'function') {
133
- options.onClose.call(this, menu);
134
- }
135
- };
136
-
137
- // Touch Event
138
- var panning = false;
139
- var menuOut = false;
140
-
141
- if (options.draggable) {
142
- $dragTarget.on('click', function () {
143
- if (menuOut) {
144
- removeMenu();
145
- }
146
- });
147
-
148
- $dragTarget.hammer({
149
- prevent_default: false
150
- }).on('pan', function (e) {
151
-
152
- if (e.gesture.pointerType == "touch") {
153
-
154
- var direction = e.gesture.direction;
155
- var x = e.gesture.center.x;
156
- var y = e.gesture.center.y;
157
- var velocityX = e.gesture.velocityX;
158
-
159
- // Vertical scroll bugfix
160
- if (x === 0 && y === 0) {
161
- return;
162
- }
163
-
164
- // Disable Scrolling
165
- var $body = $('body');
166
- var $overlay = $('#sidenav-overlay');
167
- var oldWidth = $body.innerWidth();
168
- $body.css('overflow', 'hidden');
169
- $body.width(oldWidth);
170
-
171
- // If overlay does not exist, create one and if it is clicked, close menu
172
- if ($overlay.length === 0) {
173
- $overlay = $('<div id="sidenav-overlay"></div>');
174
- $overlay.css('opacity', 0).click(function () {
175
- removeMenu();
176
- });
177
-
178
- // Run 'onOpen' when sidenav is opened via touch/swipe if applicable
179
- if (typeof options.onOpen === 'function') {
180
- options.onOpen.call(this, menu);
181
- }
182
-
183
- $('body').append($overlay);
184
- }
185
-
186
- // Keep within boundaries
187
- if (options.edge === 'left') {
188
- if (x > options.menuWidth) {
189
- x = options.menuWidth;
190
- } else if (x < 0) {
191
- x = 0;
192
- }
193
- }
194
-
195
- if (options.edge === 'left') {
196
- // Left Direction
197
- if (x < options.menuWidth / 2) {
198
- menuOut = false;
199
- }
200
- // Right Direction
201
- else if (x >= options.menuWidth / 2) {
202
- menuOut = true;
203
- }
204
- menu.css('transform', 'translateX(' + (x - options.menuWidth) + 'px)');
205
- } else {
206
- // Left Direction
207
- if (x < window.innerWidth - options.menuWidth / 2) {
208
- menuOut = true;
209
- }
210
- // Right Direction
211
- else if (x >= window.innerWidth - options.menuWidth / 2) {
212
- menuOut = false;
213
- }
214
- var rightPos = x - options.menuWidth / 2;
215
- if (rightPos < 0) {
216
- rightPos = 0;
217
- }
218
-
219
- menu.css('transform', 'translateX(' + rightPos + 'px)');
220
- }
221
-
222
- // Percentage overlay
223
- var overlayPerc;
224
- if (options.edge === 'left') {
225
- overlayPerc = x / options.menuWidth;
226
- $overlay.velocity({ opacity: overlayPerc }, { duration: 10, queue: false, easing: 'easeOutQuad' });
227
- } else {
228
- overlayPerc = Math.abs((x - window.innerWidth) / options.menuWidth);
229
- $overlay.velocity({ opacity: overlayPerc }, { duration: 10, queue: false, easing: 'easeOutQuad' });
230
- }
231
- }
232
- }).on('panend', function (e) {
233
-
234
- if (e.gesture.pointerType == "touch") {
235
- var $overlay = $('#sidenav-overlay');
236
- var velocityX = e.gesture.velocityX;
237
- var x = e.gesture.center.x;
238
- var leftPos = x - options.menuWidth;
239
- var rightPos = x - options.menuWidth / 2;
240
- if (leftPos > 0) {
241
- leftPos = 0;
242
- }
243
- if (rightPos < 0) {
244
- rightPos = 0;
245
- }
246
- panning = false;
247
-
248
- if (options.edge === 'left') {
249
- // If velocityX <= 0.3 then the user is flinging the menu closed so ignore menuOut
250
- if (menuOut && velocityX <= 0.3 || velocityX < -0.5) {
251
- // Return menu to open
252
- if (leftPos !== 0) {
253
- menu.velocity({ 'translateX': [0, leftPos] }, { duration: 300, queue: false, easing: 'easeOutQuad' });
254
- }
255
-
256
- $overlay.velocity({ opacity: 1 }, { duration: 50, queue: false, easing: 'easeOutQuad' });
257
- $dragTarget.css({ width: '50%', right: 0, left: '' });
258
- menuOut = true;
259
- } else if (!menuOut || velocityX > 0.3) {
260
- // Enable Scrolling
261
- $('body').css({
262
- overflow: '',
263
- width: ''
264
- });
265
- // Slide menu closed
266
- menu.velocity({ 'translateX': [-1 * options.menuWidth - 10, leftPos] }, { duration: 200, queue: false, easing: 'easeOutQuad' });
267
- $overlay.velocity({ opacity: 0 }, { duration: 200, queue: false, easing: 'easeOutQuad',
268
- complete: function () {
269
- // Run 'onClose' when sidenav is closed via touch/swipe if applicable
270
- if (typeof options.onClose === 'function') {
271
- options.onClose.call(this, menu);
272
- }
273
-
274
- $(this).remove();
275
- } });
276
- $dragTarget.css({ width: '10px', right: '', left: 0 });
277
- }
278
- } else {
279
- if (menuOut && velocityX >= -0.3 || velocityX > 0.5) {
280
- // Return menu to open
281
- if (rightPos !== 0) {
282
- menu.velocity({ 'translateX': [0, rightPos] }, { duration: 300, queue: false, easing: 'easeOutQuad' });
283
- }
284
-
285
- $overlay.velocity({ opacity: 1 }, { duration: 50, queue: false, easing: 'easeOutQuad' });
286
- $dragTarget.css({ width: '50%', right: '', left: 0 });
287
- menuOut = true;
288
- } else if (!menuOut || velocityX < -0.3) {
289
- // Enable Scrolling
290
- $('body').css({
291
- overflow: '',
292
- width: ''
293
- });
294
-
295
- // Slide menu closed
296
- menu.velocity({ 'translateX': [options.menuWidth + 10, rightPos] }, { duration: 200, queue: false, easing: 'easeOutQuad' });
297
- $overlay.velocity({ opacity: 0 }, { duration: 200, queue: false, easing: 'easeOutQuad',
298
- complete: function () {
299
- // Run 'onClose' when sidenav is closed via touch/swipe if applicable
300
- if (typeof options.onClose === 'function') {
301
- options.onClose.call(this, menu);
302
- }
303
-
304
- $(this).remove();
305
- } });
306
- $dragTarget.css({ width: '10px', right: 0, left: '' });
307
- }
308
- }
309
- }
310
- });
311
- }
312
-
313
- $this.off('click.sidenav').on('click.sidenav', function () {
314
- if (menuOut === true) {
315
- menuOut = false;
316
- panning = false;
317
- removeMenu();
318
- } else {
319
-
320
- // Disable Scrolling
321
- var $body = $('body');
322
- var $overlay = $('<div id="sidenav-overlay"></div>');
323
- var oldWidth = $body.innerWidth();
324
- $body.css('overflow', 'hidden');
325
- $body.width(oldWidth);
326
-
327
- // Push current drag target on top of DOM tree
328
- $('body').append($dragTarget);
329
-
330
- if (options.edge === 'left') {
331
- $dragTarget.css({ width: '50%', right: 0, left: '' });
332
- menu.velocity({ 'translateX': [0, -1 * options.menuWidth] }, { duration: 300, queue: false, easing: 'easeOutQuad' });
333
- } else {
334
- $dragTarget.css({ width: '50%', right: '', left: 0 });
335
- menu.velocity({ 'translateX': [0, options.menuWidth] }, { duration: 300, queue: false, easing: 'easeOutQuad' });
336
- }
337
-
338
- // Overlay close on click
339
- $overlay.css('opacity', 0).click(function () {
340
- menuOut = false;
341
- panning = false;
342
- removeMenu();
343
- $overlay.velocity({ opacity: 0 }, { duration: 300, queue: false, easing: 'easeOutQuad',
344
- complete: function () {
345
- $(this).remove();
346
- }
347
- });
348
- });
349
-
350
- // Append body
351
- $('body').append($overlay);
352
- $overlay.velocity({ opacity: 1 }, { duration: 300, queue: false, easing: 'easeOutQuad',
353
- complete: function () {
354
- menuOut = true;
355
- panning = false;
356
- }
357
- });
358
-
359
- // Callback
360
- if (typeof options.onOpen === 'function') {
361
- options.onOpen.call(this, menu);
362
- }
363
- }
364
-
365
- return false;
366
- });
367
- });
368
- },
369
- destroy: function () {
370
- var $overlay = $('#sidenav-overlay');
371
- var $dragTarget = $('.drag-target[data-sidenav="' + $(this).attr('data-activates') + '"]');
372
- $overlay.trigger('click');
373
- $dragTarget.remove();
374
- $(this).off('click');
375
- $overlay.remove();
376
- },
377
- show: function () {
378
- this.trigger('click');
379
- },
380
- hide: function () {
381
- $('#sidenav-overlay').trigger('click');
382
- }
383
- };
384
-
385
- $.fn.sideNav = function (methodOrOptions) {
386
- if (methods[methodOrOptions]) {
387
- return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1));
388
- } else if (typeof methodOrOptions === 'object' || !methodOrOptions) {
389
- // Default to "init"
390
- return methods.init.apply(this, arguments);
391
- } else {
392
- $.error('Method ' + methodOrOptions + ' does not exist on jQuery.sideNav');
393
- }
394
- }; // Plugin end
395
- })(jQuery);