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
!146
Issue
#2937191
: Render using theme input and select instead of lists with links for checkboxes and dropdown
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2937191
: Render using theme input and select instead of lists with links for checkboxes and dropdown
issue/facets-2937191:2937191-render-using-theme-2.0.x-v2
into
2.0.x
Overview
1
Commits
8
Pipelines
4
Changes
17
1 unresolved thread
Hide all comments
Open
codebymikey
requested to merge
issue/facets-2937191:2937191-render-using-theme-2.0.x-v2
into
2.0.x
1 year ago
Overview
1
Commits
8
Pipelines
4
Changes
17
1 unresolved thread
Hide all comments
Expand
0
0
Merge request reports
Compare
2.0.x
version 8
fa1b15d7
4 months ago
version 7
db79af9f
4 months ago
version 6
5d49cbca
4 months ago
version 5
b9c215d6
4 months ago
version 4
ff35729b
1 year ago
version 3
24fb00b3
1 year ago
version 2
7651798f
1 year ago
version 1
e2792ef6
1 year ago
2.0.x (HEAD)
and
latest version
latest version
02645063
8 commits,
3 months ago
version 8
fa1b15d7
7 commits,
4 months ago
version 7
db79af9f
6 commits,
4 months ago
version 6
5d49cbca
5 commits,
4 months ago
version 5
b9c215d6
4 commits,
4 months ago
version 4
ff35729b
3 commits,
1 year ago
version 3
24fb00b3
2 commits,
1 year ago
version 2
7651798f
2 commits,
1 year ago
version 1
e2792ef6
2 commits,
1 year ago
17 files
+
502
−
217
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
17
Search (e.g. *.vue) (Ctrl+P)
js/checkbox-widget.js
+
21
−
61
Options
/**
* @file
*
Transforms links into
checkboxes.
*
Navigate to the correct url when a
checkbox
chang
es.
*/
(
function
(
$
,
Drupal
,
once
)
{
@@ -10,7 +10,9 @@
Drupal
.
facets
=
Drupal
.
facets
||
{};
Drupal
.
behaviors
.
facetsCheckboxWidget
=
{
attach
:
function
(
context
)
{
Drupal
.
facets
.
makeCheckboxes
(
context
);
// Find all checkbox facet results and add an event listener.
var
$checkboxes
=
$
(
once
(
'
facets-checkbox-transform
'
,
'
.js-facets-checkbox-links input[type="checkbox"]
'
,
context
));
$checkboxes
.
each
(
Drupal
.
facets
.
addCheckboxChangeListener
);
}
};
@@ -28,67 +30,15 @@
};
/**
*
Turns all facet links into checkboxes
.
*
Add event listener to the change event of the checkboxes to navigate to the correct url
.
*/
Drupal
.
facets
.
makeCheckboxes
=
function
(
context
)
{
// Find all checkbox facet links and give them a checkbox.
var
$checkboxWidgets
=
$
(
once
(
'
facets-checkbox-transform
'
,
'
.js-facets-checkbox-links
'
,
context
));
if
(
$checkboxWidgets
.
length
>
0
)
{
$checkboxWidgets
.
each
(
function
(
index
,
widget
)
{
var
$widget
=
$
(
widget
);
var
$widgetLinks
=
$widget
.
find
(
'
.facet-item > a
'
);
// Add correct CSS selector for the widget. The Facets JS API will
// register handlers on that element.
$widget
.
addClass
(
'
js-facets-widget
'
);
// Transform links to checkboxes.
$widgetLinks
.
each
(
Drupal
.
facets
.
makeCheckbox
);
// We have to trigger attaching of behaviours, so that Facets JS API can
// register handlers on checkbox widgets.
Drupal
.
attachBehaviors
(
this
.
parentNode
,
Drupal
.
settings
);
});
}
// Set indeterminate value on parents having an active trail.
$
(
'
.facet-item--expanded.facet-item--active-trail > input
'
).
prop
(
'
indeterminate
'
,
true
);
};
/**
* Replace a link with a checked checkbox.
*/
Drupal
.
facets
.
makeCheckbox
=
function
()
{
var
$link
=
$
(
this
);
var
active
=
$link
.
hasClass
(
'
is-active
'
);
var
description
=
$link
.
html
();
var
href
=
$link
.
attr
(
'
href
'
);
var
id
=
$link
.
data
(
'
drupal-facet-item-id
'
);
var
checkbox
=
$
(
'
<input type="checkbox" class="facets-checkbox">
'
)
.
attr
(
'
id
'
,
id
)
.
data
(
$link
.
data
())
.
data
(
'
facetsredir
'
,
href
);
var
label
=
$
(
'
<label for="
'
+
id
+
'
">
'
+
description
+
'
</label>
'
);
checkbox
.
on
(
'
change.facets
'
,
function
(
e
)
{
e
.
preventDefault
();
var
$widget
=
$
(
this
).
closest
(
'
.js-facets-widget
'
);
Drupal
.
facets
.
disableFacet
(
$widget
);
$widget
.
trigger
(
'
facets_filter
'
,
[
href
]);
Drupal
.
facets
.
addCheckboxChangeListener
=
function
()
{
var
$checkbox
=
$
(
this
);
$checkbox
.
on
(
'
change.facets
'
,
function
(
e
)
{
var
$widget
=
$checkbox
.
parents
(
'
.js-facets-checkbox-links
'
);
Drupal
.
facets
.
disableCheckboxFacet
(
$widget
);
$widget
.
trigger
(
'
facets_filter
'
,
[
$checkbox
.
val
()
]);
});
if
(
active
)
{
checkbox
.
attr
(
'
checked
'
,
true
);
label
.
find
(
'
.js-facet-deactivate
'
).
remove
();
}
$link
.
before
(
checkbox
).
before
(
label
).
hide
();
};
/**
@@ -115,6 +65,16 @@
$
(
'
input.facets-checkbox
'
,
$facet
).
attr
(
'
disabled
'
,
true
);
};
/**
* Callback to disable checkbox facets.
*/
Drupal
.
facets
.
disableCheckboxFacet
=
function
(
$widget
)
{
$widget
.
addClass
(
'
facets-disabled form-disabled
'
);
var
$checkboxes
=
$
(
'
input[type="checkbox"]
'
,
$widget
);
$checkboxes
.
click
(
Drupal
.
facets
.
preventDefault
);
$checkboxes
.
attr
(
'
disabled
'
,
true
);
};
/**
* Event listener for easy prevention of event propagation.
*
Loading