Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap-multiselect
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap-multiselect
Commits
614bd4b5
Commit
614bd4b5
authored
Feb 12, 2015
by
David Stutz
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #439 from Tyf0x/shift-select-improvement
Shift + Click range selection improvements. Fixes #431.
parents
847873e4
1bb4af91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
35 deletions
+55
-35
bootstrap-multiselect.js
dist/js/bootstrap-multiselect.js
+54
-34
bootstrap-multiselect.js
tests/spec/bootstrap-multiselect.js
+1
-1
No files found.
dist/js/bootstrap-multiselect.js
View file @
614bd4b5
...
...
@@ -99,6 +99,7 @@
this
.
originalOptions
=
this
.
$select
.
clone
()[
0
].
options
;
this
.
query
=
''
;
this
.
searchTimeout
=
null
;
this
.
lastToggledInput
=
null
this
.
options
.
multiple
=
this
.
$select
.
attr
(
'
multiple
'
)
===
"
multiple
"
;
this
.
options
.
onChange
=
$
.
proxy
(
this
.
options
.
onChange
,
this
);
...
...
@@ -261,7 +262,7 @@
ul
:
'
<ul class="multiselect-container dropdown-menu"></ul>
'
,
filter
:
'
<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>
'
,
filterClearBtn
:
'
<span class="input-group-btn"><button class="btn btn-default multiselect-clear-filter" type="button"><i class="glyphicon glyphicon-remove-circle"></i></button></span>
'
,
li
:
'
<li><a
href="javascript:void(0);
"><label></label></a></li>
'
,
li
:
'
<li><a
tabindex="0
"><label></label></a></li>
'
,
divider
:
'
<li class="multiselect-item divider"></li>
'
,
liGroup
:
'
<li class="multiselect-item multiselect-group"><label></label></li>
'
}
...
...
@@ -451,50 +452,69 @@
}
},
this
));
$
(
'
li a
'
,
this
.
$ul
).
on
(
'
touchstart click
'
,
function
(
event
)
{
$
(
'
li a
'
,
this
.
$ul
).
on
(
'
mousedown
'
,
function
(
e
)
{
if
(
e
.
shiftKey
)
{
// Prevent selecting text by Shift+click
return
false
;
}
});
$
(
'
li a
'
,
this
.
$ul
).
on
(
'
touchstart click
'
,
$
.
proxy
(
function
(
event
)
{
event
.
stopPropagation
();
var
$target
=
$
(
event
.
target
);
if
(
document
.
getSelection
().
type
===
'
Range
'
)
{
var
$input
=
$
(
this
).
find
(
"
input:first
"
);
$input
.
prop
(
"
checked
"
,
!
$input
.
prop
(
"
checked
"
))
.
trigger
(
"
change
"
);
}
if
(
event
.
shiftKey
)
{
if
(
event
.
shiftKey
&&
this
.
options
.
multiple
)
{
if
(
$target
.
is
(
"
label
"
)){
// Handles checkbox selection manually (see https://github.com/davidstutz/bootstrap-multiselect/issues/431)
event
.
preventDefault
();
$target
=
$target
.
find
(
"
input
"
);
$target
.
prop
(
"
checked
"
,
!
$target
.
prop
(
"
checked
"
));
}
var
checked
=
$target
.
prop
(
'
checked
'
)
||
false
;
if
(
checked
)
{
var
prev
=
$target
.
closest
(
'
li
'
)
.
siblings
(
'
li[class="active"]:first
'
);
var
currentIdx
=
$target
.
closest
(
'
li
'
)
.
index
();
var
prevIdx
=
prev
.
index
();
if
(
currentIdx
>
prevIdx
)
{
$target
.
closest
(
"
li
"
).
prevUntil
(
prev
).
each
(
function
()
{
$
(
this
).
find
(
"
input:first
"
).
prop
(
"
checked
"
,
true
)
.
trigger
(
"
change
"
);
}
);
if
(
this
.
lastToggledInput
!==
null
&&
this
.
lastToggledInput
!==
$target
)
{
// Make sure we actually have a range
var
from
=
$target
.
closest
(
"
li
"
).
index
();
var
to
=
this
.
lastToggledInput
.
closest
(
"
li
"
).
index
();
if
(
from
>
to
)
{
// Swap the indices
var
tmp
=
to
;
to
=
from
;
from
=
tmp
;
}
else
{
$target
.
closest
(
"
li
"
).
nextUntil
(
prev
).
each
(
function
()
{
$
(
this
).
find
(
"
input:first
"
).
prop
(
"
checked
"
,
true
)
.
trigger
(
"
change
"
);
}
);
// Make sure we grab all elements since slice excludes the last index
++
to
;
// Change the checkboxes and underlying options
var
range
=
this
.
$ul
.
find
(
"
li
"
).
slice
(
from
,
to
).
find
(
"
input
"
);
range
.
prop
(
'
checked
'
,
checked
);
if
(
this
.
options
.
selectedClass
)
{
range
.
closest
(
'
li
'
)
.
toggleClass
(
this
.
options
.
selectedClass
,
checked
);
}
for
(
var
i
=
0
,
j
=
range
.
length
;
i
<
j
;
i
++
)
{
var
$checkbox
=
$
(
range
[
i
]);
var
$option
=
this
.
getOptionByValue
(
$checkbox
.
val
());
$option
.
prop
(
'
selected
'
,
checked
);
}
}
// Trigger the select "change" event
$target
.
trigger
(
"
change
"
);
}
// Remembers last clicked option
if
(
$target
.
is
(
"
input
"
)
&&
!
$target
.
closest
(
"
li
"
).
is
(
"
.multiselect-item
"
)){
this
.
lastToggledInput
=
$target
;
}
$target
.
blur
();
});
}
,
this
)
);
// Keyboard support.
this
.
$container
.
off
(
'
keydown.multiselect
'
).
on
(
'
keydown.multiselect
'
,
$
.
proxy
(
function
(
event
)
{
...
...
tests/spec/bootstrap-multiselect.js
View file @
614bd4b5
...
...
@@ -596,7 +596,7 @@ describe('Bootstrap Multiselect Specific Issues', function() {
selection
.
addRange
(
range
);
if
(
document
.
getSelection
().
type
===
'
Range
'
)
{
$
(
'
#multiselect-container
'
).
find
(
'
a:first
'
).
trigger
(
'
click
'
);
$
(
'
#multiselect-container
'
).
find
(
'
a:first
label
'
).
trigger
(
'
click
'
);
expect
(
$
(
'
#multiselect-container
'
).
find
(
'
input:first
'
).
prop
(
'
checked
'
)).
toBe
(
true
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment