Skip to content
Browse files

Version bump and code formatting tweaks

  • Loading branch information...
1 parent b6e80f6 commit 103f1a1d799c1b0a0bf123d14b0242e1f4d84159 @jnicol committed Apr 29, 2014
Showing with 7 additions and 38 deletions.
  1. +1 −0 .gitignore
  2. +5 −10 jquery.trackpad-scroll-emulator.js
  3. +1 −28 jquery.trackpad-scroll-emulator.min.js
View
1 .gitignore
@@ -0,0 +1 @@
+config.codekit
View
15 jquery.trackpad-scroll-emulator.js
@@ -1,12 +1,12 @@
/**
* TrackpadScrollEmulator
- * Version: 1.0.4
+ * Version: 1.0.5
* Author: Jonathan Nicol @f6design
* https://github.com/jnicol/trackpad-scroll-emulator
*
* The MIT License
*
- * Copyright (c) 2012-2013 Jonathan Nicol
+ * Copyright (c) 2012-2014 Jonathan Nicol
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -147,18 +147,13 @@
var jumpAmt = pageJumpMultp * $scrollContentEl[sizeAttr]();
// Calculate where along the scrollbar the user clicked.
- var eventOffset = e.originalEvent.layerY;
- if (scrollDirection === 'horiz') {
- eventOffset = e.originalEvent.layerX;
- }
+ var eventOffset = (scrollDirection === 'vert') ? e.originalEvent.layerY : e.originalEvent.layerX;
+
// Get the position of the top (or left) of the drag handle.
var dragHandleOffset = $dragHandleEl.position()[offsetAttr];
// Determine which direction to scroll.
- var scrollPos = $scrollContentEl[scrollOffsetAttr]() + jumpAmt;
- if (eventOffset < dragHandleOffset) {
- scrollPos = $scrollContentEl[scrollOffsetAttr]() - jumpAmt;
- }
+ var scrollPos = (eventOffset < dragHandleOffset) ? $scrollContentEl[scrollOffsetAttr]() - jumpAmt : $scrollContentEl[scrollOffsetAttr]() + jumpAmt;
$scrollContentEl[scrollOffsetAttr](scrollPos);
}
View
29 jquery.trackpad-scroll-emulator.min.js
@@ -1,28 +1 @@
-/**
- * TrackpadScrollEmulator
- * Version: 1.0.4
- * Author: Jonathan Nicol @f6design
- * https://github.com/jnicol/trackpad-scroll-emulator
- *
- * The MIT License
- *
- * Copyright (c) 2012-2013 Jonathan Nicol
- *
- * 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.
- */(function(e){function n(n,r){function m(){if(s.hasClass("horizontal")){h="horiz";p="scrollLeft";d="width";v="left"}s.prepend('<div class="tse-scrollbar"><div class="drag-handle"></div></div>');a=s.find(".tse-scrollbar");f=s.find(".drag-handle");if(r.wrapContent){u.wrap('<div class="tse-scroll-content" />')}o=s.find(".tse-scroll-content");N();if(r.autoHide){s.on("mouseenter",S)}f.on("mousedown",g);o.on("scroll",w);E();e(window).on("resize",function(){k()});if(!r.autoHide){x()}}function g(t){t.preventDefault();var n=t.pageY;if(h==="horiz"){n=t.pageX}l=n-f.offset()[v];e(document).on("mousemove",y);e(document).on("mouseup",b)}function y(e){e.preventDefault();var t=e.pageY;if(h==="horiz"){t=e.pageX}var n=t-a.offset()[v]-l;var r=n/a[d]();var i=r*u[d]();o[p](i)}function b(){e(document).off("mousemove",y);e(document).off("mouseup",b)}function w(e){S()}function E(){var e=u[d]();var t=o[p]();var n=a[d]();var r=n/e;var i=Math.round(r*t)+2;var s=Math.floor(r*(n-2))-2;if(n<e){if(h==="vert"){f.css({top:i,height:s})}else{f.css({left:i,width:s})}a.show()}else{a.hide()}}function S(){E();x()}function x(){f.addClass("visible");if(!r.autoHide){return}if(typeof c==="number"){window.clearTimeout(c)}c=window.setTimeout(function(){T()},1e3)}function T(){f.removeClass("visible");if(typeof c==="number"){window.clearTimeout(c)}}function N(){if(h==="vert"){o.width(s.width()+C());o.height(s.height())}else{o.width(s.width());o.height(s.height()+C());u.height(s.height())}}function C(){var t=e('<div class="scrollbar-width-tester" style="width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');e("body").append(t);var n=e(t).innerWidth();var r=e("div",t).innerWidth();t.remove();return n-r}function k(){N();E()}function L(e,t){if(t){r[e]=t}else{return r[e]}}function A(){u.insertBefore(a);a.remove();o.remove();u.css({height:s.height()+"px","overflow-y":"scroll"});O("onDestroy");s.removeData("plugin_"+t)}function O(e){if(r[e]!==undefined){r[e].call(i)}}var i=n;var s=e(n);var o;var u=s.find(".tse-content");var a;var f;var l;var c;var h="vert";var p="scrollTop";var d="height";var v="top";r=e.extend({},e.fn[t].defaults,r);m();return{option:L,destroy:A,recalculate:k}}var t="TrackpadScrollEmulator";e.fn[t]=function(r){if(typeof arguments[0]==="string"){var i=arguments[0];var s=Array.prototype.slice.call(arguments,1);var o;this.each(function(){if(e.data(this,"plugin_"+t)&&typeof e.data(this,"plugin_"+t)[i]==="function"){o=e.data(this,"plugin_"+t)[i].apply(this,s)}else{throw new Error("Method "+i+" does not exist on jQuery."+t)}});if(o!==undefined){return o}else{return this}}else if(typeof r==="object"||!r){return this.each(function(){if(!e.data(this,"plugin_"+t)){e.data(this,"plugin_"+t,new n(this,r))}})}};e.fn[t].defaults={onInit:function(){},onDestroy:function(){},wrapContent:true,autoHide:true}})(jQuery)
+!function(t){function e(e,n){function i(){x.hasClass("horizontal")&&(j="horiz",M="scrollLeft",X="width",Y="left"),x.prepend('<div class="tse-scrollbar"><div class="drag-handle"></div></div>'),C=x.find(".tse-scrollbar"),D=x.find(".drag-handle"),n.wrapContent&&z.wrap('<div class="tse-scroll-content" />'),_=x.find(".tse-scroll-content"),p(),n.autoHide&&x.on("mouseenter",c),D.on("mousedown",r),C.on("mousedown",u),_.on("scroll",l),d(),t(window).on("resize",function(){g()}),n.autoHide||f()}function r(e){e.preventDefault();var o=e.pageY;"horiz"===j&&(o=e.pageX),T=o-D.offset()[Y],t(document).on("mousemove",a),t(document).on("mouseup",s)}function a(t){t.preventDefault();var e=t.pageY;"horiz"===j&&(e=t.pageX);var o=e-C.offset()[Y]-T,n=o/C[X](),i=n*z[X]();_[M](i)}function s(){t(document).off("mousemove",a),t(document).off("mouseup",s)}function u(t){if(t.target!==D[0]){var e=H*_[X](),o="vert"===j?t.originalEvent.layerY:t.originalEvent.layerX,n=D.position()[Y],i=n>o?_[M]()-e:_[M]()+e;_[M](i)}}function l(t){c()}function d(){var t=z[X](),e=_[M](),o=C[X](),n=o/t,i=Math.round(n*e)+2,r=Math.floor(n*(o-2))-2;t>o?(D.css("vert"===j?{top:i,height:r}:{left:i,width:r}),C.show()):C.hide()}function c(){d(),f()}function f(){D.addClass("visible"),n.autoHide&&("number"==typeof E&&window.clearTimeout(E),E=window.setTimeout(function(){h()},1e3))}function h(){D.removeClass("visible"),"number"==typeof E&&window.clearTimeout(E)}function p(){"vert"===j?(_.width(x.width()+v()),_.height(x.height())):(_.width(x.width()),_.height(x.height()+v()),z.height(x.height()))}function v(){var e=t('<div class="scrollbar-width-tester" style="width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');t("body").append(e);var o=t(e).innerWidth(),n=t("div",e).innerWidth();return e.remove(),o-n}function g(){p(),d()}function m(t,e){return e?void(n[t]=e):n[t]}function w(){z.insertBefore(C),C.remove(),_.remove(),z.css({height:x.height()+"px","overflow-y":"scroll"}),y("onDestroy"),x.removeData("plugin_"+o)}function y(t){void 0!==n[t]&&n[t].call(b)}var b=e,x=t(e),_,z=x.find(".tse-content"),C,D,T,E,H=7/8,j="vert",M="scrollTop",X="height",Y="top";return n=t.extend({},t.fn[o].defaults,n),i(),{option:m,destroy:w,recalculate:g}}var o="TrackpadScrollEmulator";t.fn[o]=function(n){if("string"==typeof arguments[0]){var i=arguments[0],r=Array.prototype.slice.call(arguments,1),a;return this.each(function(){if(!t.data(this,"plugin_"+o)||"function"!=typeof t.data(this,"plugin_"+o)[i])throw new Error("Method "+i+" does not exist on jQuery."+o);a=t.data(this,"plugin_"+o)[i].apply(this,r)}),void 0!==a?a:this}return"object"!=typeof n&&n?void 0:this.each(function(){t.data(this,"plugin_"+o)||t.data(this,"plugin_"+o,new e(this,n))})},t.fn[o].defaults={onInit:function(){},onDestroy:function(){},wrapContent:!0,autoHide:!0}}(jQuery);

0 comments on commit 103f1a1

Please sign in to comment.
Something went wrong with that request. Please try again.