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
77dc6ab5
Commit
77dc6ab5
authored
Mar 11, 2014
by
David Stutz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/davidstutz/bootstrap-multiselect
parents
ebd00ed5
ad7e1b5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
24 deletions
+119
-24
index.html
index.html
+18
-0
bootstrap-multiselect.js
js/bootstrap-multiselect.js
+101
-24
No files found.
index.html
View file @
77dc6ab5
...
...
@@ -802,6 +802,24 @@
includeSelectAllOption: true
});
});
<
/script
>
</pre>
</td>
</tr>
<tr>
<td><code>
includeSelectAllDivider
</code></td>
<td>
If set to
<code>
true
</code>
(along with
<code>
includeSelectAllOption
</code>
) a divider will be placed below the 'Select all' option.
</td>
<td>
<pre
class=
"prettyprint linenums"
>
<
script type=
"
text/javascript
">
$(document).ready(function() {
$(
'
.multiselect
'
).multiselect({
includeSelectAllOption: true,
includeSelectAllDivider: true
});
});
<
/script
>
</pre>
</td>
...
...
js/bootstrap-multiselect.js
View file @
77dc6ab5
...
...
@@ -12,26 +12,65 @@
if
(
typeof
ko
!==
'
undefined
'
&&
ko
.
bindingHandlers
&&
!
ko
.
bindingHandlers
.
multiselect
)
{
ko
.
bindingHandlers
.
multiselect
=
{
init
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
,
viewModel
,
bindingContext
)
{},
update
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
,
viewModel
,
bindingContext
)
{
var
config
=
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
var
selectOptions
=
allBindingsAccessor
().
options
;
var
ms
=
$
(
element
).
data
(
'
multiselect
'
);
if
(
!
ms
)
{
$
(
element
).
multiselect
(
config
);
}
else
{
ms
.
updateOriginalOptions
();
if
(
selectOptions
&&
selectOptions
().
length
!==
ms
.
originalOptions
.
length
)
{
$
(
element
).
multiselect
(
'
rebuild
'
);
}
}
init
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
,
viewModel
,
bindingContext
)
{
var
listOfSelectedItems
=
allBindingsAccessor
().
selectedOptions
,
config
=
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
$
(
element
).
multiselect
(
config
);
if
(
isObservableArray
(
listOfSelectedItems
))
{
// Subscribe to the selectedOptions: ko.observableArray
listOfSelectedItems
.
subscribe
(
function
(
changes
)
{
var
addedArray
=
[],
deletedArray
=
[];
changes
.
forEach
(
function
(
change
)
{
switch
(
change
.
status
)
{
case
'
added
'
:
addedArray
.
push
(
change
.
value
);
break
;
case
'
deleted
'
:
deletedArray
.
push
(
change
.
value
);
break
;
}
});
if
(
addedArray
.
length
>
0
)
{
$
(
element
).
multiselect
(
'
select
'
,
addedArray
);
};
if
(
deletedArray
.
length
>
0
)
{
$
(
element
).
multiselect
(
'
deselect
'
,
deletedArray
);
};
},
null
,
"
arrayChange
"
);
}
},
update
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
,
viewModel
,
bindingContext
)
{
var
listOfItems
=
allBindingsAccessor
().
options
,
ms
=
$
(
element
).
data
(
'
multiselect
'
),
config
=
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
if
(
isObservableArray
(
listOfItems
))
{
// Subscribe to the options: ko.observableArray incase it changes later
listOfItems
.
subscribe
(
function
(
theArray
)
{
$
(
element
).
multiselect
(
'
rebuild
'
);
});
}
if
(
!
ms
)
{
$
(
element
).
multiselect
(
config
);
}
else
{
ms
.
updateOriginalOptions
();
}
}
};
}
function
isObservableArray
(
obj
)
{
return
ko
.
isObservable
(
obj
)
&&
!
(
obj
.
destroyAll
===
undefined
);
}
/**
* Constructor to create a new multiselect using the given select.
*
...
...
@@ -536,6 +575,9 @@
// If options.includeSelectAllOption === true, add the include all checkbox.
if
(
this
.
options
.
includeSelectAllOption
&&
this
.
options
.
multiple
&&
!
alreadyHasSelectAll
)
{
if
(
this
.
options
.
includeSelectAllDivider
)
{
this
.
$select
.
prepend
(
'
<option value="" disabled="disabled" data-role="divider">
'
);
}
this
.
$select
.
prepend
(
'
<option value="
'
+
this
.
options
.
selectAllValue
+
'
">
'
+
this
.
options
.
selectAllText
+
'
</option>
'
);
}
},
...
...
@@ -686,6 +728,27 @@
this
.
updateButtonText
();
},
/**
* Clears all selected items
*
*/
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
();
}
},
/**
* Deselects all options of the given values.
*
...
...
@@ -844,10 +907,17 @@
* @param {String} value
* @returns {jQuery}
*/
getOptionByValue
:
function
(
value
)
{
return
$
(
'
option
'
,
this
.
$select
).
filter
(
function
()
{
return
$
(
this
).
val
()
===
value
;
});
getOptionByValue
:
function
(
value
)
{
var
options
=
$
(
'
option
'
,
this
.
$select
);
var
valueToCompare
=
value
.
toString
();
for
(
var
i
=
0
;
i
<
options
.
length
;
i
=
i
+
1
)
{
var
option
=
options
[
i
];
if
(
option
.
value
==
valueToCompare
)
{
return
$
(
option
);
}
}
},
/**
...
...
@@ -856,10 +926,17 @@
* @param {String} value
* @returns {jQuery}
*/
getInputByValue
:
function
(
value
)
{
return
$
(
'
li input
'
,
this
.
$ul
).
filter
(
function
()
{
return
$
(
this
).
val
()
===
value
;
});
getInputByValue
:
function
(
value
)
{
var
checkboxes
=
$
(
'
li input
'
,
this
.
$ul
);
var
valueToCompare
=
value
.
toString
();
for
(
var
i
=
0
;
i
<
checkboxes
.
length
;
i
=
i
+
1
)
{
var
checkbox
=
checkboxes
[
i
];
if
(
checkbox
.
value
==
valueToCompare
)
{
return
$
(
checkbox
);
}
}
},
/**
...
...
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