Skip to content

Commit

Permalink
Cleanup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogasparin committed Jun 26, 2017
1 parent 95b72e1 commit 2948aee
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 89 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
25 changes: 13 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html>
<html>
<head>
<meta charset="utf-8">
<meta name="MobileOptimized" content="320">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="user-scalable=no, initial-scale=1.0">
<title>Optiscroll.js</title>

<link rel="stylesheet" href="dist/optiscroll.css">
<style type="text/css">
* { box-sizing: border-box; }
Expand All @@ -20,7 +20,7 @@
#os1 p { transition: all 2s ease 0s; max-width: 99em; max-height: 99em; }
.collapse { max-width: 0 !important; max-height: 0 !important; overflow: hidden; }
</style>

<script type="text/javascript" src="src/optiscroll.js"></script>
<script type="text/javascript" src="src/events.js"></script>
<script type="text/javascript" src="src/scrollbar.js"></script>
Expand All @@ -30,14 +30,14 @@
<body>

<div id="m-wrapper" class="m-wrapper optiscroll">

<h1>Optiscroll</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut id nibh dictum ex ultrices pellentesque non eget eros. Sed pellentesque in lorem ac porttitor. Phasellus consectetur risus eu quam pellentesque, at malesuada odio hendrerit. Morbi vitae commodo lectus. In hac habitasse platea dictumst. Quisque placerat arcu ac risus pretium, a efficitur elit hendrerit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</p>

<h2>Nested</h2>

<div id="os1" class="optiscroll column">
<div id="os1-content" class="optiscroll-content">
<p style="width: 150%">
Expand Down Expand Up @@ -75,27 +75,28 @@ <h2>Lorem</h2>
</p>

