1- /*! nouislider - 10.0 .0 - 2017-05 -28 14:52:48 */
1+ /*! nouislider - 10.1 .0 - 2017-07 -28 13:09:54 */
22
33( function ( factory ) {
44
2222
2323 'use strict' ;
2424
25- var VERSION = '10.0 .0' ;
25+ var VERSION = '10.1 .0' ;
2626
2727
2828 function isValidFormatter ( entry ) {
723723 } ;
724724 }
725725
726+ function testMultitouch ( parsed , entry ) {
727+ parsed . multitouch = entry ;
728+
729+ if ( typeof entry !== 'boolean' ) {
730+ throw new Error ( "noUiSlider (" + VERSION + "): 'multitouch' option must be a boolean." ) ;
731+ }
732+ }
733+
726734 function testTooltips ( parsed , entry ) {
727735
728736 if ( entry === false ) {
832840 'limit' : { r : false , t : testLimit } ,
833841 'padding' : { r : false , t : testPadding } ,
834842 'behaviour' : { r : true , t : testBehaviour } ,
843+ 'multitouch' : { r : true , t : testMultitouch } ,
835844 'ariaFormat' : { r : false , t : testAriaFormat } ,
836845 'format' : { r : false , t : testFormat } ,
837846 'tooltips' : { r : false , t : testTooltips } ,
844853 'connect' : false ,
845854 'direction' : 'ltr' ,
846855 'behaviour' : 'tap' ,
856+ 'multitouch' : false ,
847857 'orientation' : 'horizontal' ,
848858 'cssPrefix' : 'noUi-' ,
849859 'cssClasses' : {
@@ -931,14 +941,13 @@ function closure ( target, options, originalOptions ){
931941 var scope_Base ;
932942 var scope_Handles ;
933943 var scope_HandleNumbers = [ ] ;
934- var scope_ActiveHandle = false ;
944+ var scope_ActiveHandlesCount = 0 ;
935945 var scope_Connects ;
936946 var scope_Spectrum = options . spectrum ;
937947 var scope_Values = [ ] ;
938948 var scope_Events = { } ;
939949 var scope_Self ;
940950 var scope_Pips ;
941- var scope_Listeners = null ;
942951 var scope_Document = target . ownerDocument ;
943952 var scope_DocumentElement = scope_Document . documentElement ;
944953 var scope_Body = scope_Document . body ;
@@ -1376,7 +1385,7 @@ function closure ( target, options, originalOptions ){
13761385 return false ;
13771386 }
13781387
1379- e = fixEvent ( e , data . pageOffset ) ;
1388+ e = fixEvent ( e , data . pageOffset , data . target || element ) ;
13801389
13811390 // Handle reject of multitouch
13821391 if ( ! e ) {
@@ -1420,7 +1429,7 @@ function closure ( target, options, originalOptions ){
14201429 }
14211430
14221431 // Provide a clean event with standardized offset values.
1423- function fixEvent ( e , pageOffset ) {
1432+ function fixEvent ( e , pageOffset , target ) {
14241433
14251434 // Filter the event to register the type, which can be
14261435 // touch, mouse or pointer. Offset changes need to be
@@ -1437,8 +1446,35 @@ function closure ( target, options, originalOptions ){
14371446 pointer = true ;
14381447 }
14391448
1440- if ( touch ) {
14411449
1450+ // In the event that multitouch is activated, the only thing one handle should be concerned
1451+ // about is the touches that originated on top of it.
1452+ if ( touch && options . multitouch ) {
1453+ // Returns true if a touch originated on the target.
1454+ var isTouchOnTarget = function ( touch ) {
1455+ return touch . target === target || target . contains ( touch . target ) ;
1456+ } ;
1457+ // In the case of touchstart events, we need to make sure there is still no more than one
1458+ // touch on the target so we look amongst all touches.
1459+ if ( e . type === 'touchstart' ) {
1460+ var targetTouches = Array . prototype . filter . call ( e . touches , isTouchOnTarget ) ;
1461+ // Do not support more than one touch per handle.
1462+ if ( targetTouches . length > 1 ) {
1463+ return false ;
1464+ }
1465+ x = targetTouches [ 0 ] . pageX ;
1466+ y = targetTouches [ 0 ] . pageY ;
1467+ } else {
1468+ // In the other cases, find on changedTouches is enough.
1469+ var targetTouch = Array . prototype . find . call ( e . changedTouches , isTouchOnTarget ) ;
1470+ // Cancel if the target touch has not moved.
1471+ if ( ! targetTouch ) {
1472+ return false ;
1473+ }
1474+ x = targetTouch . pageX ;
1475+ y = targetTouch . pageY ;
1476+ }
1477+ } else if ( touch ) {
14421478 // Fix bug when user touches with two or more fingers on mobile devices.
14431479 // It's useful when you have two or more sliders on one page,
14441480 // that can be touched simultaneously.
@@ -1616,26 +1652,27 @@ function closure ( target, options, originalOptions ){
16161652 function eventEnd ( event , data ) {
16171653
16181654 // The handle is no longer active, so remove the class.
1619- if ( scope_ActiveHandle ) {
1620- removeClass ( scope_ActiveHandle , options . cssClasses . active ) ;
1621- scope_ActiveHandle = false ;
1622- }
1623-
1624- // Remove cursor styles and text-selection events bound to the body.
1625- if ( event . cursor ) {
1626- scope_Body . style . cursor = '' ;
1627- scope_Body . removeEventListener ( 'selectstart' , preventDefault ) ;
1655+ if ( data . handle ) {
1656+ removeClass ( data . handle , options . cssClasses . active ) ;
1657+ scope_ActiveHandlesCount -= 1 ;
16281658 }
16291659
16301660 // Unbind the move and end events, which are added on 'start'.
1631- scope_Listeners . forEach ( function ( c ) {
1661+ data . listeners . forEach ( function ( c ) {
16321662 scope_DocumentElement . removeEventListener ( c [ 0 ] , c [ 1 ] ) ;
16331663 } ) ;
16341664
1635- // Remove dragging class.
1636- removeClass ( scope_Target , options . cssClasses . drag ) ;
1665+ if ( scope_ActiveHandlesCount === 0 ) {
1666+ // Remove dragging class.
1667+ removeClass ( scope_Target , options . cssClasses . drag ) ;
1668+ setZindex ( ) ;
16371669
1638- setZindex ( ) ;
1670+ // Remove cursor styles and text-selection events bound to the body.
1671+ if ( event . cursor ) {
1672+ scope_Body . style . cursor = '' ;
1673+ scope_Body . removeEventListener ( 'selectstart' , preventDefault ) ;
1674+ }
1675+ }
16391676
16401677 data . handleNumbers . forEach ( function ( handleNumber ) {
16411678 fireEvent ( 'change' , handleNumber ) ;
@@ -1647,25 +1684,36 @@ function closure ( target, options, originalOptions ){
16471684 // Bind move events on document.
16481685 function eventStart ( event , data ) {
16491686
1687+ var handle ;
16501688 if ( data . handleNumbers . length === 1 ) {
16511689
1652- var handle = scope_Handles [ data . handleNumbers [ 0 ] ] ;
1690+ var handleOrigin = scope_Handles [ data . handleNumbers [ 0 ] ] ;
16531691
16541692 // Ignore 'disabled' handles
1655- if ( handle . hasAttribute ( 'disabled' ) ) {
1693+ if ( handleOrigin . hasAttribute ( 'disabled' ) ) {
16561694 return false ;
16571695 }
16581696
1697+ handle = handleOrigin . children [ 0 ] ;
1698+ scope_ActiveHandlesCount += 1 ;
1699+
16591700 // Mark the handle as 'active' so it can be styled.
1660- scope_ActiveHandle = handle . children [ 0 ] ;
1661- addClass ( scope_ActiveHandle , options . cssClasses . active ) ;
1701+ addClass ( handle , options . cssClasses . active ) ;
16621702 }
16631703
16641704 // A drag should never propagate up to the 'tap' event.
16651705 event . stopPropagation ( ) ;
16661706
1707+ // Record the event listeners.
1708+ var listeners = [ ] ;
1709+
16671710 // Attach the move and end events.
16681711 var moveEvent = attachEvent ( actions . move , scope_DocumentElement , eventMove , {
1712+ // The event target has changed so we need to propagate the original one so that we keep
1713+ // relying on it to extract target touches.
1714+ target : event . target ,
1715+ handle : handle ,
1716+ listeners : listeners ,
16691717 startCalcPoint : event . calcPoint ,
16701718 baseSize : baseSize ( ) ,
16711719 pageOffset : event . pageOffset ,
@@ -1675,14 +1723,22 @@ function closure ( target, options, originalOptions ){
16751723 } ) ;
16761724
16771725 var endEvent = attachEvent ( actions . end , scope_DocumentElement , eventEnd , {
1726+ target : event . target ,
1727+ handle : handle ,
1728+ listeners : listeners ,
16781729 handleNumbers : data . handleNumbers
16791730 } ) ;
16801731
16811732 var outEvent = attachEvent ( "mouseout" , scope_DocumentElement , documentLeave , {
1733+ target : event . target ,
1734+ handle : handle ,
1735+ listeners : listeners ,
16821736 handleNumbers : data . handleNumbers
16831737 } ) ;
16841738
1685- scope_Listeners = moveEvent . concat ( endEvent , outEvent ) ;
1739+ // We want to make sure we pushed the listeners in the listener list rather than creating
1740+ // a new one as it has already been passed to the event handlers.
1741+ listeners . push . apply ( listeners , moveEvent . concat ( endEvent , outEvent ) ) ;
16861742
16871743 // Text selection isn't an issue on touch devices,
16881744 // so adding cursor styles can be skipped.
0 commit comments