Compare commits
307 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2b66c76ad | ||
|
|
85009c34cd | ||
|
|
7e39eb3d68 | ||
|
|
085cd7abdd | ||
|
|
6edd7a183c | ||
|
|
735c6c0bf3 | ||
|
|
553756b346 | ||
|
|
4707acc287 | ||
|
|
5f0a423128 | ||
|
|
6d2c6ac8ec | ||
|
|
d1340f1b85 | ||
|
|
4a988b5a21 | ||
|
|
1a39d76e48 | ||
|
|
9fc34100df | ||
|
|
d74bdcccec | ||
|
|
5f34edc8c7 | ||
|
|
ce3a199cb3 | ||
|
|
9c485584b9 | ||
|
|
d5db8ca18e | ||
|
|
89174ed99f | ||
|
|
6e7e3f94fa | ||
|
|
7d61475e1d | ||
|
|
2f8daae695 | ||
|
|
5ce0d77f87 | ||
|
|
f811bbcab5 | ||
|
|
4593eb9115 | ||
|
|
b3b1bc2454 | ||
|
|
25e5be13ff | ||
|
|
f683b01959 | ||
|
|
6d2f203441 | ||
|
|
a4808f662e | ||
|
|
98fa15167a | ||
|
|
06929ae685 | ||
|
|
aa63ff0370 | ||
|
|
c7ddde69c2 | ||
|
|
69e3fb2688 | ||
|
|
fad7f8b4a6 | ||
|
|
0deb4c9bc7 | ||
|
|
11fcd09a99 | ||
|
|
0fc5c69b3f | ||
|
|
898928b686 | ||
|
|
ce7146121f | ||
|
|
908cee5490 | ||
|
|
b3880ca638 | ||
|
|
7123891d4d | ||
|
|
4c00a7fdb9 | ||
|
|
3719dd614c | ||
|
|
68dbc427ea | ||
|
|
34135d6ef0 | ||
|
|
0ab95f2d57 | ||
|
|
985980a892 | ||
|
|
fdc8d64fd9 | ||
|
|
26852236cc | ||
|
|
e0510b5fad | ||
|
|
838ccbba77 | ||
|
|
4198b23231 | ||
|
|
3eb2a49109 | ||
|
|
1b2c853972 | ||
|
|
e9d7cc97c8 | ||
|
|
9016f207e9 | ||
|
|
aec4e37f61 | ||
|
|
269a1dc402 | ||
|
|
2cac43ef39 | ||
|
|
b0a38741df | ||
|
|
edaeccebf2 | ||
|
|
42364c4d43 | ||
|
|
f20a8532ff | ||
|
|
7621a2488c | ||
|
|
205c6d0223 | ||
|
|
ad5cd4fe53 | ||
|
|
dc951a3804 | ||
|
|
9996b1c8e3 | ||
|
|
f14b6a0d47 | ||
|
|
9580e08886 | ||
|
|
a2b2a77de1 | ||
|
|
e63d4c03cb | ||
|
|
d277a363b0 | ||
|
|
4a661f181f | ||
|
|
bd7134f33d | ||
|
|
6f63623b93 | ||
|
|
cfc658d648 | ||
|
|
181265261b | ||
|
|
db65fe0f6a | ||
|
|
7e0d5f5dc5 | ||
|
|
e0d6243f24 | ||
|
|
3d91c6f098 | ||
|
|
636eaffd41 | ||
|
|
3ba211133d | ||
|
|
40b1510d49 | ||
|
|
b959edbf78 | ||
|
|
c49cf7905e | ||
|
|
f4cb31f8d8 | ||
|
|
965e315b30 | ||
|
|
3e76ce9d3e | ||
|
|
2413028ad4 | ||
|
|
cc0fded8cb | ||
|
|
fbfe505408 | ||
|
|
c76aa08113 | ||
|
|
4d7f441d1f | ||
|
|
4f6ed64b17 | ||
|
|
2fe45b3a97 | ||
|
|
57b1404e29 | ||
|
|
bcfe954803 | ||
|
|
31434f81d4 | ||
|
|
8a3ed6d0b7 | ||
|
|
1dfbbe9e56 | ||
|
|
eb02d5ae65 | ||
|
|
6fbaa00403 | ||
|
|
c14feba0bf | ||
|
|
6fbfd5c90d | ||
|
|
eddd2c2731 | ||
|
|
4c08b0e089 | ||
|
|
c04b662a1b | ||
|
|
5ba86c2217 | ||
|
|
6e32d3ddce | ||
|
|
9f9f15f83c | ||
|
|
7e04a2e72b | ||
|
|
24b34d3dea | ||
|
|
e1910cde3e | ||
|
|
bbf3d4db9f | ||
|
|
3b134d6193 | ||
|
|
e9024292cd | ||
|
|
e4dda6f408 | ||
|
|
fd53ae0b48 | ||
|
|
66fd8bfd6a | ||
|
|
4aa28add99 | ||
|
|
d6ede33202 | ||
|
|
1c3b409d12 | ||
|
|
17e5f67519 | ||
|
|
002034fd54 | ||
|
|
8761735a54 | ||
|
|
c285521caa | ||
|
|
3d2d50c308 | ||
|
|
a0d39e1b49 | ||
|
|
e288476ba0 | ||
|
|
e9bc40bd37 | ||
|
|
0b8fe0ac0b | ||
|
|
a3676556b2 | ||
|
|
39893fc6f2 | ||
|
|
6c5b9d249e | ||
|
|
2ef7e81ce9 | ||
|
|
3b90c734e4 | ||
|
|
afebe908b1 | ||
|
|
6cbb4a9b9d | ||
|
|
51f33a44b5 | ||
|
|
8eac54d49f | ||
|
|
ed4e335978 | ||
|
|
272bb4983a | ||
|
|
f200bea4cc | ||
|
|
b1d7aa0e64 | ||
|
|
49e39f513d | ||
|
|
89f4226778 | ||
|
|
79f4cfcf5f | ||
|
|
158b113d18 | ||
|
|
6c642d8a47 | ||
|
|
f9f20eeb6f | ||
|
|
1f082a2e04 | ||
|
|
b19c5e0765 | ||
|
|
3dbf20a5d0 | ||
|
|
db855ceca1 | ||
|
|
84b74926e3 | ||
|
|
d6bd30f2da | ||
|
|
fc28ceb4ea | ||
|
|
ca4d835129 | ||
|
|
88b4e2fc19 | ||
|
|
de32082a62 | ||
|
|
7ba25d020c | ||
|
|
08d559561e | ||
|
|
046ce954fd | ||
|
|
a40ab40695 | ||
|
|
2cd65684e2 | ||
|
|
a0b3754a0d | ||
|
|
dc7b14d0e1 | ||
|
|
a5aab04264 | ||
|
|
aca7683de1 | ||
|
|
c21cfb6ed0 | ||
|
|
e4b21c7069 | ||
|
|
bb58ab98e3 | ||
|
|
633f1f53d3 | ||
|
|
4a7f27356a | ||
|
|
2e071274db | ||
|
|
b23ad2834e | ||
|
|
cbdf812de8 | ||
|
|
5e363b876f | ||
|
|
cbf96b3302 | ||
|
|
9354fb064a | ||
|
|
4d060c7df5 | ||
|
|
4984102cd3 | ||
|
|
fb5c6ef74f | ||
|
|
c280c270b8 | ||
|
|
73ff93984b | ||
|
|
9ca1539ab4 | ||
|
|
05ccc0a5cb | ||
|
|
42cf8d3679 | ||
|
|
313f62d2f8 | ||
|
|
6af7500d6b | ||
|
|
f7dbb9b485 | ||
|
|
8290c4f726 | ||
|
|
b4a51fc454 | ||
|
|
a12def5213 | ||
|
|
c4790bb656 | ||
|
|
86a23cb74e | ||
|
|
17aac6c8c8 | ||
|
|
41ca0246ad | ||
|
|
9668a79468 | ||
|
|
30b4f27e03 | ||
|
|
11997131f4 | ||
|
|
7a8b47179c | ||
|
|
ab40b55c8f | ||
|
|
64ea58514b | ||
|
|
68d468c465 | ||
|
|
db2b282431 | ||
|
|
ff3a3c04b2 | ||
|
|
81dd8e9eb0 | ||
|
|
b5d0958e82 | ||
|
|
c8fe0b9269 | ||
|
|
b000c771af | ||
|
|
a52a945226 | ||
|
|
0acf3602f0 | ||
|
|
48eb80bd7f | ||
|
|
89c3bdb1cf | ||
|
|
ee455fafa5 | ||
|
|
6f5a9088aa | ||
|
|
f8b20a9fc9 | ||
|
|
70acad4941 | ||
|
|
95540bdd9e | ||
|
|
5d62b130e9 | ||
|
|
80cfa8dc0e | ||
|
|
fa7e169b9f | ||
|
|
7ab6c5e5ef | ||
|
|
427284337f | ||
|
|
796a0a9093 | ||
|
|
bbab2a3c53 | ||
|
|
aa58a8298e | ||
|
|
1541f73add | ||
|
|
ff5ca3d804 | ||
|
|
3f002c49a1 | ||
|
|
a496ff1a75 | ||
|
|
9a89e73cf9 | ||
|
|
6d1f558c02 | ||
|
|
339e478674 | ||
|
|
d54c7d6640 | ||
|
|
74fc0daf49 | ||
|
|
c0cf399841 | ||
|
|
804d94d3a0 | ||
|
|
254b22877c | ||
|
|
1a6197cbed | ||
|
|
2fc41e7045 | ||
|
|
bd22fc0e58 | ||
|
|
3b3431e226 | ||
|
|
373838d825 | ||
|
|
b927c177ca | ||
|
|
d6558c492d | ||
|
|
e1db204dd4 | ||
|
|
dcdefebded | ||
|
|
fae5c001d4 | ||
|
|
febcaa3603 | ||
|
|
20576ac717 | ||
|
|
7ce708216d | ||
|
|
931be25635 | ||
|
|
74d0fcb1de | ||
|
|
9b3301fd0c | ||
|
|
a94df46fe3 | ||
|
|
20053e9cf1 | ||
|
|
aaab294dc4 | ||
|
|
e9fcc0f02a | ||
|
|
05b20f45ef | ||
|
|
3821413589 | ||
|
|
08a387d9c1 | ||
|
|
1849e64122 | ||
|
|
f9c3dc0b20 | ||
|
|
aa92487ed3 | ||
|
|
a3bf38ada2 | ||
|
|
d24f9bd41b | ||
|
|
5be50316ca | ||
|
|
94be67d998 | ||
|
|
17fd46a07d | ||
|
|
f099448e44 | ||
|
|
d0b97e4039 | ||
|
|
f2342f2678 | ||
|
|
967c30a5e4 | ||
|
|
7cf8303b30 | ||
|
|
7dd6335965 | ||
|
|
494d68fe02 | ||
|
|
3dde3ebb0c | ||
|
|
12086573fc | ||
|
|
a98c77d160 | ||
|
|
48e1c688b2 | ||
|
|
991e664b18 | ||
|
|
ee4fc96b7a | ||
|
|
664dec23d6 | ||
|
|
65869821c1 | ||
|
|
4f7595a34f | ||
|
|
97a44c29a8 | ||
|
|
467cdb17ed | ||
|
|
6ac02fae2b | ||
|
|
d4ec7fca6d | ||
|
|
0022bd5595 | ||
|
|
1b1195288b | ||
|
|
e6590da884 | ||
|
|
e98bfec4f2 | ||
|
|
f7d90464e0 | ||
|
|
337c0be9e2 | ||
|
|
36c988faba | ||
|
|
a573d2cd9d | ||
|
|
f231110f21 | ||
|
|
503b05f5ae |
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"adjoining-classes": false
|
||||
}
|
||||
14
.editorconfig
Normal file
14
.editorconfig
Normal file
@@ -0,0 +1,14 @@
|
||||
# EditorConfig: http://editorconfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
# Indentation for JS & SCSS
|
||||
[*.{js, scss}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
40
.eslintrc
Normal file
40
.eslintrc
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"browser": true
|
||||
},
|
||||
"globals": {
|
||||
"$": true,
|
||||
"define": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"eqeqeq": 2,
|
||||
"no-multi-spaces": 2,
|
||||
"curly": 2,
|
||||
"semi": 2,
|
||||
"no-with": 2,
|
||||
"strict": [2, "global"],
|
||||
"radix": 2,
|
||||
"no-use-before-define": 2,
|
||||
"block-spacing": 2,
|
||||
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
|
||||
"camelcase": 2,
|
||||
"comma-spacing": [2, {"before": false, "after": true}],
|
||||
"eol-last": 2,
|
||||
"no-multiple-empty-lines": 2,
|
||||
"indent": [2, 2],
|
||||
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
|
||||
"linebreak-style": [2, "unix"],
|
||||
"new-parens": 2,
|
||||
"no-trailing-spaces": 2,
|
||||
"semi-spacing": 2,
|
||||
"space-before-blocks": [2, "always"],
|
||||
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
|
||||
"space-in-parens": 2,
|
||||
"space-infix-ops": 2,
|
||||
"space-return-throw-case": 2,
|
||||
"space-unary-ops": 2,
|
||||
"spaced-comment": 2
|
||||
}
|
||||
}
|
||||
8
.github/ISSUE_TEMPLATE.md
vendored
Normal file
8
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
Make sure these boxes are checked before submitting your issue -- thank you!
|
||||
|
||||
- [ ] Check [FAQ](https://github.com/noraesae/perfect-scrollbar/wiki/FAQ)
|
||||
- [ ] Search if there's already one reported in Issues
|
||||
- [ ] Prepare a JSFiddle reproducing the issue
|
||||
- Perfect Scrollbar JSFiddle: https://jsfiddle.net/DanielApt/xv0rrxv3/
|
||||
- With jQuery: https://jsfiddle.net/DanielApt/gbfLazpx/
|
||||
- [ ] Provide a page or source code where the issue can be checked
|
||||
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
Thank you very much for your contribution! Please make sure the followings
|
||||
are checked.
|
||||
|
||||
- [ ] Read [CONTRIBUTING.md](../CONTRIBUTING.md)
|
||||
- [ ] Run `gulp` to make sure it builds and lints successfully
|
||||
- [ ] Provide the scenario this PR will address(some JSFiddles will be perfect)
|
||||
- Perfect Scrollbar JSFiddle: https://jsfiddle.net/DanielApt/xv0rrxv3/
|
||||
- With jQuery: https://jsfiddle.net/DanielApt/gbfLazpx/
|
||||
- [ ] Refer to concerning issues if exist
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
bower_components
|
||||
/dist
|
||||
.idea
|
||||
|
||||
61
.jshintrc
61
.jshintrc
@@ -1,61 +0,0 @@
|
||||
{
|
||||
"passfail" : false,
|
||||
"maxerr" : 100,
|
||||
|
||||
"browser" : true,
|
||||
|
||||
"node" : true,
|
||||
"rhino" : false,
|
||||
"couch" : false,
|
||||
"wsh" : false,
|
||||
|
||||
"jquery" : true,
|
||||
"prototypejs" : false,
|
||||
"mootools" : false,
|
||||
"dojo" : false,
|
||||
|
||||
"predef" : [
|
||||
"require",
|
||||
"define"
|
||||
],
|
||||
|
||||
"debug" : false,
|
||||
"devel" : true,
|
||||
|
||||
"strict" : true,
|
||||
"globalstrict" : false,
|
||||
|
||||
"asi" : false,
|
||||
"laxbreak" : false,
|
||||
"bitwise" : true,
|
||||
"boss" : false,
|
||||
"curly" : true,
|
||||
"eqeqeq" : true,
|
||||
"eqnull" : false,
|
||||
"evil" : false,
|
||||
"expr" : false,
|
||||
"forin" : false,
|
||||
"immed" : true,
|
||||
"latedef" : true,
|
||||
"loopfunc" : false,
|
||||
"noarg" : true,
|
||||
"regexp" : true,
|
||||
"regexdash" : false,
|
||||
"scripturl" : true,
|
||||
"shadow" : false,
|
||||
"supernew" : false,
|
||||
"undef" : true,
|
||||
|
||||
"newcap" : true,
|
||||
"noempty" : false,
|
||||
"nonew" : true,
|
||||
"nomen" : false,
|
||||
"onevar" : false,
|
||||
"plusplus" : false,
|
||||
"sub" : false,
|
||||
"trailing" : true,
|
||||
"white" : true,
|
||||
"indent" : 2,
|
||||
"laxcomma" : true,
|
||||
"camelcase" : true
|
||||
}
|
||||
15
.travis.yml
15
.travis.yml
@@ -1,5 +1,14 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
before_script:
|
||||
- npm install -g grunt-cli
|
||||
- 4
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: jMfEk/5oF5NybZlrI2/QA3Gs2fYvE38GQQPyTVBgH5gBZqnaH4ij28fegxercTuzqO4AMGK7BvAmxNd6Wf95CYt72uuiRKFCpRto3/8kBh6TNS1SWQCB6U/heccr4hHGvPViCkkidPCAzAjRLe0TIkrHhJt1nQ5u/d6ZI3++e/0=
|
||||
file: ./dist/perfect-scrollbar.zip
|
||||
on:
|
||||
repo: noraesae/perfect-scrollbar
|
||||
branch: master
|
||||
tags: true
|
||||
before_deploy:
|
||||
- npm run before-deploy
|
||||
|
||||
74
CONTRIBUTING.md
Normal file
74
CONTRIBUTING.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Contributing
|
||||
|
||||
I *really* welcome contributions! Please feel free to fork and issue pull requests when...
|
||||
|
||||
* You have a very nice idea to improve this plugin!
|
||||
* You found a bug!
|
||||
* You're good at English and can help my bad English!
|
||||
|
||||
For IE problems, please refer to [IE Support](https://github.com/noraesae/perfect-scrollbar#ie-support).
|
||||
|
||||
## Introduction
|
||||
First of all, thank you in advance for your contribution!
|
||||
|
||||
This document will introduce something you should know before making some contributions to **perfect-scrollbar**. I'll try to explain as easy as possible. If there are something missed or not well-documented, please let me know.
|
||||
|
||||
Email: me@noraesae.net
|
||||
|
||||
## Directory Structure
|
||||
Please don't edit files in the `out` subdirectory as they are generated via Gulp. You'll find source code in the `src` subdirectory!
|
||||
|
||||
`examples` directory is for the example sources. If you have any example you want to add with a new feature, please add it in the directory.
|
||||
|
||||
## Code Conventions
|
||||
Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.**
|
||||
|
||||
Basically, I try to follow [Douglas Crockford's JavaScript Code Conventions](http://javascript.crockford.com/code.html).
|
||||
|
||||
You can check if your code fits in the convention with `gulp lint`.
|
||||
|
||||
## Getting Started
|
||||
First, ensure that you have stable [Node.js](https://nodejs.org/) and [npm](https://npmjs.com) installed.
|
||||
|
||||
Test if Gulp CLI is installed by running `gulp --version`. If the command isn't found, run `npm install -g gulp`. For more information about installing Gulp, see the Gulp's [Getting Started](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md).
|
||||
|
||||
If `gulp` is installed, follow the steps below.
|
||||
|
||||
1. Fork and clone the repo.
|
||||
1. Run `npm install` to install all dev dependencies.
|
||||
1. Run `gulp` to check if Gulp works well.
|
||||
|
||||
Assuming that you don't see any error, you're ready to go.
|
||||
|
||||
## Linting Sources
|
||||
|
||||
You can use `gulp lint` command to lint the source files. If there're warnings with the command, it means that there are something that don't fit into the convention. Please modify the source to fit.
|
||||
|
||||
## Building Sources
|
||||
|
||||
You can use the `gulp build` command to build source files into output files.
|
||||
|
||||
If you want to watch the modification and build automatically during development, use the `gulp serve` command. It'll automatically rebuild the code when there's any change in it. It will also reload example pages, which is quite helpful.
|
||||
|
||||
## Submitting pull requests
|
||||
|
||||
1. Create a new branch. Working in your `master` branch is okay, but not recommended.
|
||||
1. Modify the sources.
|
||||
1. Run `gulp` to see if the code fit into the code convention and build without an error. Repeat steps 2-3 until done.
|
||||
1. Update the documentation to reflect any changes.
|
||||
1. Create examples if needed.
|
||||
1. Push to your fork and submit a pull request.
|
||||
|
||||
For further information about pull requests, please refer to GitHub's [Using Pull Requests](https://help.github.com/articles/using-pull-requests).
|
||||
|
||||
## Code Review
|
||||
|
||||
When the pull request is created, anyone can review the source code. After the review is finished and the patch doesn't have any problem, it'll be merged.
|
||||
|
||||
## Conclusion
|
||||
|
||||
The process looks somewhat difficult, but it's necessary to avoid maintanance issues and make the code easy to read and use.
|
||||
|
||||
If there is any opinion or question, please feel free to contact me.
|
||||
|
||||
Email: me@noraesae.net
|
||||
83
Gruntfile.js
83
Gruntfile.js
@@ -1,83 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (grunt) {
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
// Metadata.
|
||||
pkg: grunt.file.readJSON('perfect-scrollbar.jquery.json'),
|
||||
version: grunt.file.readJSON('package.json').version,
|
||||
banner: '/*! <%= pkg.title || pkg.name %> - v<%= version %>\n' +
|
||||
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
|
||||
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
|
||||
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
|
||||
clean: {
|
||||
files: ['min']
|
||||
},
|
||||
// Task configuration.
|
||||
uglify: {
|
||||
options: {
|
||||
banner: '<%= banner %>'
|
||||
},
|
||||
min: {
|
||||
files: {
|
||||
'min/perfect-scrollbar.min.js': ['src/perfect-scrollbar.js']
|
||||
}
|
||||
}
|
||||
},
|
||||
jshint: {
|
||||
gruntfile: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
},
|
||||
src: 'Gruntfile.js'
|
||||
},
|
||||
src: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
},
|
||||
src: 'src/perfect-scrollbar.js'
|
||||
}
|
||||
},
|
||||
csslint: {
|
||||
strict: {
|
||||
options: {
|
||||
csslintrc: '.csslintrc',
|
||||
'import': 2
|
||||
},
|
||||
src: ['src/perfect-scrollbar.css']
|
||||
}
|
||||
},
|
||||
cssmin: {
|
||||
options: {
|
||||
banner: '<%= banner %>'
|
||||
},
|
||||
minify: {
|
||||
expand: true,
|
||||
cwd: 'src/',
|
||||
src: ['perfect-scrollbar.css'],
|
||||
dest: 'min/',
|
||||
ext: '.min.css'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// These plugins provide necessary tasks.
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-contrib-csslint');
|
||||
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
||||
|
||||
grunt.registerTask('default', 'List commands', function () {
|
||||
grunt.log.writeln("");
|
||||
|
||||
grunt.log.writeln("Run 'grunt lint' to lint the source files");
|
||||
grunt.log.writeln("Run 'grunt build' to minify the source files");
|
||||
});
|
||||
|
||||
grunt.registerTask('lint', ['jshint', 'csslint']);
|
||||
grunt.registerTask('build', ['clean', 'uglify', 'cssmin']);
|
||||
grunt.registerTask('travis', ['lint']);
|
||||
|
||||
};
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
The MIT License (MIT) Copyright (c) 2016 Hyunje Alex Jun and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
515
README.md
515
README.md
@@ -1,206 +1,451 @@
|
||||
perfect-scrollbar [](https://travis-ci.org/noraesae/perfect-scrollbar)
|
||||
=================
|
||||
# `perfect-scrollbar`
|
||||
|
||||
Tiny but perfect jQuery scrollbar plugin
|
||||
Minimalistic but perfect custom scrollbar plugin
|
||||
|
||||
Why perfect-scrollbar?
|
||||
------------------
|
||||
[](https://travis-ci.org/noraesae/perfect-scrollbar)
|
||||
|
||||
I worked on a personal project recently, and I was trying to find the jQuery scrollbar plugin that's *perfect*. But there was no *perfect* scrollbar plugin. That's why I decided to make one.
|
||||
If you want information of old versions<0.6.0, please refer to
|
||||
[an old documentation](https://github.com/noraesae/perfect-scrollbar/tree/0.5.9).
|
||||
|
||||
perfect-scrollbar is very tiny but *perfect* (for me, and maybe for the most of developers) jQuery scrollbar plugin.
|
||||
I hope you love this!
|
||||
## Why perfect-scrollbar?
|
||||
|
||||
Demo: http://noraesae.github.com/perfect-scrollbar/
|
||||
I was once working on a personal project, and trying to find the jQuery
|
||||
scrollbar plugin that's *perfect*. But there was no *perfect* one.
|
||||
That's why I decided to make one.
|
||||
|
||||
What does *perfect* mean?
|
||||
---------------------
|
||||
perfect-scrollbar is minimalistic but *perfect* (for me, and maybe for most developers)
|
||||
scrollbar plugin working with jQuery or vanilla JavaScript as well.
|
||||
|
||||
I hope you love it!
|
||||
|
||||
## [Demo](http://noraesae.github.com/perfect-scrollbar/)
|
||||
|
||||
[It's on the GitHub Pages](http://noraesae.github.com/perfect-scrollbar/).
|
||||
|
||||
## What does *perfect* mean?
|
||||
|
||||
*perfect* means...
|
||||
|
||||
* There should be no css change on any original element.
|
||||
* The scrollbar should not affect the original design layout.
|
||||
* The design of the scrollbar should be (nearly) fully customizable.
|
||||
* If the size of the container or the content changes, the scrollbar size and position should be able to change.
|
||||
* If the size of the container or the content changes, the scrollbar
|
||||
size and position should be able to change.
|
||||
* *New!* It should work with vanilla JavaScript and major tools like
|
||||
NPM or Browserify.
|
||||
|
||||
Then perfect-scrollbar is really *perfect*?
|
||||
-------------------------------------------
|
||||
## Then perfect-scrollbar is really *perfect*?
|
||||
|
||||
Yes! the only thing that's not *perfect* is my English.
|
||||
|
||||
* perfect-scrollbar has some requirements, but doesn't change or add any style on original elements.
|
||||
* perfect-scrollbar is designed not to have width or height. It's fixed on the right and bottom side of the container.
|
||||
* You can change nearly all css styles of the scrollbar. The scrollbar design has no dependency on scripts.
|
||||
* perfect-scrollbar support 'update' function. Whenever you need to update the size or position of the scrollbar, just update.
|
||||
* Additionally, perfect-scrollbar do use 'scrollTop' and 'scrollLeft', not absolute position or something messy.
|
||||
* perfect-scrollbar has some requirements, but doesn't change or add
|
||||
any style on original elements.
|
||||
* perfect-scrollbar is designed not to have width or height. It's fixed
|
||||
on the right and bottom side of the container.
|
||||
* You can change nearly all css styles of the scrollbar. The scrollbar
|
||||
design has no dependency on scripts.
|
||||
* perfect-scrollbar supports an 'update' function. Whenever you need
|
||||
to update the size or position of the scrollbar, just update.
|
||||
* Additionally, perfect-scrollbar uses 'scrollTop' and 'scrollLeft',
|
||||
not absolute positioning or something messy.
|
||||
* perfect-scrollbar supports RTL perfectly on both WebKit and Gecko based browsers.
|
||||
|
||||
It's cool, isn't it?
|
||||
|
||||
Install
|
||||
-------
|
||||
## Install
|
||||
|
||||
You can download the latest stable version with download links in [Github Page](http://noraesae.github.io/perfect-scrollbar/). You also can find all releases in [Releases](https://github.com/noraesae/perfect-scrollbar/releases) page.
|
||||
#### NPM
|
||||
|
||||
If you want to use the development version of the plugin, use the source files which are not minified. They're in the `src` directory. The development version may be unstable, but some known bugs can be fixed.
|
||||
The best way to install and use perfect-scrollbar is with NPM.
|
||||
It's registered on [npm](https://www.npmjs.com/package/perfect-scrollbar) as `perfect-scrollbar`.
|
||||
|
||||
```
|
||||
git clone https://github.com/noraesae/perfect-scrollbar.git
|
||||
cd perfect-scrollbar/src
|
||||
$ npm install perfect-scrollbar
|
||||
```
|
||||
|
||||
You can use [Bower](http://bower.io/) to install the plugin. The plugin is registered as `perfect-scrollbar`.
|
||||
#### Rails
|
||||
|
||||
In the case you would like to have perfect-scrollbar in your Rails application, there is the [perfect-scrollbar-rails gem](https://github.com/YourCursus/perfect-scrollbar-rails).
|
||||
|
||||
#### Manually
|
||||
|
||||
You can download the latest stable version with download links [here](http://noraesae.github.io/perfect-scrollbar/).
|
||||
You also can find all releases on [Releases](https://github.com/noraesae/perfect-scrollbar/releases).
|
||||
|
||||
#### From sources
|
||||
|
||||
If you want to use the development version of the plugin, use the
|
||||
source files which are not minified. They're in the `src` directory.
|
||||
The development version may be unstable, but some known bugs may
|
||||
have been fixed.
|
||||
|
||||
```
|
||||
bower install perfect-scrollbar
|
||||
$ git clone https://github.com/noraesae/perfect-scrollbar.git
|
||||
$ cd perfect-scrollbar/src
|
||||
$ npm install
|
||||
$ gulp # will lint and build the source code.
|
||||
```
|
||||
|
||||
Requirements
|
||||
------------
|
||||
#### Bower
|
||||
|
||||
To make this plugin *perfect*, some requirements were not avoidable. But they're all very trivial and there's nothing to worry about.
|
||||
There is a Bower package for perfect-scrollbar as well. It is managed
|
||||
under the [perfect-scrollbar-bower](https://github.com/noraesae/perfect-scrollbar-bower)
|
||||
repository. The plugin is registered as `perfect-scrollbar`.
|
||||
|
||||
```
|
||||
$ bower install perfect-scrollbar
|
||||
```
|
||||
|
||||
#### CDNs
|
||||
|
||||
* [cdnjs](http://www.cdnjs.com/libraries/jquery.perfect-scrollbar)
|
||||
* [JSDelivr](https://www.jsdelivr.com/projects/perfect-scrollbar)
|
||||
|
||||
#### JSFiddle
|
||||
|
||||
You can fork the following JSFiddles for testing and experimenting purposes:
|
||||
|
||||
* [Perfect Scrollbar](https://jsfiddle.net/DanielApt/xv0rrxv3/)
|
||||
* [Perfect Scrollbar (jQuery)](https://jsfiddle.net/DanielApt/gbfLazpx/)
|
||||
|
||||
## Before using perfect-scrollbar
|
||||
|
||||
The following requirements should meet.
|
||||
|
||||
* the container must have a 'position' css style.
|
||||
* the container must have an 'overflow:hidden' css style.
|
||||
* the container must be a normal container element.
|
||||
* PS may not work well in `body`, `textarea`, `iframe` or flexbox.
|
||||
|
||||
The following requirements are included in the basic CSS, but please
|
||||
keep in mind when you'd like to change the CSS files.
|
||||
|
||||
* the container must have an 'overflow: hidden' css style.
|
||||
* the scrollbar's position must be 'absolute'.
|
||||
* the scrollbar-x must have a 'bottom' css style, and the scrollbar-y must have a 'right' css style.
|
||||
* the scrollbar-x must have a 'bottom' css style, and the scrollbar-y
|
||||
must have a 'right' css style.
|
||||
|
||||
The requirement below is for perfect-scrollbar <= 0.3.4
|
||||
Please keep in mind that perfect-scrollbar won't completely emulate native
|
||||
scrolls. Scroll hooking is generally considered as bad practice, and
|
||||
perfect-scrollbar should be used with care. Unless custom scroll is really needed,
|
||||
please consider using native scrolls.
|
||||
|
||||
* there must be the *one* content element(like div) for the container.
|
||||
## How to use
|
||||
|
||||
Optional parameters
|
||||
-------------------
|
||||
|
||||
perfect-scrollbar supports optional parameters.
|
||||
|
||||
### wheelSpeed
|
||||
The scroll speed applied to mousewheel event.
|
||||
**Default: 1**
|
||||
|
||||
### wheelPropagation
|
||||
If this option is true, when the scroll reach the end of the side, mousewheel event will be propagated to parent element.
|
||||
*Currently not supported for touch events*
|
||||
**Default: false**
|
||||
|
||||
|
||||
### minScrollbarLength
|
||||
When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.
|
||||
**Default: null**
|
||||
|
||||
### maxScrollbarLength
|
||||
When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.
|
||||
**Default: null**
|
||||
|
||||
### useBothWheelAxes
|
||||
When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.
|
||||
**Default: false**
|
||||
|
||||
### useKeyboard
|
||||
When set to true, the scroll works with arrow keys on the keyboard. The element is scrolled only when the mouse cursor hovers the element.
|
||||
**Default: true**
|
||||
|
||||
### suppressScrollX
|
||||
When set to true, the scroll bar in X axis will not be available, regardless of the content width.
|
||||
**Default: false**
|
||||
|
||||
### suppressScrollY
|
||||
When set to true, the scroll bar in Y axis will not be available, regardless of the content height.
|
||||
**Default: false**
|
||||
|
||||
### scrollXMarginOffset
|
||||
The number of pixels the content width can surpass the container width without enabling the X axis scroll bar. Allows some "wiggle room" or "offset break", so that X axis scroll bar is not enabled just because of a few pixels.
|
||||
**Default: 0**
|
||||
|
||||
### scrollYMarginOffset
|
||||
The number of pixels the content height can surpass the container height without enabling the Y axis scroll bar. Allows some "wiggle room" or "offset break", so that Y axis scroll bar is not enabled just because of a few pixels.
|
||||
**Default: 0**
|
||||
|
||||
### includePadding
|
||||
When set to true, it uses `innerWidth` and `innerHeight` for the container size instead of `width` and `height`. When your container element has non-zero padding and the scrollbar layout looks weird, this option can be helpful.
|
||||
**Default: false**
|
||||
|
||||
How to Use
|
||||
----------
|
||||
First of all, please check if the container element meets the
|
||||
requirements.
|
||||
|
||||
```html
|
||||
<link rel='stylesheet' href='dist/css/perfect-scrollbar.css' />
|
||||
<style>
|
||||
#Demo {
|
||||
position: 'relative';
|
||||
height: 100%; // Or whatever you want (eg. 400px)
|
||||
overflow: hidden;
|
||||
#container {
|
||||
position: relative;
|
||||
height: 100%; /* Or whatever you want (eg. 400px) */
|
||||
}
|
||||
</style>
|
||||
<div id='Demo'>
|
||||
<div>
|
||||
...
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
When the html document is like above, just use like this:
|
||||
```javascript
|
||||
$('#Demo').perfectScrollbar();
|
||||
```
|
||||
|
||||
With optional parameters:
|
||||
I would recommend using the plugin with NPM and CommonJS module system
|
||||
like Browserify.
|
||||
|
||||
```javascript
|
||||
$("#Demo").perfectScrollbar({
|
||||
wheelSpeed: 20,
|
||||
var Ps = require('perfect-scrollbar');
|
||||
```
|
||||
|
||||
Or you can just load the script file as usual.
|
||||
|
||||
```html
|
||||
<script src='dist/js/perfect-scrollbar.js'></script>
|
||||
```
|
||||
|
||||
To initialise the plugin, `Ps.initialize` is used.
|
||||
|
||||
```javascript
|
||||
var container = document.getElementById('container');
|
||||
Ps.initialize(container);
|
||||
```
|
||||
|
||||
It can be initialised with optional parameters.
|
||||
|
||||
```javascript
|
||||
Ps.initialize(container, {
|
||||
wheelSpeed: 2,
|
||||
wheelPropagation: true,
|
||||
minScrollbarLength: 20
|
||||
});
|
||||
```
|
||||
|
||||
If the size of your container or content changes, call `update`.
|
||||
|
||||
```javascript
|
||||
Ps.update(container);
|
||||
```
|
||||
|
||||
If you want to destroy the scrollbar, use `destroy`.
|
||||
|
||||
```javascript
|
||||
Ps.destroy(container);
|
||||
```
|
||||
|
||||
If you want to scroll to somewhere, just use a `scrollTop`
|
||||
property and update.
|
||||
|
||||
```javascript
|
||||
container.scrollTop = 0;
|
||||
Ps.update(container);
|
||||
```
|
||||
|
||||
You can also get information about how to use the plugin
|
||||
from code in the `examples` directory of the source tree.
|
||||
|
||||
## jQuery
|
||||
|
||||
As you may already know, perfect-scrollbar was a jQuery plugin.
|
||||
And it *is* as well. There's a jQuery adaptor and the plugin can
|
||||
be used in the same way it used to be used before.
|
||||
|
||||
I also recommend using NPM and CommonJS here, but it's not mandatory.
|
||||
|
||||
```javascript
|
||||
var $ = require('jquery');
|
||||
require('perfect-scrollbar/jquery')($);
|
||||
```
|
||||
|
||||
For sure, you can just import a built script.
|
||||
|
||||
```html
|
||||
<script src='dist/js/perfect-scrollbar.jquery.js'></script>
|
||||
```
|
||||
|
||||
After importing it, you can use the plugin in the usual way.
|
||||
|
||||
```javascript
|
||||
$('#container').perfectScrollbar(); // Initialize
|
||||
$('#container').perfectScrollbar({ ... }); // with options
|
||||
$('#container').perfectScrollbar('update'); // Update
|
||||
$('#container').perfectScrollbar('destroy'); // Destroy
|
||||
```
|
||||
|
||||
## RequireJS usage
|
||||
|
||||
For RequireJS loader, no need to write shim, simply import two libs:
|
||||
|
||||
```javascript
|
||||
require.config({
|
||||
paths: {
|
||||
perfectScrollbarJQuery: '.../perfect-scrollbar.jquery',
|
||||
perfectScrollbar: '.../perfect-scrollbar',
|
||||
}
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
If the size of your container or content changes:
|
||||
|
||||
and load `perfectScrollbar` in the initialiser of your app:
|
||||
|
||||
```javascript
|
||||
$('#Demo').perfectScrollbar('update');
|
||||
```
|
||||
If you want to destory the scrollbar:
|
||||
```javascript
|
||||
$('#Demo').perfectScrollbar('destroy');
|
||||
// for vanilla JS:
|
||||
window.Ps = require('perfectScrollbar');
|
||||
|
||||
// for jQuery:
|
||||
require('perfectScrollbarJQuery');
|
||||
```
|
||||
|
||||
If you want to scroll to somewhere, just use scroll-top css and update.
|
||||
|
||||
## AngularJS + RequireJS usage
|
||||
|
||||
With the require.config settings above, at the beginning of your app module
|
||||
definition, you can have following code:
|
||||
|
||||
```javascript
|
||||
$("#Demo").scrollTop(0);
|
||||
$("#Demo").perfectScrollbar('update');
|
||||
define([
|
||||
'angular',
|
||||
'perfectScrollbar',
|
||||
'perfectScrollbarJquery'
|
||||
],
|
||||
function (angular) {
|
||||
var app = angular.module('myApp', []);
|
||||
app.run(function () {
|
||||
window.Ps = require('perfectScrollbar');
|
||||
require('perfectScrollbarJQuery');
|
||||
});
|
||||
return app;
|
||||
});
|
||||
```
|
||||
|
||||
Also you can get the informations about how to use the plugin from example codes in the `examples` directory of the source tree.
|
||||
And initialise perfectScrollbar in a controller:
|
||||
|
||||
Contribution
|
||||
------------
|
||||
```javascript
|
||||
// by vanilla JS:
|
||||
var container = document.getElementById('imgLoader');
|
||||
Ps.initialize(container);
|
||||
Ps.update(container);
|
||||
|
||||
#### Please read [Contributing](https://github.com/noraesae/perfect-scrollbar/wiki/Contributing) in the wiki before making any contibution.
|
||||
// or by jQuery:
|
||||
var imgLoader = $('#imgLoader')
|
||||
imgLoader.perfectScrollbar();
|
||||
```
|
||||
|
||||
## Optional parameters
|
||||
|
||||
perfect-scrollbar supports optional parameters.
|
||||
|
||||
### handlers
|
||||
It is a list of handlers to use to scroll the element.
|
||||
**Default**: `['click-rail', 'drag-scrollbar', 'keyboard', 'wheel', 'touch']`
|
||||
**Disabled by default**: `'selection'`
|
||||
|
||||
### wheelSpeed
|
||||
The scroll speed applied to mousewheel event.
|
||||
**Default**: `1`
|
||||
|
||||
### wheelPropagation
|
||||
If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element.
|
||||
**Default**: `false`
|
||||
|
||||
### swipePropagation
|
||||
If this option is true, when the scroll reaches the end of the side, touch scrolling will be propagated to parent element.
|
||||
**Default**: `true`
|
||||
|
||||
### minScrollbarLength
|
||||
When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.
|
||||
**Default**: `null`
|
||||
|
||||
### maxScrollbarLength
|
||||
When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.
|
||||
**Default**: `null`
|
||||
|
||||
### useBothWheelAxes
|
||||
When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.
|
||||
**Default**: `false`
|
||||
|
||||
### suppressScrollX
|
||||
When set to true, the scroll bar in X axis will not be available, regardless of the content width.
|
||||
**Default**: `false`
|
||||
|
||||
### suppressScrollY
|
||||
When set to true, the scroll bar in Y axis will not be available, regardless of the content height.
|
||||
**Default**: `false`
|
||||
|
||||
### scrollXMarginOffset
|
||||
The number of pixels the content width can surpass the container width without enabling the X axis scroll bar. Allows some "wiggle room" or "offset break", so that X axis scroll bar is not enabled just because of a few pixels.
|
||||
**Default**: `0`
|
||||
|
||||
### scrollYMarginOffset
|
||||
The number of pixels the content height can surpass the container height without enabling the Y axis scroll bar. Allows some "wiggle room" or "offset break", so that Y axis scroll bar is not enabled just because of a few pixels.
|
||||
**Default**: `0`
|
||||
|
||||
### autoupdate
|
||||
When set to true, the scroll will be updated when an element is added or removed from the content.
|
||||
**Default**: `true`
|
||||
|
||||
### theme
|
||||
A string. It's a class name added to the container element. The class name is prepended with `ps-theme-`. So default theme class name is `ps-theme-default`. In order to create custom themes with scss use `ps-container($theme)` mixin, where `$theme` is a scss map.
|
||||
**Default**: `'default'`
|
||||
|
||||
**Example 1:**
|
||||
|
||||
Add `theme` parameter:
|
||||
```javascript
|
||||
Ps.initialize(container, {
|
||||
theme: 'my-theme-name'
|
||||
});
|
||||
```
|
||||
Create a class name prefixed with `.ps-theme-`. Include `ps-container()` mixin. It's recommended to use `map-merge()` to extend `$ps-theme-default` map with your custom styles.
|
||||
```scss
|
||||
.ps-theme-my-theme-name {
|
||||
@include ps-container(map-merge($ps-theme-default, (
|
||||
border-radius: 0,
|
||||
scrollbar-x-rail-height: 20px,
|
||||
scrollbar-x-height: 20px,
|
||||
scrollbar-y-rail-width: 20px,
|
||||
scrollbar-y-width: 20px
|
||||
)));
|
||||
}
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
Alternatively, if you don't want to create your own themes, but only modify the default one, you could simply overwrite `$ps-*` variables with your own values. In this case `theme` parameter is not required when calling `.initialize()` method. Remember do define your own variables before the `theme.scss` file is imported.
|
||||
|
||||
|
||||
I *really* welcome contributions! Please feel free to fork and issue pull requests when...
|
||||
## Events
|
||||
|
||||
* You have a very nice idea to improve this plugin!
|
||||
* You found a bug!
|
||||
* You're good at English and can help my bad English!
|
||||
perfect-scrollbar dispatches custom events.
|
||||
|
||||
For IE problems, please refer to [IE Support](https://github.com/noraesae/perfect-scrollbar#ie-support)
|
||||
### ps-scroll-y
|
||||
This event fires when the y-axis is scrolled in either direction.
|
||||
|
||||
IE Support
|
||||
----------
|
||||
### ps-scroll-x
|
||||
This event fires when the x-axis is scrolled in either direction.
|
||||
|
||||
This plugin supports old IE browsers in the **minimum** range. The plugin is tested in IEs >= IE6 and works(not well, but works).
|
||||
### ps-scroll-up
|
||||
This event fires when scrolling upwards.
|
||||
|
||||
**But the project will not accept the patches to fix IE problems in IE 6/7/8.**
|
||||
### ps-scroll-down
|
||||
This event fires when scrolling downwards.
|
||||
|
||||
From jQuery 2.0, jQuery also will not support IE 6/7/8. I also think that supporting old browsers really breaks the web development conventions.
|
||||
### ps-scroll-left
|
||||
This event fires when scrolling to the left.
|
||||
|
||||
When old IEs should be supported, please fork the project and make patches personally.
|
||||
### ps-scroll-right
|
||||
This event fires when scrolling to the right.
|
||||
|
||||
Helpdesk
|
||||
--------
|
||||
### ps-y-reach-start
|
||||
This event fires when scrolling reaches the start of the y-axis.
|
||||
|
||||
If you have any idea to improve this project or any problem using this, please feel free to upload an [issue](https://github.com/noraesae/perfect-scrollbar/issues).
|
||||
### ps-y-reach-end
|
||||
This event fires when scrolling reaches the end of the y-axis (useful for infinite scroll).
|
||||
|
||||
License
|
||||
-------
|
||||
### ps-x-reach-start
|
||||
This event fires when scrolling reaches the start of the x-axis.
|
||||
|
||||
The MIT License (MIT) Copyright (c) 2012, 2014 Hyunje Alex Jun and other contributors.
|
||||
### ps-x-reach-end
|
||||
This event fires when scrolling reaches the end of the x-axis.
|
||||
|
||||
### ps-dom-change
|
||||
This event fires when dom elements have been added to or removed from the content.
|
||||
|
||||
You can listen to these events either with vanilla JavaScript
|
||||
```javascript
|
||||
document.addEventListener('ps-scroll-x', function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
or with jQuery
|
||||
```javascript
|
||||
$(document).on('ps-scroll-x', function () {
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
### Scrolling children inside perfect-scrollbar
|
||||
|
||||
You can natively scroll children inside `perfect-scrollbar` with the mouse-wheel. Scrolling automatically works if
|
||||
the child is a `textarea`. All other elements need to have the `ps-child` class. This is demonstrated in [`/examples/children-native-scroll.html`](examples/children-native-scroll.html)
|
||||
|
||||
## IE Support
|
||||
|
||||
The plugin is designed to work in modern browsers, including the very latest
|
||||
version of IE and Edge. Specifically, it should work in IEs >= IE10. If there
|
||||
is any issue in the browsers, please [file it](https://github.com/noraesae/perfect-scrollbar/issues).
|
||||
|
||||
**The patches to fix problems in IE<=9 won't be accepted.**
|
||||
|
||||
When old IEs should be supported, please fork the project and
|
||||
make patches personally.
|
||||
|
||||
## Helpdesk
|
||||
|
||||
If you have any idea to improve this project or any problem
|
||||
using this, please feel free to upload an
|
||||
[issue](https://github.com/noraesae/perfect-scrollbar/issues).
|
||||
|
||||
For common problems there is a
|
||||
[FAQ](https://github.com/noraesae/perfect-scrollbar/wiki/FAQ) wiki page. Please check the page before uploading an issue.
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT) Copyright (c) 2016 Hyunje Alex Jun and other contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
24
bower.json
24
bower.json
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "perfect-scrollbar",
|
||||
"version": "0.5.2",
|
||||
"homepage": "http://noraesae.github.io/perfect-scrollbar/",
|
||||
"authors": [
|
||||
"Hyunje Alex Jun <me@noraesae.net>"
|
||||
],
|
||||
"description": "Tiny but perfect jQuery scrollbar plugin",
|
||||
"main": [
|
||||
"src/perfect-scrollbar.css",
|
||||
"src/perfect-scrollbar.js"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"dependencies": {
|
||||
"jquery": ">=1.10"
|
||||
}
|
||||
}
|
||||
41
examples/always-visible.html
Normal file
41
examples/always-visible.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
h1 { text-align: center; }
|
||||
.container { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.container .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
</style>
|
||||
<style>
|
||||
/* to make scrollbars always visible */
|
||||
.always-visible.ps-container > .ps-scrollbar-x-rail,
|
||||
.always-visible.ps-container > .ps-scrollbar-y-rail {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Default</h1>
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Always visible</h1>
|
||||
<div class="container always-visible">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
[].forEach.call(document.querySelectorAll('.container'), function (el) {
|
||||
Ps.initialize(el);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
73
examples/children-native-scroll.html
Normal file
73
examples/children-native-scroll.html
Normal file
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.my-list, textarea {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 130px;
|
||||
height: 200px;
|
||||
overflow: scroll;
|
||||
background-color: rgba(255,255,255,0.6);
|
||||
}
|
||||
|
||||
.my-list {
|
||||
left: 140px;
|
||||
}
|
||||
|
||||
.my-list-two {
|
||||
left: 280px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
li {
|
||||
box-sizing: border-box;
|
||||
padding: 10px 5px;
|
||||
border-width: 0 0 1px 0;
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
li:nth-child(even) {
|
||||
background-color: rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
textarea {
|
||||
font-size: 120%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<div id="Default" class="contentHolder">
|
||||
<div class="content">
|
||||
<textarea cols="20" rows="50">
|
||||
Children inside perfect scrollbar can be natively scrolled by the mousewheel. It automatically works for textarea elements, other elements need the .ps-child class.
|
||||
</textarea>
|
||||
<div class="ps-child my-list">
|
||||
<code>overflow: scroll</code>
|
||||
<ul><li>One</li><li>Two</li><li>Three</li><li>Four</li><li>Five</li><li>Six</li><li>Seven</li><li>Eight</li></ul>
|
||||
</div>
|
||||
<div class="ps-child my-list my-list-two">
|
||||
<code>overflow: auto</code>
|
||||
<ul><li>One</li><li>Two</li><li>Three</li><li>Four</li><li>Five</li><li>Six</li><li>Seven</li><li>Eight</li></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
window.onload = function () {
|
||||
Ps.initialize(document.querySelector('#Default'));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
190
examples/custom-theme.css
Normal file
190
examples/custom-theme.css
Normal file
@@ -0,0 +1,190 @@
|
||||
.ps-container {
|
||||
-ms-touch-action: none;
|
||||
touch-action: none;
|
||||
overflow: hidden !important;
|
||||
-ms-overflow-style: none; }
|
||||
@supports (-ms-overflow-style: none) {
|
||||
.ps-container {
|
||||
overflow: auto !important; } }
|
||||
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
|
||||
.ps-container {
|
||||
overflow: auto !important; } }
|
||||
.ps-container.ps-active-x > .ps-scrollbar-x-rail,
|
||||
.ps-container.ps-active-y > .ps-scrollbar-y-rail {
|
||||
display: block;
|
||||
background-color: transparent; }
|
||||
.ps-container.ps-in-scrolling {
|
||||
pointer-events: none; }
|
||||
.ps-container.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-container.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
.ps-container > .ps-scrollbar-x-rail {
|
||||
display: none;
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
opacity: 0;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
bottom: 0px;
|
||||
/* there must be 'bottom' for ps-scrollbar-x-rail */
|
||||
height: 15px; }
|
||||
.ps-container > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
background-color: #aaa;
|
||||
border-radius: 6px;
|
||||
transition: background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;
|
||||
bottom: 2px;
|
||||
/* there must be 'bottom' for ps-scrollbar-x */
|
||||
height: 6px; }
|
||||
.ps-container > .ps-scrollbar-x-rail:hover > .ps-scrollbar-x, .ps-container > .ps-scrollbar-x-rail:active > .ps-scrollbar-x {
|
||||
height: 11px; }
|
||||
.ps-container > .ps-scrollbar-y-rail {
|
||||
display: none;
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
opacity: 0;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
right: 0;
|
||||
/* there must be 'right' for ps-scrollbar-y-rail */
|
||||
width: 15px; }
|
||||
.ps-container > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
background-color: #aaa;
|
||||
border-radius: 6px;
|
||||
transition: background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;
|
||||
right: 2px;
|
||||
/* there must be 'right' for ps-scrollbar-y */
|
||||
width: 6px; }
|
||||
.ps-container > .ps-scrollbar-y-rail:hover > .ps-scrollbar-y, .ps-container > .ps-scrollbar-y-rail:active > .ps-scrollbar-y {
|
||||
width: 11px; }
|
||||
.ps-container:hover.ps-in-scrolling {
|
||||
pointer-events: none; }
|
||||
.ps-container:hover.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container:hover.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-container:hover.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container:hover.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
.ps-container:hover > .ps-scrollbar-x-rail,
|
||||
.ps-container:hover > .ps-scrollbar-y-rail {
|
||||
opacity: 0.6; }
|
||||
.ps-container:hover > .ps-scrollbar-x-rail:hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container:hover > .ps-scrollbar-x-rail:hover > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-container:hover > .ps-scrollbar-y-rail:hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-container:hover > .ps-scrollbar-y-rail:hover > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
|
||||
/*
|
||||
this file is built into custom-theme.css
|
||||
|
||||
$ node-sass examples/custom-theme.scss -o examples/
|
||||
*/
|
||||
.ps-theme-square {
|
||||
-ms-touch-action: none;
|
||||
touch-action: none;
|
||||
overflow: hidden !important;
|
||||
-ms-overflow-style: none; }
|
||||
@supports (-ms-overflow-style: none) {
|
||||
.ps-theme-square {
|
||||
overflow: auto !important; } }
|
||||
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
|
||||
.ps-theme-square {
|
||||
overflow: auto !important; } }
|
||||
.ps-theme-square.ps-active-x > .ps-scrollbar-x-rail,
|
||||
.ps-theme-square.ps-active-y > .ps-scrollbar-y-rail {
|
||||
display: block;
|
||||
background-color: transparent; }
|
||||
.ps-theme-square.ps-in-scrolling {
|
||||
pointer-events: none; }
|
||||
.ps-theme-square.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-theme-square.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
.ps-theme-square > .ps-scrollbar-x-rail {
|
||||
display: none;
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
opacity: 0;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
bottom: 0;
|
||||
/* there must be 'bottom' for ps-scrollbar-x-rail */
|
||||
height: 10px; }
|
||||
.ps-theme-square > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
background-color: #aaa;
|
||||
border-radius: 0;
|
||||
transition: background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;
|
||||
bottom: 0;
|
||||
/* there must be 'bottom' for ps-scrollbar-x */
|
||||
height: 10px; }
|
||||
.ps-theme-square > .ps-scrollbar-x-rail:hover > .ps-scrollbar-x, .ps-theme-square > .ps-scrollbar-x-rail:active > .ps-scrollbar-x {
|
||||
height: 10px; }
|
||||
.ps-theme-square > .ps-scrollbar-y-rail {
|
||||
display: none;
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
opacity: 0;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
right: 0;
|
||||
/* there must be 'right' for ps-scrollbar-y-rail */
|
||||
width: 10px; }
|
||||
.ps-theme-square > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
position: absolute;
|
||||
/* please don't change 'position' */
|
||||
background-color: #aaa;
|
||||
border-radius: 0;
|
||||
transition: background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;
|
||||
right: 0;
|
||||
/* there must be 'right' for ps-scrollbar-y */
|
||||
width: 10px; }
|
||||
.ps-theme-square > .ps-scrollbar-y-rail:hover > .ps-scrollbar-y, .ps-theme-square > .ps-scrollbar-y-rail:active > .ps-scrollbar-y {
|
||||
width: 10px; }
|
||||
.ps-theme-square:hover.ps-in-scrolling {
|
||||
pointer-events: none; }
|
||||
.ps-theme-square:hover.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square:hover.ps-in-scrolling.ps-x > .ps-scrollbar-x-rail > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-theme-square:hover.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square:hover.ps-in-scrolling.ps-y > .ps-scrollbar-y-rail > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
.ps-theme-square:hover > .ps-scrollbar-x-rail,
|
||||
.ps-theme-square:hover > .ps-scrollbar-y-rail {
|
||||
opacity: 0.6; }
|
||||
.ps-theme-square:hover > .ps-scrollbar-x-rail:hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square:hover > .ps-scrollbar-x-rail:hover > .ps-scrollbar-x {
|
||||
background-color: #999; }
|
||||
.ps-theme-square:hover > .ps-scrollbar-y-rail:hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9; }
|
||||
.ps-theme-square:hover > .ps-scrollbar-y-rail:hover > .ps-scrollbar-y {
|
||||
background-color: #999; }
|
||||
38
examples/custom-theme.html
Normal file
38
examples/custom-theme.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="custom-theme.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position: relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<p style='text-align: center'>
|
||||
<button id='default'>default</button>
|
||||
<button id='custom'>custom</button>
|
||||
</p>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
var container = $('#container');
|
||||
window.onload = function () {
|
||||
Ps.initialize(container, { theme: 'square' });
|
||||
};
|
||||
$('#default').addEventListener('click', function () {
|
||||
Ps.destroy(container);
|
||||
Ps.initialize(container);
|
||||
});
|
||||
$('#custom').addEventListener('click', function () {
|
||||
Ps.destroy(container);
|
||||
Ps.initialize(container, { theme: 'square' });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
23
examples/custom-theme.scss
Normal file
23
examples/custom-theme.scss
Normal file
@@ -0,0 +1,23 @@
|
||||
@import '../src/css/main';
|
||||
|
||||
/*
|
||||
this file is built into custom-theme.css
|
||||
|
||||
$ node-sass examples/custom-theme.scss -o examples/
|
||||
*/
|
||||
|
||||
.ps-theme-square {
|
||||
@include ps-container(map-merge($ps-theme-default, (
|
||||
border-radius: 0,
|
||||
scrollbar-x-rail-bottom: 0,
|
||||
scrollbar-x-rail-height: 10px,
|
||||
scrollbar-x-bottom: 0,
|
||||
scrollbar-x-height: 10px,
|
||||
scrollbar-x-hover-height: 10px,
|
||||
scrollbar-y-rail-right: 0,
|
||||
scrollbar-y-rail-width: 10px,
|
||||
scrollbar-y-right: 0,
|
||||
scrollbar-y-width: 10px,
|
||||
scrollbar-y-hover-width: 10px,
|
||||
)));
|
||||
}
|
||||
89
examples/events.html
Normal file
89
examples/events.html
Normal file
@@ -0,0 +1,89 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
margin: 0px auto;
|
||||
padding: 0px;
|
||||
width: 600px;
|
||||
height: 400px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.container .content {
|
||||
background-image: url('./azusa.jpg');
|
||||
width: 1280px;
|
||||
height: 720px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p><strong>Axis</strong> <span id="axis">…</span></p>
|
||||
|
||||
<p><strong>Direction</strong> <span id="direction">…</span></p>
|
||||
|
||||
<p><strong>Start / End</strong> <span id="start-end">(scroll to the start or end of an axis)</span></p>
|
||||
<script>
|
||||
var container = document.querySelector('.container');
|
||||
var axis = document.getElementById('axis');
|
||||
var direction = document.getElementById('direction');
|
||||
var startEnd = document.getElementById('start-end');
|
||||
|
||||
Ps.initialize(container);
|
||||
|
||||
document.addEventListener('ps-scroll-y', function () {
|
||||
axis.innerHTML = 'Y Axis';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-scroll-x', function () {
|
||||
axis.innerHTML = 'X Axis';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-scroll-up', function () {
|
||||
direction.innerHTML = 'up';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-scroll-down', function () {
|
||||
direction.innerHTML = 'down';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-scroll-left', function () {
|
||||
direction.innerHTML = 'left';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-scroll-right', function () {
|
||||
direction.innerHTML = 'right';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-y-reach-start', function () {
|
||||
startEnd.innerHTML = 'Reached start of <em>Y-Axis</em>';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-y-reach-end', function () {
|
||||
startEnd.innerHTML = 'Reached end of <em>Y-Axis</em>';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-x-reach-start', function () {
|
||||
startEnd.innerHTML = 'Reached start of <em>X-Axis</em>';
|
||||
});
|
||||
|
||||
document.addEventListener('ps-x-reach-end', function () {
|
||||
startEnd.innerHTML = 'Reached end of <em>X-Axis</em>'
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
20
examples/iframe-content.html
Normal file
20
examples/iframe-content.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px;}
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
22
examples/iframe.html
Normal file
22
examples/iframe.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#iframe { width: 100%; min-height: 450px; border: 0; }
|
||||
html { direction: rtl; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="iframe-content.html" id="iframe"></iframe>
|
||||
<script>
|
||||
var iframe = document.querySelector('#iframe');
|
||||
iframe.onload = function () {
|
||||
Ps.initialize(iframe.contentDocument.querySelector('#Default'))
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
63
examples/infinite-scroll.html
Normal file
63
examples/infinite-scroll.html
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#Default {
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
background-color: #f1f1f1;
|
||||
border: 1px solid blue;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
.entryPlaceholder {
|
||||
height: 48px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var x = 0;
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
// show some initial data
|
||||
for(var i = 0; i < 10; i++) {
|
||||
$('#Default').innerHTML += '<div class="entryPlaceholder">Entry #' + (x++) + '</div>';
|
||||
}
|
||||
Ps.initialize($('#Default'));
|
||||
|
||||
};
|
||||
|
||||
var isProgramaticallyTriggered = false;
|
||||
var addEntries = function(num) {
|
||||
for(var i = 0; i < num; i++) {
|
||||
$('#Default').innerHTML += '<div class="entryPlaceholder">Entry #' + (x++) + '</div>';
|
||||
}
|
||||
|
||||
isProgramaticallyTriggered = true;
|
||||
Ps.update($('#Default'));
|
||||
isProgramaticallyTriggered = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// on scroll, add more entries
|
||||
document.addEventListener('ps-scroll-y', function(e) {
|
||||
if (!isProgramaticallyTriggered) {
|
||||
console.debug("user scrolled to pos: ", $('#Default').scrollTop);
|
||||
addEntries(1);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
40
examples/jquery.html
Normal file
40
examples/jquery.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../dist/js/perfect-scrollbar.jquery.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Default; wheelSpeed:1</h1>
|
||||
<div id="Default" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<h1 style="text-align:center">Fast: wheelSpeed:10</h1>
|
||||
<div id="FastWheelSpeed" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<h1 style="text-align:center">Slow: wheelSpeed:0.1</h1>
|
||||
<div id="SlowWheelSpeed" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function ($) {
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#FastWheelSpeed').perfectScrollbar({wheelSpeed: 10});
|
||||
$('#SlowWheelSpeed').perfectScrollbar({wheelSpeed: 0.1});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
55
examples/options-autoupdate.html
Normal file
55
examples/options-autoupdate.html
Normal file
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 80%; height: 400px; overflow: auto; }
|
||||
.always-visible.contentHolder .content { background-image: url('./azusa.jpg'); width: 680px; height: 320px; }
|
||||
.spacer { text-align:center }
|
||||
|
||||
.always-visible.ps-container > .ps-scrollbar-x-rail,
|
||||
.always-visible.ps-container > .ps-scrollbar-y-rail {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default" class="contentHolder always-visible">
|
||||
<div id="Content" class="content">
|
||||
</div>
|
||||
</div>
|
||||
<p style='text-align: center'>
|
||||
<button onclick='addContent()'>Add new content!</button>
|
||||
<button onclick='removeContent()'>Remove content!</button>
|
||||
</p>
|
||||
<script>
|
||||
var i = 1;
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'), {
|
||||
autoupdate: true
|
||||
});
|
||||
};
|
||||
|
||||
var addContent = function () {
|
||||
var newDiv = document.createElement('div');
|
||||
newDiv.id = 'node' + i++;
|
||||
var newContent = document.createTextNode('Hi there!');
|
||||
newDiv.appendChild(newContent);
|
||||
|
||||
$('#Default').insertBefore(newDiv, $('#Content'));
|
||||
};
|
||||
|
||||
var removeContent = function () {
|
||||
if (i <= 1) return;
|
||||
|
||||
var node = $('#node' + --i);
|
||||
node.parentNode.removeChild(node);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
});
|
||||
var updateSize = function () {
|
||||
var width = parseInt($('#width').val(), 10);
|
||||
var height = parseInt($('#height').val(), 10);
|
||||
$('#Default').width(width).height(height).perfectScrollbar('update');
|
||||
};
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default" class="contentHolder">
|
||||
@@ -33,6 +21,20 @@
|
||||
Height <input type='text' id='height' value='400'>
|
||||
<button onclick='updateSize()'>Change!</button>
|
||||
</p>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
};
|
||||
var updateSize = function () {
|
||||
var width = parseInt($('#width').value, 10);
|
||||
var height = parseInt($('#height').value, 10);
|
||||
var container = $('#Default');
|
||||
container.style.width = width + 'px';
|
||||
container.style.height = height + 'px';
|
||||
Ps.update(document.querySelector('#Default'));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
49
examples/options-handlers.html
Normal file
49
examples/options-handlers.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Default</h1>
|
||||
<pre><code>handlers: ['click-rail', 'drag-scrollbar', 'keyboard', 'wheel', 'touch']</code></pre>
|
||||
<div id="default" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>No keyboard</h1>
|
||||
<pre><code>handlers: ['click-rail', 'drag-scrollbar', 'wheel', 'touch']</code></pre>
|
||||
<div id="no-keyboard" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Click and Drag</h1>
|
||||
<pre><code>handlers: ['click-rail', 'drag-scrollbar']</code></pre>
|
||||
<div id="click-and-drag" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#default'));
|
||||
Ps.initialize($('#no-keyboard'), {
|
||||
handlers: ['click-rail', 'drag-scrollbar', 'wheel', 'touch']
|
||||
});
|
||||
Ps.initialize($('#click-and-drag'), {
|
||||
handlers: ['click-rail', 'drag-scrollbar']
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 640px; height: 360px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 12800px; height: 7200px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#LongThumb').perfectScrollbar({minScrollbarLength:100});
|
||||
});
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 640px; height: 360px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 12800px; height: 7200px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">No minimum</h1>
|
||||
@@ -30,5 +22,12 @@
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
Ps.initialize($('#LongThumb'), {minScrollbarLength: 100});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
h2 { text-align: center; }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#SuppressScrollX').perfectScrollbar({suppressScrollX: true});
|
||||
$('#SuppressScrollY').perfectScrollbar({suppressScrollY: true});
|
||||
});
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
h2 { text-align: center; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Default</h2>
|
||||
@@ -37,6 +28,13 @@
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
Ps.initialize($('#SuppressScrollX'), {suppressScrollX: true});
|
||||
Ps.initialize($('#SuppressScrollY'), {suppressScrollY: true});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 640px; height: 360px; overflow: hidden; }
|
||||
.contentHolder .content-x { background-image: url('./azusa.jpg'); width: 1920px; height: 360px; }
|
||||
.contentHolder .content-y { background-image: url('./azusa.jpg'); width: 640px; height: 1080px; }
|
||||
.spacer { text-align:center; }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#CanScrollWithYAxis').perfectScrollbar({useBothWheelAxes: true});
|
||||
$('#CanScrollWithXAxis').perfectScrollbar({useBothWheelAxes: true});
|
||||
});
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 640px; height: 360px; overflow: auto; }
|
||||
.contentHolder .content-x { background-image: url('./azusa.jpg'); width: 1920px; height: 360px; }
|
||||
.contentHolder .content-y { background-image: url('./azusa.jpg'); width: 640px; height: 1080px; }
|
||||
.spacer { text-align:center; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Default.</h1>
|
||||
@@ -37,5 +28,13 @@
|
||||
<div class="content-y">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
Ps.initialize($('#CanScrollWithYAxis'), {useBothWheelAxes: true});
|
||||
Ps.initialize($('#CanScrollWithXAxis'), {useBothWheelAxes: true});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#NoWheelPropagation').perfectScrollbar({wheelPropagation:true});
|
||||
});
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Default; wheelPropagation:false</h1>
|
||||
@@ -26,7 +18,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<h1 style="text-align:center">wheelPropagation:true</h1>
|
||||
<div id="NoWheelPropagation" class="contentHolder">
|
||||
<div id="WheelPropagation" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
@@ -34,6 +26,13 @@
|
||||
Note<br>that<br>there<br>is<br>plenty<br>of<br>text<br>after<br>the<br>image<br>to<br>ensure<br>that<br>it<br>is<br>possible<br>to<br>down<br>
|
||||
after<br>the<br>bottom<br>of<br>the<br>image<br>has<br>been<br>reached<br>to<br>enable<br>the<br>wheel<br>propagation<br>to<br>be<br>tested<br>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
Ps.initialize($('#WheelPropagation'), {wheelPropagation: true});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
$('#FastWheelSpeed').perfectScrollbar({wheelSpeed:10});
|
||||
$('#SlowWheelSpeed').perfectScrollbar({wheelSpeed:0.1});
|
||||
});
|
||||
</script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Default; wheelSpeed:1</h1>
|
||||
@@ -36,6 +27,14 @@
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
Ps.initialize($('#FastWheelSpeed'), {wheelSpeed: 10});
|
||||
Ps.initialize($('#SlowWheelSpeed'), {wheelSpeed: 0.1});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#description {
|
||||
border: 1px solid gray;
|
||||
height:150px;
|
||||
width: 400px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
#status {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function ($) {
|
||||
var $container = $('#description');
|
||||
var $status = $('#status');
|
||||
$container.perfectScrollbar();
|
||||
$container.scroll(function(e) {
|
||||
if($container.scrollTop() === 0) {
|
||||
$status.text('it reaches the top!');
|
||||
}
|
||||
else if ($container.scrollTop() === $container.prop('scrollHeight') - $container.height()) {
|
||||
$status.text('it reaches the end!');
|
||||
} else {
|
||||
$status.text('');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="description" class="wrapper">
|
||||
<p>Hello, world! 0</p>
|
||||
<p>Hello, world! 1</p>
|
||||
<p>Hello, world! 2</p>
|
||||
<p>Hello, world! 3</p>
|
||||
<p>Hello, world! 4</p>
|
||||
<p>Hello, world! 5</p>
|
||||
<p>Hello, world! 6</p>
|
||||
<p>Hello, world! 7</p>
|
||||
<p>Hello, world! 8</p>
|
||||
<p>Hello, world! 9</p>
|
||||
</div>
|
||||
<div id="status">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
53
examples/removable-list-element.html
Normal file
53
examples/removable-list-element.html
Normal file
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#test {
|
||||
border: 1px solid gray;
|
||||
max-height: 300px;
|
||||
width: 400px;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
#test .element {
|
||||
margin: 1px;
|
||||
background-color: #cec;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="test" class="wrapper">
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
<div class='element'>Hello! Click <a href='#'>here</a> to remove this!</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
var test = $('#test');
|
||||
Ps.initialize(test);
|
||||
[].forEach.call(test.querySelectorAll('.element'), function (el) {
|
||||
el.querySelector('a').addEventListener('click', function () {
|
||||
el.parentNode.removeChild(el);
|
||||
Ps.update(test);
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
|
||||
html { direction: rtl; }
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
});
|
||||
</script>
|
||||
html { direction: rtl; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
.spacer { text-align:center }
|
||||
|
||||
/* Change the alignment of scrollbars */
|
||||
/* Recommended: You can just modify the CSS file directly. */
|
||||
.ps-container .ps-scrollbar-x-rail {
|
||||
top: 3px;
|
||||
bottom: auto; /* If using `top`, there shouldn't be a `bottom`. */
|
||||
}
|
||||
.ps-container .ps-scrollbar-y-rail {
|
||||
left: 3px;
|
||||
right: auto; /* If using `left`, there shouldn't be a `right`. */
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
"use strict";
|
||||
$('#Default').perfectScrollbar();
|
||||
});
|
||||
</script>
|
||||
/* Change the alignment of scrollbars */
|
||||
/* Recommended: You can just modify the CSS file directly. */
|
||||
.ps-container .ps-scrollbar-x-rail {
|
||||
top: 3px;
|
||||
bottom: auto; /* If using `top`, there shouldn't be a `bottom`. */
|
||||
}
|
||||
.ps-container .ps-scrollbar-y-rail {
|
||||
left: 3px;
|
||||
right: auto; /* If using `left`, there shouldn't be a `right`. */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="Default" class="contentHolder">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#Default'));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
45
examples/scrollbars-with-margin.html
Normal file
45
examples/scrollbars-with-margin.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
h1 { text-align: center; }
|
||||
.container { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: auto; }
|
||||
.container .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
|
||||
|
||||
.large-margin .ps-scrollbar-x-rail {
|
||||
margin: 0 25%;
|
||||
opacity: 0.5;
|
||||
background-color: #eee;
|
||||
}
|
||||
.large-margin .ps-scrollbar-y-rail {
|
||||
margin: 100px 0;
|
||||
opacity: 0.5;
|
||||
background-color: #eee;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Default</h1>
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>Margins</h1>
|
||||
<div class="container large-margin">
|
||||
<div class="content">
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
[].forEach.call(document.querySelectorAll('.container'), function (el) {
|
||||
Ps.initialize(el);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
83
examples/table-content.html
Normal file
83
examples/table-content.html
Normal file
@@ -0,0 +1,83 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#table {
|
||||
font-size: 20px;
|
||||
}
|
||||
#table thead, #table tbody, #table tr {
|
||||
display: block;
|
||||
width: 600px;
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
#table tbody {
|
||||
height: 100px;
|
||||
overflow-y: auto;
|
||||
overflow-x:hidden;
|
||||
position: relative;
|
||||
}
|
||||
#table tbody td, #table thead th {
|
||||
display: block;
|
||||
border: 1px solid black;
|
||||
width: 200px;
|
||||
float: left;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="table" class="wrapper">
|
||||
<table id='table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Age</th>
|
||||
<th>Occupation</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Alex</td>
|
||||
<td>20</td>
|
||||
<td>Student</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Paul</td>
|
||||
<td>23</td>
|
||||
<td>Engineer</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Chris</td>
|
||||
<td>19</td>
|
||||
<td>Human being</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Alex</td>
|
||||
<td>20</td>
|
||||
<td>Student</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Paul</td>
|
||||
<td>23</td>
|
||||
<td>Engineer</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Chris</td>
|
||||
<td>19</td>
|
||||
<td>Human being</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#table tbody'));
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,41 +1,59 @@
|
||||
<!DOCTYPE HTML>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
|
||||
<title>perfect-scrollbar example</title>
|
||||
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script src="../src/perfect-scrollbar.js"></script>
|
||||
<link href="../dist/css/perfect-scrollbar.css" rel="stylesheet">
|
||||
<script src="../dist/js/perfect-scrollbar.js"></script>
|
||||
<style>
|
||||
#description {
|
||||
border: 1px solid gray;
|
||||
height:150px;
|
||||
width: 400px;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function ($) {
|
||||
$('#description').perfectScrollbar();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="description" class="wrapper">
|
||||
<div>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
</div>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
<p>The command takes options applicable</p>
|
||||
</div>
|
||||
<button id='redraw'>Redraw</button>
|
||||
<script>
|
||||
var $ = document.querySelector.bind(document);
|
||||
window.onload = function () {
|
||||
Ps.initialize($('#description'), {
|
||||
useSelectionScroll: true
|
||||
});
|
||||
};
|
||||
$('#redraw').addEventListener('click', function () {
|
||||
var oldHtml = $('#description').innerHTML;
|
||||
$('#description').innerHTML = '';
|
||||
setTimeout(function () {
|
||||
$('#description').innerHTML = '' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>' +
|
||||
'<p>The command takes options applicable</p>';
|
||||
Ps.update($('#description'));
|
||||
}, 500);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
134
gulpfile.js
Normal file
134
gulpfile.js
Normal file
@@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
|
||||
var autoprefixer = require('gulp-autoprefixer');
|
||||
var browserify = require('browserify');
|
||||
var buffer = require('vinyl-buffer');
|
||||
var connect = require('gulp-connect');
|
||||
var del = require('del');
|
||||
var eslint = require('gulp-eslint');
|
||||
var gulp = require('gulp');
|
||||
var insert = require('gulp-insert');
|
||||
var path = require('path');
|
||||
var rename = require('gulp-rename');
|
||||
var sass = require('gulp-sass');
|
||||
var source = require('vinyl-source-stream');
|
||||
var stream = require('event-stream');
|
||||
var uglify = require('gulp-uglify');
|
||||
var zip = require('gulp-zip');
|
||||
|
||||
var version = '/* perfect-scrollbar v' + require('./package').version + ' */\n';
|
||||
|
||||
gulp.task('lint', function () {
|
||||
return gulp.src(['./src/**/*.js', './gulpfile.js'])
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format())
|
||||
.pipe(eslint.failOnError());
|
||||
});
|
||||
|
||||
gulp.task('clean:js', function () {
|
||||
return del(['./dist/js/*.js']);
|
||||
});
|
||||
|
||||
gulp.task('clean:js:min', function () {
|
||||
return del(['./dist/js/*.min.js']);
|
||||
});
|
||||
|
||||
var jsEntries = [
|
||||
'./src/js/adaptor/global.js',
|
||||
'./src/js/adaptor/jquery.js'
|
||||
];
|
||||
|
||||
var autoPrefixerConfig = {
|
||||
browsers: ['> 0%'], // '> 0%' forces autoprefixer to use all the possible prefixes. See https://github.com/ai/browserslist#queries for more details. IMO 'last 3 versions' would be good enough.
|
||||
cascade: false
|
||||
};
|
||||
|
||||
gulp.task('js', ['clean:js'], function () {
|
||||
var tasks = jsEntries.map(function (src) {
|
||||
return browserify([src]).bundle()
|
||||
.pipe(source(path.basename(src)))
|
||||
.pipe(buffer())
|
||||
.pipe(insert.prepend(version))
|
||||
.pipe(rename(function (path) {
|
||||
if (path.basename === 'global') {
|
||||
path.basename = 'perfect-scrollbar';
|
||||
} else {
|
||||
path.basename = 'perfect-scrollbar.' + path.basename;
|
||||
}
|
||||
}))
|
||||
.pipe(gulp.dest('./dist/js'))
|
||||
.pipe(connect.reload());
|
||||
});
|
||||
return stream.merge.apply(null, tasks);
|
||||
});
|
||||
|
||||
gulp.task('js:min', ['clean:js:min'], function () {
|
||||
var tasks = jsEntries.map(function (src) {
|
||||
return browserify([src]).bundle()
|
||||
.pipe(source(path.basename(src)))
|
||||
.pipe(buffer())
|
||||
.pipe(uglify())
|
||||
.pipe(insert.prepend(version))
|
||||
.pipe(rename(function (path) {
|
||||
if (path.basename === 'global') {
|
||||
path.basename = 'perfect-scrollbar.min';
|
||||
} else {
|
||||
path.basename = 'perfect-scrollbar.' + path.basename + '.min';
|
||||
}
|
||||
}))
|
||||
.pipe(gulp.dest('./dist/js'))
|
||||
.pipe(connect.reload());
|
||||
});
|
||||
return stream.merge.apply(null, tasks);
|
||||
});
|
||||
|
||||
gulp.task('clean:css', function () {
|
||||
return del(['./dist/css/perfect-scrollbar.css']);
|
||||
});
|
||||
|
||||
gulp.task('clean:css:min', function () {
|
||||
return del(['./dist/css/perfect-scrollbar.min.css']);
|
||||
});
|
||||
|
||||
gulp.task('css', ['clean:css'], function () {
|
||||
return gulp.src('./src/css/main.scss')
|
||||
.pipe(sass())
|
||||
.pipe(autoprefixer(autoPrefixerConfig))
|
||||
.pipe(insert.prepend(version))
|
||||
.pipe(rename('perfect-scrollbar.css'))
|
||||
.pipe(gulp.dest('./dist/css'))
|
||||
.pipe(connect.reload());
|
||||
});
|
||||
|
||||
gulp.task('css:min', ['clean:css:min'], function () {
|
||||
return gulp.src('./src/css/main.scss')
|
||||
.pipe(sass({outputStyle: 'compressed'}))
|
||||
.pipe(autoprefixer(autoPrefixerConfig))
|
||||
.pipe(insert.prepend(version))
|
||||
.pipe(rename('perfect-scrollbar.min.css'))
|
||||
.pipe(gulp.dest('./dist/css'));
|
||||
});
|
||||
|
||||
gulp.task('build', ['js', 'js:min', 'css', 'css:min']);
|
||||
|
||||
gulp.task('connect', ['build'], function () {
|
||||
connect.server({
|
||||
root: __dirname,
|
||||
livereload: true
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('watch', function () {
|
||||
gulp.watch(['src/js/**/*'], ['js']);
|
||||
gulp.watch(['src/css/**/*'], ['css']);
|
||||
});
|
||||
|
||||
gulp.task('serve', ['connect', 'watch']);
|
||||
|
||||
gulp.task('compress', function () {
|
||||
return gulp.src('./dist/**')
|
||||
.pipe(zip('perfect-scrollbar.zip'))
|
||||
.pipe(gulp.dest('./dist'));
|
||||
});
|
||||
|
||||
gulp.task('default', ['lint', 'build']);
|
||||
3
index.js
Normal file
3
index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./src/js/main');
|
||||
3
jquery.js
vendored
Normal file
3
jquery.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./src/js/adaptor/jquery');
|
||||
5
min/perfect-scrollbar.min.css
vendored
5
min/perfect-scrollbar.min.css
vendored
@@ -1,5 +0,0 @@
|
||||
/*! perfect-scrollbar - v0.5.2
|
||||
* http://noraesae.github.com/perfect-scrollbar/
|
||||
* Copyright (c) 2014 Hyunje Alex Jun; Licensed MIT */
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail{position:absolute;bottom:3px;height:8px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;opacity:0;filter:alpha(opacity=0);-o-transition:background-color .2s linear,opacity .2s linear;-webkit-transition:background-color .2s linear,opacity .2s linear;-moz-transition:background-color .2s linear,opacity .2s linear;transition:background-color .2s linear,opacity .2s linear}.ps-container:hover .ps-scrollbar-x-rail,.ps-container.hover .ps-scrollbar-x-rail{opacity:.6;filter:alpha(opacity=60)}.ps-container .ps-scrollbar-x-rail:hover,.ps-container .ps-scrollbar-x-rail.hover{background-color:#eee;opacity:.9;filter:alpha(opacity=90)}.ps-container .ps-scrollbar-x-rail.in-scrolling{background-color:#eee;opacity:.9;filter:alpha(opacity=90)}.ps-container .ps-scrollbar-y-rail{position:absolute;right:3px;width:8px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;opacity:0;filter:alpha(opacity=0);-o-transition:background-color .2s linear,opacity .2s linear;-webkit-transition:background-color .2s linear,opacity .2s linear;-moz-transition:background-color .2s linear,opacity .2s linear;transition:background-color .2s linear,opacity .2s linear}.ps-container:hover .ps-scrollbar-y-rail,.ps-container.hover .ps-scrollbar-y-rail{opacity:.6;filter:alpha(opacity=60)}.ps-container .ps-scrollbar-y-rail:hover,.ps-container .ps-scrollbar-y-rail.hover{background-color:#eee;opacity:.9;filter:alpha(opacity=90)}.ps-container .ps-scrollbar-y-rail.in-scrolling{background-color:#eee;opacity:.9;filter:alpha(opacity=90)}.ps-container .ps-scrollbar-x{position:absolute;bottom:0;height:8px;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-o-transition:background-color .2s linear;-webkit-transition:background-color.2s linear;-moz-transition:background-color .2s linear;transition:background-color .2s linear}.ps-container.ie6 .ps-scrollbar-x{font-size:0}.ps-container .ps-scrollbar-x-rail:hover .ps-scrollbar-x,.ps-container .ps-scrollbar-x-rail.hover .ps-scrollbar-x{background-color:#999}.ps-container .ps-scrollbar-y{position:absolute;right:0;width:8px;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-o-transition:background-color .2s linear;-webkit-transition:background-color.2s linear;-moz-transition:background-color .2s linear;transition:background-color .2s linear}.ps-container.ie6 .ps-scrollbar-y{font-size:0}.ps-container .ps-scrollbar-y-rail:hover .ps-scrollbar-y,.ps-container .ps-scrollbar-y-rail.hover .ps-scrollbar-y{background-color:#999}.ps-container.ie .ps-scrollbar-x,.ps-container.ie .ps-scrollbar-y{visibility:hidden}.ps-container.ie:hover .ps-scrollbar-x,.ps-container.ie:hover .ps-scrollbar-y,.ps-container.ie.hover .ps-scrollbar-x,.ps-container.ie.hover .ps-scrollbar-y{visibility:visible}
|
||||
4
min/perfect-scrollbar.min.js
vendored
4
min/perfect-scrollbar.min.js
vendored
File diff suppressed because one or more lines are too long
70
package.json
70
package.json
@@ -1,19 +1,67 @@
|
||||
{
|
||||
"name": "perfect-scrollbar",
|
||||
"version": "0.5.2",
|
||||
"main": "src/perfect-scrollbar.js",
|
||||
"version": "0.6.17",
|
||||
"description": "Minimalistic but perfect custom scrollbar plugin",
|
||||
"author": "Hyunje Jun <me@noraesae.net>",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Hyunje Jun",
|
||||
"email": "me@noraesae.net"
|
||||
}
|
||||
],
|
||||
"main": "./index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/noraesae/perfect-scrollbar"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/noraesae/perfect-scrollbar/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"jquery-plugin",
|
||||
"frontend",
|
||||
"scroll",
|
||||
"scrollbar"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
"node": ">= 0.12.0"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"index.js",
|
||||
"jquery.js",
|
||||
"perfect-scrollbar.d.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib-jshint": "~0.1.1",
|
||||
"grunt-contrib-uglify": "~0.1.1",
|
||||
"grunt-contrib-cssmin": "~0.6.1",
|
||||
"grunt-contrib-csslint": "~0.1.2",
|
||||
"grunt-contrib-clean": "~0.4.1"
|
||||
"browserify": "^11.2.0",
|
||||
"del": "^2.0.2",
|
||||
"event-stream": "^3.3.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-autoprefixer": "^3.1.0",
|
||||
"gulp-connect": "^2.2.0",
|
||||
"gulp-eslint": "^1.0.0",
|
||||
"gulp-insert": "^0.5.0",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-sass": "^2.0.4",
|
||||
"gulp-uglify": "^1.4.1",
|
||||
"gulp-zip": "^3.0.2",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0"
|
||||
},
|
||||
"jspm": {
|
||||
"main": "./index.js",
|
||||
"registry": "jspm"
|
||||
},
|
||||
"typings": "perfect-scrollbar.d.ts",
|
||||
"scripts": {
|
||||
"test": "grunt travis --verbose"
|
||||
}
|
||||
"test": "gulp",
|
||||
"before-deploy": "gulp && gulp compress",
|
||||
"release": "rm -rf dist && gulp && npm publish",
|
||||
"bump": "npm version patch",
|
||||
"bump:major": "npm version major",
|
||||
"bump:minor": "npm version minor",
|
||||
"postversion": "git push origin master --follow-tags"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
29
perfect-scrollbar.d.ts
vendored
Normal file
29
perfect-scrollbar.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
interface PerfectScrollbarOptions {
|
||||
wheelSpeed?: number;
|
||||
wheelPropagation?: boolean;
|
||||
swipePropagation?: boolean;
|
||||
minScrollbarLength?: number;
|
||||
maxScrollbarLength?: number;
|
||||
useBothWheelAxes?: boolean;
|
||||
useKeyboard?: boolean;
|
||||
suppressScrollX?: boolean;
|
||||
suppressScrollY?: boolean;
|
||||
scrollXMarginOffset?: number;
|
||||
scrollYMarginOffset?: number;
|
||||
}
|
||||
|
||||
interface PerfectScrollbar {
|
||||
initialize(container: HTMLElement, options?: PerfectScrollbarOptions): void;
|
||||
update(container: HTMLElement): void;
|
||||
destroy(container: HTMLElement): void;
|
||||
}
|
||||
|
||||
interface JQuery {
|
||||
perfectScrollbar(options?: PerfectScrollbarOptions): JQuery;
|
||||
}
|
||||
|
||||
declare var ps: PerfectScrollbar;
|
||||
|
||||
declare module "perfect-scrollbar" {
|
||||
export = ps;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
{
|
||||
"name": "perfect-scrollbar",
|
||||
"title": "perfect-scrollbar",
|
||||
"description": "Tiny but perfect jquery scrollbar plugin.",
|
||||
"version": "0.5.2",
|
||||
"author": {
|
||||
"name": "Hyunje Alex Jun",
|
||||
"email": "me@noraesae.net",
|
||||
"url": "https://github.com/noraesae/"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/noraesae/perfect-scrollbar#license"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"jquery": ">=1.10"
|
||||
},
|
||||
"keywords": [
|
||||
"ui",
|
||||
"scroll",
|
||||
"scrollbar"
|
||||
],
|
||||
"homepage": "http://noraesae.github.com/perfect-scrollbar/",
|
||||
"docs": "https://github.com/noraesae/perfect-scrollbar/",
|
||||
"download": "http://noraesae.github.com/perfect-scrollbar/",
|
||||
"demo": "http://noraesae.github.com/perfect-scrollbar/",
|
||||
"bugs": "https://github.com/noraesae/perfect-scrollbar/issues/",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Hyunje Alex Jun",
|
||||
"email": "me@noraesae.net",
|
||||
"url": "https://github.com/noraesae/"
|
||||
}
|
||||
]
|
||||
}
|
||||
3
src/css/main.scss
Normal file
3
src/css/main.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
@import 'variables';
|
||||
@import 'mixins';
|
||||
@import 'themes';
|
||||
128
src/css/mixins.scss
Normal file
128
src/css/mixins.scss
Normal file
@@ -0,0 +1,128 @@
|
||||
@mixin scrollbar-rail-default($theme) {
|
||||
display: none;
|
||||
position: absolute; /* please don't change 'position' */
|
||||
opacity: map_get($theme, rail-default-opacity);
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
}
|
||||
|
||||
@mixin scrollbar-rail-hover($theme) {
|
||||
background-color: map_get($theme, rail-hover-bg);
|
||||
opacity: map_get($theme, rail-hover-opacity);
|
||||
}
|
||||
|
||||
@mixin scrollbar-default($theme) {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
background-color: map_get($theme, bar-container-hover-bg);
|
||||
border-radius: map_get($theme, border-radius);
|
||||
transition: background-color .2s linear, height .2s linear, width .2s ease-in-out,
|
||||
border-radius .2s ease-in-out;
|
||||
}
|
||||
|
||||
@mixin scrollbar-hover($theme) {
|
||||
background-color: map_get($theme, bar-hover-bg);
|
||||
}
|
||||
|
||||
@mixin in-scrolling($theme) {
|
||||
&.ps-in-scrolling {
|
||||
&.ps-x > .ps-scrollbar-x-rail {
|
||||
@include scrollbar-rail-hover($theme);
|
||||
> .ps-scrollbar-x {
|
||||
@include scrollbar-hover($theme);
|
||||
height: map_get($theme, scrollbar-x-hover-height);
|
||||
}
|
||||
}
|
||||
&.ps-y > .ps-scrollbar-y-rail {
|
||||
@include scrollbar-rail-hover($theme);
|
||||
> .ps-scrollbar-y {
|
||||
@include scrollbar-hover($theme);
|
||||
width: map_get($theme, scrollbar-y-hover-width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Layout and theme mixin
|
||||
@mixin ps-container($theme) {
|
||||
-ms-touch-action: auto;
|
||||
touch-action: auto;
|
||||
overflow: hidden !important;
|
||||
-ms-overflow-style: none;
|
||||
|
||||
// Edge
|
||||
@supports (-ms-overflow-style: none) {
|
||||
overflow: auto !important;
|
||||
}
|
||||
// IE10+
|
||||
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
|
||||
overflow: auto !important;
|
||||
}
|
||||
|
||||
&.ps-active-x > .ps-scrollbar-x-rail,
|
||||
&.ps-active-y > .ps-scrollbar-y-rail {
|
||||
display: block;
|
||||
background-color: map_get($theme, bar-bg);
|
||||
}
|
||||
|
||||
@include in-scrolling($theme);
|
||||
|
||||
> .ps-scrollbar-x-rail {
|
||||
@include scrollbar-rail-default($theme);
|
||||
bottom: map_get($theme, scrollbar-x-rail-bottom); /* there must be 'bottom' for ps-scrollbar-x-rail */
|
||||
height: map_get($theme, scrollbar-x-rail-height);
|
||||
|
||||
> .ps-scrollbar-x {
|
||||
@include scrollbar-default($theme);
|
||||
bottom: map_get($theme, scrollbar-x-bottom); /* there must be 'bottom' for ps-scrollbar-x */
|
||||
height: map_get($theme, scrollbar-x-height);
|
||||
}
|
||||
&:hover,
|
||||
&:active {
|
||||
> .ps-scrollbar-x {
|
||||
height: map_get($theme, scrollbar-x-hover-height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .ps-scrollbar-y-rail {
|
||||
@include scrollbar-rail-default($theme);
|
||||
right: map_get($theme, scrollbar-y-rail-right); /* there must be 'right' for ps-scrollbar-y-rail */
|
||||
width: map_get($theme, scrollbar-y-rail-width);
|
||||
|
||||
> .ps-scrollbar-y {
|
||||
@include scrollbar-default($theme);
|
||||
right: map_get($theme, scrollbar-y-right); /* there must be 'right' for ps-scrollbar-y */
|
||||
width: map_get($theme, scrollbar-y-width);
|
||||
}
|
||||
&:hover,
|
||||
&:active {
|
||||
> .ps-scrollbar-y {
|
||||
width: map_get($theme, scrollbar-y-hover-width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
@include in-scrolling($theme);
|
||||
|
||||
> .ps-scrollbar-x-rail,
|
||||
> .ps-scrollbar-y-rail {
|
||||
opacity: map_get($theme, rail-container-hover-opacity);
|
||||
}
|
||||
|
||||
> .ps-scrollbar-x-rail:hover {
|
||||
@include scrollbar-rail-hover($theme);
|
||||
|
||||
> .ps-scrollbar-x {
|
||||
@include scrollbar-hover($theme);
|
||||
}
|
||||
}
|
||||
|
||||
> .ps-scrollbar-y-rail:hover {
|
||||
@include scrollbar-rail-hover($theme);
|
||||
|
||||
> .ps-scrollbar-y {
|
||||
@include scrollbar-hover($theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/css/themes.scss
Normal file
25
src/css/themes.scss
Normal file
@@ -0,0 +1,25 @@
|
||||
$ps-theme-default: (
|
||||
border-radius: $ps-border-radius,
|
||||
rail-default-opacity: $ps-rail-default-opacity,
|
||||
rail-container-hover-opacity: $ps-rail-container-hover-opacity,
|
||||
rail-hover-opacity: $ps-rail-hover-opacity,
|
||||
bar-bg: $ps-bar-bg,
|
||||
bar-container-hover-bg: $ps-bar-container-hover-bg,
|
||||
bar-hover-bg: $ps-bar-hover-bg,
|
||||
rail-hover-bg: $ps-rail-hover-bg,
|
||||
scrollbar-x-rail-bottom: $ps-scrollbar-x-rail-bottom,
|
||||
scrollbar-x-rail-height: $ps-scrollbar-x-rail-height,
|
||||
scrollbar-x-bottom: $ps-scrollbar-x-bottom,
|
||||
scrollbar-x-height: $ps-scrollbar-x-height,
|
||||
scrollbar-x-hover-height: $ps-scrollbar-x-hover-height,
|
||||
scrollbar-y-rail-right: $ps-scrollbar-y-rail-right,
|
||||
scrollbar-y-rail-width: $ps-scrollbar-y-rail-width,
|
||||
scrollbar-y-right: $ps-scrollbar-y-right,
|
||||
scrollbar-y-width: $ps-scrollbar-y-width,
|
||||
scrollbar-y-hover-width: $ps-scrollbar-y-hover-width,
|
||||
);
|
||||
|
||||
// Default theme
|
||||
.ps-container {
|
||||
@include ps-container($ps-theme-default);
|
||||
}
|
||||
24
src/css/variables.scss
Normal file
24
src/css/variables.scss
Normal file
@@ -0,0 +1,24 @@
|
||||
// Colors
|
||||
$ps-border-radius: 6px !default;
|
||||
|
||||
$ps-rail-default-opacity: 0 !default;
|
||||
$ps-rail-container-hover-opacity: 0.6 !default;
|
||||
$ps-rail-hover-opacity: 0.9 !default;
|
||||
|
||||
$ps-bar-bg: transparent !default;
|
||||
$ps-bar-container-hover-bg: #aaa !default;
|
||||
$ps-bar-hover-bg: #999 !default;
|
||||
$ps-rail-hover-bg: #eee !default;
|
||||
|
||||
// Sizes
|
||||
$ps-scrollbar-x-rail-bottom: 0px !default;
|
||||
$ps-scrollbar-x-rail-height: 15px !default;
|
||||
$ps-scrollbar-x-bottom: 2px !default;
|
||||
$ps-scrollbar-x-height: 6px !default;
|
||||
$ps-scrollbar-x-hover-height: 11px !default;
|
||||
|
||||
$ps-scrollbar-y-rail-right: 0 !default;
|
||||
$ps-scrollbar-y-rail-width: 15px !default;
|
||||
$ps-scrollbar-y-right: 2px !default;
|
||||
$ps-scrollbar-y-width: 6px !default;
|
||||
$ps-scrollbar-y-hover-width: 11px !default;
|
||||
14
src/js/adaptor/global.js
Normal file
14
src/js/adaptor/global.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var ps = require('../main');
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD
|
||||
define(ps);
|
||||
} else {
|
||||
// Add to a global object.
|
||||
window.PerfectScrollbar = ps;
|
||||
if (typeof window.Ps === 'undefined') {
|
||||
window.Ps = ps;
|
||||
}
|
||||
}
|
||||
41
src/js/adaptor/jquery.js
vendored
Normal file
41
src/js/adaptor/jquery.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var ps = require('../main');
|
||||
var psInstances = require('../plugin/instances');
|
||||
|
||||
function mountJQuery(jQuery) {
|
||||
jQuery.fn.perfectScrollbar = function (settingOrCommand) {
|
||||
return this.each(function () {
|
||||
if (typeof settingOrCommand === 'object' ||
|
||||
typeof settingOrCommand === 'undefined') {
|
||||
// If it's an object or none, initialize.
|
||||
var settings = settingOrCommand;
|
||||
|
||||
if (!psInstances.get(this)) {
|
||||
ps.initialize(this, settings);
|
||||
}
|
||||
} else {
|
||||
// Unless, it may be a command.
|
||||
var command = settingOrCommand;
|
||||
|
||||
if (command === 'update') {
|
||||
ps.update(this);
|
||||
} else if (command === 'destroy') {
|
||||
ps.destroy(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], mountJQuery);
|
||||
} else {
|
||||
var jq = window.jQuery ? window.jQuery : window.$;
|
||||
if (typeof jq !== 'undefined') {
|
||||
mountJQuery(jq);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = mountJQuery;
|
||||
42
src/js/lib/class.js
Normal file
42
src/js/lib/class.js
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
function oldAdd(element, className) {
|
||||
var classes = element.className.split(' ');
|
||||
if (classes.indexOf(className) < 0) {
|
||||
classes.push(className);
|
||||
}
|
||||
element.className = classes.join(' ');
|
||||
}
|
||||
|
||||
function oldRemove(element, className) {
|
||||
var classes = element.className.split(' ');
|
||||
var idx = classes.indexOf(className);
|
||||
if (idx >= 0) {
|
||||
classes.splice(idx, 1);
|
||||
}
|
||||
element.className = classes.join(' ');
|
||||
}
|
||||
|
||||
exports.add = function (element, className) {
|
||||
if (element.classList) {
|
||||
element.classList.add(className);
|
||||
} else {
|
||||
oldAdd(element, className);
|
||||
}
|
||||
};
|
||||
|
||||
exports.remove = function (element, className) {
|
||||
if (element.classList) {
|
||||
element.classList.remove(className);
|
||||
} else {
|
||||
oldRemove(element, className);
|
||||
}
|
||||
};
|
||||
|
||||
exports.list = function (element) {
|
||||
if (element.classList) {
|
||||
return Array.prototype.slice.apply(element.classList);
|
||||
} else {
|
||||
return element.className.split(' ');
|
||||
}
|
||||
};
|
||||
87
src/js/lib/dom.js
Normal file
87
src/js/lib/dom.js
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
var DOM = {};
|
||||
|
||||
DOM.e = function (tagName, className) {
|
||||
var element = document.createElement(tagName);
|
||||
element.className = className;
|
||||
return element;
|
||||
};
|
||||
|
||||
DOM.appendTo = function (child, parent) {
|
||||
parent.appendChild(child);
|
||||
return child;
|
||||
};
|
||||
|
||||
function cssGet(element, styleName) {
|
||||
var style = window.getComputedStyle(element);
|
||||
return style
|
||||
? style[styleName]
|
||||
: null;
|
||||
}
|
||||
|
||||
function cssSet(element, styleName, styleValue) {
|
||||
if (typeof styleValue === 'number') {
|
||||
styleValue = styleValue.toString() + 'px';
|
||||
}
|
||||
element.style[styleName] = styleValue;
|
||||
return element;
|
||||
}
|
||||
|
||||
function cssMultiSet(element, obj) {
|
||||
for (var key in obj) {
|
||||
var val = obj[key];
|
||||
if (typeof val === 'number') {
|
||||
val = val.toString() + 'px';
|
||||
}
|
||||
element.style[key] = val;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
DOM.css = function (element, styleNameOrObject, styleValue) {
|
||||
if (typeof styleNameOrObject === 'object') {
|
||||
// multiple set with object
|
||||
return cssMultiSet(element, styleNameOrObject);
|
||||
} else {
|
||||
if (typeof styleValue === 'undefined') {
|
||||
return cssGet(element, styleNameOrObject);
|
||||
} else {
|
||||
return cssSet(element, styleNameOrObject, styleValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DOM.matches = function (element, query) {
|
||||
if (typeof element.matches !== 'undefined') {
|
||||
return element.matches(query);
|
||||
} else {
|
||||
if (typeof element.matchesSelector !== 'undefined') {
|
||||
return element.matchesSelector(query);
|
||||
} else if (typeof element.webkitMatchesSelector !== 'undefined') {
|
||||
return element.webkitMatchesSelector(query);
|
||||
} else if (typeof element.mozMatchesSelector !== 'undefined') {
|
||||
return element.mozMatchesSelector(query);
|
||||
} else if (typeof element.msMatchesSelector !== 'undefined') {
|
||||
return element.msMatchesSelector(query);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DOM.remove = function (element) {
|
||||
if (typeof element.remove !== 'undefined') {
|
||||
element.remove();
|
||||
} else {
|
||||
if (element.parentNode) {
|
||||
element.parentNode.removeChild(element);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DOM.queryChildren = function (element, selector) {
|
||||
return Array.prototype.filter.call(element.childNodes, function (child) {
|
||||
return DOM.matches(child, selector);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = DOM;
|
||||
71
src/js/lib/event-manager.js
Normal file
71
src/js/lib/event-manager.js
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var EventElement = function (element) {
|
||||
this.element = element;
|
||||
this.events = {};
|
||||
};
|
||||
|
||||
EventElement.prototype.bind = function (eventName, handler) {
|
||||
if (typeof this.events[eventName] === 'undefined') {
|
||||
this.events[eventName] = [];
|
||||
}
|
||||
this.events[eventName].push(handler);
|
||||
this.element.addEventListener(eventName, handler, false);
|
||||
};
|
||||
|
||||
EventElement.prototype.unbind = function (eventName, handler) {
|
||||
var isHandlerProvided = (typeof handler !== 'undefined');
|
||||
this.events[eventName] = this.events[eventName].filter(function (hdlr) {
|
||||
if (isHandlerProvided && hdlr !== handler) {
|
||||
return true;
|
||||
}
|
||||
this.element.removeEventListener(eventName, hdlr, false);
|
||||
return false;
|
||||
}, this);
|
||||
};
|
||||
|
||||
EventElement.prototype.unbindAll = function () {
|
||||
for (var name in this.events) {
|
||||
this.unbind(name);
|
||||
}
|
||||
};
|
||||
|
||||
var EventManager = function () {
|
||||
this.eventElements = [];
|
||||
};
|
||||
|
||||
EventManager.prototype.eventElement = function (element) {
|
||||
var ee = this.eventElements.filter(function (eventElement) {
|
||||
return eventElement.element === element;
|
||||
})[0];
|
||||
if (typeof ee === 'undefined') {
|
||||
ee = new EventElement(element);
|
||||
this.eventElements.push(ee);
|
||||
}
|
||||
return ee;
|
||||
};
|
||||
|
||||
EventManager.prototype.bind = function (element, eventName, handler) {
|
||||
this.eventElement(element).bind(eventName, handler);
|
||||
};
|
||||
|
||||
EventManager.prototype.unbind = function (element, eventName, handler) {
|
||||
this.eventElement(element).unbind(eventName, handler);
|
||||
};
|
||||
|
||||
EventManager.prototype.unbindAll = function () {
|
||||
for (var i = 0; i < this.eventElements.length; i++) {
|
||||
this.eventElements[i].unbindAll();
|
||||
}
|
||||
};
|
||||
|
||||
EventManager.prototype.once = function (element, eventName, handler) {
|
||||
var ee = this.eventElement(element);
|
||||
var onceHandler = function (e) {
|
||||
ee.unbind(eventName, onceHandler);
|
||||
handler(e);
|
||||
};
|
||||
ee.bind(eventName, onceHandler);
|
||||
};
|
||||
|
||||
module.exports = EventManager;
|
||||
13
src/js/lib/guid.js
Normal file
13
src/js/lib/guid.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (function () {
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
return function () {
|
||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
||||
s4() + '-' + s4() + s4() + s4();
|
||||
};
|
||||
})();
|
||||
103
src/js/lib/helper.js
Normal file
103
src/js/lib/helper.js
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict';
|
||||
|
||||
var cls = require('./class');
|
||||
var dom = require('./dom');
|
||||
|
||||
var toInt = exports.toInt = function (x) {
|
||||
return parseInt(x, 10) || 0;
|
||||
};
|
||||
|
||||
var clone = exports.clone = function (obj) {
|
||||
if (!obj) {
|
||||
return null;
|
||||
} else if (Array.isArray(obj)) {
|
||||
return obj.map(clone);
|
||||
} else if (typeof obj === 'object') {
|
||||
var result = {};
|
||||
for (var key in obj) {
|
||||
result[key] = clone(obj[key]);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
exports.debounce = function (func, wait, immediate) {
|
||||
var timeout;
|
||||
return function () {
|
||||
var context = this;
|
||||
var args = arguments;
|
||||
var later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.extend = function (original, source) {
|
||||
var result = clone(original);
|
||||
for (var key in source) {
|
||||
result[key] = clone(source[key]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.isEditable = function (el) {
|
||||
return dom.matches(el, "input,[contenteditable]") ||
|
||||
dom.matches(el, "select,[contenteditable]") ||
|
||||
dom.matches(el, "textarea,[contenteditable]") ||
|
||||
dom.matches(el, "button,[contenteditable]");
|
||||
};
|
||||
|
||||
exports.removePsClasses = function (element) {
|
||||
var clsList = cls.list(element);
|
||||
for (var i = 0; i < clsList.length; i++) {
|
||||
var className = clsList[i];
|
||||
if (className.indexOf('ps-') === 0) {
|
||||
cls.remove(element, className);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.outerWidth = function (element) {
|
||||
return toInt(dom.css(element, 'width')) +
|
||||
toInt(dom.css(element, 'paddingLeft')) +
|
||||
toInt(dom.css(element, 'paddingRight')) +
|
||||
toInt(dom.css(element, 'borderLeftWidth')) +
|
||||
toInt(dom.css(element, 'borderRightWidth'));
|
||||
};
|
||||
|
||||
exports.startScrolling = function (element, axis) {
|
||||
cls.add(element, 'ps-in-scrolling');
|
||||
if (typeof axis !== 'undefined') {
|
||||
cls.add(element, 'ps-' + axis);
|
||||
} else {
|
||||
cls.add(element, 'ps-x');
|
||||
cls.add(element, 'ps-y');
|
||||
}
|
||||
};
|
||||
|
||||
exports.stopScrolling = function (element, axis) {
|
||||
cls.remove(element, 'ps-in-scrolling');
|
||||
if (typeof axis !== 'undefined') {
|
||||
cls.remove(element, 'ps-' + axis);
|
||||
} else {
|
||||
cls.remove(element, 'ps-x');
|
||||
cls.remove(element, 'ps-y');
|
||||
}
|
||||
};
|
||||
|
||||
exports.env = {
|
||||
isWebKit: 'WebkitAppearance' in document.documentElement.style,
|
||||
supportsTouch: (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch),
|
||||
supportsIePointer: window.navigator.msMaxTouchPoints !== null
|
||||
};
|
||||
11
src/js/main.js
Normal file
11
src/js/main.js
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var destroy = require('./plugin/destroy');
|
||||
var initialize = require('./plugin/initialize');
|
||||
var update = require('./plugin/update');
|
||||
|
||||
module.exports = {
|
||||
initialize: initialize,
|
||||
update: update,
|
||||
destroy: destroy
|
||||
};
|
||||
30
src/js/plugin/autoupdate.js
Normal file
30
src/js/plugin/autoupdate.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var update = require('./update');
|
||||
var MutationObserver = window.MutationObserver;
|
||||
var instances = require('./instances');
|
||||
|
||||
var createDOMEvent = function (name) {
|
||||
var event = document.createEvent('Event');
|
||||
event.initEvent(name, true, true);
|
||||
return event;
|
||||
};
|
||||
|
||||
module.exports = function (element) {
|
||||
if (MutationObserver === null || MutationObserver === undefined) {
|
||||
// MutationObserver is not supported
|
||||
return;
|
||||
}
|
||||
|
||||
var i = instances.get(element);
|
||||
var onMutationObserver = function () {
|
||||
update(element);
|
||||
element.dispatchEvent(createDOMEvent('ps-dom-change'));
|
||||
};
|
||||
|
||||
i.observer = new MutationObserver(onMutationObserver);
|
||||
onMutationObserver();
|
||||
|
||||
var config = { childList: true, subtree: true };
|
||||
i.observer.observe(element, config);
|
||||
};
|
||||
17
src/js/plugin/default-setting.js
Normal file
17
src/js/plugin/default-setting.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
handlers: ['click-rail', 'drag-scrollbar', 'keyboard', 'wheel', 'touch'],
|
||||
maxScrollbarLength: null,
|
||||
minScrollbarLength: null,
|
||||
scrollXMarginOffset: 0,
|
||||
scrollYMarginOffset: 0,
|
||||
suppressScrollX: false,
|
||||
suppressScrollY: false,
|
||||
swipePropagation: true,
|
||||
useBothWheelAxes: false,
|
||||
wheelPropagation: false,
|
||||
wheelSpeed: 1,
|
||||
theme: 'default',
|
||||
autoupdate: true
|
||||
};
|
||||
26
src/js/plugin/destroy.js
Normal file
26
src/js/plugin/destroy.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../lib/helper');
|
||||
var dom = require('../lib/dom');
|
||||
var instances = require('./instances');
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
|
||||
if (!i) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (i.observer) {
|
||||
i.observer.disconnect();
|
||||
}
|
||||
|
||||
i.event.unbindAll();
|
||||
dom.remove(i.scrollbarX);
|
||||
dom.remove(i.scrollbarY);
|
||||
dom.remove(i.scrollbarXRail);
|
||||
dom.remove(i.scrollbarYRail);
|
||||
_.removePsClasses(element);
|
||||
|
||||
instances.remove(element);
|
||||
};
|
||||
39
src/js/plugin/handler/click-rail.js
Normal file
39
src/js/plugin/handler/click-rail.js
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindClickRailHandler(element, i) {
|
||||
function pageOffset(el) {
|
||||
return el.getBoundingClientRect();
|
||||
}
|
||||
var stopPropagation = function (e) { e.stopPropagation(); };
|
||||
|
||||
i.event.bind(i.scrollbarY, 'click', stopPropagation);
|
||||
i.event.bind(i.scrollbarYRail, 'click', function (e) {
|
||||
var positionTop = e.pageY - window.pageYOffset - pageOffset(i.scrollbarYRail).top;
|
||||
var direction = positionTop > i.scrollbarYTop ? 1 : -1;
|
||||
|
||||
updateScroll(element, 'top', element.scrollTop + direction * i.containerHeight);
|
||||
updateGeometry(element);
|
||||
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
i.event.bind(i.scrollbarX, 'click', stopPropagation);
|
||||
i.event.bind(i.scrollbarXRail, 'click', function (e) {
|
||||
var positionLeft = e.pageX - window.pageXOffset - pageOffset(i.scrollbarXRail).left;
|
||||
var direction = positionLeft > i.scrollbarXLeft ? 1 : -1;
|
||||
|
||||
updateScroll(element, 'left', element.scrollLeft + direction * i.containerWidth);
|
||||
updateGeometry(element);
|
||||
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindClickRailHandler(element, i);
|
||||
};
|
||||
103
src/js/plugin/handler/drag-scrollbar.js
Normal file
103
src/js/plugin/handler/drag-scrollbar.js
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../../lib/helper');
|
||||
var dom = require('../../lib/dom');
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindMouseScrollXHandler(element, i) {
|
||||
var currentLeft = null;
|
||||
var currentPageX = null;
|
||||
|
||||
function updateScrollLeft(deltaX) {
|
||||
var newLeft = currentLeft + (deltaX * i.railXRatio);
|
||||
var maxLeft = Math.max(0, i.scrollbarXRail.getBoundingClientRect().left) + (i.railXRatio * (i.railXWidth - i.scrollbarXWidth));
|
||||
|
||||
if (newLeft < 0) {
|
||||
i.scrollbarXLeft = 0;
|
||||
} else if (newLeft > maxLeft) {
|
||||
i.scrollbarXLeft = maxLeft;
|
||||
} else {
|
||||
i.scrollbarXLeft = newLeft;
|
||||
}
|
||||
|
||||
var scrollLeft = _.toInt(i.scrollbarXLeft * (i.contentWidth - i.containerWidth) / (i.containerWidth - (i.railXRatio * i.scrollbarXWidth))) - i.negativeScrollAdjustment;
|
||||
updateScroll(element, 'left', scrollLeft);
|
||||
}
|
||||
|
||||
var mouseMoveHandler = function (e) {
|
||||
updateScrollLeft(e.pageX - currentPageX);
|
||||
updateGeometry(element);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
var mouseUpHandler = function () {
|
||||
_.stopScrolling(element, 'x');
|
||||
i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
|
||||
};
|
||||
|
||||
i.event.bind(i.scrollbarX, 'mousedown', function (e) {
|
||||
currentPageX = e.pageX;
|
||||
currentLeft = _.toInt(dom.css(i.scrollbarX, 'left')) * i.railXRatio;
|
||||
_.startScrolling(element, 'x');
|
||||
|
||||
i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
|
||||
i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
function bindMouseScrollYHandler(element, i) {
|
||||
var currentTop = null;
|
||||
var currentPageY = null;
|
||||
|
||||
function updateScrollTop(deltaY) {
|
||||
var newTop = currentTop + (deltaY * i.railYRatio);
|
||||
var maxTop = Math.max(0, i.scrollbarYRail.getBoundingClientRect().top) + (i.railYRatio * (i.railYHeight - i.scrollbarYHeight));
|
||||
|
||||
if (newTop < 0) {
|
||||
i.scrollbarYTop = 0;
|
||||
} else if (newTop > maxTop) {
|
||||
i.scrollbarYTop = maxTop;
|
||||
} else {
|
||||
i.scrollbarYTop = newTop;
|
||||
}
|
||||
|
||||
var scrollTop = _.toInt(i.scrollbarYTop * (i.contentHeight - i.containerHeight) / (i.containerHeight - (i.railYRatio * i.scrollbarYHeight)));
|
||||
updateScroll(element, 'top', scrollTop);
|
||||
}
|
||||
|
||||
var mouseMoveHandler = function (e) {
|
||||
updateScrollTop(e.pageY - currentPageY);
|
||||
updateGeometry(element);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
var mouseUpHandler = function () {
|
||||
_.stopScrolling(element, 'y');
|
||||
i.event.unbind(i.ownerDocument, 'mousemove', mouseMoveHandler);
|
||||
};
|
||||
|
||||
i.event.bind(i.scrollbarY, 'mousedown', function (e) {
|
||||
currentPageY = e.pageY;
|
||||
currentTop = _.toInt(dom.css(i.scrollbarY, 'top')) * i.railYRatio;
|
||||
_.startScrolling(element, 'y');
|
||||
|
||||
i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
|
||||
i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
|
||||
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindMouseScrollXHandler(element, i);
|
||||
bindMouseScrollYHandler(element, i);
|
||||
};
|
||||
154
src/js/plugin/handler/keyboard.js
Normal file
154
src/js/plugin/handler/keyboard.js
Normal file
@@ -0,0 +1,154 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../../lib/helper');
|
||||
var dom = require('../../lib/dom');
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindKeyboardHandler(element, i) {
|
||||
var hovered = false;
|
||||
i.event.bind(element, 'mouseenter', function () {
|
||||
hovered = true;
|
||||
});
|
||||
i.event.bind(element, 'mouseleave', function () {
|
||||
hovered = false;
|
||||
});
|
||||
|
||||
var shouldPrevent = false;
|
||||
function shouldPreventDefault(deltaX, deltaY) {
|
||||
var scrollTop = element.scrollTop;
|
||||
if (deltaX === 0) {
|
||||
if (!i.scrollbarYActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
|
||||
return !i.settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollLeft = element.scrollLeft;
|
||||
if (deltaY === 0) {
|
||||
if (!i.scrollbarXActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
|
||||
return !i.settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
i.event.bind(i.ownerDocument, 'keydown', function (e) {
|
||||
if ((e.isDefaultPrevented && e.isDefaultPrevented()) || e.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
var focused = dom.matches(i.scrollbarX, ':focus') ||
|
||||
dom.matches(i.scrollbarY, ':focus');
|
||||
|
||||
if (!hovered && !focused) {
|
||||
return;
|
||||
}
|
||||
|
||||
var activeElement = document.activeElement ? document.activeElement : i.ownerDocument.activeElement;
|
||||
if (activeElement) {
|
||||
if (activeElement.tagName === 'IFRAME') {
|
||||
activeElement = activeElement.contentDocument.activeElement;
|
||||
} else {
|
||||
// go deeper if element is a webcomponent
|
||||
while (activeElement.shadowRoot) {
|
||||
activeElement = activeElement.shadowRoot.activeElement;
|
||||
}
|
||||
}
|
||||
if (_.isEditable(activeElement)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var deltaX = 0;
|
||||
var deltaY = 0;
|
||||
|
||||
switch (e.which) {
|
||||
case 37: // left
|
||||
if (e.metaKey) {
|
||||
deltaX = -i.contentWidth;
|
||||
} else if (e.altKey) {
|
||||
deltaX = -i.containerWidth;
|
||||
} else {
|
||||
deltaX = -30;
|
||||
}
|
||||
break;
|
||||
case 38: // up
|
||||
if (e.metaKey) {
|
||||
deltaY = i.contentHeight;
|
||||
} else if (e.altKey) {
|
||||
deltaY = i.containerHeight;
|
||||
} else {
|
||||
deltaY = 30;
|
||||
}
|
||||
break;
|
||||
case 39: // right
|
||||
if (e.metaKey) {
|
||||
deltaX = i.contentWidth;
|
||||
} else if (e.altKey) {
|
||||
deltaX = i.containerWidth;
|
||||
} else {
|
||||
deltaX = 30;
|
||||
}
|
||||
break;
|
||||
case 40: // down
|
||||
if (e.metaKey) {
|
||||
deltaY = -i.contentHeight;
|
||||
} else if (e.altKey) {
|
||||
deltaY = -i.containerHeight;
|
||||
} else {
|
||||
deltaY = -30;
|
||||
}
|
||||
break;
|
||||
case 33: // page up
|
||||
deltaY = 90;
|
||||
break;
|
||||
case 32: // space bar
|
||||
if (e.shiftKey) {
|
||||
deltaY = 90;
|
||||
} else {
|
||||
deltaY = -90;
|
||||
}
|
||||
break;
|
||||
case 34: // page down
|
||||
deltaY = -90;
|
||||
break;
|
||||
case 35: // end
|
||||
if (e.ctrlKey) {
|
||||
deltaY = -i.contentHeight;
|
||||
} else {
|
||||
deltaY = -i.containerHeight;
|
||||
}
|
||||
break;
|
||||
case 36: // home
|
||||
if (e.ctrlKey) {
|
||||
deltaY = element.scrollTop;
|
||||
} else {
|
||||
deltaY = i.containerHeight;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
updateScroll(element, 'top', element.scrollTop - deltaY);
|
||||
updateScroll(element, 'left', element.scrollLeft + deltaX);
|
||||
updateGeometry(element);
|
||||
|
||||
shouldPrevent = shouldPreventDefault(deltaX, deltaY);
|
||||
if (shouldPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindKeyboardHandler(element, i);
|
||||
};
|
||||
141
src/js/plugin/handler/mouse-wheel.js
Normal file
141
src/js/plugin/handler/mouse-wheel.js
Normal file
@@ -0,0 +1,141 @@
|
||||
'use strict';
|
||||
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindMouseWheelHandler(element, i) {
|
||||
var shouldPrevent = false;
|
||||
|
||||
function shouldPreventDefault(deltaX, deltaY) {
|
||||
var scrollTop = element.scrollTop;
|
||||
if (deltaX === 0) {
|
||||
if (!i.scrollbarYActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= i.contentHeight - i.containerHeight && deltaY < 0)) {
|
||||
return !i.settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollLeft = element.scrollLeft;
|
||||
if (deltaY === 0) {
|
||||
if (!i.scrollbarXActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= i.contentWidth - i.containerWidth && deltaX > 0)) {
|
||||
return !i.settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDeltaFromEvent(e) {
|
||||
var deltaX = e.deltaX;
|
||||
var deltaY = -1 * e.deltaY;
|
||||
|
||||
if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
|
||||
// OS X Safari
|
||||
deltaX = -1 * e.wheelDeltaX / 6;
|
||||
deltaY = e.wheelDeltaY / 6;
|
||||
}
|
||||
|
||||
if (e.deltaMode && e.deltaMode === 1) {
|
||||
// Firefox in deltaMode 1: Line scrolling
|
||||
deltaX *= 10;
|
||||
deltaY *= 10;
|
||||
}
|
||||
|
||||
if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
|
||||
// IE in some mouse drivers
|
||||
deltaX = 0;
|
||||
deltaY = e.wheelDelta;
|
||||
}
|
||||
|
||||
if (e.shiftKey) {
|
||||
// reverse axis with shift key
|
||||
return [-deltaY, -deltaX];
|
||||
}
|
||||
return [deltaX, deltaY];
|
||||
}
|
||||
|
||||
function shouldBeConsumedByChild(deltaX, deltaY) {
|
||||
var child = element.querySelector('textarea:hover, select[multiple]:hover, .ps-child:hover');
|
||||
if (child) {
|
||||
if (!window.getComputedStyle(child).overflow.match(/(scroll|auto)/)) {
|
||||
// if not scrollable
|
||||
return false;
|
||||
}
|
||||
|
||||
var maxScrollTop = child.scrollHeight - child.clientHeight;
|
||||
if (maxScrollTop > 0) {
|
||||
if (!(child.scrollTop === 0 && deltaY > 0) && !(child.scrollTop === maxScrollTop && deltaY < 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
var maxScrollLeft = child.scrollLeft - child.clientWidth;
|
||||
if (maxScrollLeft > 0) {
|
||||
if (!(child.scrollLeft === 0 && deltaX < 0) && !(child.scrollLeft === maxScrollLeft && deltaX > 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function mousewheelHandler(e) {
|
||||
var delta = getDeltaFromEvent(e);
|
||||
|
||||
var deltaX = delta[0];
|
||||
var deltaY = delta[1];
|
||||
|
||||
if (shouldBeConsumedByChild(deltaX, deltaY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
shouldPrevent = false;
|
||||
if (!i.settings.useBothWheelAxes) {
|
||||
// deltaX will only be used for horizontal scrolling and deltaY will
|
||||
// only be used for vertical scrolling - this is the default
|
||||
updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
|
||||
updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
|
||||
} else if (i.scrollbarYActive && !i.scrollbarXActive) {
|
||||
// only vertical scrollbar is active and useBothWheelAxes option is
|
||||
// active, so let's scroll vertical bar using both mouse wheel axes
|
||||
if (deltaY) {
|
||||
updateScroll(element, 'top', element.scrollTop - (deltaY * i.settings.wheelSpeed));
|
||||
} else {
|
||||
updateScroll(element, 'top', element.scrollTop + (deltaX * i.settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
} else if (i.scrollbarXActive && !i.scrollbarYActive) {
|
||||
// useBothWheelAxes and only horizontal bar is active, so use both
|
||||
// wheel axes for horizontal bar
|
||||
if (deltaX) {
|
||||
updateScroll(element, 'left', element.scrollLeft + (deltaX * i.settings.wheelSpeed));
|
||||
} else {
|
||||
updateScroll(element, 'left', element.scrollLeft - (deltaY * i.settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
}
|
||||
|
||||
updateGeometry(element);
|
||||
|
||||
shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
|
||||
if (shouldPrevent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window.onwheel !== "undefined") {
|
||||
i.event.bind(element, 'wheel', mousewheelHandler);
|
||||
} else if (typeof window.onmousewheel !== "undefined") {
|
||||
i.event.bind(element, 'mousewheel', mousewheelHandler);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindMouseWheelHandler(element, i);
|
||||
};
|
||||
15
src/js/plugin/handler/native-scroll.js
Normal file
15
src/js/plugin/handler/native-scroll.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
|
||||
function bindNativeScrollHandler(element, i) {
|
||||
i.event.bind(element, 'scroll', function () {
|
||||
updateGeometry(element);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindNativeScrollHandler(element, i);
|
||||
};
|
||||
115
src/js/plugin/handler/selection.js
Normal file
115
src/js/plugin/handler/selection.js
Normal file
@@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../../lib/helper');
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindSelectionHandler(element, i) {
|
||||
function getRangeNode() {
|
||||
var selection = window.getSelection ? window.getSelection() :
|
||||
document.getSelection ? document.getSelection() : '';
|
||||
if (selection.toString().length === 0) {
|
||||
return null;
|
||||
} else {
|
||||
return selection.getRangeAt(0).commonAncestorContainer;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollingLoop = null;
|
||||
var scrollDiff = {top: 0, left: 0};
|
||||
function startScrolling() {
|
||||
if (!scrollingLoop) {
|
||||
scrollingLoop = setInterval(function () {
|
||||
if (!instances.get(element)) {
|
||||
clearInterval(scrollingLoop);
|
||||
return;
|
||||
}
|
||||
|
||||
updateScroll(element, 'top', element.scrollTop + scrollDiff.top);
|
||||
updateScroll(element, 'left', element.scrollLeft + scrollDiff.left);
|
||||
updateGeometry(element);
|
||||
}, 50); // every .1 sec
|
||||
}
|
||||
}
|
||||
function stopScrolling() {
|
||||
if (scrollingLoop) {
|
||||
clearInterval(scrollingLoop);
|
||||
scrollingLoop = null;
|
||||
}
|
||||
_.stopScrolling(element);
|
||||
}
|
||||
|
||||
var isSelected = false;
|
||||
i.event.bind(i.ownerDocument, 'selectionchange', function () {
|
||||
if (element.contains(getRangeNode())) {
|
||||
isSelected = true;
|
||||
} else {
|
||||
isSelected = false;
|
||||
stopScrolling();
|
||||
}
|
||||
});
|
||||
i.event.bind(window, 'mouseup', function () {
|
||||
if (isSelected) {
|
||||
isSelected = false;
|
||||
stopScrolling();
|
||||
}
|
||||
});
|
||||
i.event.bind(window, 'keyup', function () {
|
||||
if (isSelected) {
|
||||
isSelected = false;
|
||||
stopScrolling();
|
||||
}
|
||||
});
|
||||
|
||||
i.event.bind(window, 'mousemove', function (e) {
|
||||
if (isSelected) {
|
||||
var mousePosition = {x: e.pageX, y: e.pageY};
|
||||
var containerGeometry = {
|
||||
left: element.offsetLeft,
|
||||
right: element.offsetLeft + element.offsetWidth,
|
||||
top: element.offsetTop,
|
||||
bottom: element.offsetTop + element.offsetHeight
|
||||
};
|
||||
|
||||
if (mousePosition.x < containerGeometry.left + 3) {
|
||||
scrollDiff.left = -5;
|
||||
_.startScrolling(element, 'x');
|
||||
} else if (mousePosition.x > containerGeometry.right - 3) {
|
||||
scrollDiff.left = 5;
|
||||
_.startScrolling(element, 'x');
|
||||
} else {
|
||||
scrollDiff.left = 0;
|
||||
}
|
||||
|
||||
if (mousePosition.y < containerGeometry.top + 3) {
|
||||
if (containerGeometry.top + 3 - mousePosition.y < 5) {
|
||||
scrollDiff.top = -5;
|
||||
} else {
|
||||
scrollDiff.top = -20;
|
||||
}
|
||||
_.startScrolling(element, 'y');
|
||||
} else if (mousePosition.y > containerGeometry.bottom - 3) {
|
||||
if (mousePosition.y - containerGeometry.bottom + 3 < 5) {
|
||||
scrollDiff.top = 5;
|
||||
} else {
|
||||
scrollDiff.top = 20;
|
||||
}
|
||||
_.startScrolling(element, 'y');
|
||||
} else {
|
||||
scrollDiff.top = 0;
|
||||
}
|
||||
|
||||
if (scrollDiff.top === 0 && scrollDiff.left === 0) {
|
||||
stopScrolling();
|
||||
} else {
|
||||
startScrolling();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
bindSelectionHandler(element, i);
|
||||
};
|
||||
184
src/js/plugin/handler/touch.js
Normal file
184
src/js/plugin/handler/touch.js
Normal file
@@ -0,0 +1,184 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../../lib/helper');
|
||||
var instances = require('../instances');
|
||||
var updateGeometry = require('../update-geometry');
|
||||
var updateScroll = require('../update-scroll');
|
||||
|
||||
function bindTouchHandler(element, i, supportsTouch, supportsIePointer) {
|
||||
function shouldPreventDefault(deltaX, deltaY) {
|
||||
var scrollTop = element.scrollTop;
|
||||
var scrollLeft = element.scrollLeft;
|
||||
var magnitudeX = Math.abs(deltaX);
|
||||
var magnitudeY = Math.abs(deltaY);
|
||||
|
||||
if (magnitudeY > magnitudeX) {
|
||||
// user is perhaps trying to swipe up/down the page
|
||||
|
||||
if (((deltaY < 0) && (scrollTop === i.contentHeight - i.containerHeight)) ||
|
||||
((deltaY > 0) && (scrollTop === 0))) {
|
||||
return !i.settings.swipePropagation;
|
||||
}
|
||||
} else if (magnitudeX > magnitudeY) {
|
||||
// user is perhaps trying to swipe left/right across the page
|
||||
|
||||
if (((deltaX < 0) && (scrollLeft === i.contentWidth - i.containerWidth)) ||
|
||||
((deltaX > 0) && (scrollLeft === 0))) {
|
||||
return !i.settings.swipePropagation;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function applyTouchMove(differenceX, differenceY) {
|
||||
updateScroll(element, 'top', element.scrollTop - differenceY);
|
||||
updateScroll(element, 'left', element.scrollLeft - differenceX);
|
||||
|
||||
updateGeometry(element);
|
||||
}
|
||||
|
||||
var startOffset = {};
|
||||
var startTime = 0;
|
||||
var speed = {};
|
||||
var easingLoop = null;
|
||||
var inGlobalTouch = false;
|
||||
var inLocalTouch = false;
|
||||
|
||||
function globalTouchStart() {
|
||||
inGlobalTouch = true;
|
||||
}
|
||||
function globalTouchEnd() {
|
||||
inGlobalTouch = false;
|
||||
}
|
||||
|
||||
function getTouch(e) {
|
||||
if (e.targetTouches) {
|
||||
return e.targetTouches[0];
|
||||
} else {
|
||||
// Maybe IE pointer
|
||||
return e;
|
||||
}
|
||||
}
|
||||
function shouldHandle(e) {
|
||||
if (e.targetTouches && e.targetTouches.length === 1) {
|
||||
return true;
|
||||
}
|
||||
if (e.pointerType && e.pointerType !== 'mouse' && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function touchStart(e) {
|
||||
if (shouldHandle(e)) {
|
||||
inLocalTouch = true;
|
||||
|
||||
var touch = getTouch(e);
|
||||
|
||||
startOffset.pageX = touch.pageX;
|
||||
startOffset.pageY = touch.pageY;
|
||||
|
||||
startTime = (new Date()).getTime();
|
||||
|
||||
if (easingLoop !== null) {
|
||||
clearInterval(easingLoop);
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
function touchMove(e) {
|
||||
var target = e.target;
|
||||
var className = target && target.getAttribute && target.getAttribute('class') || '';
|
||||
|
||||
if (!className.match(/ps-prevent-touchmove/)) {
|
||||
if (!inLocalTouch && i.settings.swipePropagation) {
|
||||
touchStart(e);
|
||||
}
|
||||
if (!inGlobalTouch && inLocalTouch && shouldHandle(e)) {
|
||||
var touch = getTouch(e);
|
||||
|
||||
var currentOffset = {pageX: touch.pageX, pageY: touch.pageY};
|
||||
|
||||
var differenceX = currentOffset.pageX - startOffset.pageX;
|
||||
var differenceY = currentOffset.pageY - startOffset.pageY;
|
||||
|
||||
applyTouchMove(differenceX, differenceY);
|
||||
startOffset = currentOffset;
|
||||
|
||||
var currentTime = (new Date()).getTime();
|
||||
|
||||
var timeGap = currentTime - startTime;
|
||||
if (timeGap > 0) {
|
||||
speed.x = differenceX / timeGap;
|
||||
speed.y = differenceY / timeGap;
|
||||
startTime = currentTime;
|
||||
}
|
||||
|
||||
if (shouldPreventDefault(differenceX, differenceY)) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function touchEnd() {
|
||||
if (!inGlobalTouch && inLocalTouch) {
|
||||
inLocalTouch = false;
|
||||
|
||||
clearInterval(easingLoop);
|
||||
easingLoop = setInterval(function () {
|
||||
if (!instances.get(element)) {
|
||||
clearInterval(easingLoop);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!speed.x && !speed.y) {
|
||||
clearInterval(easingLoop);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
|
||||
clearInterval(easingLoop);
|
||||
return;
|
||||
}
|
||||
|
||||
applyTouchMove(speed.x * 30, speed.y * 30);
|
||||
|
||||
speed.x *= 0.8;
|
||||
speed.y *= 0.8;
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
if (supportsTouch) {
|
||||
i.event.bind(window, 'touchstart', globalTouchStart);
|
||||
i.event.bind(window, 'touchend', globalTouchEnd);
|
||||
i.event.bind(element, 'touchstart', touchStart);
|
||||
i.event.bind(element, 'touchmove', touchMove);
|
||||
i.event.bind(element, 'touchend', touchEnd);
|
||||
} else if (supportsIePointer) {
|
||||
if (window.PointerEvent) {
|
||||
i.event.bind(window, 'pointerdown', globalTouchStart);
|
||||
i.event.bind(window, 'pointerup', globalTouchEnd);
|
||||
i.event.bind(element, 'pointerdown', touchStart);
|
||||
i.event.bind(element, 'pointermove', touchMove);
|
||||
i.event.bind(element, 'pointerup', touchEnd);
|
||||
} else if (window.MSPointerEvent) {
|
||||
i.event.bind(window, 'MSPointerDown', globalTouchStart);
|
||||
i.event.bind(window, 'MSPointerUp', globalTouchEnd);
|
||||
i.event.bind(element, 'MSPointerDown', touchStart);
|
||||
i.event.bind(element, 'MSPointerMove', touchMove);
|
||||
i.event.bind(element, 'MSPointerUp', touchEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
if (!_.env.supportsTouch && !_.env.supportsIePointer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var i = instances.get(element);
|
||||
bindTouchHandler(element, i, _.env.supportsTouch, _.env.supportsIePointer);
|
||||
};
|
||||
44
src/js/plugin/initialize.js
Normal file
44
src/js/plugin/initialize.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../lib/helper');
|
||||
var cls = require('../lib/class');
|
||||
var instances = require('./instances');
|
||||
var updateGeometry = require('./update-geometry');
|
||||
var autoupdate = require('./autoupdate');
|
||||
var resizer = require('./resizer');
|
||||
|
||||
// Handlers
|
||||
var handlers = {
|
||||
'click-rail': require('./handler/click-rail'),
|
||||
'drag-scrollbar': require('./handler/drag-scrollbar'),
|
||||
'keyboard': require('./handler/keyboard'),
|
||||
'wheel': require('./handler/mouse-wheel'),
|
||||
'touch': require('./handler/touch'),
|
||||
'selection': require('./handler/selection')
|
||||
};
|
||||
var nativeScrollHandler = require('./handler/native-scroll');
|
||||
|
||||
module.exports = function (element, userSettings) {
|
||||
userSettings = typeof userSettings === 'object' ? userSettings : {};
|
||||
|
||||
cls.add(element, 'ps-container');
|
||||
|
||||
// Create a plugin instance.
|
||||
var i = instances.add(element);
|
||||
|
||||
i.settings = _.extend(i.settings, userSettings);
|
||||
cls.add(element, 'ps-theme-' + i.settings.theme);
|
||||
|
||||
i.settings.handlers.forEach(function (handlerName) {
|
||||
handlers[handlerName](element);
|
||||
});
|
||||
|
||||
nativeScrollHandler(element);
|
||||
|
||||
updateGeometry(element);
|
||||
|
||||
if (i.settings.autoupdate) {
|
||||
autoupdate(element);
|
||||
resizer(element);
|
||||
}
|
||||
};
|
||||
107
src/js/plugin/instances.js
Normal file
107
src/js/plugin/instances.js
Normal file
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../lib/helper');
|
||||
var cls = require('../lib/class');
|
||||
var defaultSettings = require('./default-setting');
|
||||
var dom = require('../lib/dom');
|
||||
var EventManager = require('../lib/event-manager');
|
||||
var guid = require('../lib/guid');
|
||||
|
||||
var instances = {};
|
||||
|
||||
function Instance(element) {
|
||||
var i = this;
|
||||
|
||||
i.settings = _.clone(defaultSettings);
|
||||
i.containerWidth = null;
|
||||
i.containerHeight = null;
|
||||
i.contentWidth = null;
|
||||
i.contentHeight = null;
|
||||
|
||||
i.isRtl = dom.css(element, 'direction') === "rtl";
|
||||
i.isNegativeScroll = (function () {
|
||||
var originalScrollLeft = element.scrollLeft;
|
||||
var result = null;
|
||||
element.scrollLeft = -1;
|
||||
result = element.scrollLeft < 0;
|
||||
element.scrollLeft = originalScrollLeft;
|
||||
return result;
|
||||
})();
|
||||
i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
|
||||
i.event = new EventManager();
|
||||
i.ownerDocument = element.ownerDocument || document;
|
||||
|
||||
function focus() {
|
||||
cls.add(element, 'ps-focus');
|
||||
}
|
||||
|
||||
function blur() {
|
||||
cls.remove(element, 'ps-focus');
|
||||
}
|
||||
|
||||
i.scrollbarXRail = dom.appendTo(dom.e('div', 'ps-scrollbar-x-rail'), element);
|
||||
i.scrollbarX = dom.appendTo(dom.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
|
||||
i.scrollbarX.setAttribute('tabindex', 0);
|
||||
i.event.bind(i.scrollbarX, 'focus', focus);
|
||||
i.event.bind(i.scrollbarX, 'blur', blur);
|
||||
i.scrollbarXActive = null;
|
||||
i.scrollbarXWidth = null;
|
||||
i.scrollbarXLeft = null;
|
||||
i.scrollbarXBottom = _.toInt(dom.css(i.scrollbarXRail, 'bottom'));
|
||||
i.isScrollbarXUsingBottom = i.scrollbarXBottom === i.scrollbarXBottom; // !isNaN
|
||||
i.scrollbarXTop = i.isScrollbarXUsingBottom ? null : _.toInt(dom.css(i.scrollbarXRail, 'top'));
|
||||
i.railBorderXWidth = _.toInt(dom.css(i.scrollbarXRail, 'borderLeftWidth')) + _.toInt(dom.css(i.scrollbarXRail, 'borderRightWidth'));
|
||||
// Set rail to display:block to calculate margins
|
||||
dom.css(i.scrollbarXRail, 'display', 'block');
|
||||
i.railXMarginWidth = _.toInt(dom.css(i.scrollbarXRail, 'marginLeft')) + _.toInt(dom.css(i.scrollbarXRail, 'marginRight'));
|
||||
dom.css(i.scrollbarXRail, 'display', '');
|
||||
i.railXWidth = null;
|
||||
i.railXRatio = null;
|
||||
|
||||
i.scrollbarYRail = dom.appendTo(dom.e('div', 'ps-scrollbar-y-rail'), element);
|
||||
i.scrollbarY = dom.appendTo(dom.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
|
||||
i.scrollbarY.setAttribute('tabindex', 0);
|
||||
i.event.bind(i.scrollbarY, 'focus', focus);
|
||||
i.event.bind(i.scrollbarY, 'blur', blur);
|
||||
i.scrollbarYActive = null;
|
||||
i.scrollbarYHeight = null;
|
||||
i.scrollbarYTop = null;
|
||||
i.scrollbarYRight = _.toInt(dom.css(i.scrollbarYRail, 'right'));
|
||||
i.isScrollbarYUsingRight = i.scrollbarYRight === i.scrollbarYRight; // !isNaN
|
||||
i.scrollbarYLeft = i.isScrollbarYUsingRight ? null : _.toInt(dom.css(i.scrollbarYRail, 'left'));
|
||||
i.scrollbarYOuterWidth = i.isRtl ? _.outerWidth(i.scrollbarY) : null;
|
||||
i.railBorderYWidth = _.toInt(dom.css(i.scrollbarYRail, 'borderTopWidth')) + _.toInt(dom.css(i.scrollbarYRail, 'borderBottomWidth'));
|
||||
dom.css(i.scrollbarYRail, 'display', 'block');
|
||||
i.railYMarginHeight = _.toInt(dom.css(i.scrollbarYRail, 'marginTop')) + _.toInt(dom.css(i.scrollbarYRail, 'marginBottom'));
|
||||
dom.css(i.scrollbarYRail, 'display', '');
|
||||
i.railYHeight = null;
|
||||
i.railYRatio = null;
|
||||
}
|
||||
|
||||
function getId(element) {
|
||||
return element.getAttribute('data-ps-id');
|
||||
}
|
||||
|
||||
function setId(element, id) {
|
||||
element.setAttribute('data-ps-id', id);
|
||||
}
|
||||
|
||||
function removeId(element) {
|
||||
element.removeAttribute('data-ps-id');
|
||||
}
|
||||
|
||||
exports.add = function (element) {
|
||||
var newId = guid();
|
||||
setId(element, newId);
|
||||
instances[newId] = new Instance(element);
|
||||
return instances[newId];
|
||||
};
|
||||
|
||||
exports.remove = function (element) {
|
||||
delete instances[getId(element)];
|
||||
removeId(element);
|
||||
};
|
||||
|
||||
exports.get = function (element) {
|
||||
return instances[getId(element)];
|
||||
};
|
||||
15
src/js/plugin/resizer.js
Normal file
15
src/js/plugin/resizer.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var update = require('./update');
|
||||
var instances = require('./instances');
|
||||
var _ = require('../lib/helper');
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
|
||||
var onResize = function () {
|
||||
update(element);
|
||||
};
|
||||
|
||||
i.event.bind(window, 'resize', _.debounce(onResize, 60));
|
||||
};
|
||||
126
src/js/plugin/update-geometry.js
Normal file
126
src/js/plugin/update-geometry.js
Normal file
@@ -0,0 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../lib/helper');
|
||||
var cls = require('../lib/class');
|
||||
var dom = require('../lib/dom');
|
||||
var instances = require('./instances');
|
||||
var updateScroll = require('./update-scroll');
|
||||
|
||||
function getThumbSize(i, thumbSize) {
|
||||
if (i.settings.minScrollbarLength) {
|
||||
thumbSize = Math.max(thumbSize, i.settings.minScrollbarLength);
|
||||
}
|
||||
if (i.settings.maxScrollbarLength) {
|
||||
thumbSize = Math.min(thumbSize, i.settings.maxScrollbarLength);
|
||||
}
|
||||
return thumbSize;
|
||||
}
|
||||
|
||||
function updateCss(element, i) {
|
||||
var xRailOffset = {width: i.railXWidth};
|
||||
if (i.isRtl) {
|
||||
xRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth - i.contentWidth;
|
||||
} else {
|
||||
xRailOffset.left = element.scrollLeft;
|
||||
}
|
||||
if (i.isScrollbarXUsingBottom) {
|
||||
xRailOffset.bottom = i.scrollbarXBottom - element.scrollTop;
|
||||
} else {
|
||||
xRailOffset.top = i.scrollbarXTop + element.scrollTop;
|
||||
}
|
||||
dom.css(i.scrollbarXRail, xRailOffset);
|
||||
|
||||
var yRailOffset = {top: element.scrollTop, height: i.railYHeight};
|
||||
if (i.isScrollbarYUsingRight) {
|
||||
if (i.isRtl) {
|
||||
yRailOffset.right = i.contentWidth - (i.negativeScrollAdjustment + element.scrollLeft) - i.scrollbarYRight - i.scrollbarYOuterWidth;
|
||||
} else {
|
||||
yRailOffset.right = i.scrollbarYRight - element.scrollLeft;
|
||||
}
|
||||
} else {
|
||||
if (i.isRtl) {
|
||||
yRailOffset.left = i.negativeScrollAdjustment + element.scrollLeft + i.containerWidth * 2 - i.contentWidth - i.scrollbarYLeft - i.scrollbarYOuterWidth;
|
||||
} else {
|
||||
yRailOffset.left = i.scrollbarYLeft + element.scrollLeft;
|
||||
}
|
||||
}
|
||||
dom.css(i.scrollbarYRail, yRailOffset);
|
||||
|
||||
dom.css(i.scrollbarX, {left: i.scrollbarXLeft, width: i.scrollbarXWidth - i.railBorderXWidth});
|
||||
dom.css(i.scrollbarY, {top: i.scrollbarYTop, height: i.scrollbarYHeight - i.railBorderYWidth});
|
||||
}
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
|
||||
i.containerWidth = element.clientWidth;
|
||||
i.containerHeight = element.clientHeight;
|
||||
i.contentWidth = element.scrollWidth;
|
||||
i.contentHeight = element.scrollHeight;
|
||||
|
||||
var existingRails;
|
||||
if (!element.contains(i.scrollbarXRail)) {
|
||||
existingRails = dom.queryChildren(element, '.ps-scrollbar-x-rail');
|
||||
if (existingRails.length > 0) {
|
||||
existingRails.forEach(function (rail) {
|
||||
dom.remove(rail);
|
||||
});
|
||||
}
|
||||
dom.appendTo(i.scrollbarXRail, element);
|
||||
}
|
||||
if (!element.contains(i.scrollbarYRail)) {
|
||||
existingRails = dom.queryChildren(element, '.ps-scrollbar-y-rail');
|
||||
if (existingRails.length > 0) {
|
||||
existingRails.forEach(function (rail) {
|
||||
dom.remove(rail);
|
||||
});
|
||||
}
|
||||
dom.appendTo(i.scrollbarYRail, element);
|
||||
}
|
||||
|
||||
if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
|
||||
i.scrollbarXActive = true;
|
||||
i.railXWidth = i.containerWidth - i.railXMarginWidth;
|
||||
i.railXRatio = i.containerWidth / i.railXWidth;
|
||||
i.scrollbarXWidth = getThumbSize(i, _.toInt(i.railXWidth * i.containerWidth / i.contentWidth));
|
||||
i.scrollbarXLeft = _.toInt((i.negativeScrollAdjustment + element.scrollLeft) * (i.railXWidth - i.scrollbarXWidth) / (i.contentWidth - i.containerWidth));
|
||||
} else {
|
||||
i.scrollbarXActive = false;
|
||||
}
|
||||
|
||||
if (!i.settings.suppressScrollY && i.containerHeight + i.settings.scrollYMarginOffset < i.contentHeight) {
|
||||
i.scrollbarYActive = true;
|
||||
i.railYHeight = i.containerHeight - i.railYMarginHeight;
|
||||
i.railYRatio = i.containerHeight / i.railYHeight;
|
||||
i.scrollbarYHeight = getThumbSize(i, _.toInt(i.railYHeight * i.containerHeight / i.contentHeight));
|
||||
i.scrollbarYTop = _.toInt(element.scrollTop * (i.railYHeight - i.scrollbarYHeight) / (i.contentHeight - i.containerHeight));
|
||||
} else {
|
||||
i.scrollbarYActive = false;
|
||||
}
|
||||
|
||||
if (i.scrollbarXLeft >= i.railXWidth - i.scrollbarXWidth) {
|
||||
i.scrollbarXLeft = i.railXWidth - i.scrollbarXWidth;
|
||||
}
|
||||
if (i.scrollbarYTop >= i.railYHeight - i.scrollbarYHeight) {
|
||||
i.scrollbarYTop = i.railYHeight - i.scrollbarYHeight;
|
||||
}
|
||||
|
||||
updateCss(element, i);
|
||||
|
||||
if (i.scrollbarXActive) {
|
||||
cls.add(element, 'ps-active-x');
|
||||
} else {
|
||||
cls.remove(element, 'ps-active-x');
|
||||
i.scrollbarXWidth = 0;
|
||||
i.scrollbarXLeft = 0;
|
||||
updateScroll(element, 'left', 0);
|
||||
}
|
||||
if (i.scrollbarYActive) {
|
||||
cls.add(element, 'ps-active-y');
|
||||
} else {
|
||||
cls.remove(element, 'ps-active-y');
|
||||
i.scrollbarYHeight = 0;
|
||||
i.scrollbarYTop = 0;
|
||||
updateScroll(element, 'top', 0);
|
||||
}
|
||||
};
|
||||
97
src/js/plugin/update-scroll.js
Normal file
97
src/js/plugin/update-scroll.js
Normal file
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
var instances = require('./instances');
|
||||
|
||||
var lastTop;
|
||||
var lastLeft;
|
||||
|
||||
var createDOMEvent = function (name) {
|
||||
var event = document.createEvent("Event");
|
||||
event.initEvent(name, true, true);
|
||||
return event;
|
||||
};
|
||||
|
||||
module.exports = function (element, axis, value) {
|
||||
if (typeof element === 'undefined') {
|
||||
throw 'You must provide an element to the update-scroll function';
|
||||
}
|
||||
|
||||
if (typeof axis === 'undefined') {
|
||||
throw 'You must provide an axis to the update-scroll function';
|
||||
}
|
||||
|
||||
if (typeof value === 'undefined') {
|
||||
throw 'You must provide a value to the update-scroll function';
|
||||
}
|
||||
|
||||
if (axis === 'top' && value <= 0) {
|
||||
element.scrollTop = value = 0; // don't allow negative scroll
|
||||
element.dispatchEvent(createDOMEvent('ps-y-reach-start'));
|
||||
}
|
||||
|
||||
if (axis === 'left' && value <= 0) {
|
||||
element.scrollLeft = value = 0; // don't allow negative scroll
|
||||
element.dispatchEvent(createDOMEvent('ps-x-reach-start'));
|
||||
}
|
||||
|
||||
var i = instances.get(element);
|
||||
|
||||
if (axis === 'top' && value >= i.contentHeight - i.containerHeight) {
|
||||
// don't allow scroll past container
|
||||
value = i.contentHeight - i.containerHeight;
|
||||
if (value - element.scrollTop <= 1) {
|
||||
// mitigates rounding errors on non-subpixel scroll values
|
||||
value = element.scrollTop;
|
||||
} else {
|
||||
element.scrollTop = value;
|
||||
}
|
||||
element.dispatchEvent(createDOMEvent('ps-y-reach-end'));
|
||||
}
|
||||
|
||||
if (axis === 'left' && value >= i.contentWidth - i.containerWidth) {
|
||||
// don't allow scroll past container
|
||||
value = i.contentWidth - i.containerWidth;
|
||||
if (value - element.scrollLeft <= 1) {
|
||||
// mitigates rounding errors on non-subpixel scroll values
|
||||
value = element.scrollLeft;
|
||||
} else {
|
||||
element.scrollLeft = value;
|
||||
}
|
||||
element.dispatchEvent(createDOMEvent('ps-x-reach-end'));
|
||||
}
|
||||
|
||||
if (!lastTop) {
|
||||
lastTop = element.scrollTop;
|
||||
}
|
||||
|
||||
if (!lastLeft) {
|
||||
lastLeft = element.scrollLeft;
|
||||
}
|
||||
|
||||
if (axis === 'top' && value < lastTop) {
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-up'));
|
||||
}
|
||||
|
||||
if (axis === 'top' && value > lastTop) {
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-down'));
|
||||
}
|
||||
|
||||
if (axis === 'left' && value < lastLeft) {
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-left'));
|
||||
}
|
||||
|
||||
if (axis === 'left' && value > lastLeft) {
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-right'));
|
||||
}
|
||||
|
||||
if (axis === 'top') {
|
||||
element.scrollTop = lastTop = value;
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-y'));
|
||||
}
|
||||
|
||||
if (axis === 'left') {
|
||||
element.scrollLeft = lastLeft = value;
|
||||
element.dispatchEvent(createDOMEvent('ps-scroll-x'));
|
||||
}
|
||||
|
||||
};
|
||||
37
src/js/plugin/update.js
Normal file
37
src/js/plugin/update.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../lib/helper');
|
||||
var dom = require('../lib/dom');
|
||||
var instances = require('./instances');
|
||||
var updateGeometry = require('./update-geometry');
|
||||
var updateScroll = require('./update-scroll');
|
||||
|
||||
module.exports = function (element) {
|
||||
var i = instances.get(element);
|
||||
|
||||
if (!i) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Recalcuate negative scrollLeft adjustment
|
||||
i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;
|
||||
|
||||
// Recalculate rail margins
|
||||
dom.css(i.scrollbarXRail, 'display', 'block');
|
||||
dom.css(i.scrollbarYRail, 'display', 'block');
|
||||
i.railXMarginWidth = _.toInt(dom.css(i.scrollbarXRail, 'marginLeft')) + _.toInt(dom.css(i.scrollbarXRail, 'marginRight'));
|
||||
i.railYMarginHeight = _.toInt(dom.css(i.scrollbarYRail, 'marginTop')) + _.toInt(dom.css(i.scrollbarYRail, 'marginBottom'));
|
||||
|
||||
// Hide scrollbars not to affect scrollWidth and scrollHeight
|
||||
dom.css(i.scrollbarXRail, 'display', 'none');
|
||||
dom.css(i.scrollbarYRail, 'display', 'none');
|
||||
|
||||
updateGeometry(element);
|
||||
|
||||
// Update top/left scroll to trigger events
|
||||
updateScroll(element, 'top', element.scrollTop);
|
||||
updateScroll(element, 'left', element.scrollLeft);
|
||||
|
||||
dom.css(i.scrollbarXRail, 'display', '');
|
||||
dom.css(i.scrollbarYRail, 'display', '');
|
||||
};
|
||||
@@ -1,125 +0,0 @@
|
||||
.ps-container .ps-scrollbar-x-rail {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
bottom: 3px; /* there must be 'bottom' for ps-scrollbar-x-rail */
|
||||
height: 8px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
opacity: 0;
|
||||
filter: alpha(opacity=0);
|
||||
-o-transition: background-color .2s linear, opacity .2s linear;
|
||||
-webkit-transition: background-color .2s linear, opacity .2s linear;
|
||||
-moz-transition: background-color .2s linear, opacity .2s linear;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
}
|
||||
|
||||
.ps-container:hover .ps-scrollbar-x-rail,
|
||||
.ps-container.hover .ps-scrollbar-x-rail {
|
||||
opacity: 0.6;
|
||||
filter: alpha(opacity=60);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail:hover,
|
||||
.ps-container .ps-scrollbar-x-rail.hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity=90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail.in-scrolling {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity=90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
right: 3px; /* there must be 'right' for ps-scrollbar-y-rail */
|
||||
width: 8px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
opacity: 0;
|
||||
filter: alpha(opacity = 0);
|
||||
-o-transition: background-color .2s linear, opacity .2s linear;
|
||||
-webkit-transition: background-color .2s linear, opacity .2s linear;
|
||||
-moz-transition: background-color .2s linear, opacity .2s linear;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
}
|
||||
|
||||
.ps-container:hover .ps-scrollbar-y-rail,
|
||||
.ps-container.hover .ps-scrollbar-y-rail {
|
||||
opacity: 0.6;
|
||||
filter: alpha(opacity=60);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail:hover,
|
||||
.ps-container .ps-scrollbar-y-rail.hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity=90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail.in-scrolling {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity=90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
bottom: 0; /* there must be 'bottom' for ps-scrollbar-x */
|
||||
height: 8px;
|
||||
background-color: #aaa;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
-o-transition: background-color .2s linear;
|
||||
-webkit-transition: background-color.2s linear;
|
||||
-moz-transition: background-color .2s linear;
|
||||
transition: background-color .2s linear;
|
||||
}
|
||||
|
||||
.ps-container.ie6 .ps-scrollbar-x {
|
||||
font-size: 0; /* fixed scrollbar height in xp sp3 ie6 */
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail:hover .ps-scrollbar-x,
|
||||
.ps-container .ps-scrollbar-x-rail.hover .ps-scrollbar-x {
|
||||
background-color: #999;
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
right: 0; /* there must be 'right' for ps-scrollbar-y */
|
||||
width: 8px;
|
||||
background-color: #aaa;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
-o-transition: background-color .2s linear;
|
||||
-webkit-transition: background-color.2s linear;
|
||||
-moz-transition: background-color .2s linear;
|
||||
transition: background-color .2s linear;
|
||||
}
|
||||
|
||||
.ps-container.ie6 .ps-scrollbar-y {
|
||||
font-size: 0; /* fixed scrollbar height in xp sp3 ie6 */
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail:hover .ps-scrollbar-y,
|
||||
.ps-container .ps-scrollbar-y-rail.hover .ps-scrollbar-y {
|
||||
background-color: #999;
|
||||
}
|
||||
|
||||
.ps-container.ie .ps-scrollbar-x,
|
||||
.ps-container.ie .ps-scrollbar-y {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.ps-container.ie:hover .ps-scrollbar-x,
|
||||
.ps-container.ie:hover .ps-scrollbar-y,
|
||||
.ps-container.ie.hover .ps-scrollbar-x,
|
||||
.ps-container.ie.hover .ps-scrollbar-y {
|
||||
visibility: visible;
|
||||
}
|
||||
@@ -1,718 +0,0 @@
|
||||
/* Copyright (c) 2012, 2014 Hyunje Alex Jun and other contributors
|
||||
* Licensed under the MIT License
|
||||
*/
|
||||
(function (factory) {
|
||||
'use strict';
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS
|
||||
factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
'use strict';
|
||||
|
||||
// The default settings for the plugin
|
||||
var defaultSettings = {
|
||||
wheelSpeed: 1,
|
||||
wheelPropagation: false,
|
||||
minScrollbarLength: null,
|
||||
maxScrollbarLength: null,
|
||||
useBothWheelAxes: false,
|
||||
useKeyboard: true,
|
||||
suppressScrollX: false,
|
||||
suppressScrollY: false,
|
||||
scrollXMarginOffset: 0,
|
||||
scrollYMarginOffset: 0,
|
||||
includePadding: false
|
||||
};
|
||||
|
||||
var getEventClassName = (function () {
|
||||
var incrementingId = 0;
|
||||
return function () {
|
||||
var id = incrementingId;
|
||||
incrementingId += 1;
|
||||
return '.perfect-scrollbar-' + id;
|
||||
};
|
||||
}());
|
||||
|
||||
$.fn.perfectScrollbar = function (suppliedSettings, option) {
|
||||
|
||||
return this.each(function () {
|
||||
// Use the default settings
|
||||
var settings = $.extend(true, {}, defaultSettings),
|
||||
$this = $(this);
|
||||
|
||||
if (typeof suppliedSettings === "object") {
|
||||
// But over-ride any supplied
|
||||
$.extend(true, settings, suppliedSettings);
|
||||
} else {
|
||||
// If no settings were supplied, then the first param must be the option
|
||||
option = suppliedSettings;
|
||||
}
|
||||
|
||||
// Catch options
|
||||
|
||||
if (option === 'update') {
|
||||
if ($this.data('perfect-scrollbar-update')) {
|
||||
$this.data('perfect-scrollbar-update')();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
else if (option === 'destroy') {
|
||||
if ($this.data('perfect-scrollbar-destroy')) {
|
||||
$this.data('perfect-scrollbar-destroy')();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this.data('perfect-scrollbar')) {
|
||||
// if there's already perfect-scrollbar
|
||||
return $this.data('perfect-scrollbar');
|
||||
}
|
||||
|
||||
|
||||
// Or generate new perfectScrollbar
|
||||
|
||||
// Set class to the container
|
||||
$this.addClass('ps-container');
|
||||
|
||||
var $scrollbarXRail = $("<div class='ps-scrollbar-x-rail'></div>").appendTo($this),
|
||||
$scrollbarYRail = $("<div class='ps-scrollbar-y-rail'></div>").appendTo($this),
|
||||
$scrollbarX = $("<div class='ps-scrollbar-x'></div>").appendTo($scrollbarXRail),
|
||||
$scrollbarY = $("<div class='ps-scrollbar-y'></div>").appendTo($scrollbarYRail),
|
||||
scrollbarXActive,
|
||||
scrollbarYActive,
|
||||
containerWidth,
|
||||
containerHeight,
|
||||
contentWidth,
|
||||
contentHeight,
|
||||
scrollbarXWidth,
|
||||
scrollbarXLeft,
|
||||
scrollbarXBottom = parseInt($scrollbarXRail.css('bottom'), 10),
|
||||
isScrollbarXUsingBottom = scrollbarXBottom === scrollbarXBottom, // !isNaN
|
||||
scrollbarXTop = isScrollbarXUsingBottom ? null : parseInt($scrollbarXRail.css('top'), 10),
|
||||
scrollbarYHeight,
|
||||
scrollbarYTop,
|
||||
scrollbarYRight = parseInt($scrollbarYRail.css('right'), 10),
|
||||
isScrollbarYUsingRight = scrollbarYRight === scrollbarYRight, // !isNaN
|
||||
scrollbarYLeft = isScrollbarYUsingRight ? null: parseInt($scrollbarYRail.css('left'), 10),
|
||||
isRtl = $this.css('direction') === "rtl",
|
||||
eventClassName = getEventClassName(),
|
||||
railBorderXWidth = parseInt($scrollbarXRail.css('borderLeftWidth'), 10) + parseInt($scrollbarXRail.css('borderRightWidth'), 10),
|
||||
railBorderYWidth = parseInt($scrollbarXRail.css('borderTopWidth'), 10) + parseInt($scrollbarXRail.css('borderBottomWidth'), 10);
|
||||
|
||||
var updateContentScrollTop = function (currentTop, deltaY) {
|
||||
var newTop = currentTop + deltaY,
|
||||
maxTop = containerHeight - scrollbarYHeight;
|
||||
|
||||
if (newTop < 0) {
|
||||
scrollbarYTop = 0;
|
||||
}
|
||||
else if (newTop > maxTop) {
|
||||
scrollbarYTop = maxTop;
|
||||
}
|
||||
else {
|
||||
scrollbarYTop = newTop;
|
||||
}
|
||||
|
||||
var scrollTop = parseInt(scrollbarYTop * (contentHeight - containerHeight) / (containerHeight - scrollbarYHeight), 10);
|
||||
$this.scrollTop(scrollTop);
|
||||
};
|
||||
|
||||
var updateContentScrollLeft = function (currentLeft, deltaX) {
|
||||
var newLeft = currentLeft + deltaX,
|
||||
maxLeft = containerWidth - scrollbarXWidth;
|
||||
|
||||
if (newLeft < 0) {
|
||||
scrollbarXLeft = 0;
|
||||
}
|
||||
else if (newLeft > maxLeft) {
|
||||
scrollbarXLeft = maxLeft;
|
||||
}
|
||||
else {
|
||||
scrollbarXLeft = newLeft;
|
||||
}
|
||||
|
||||
var scrollLeft = parseInt(scrollbarXLeft * (contentWidth - containerWidth) / (containerWidth - scrollbarXWidth), 10);
|
||||
$this.scrollLeft(scrollLeft);
|
||||
};
|
||||
|
||||
var getSettingsAdjustedThumbSize = function (thumbSize) {
|
||||
if (settings.minScrollbarLength) {
|
||||
thumbSize = Math.max(thumbSize, settings.minScrollbarLength);
|
||||
}
|
||||
if (settings.maxScrollbarLength) {
|
||||
thumbSize = Math.min(thumbSize, settings.maxScrollbarLength);
|
||||
}
|
||||
return thumbSize;
|
||||
};
|
||||
|
||||
var updateScrollbarCss = function () {
|
||||
var scrollbarXStyles = {width: containerWidth, display: scrollbarXActive ? "inherit": "none"};
|
||||
if (isRtl) {
|
||||
scrollbarXStyles.left = $this.scrollLeft() + containerWidth - contentWidth;
|
||||
} else {
|
||||
scrollbarXStyles.left = $this.scrollLeft();
|
||||
}
|
||||
if (isScrollbarXUsingBottom) {
|
||||
scrollbarXStyles.bottom = scrollbarXBottom - $this.scrollTop();
|
||||
} else {
|
||||
scrollbarXStyles.top = scrollbarXTop + $this.scrollTop();
|
||||
}
|
||||
$scrollbarXRail.css(scrollbarXStyles);
|
||||
|
||||
var scrollbarYStyles = {top: $this.scrollTop(), height: containerHeight, display: scrollbarYActive ? "inherit": "none"};
|
||||
|
||||
if (isScrollbarYUsingRight) {
|
||||
if (isRtl) {
|
||||
scrollbarYStyles.right = contentWidth - $this.scrollLeft() - scrollbarYRight - $scrollbarY.outerWidth();
|
||||
} else {
|
||||
scrollbarYStyles.right = scrollbarYRight - $this.scrollLeft();
|
||||
}
|
||||
} else {
|
||||
if (isRtl) {
|
||||
scrollbarYStyles.left = $this.scrollLeft() + containerWidth * 2 - contentWidth - scrollbarYLeft - $scrollbarY.outerWidth();
|
||||
} else {
|
||||
scrollbarYStyles.left = scrollbarYLeft + $this.scrollLeft();
|
||||
}
|
||||
}
|
||||
$scrollbarYRail.css(scrollbarYStyles);
|
||||
|
||||
$scrollbarX.css({left: scrollbarXLeft, width: scrollbarXWidth - railBorderXWidth});
|
||||
$scrollbarY.css({top: scrollbarYTop, height: scrollbarYHeight - railBorderYWidth});
|
||||
|
||||
if (scrollbarXActive) {
|
||||
$this.addClass('ps-active-x');
|
||||
} else {
|
||||
$this.removeClass('ps-active-x');
|
||||
}
|
||||
|
||||
if (scrollbarYActive) {
|
||||
$this.addClass('ps-active-y');
|
||||
} else {
|
||||
$this.removeClass('ps-active-y');
|
||||
}
|
||||
};
|
||||
|
||||
var updateBarSizeAndPosition = function () {
|
||||
// Hide scrollbars not to affect scrollWidth and scrollHeight
|
||||
$scrollbarXRail.hide();
|
||||
$scrollbarYRail.hide();
|
||||
|
||||
containerWidth = settings.includePadding ? $this.innerWidth() : $this.width();
|
||||
containerHeight = settings.includePadding ? $this.innerHeight() : $this.height();
|
||||
contentWidth = $this.prop('scrollWidth');
|
||||
contentHeight = $this.prop('scrollHeight');
|
||||
|
||||
if (!settings.suppressScrollX && containerWidth + settings.scrollXMarginOffset < contentWidth) {
|
||||
scrollbarXActive = true;
|
||||
scrollbarXWidth = getSettingsAdjustedThumbSize(parseInt(containerWidth * containerWidth / contentWidth, 10));
|
||||
scrollbarXLeft = parseInt($this.scrollLeft() * (containerWidth - scrollbarXWidth) / (contentWidth - containerWidth), 10);
|
||||
}
|
||||
else {
|
||||
scrollbarXActive = false;
|
||||
scrollbarXWidth = 0;
|
||||
scrollbarXLeft = 0;
|
||||
$this.scrollLeft(0);
|
||||
}
|
||||
|
||||
if (!settings.suppressScrollY && containerHeight + settings.scrollYMarginOffset < contentHeight) {
|
||||
scrollbarYActive = true;
|
||||
scrollbarYHeight = getSettingsAdjustedThumbSize(parseInt(containerHeight * containerHeight / contentHeight, 10));
|
||||
scrollbarYTop = parseInt($this.scrollTop() * (containerHeight - scrollbarYHeight) / (contentHeight - containerHeight), 10);
|
||||
}
|
||||
else {
|
||||
scrollbarYActive = false;
|
||||
scrollbarYHeight = 0;
|
||||
scrollbarYTop = 0;
|
||||
$this.scrollTop(0);
|
||||
}
|
||||
|
||||
if (scrollbarYTop >= containerHeight - scrollbarYHeight) {
|
||||
scrollbarYTop = containerHeight - scrollbarYHeight;
|
||||
}
|
||||
if (scrollbarXLeft >= containerWidth - scrollbarXWidth) {
|
||||
scrollbarXLeft = containerWidth - scrollbarXWidth;
|
||||
}
|
||||
|
||||
updateScrollbarCss();
|
||||
|
||||
// Show scrollbars if needed after updated
|
||||
if (!settings.suppressScrollX) {
|
||||
$scrollbarXRail.show();
|
||||
}
|
||||
if (!settings.suppressScrollY) {
|
||||
$scrollbarYRail.show();
|
||||
}
|
||||
};
|
||||
|
||||
var bindMouseScrollXHandler = function () {
|
||||
var currentLeft,
|
||||
currentPageX;
|
||||
|
||||
$scrollbarX.bind('mousedown' + eventClassName, function (e) {
|
||||
currentPageX = e.pageX;
|
||||
currentLeft = $scrollbarX.position().left;
|
||||
$scrollbarXRail.addClass('in-scrolling');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind('mousemove' + eventClassName, function (e) {
|
||||
if ($scrollbarXRail.hasClass('in-scrolling')) {
|
||||
updateContentScrollLeft(currentLeft, e.pageX - currentPageX);
|
||||
updateBarSizeAndPosition();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('mouseup' + eventClassName, function (e) {
|
||||
if ($scrollbarXRail.hasClass('in-scrolling')) {
|
||||
$scrollbarXRail.removeClass('in-scrolling');
|
||||
}
|
||||
});
|
||||
|
||||
currentLeft =
|
||||
currentPageX = null;
|
||||
};
|
||||
|
||||
var bindMouseScrollYHandler = function () {
|
||||
var currentTop,
|
||||
currentPageY;
|
||||
|
||||
$scrollbarY.bind('mousedown' + eventClassName, function (e) {
|
||||
currentPageY = e.pageY;
|
||||
currentTop = $scrollbarY.position().top;
|
||||
$scrollbarYRail.addClass('in-scrolling');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind('mousemove' + eventClassName, function (e) {
|
||||
if ($scrollbarYRail.hasClass('in-scrolling')) {
|
||||
updateContentScrollTop(currentTop, e.pageY - currentPageY);
|
||||
updateBarSizeAndPosition();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('mouseup' + eventClassName, function (e) {
|
||||
if ($scrollbarYRail.hasClass('in-scrolling')) {
|
||||
$scrollbarYRail.removeClass('in-scrolling');
|
||||
}
|
||||
});
|
||||
|
||||
currentTop =
|
||||
currentPageY = null;
|
||||
};
|
||||
|
||||
// check if the default scrolling should be prevented.
|
||||
var shouldPreventDefault = function (deltaX, deltaY) {
|
||||
var scrollTop = $this.scrollTop();
|
||||
if (deltaX === 0) {
|
||||
if (!scrollbarYActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= contentHeight - containerHeight && deltaY < 0)) {
|
||||
return !settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollLeft = $this.scrollLeft();
|
||||
if (deltaY === 0) {
|
||||
if (!scrollbarXActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= contentWidth - containerWidth && deltaX > 0)) {
|
||||
return !settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// bind handlers
|
||||
var bindMouseWheelHandler = function () {
|
||||
var shouldPrevent = false;
|
||||
|
||||
var getDeltaFromEvent = function (e) {
|
||||
var deltaX = e.originalEvent.deltaX,
|
||||
deltaY = -1 * e.originalEvent.deltaY;
|
||||
|
||||
if (typeof deltaX === "undefined" || typeof deltaY === "undefined") {
|
||||
// OS X Safari
|
||||
deltaX = -1 * e.originalEvent.wheelDeltaX / 6;
|
||||
deltaY = e.originalEvent.wheelDeltaY / 6;
|
||||
}
|
||||
|
||||
if (e.originalEvent.deltaMode && e.originalEvent.deltaMode === 1) {
|
||||
// Firefox in deltaMode 1: Line scrolling
|
||||
deltaX *= 10;
|
||||
deltaY *= 10;
|
||||
}
|
||||
|
||||
if (deltaX !== deltaX && deltaY !== deltaY/* NaN checks */) {
|
||||
// IE in some mouse drivers
|
||||
deltaX = 0;
|
||||
deltaY = e.originalEvent.wheelDelta;
|
||||
}
|
||||
|
||||
return [deltaX, deltaY];
|
||||
};
|
||||
|
||||
var mousewheelHandler = function (e) {
|
||||
var delta = getDeltaFromEvent(e);
|
||||
|
||||
var deltaX = delta[0],
|
||||
deltaY = delta[1];
|
||||
|
||||
shouldPrevent = false;
|
||||
if (!settings.useBothWheelAxes) {
|
||||
// deltaX will only be used for horizontal scrolling and deltaY will
|
||||
// only be used for vertical scrolling - this is the default
|
||||
$this.scrollTop($this.scrollTop() - (deltaY * settings.wheelSpeed));
|
||||
$this.scrollLeft($this.scrollLeft() + (deltaX * settings.wheelSpeed));
|
||||
} else if (scrollbarYActive && !scrollbarXActive) {
|
||||
// only vertical scrollbar is active and useBothWheelAxes option is
|
||||
// active, so let's scroll vertical bar using both mouse wheel axes
|
||||
if (deltaY) {
|
||||
$this.scrollTop($this.scrollTop() - (deltaY * settings.wheelSpeed));
|
||||
} else {
|
||||
$this.scrollTop($this.scrollTop() + (deltaX * settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
} else if (scrollbarXActive && !scrollbarYActive) {
|
||||
// useBothWheelAxes and only horizontal bar is active, so use both
|
||||
// wheel axes for horizontal bar
|
||||
if (deltaX) {
|
||||
$this.scrollLeft($this.scrollLeft() + (deltaX * settings.wheelSpeed));
|
||||
} else {
|
||||
$this.scrollLeft($this.scrollLeft() - (deltaY * settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
}
|
||||
|
||||
// update bar position
|
||||
updateBarSizeAndPosition();
|
||||
|
||||
shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
|
||||
if (shouldPrevent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof window.onwheel !== "undefined") {
|
||||
$this.bind('wheel' + eventClassName, mousewheelHandler);
|
||||
} else if (typeof window.onmousewheel !== "undefined") {
|
||||
$this.bind('mousewheel' + eventClassName, mousewheelHandler);
|
||||
}
|
||||
};
|
||||
|
||||
var bindKeyboardHandler = function () {
|
||||
var hovered = false;
|
||||
$this.bind('mouseenter' + eventClassName, function (e) {
|
||||
hovered = true;
|
||||
});
|
||||
$this.bind('mouseleave' + eventClassName, function (e) {
|
||||
hovered = false;
|
||||
});
|
||||
|
||||
var shouldPrevent = false;
|
||||
$(document).bind('keydown' + eventClassName, function (e) {
|
||||
if (e.isDefaultPrevented && e.isDefaultPrevented()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hovered || $(document.activeElement).is(":input,[contenteditable]")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaX = 0,
|
||||
deltaY = 0;
|
||||
|
||||
switch (e.which) {
|
||||
case 37: // left
|
||||
deltaX = -30;
|
||||
break;
|
||||
case 38: // up
|
||||
deltaY = 30;
|
||||
break;
|
||||
case 39: // right
|
||||
deltaX = 30;
|
||||
break;
|
||||
case 40: // down
|
||||
deltaY = -30;
|
||||
break;
|
||||
case 33: // page up
|
||||
deltaY = 90;
|
||||
break;
|
||||
case 32: // space bar
|
||||
case 34: // page down
|
||||
deltaY = -90;
|
||||
break;
|
||||
case 35: // end
|
||||
deltaY = -containerHeight;
|
||||
break;
|
||||
case 36: // home
|
||||
deltaY = containerHeight;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$this.scrollTop($this.scrollTop() - deltaY);
|
||||
$this.scrollLeft($this.scrollLeft() + deltaX);
|
||||
|
||||
shouldPrevent = shouldPreventDefault(deltaX, deltaY);
|
||||
if (shouldPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var bindRailClickHandler = function () {
|
||||
var stopPropagation = function (e) { e.stopPropagation(); };
|
||||
|
||||
$scrollbarY.bind('click' + eventClassName, stopPropagation);
|
||||
$scrollbarYRail.bind('click' + eventClassName, function (e) {
|
||||
var halfOfScrollbarLength = parseInt(scrollbarYHeight / 2, 10),
|
||||
positionTop = e.pageY - $scrollbarYRail.offset().top - halfOfScrollbarLength,
|
||||
maxPositionTop = containerHeight - scrollbarYHeight,
|
||||
positionRatio = positionTop / maxPositionTop;
|
||||
|
||||
if (positionRatio < 0) {
|
||||
positionRatio = 0;
|
||||
} else if (positionRatio > 1) {
|
||||
positionRatio = 1;
|
||||
}
|
||||
|
||||
$this.scrollTop((contentHeight - containerHeight) * positionRatio);
|
||||
});
|
||||
|
||||
$scrollbarX.bind('click' + eventClassName, stopPropagation);
|
||||
$scrollbarXRail.bind('click' + eventClassName, function (e) {
|
||||
var halfOfScrollbarLength = parseInt(scrollbarXWidth / 2, 10),
|
||||
positionLeft = e.pageX - $scrollbarXRail.offset().left - halfOfScrollbarLength,
|
||||
maxPositionLeft = containerWidth - scrollbarXWidth,
|
||||
positionRatio = positionLeft / maxPositionLeft;
|
||||
|
||||
if (positionRatio < 0) {
|
||||
positionRatio = 0;
|
||||
} else if (positionRatio > 1) {
|
||||
positionRatio = 1;
|
||||
}
|
||||
|
||||
$this.scrollLeft((contentWidth - containerWidth) * positionRatio);
|
||||
});
|
||||
};
|
||||
|
||||
// bind mobile touch handler
|
||||
var bindMobileTouchHandler = function () {
|
||||
var applyTouchMove = function (differenceX, differenceY) {
|
||||
$this.scrollTop($this.scrollTop() - differenceY);
|
||||
$this.scrollLeft($this.scrollLeft() - differenceX);
|
||||
|
||||
// update bar position
|
||||
updateBarSizeAndPosition();
|
||||
};
|
||||
|
||||
var startCoords = {},
|
||||
startTime = 0,
|
||||
speed = {},
|
||||
breakingProcess = null,
|
||||
inGlobalTouch = false;
|
||||
|
||||
$(window).bind("touchstart" + eventClassName, function (e) {
|
||||
inGlobalTouch = true;
|
||||
});
|
||||
$(window).bind("touchend" + eventClassName, function (e) {
|
||||
inGlobalTouch = false;
|
||||
});
|
||||
|
||||
$this.bind("touchstart" + eventClassName, function (e) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
|
||||
startCoords.pageX = touch.pageX;
|
||||
startCoords.pageY = touch.pageY;
|
||||
|
||||
startTime = (new Date()).getTime();
|
||||
|
||||
if (breakingProcess !== null) {
|
||||
clearInterval(breakingProcess);
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
});
|
||||
$this.bind("touchmove" + eventClassName, function (e) {
|
||||
if (!inGlobalTouch && e.originalEvent.targetTouches.length === 1) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
|
||||
var currentCoords = {};
|
||||
currentCoords.pageX = touch.pageX;
|
||||
currentCoords.pageY = touch.pageY;
|
||||
|
||||
var differenceX = currentCoords.pageX - startCoords.pageX,
|
||||
differenceY = currentCoords.pageY - startCoords.pageY;
|
||||
|
||||
applyTouchMove(differenceX, differenceY);
|
||||
startCoords = currentCoords;
|
||||
|
||||
var currentTime = (new Date()).getTime();
|
||||
|
||||
var timeGap = currentTime - startTime;
|
||||
if (timeGap > 0) {
|
||||
speed.x = differenceX / timeGap;
|
||||
speed.y = differenceY / timeGap;
|
||||
startTime = currentTime;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
$this.bind("touchend" + eventClassName, function (e) {
|
||||
clearInterval(breakingProcess);
|
||||
breakingProcess = setInterval(function () {
|
||||
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
|
||||
clearInterval(breakingProcess);
|
||||
return;
|
||||
}
|
||||
|
||||
applyTouchMove(speed.x * 30, speed.y * 30);
|
||||
|
||||
speed.x *= 0.8;
|
||||
speed.y *= 0.8;
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
|
||||
var bindScrollHandler = function () {
|
||||
$this.bind('scroll' + eventClassName, function (e) {
|
||||
updateBarSizeAndPosition();
|
||||
});
|
||||
};
|
||||
|
||||
var destroy = function () {
|
||||
$this.unbind(eventClassName);
|
||||
$(window).unbind(eventClassName);
|
||||
$(document).unbind(eventClassName);
|
||||
$this.data('perfect-scrollbar', null);
|
||||
$this.data('perfect-scrollbar-update', null);
|
||||
$this.data('perfect-scrollbar-destroy', null);
|
||||
$scrollbarX.remove();
|
||||
$scrollbarY.remove();
|
||||
$scrollbarXRail.remove();
|
||||
$scrollbarYRail.remove();
|
||||
|
||||
// clean all variables
|
||||
$scrollbarXRail =
|
||||
$scrollbarYRail =
|
||||
$scrollbarX =
|
||||
$scrollbarY =
|
||||
scrollbarXActive =
|
||||
scrollbarYActive =
|
||||
containerWidth =
|
||||
containerHeight =
|
||||
contentWidth =
|
||||
contentHeight =
|
||||
scrollbarXWidth =
|
||||
scrollbarXLeft =
|
||||
scrollbarXBottom =
|
||||
isScrollbarXUsingBottom =
|
||||
scrollbarXTop =
|
||||
scrollbarYHeight =
|
||||
scrollbarYTop =
|
||||
scrollbarYRight =
|
||||
isScrollbarYUsingRight =
|
||||
scrollbarYLeft =
|
||||
isRtl =
|
||||
eventClassName = null;
|
||||
};
|
||||
|
||||
var ieSupport = function (version) {
|
||||
$this.addClass('ie').addClass('ie' + version);
|
||||
|
||||
var bindHoverHandlers = function () {
|
||||
var mouseenter = function () {
|
||||
$(this).addClass('hover');
|
||||
};
|
||||
var mouseleave = function () {
|
||||
$(this).removeClass('hover');
|
||||
};
|
||||
$this.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarXRail.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarYRail.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarX.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarY.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
};
|
||||
|
||||
var fixIe6ScrollbarPosition = function () {
|
||||
updateScrollbarCss = function () {
|
||||
var scrollbarXStyles = {left: scrollbarXLeft + $this.scrollLeft(), width: scrollbarXWidth};
|
||||
if (isScrollbarXUsingBottom) {
|
||||
scrollbarXStyles.bottom = scrollbarXBottom;
|
||||
} else {
|
||||
scrollbarXStyles.top = scrollbarXTop;
|
||||
}
|
||||
$scrollbarX.css(scrollbarXStyles);
|
||||
|
||||
var scrollbarYStyles = {top: scrollbarYTop + $this.scrollTop(), height: scrollbarYHeight};
|
||||
if (isScrollbarYUsingRight) {
|
||||
scrollbarYStyles.right = scrollbarYRight;
|
||||
} else {
|
||||
scrollbarYStyles.left = scrollbarYLeft;
|
||||
}
|
||||
|
||||
$scrollbarY.css(scrollbarYStyles);
|
||||
$scrollbarX.hide().show();
|
||||
$scrollbarY.hide().show();
|
||||
};
|
||||
};
|
||||
|
||||
if (version === 6) {
|
||||
bindHoverHandlers();
|
||||
fixIe6ScrollbarPosition();
|
||||
}
|
||||
};
|
||||
|
||||
var supportsTouch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);
|
||||
|
||||
var initialize = function () {
|
||||
var ieMatch = navigator.userAgent.toLowerCase().match(/(msie) ([\w.]+)/);
|
||||
if (ieMatch && ieMatch[1] === 'msie') {
|
||||
// must be executed at first, because 'ieSupport' may addClass to the container
|
||||
ieSupport(parseInt(ieMatch[2], 10));
|
||||
}
|
||||
|
||||
updateBarSizeAndPosition();
|
||||
bindScrollHandler();
|
||||
bindMouseScrollXHandler();
|
||||
bindMouseScrollYHandler();
|
||||
bindRailClickHandler();
|
||||
bindMouseWheelHandler();
|
||||
|
||||
if (supportsTouch) {
|
||||
bindMobileTouchHandler();
|
||||
}
|
||||
if (settings.useKeyboard) {
|
||||
bindKeyboardHandler();
|
||||
}
|
||||
$this.data('perfect-scrollbar', $this);
|
||||
$this.data('perfect-scrollbar-update', updateBarSizeAndPosition);
|
||||
$this.data('perfect-scrollbar-destroy', destroy);
|
||||
};
|
||||
|
||||
// initialize
|
||||
initialize();
|
||||
|
||||
return $this;
|
||||
});
|
||||
};
|
||||
}));
|
||||
Reference in New Issue
Block a user