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
8ada7d15
Commit
8ada7d15
authored
Apr 22, 2013
by
Luís Rudge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing the problem with knockoutjs
parent
5d02a5c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
34 deletions
+39
-34
bootstrap-multiselect.js
js/bootstrap-multiselect.js
+33
-34
knockout-examples.html
knockout-examples.html
+6
-0
No files found.
js/bootstrap-multiselect.js
View file @
8ada7d15
...
...
@@ -23,17 +23,23 @@
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
multiSelectData
=
valueAccessor
();
var
options
=
ko
.
utils
.
unwrapObservable
(
multiSelectData
.
options
)
;
var
options
=
multiSelectData
.
options
;
var
optionsText
=
allBindingsAccessor
().
optionsText
;
var
optionsValue
=
allBindingsAccessor
().
optionsValue
;
ko
.
applyBindingsToNode
(
element
,
{
options
:
options
,
optionsValue
:
optionsValue
,
optionsText
:
optionsText
},
viewModel
);
$
(
element
).
multiselect
(
ko
.
utils
.
unwrapObservable
(
multiSelectData
.
initOptions
));
},
update
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
,
viewModel
,
bindingContext
)
{
}
var
ms
=
$
(
element
).
data
(
'
multiselect
'
);
if
(
ms
)
{
$
(
element
).
multiselect
(
'
rebuild
'
);
}
else
{
$
(
element
).
multiselect
(
ko
.
utils
.
unwrapObservable
(
multiSelectData
.
initOptions
));
}
}
};
}
...
...
@@ -146,11 +152,12 @@
// Build the dropdown and bind event handling.
buildDropdown
:
function
()
{
var
alreadyHasSelectAll
=
this
.
$select
[
0
][
0
].
value
==
'
select-all-option
'
;
//If options.includeSelectAllOption === true, add the include all checkbox
if
(
this
.
options
.
includeSelectAllOption
&&
this
.
options
.
multiple
)
{
if
(
this
.
options
.
includeSelectAllOption
&&
this
.
options
.
multiple
&&
!
alreadyHasSelectAll
)
{
this
.
$select
.
prepend
(
'
<option value="select-all-option">
'
+
this
.
options
.
selectAllText
+
'
</option>
'
);
}
}
this
.
$select
.
children
().
each
(
$
.
proxy
(
function
(
index
,
element
)
{
// Support optgroups and options without a group simultaneously.
var
tag
=
$
(
element
).
prop
(
'
tagName
'
).
toLowerCase
();
...
...
@@ -354,7 +361,7 @@
// Rebuild the whole dropdown menu.
rebuild
:
function
()
{
$
(
'
ul
'
,
this
.
$container
).
html
(
''
);
$
(
'
ul
'
,
this
.
$container
).
html
(
''
);
this
.
buildDropdown
(
this
.
$select
,
this
.
options
);
this
.
updateButtonText
();
},
...
...
@@ -369,35 +376,27 @@
$
(
'
button
'
,
this
.
$container
).
html
(
this
.
options
.
buttonText
(
options
,
this
.
$select
));
},
// For IE 9 support.
getSelected
:
function
()
{
//if (navigator.appName == 'Microsoft Internet Explorer') {
// var regex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
// if (regex.exec(navigator.userAgent) != null) {
// return $('option:selected[value!="select-all-option"]', this.$select);
// }
//}
getSelected
:
function
()
{
return
$
(
'
option:selected[value!="select-all-option"]
'
,
this
.
$select
);
}
};
$
.
fn
.
multiselect
=
function
(
option
,
parameter
)
{
return
this
.
each
(
function
()
{
var
data
=
$
(
this
).
data
(
'
multiselect
'
),
options
=
typeof
option
==
'
object
'
&&
option
;
// Initialize the multiselect.
if
(
!
data
)
{
$
(
this
).
data
(
'
multiselect
'
,
(
data
=
new
Multiselect
(
this
,
options
)));
}
// Call multiselect method.
if
(
typeof
option
==
'
string
'
)
{
data
[
option
](
parameter
);
}
});
}
$
.
fn
.
multiselect
=
function
(
option
,
parameter
)
{
return
this
.
each
(
function
()
{
var
data
=
$
(
this
).
data
(
'
multiselect
'
),
options
=
typeof
option
==
'
object
'
&&
option
;
// Initialize the multiselect.
if
(
!
data
)
{
$
(
this
).
data
(
'
multiselect
'
,
(
data
=
new
Multiselect
(
this
,
options
)));
}
// Call multiselect method.
if
(
typeof
option
==
'
string
'
)
{
data
[
option
](
parameter
);
}
});
};
$
(
function
()
{
$
(
"
select[data-role=multiselect]
"
).
multiselect
();
...
...
knockout-examples.html
View file @
8ada7d15
...
...
@@ -73,4 +73,10 @@
var
vm
=
new
viewModel
();
ko
.
applyBindings
(
vm
);
//simulating changes on the observable
var
t
=
setInterval
(
function
()
{
if
(
vm
.
items
().
length
>=
15
)
clearInterval
(
t
);
vm
.
items
.
push
({
id
:
vm
.
items
().
length
+
1
,
text
:
'
item
'
+
(
vm
.
items
().
length
+
1
)
});
},
1000
);
</script>
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