<script type="text/javascript">
var os1 = new Optiscroll(document.getElementById('os1'), {
var os1 = new Optiscroll(document.getElementById('os1'), {
maxTrackSize: 70,
preventParentScroll: true,
preventParentScroll: true,
wrapContent: false,
forceScrollbars: true,
});
setInterval(function () {
document.querySelector('#os1-content p').classList.toggle('collapse');
}, 5000);

var os2 = new Optiscroll(document.getElementById('os2'), {
var os2 = new Optiscroll(document.getElementById('os2'), {
maxTrackSize: 70,
preventParentScroll: true,
preventParentScroll: true,
wrapContent: false,
});
</script>

</div>

<script type="text/javascript">
var wr = new Optiscroll(document.getElementById('m-wrapper'), { forceScrollbars: true });
</script>

</body>
</html>
</html>
12 changes: 6 additions & 6 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var Events = {

scroll: function (ev) {

if (!G.pauseCheck) {
this.fireCustomEvent('scrollstart');
}
G.pauseCheck = true;

this.scrollbars.v.update();
this.scrollbars.h.update();

this.fireCustomEvent('scroll');

clearTimeout(this.cache.timerStop);
this.cache.timerStop = setTimeout(Events.scrollStop.bind(this), this.settings.scrollStopDelay);
},
Expand All @@ -21,7 +21,7 @@ var Events = {
G.pauseCheck = false;
this.scrollbars.v.update();
this.scrollbars.h.update();

Events.wheel.call(this, ev);
},

Expand All @@ -41,12 +41,12 @@ var Events = {

wheel: function (ev) {
var cache = this.cache,
cacheV = cache.v,
cacheV = cache.v,
cacheH = cache.h,
preventScroll = this.settings.preventParentScroll && G.isTouch;

window.cancelAnimationFrame(this.scrollAnimation);

if(preventScroll && cacheV.enabled && cacheV.percent % 100 === 0) {
this.scrollEl.scrollTop = cacheV.percent ? (cache.scrollH - cache.clientH - 1) : 1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ function getScrollbarSpec () {
outerEl.appendChild(innerEl);
htmlEl.appendChild(outerEl);
width = outerEl.offsetWidth - outerEl.clientWidth;
if (outerEl.scrollLeft > 0) {
if (outerEl.scrollLeft > 0) {
rtl = 0; // webkit is default
} else {
outerEl.scrollLeft = 1;
if (outerEl.scrollLeft === 0) {
if (outerEl.scrollLeft === 0) {
rtl = -1; // firefox is negative
}
}
htmlEl.removeChild(outerEl);

return { width: width, rtl: rtl };
}

Expand All @@ -56,7 +56,7 @@ function cssTest (prop) {
var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
el = document.createElement('test'),
props = [prop, 'Webkit' + ucProp];

for (var i in props) {
if(el.style[props[i]] !== undefined) { return props[i]; }
}
Expand All @@ -68,7 +68,7 @@ function cssTest (prop) {
function toggleClass (el, value, bool) {
var classes = el.className.split(/\s+/),
index = classes.indexOf(value);

if(bool) {
~index || classes.push(value);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/intro.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
;(function ( window, document, Math, undefined ) {
'use strict';
'use strict';
6 changes: 3 additions & 3 deletions src/jquery.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/

(function ($) {

var pluginName = 'optiscroll';

$.fn[pluginName] = function(options) {
var method, args;

if(typeof options === 'string') {
args = Array.prototype.slice.call(arguments);
method = args.shift();
Expand All @@ -31,7 +31,7 @@
inst = new window.Optiscroll(this, options || {});
$el.data(pluginName, inst);
}
// allow exec method on instance
// allow exec method on instance
else if(inst && typeof method === 'string') {
inst[method].apply(inst, args);
if(method === 'destroy') {
Expand Down
36 changes: 18 additions & 18 deletions src/optiscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Optiscroll = function Optiscroll(element, options) {
};



var GS = Optiscroll.globalSettings = {
scrollMinUpdateInterval: 1000 / 40, // 40 FPS
checkFrequency: 1000,
Expand All @@ -34,13 +34,13 @@ Optiscroll.defaults = {

Optiscroll.Instance = function (element, options) {
// instance variables
this.element = element;
this.element = element;
this.settings = _extend(_extend({}, Optiscroll.defaults), options || {});
if (typeof options.rtl !== 'boolean') {
this.settings.rtl = window.getComputedStyle(element).direction === 'rtl';
}
this.cache = {};

this.init();
};

Expand All @@ -53,24 +53,24 @@ Optiscroll.Instance.prototype = {
var element = this.element,
settings = this.settings,
shouldCreateScrollbars = false;
var scrollEl = this.scrollEl = settings.wrapContent
? Utils.createWrapper(element)

var scrollEl = this.scrollEl = settings.wrapContent
? Utils.createWrapper(element)
: element.firstElementChild;

toggleClass(scrollEl, settings.classPrefix + 'content', true);
toggleClass(element, 'is-enabled' + (settings.rtl ? ' is-rtl' : ''), true);

// initialize scrollbars
this.scrollbars = {
this.scrollbars = {
v: Scrollbar('v', this),
h: Scrollbar('h', this),
};

// create DOM scrollbars only if they have size or if it's forced
if(G.scrollbarSpec.width || settings.forceScrollbars) {
shouldCreateScrollbars = Utils.hideNativeScrollbars(scrollEl, settings.rtl);
}
}

if(shouldCreateScrollbars) {
_invoke(this.scrollbars, 'create');
Expand Down Expand Up @@ -98,7 +98,7 @@ Optiscroll.Instance.prototype = {

},



bind: function () {
var listeners = this.listeners = {},
Expand Down Expand Up @@ -132,10 +132,10 @@ Optiscroll.Instance.prototype = {
cH = scrollEl.clientHeight,
sW = scrollEl.scrollWidth,
cW = scrollEl.clientWidth;
if(sH !== cache.scrollH || cH !== cache.clientH ||

if(sH !== cache.scrollH || cH !== cache.clientH ||
sW !== cache.scrollW || cW !== cache.clientW) {

cache.scrollH = sH;
cache.clientH = cH;
cache.scrollW = sW;
Expand Down Expand Up @@ -175,7 +175,7 @@ Optiscroll.Instance.prototype = {

startX = this.scrollEl.scrollLeft;
startY = this.scrollEl.scrollTop;

endX = +destX;
if(destX === 'left') { endX = 0; }
if(destX === 'right') { endX = cache.scrollW - cache.clientW; }
Expand All @@ -188,7 +188,7 @@ Optiscroll.Instance.prototype = {

// animate
this.animateScroll(startX, endX, startY, endY, +duration);

},


Expand Down Expand Up @@ -227,7 +227,7 @@ Optiscroll.Instance.prototype = {
topEdge = offsetY - (delta.top || 0);
rightEdge = offsetX + eDim.width - this.cache.clientW + (delta.right || 0);
bottomEdge = offsetY + eDim.height - this.cache.clientH + (delta.bottom || 0);

if(leftEdge < startX) { endX = leftEdge; }
if(rightEdge > startX) { endX = rightEdge; }

Expand Down Expand Up @@ -260,11 +260,11 @@ Optiscroll.Instance.prototype = {
// 500px in 430ms, 1000px in 625ms, 2000px in 910ms
duration = Math.pow(Math.max(Math.abs(endX - startX), Math.abs(endY - startY)), 0.54) * 15;
}

(function animate () {
var time = Math.min(1, ((Date.now() - startTime) / duration)),
easedTime = Utils.easingFunction(time);

if(endY !== startY) {
scrollEl.scrollTop = ~~(easedTime * (endY - startY)) + startY;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ Optiscroll.Instance.prototype = {
var cache = this.cache,
sH = cache.scrollH, sW = cache.scrollW,
eventData;

eventData = {
// scrollbars data
scrollbarV: _extend({}, cache.v),
Expand Down
6 changes: 3 additions & 3 deletions src/outro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
return Optiscroll;
});
}

// commonjs export
if(typeof module !== 'undefined' && module.exports) {
module.exports = Optiscroll;
}

window.Optiscroll = Optiscroll;

})(window, document, Math);
})(window, document, Math);
Loading

0 comments on commit 2948aee

Please sign in to comment.