Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_suite_bootstrap
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
ui_suite_bootstrap
Commits
ad400759
Commit
ad400759
authored
1 year ago
by
Florent Torregrosa
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3406533
by Grimreaper: [BS3 port] Message generated by JS
parent
617a1690
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!189
Issue #3406533 by Grimreaper: [BS3 port] Message generated by JS
Pipeline
#192767
passed
1 year ago
Stage: build
Stage: validate
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/js/misc/message.js
+166
-0
166 additions, 0 deletions
assets/js/misc/message.js
ui_suite_bootstrap.info.yml
+2
-0
2 additions, 0 deletions
ui_suite_bootstrap.info.yml
ui_suite_bootstrap.libraries.yml
+4
-0
4 additions, 0 deletions
ui_suite_bootstrap.libraries.yml
with
172 additions
and
0 deletions
assets/js/misc/message.js
0 → 100644
+
166
−
0
View file @
ad400759
/**
* @file
* message.js
*/
((
Drupal
)
=>
{
/**
* Helper function to map Drupal types to Bootstrap classes.
*
* @return {Object<String, String>}
* A map of classes, keyed by message type.
*/
Drupal
.
Message
.
getMessageTypeClasses
=
()
=>
{
return
{
status
:
'
success
'
,
error
:
'
danger
'
,
warning
:
'
warning
'
,
info
:
'
info
'
,
};
};
/**
* Retrieves the classes for a specific message type.
*
* @param {String} type
* The type of message.
*
* @return {String}
* The classes to add, space separated.
*/
Drupal
.
Message
.
getMessageTypeClass
=
(
type
)
=>
{
const
classes
=
Drupal
.
Message
.
getMessageTypeClasses
();
return
`alert alert-
${
classes
[
type
]
||
'
success
'
}
`
;
};
/**
* @inheritDoc
*/
Drupal
.
Message
.
getMessageTypeLabels
=
()
=>
{
return
{
status
:
Drupal
.
t
(
'
Status message
'
),
error
:
Drupal
.
t
(
'
Error message
'
),
warning
:
Drupal
.
t
(
'
Warning message
'
),
info
:
Drupal
.
t
(
'
Informative message
'
),
};
};
/**
* Retrieves a label for a specific message type.
*
* @param {String} type
* The type of message.
*
* @return {String}
* The message type label.
*/
Drupal
.
Message
.
getMessageTypeLabel
=
(
type
)
=>
{
const
labels
=
Drupal
.
Message
.
getMessageTypeLabels
();
return
labels
[
type
];
};
/**
* Map of the message type aria-role values.
*
* @return {Object<String, String>}
* A map of roles, keyed by message type.
*/
Drupal
.
Message
.
getMessageTypeRoles
=
()
=>
{
return
{
status
:
'
status
'
,
error
:
'
alert
'
,
warning
:
'
alert
'
,
info
:
'
status
'
,
};
};
/**
* Retrieves the aria-role for a specific message type.
*
* @param {String} type
* The type of message.
*
* @return {String}
* The message type role.
*/
Drupal
.
Message
.
getMessageTypeRole
=
(
type
)
=>
{
const
labels
=
Drupal
.
Message
.
getMessageTypeRoles
();
return
labels
[
type
];
};
/**
* @inheritDoc
*/
Drupal
.
theme
.
message
=
(
message
,
options
)
=>
{
options
=
options
||
{};
const
wrapper
=
Drupal
.
theme
(
'
messageWrapper
'
,
options
.
id
||
new
Date
().
getTime
(),
options
.
type
||
'
status
'
,
);
if
(
options
.
dismissible
===
undefined
||
!!
options
.
dismissible
)
{
wrapper
.
classList
.
add
(
'
alert-dismissible
'
,
'
fade
'
,
'
show
'
);
wrapper
.
appendChild
(
Drupal
.
theme
(
'
messageClose
'
));
}
wrapper
.
innerHTML
+=
message
&&
message
.
text
;
return
wrapper
;
};
/**
* Themes the message container.
*
* @param {String} id
* The message identifier.
* @param {String} type
* The type of message.
*
* @return {HTMLElement}
* A constructed HTMLElement.
*/
Drupal
.
theme
.
messageWrapper
=
(
id
,
type
)
=>
{
const
wrapper
=
document
.
createElement
(
'
div
'
);
const
label
=
Drupal
.
Message
.
getMessageTypeLabel
(
type
);
wrapper
.
setAttribute
(
'
class
'
,
Drupal
.
Message
.
getMessageTypeClass
(
type
));
wrapper
.
setAttribute
(
'
role
'
,
Drupal
.
Message
.
getMessageTypeRole
(
type
));
wrapper
.
setAttribute
(
'
aria-label
'
,
label
);
wrapper
.
setAttribute
(
'
data-drupal-message-id
'
,
id
);
wrapper
.
setAttribute
(
'
data-drupal-message-type
'
,
type
);
if
(
label
)
{
wrapper
.
appendChild
(
Drupal
.
theme
(
'
messageLabel
'
,
label
));
}
return
wrapper
;
};
/**
* Themes the message close button.
*
* @return {HTMLElement}
* A constructed HTMLElement.
*/
Drupal
.
theme
.
messageClose
=
()
=>
{
const
element
=
document
.
createElement
(
'
button
'
);
element
.
setAttribute
(
'
class
'
,
'
btn-close
'
);
element
.
setAttribute
(
'
type
'
,
'
button
'
);
element
.
setAttribute
(
'
role
'
,
'
button
'
);
element
.
setAttribute
(
'
data-bs-dismiss
'
,
'
alert
'
);
element
.
setAttribute
(
'
aria-label
'
,
Drupal
.
t
(
'
Close
'
));
return
element
;
};
/**
* Themes the message container.
*
* @param {String} label
* The message label.
*
* @return {HTMLElement}
* A constructed HTMLElement.
*/
Drupal
.
theme
.
messageLabel
=
(
label
)
=>
{
const
element
=
document
.
createElement
(
'
h4
'
);
element
.
setAttribute
(
'
class
'
,
'
visually-hidden
'
);
element
.
innerHTML
=
label
;
return
element
;
};
})(
Drupal
);
This diff is collapsed.
Click to expand it.
ui_suite_bootstrap.info.yml
+
2
−
0
View file @
ad400759
...
...
@@ -51,6 +51,8 @@ libraries-extend:
# - ui_suite_bootstrap/drupal.dialog.ajax
core/drupal.dialog.off_canvas
:
-
ui_suite_bootstrap/drupal.dialog.off_canvas
core/drupal.message
:
-
ui_suite_bootstrap/drupal.message
core/drupal.progress
:
-
ui_suite_bootstrap/drupal.progress
core/drupal.tabledrag
:
...
...
This diff is collapsed.
Click to expand it.
ui_suite_bootstrap.libraries.yml
+
4
−
0
View file @
ad400759
...
...
@@ -57,6 +57,10 @@ drupal.dialog.off_canvas:
assets/css/form/off-canvas.button.css
:
{}
assets/css/form/off-canvas.form.css
:
{}
drupal.message
:
js
:
assets/js/misc/message.js
:
{}
drupal.progress
:
js
:
assets/js/misc/progress.js
:
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment