settings = settings || drupalSettings;
const behaviors = Drupal.behaviors;
// Execute all of them.
- for (const i in behaviors) {
- if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') {
+ Object.keys(behaviors || {}).forEach((i) => {
+ if (typeof behaviors[i].attach === 'function') {
// Don't stop the execution of behaviors in case of an error.
try {
behaviors[i].attach(context, settings);
Drupal.throwError(e);
}
}
- }
+ });
};
/**
trigger = trigger || 'unload';
const behaviors = Drupal.behaviors;
// Execute all of them.
- for (const i in behaviors) {
- if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') {
+ Object.keys(behaviors || {}).forEach((i) => {
+ if (typeof behaviors[i].detach === 'function') {
// Don't stop the execution of behaviors in case of an error.
try {
behaviors[i].detach(context, settings, trigger);
Drupal.throwError(e);
}
}
- }
+ });
};
/**
// Keep args intact.
const processedArgs = {};
// Transform arguments before inserting them.
- for (const key in args) {
- if (args.hasOwnProperty(key)) {
- switch (key.charAt(0)) {
- // Escaped only.
- case '@':
- processedArgs[key] = Drupal.checkPlain(args[key]);
- break;
-
- // Pass-through.
- case '!':
- processedArgs[key] = args[key];
- break;
-
- // Escaped and placeholder.
- default:
- processedArgs[key] = Drupal.theme('placeholder', args[key]);
- break;
- }
+ Object.keys(args || {}).forEach((key) => {
+ switch (key.charAt(0)) {
+ // Escaped only.
+ case '@':
+ processedArgs[key] = Drupal.checkPlain(args[key]);
+ break;
+
+ // Pass-through.
+ case '!':
+ processedArgs[key] = args[key];
+ break;
+
+ // Escaped and placeholder.
+ default:
+ processedArgs[key] = Drupal.theme('placeholder', args[key]);
+ break;
}
- }
+ });
return Drupal.stringReplace(str, processedArgs, null);
};
// If the array of keys is not passed then collect the keys from the args.
if (!Array.isArray(keys)) {
- keys = [];
- for (const k in args) {
- if (args.hasOwnProperty(k)) {
- keys.push(k);
- }
- }
+ keys = Object.keys(args || {});
// Order the keys by the character length. The shortest one is the first.
keys.sort((a, b) => a.length - b.length);
* Any data the theme function returns. This could be a plain HTML string,
* but also a complex object.
*/
- Drupal.theme = function (func) {
- const args = Array.prototype.slice.apply(arguments, [1]);
+ Drupal.theme = function (func, ...args) {
if (func in Drupal.theme) {
- return Drupal.theme[func].apply(this, args);
+ return Drupal.theme[func](...args);
}
};