X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmisc%2Fdrupal.es6.js;fp=web%2Fcore%2Fmisc%2Fdrupal.es6.js;h=546527a34c6bf90dc09e17ae53a47d95afeaa916;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=7054d5ee5ee1552922cb0b9e143ce5d33169aef1;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/core/misc/drupal.es6.js b/web/core/misc/drupal.es6.js index 7054d5ee5..546527a34 100644 --- a/web/core/misc/drupal.es6.js +++ b/web/core/misc/drupal.es6.js @@ -152,8 +152,8 @@ window.Drupal = { behaviors: {}, locale: {} }; 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); @@ -162,7 +162,7 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.throwError(e); } } - } + }); }; /** @@ -212,8 +212,8 @@ window.Drupal = { behaviors: {}, locale: {} }; 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); @@ -222,7 +222,7 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.throwError(e); } } - } + }); }; /** @@ -270,26 +270,24 @@ window.Drupal = { behaviors: {}, locale: {} }; // 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); }; @@ -317,12 +315,7 @@ window.Drupal = { behaviors: {}, locale: {} }; // 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); @@ -560,10 +553,9 @@ window.Drupal = { behaviors: {}, locale: {} }; * 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); } };