jquery-scrollbar-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5504aa53e9627da8baea6f6368dcfcf35852408
4
+ data.tar.gz: e577044dbca914224e635ae6223e92751ee7a86f
5
+ SHA512:
6
+ metadata.gz: bcd0b55369db5eca14922911251b2b1bbf8dd0285d10d2c55287275df886a0194e644e137c5420b820958aacca65c1303e7b5552589b37bbffeec71ff07fc334
7
+ data.tar.gz: dd3e1a01a515301d7ecfc064fe53f03eb0366f947239f33a9256366f38c6463f260bc7a64f6bbc1e2abd493d11a3f348c0146c34ef2529f0d8c9f1c42d25d096
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at c.derche@me.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-scrollbar-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kirill
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Jquery::Scrollbar::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jquery/scrollbar/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jquery-scrollbar-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jquery-scrollbar-rails
22
+
23
+ ## Usage
24
+
25
+ 1. Add to your application.js
26
+ ```
27
+ //= require jquery.scrollbar
28
+ ```
29
+
30
+ 2. Add to your application.css or application.scss
31
+ ```
32
+ @import "jquery.scrollbar";
33
+ OR
34
+ /*
35
+ *= require jquery.scrollbar
36
+ */
37
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jquery/scrollbar/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery/scrollbar/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-scrollbar-rails"
8
+ spec.version = Jquery::Scrollbar::Rails::VERSION
9
+ spec.authors = ["Kirill"]
10
+ spec.email = ["c.derche@me.com"]
11
+
12
+ spec.summary = %q{Gem wrapper to include jquery.scrollbar library via the asset pipeline.}
13
+ spec.description = %q{This jquery.scrollbar was built using the library at https://github.com/gromo/jquery.scrollbar}
14
+ spec.homepage = "https://github.com/cderche/jquery-scrollbar-rails"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
@@ -0,0 +1,10 @@
1
+ require "jquery/scrollbar/rails/version"
2
+
3
+ module Jquery
4
+ module Scrollbar
5
+ module Rails
6
+ require 'jquery/scrollbar/rails/engine'
7
+ require 'jquery/scrollbar/rails/version'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Jquery
2
+ module Scrollbar
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ initializer 'Modernizr precompile hook', :group => :all do |app|
6
+ app.config.assets.precompile += ['jquery.scrollbar.js']
7
+ app.config.assets.precompile += ['jquery.scrollbar.min.js']
8
+ app.config.assets.precompile += ['jquery.scrollbar.css']
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Scrollbar
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,781 @@
1
+ /**
2
+ * jQuery CSS Customizable Scrollbar
3
+ *
4
+ * Copyright 2015, Yuriy Khabarov
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ *
7
+ * If you found bug, please contact me via email <13real008@gmail.com>
8
+ *
9
+ * @author Yuriy Khabarov aka Gromo
10
+ * @version 0.2.10
11
+ * @url https://github.com/gromo/jquery.scrollbar/
12
+ *
13
+ */
14
+ ;
15
+ (function (root, factory) {
16
+ if (typeof define === 'function' && define.amd) {
17
+ define(['jquery'], factory);
18
+ } else {
19
+ factory(root.jQuery);
20
+ }
21
+ }(this, function ($) {
22
+ 'use strict';
23
+
24
+ // init flags & variables
25
+ var debug = false;
26
+
27
+ var browser = {
28
+ data: {
29
+ index: 0,
30
+ name: 'scrollbar'
31
+ },
32
+ macosx: /mac/i.test(navigator.platform),
33
+ mobile: /android|webos|iphone|ipad|ipod|blackberry/i.test(navigator.userAgent),
34
+ overlay: null,
35
+ scroll: null,
36
+ scrolls: [],
37
+ webkit: /webkit/i.test(navigator.userAgent) && !/edge\/\d+/i.test(navigator.userAgent)
38
+ };
39
+
40
+ browser.scrolls.add = function (instance) {
41
+ this.remove(instance).push(instance);
42
+ };
43
+ browser.scrolls.remove = function (instance) {
44
+ while ($.inArray(instance, this) >= 0) {
45
+ this.splice($.inArray(instance, this), 1);
46
+ }
47
+ return this;
48
+ };
49
+
50
+ var defaults = {
51
+ "autoScrollSize": true, // automatically calculate scrollsize
52
+ "autoUpdate": true, // update scrollbar if content/container size changed
53
+ "debug": false, // debug mode
54
+ "disableBodyScroll": false, // disable body scroll if mouse over container
55
+ "duration": 200, // scroll animate duration in ms
56
+ "ignoreMobile": false, // ignore mobile devices
57
+ "ignoreOverlay": false, // ignore browsers with overlay scrollbars (mobile, MacOS)
58
+ "scrollStep": 30, // scroll step for scrollbar arrows
59
+ "showArrows": false, // add class to show arrows
60
+ "stepScrolling": true, // when scrolling to scrollbar mousedown position
61
+
62
+ "scrollx": null, // horizontal scroll element
63
+ "scrolly": null, // vertical scroll element
64
+
65
+ "onDestroy": null, // callback function on destroy,
66
+ "onInit": null, // callback function on first initialization
67
+ "onScroll": null, // callback function on content scrolling
68
+ "onUpdate": null // callback function on init/resize (before scrollbar size calculation)
69
+ };
70
+
71
+
72
+ var BaseScrollbar = function (container) {
73
+
74
+ if (!browser.scroll) {
75
+ browser.overlay = isScrollOverlaysContent();
76
+ browser.scroll = getBrowserScrollSize();
77
+ updateScrollbars();
78
+
79
+ $(window).resize(function () {
80
+ var forceUpdate = false;
81
+ if (browser.scroll && (browser.scroll.height || browser.scroll.width)) {
82
+ var scroll = getBrowserScrollSize();
83
+ if (scroll.height !== browser.scroll.height || scroll.width !== browser.scroll.width) {
84
+ browser.scroll = scroll;
85
+ forceUpdate = true; // handle page zoom
86
+ }
87
+ }
88
+ updateScrollbars(forceUpdate);
89
+ });
90
+ }
91
+
92
+ this.container = container;
93
+ this.namespace = '.scrollbar_' + browser.data.index++;
94
+ this.options = $.extend({}, defaults, window.jQueryScrollbarOptions || {});
95
+ this.scrollTo = null;
96
+ this.scrollx = {};
97
+ this.scrolly = {};
98
+
99
+ container.data(browser.data.name, this);
100
+ browser.scrolls.add(this);
101
+ };
102
+
103
+ BaseScrollbar.prototype = {
104
+
105
+ destroy: function () {
106
+
107
+ if (!this.wrapper) {
108
+ return;
109
+ }
110
+
111
+ this.container.removeData(browser.data.name);
112
+ browser.scrolls.remove(this);
113
+
114
+ // init variables
115
+ var scrollLeft = this.container.scrollLeft();
116
+ var scrollTop = this.container.scrollTop();
117
+
118
+ this.container.insertBefore(this.wrapper).css({
119
+ "height": "",
120
+ "margin": "",
121
+ "max-height": ""
122
+ })
123
+ .removeClass('scroll-content scroll-scrollx_visible scroll-scrolly_visible')
124
+ .off(this.namespace)
125
+ .scrollLeft(scrollLeft)
126
+ .scrollTop(scrollTop);
127
+
128
+ this.scrollx.scroll.removeClass('scroll-scrollx_visible').find('div').andSelf().off(this.namespace);
129
+ this.scrolly.scroll.removeClass('scroll-scrolly_visible').find('div').andSelf().off(this.namespace);
130
+
131
+ this.wrapper.remove();
132
+
133
+ $(document).add('body').off(this.namespace);
134
+
135
+ if ($.isFunction(this.options.onDestroy)){
136
+ this.options.onDestroy.apply(this, [this.container]);
137
+ }
138
+ },
139
+ init: function (options) {
140
+
141
+ // init variables
142
+ var S = this,
143
+ c = this.container,
144
+ cw = this.containerWrapper || c,
145
+ namespace = this.namespace,
146
+ o = $.extend(this.options, options || {}),
147
+ s = {x: this.scrollx, y: this.scrolly},
148
+ w = this.wrapper;
149
+
150
+ var initScroll = {
151
+ "scrollLeft": c.scrollLeft(),
152
+ "scrollTop": c.scrollTop()
153
+ };
154
+
155
+ // do not init if in ignorable browser
156
+ if ((browser.mobile && o.ignoreMobile)
157
+ || (browser.overlay && o.ignoreOverlay)
158
+ || (browser.macosx && !browser.webkit) // still required to ignore nonWebKit browsers on Mac
159
+ ) {
160
+ return false;
161
+ }
162
+
163
+ // init scroll container
164
+ if (!w) {
165
+ this.wrapper = w = $('<div>').addClass('scroll-wrapper').addClass(c.attr('class'))
166
+ .css('position', c.css('position') == 'absolute' ? 'absolute' : 'relative')
167
+ .insertBefore(c).append(c);
168
+
169
+ if (c.is('textarea')) {
170
+ this.containerWrapper = cw = $('<div>').insertBefore(c).append(c);
171
+ w.addClass('scroll-textarea');
172
+ }
173
+
174
+ cw.addClass('scroll-content').css({
175
+ "height": "auto",
176
+ "margin-bottom": browser.scroll.height * -1 + 'px',
177
+ "margin-right": browser.scroll.width * -1 + 'px',
178
+ "max-height": ""
179
+ });
180
+
181
+ c.on('scroll' + namespace, function (event) {
182
+ if ($.isFunction(o.onScroll)) {
183
+ o.onScroll.call(S, {
184
+ "maxScroll": s.y.maxScrollOffset,
185
+ "scroll": c.scrollTop(),
186
+ "size": s.y.size,
187
+ "visible": s.y.visible
188
+ }, {
189
+ "maxScroll": s.x.maxScrollOffset,
190
+ "scroll": c.scrollLeft(),
191
+ "size": s.x.size,
192
+ "visible": s.x.visible
193
+ });
194
+ }
195
+ s.x.isVisible && s.x.scroll.bar.css('left', c.scrollLeft() * s.x.kx + 'px');
196
+ s.y.isVisible && s.y.scroll.bar.css('top', c.scrollTop() * s.y.kx + 'px');
197
+ });
198
+
199
+ /* prevent native scrollbars to be visible on #anchor click */
200
+ w.on('scroll' + namespace, function () {
201
+ w.scrollTop(0).scrollLeft(0);
202
+ });
203
+
204
+ if (o.disableBodyScroll) {
205
+ var handleMouseScroll = function (event) {
206
+ isVerticalScroll(event) ?
207
+ s.y.isVisible && s.y.mousewheel(event) :
208
+ s.x.isVisible && s.x.mousewheel(event);
209
+ };
210
+ w.on('MozMousePixelScroll' + namespace, handleMouseScroll);
211
+ w.on('mousewheel' + namespace, handleMouseScroll);
212
+
213
+ if (browser.mobile) {
214
+ w.on('touchstart' + namespace, function (event) {
215
+ var touch = event.originalEvent.touches && event.originalEvent.touches[0] || event;
216
+ var originalTouch = {
217
+ "pageX": touch.pageX,
218
+ "pageY": touch.pageY
219
+ };
220
+ var originalScroll = {
221
+ "left": c.scrollLeft(),
222
+ "top": c.scrollTop()
223
+ };
224
+ $(document).on('touchmove' + namespace, function (event) {
225
+ var touch = event.originalEvent.targetTouches && event.originalEvent.targetTouches[0] || event;
226
+ c.scrollLeft(originalScroll.left + originalTouch.pageX - touch.pageX);
227
+ c.scrollTop(originalScroll.top + originalTouch.pageY - touch.pageY);
228
+ event.preventDefault();
229
+ });
230
+ $(document).on('touchend' + namespace, function () {
231
+ $(document).off(namespace);
232
+ });
233
+ });
234
+ }
235
+ }
236
+ if ($.isFunction(o.onInit)){
237
+ o.onInit.apply(this, [c]);
238
+ }
239
+ } else {
240
+ cw.css({
241
+ "height": "auto",
242
+ "margin-bottom": browser.scroll.height * -1 + 'px',
243
+ "margin-right": browser.scroll.width * -1 + 'px',
244
+ "max-height": ""
245
+ });
246
+ }
247
+
248
+ // init scrollbars & recalculate sizes
249
+ $.each(s, function (d, scrollx) {
250
+
251
+ var scrollCallback = null;
252
+ var scrollForward = 1;
253
+ var scrollOffset = (d === 'x') ? 'scrollLeft' : 'scrollTop';
254
+ var scrollStep = o.scrollStep;
255
+ var scrollTo = function () {
256
+ var currentOffset = c[scrollOffset]();
257
+ c[scrollOffset](currentOffset + scrollStep);
258
+ if (scrollForward == 1 && (currentOffset + scrollStep) >= scrollToValue)
259
+ currentOffset = c[scrollOffset]();
260
+ if (scrollForward == -1 && (currentOffset + scrollStep) <= scrollToValue)
261
+ currentOffset = c[scrollOffset]();
262
+ if (c[scrollOffset]() == currentOffset && scrollCallback) {
263
+ scrollCallback();
264
+ }
265
+ }
266
+ var scrollToValue = 0;
267
+
268
+ if (!scrollx.scroll) {
269
+
270
+ scrollx.scroll = S._getScroll(o['scroll' + d]).addClass('scroll-' + d);
271
+
272
+ if(o.showArrows){
273
+ scrollx.scroll.addClass('scroll-element_arrows_visible');
274
+ }
275
+
276
+ scrollx.mousewheel = function (event) {
277
+
278
+ if (!scrollx.isVisible || (d === 'x' && isVerticalScroll(event))) {
279
+ return true;
280
+ }
281
+ if (d === 'y' && !isVerticalScroll(event)) {
282
+ s.x.mousewheel(event);
283
+ return true;
284
+ }
285
+
286
+ var delta = event.originalEvent.wheelDelta * -1 || event.originalEvent.detail;
287
+ var maxScrollValue = scrollx.size - scrollx.visible - scrollx.offset;
288
+
289
+ if ((delta > 0 && scrollToValue < maxScrollValue) || (delta < 0 && scrollToValue > 0)) {
290
+ scrollToValue = scrollToValue + delta;
291
+ if (scrollToValue < 0)
292
+ scrollToValue = 0;
293
+ if (scrollToValue > maxScrollValue)
294
+ scrollToValue = maxScrollValue;
295
+
296
+ S.scrollTo = S.scrollTo || {};
297
+ S.scrollTo[scrollOffset] = scrollToValue;
298
+ setTimeout(function () {
299
+ if (S.scrollTo) {
300
+ c.stop().animate(S.scrollTo, 240, 'linear', function () {
301
+ scrollToValue = c[scrollOffset]();
302
+ });
303
+ S.scrollTo = null;
304
+ }
305
+ }, 1);
306
+ }
307
+
308
+ event.preventDefault();
309
+ return false;
310
+ };
311
+
312
+ scrollx.scroll
313
+ .on('MozMousePixelScroll' + namespace, scrollx.mousewheel)
314
+ .on('mousewheel' + namespace, scrollx.mousewheel)
315
+ .on('mouseenter' + namespace, function () {
316
+ scrollToValue = c[scrollOffset]();
317
+ });
318
+
319
+ // handle arrows & scroll inner mousedown event
320
+ scrollx.scroll.find('.scroll-arrow, .scroll-element_track')
321
+ .on('mousedown' + namespace, function (event) {
322
+
323
+ if (event.which != 1) // lmb
324
+ return true;
325
+
326
+ scrollForward = 1;
327
+
328
+ var data = {
329
+ "eventOffset": event[(d === 'x') ? 'pageX' : 'pageY'],
330
+ "maxScrollValue": scrollx.size - scrollx.visible - scrollx.offset,
331
+ "scrollbarOffset": scrollx.scroll.bar.offset()[(d === 'x') ? 'left' : 'top'],
332
+ "scrollbarSize": scrollx.scroll.bar[(d === 'x') ? 'outerWidth' : 'outerHeight']()
333
+ };
334
+ var timeout = 0, timer = 0;
335
+
336
+ if ($(this).hasClass('scroll-arrow')) {
337
+ scrollForward = $(this).hasClass("scroll-arrow_more") ? 1 : -1;
338
+ scrollStep = o.scrollStep * scrollForward;
339
+ scrollToValue = scrollForward > 0 ? data.maxScrollValue : 0;
340
+ } else {
341
+ scrollForward = (data.eventOffset > (data.scrollbarOffset + data.scrollbarSize) ? 1
342
+ : (data.eventOffset < data.scrollbarOffset ? -1 : 0));
343
+ scrollStep = Math.round(scrollx.visible * 0.75) * scrollForward;
344
+ scrollToValue = (data.eventOffset - data.scrollbarOffset -
345
+ (o.stepScrolling ? (scrollForward == 1 ? data.scrollbarSize : 0)
346
+ : Math.round(data.scrollbarSize / 2)));
347
+ scrollToValue = c[scrollOffset]() + (scrollToValue / scrollx.kx);
348
+ }
349
+
350
+ S.scrollTo = S.scrollTo || {};
351
+ S.scrollTo[scrollOffset] = o.stepScrolling ? c[scrollOffset]() + scrollStep : scrollToValue;
352
+
353
+ if (o.stepScrolling) {
354
+ scrollCallback = function () {
355
+ scrollToValue = c[scrollOffset]();
356
+ clearInterval(timer);
357
+ clearTimeout(timeout);
358
+ timeout = 0;
359
+ timer = 0;
360
+ };
361
+ timeout = setTimeout(function () {
362
+ timer = setInterval(scrollTo, 40);
363
+ }, o.duration + 100);
364
+ }
365
+
366
+ setTimeout(function () {
367
+ if (S.scrollTo) {
368
+ c.animate(S.scrollTo, o.duration);
369
+ S.scrollTo = null;
370
+ }
371
+ }, 1);
372
+
373
+ return S._handleMouseDown(scrollCallback, event);
374
+ });
375
+
376
+ // handle scrollbar drag'n'drop
377
+ scrollx.scroll.bar.on('mousedown' + namespace, function (event) {
378
+
379
+ if (event.which != 1) // lmb
380
+ return true;
381
+
382
+ var eventPosition = event[(d === 'x') ? 'pageX' : 'pageY'];
383
+ var initOffset = c[scrollOffset]();
384
+
385
+ scrollx.scroll.addClass('scroll-draggable');
386
+
387
+ $(document).on('mousemove' + namespace, function (event) {
388
+ var diff = parseInt((event[(d === 'x') ? 'pageX' : 'pageY'] - eventPosition) / scrollx.kx, 10);
389
+ c[scrollOffset](initOffset + diff);
390
+ });
391
+
392
+ return S._handleMouseDown(function () {
393
+ scrollx.scroll.removeClass('scroll-draggable');
394
+ scrollToValue = c[scrollOffset]();
395
+ }, event);
396
+ });
397
+ }
398
+ });
399
+
400
+ // remove classes & reset applied styles
401
+ $.each(s, function (d, scrollx) {
402
+ var scrollClass = 'scroll-scroll' + d + '_visible';
403
+ var scrolly = (d == "x") ? s.y : s.x;
404
+
405
+ scrollx.scroll.removeClass(scrollClass);
406
+ scrolly.scroll.removeClass(scrollClass);
407
+ cw.removeClass(scrollClass);
408
+ });
409
+
410
+ // calculate init sizes
411
+ $.each(s, function (d, scrollx) {
412
+ $.extend(scrollx, (d == "x") ? {
413
+ "offset": parseInt(c.css('left'), 10) || 0,
414
+ "size": c.prop('scrollWidth'),
415
+ "visible": w.width()
416
+ } : {
417
+ "offset": parseInt(c.css('top'), 10) || 0,
418
+ "size": c.prop('scrollHeight'),
419
+ "visible": w.height()
420
+ });
421
+ });
422
+
423
+ // update scrollbar visibility/dimensions
424
+ this._updateScroll('x', this.scrollx);
425
+ this._updateScroll('y', this.scrolly);
426
+
427
+ if ($.isFunction(o.onUpdate)){
428
+ o.onUpdate.apply(this, [c]);
429
+ }
430
+
431
+ // calculate scroll size
432
+ $.each(s, function (d, scrollx) {
433
+
434
+ var cssOffset = (d === 'x') ? 'left' : 'top';
435
+ var cssFullSize = (d === 'x') ? 'outerWidth' : 'outerHeight';
436
+ var cssSize = (d === 'x') ? 'width' : 'height';
437
+ var offset = parseInt(c.css(cssOffset), 10) || 0;
438
+
439
+ var AreaSize = scrollx.size;
440
+ var AreaVisible = scrollx.visible + offset;
441
+
442
+ var scrollSize = scrollx.scroll.size[cssFullSize]() + (parseInt(scrollx.scroll.size.css(cssOffset), 10) || 0);
443
+
444
+ if (o.autoScrollSize) {
445
+ scrollx.scrollbarSize = parseInt(scrollSize * AreaVisible / AreaSize, 10);
446
+ scrollx.scroll.bar.css(cssSize, scrollx.scrollbarSize + 'px');
447
+ }
448
+
449
+ scrollx.scrollbarSize = scrollx.scroll.bar[cssFullSize]();
450
+ scrollx.kx = ((scrollSize - scrollx.scrollbarSize) / (AreaSize - AreaVisible)) || 1;
451
+ scrollx.maxScrollOffset = AreaSize - AreaVisible;
452
+ });
453
+
454
+ c.scrollLeft(initScroll.scrollLeft).scrollTop(initScroll.scrollTop).trigger('scroll');
455
+ },
456
+
457
+ /**
458
+ * Get scrollx/scrolly object
459
+ *
460
+ * @param {Mixed} scroll
461
+ * @returns {jQuery} scroll object
462
+ */
463
+ _getScroll: function (scroll) {
464
+ var types = {
465
+ advanced: [
466
+ '<div class="scroll-element">',
467
+ '<div class="scroll-element_corner"></div>',
468
+ '<div class="scroll-arrow scroll-arrow_less"></div>',
469
+ '<div class="scroll-arrow scroll-arrow_more"></div>',
470
+ '<div class="scroll-element_outer">',
471
+ '<div class="scroll-element_size"></div>', // required! used for scrollbar size calculation !
472
+ '<div class="scroll-element_inner-wrapper">',
473
+ '<div class="scroll-element_inner scroll-element_track">', // used for handling scrollbar click
474
+ '<div class="scroll-element_inner-bottom"></div>',
475
+ '</div>',
476
+ '</div>',
477
+ '<div class="scroll-bar">', // required
478
+ '<div class="scroll-bar_body">',
479
+ '<div class="scroll-bar_body-inner"></div>',
480
+ '</div>',
481
+ '<div class="scroll-bar_bottom"></div>',
482
+ '<div class="scroll-bar_center"></div>',
483
+ '</div>',
484
+ '</div>',
485
+ '</div>'
486
+ ].join(''),
487
+ simple: [
488
+ '<div class="scroll-element">',
489
+ '<div class="scroll-element_outer">',
490
+ '<div class="scroll-element_size"></div>', // required! used for scrollbar size calculation !
491
+ '<div class="scroll-element_track"></div>', // used for handling scrollbar click
492
+ '<div class="scroll-bar"></div>', // required
493
+ '</div>',
494
+ '</div>'
495
+ ].join('')
496
+ };
497
+ if (types[scroll]) {
498
+ scroll = types[scroll];
499
+ }
500
+ if (!scroll) {
501
+ scroll = types['simple'];
502
+ }
503
+ if (typeof (scroll) == 'string') {
504
+ scroll = $(scroll).appendTo(this.wrapper);
505
+ } else {
506
+ scroll = $(scroll);
507
+ }
508
+ $.extend(scroll, {
509
+ bar: scroll.find('.scroll-bar'),
510
+ size: scroll.find('.scroll-element_size'),
511
+ track: scroll.find('.scroll-element_track')
512
+ });
513
+ return scroll;
514
+ },
515
+
516
+ _handleMouseDown: function(callback, event) {
517
+
518
+ var namespace = this.namespace;
519
+
520
+ $(document).on('blur' + namespace, function () {
521
+ $(document).add('body').off(namespace);
522
+ callback && callback();
523
+ });
524
+ $(document).on('dragstart' + namespace, function (event) {
525
+ event.preventDefault();
526
+ return false;
527
+ });
528
+ $(document).on('mouseup' + namespace, function () {
529
+ $(document).add('body').off(namespace);
530
+ callback && callback();
531
+ });
532
+ $('body').on('selectstart' + namespace, function (event) {
533
+ event.preventDefault();
534
+ return false;
535
+ });
536
+
537
+ event && event.preventDefault();
538
+ return false;
539
+ },
540
+
541
+ _updateScroll: function (d, scrollx) {
542
+
543
+ var container = this.container,
544
+ containerWrapper = this.containerWrapper || container,
545
+ scrollClass = 'scroll-scroll' + d + '_visible',
546
+ scrolly = (d === 'x') ? this.scrolly : this.scrollx,
547
+ offset = parseInt(this.container.css((d === 'x') ? 'left' : 'top'), 10) || 0,
548
+ wrapper = this.wrapper;
549
+
550
+ var AreaSize = scrollx.size;
551
+ var AreaVisible = scrollx.visible + offset;
552
+
553
+ scrollx.isVisible = (AreaSize - AreaVisible) > 1; // bug in IE9/11 with 1px diff
554
+ if (scrollx.isVisible) {
555
+ scrollx.scroll.addClass(scrollClass);
556
+ scrolly.scroll.addClass(scrollClass);
557
+ containerWrapper.addClass(scrollClass);
558
+ } else {
559
+ scrollx.scroll.removeClass(scrollClass);
560
+ scrolly.scroll.removeClass(scrollClass);
561
+ containerWrapper.removeClass(scrollClass);
562
+ }
563
+
564
+ if (d === 'y') {
565
+ if(container.is('textarea') || AreaSize < AreaVisible){
566
+ containerWrapper.css({
567
+ "height": (AreaVisible + browser.scroll.height) + 'px',
568
+ "max-height": "none"
569
+ });
570
+ } else {
571
+ containerWrapper.css({
572
+ //"height": "auto", // do not reset height value: issue with height:100%!
573
+ "max-height": (AreaVisible + browser.scroll.height) + 'px'
574
+ });
575
+ }
576
+ }
577
+
578
+ if (scrollx.size != container.prop('scrollWidth')
579
+ || scrolly.size != container.prop('scrollHeight')
580
+ || scrollx.visible != wrapper.width()
581
+ || scrolly.visible != wrapper.height()
582
+ || scrollx.offset != (parseInt(container.css('left'), 10) || 0)
583
+ || scrolly.offset != (parseInt(container.css('top'), 10) || 0)
584
+ ) {
585
+ $.extend(this.scrollx, {
586
+ "offset": parseInt(container.css('left'), 10) || 0,
587
+ "size": container.prop('scrollWidth'),
588
+ "visible": wrapper.width()
589
+ });
590
+ $.extend(this.scrolly, {
591
+ "offset": parseInt(container.css('top'), 10) || 0,
592
+ "size": this.container.prop('scrollHeight'),
593
+ "visible": wrapper.height()
594
+ });
595
+ this._updateScroll(d === 'x' ? 'y' : 'x', scrolly);
596
+ }
597
+ }
598
+ };
599
+
600
+ var CustomScrollbar = BaseScrollbar;
601
+
602
+ /*
603
+ * Extend jQuery as plugin
604
+ *
605
+ * @param {Mixed} command to execute
606
+ * @param {Mixed} arguments as Array
607
+ * @return {jQuery}
608
+ */
609
+ $.fn.scrollbar = function (command, args) {
610
+ if (typeof command !== 'string') {
611
+ args = command;
612
+ command = 'init';
613
+ }
614
+ if (typeof args === 'undefined') {
615
+ args = [];
616
+ }
617
+ if (!$.isArray(args)) {
618
+ args = [args];
619
+ }
620
+ this.not('body, .scroll-wrapper').each(function () {
621
+ var element = $(this),
622
+ instance = element.data(browser.data.name);
623
+ if (instance || command === 'init') {
624
+ if (!instance) {
625
+ instance = new CustomScrollbar(element);
626
+ }
627
+ if (instance[command]) {
628
+ instance[command].apply(instance, args);
629
+ }
630
+ }
631
+ });
632
+ return this;
633
+ };
634
+
635
+ /**
636
+ * Connect default options to global object
637
+ */
638
+ $.fn.scrollbar.options = defaults;
639
+
640
+
641
+ /**
642
+ * Check if scroll content/container size is changed
643
+ */
644
+
645
+ var updateScrollbars = (function () {
646
+ var timer = 0,
647
+ timerCounter = 0;
648
+
649
+ return function (force) {
650
+ var i, container, options, scroll, wrapper, scrollx, scrolly;
651
+ for (i = 0; i < browser.scrolls.length; i++) {
652
+ scroll = browser.scrolls[i];
653
+ container = scroll.container;
654
+ options = scroll.options;
655
+ wrapper = scroll.wrapper;
656
+ scrollx = scroll.scrollx;
657
+ scrolly = scroll.scrolly;
658
+ if (force || (options.autoUpdate && wrapper && wrapper.is(':visible') &&
659
+ (container.prop('scrollWidth') != scrollx.size || container.prop('scrollHeight') != scrolly.size || wrapper.width() != scrollx.visible || wrapper.height() != scrolly.visible))) {
660
+ scroll.init();
661
+
662
+ if (options.debug) {
663
+ window.console && console.log({
664
+ scrollHeight: container.prop('scrollHeight') + ':' + scroll.scrolly.size,
665
+ scrollWidth: container.prop('scrollWidth') + ':' + scroll.scrollx.size,
666
+ visibleHeight: wrapper.height() + ':' + scroll.scrolly.visible,
667
+ visibleWidth: wrapper.width() + ':' + scroll.scrollx.visible
668
+ }, true);
669
+ timerCounter++;
670
+ }
671
+ }
672
+ }
673
+ if (debug && timerCounter > 10) {
674
+ window.console && console.log('Scroll updates exceed 10');
675
+ updateScrollbars = function () {};
676
+ } else {
677
+ clearTimeout(timer);
678
+ timer = setTimeout(updateScrollbars, 300);
679
+ }
680
+ };
681
+ })();
682
+
683
+ /* ADDITIONAL FUNCTIONS */
684
+ /**
685
+ * Get native browser scrollbar size (height/width)
686
+ *
687
+ * @param {Boolean} actual size or CSS size, default - CSS size
688
+ * @returns {Object} with height, width
689
+ */
690
+ function getBrowserScrollSize(actualSize) {
691
+
692
+ if (browser.webkit && !actualSize) {
693
+ return {
694
+ "height": 0,
695
+ "width": 0
696
+ };
697
+ }
698
+
699
+ if (!browser.data.outer) {
700
+ var css = {
701
+ "border": "none",
702
+ "box-sizing": "content-box",
703
+ "height": "200px",
704
+ "margin": "0",
705
+ "padding": "0",
706
+ "width": "200px"
707
+ };
708
+ browser.data.inner = $("<div>").css($.extend({}, css));
709
+ browser.data.outer = $("<div>").css($.extend({
710
+ "left": "-1000px",
711
+ "overflow": "scroll",
712
+ "position": "absolute",
713
+ "top": "-1000px"
714
+ }, css)).append(browser.data.inner).appendTo("body");
715
+ }
716
+
717
+ browser.data.outer.scrollLeft(1000).scrollTop(1000);
718
+
719
+ return {
720
+ "height": Math.ceil((browser.data.outer.offset().top - browser.data.inner.offset().top) || 0),
721
+ "width": Math.ceil((browser.data.outer.offset().left - browser.data.inner.offset().left) || 0)
722
+ };
723
+ }
724
+
725
+ /**
726
+ * Check if native browser scrollbars overlay content
727
+ *
728
+ * @returns {Boolean}
729
+ */
730
+ function isScrollOverlaysContent() {
731
+ var scrollSize = getBrowserScrollSize(true);
732
+ return !(scrollSize.height || scrollSize.width);
733
+ }
734
+
735
+ function isVerticalScroll(event) {
736
+ var e = event.originalEvent;
737
+ if (e.axis && e.axis === e.HORIZONTAL_AXIS)
738
+ return false;
739
+ if (e.wheelDeltaX)
740
+ return false;
741
+ return true;
742
+ }
743
+
744
+
745
+ /**
746
+ * Extend AngularJS as UI directive
747
+ * and expose a provider for override default config
748
+ *
749
+ */
750
+ if (window.angular) {
751
+ (function (angular) {
752
+ angular.module('jQueryScrollbar', [])
753
+ .provider('jQueryScrollbar', function () {
754
+ var defaultOptions = defaults;
755
+ return {
756
+ setOptions: function (options) {
757
+ angular.extend(defaultOptions, options);
758
+ },
759
+ $get: function () {
760
+ return {
761
+ options: angular.copy(defaultOptions)
762
+ };
763
+ }
764
+ };
765
+ })
766
+ .directive('jqueryScrollbar', ['jQueryScrollbar', '$parse', function (jQueryScrollbar, $parse) {
767
+ return {
768
+ "restrict": "AC",
769
+ "link": function (scope, element, attrs) {
770
+ var model = $parse(attrs.jqueryScrollbar),
771
+ options = model(scope);
772
+ element.scrollbar(options || jQueryScrollbar.options)
773
+ .on('$destroy', function () {
774
+ element.scrollbar('destroy');
775
+ });
776
+ }
777
+ };
778
+ }]);
779
+ })(window.angular);
780
+ }
781
+ }));