Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
facets
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
facets
Merge requests
!230
Fix Issue
#3264284
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Fix Issue
#3264284
issue/facets-2811331:2811331-create-a-multiple
into
2.0.x
Overview
0
Commits
1
Pipelines
1
Changes
3
Open
Panagiotis Moutsopoulos
requested to merge
issue/facets-2811331:2811331-create-a-multiple
into
2.0.x
9 months ago
Overview
0
Commits
1
Pipelines
1
Changes
3
Expand
Closes
#2811331
0
0
Merge request reports
Compare
2.0.x
2.0.x (HEAD)
and
latest version
latest version
a6d8111a
1 commit,
9 months ago
3 files
+
80
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
js/dropdown-widget.js
+
76
−
5
Options
@@ -40,17 +40,24 @@
$dropdown
.
addClass
(
'
facets-dropdown
'
);
$dropdown
.
addClass
(
'
js-facets-widget
'
);
$dropdown
.
addClass
(
'
js-facets-dropdown
'
);
if
(
$ul
.
hasClass
(
'
js-multiple-select
'
))
{
$dropdown
.
attr
(
'
multiple
'
,
'
multiple
'
);
}
var
id
=
$
(
this
).
data
(
'
drupal-facet-id
'
);
// Add aria-labelledby attribute to reference label.
$dropdown
.
attr
(
'
aria-labelledby
'
,
"
facet_
"
+
id
+
"
_label
"
);
var
default_option_label
=
settings
.
facets
.
dropdown_widget
[
id
][
'
facet-default-option-label
'
];
// Add empty text option first.
// Add empty text option first
and make it 'disabled'
.
var
$default_option
=
$
(
'
<option></option>
'
)
.
prop
(
'
disabled
'
,
true
)
.
attr
(
'
value
'
,
''
)
.
text
(
default_option_label
);
$dropdown
.
append
(
$default_option
);
// If default_option_label is set to be blank in facets UI, simply don't render it.
if
(
default_option_label
)
{
$dropdown
.
append
(
$default_option
);
}
$ul
.
prepend
(
'
<li class="default-option"><a href="
'
+
window
.
location
.
href
.
split
(
'
?
'
)[
0
]
+
'
">
'
+
Drupal
.
checkPlain
(
default_option_label
)
+
'
</a></li>
'
);
@@ -69,8 +76,12 @@
$option
.
attr
(
'
selected
'
,
'
selected
'
);
$link
.
find
(
'
.js-facet-deactivate
'
).
remove
();
}
$option
.
text
(
function
()
{
// Add hierarchy indicator in case hierarchy is enabled.
// Define parents and determine if current $link is a parent.
var
$parents
=
$link
.
parent
(
'
li.facet-item
'
).
parents
(
'
li.facet-item
'
);
var
is_parent
=
$link
.
parent
(
'
li.facet-item--expanded
'
).
length
>
0
;
$option
.
html
(
function
()
{
// Add label-based hierarchy indicator in case hierarchy is enabled.
var
$parents
=
$link
.
parent
(
'
li.facet-item
'
).
parents
(
'
li.facet-item
'
);
var
prefix
=
''
;
for
(
var
i
=
0
;
i
<
$parents
.
length
;
i
++
)
{
@@ -78,15 +89,53 @@
}
return
prefix
+
'
'
+
$link
.
text
().
trim
();
});
// Add some basic level and parent classing.
if
(
is_parent
)
{
$option
.
addClass
(
'
parent
'
);
}
if
(
typeof
$parents
!==
'
undefined
'
)
{
if
(
$parents
.
length
>
0
)
{
$option
.
addClass
(
'
level-
'
+
$parents
.
length
);
}
}
$dropdown
.
append
(
$option
);
});
$dropdown
.
data
(
'
facetsPreviousValue
'
,
$dropdown
.
val
());
// Go to the selected option when it's clicked.
$dropdown
.
on
(
'
change.facets
'
,
function
()
{
var
anchor
=
$
(
$ul
).
find
(
"
[data-drupal-facet-item-id='
"
+
$
(
this
).
find
(
'
:selected
'
).
data
(
'
drupalFacetItemId
'
)
+
"
']
"
);
var
anchor
=
[];
var
current
=
$
(
this
).
val
();
if
(
typeof
current
===
'
string
'
)
{
// Single select
anchor
=
$
(
$ul
).
find
(
"
[data-drupal-facet-item-id='
"
+
$
(
this
).
find
(
'
:selected
'
).
data
(
'
drupalFacetItemId
'
)
+
"
']
"
);
}
else
{
// Multiple select.
var
previous
=
$
(
this
).
data
(
'
facetsPreviousValue
'
);
var
added
=
$
(
current
).
not
(
previous
).
get
();
var
removed
=
$
(
previous
).
not
(
current
).
get
();
var
symDiff
=
added
.
concat
(
removed
);
var
filteredSymDiff
=
symDiff
.
filter
(
String
);
if
(
0
in
filteredSymDiff
)
{
anchor
=
$
(
$ul
).
find
(
"
[href='
"
+
filteredSymDiff
[
0
]
+
"
']
"
);
}
else
{
// If not, at least keep our house clean.
// This may only happen if our empty-text value was toggled.
$
(
this
).
data
(
'
facetsPreviousValue
'
,
current
);
}
}
var
$linkElement
=
(
anchor
.
length
>
0
)
?
$
(
anchor
)
:
$ul
.
find
(
'
.default-option a
'
);
var
url
=
$linkElement
.
attr
(
'
href
'
);
var
$widget
=
$
(
this
).
closest
(
'
.multiselect-native-select
'
);
Drupal
.
facets
.
disableFacet
(
$widget
);
$
(
this
).
trigger
(
'
facets_filter
'
,
[
url
]);
});
@@ -101,4 +150,26 @@
});
};
/**
* Disable all facet checkboxes in the facet and apply a 'disabled' class.
*
* @param {object} $facet
* jQuery object of the facet.
*/
Drupal
.
facets
.
disableFacet
=
function
(
$facet
)
{
$facet
.
addClass
(
'
facets-disabled
'
);
$
(
'
input:checkbox
'
,
$facet
).
click
(
Drupal
.
facets
.
preventDefault
);
$
(
'
input:checkbox
'
,
$facet
).
attr
(
'
disabled
'
,
true
);
};
/**
* Event listener for easy prevention of event propagation.
*
* @param {object} e
* Event.
*/
Drupal
.
facets
.
preventDefault
=
function
(
e
)
{
e
.
preventDefault
();
};
})(
jQuery
,
Drupal
,
once
);
Loading