Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement drag all when more than two handles are configured #841

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribute/nouislider.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! nouislider - 10.1.0 - 2017-07-28 13:09:54 */
/*! nouislider - 10.1.0 - 2017-11-22 12:08:52 */
/* Functional styling;
* These styles are required for noUiSlider to function.
* You don't need to change these rules to apply your design.
Expand Down
31 changes: 22 additions & 9 deletions distribute/nouislider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! nouislider - 10.1.0 - 2017-07-28 13:09:54 */
/*! nouislider - 10.1.0 - 2017-11-22 12:08:52 */

(function (factory) {

Expand Down Expand Up @@ -1844,33 +1844,46 @@ function closure ( target, options, originalOptions ){
}

// Make the range draggable.
if ( behaviour.drag ){
if (behaviour.drag) {

scope_Connects.forEach(function( connect, index ){
scope_Connects.forEach(function (connect, index) {

if ( connect === false || index === 0 || index === scope_Connects.length - 1 ) {
if (connect === false || index === 0 || index === scope_Connects.length - 1) {
return;
}

var handleBefore = scope_Handles[index - 1];
var handleAfter = scope_Handles[index];
var eventHolders = [connect];
var handlesToDrag = [handleBefore, handleAfter];
var handleNumbersToDrag = [index - 1, index];

addClass(connect, options.cssClasses.draggable);

// When the range is fixed, the entire range can
// be dragged by the handles. The handle in the first
// origin will propagate the start event upward,
// but it needs to be bound manually on the other.
if ( behaviour.fixed ) {
if (behaviour.fixed) {
eventHolders.push(handleBefore.children[0]);
eventHolders.push(handleAfter.children[0]);
}

eventHolders.forEach(function( eventHolder ) {
attachEvent ( actions.start, eventHolder, eventStart, {
handles: [handleBefore, handleAfter],
handleNumbers: [index - 1, index]
// Check for the option dragAllHandles to see if
// must drag all handles at the same time
if (originalOptions.dragAllHandles) {
handlesToDrag = scope_Handles;
handleNumbersToDrag = [0];
while (handleNumbersToDrag.length < scope_Handles.length)
{
handleNumbersToDrag.push(handleNumbersToDrag.length);
}
}

eventHolders.forEach(function (eventHolder) {
attachEvent(actions.start, eventHolder, eventStart, {
handles: handlesToDrag,
handleNumbers: handleNumbersToDrag
});
});
});
Expand Down
15 changes: 15 additions & 0 deletions documentation/behaviour-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@
</div>
</section>

<section>

<div class="view">
<p>If you want to drag all handles when you have more than two, you can set the <code>dragAllHandles</code> option to <strong>true</strong>. The <code>slide</code> event fires for all handles when dragging the range.</p>
<div class="example">
<div id="drag-all"></div>
<?php run('drag-all'); ?>
</div>
</div>

<div class="side">
<?php code('drag-all'); ?>
</div>
</section>


<?php sect('fixed'); ?>
<h2>Fixed dragging</h2>
Expand Down
12 changes: 12 additions & 0 deletions documentation/behaviour-option/drag-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var dragSlider = document.getElementById('drag-all');

noUiSlider.create(dragSlider, {
start: [ 40, 60, 80 ],
behaviour: 'drag',
dragAllHandles: true,
connect: true,
range: {
'min': 20,
'max': 80
}
});
29 changes: 21 additions & 8 deletions src/js/scope_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,46 @@
}

// Make the range draggable.
if ( behaviour.drag ){
if (behaviour.drag) {

scope_Connects.forEach(function( connect, index ){
scope_Connects.forEach(function (connect, index) {

if ( connect === false || index === 0 || index === scope_Connects.length - 1 ) {
if (connect === false || index === 0 || index === scope_Connects.length - 1) {
return;
}

var handleBefore = scope_Handles[index - 1];
var handleAfter = scope_Handles[index];
var eventHolders = [connect];
var handlesToDrag = [handleBefore, handleAfter];
var handleNumbersToDrag = [index - 1, index];

addClass(connect, options.cssClasses.draggable);

// When the range is fixed, the entire range can
// be dragged by the handles. The handle in the first
// origin will propagate the start event upward,
// but it needs to be bound manually on the other.
if ( behaviour.fixed ) {
if (behaviour.fixed) {
eventHolders.push(handleBefore.children[0]);
eventHolders.push(handleAfter.children[0]);
}

eventHolders.forEach(function( eventHolder ) {
attachEvent ( actions.start, eventHolder, eventStart, {
handles: [handleBefore, handleAfter],
handleNumbers: [index - 1, index]
// Check for the option dragAllHandles to see if
// must drag all handles at the same time
if (originalOptions.dragAllHandles) {
handlesToDrag = scope_Handles;
handleNumbersToDrag = [0];
while (handleNumbersToDrag.length < scope_Handles.length)
{
handleNumbersToDrag.push(handleNumbersToDrag.length);
}
}

eventHolders.forEach(function (eventHolder) {
attachEvent(actions.start, eventHolder, eventStart, {
handles: handlesToDrag,
handleNumbers: handleNumbersToDrag
});
});
});
Expand Down