From 0aa693bacb0d5c726c3f5a273bd5db193f0b4449 Mon Sep 17 00:00:00 2001 From: "venkateshwar@divami.com" Date: Mon, 27 Nov 2017 11:24:03 +0530 Subject: [PATCH] Add gulp and minification task --- .gitignore | 1 + README.md | 4 +- slimscroll.js => dist/slimscroll.js | 0 dist/slimscroll.min.js | 1 + gulpfile.js | 15 ++ package.json | 6 +- slimscroll.min.js | 2 - src/slimscroll.js | 290 +++++++++++++++++++++++++++ {test => tests/test1}/index.html | 2 +- {test => tests/test1}/slimscroll.css | 0 {test2 => tests/test2}/index.html | 2 +- 11 files changed, 316 insertions(+), 7 deletions(-) create mode 100644 .gitignore rename slimscroll.js => dist/slimscroll.js (100%) create mode 100644 dist/slimscroll.min.js create mode 100644 gulpfile.js delete mode 100644 slimscroll.min.js create mode 100644 src/slimscroll.js rename {test => tests/test1}/index.html (99%) rename {test => tests/test1}/slimscroll.css (100%) rename {test2 => tests/test2}/index.html (96%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index b467d46..a2ae3f5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Slim-scroll (_JavaScript Scroll Library_) ~ 5KB compressed +# Slim-scroll (_JavaScript Scroll Library_) ~ 4KB compressed Slim scroll is a replacement of default scrollbar provided by browsers on Windows. This library lets you design the scroll-bar by using simple css properties. It is created using javascript and css. -[Download](https://github.com/kamlekar/slim-scroll/releases/latest)  |  [Github](https://github.com/venkateshwar/slim-scroll/)  |  [Demo](https://rawgit.com/venkateshwar/slim-scroll/master/test/index.html)   |   [CDNjs](https://cdnjs.com/libraries/slim-scroll) +[Download](https://github.com/kamlekar/slim-scroll/releases/latest)  |  [Github](https://github.com/venkateshwar/slim-scroll/)  |  [Demo](https://rawgit.com/venkateshwar/slim-scroll/master/tests/test1/index.html)   |   [CDNjs](https://cdnjs.com/libraries/slim-scroll) **Tested on**: IE9+, Chrome and Firefox. diff --git a/slimscroll.js b/dist/slimscroll.js similarity index 100% rename from slimscroll.js rename to dist/slimscroll.js diff --git a/dist/slimscroll.min.js b/dist/slimscroll.min.js new file mode 100644 index 0000000..0a47e05 --- /dev/null +++ b/dist/slimscroll.min.js @@ -0,0 +1 @@ +var slimScroll=function(e,t){var n={},o=this,i="wrapper",r="scrollBar",s="scrollBarContainer",l="data-slimscroll",a="scrollTop",c="parentElement",u="innerHTML",d="parentNode",p="srcElement",f=function(e){if(o.initInProcess||(o.initDone||o.init(),B(n[i]))){n[i].setAttribute("style","overflow: hidden !important");var t=n.E;n.h=n[s].offsetHeight,n.sH=n[i].scrollHeight,n.sP=n.h/n.sH*100,n.sbh=n.sP*n.h/100,t.sH?n.sP1=t.sH/n.h*100:n.sP1=n.sbhn.rP1?u=n.rP1:u<0&&(u=0),n[r].style.top=u+"%",n[i][a]=u*n.sH1,m(n[s],l.S+l.a)}},S=function(e){var t=window.getSelection?window.getSelection():document.selection;t&&(t.removeAllRanges?t.removeAllRanges():t.empty&&t.empty());(e=e||event).currentTarget||e[p];return w("mousemove",document,x),w("mouseup",document,P),n.offsetTop=T(n[i]),n.firstY=e.pageY||event.clientY,n.reposition||(n.reposition=H(n[r],n.h)),!1},H=function(e,t){var n=parseInt(e.style.top.replace("%",""),10)*t/100;return n||0},x=function(e){var e=e||event,t=n.E,o=e.pageY||e.clientY,l=(n.reposition+o-n.firstY)/n.h*100;n.rP1=0&&n.firstY>n.offsetTop;(n.previousTop>l&&c||c&&n[i][a]+n.h!==n.sH)&&(n[r].style.top=l+"%",n.previousTop=l,n[i][a]=l*n.sH1),m(n[s],t.S)},P=function(e){var e=e||event,t=n.E;b("mousemove",document),b("mouseup",document),n.reposition=0,m(n[s],t.S+t.a)},y=function(e){e=e||event;if(n){var t=n.E;m(n[s],t.S),n[r].style.top=n[i][a]/n.sH1+"%",m(n[s],t.S+t.a)}},w=function(e,t,n){t["on"+e]=n},b=function(e,t){t["on"+e]=null},C=function(e,t,n,o){e.insertRule?e.insertRule(t+"{"+n+"}",o):e.addRule&&e.addRule(t,n,o)},T=function(e){var t=document.documentElement[a];return e.getBoundingClientRect().top+(t||document.body[a])},E=function(){if(e.removeAttribute(l),o.isSlimScrollInserted){var t=e.firstChild.innerHTML;t&&(e.innerHTML=t)}o.isSlimScrollInserted=!1,o.initDone=!1},B=function(t){return t||(t=e),t.offsetHeightdiv",i,0),C(u,e+">div+div",r,0),C(u,"[data-scrollbar]",s,0)):a.styleSheet.cssText=e+">div{"+i+"}"+e+">div+div{"+r+"}"+e+">div+div>div{"+s+"}",o.isSlimScrollInserted=!0,window.slimScrollStylesApplied=!0}}();var a=e[u],c=n.E={};t=t||{},c.w=t.wrapperClass||"",c.s=t.scrollBarClass||"",c.S=t.scrollBarContainerClass||"",c.a=t.scrollBarContainerSpecialClass?" "+t.scrollBarContainerSpecialClass:"",c.mH=t.scrollBarMinHeight||25,c.sH=t.scrollBarFixedHeight,e[u]="",n[i]=h(c.w,a,e),n[s]=h(c.S+c.a,"",e),n[r]=h(c.s,"",n[s]),v(n[r],"data-scrollbar","1"),f(),Y(),t.keepFocus&&(v(n[i],"tabindex","-1"),n[i].focus()),w("mousedown",n[r],S),w("click",n[s],g),w("scroll",n[i],y),o.initInProcess=!1}else E()},Y=function(){n[i].style.overflow="";var e=n[i].offsetWidth-n[i].clientWidth;n[i].style.right=-e+"px",o.isSlimScrollInserted=!0,t.keepFocus&&(v(n[i],"tabindex","-1"),n[i].focus())};return o.resetValues=function(){Object.keys(n).length?(f(),Y()):f()},o.init=I,I(),o}; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..6a2fbf4 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,15 @@ +var minify = require('gulp-minify'); +var gulp = require('gulp'); + +gulp.task('default', function() { + gulp.src('src/*.js') + .pipe(minify({ + ext:{ + src:'.js', + min:'.min.js' + }, + exclude: ['tasks'], + ignoreFiles: ['.combo.js', '-min.js'] + })) + .pipe(gulp.dest('dist')) +}); \ No newline at end of file diff --git a/package.json b/package.json index 7167438..7d07120 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,9 @@ "bugs": { "url": "https://github.com/kamlekar/slim-scroll/issues" }, - "homepage": "https://github.com/kamlekar/slim-scroll#readme" + "homepage": "https://github.com/kamlekar/slim-scroll#readme", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-minify": "^2.1.0" + } } diff --git a/slimscroll.min.js b/slimscroll.min.js deleted file mode 100644 index b888d70..0000000 --- a/slimscroll.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*** slimscroll.min.js ***/ -var slimScroll=function(n,Y){var R={},f=this,G="wrapper",H="scrollBar",h="scrollBarContainer",W="",L="",N="data-slimscroll",Q="offsetTop",v="scrollTop",E="parentElement",M="previousElementSibling",X="innerHTML",I="currentTarget",A="scroll-k",g="%",T=".",x="parentNode",u="previousSibling",F="srcElement",O=function(a){if(!f.initInProcess){if(!f.initDone){f.init()}if(!B(R[G])){o();return}}R[G].setAttribute("style","overflow: hidden !important");var d=R.E;R.h=R[h].offsetHeight;R.sH=R[G].scrollHeight;R.sP=(R.h/R.sH)*100;R.sbh=R.sP*R.h/100;if(!d.sH){R.sP1=R.sbhR.rP1){l=R.rP1}else{if(l<0){l=0}}R[H].style.top=l+g;R[G][v]=l*R.sH1;r(R[h],i.S+i.a)},q=function(i){var d=window.getSelection?window.getSelection():document.selection;if(d){if(d.removeAllRanges){d.removeAllRanges()}else{if(d.empty){d.empty()}}}var i=i||event,a=i[I]||i[F];k("mousemove",document,D);k("mouseup",document,j);R[Q]=b(R[G]);R.firstY=i.pageY||event.clientY;if(!R.reposition){R.reposition=e(R[H],R.h)}return !1},e=function(d,l){var a=parseInt(d.style.top.replace(g,""),10)*l/100;return a?a:0},D=function(m){var m=m||event,i=R.E,a=m.pageY||m.clientY,l=(R.reposition+a-R.firstY)/R.h*100;if(R.rP1=0&&R.firstY>R[Q];if((R.previousTop>l&&d)||(d&&(R[G][v]+R.h!==R.sH))){R[H].style.top=l+g;R.previousTop=l;R[G][v]=l*R.sH1}r(R[h],i.S)},j=function(d){var d=d||event,a=R.E;c("mousemove",document);c("mouseup",document);R.reposition=0;r(R[h],a.S+a.a)},p=function(d){var d=d||event;if(!R){return}var a=R.E;r(R[h],a.S);R[H].style.top=R[G][v]/R.sH1+g;r(R[h],a.S+a.a)},k=function(i,a,d){a["on"+i]=d},c=function(d,a){a["on"+d]=null},y=function(d,l,m,a){if(d.insertRule){d.insertRule(l+"{"+m+"}",a)}else{if(d.addRule){d.addRule(l,m,a)}}},b=function(d){var a=document.documentElement[v];return d.getBoundingClientRect().top+(a?a:document.body[v])},z=function(){if(!window.slimScrollStylesApplied){if(f.isSlimScrollInserted){f.initInProcess=!1;return}var l="["+N+"]",d=" !important",m="position:absolute"+d,ab=m+";overflow:auto"+d+";left:0px;top:0px"+d+";right:0px;bottom:0px"+d+";padding-right:8px"+d+";",C=m+";top:0px"+d+";bottom:0px"+d+";right:0px;left:auto;width:5px;cursor:pointer"+d+";padding-right:0px"+d+";",ac=m+";background-color:#999;top:0px;left:0px;right:0px;",i=document.createElement("style"),a="[data-scrollbar]";try{i.appendChild(document.createTextNode(""))}catch(Z){}var aa=document.head||document.getElementsByTagName("head")[0];aa.insertBefore(i,(aa.hasChildNodes())?aa.childNodes[0]:null);var U=i.sheet;if(U){y(U,l+">div",ab,0);y(U,l+">div+div",C,0);y(U,a,ac,0)}else{i.styleSheet.cssText=l+">div{"+ab+"}"+l+">div+div{"+C+"}"+l+">div+div>div{"+ac+"}"}f.isSlimScrollInserted=!0;window.slimScrollStylesApplied=!0}},o=function(){n.removeAttribute(N);if(f.isSlimScrollInserted){n.innerHTML=n.firstChild.innerHTML}f.isSlimScrollInserted=!1;f.initDone=!1},B=function(a){if(!a){a=n}return a.offsetHeight