Skip to content

Commit f617bb9

Browse files
committed
Update plugin to version 3.0.8
1 parent e5b5c8c commit f617bb9

8 files changed

+280
-151
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "malihu-custom-scrollbar-plugin",
3-
"version": "3.0.7",
3+
"version": "3.0.8",
44
"title": "malihu custom scrollbar plugin",
55
"description": "Highly customizable custom scrollbar jQuery plugin, featuring vertical/horizontal scrollbars, scrolling momentum, mouse-wheel, keyboard and touch support, user defined callbacks etc.",
66
"main": [

jquery.mCustomScrollbar.concat.min.js

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

jquery.mCustomScrollbar.js

Lines changed: 132 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
== malihu jquery custom scrollbar plugin ==
3-
Version: 3.0.7
3+
Version: 3.0.8
44
Plugin URI: http://manos.malihu.gr/jquery-custom-content-scroller
55
Author: malihu
66
Author URI: http://manos.malihu.gr
@@ -36,23 +36,22 @@ the production-ready jquery.mCustomScrollbar.concat.min.js which contains the pl
3636
and dependencies (minified).
3737
*/
3838

39-
(function (factory) {
40-
if(typeof module !== 'undefined' && module.exports) {
41-
module.exports = factory;
42-
} else {
43-
factory(jQuery, window, document);
44-
}
39+
(function(factory){
40+
if(typeof module!=="undefined" && module.exports){
41+
module.exports=factory;
42+
}else{
43+
factory(jQuery,window,document);
44+
}
4545
}(function($){
46-
4746
(function(init){
4847
var _rjs=typeof define==="function" && define.amd, /* RequireJS */
49-
_njs=typeof module !== 'undefined' && module.exports, /* NodeJS */
48+
_njs=typeof module !== "undefined" && module.exports, /* NodeJS */
5049
_dlp=("https:"==document.location.protocol) ? "https:" : "http:", /* location protocol */
5150
_url="cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js";
5251
if(!_rjs){
53-
if (_njs) {
52+
if(_njs){
5453
require("jquery-mousewheel")($);
55-
} else {
54+
}else{
5655
/* load jquery-mousewheel plugin (via CDN) if it's not present or not loaded via RequireJS
5756
(works when mCustomScrollbar fn is called on window load) */
5857
$.event.special.mousewheel || $("head").append(decodeURI("%3Cscript src="+_dlp+"//"+_url+"%3E%3C/script%3E"));
@@ -782,12 +781,13 @@ and dependencies (minified).
782781
----------------------------------------
783782
*/
784783

785-
/* validates selector (if selector is invalid or undefined uses the default one) */
784+
/* validates selector (if selector is invalid or undefined uses the default one) */
786785
_selector=function(){
787786
return (typeof $(this)!=="object" || $(this).length<1) ? defaultSelector : this;
788787
},
789788
/* -------------------- */
790789

790+
791791
/* changes options according to theme */
792792
_theme=function(obj){
793793
var fixedSizeScrollbarThemes=["rounded","rounded-dark","rounded-dots","rounded-dots-dark"],
@@ -1135,12 +1135,12 @@ and dependencies (minified).
11351135
var t=e.type;
11361136
switch(t){
11371137
case "pointerdown": case "MSPointerDown": case "pointermove": case "MSPointerMove": case "pointerup": case "MSPointerUp":
1138-
return [e.originalEvent.pageY,e.originalEvent.pageX,false];
1138+
return e.target.ownerDocument!==document ? [e.originalEvent.screenY,e.originalEvent.screenX,false] : [e.originalEvent.pageY,e.originalEvent.pageX,false];
11391139
break;
11401140
case "touchstart": case "touchmove": case "touchend":
11411141
var touch=e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
11421142
touches=e.originalEvent.touches.length || e.originalEvent.changedTouches.length;
1143-
return [touch.pageY,touch.pageX,touches>1];
1143+
return e.target.ownerDocument!==document ? [touch.screenY,touch.screenX,touches>1] : [touch.pageY,touch.pageX,touches>1];
11441144
break;
11451145
default:
11461146
return [e.pageY,e.pageX,false];
@@ -1229,15 +1229,49 @@ and dependencies (minified).
12291229
mCSB_container=$("#mCSB_"+d.idx+"_container"),
12301230
mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
12311231
dragY,dragX,touchStartY,touchStartX,touchMoveY=[],touchMoveX=[],startTime,runningTime,endTime,distance,speed,amount,
1232-
durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag;
1233-
mCSB_container.bind("touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){
1232+
durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag,
1233+
iframe=mCSB_container.find("iframe"),
1234+
events=[
1235+
"touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace, //start
1236+
"touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace, //move
1237+
"touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace //end
1238+
];
1239+
mCSB_container.bind(events[0],function(e){
1240+
_onTouchstart(e);
1241+
}).bind(events[1],function(e){
1242+
_onTouchmove(e);
1243+
});
1244+
mCustomScrollBox.bind(events[0],function(e){
1245+
_onTouchstart2(e);
1246+
}).bind(events[2],function(e){
1247+
_onTouchend(e);
1248+
});
1249+
if(iframe.length){
1250+
iframe.each(function(){
1251+
$(this).load(function(){
1252+
/* bind events on accessible iframes */
1253+
if(_canAccessIFrame(this)){
1254+
$(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){
1255+
_onTouchstart(e);
1256+
_onTouchstart2(e);
1257+
}).bind(events[1],function(e){
1258+
_onTouchmove(e);
1259+
}).bind(events[2],function(e){
1260+
_onTouchend(e);
1261+
});
1262+
}
1263+
});
1264+
});
1265+
}
1266+
function _onTouchstart(e){
12341267
if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;}
12351268
touchable=1; touchDrag=0; docDrag=0;
12361269
var offset=mCSB_container.offset();
12371270
dragY=_coordinates(e)[0]-offset.top;
12381271
dragX=_coordinates(e)[1]-offset.left;
12391272
touchIntent=[_coordinates(e)[0],_coordinates(e)[1]];
1240-
}).bind("touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace,function(e){
1273+
}
1274+
function _onTouchmove(e){
12411275
if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;}
12421276
e.stopImmediatePropagation();
12431277
if(docDrag && !touchDrag){return;}
@@ -1260,8 +1294,8 @@ and dependencies (minified).
12601294
mCSB_container[0].idleTimer=250;
12611295
if(d.overflowed[0]){_drag(amount[0],durA,easing,"y","all",true);}
12621296
if(d.overflowed[1]){_drag(amount[1],durA,easing,"x",overwrite,true);}
1263-
});
1264-
mCustomScrollBox.bind("touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){
1297+
}
1298+
function _onTouchstart2(e){
12651299
if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;}
12661300
touchable=1;
12671301
e.stopImmediatePropagation();
@@ -1271,7 +1305,8 @@ and dependencies (minified).
12711305
touchStartY=_coordinates(e)[0]-offset.top;
12721306
touchStartX=_coordinates(e)[1]-offset.left;
12731307
touchMoveY=[]; touchMoveX=[];
1274-
}).bind("touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){
1308+
}
1309+
function _onTouchend(e){
12751310
if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;}
12761311
e.stopImmediatePropagation();
12771312
touchDrag=0; docDrag=0;
@@ -1295,7 +1330,7 @@ and dependencies (minified).
12951330
amount[1]=absDistance[1]>md ? amount[1] : 0;
12961331
if(d.overflowed[0]){_drag(amount[0],durB[0],easing,"y",overwrite,false);}
12971332
if(d.overflowed[1]){_drag(amount[1],durB[1],easing,"x",overwrite,false);}
1298-
});
1333+
}
12991334
function _m(ds,s){
13001335
var r=[s*1.5,s*2,s/1.5,s/2];
13011336
if(ds>90){
@@ -1376,67 +1411,74 @@ and dependencies (minified).
13761411
via mouse-wheel plugin (https://github.com/brandonaaron/jquery-mousewheel)
13771412
*/
13781413
_mousewheel=function(){
1379-
var $this=$(this),d=$this.data(pluginPfx);
1414+
var $this=$(this),d=$this.data(pluginPfx),o=d.opt,
1415+
namespace=pluginPfx+"_"+d.idx,
1416+
mCustomScrollBox=$("#mCSB_"+d.idx),
1417+
mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
1418+
iframe=$("#mCSB_"+d.idx+"_container").find("iframe");
13801419
if(d){ /* Check if the scrollbar is ready to use mousewheel events (issue: #185) */
1381-
var o=d.opt,
1382-
namespace=pluginPfx+"_"+d.idx,
1383-
mCustomScrollBox=$("#mCSB_"+d.idx),
1384-
mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")],
1385-
iframe=$("#mCSB_"+d.idx+"_container").find("iframe"),
1386-
el=mCustomScrollBox /* mousewheel element selector */;
1387-
/* check for cross domain iframes and bind mousewheel event on them in addition to default mousewheel element selector */
13881420
if(iframe.length){
13891421
iframe.each(function(){
1390-
var iFobj=this;
1391-
if(_canAccessIFrame(iFobj)){ /* check if iframe can be accessed */
1392-
el=el.add($(iFobj).contents().find("body"));
1393-
}
1422+
$(this).load(function(){
1423+
/* bind events on accessible iframes */
1424+
if(_canAccessIFrame(this)){
1425+
$(this.contentDocument || this.contentWindow.document).bind("mousewheel."+namespace,function(e,delta){
1426+
_onMousewheel(e,delta);
1427+
});
1428+
}
1429+
});
13941430
});
13951431
}
1396-
el.bind("mousewheel."+namespace,function(e,delta){
1397-
_stop($this);
1398-
if(_disableMousewheel($this,e.target)){return;} /* disables mouse-wheel when hovering specific elements */
1399-
var deltaFactor=o.mouseWheel.deltaFactor!=="auto" ? parseInt(o.mouseWheel.deltaFactor) : (oldIE && e.deltaFactor<100) ? 100 : e.deltaFactor || 100;
1400-
if(o.axis==="x" || o.mouseWheel.axis==="x"){
1401-
var dir="x",
1402-
px=[Math.round(deltaFactor*d.scrollRatio.x),parseInt(o.mouseWheel.scrollAmount)],
1403-
amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.width() ? mCustomScrollBox.width()*0.9 : px[0],
1404-
contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetLeft),
1405-
draggerPos=mCSB_dragger[1][0].offsetLeft,
1406-
limit=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(),
1407-
dlt=e.deltaX || e.deltaY || delta;
1408-
}else{
1409-
var dir="y",
1410-
px=[Math.round(deltaFactor*d.scrollRatio.y),parseInt(o.mouseWheel.scrollAmount)],
1411-
amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.height() ? mCustomScrollBox.height()*0.9 : px[0],
1412-
contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetTop),
1413-
draggerPos=mCSB_dragger[0][0].offsetTop,
1414-
limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(),
1415-
dlt=e.deltaY || delta;
1416-
}
1417-
if((dir==="y" && !d.overflowed[0]) || (dir==="x" && !d.overflowed[1])){return;}
1418-
if(o.mouseWheel.invert){dlt=-dlt;}
1419-
if(o.mouseWheel.normalizeDelta){dlt=dlt<0 ? -1 : 1;}
1420-
if((dlt>0 && draggerPos!==0) || (dlt<0 && draggerPos!==limit) || o.mouseWheel.preventDefault){
1421-
e.stopImmediatePropagation();
1422-
e.preventDefault();
1423-
}
1424-
_scrollTo($this,(contentPos-(dlt*amount)).toString(),{dir:dir});
1432+
mCustomScrollBox.bind("mousewheel."+namespace,function(e,delta){
1433+
_onMousewheel(e,delta);
14251434
});
14261435
}
1427-
/* check if iframe can be accessed */
1428-
function _canAccessIFrame(iframe){
1429-
var html=null;
1430-
try{
1431-
var doc=iframe.contentDocument || iframe.contentWindow.document;
1432-
html=doc.body.innerHTML;
1433-
}catch(err){/* do nothing */}
1434-
return(html!==null);
1436+
function _onMousewheel(e,delta){
1437+
_stop($this);
1438+
if(_disableMousewheel($this,e.target)){return;} /* disables mouse-wheel when hovering specific elements */
1439+
var deltaFactor=o.mouseWheel.deltaFactor!=="auto" ? parseInt(o.mouseWheel.deltaFactor) : (oldIE && e.deltaFactor<100) ? 100 : e.deltaFactor || 100;
1440+
if(o.axis==="x" || o.mouseWheel.axis==="x"){
1441+
var dir="x",
1442+
px=[Math.round(deltaFactor*d.scrollRatio.x),parseInt(o.mouseWheel.scrollAmount)],
1443+
amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.width() ? mCustomScrollBox.width()*0.9 : px[0],
1444+
contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetLeft),
1445+
draggerPos=mCSB_dragger[1][0].offsetLeft,
1446+
limit=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(),
1447+
dlt=e.deltaX || e.deltaY || delta;
1448+
}else{
1449+
var dir="y",
1450+
px=[Math.round(deltaFactor*d.scrollRatio.y),parseInt(o.mouseWheel.scrollAmount)],
1451+
amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.height() ? mCustomScrollBox.height()*0.9 : px[0],
1452+
contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetTop),
1453+
draggerPos=mCSB_dragger[0][0].offsetTop,
1454+
limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(),
1455+
dlt=e.deltaY || delta;
1456+
}
1457+
if((dir==="y" && !d.overflowed[0]) || (dir==="x" && !d.overflowed[1])){return;}
1458+
if(o.mouseWheel.invert){dlt=-dlt;}
1459+
if(o.mouseWheel.normalizeDelta){dlt=dlt<0 ? -1 : 1;}
1460+
if((dlt>0 && draggerPos!==0) || (dlt<0 && draggerPos!==limit) || o.mouseWheel.preventDefault){
1461+
e.stopImmediatePropagation();
1462+
e.preventDefault();
1463+
}
1464+
_scrollTo($this,(contentPos-(dlt*amount)).toString(),{dir:dir});
14351465
}
14361466
},
14371467
/* -------------------- */
14381468

14391469

1470+
/* checks if iframe can be accessed */
1471+
_canAccessIFrame=function(iframe){
1472+
var html=null;
1473+
try{
1474+
var doc=iframe.contentDocument || iframe.contentWindow.document;
1475+
html=doc.body.innerHTML;
1476+
}catch(err){/* do nothing */}
1477+
return(html!==null);
1478+
},
1479+
/* -------------------- */
1480+
1481+
14401482
/* disables mouse-wheel when hovering specific elements like select, datalist etc. */
14411483
_disableMousewheel=function(el,target){
14421484
var tag=target.nodeName.toLowerCase(),
@@ -1587,8 +1629,25 @@ and dependencies (minified).
15871629
mCustomScrollBox=$("#mCSB_"+d.idx),
15881630
mCSB_container=$("#mCSB_"+d.idx+"_container"),
15891631
wrapper=mCSB_container.parent(),
1590-
editables="input,textarea,select,datalist,keygen,[contenteditable='true']";
1591-
mCustomScrollBox.attr("tabindex","0").bind("blur."+namespace+" keydown."+namespace+" keyup."+namespace,function(e){
1632+
editables="input,textarea,select,datalist,keygen,[contenteditable='true']",
1633+
iframe=mCSB_container.find("iframe"),
1634+
events=["blur."+namespace+" keydown."+namespace+" keyup."+namespace];
1635+
if(iframe.length){
1636+
iframe.each(function(){
1637+
$(this).load(function(){
1638+
/* bind events on accessible iframes */
1639+
if(_canAccessIFrame(this)){
1640+
$(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){
1641+
_onKeyboard(e);
1642+
});
1643+
}
1644+
});
1645+
});
1646+
}
1647+
mCustomScrollBox.attr("tabindex","0").bind(events[0],function(e){
1648+
_onKeyboard(e);
1649+
});
1650+
function _onKeyboard(e){
15921651
switch(e.type){
15931652
case "blur":
15941653
if(d.tweenRunning && seq.dir){_seq("off",null);}
@@ -1645,7 +1704,7 @@ and dependencies (minified).
16451704
if(seq.type==="stepped" && d.tweenRunning){return;}
16461705
_sequentialScroll($this,a,c);
16471706
}
1648-
});
1707+
}
16491708
},
16501709
/* -------------------- */
16511710

js/minified/jquery.mCustomScrollbar.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
363 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)