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
79a15968
Commit
79a15968
authored
May 13, 2014
by
David Stutz
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #279 from Tyf0x/perf
** Performance improvement ** - based on thorst #268 contribution.
parents
b30473b0
3757ccd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
34 deletions
+67
-34
bootstrap-multiselect.js
js/bootstrap-multiselect.js
+67
-34
No files found.
js/bootstrap-multiselect.js
View file @
79a15968
...
...
@@ -225,10 +225,10 @@
templates
:
{
button
:
'
<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>
'
,
ul
:
'
<ul class="multiselect-container dropdown-menu"></ul>
'
,
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
>
'
,
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
>
'
,
li
:
'
<li><a href="javascript:void(0);"><label></label></a></li>
'
,
divider
:
'
<li class="divider"></li>
'
,
liGroup
:
'
<li><label class="multiselect-group"></label></li>
'
divider
:
'
<li class="
multiselect-item
divider"></li>
'
,
liGroup
:
'
<li
class="multiselect-item group"
><label class="multiselect-group"></label></li>
'
}
},
...
...
@@ -354,19 +354,11 @@
var
$checkboxesNotThis
=
$
(
'
input
'
,
this
.
$container
).
not
(
$target
);
if
(
isSelectAllOption
)
{
var
values
=
[];
// Select the visible checkboxes except the "select-all" and possible divider.
var
availableInputs
=
$
(
'
li input[value!="
'
+
this
.
options
.
selectAllValue
+
'
"][data-role!="divider"]
'
,
this
.
$ul
).
filter
(
'
:visible
'
);
for
(
var
i
=
0
,
j
=
availableInputs
.
length
;
i
<
j
;
i
++
)
{
values
.
push
(
availableInputs
[
i
].
value
);
}
if
(
checked
)
{
this
.
select
(
values
);
this
.
select
all
(
);
}
else
{
this
.
deselect
(
values
);
this
.
deselect
all
(
);
}
}
...
...
@@ -520,6 +512,7 @@
$checkbox
.
val
(
value
);
if
(
value
===
this
.
options
.
selectAllValue
)
{
$li
.
addClass
(
"
multiselect-item multiselect-all
"
);
$checkbox
.
parent
().
parent
()
.
addClass
(
'
multiselect-all
'
);
}
...
...
@@ -659,7 +652,7 @@
},
this
));
}
// TODO: check whether select all option needs to be updated.
this
.
updateSelectAll
();
},
this
),
300
,
this
);
},
this
));
}
...
...
@@ -751,20 +744,9 @@
*
*/
clearSelection
:
function
()
{
var
selected
=
this
.
getSelected
();
if
(
selected
.
length
)
{
var
arry
=
[];
for
(
var
i
=
0
;
i
<
selected
.
length
;
i
=
i
+
1
)
{
arry
.
push
(
selected
[
i
].
value
);
}
this
.
deselect
(
arry
);
this
.
$select
.
change
();
}
this
.
deselectall
(
false
);
this
.
updateButtonText
();
this
.
updateSelectAll
();
},
/**
...
...
@@ -795,6 +777,57 @@
this
.
updateButtonText
();
},
/**
* Selects all enabled & visible options.
*
*/
selectall
:
function
()
{
var
allCheckboxes
=
$
(
"
li input[type='checkbox']:enabled
"
,
this
.
$ul
),
visibleCheckboxes
=
allCheckboxes
.
filter
(
"
:visible
"
),
allCheckboxesCount
=
allCheckboxes
.
length
,
visibleCheckboxesCount
=
visibleCheckboxes
.
length
;
visibleCheckboxes
.
prop
(
'
checked
'
,
true
);
$
(
"
li:not(.divider):not(.disabled)
"
,
this
.
$ul
).
filter
(
"
:visible
"
).
addClass
(
this
.
options
.
selectedClass
);
if
(
allCheckboxesCount
===
visibleCheckboxesCount
)
{
$
(
"
option:enabled:not([data-role='divider'])
"
,
this
.
$select
).
prop
(
'
selected
'
,
true
);
}
else
{
var
values
=
visibleCheckboxes
.
map
(
function
()
{
return
$
(
this
).
val
()
}).
get
();
$
(
"
option:enabled:not([data-role='divider'])
"
,
this
.
$select
).
filter
(
function
(
index
){
return
$
.
inArray
(
$
(
this
).
val
(),
values
)
!==
-
1
;
}).
prop
(
'
selected
'
,
true
);
}
},
/**
* Deselects all options.
* If justVisible is true or not specified, only visible options are deselected.
*
* @param {Boolean} justVisible
*/
deselectall
:
function
(
justVisible
)
{
var
allCheckboxes
=
$
(
"
li input[type='checkbox']:enabled
"
,
this
.
$ul
),
justVisible
=
typeof
justVisible
===
'
undefined
'
?
true
:
justVisible
,
visibleCheckboxes
=
void
(
0
);
if
(
justVisible
)
{
var
values
=
void
(
0
);
visibleCheckboxes
=
allCheckboxes
.
filter
(
"
:visible
"
);
visibleCheckboxes
.
prop
(
'
checked
'
,
false
);
values
=
visibleCheckboxes
.
map
(
function
()
{
return
$
(
this
).
val
()
}).
get
();
$
(
"
option:enabled:not([data-role='divider'])
"
,
this
.
$select
).
filter
(
function
(
index
){
return
$
.
inArray
(
$
(
this
).
val
(),
values
)
!==
-
1
;
}).
prop
(
'
selected
'
,
false
);
$
(
"
li:not(.divider):not(.disabled)
"
,
this
.
$ul
).
filter
(
"
:visible
"
).
removeClass
(
this
.
options
.
selectedClass
);
}
else
{
allCheckboxes
.
prop
(
'
checked
'
,
false
);
$
(
"
option:enabled:not([data-role='divider'])
"
,
this
.
$select
).
prop
(
'
selected
'
,
false
);
$
(
"
li:not(.divider):not(.disabled)
"
,
this
.
$ul
).
removeClass
(
this
.
options
.
selectedClass
);
}
},
/**
* Rebuild the plugin.
...
...
@@ -880,13 +913,15 @@
},
/**
* Updates the select all option based on the currently
selected option
s.
* Updates the select all option based on the currently
displayed and selected checkboxe
s.
*/
updateSelectAll
:
function
()
{
if
(
this
.
hasSelectAll
())
{
var
selected
=
this
.
getSelected
();
var
allBoxes
=
$
(
"
li:not(.multiselect-item) input:enabled
"
,
this
.
$ul
).
filter
(
"
:visible
"
),
allBoxesLength
=
allBoxes
.
length
,
checkedBoxesLength
=
allBoxes
.
filter
(
"
:checked
"
).
length
;
if
(
selected
.
length
===
$
(
'
option:not([data-role=divider])
'
,
this
.
$select
).
length
-
1
)
{
if
(
checkedBoxesLength
>
0
&&
checkedBoxesLength
===
allBoxesLength
)
{
this
.
select
(
this
.
options
.
selectAllValue
);
}
else
{
...
...
@@ -915,9 +950,7 @@
* @returns {jQUery}
*/
getSelected
:
function
()
{
return
$
(
'
option[value!="
'
+
this
.
options
.
selectAllValue
+
'
"]:selected
'
,
this
.
$select
).
filter
(
function
()
{
return
$
(
this
).
prop
(
'
selected
'
);
});
return
$
(
'
option:not([value="
'
+
this
.
options
.
selectAllValue
+
'
"])
'
,
this
.
$select
).
filter
(
"
:selected
"
);
},
/**
...
...
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