Skip to content

Commit 61b356b

Browse files
committed
Initial commit
0 parents  commit 61b356b

19 files changed

Lines changed: 4644 additions & 0 deletions

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
],
5+
"plugins": ["add-module-exports"]
6+
}

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*.js]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.html]
13+
# すべてのファイルに適用する
14+
charset = utf-8
15+
# 文字コードを統一
16+
indent_style = tab
17+
#インデントを統一する。「tab」か「 space」
18+
indent_size = 2
19+
# インデントの数を統一
20+
trim_trailing_whitespace = true
21+
# 行末のホワイトスペースを削除
22+
insert_final_newline = true
23+
# フォルダの最後の行に改行
24+
end_of_line = lf

.eslintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": [
3+
"airbnb-base"
4+
],
5+
"env": {
6+
"browser": true
7+
},
8+
"globals": {
9+
"document": true,
10+
"window": true
11+
},
12+
"rules":{
13+
"comma-dangle": 0,
14+
"no-useless-escape": 0,
15+
"class-methods-use-this": 0,
16+
"no-bitwise": 0,
17+
"no-mixed-operators": 0,
18+
"no-param-reassign": 0
19+
}
20+
}

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
.DS_Store

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v7.5.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Hori Godai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

build/scroll-hint.js

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/**
2+
* Modules in this bundle
3+
* @license
4+
*
5+
* scroll-hint:
6+
* license: MIT (http://opensource.org/licenses/MIT)
7+
* author: steelydylan
8+
* version: 0.0.1
9+
*
10+
* es6-object-assign:
11+
* license: MIT (http://opensource.org/licenses/MIT)
12+
* author: Rubén Norte <rubennorte@gmail.com>
13+
* maintainers: rubennorte <rubennorte@gmail.com>
14+
* homepage: https://github.com/rubennorte/es6-object-assign
15+
* version: 1.1.0
16+
*
17+
* This header is generated by licensify (https://github.com/twada/licensify)
18+
*/
19+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ScrollHint = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
20+
/**
21+
* Code refactored from Mozilla Developer Network:
22+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
23+
*/
24+
25+
'use strict';
26+
27+
function assign(target, firstSource) {
28+
if (target === undefined || target === null) {
29+
throw new TypeError('Cannot convert first argument to object');
30+
}
31+
32+
var to = Object(target);
33+
for (var i = 1; i < arguments.length; i++) {
34+
var nextSource = arguments[i];
35+
if (nextSource === undefined || nextSource === null) {
36+
continue;
37+
}
38+
39+
var keysArray = Object.keys(Object(nextSource));
40+
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
41+
var nextKey = keysArray[nextIndex];
42+
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
43+
if (desc !== undefined && desc.enumerable) {
44+
to[nextKey] = nextSource[nextKey];
45+
}
46+
}
47+
}
48+
return to;
49+
}
50+
51+
function polyfill() {
52+
if (!Object.assign) {
53+
Object.defineProperty(Object, 'assign', {
54+
enumerable: false,
55+
configurable: true,
56+
writable: true,
57+
value: assign
58+
});
59+
}
60+
}
61+
62+
module.exports = {
63+
assign: assign,
64+
polyfill: polyfill
65+
};
66+
67+
},{}],2:[function(require,module,exports){
68+
'use strict';
69+
70+
Object.defineProperty(exports, "__esModule", {
71+
value: true
72+
});
73+
74+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
75+
76+
var _es6ObjectAssign = require('es6-object-assign');
77+
78+
var _util = require('./util');
79+
80+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
81+
82+
var defaults = {
83+
scrollableClass: 'is-scrollable'
84+
};
85+
86+
var ScrollHint = function () {
87+
function ScrollHint(ele, option) {
88+
var _this = this;
89+
90+
_classCallCheck(this, ScrollHint);
91+
92+
this.opt = (0, _es6ObjectAssign.assign)({}, defaults, option);
93+
this.items = [];
94+
var elements = typeof ele === 'string' ? document.querySelectorAll(ele) : ele;
95+
[].forEach.call(elements, function (element) {
96+
element.style.position = 'relative';
97+
element.style.overflow = 'auto';
98+
var item = {
99+
element: element,
100+
scrolledIn: false,
101+
interacted: false
102+
};
103+
element.addEventListener('scroll', function () {
104+
item.interacted = true;
105+
_this.updateItem(item);
106+
});
107+
(0, _util.append)(element, '<div class="scroll-hint"><span></span></div>');
108+
_this.items.push(item);
109+
});
110+
window.addEventListener('scroll', function () {
111+
_this.updateItems();
112+
});
113+
window.addEventListener('resize', function () {
114+
_this.updateItems();
115+
});
116+
this.updateItems();
117+
}
118+
119+
_createClass(ScrollHint, [{
120+
key: 'canScroll',
121+
value: function canScroll(item) {
122+
var element = item.element,
123+
scrolledIn = item.scrolledIn,
124+
interacted = item.interacted;
125+
126+
return !interacted && scrolledIn && element.offsetHeight === element.scrollHeight && element.clientWidth <= element.scrollWidth;
127+
}
128+
}, {
129+
key: 'updateItems',
130+
value: function updateItems() {
131+
var _this2 = this;
132+
133+
[].forEach.call(this.items, function (item) {
134+
_this2.updateItem(item);
135+
});
136+
}
137+
}, {
138+
key: 'checkPosition',
139+
value: function checkPosition(item) {
140+
var element = item.element,
141+
scrolledIn = item.scrolledIn,
142+
interacted = item.interacted;
143+
144+
if (scrolledIn) {
145+
return;
146+
}
147+
if ((0, _util.getOffset)(element).top < (0, _util.getScrollTop)() + window.innerHeight) {
148+
item.scrolledIn = true;
149+
}
150+
}
151+
}, {
152+
key: 'updateItem',
153+
value: function updateItem(item) {
154+
var opt = this.opt;
155+
var element = item.element;
156+
157+
this.checkPosition(item);
158+
if (this.canScroll(item)) {
159+
(0, _util.addClass)(element, opt.scrollableClass);
160+
} else {
161+
(0, _util.removeClass)(element, opt.scrollableClass);
162+
}
163+
}
164+
}]);
165+
166+
return ScrollHint;
167+
}();
168+
169+
exports.default = ScrollHint;
170+
module.exports = exports['default'];
171+
172+
},{"./util":3,"es6-object-assign":1}],3:[function(require,module,exports){
173+
'use strict';
174+
175+
Object.defineProperty(exports, "__esModule", {
176+
value: true
177+
});
178+
var append = exports.append = function append(element, string) {
179+
var div = document.createElement('div');
180+
div.innerHTML = string;
181+
while (div.children.length > 0) {
182+
element.appendChild(div.children[0]);
183+
}
184+
};
185+
186+
var addClass = exports.addClass = function addClass(element, className) {
187+
if (element.classList) {
188+
element.classList.add(className);
189+
} else {
190+
element.className += ' ' + className;
191+
}
192+
};
193+
194+
var removeClass = exports.removeClass = function removeClass(element, className) {
195+
if (element.classList) {
196+
element.classList.remove(className);
197+
} else {
198+
element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
199+
}
200+
};
201+
202+
var getScrollTop = exports.getScrollTop = function getScrollTop() {
203+
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
204+
};
205+
206+
var getScrollLeft = exports.getScrollLeft = function getScrollLeft() {
207+
return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
208+
};
209+
210+
var getOffset = exports.getOffset = function getOffset(el) {
211+
var rect = el.getBoundingClientRect();
212+
return {
213+
top: rect.top + getScrollTop(),
214+
left: rect.left + getScrollLeft()
215+
};
216+
};
217+
218+
},{}]},{},[2])(2)
219+
});

build/scroll-hint.min.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)