Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / misc / drupal.js
index f0c2b72243f75a53877b093f9d2dbe0076fde103..39a74e4f51863ef988be9b8bc987ae4b4798aa6a 100644 (file)
@@ -19,15 +19,15 @@ window.Drupal = { behaviors: {}, locale: {} };
     settings = settings || drupalSettings;
     var behaviors = Drupal.behaviors;
 
-    for (var i in behaviors) {
-      if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') {
+    Object.keys(behaviors || {}).forEach(function (i) {
+      if (typeof behaviors[i].attach === 'function') {
         try {
           behaviors[i].attach(context, settings);
         } catch (e) {
           Drupal.throwError(e);
         }
       }
-    }
+    });
   };
 
   Drupal.detachBehaviors = function (context, settings, trigger) {
@@ -36,15 +36,15 @@ window.Drupal = { behaviors: {}, locale: {} };
     trigger = trigger || 'unload';
     var behaviors = Drupal.behaviors;
 
-    for (var i in behaviors) {
-      if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') {
+    Object.keys(behaviors || {}).forEach(function (i) {
+      if (typeof behaviors[i].detach === 'function') {
         try {
           behaviors[i].detach(context, settings, trigger);
         } catch (e) {
           Drupal.throwError(e);
         }
       }
-    }
+    });
   };
 
   Drupal.checkPlain = function (str) {
@@ -55,23 +55,21 @@ window.Drupal = { behaviors: {}, locale: {} };
   Drupal.formatString = function (str, args) {
     var processedArgs = {};
 
-    for (var key in args) {
-      if (args.hasOwnProperty(key)) {
-        switch (key.charAt(0)) {
-          case '@':
-            processedArgs[key] = Drupal.checkPlain(args[key]);
-            break;
+    Object.keys(args || {}).forEach(function (key) {
+      switch (key.charAt(0)) {
+        case '@':
+          processedArgs[key] = Drupal.checkPlain(args[key]);
+          break;
 
-          case '!':
-            processedArgs[key] = args[key];
-            break;
+        case '!':
+          processedArgs[key] = args[key];
+          break;
 
-          default:
-            processedArgs[key] = Drupal.theme('placeholder', args[key]);
-            break;
-        }
+        default:
+          processedArgs[key] = Drupal.theme('placeholder', args[key]);
+          break;
       }
-    }
+    });
 
     return Drupal.stringReplace(str, processedArgs, null);
   };
@@ -82,12 +80,7 @@ window.Drupal = { behaviors: {}, locale: {} };
     }
 
     if (!Array.isArray(keys)) {
-      keys = [];
-      for (var k in args) {
-        if (args.hasOwnProperty(k)) {
-          keys.push(k);
-        }
-      }
+      keys = Object.keys(args || {});
 
       keys.sort(function (a, b) {
         return a.length - b.length;
@@ -181,9 +174,14 @@ window.Drupal = { behaviors: {}, locale: {} };
   };
 
   Drupal.theme = function (func) {
-    var args = Array.prototype.slice.apply(arguments, [1]);
     if (func in Drupal.theme) {
-      return Drupal.theme[func].apply(this, args);
+      var _Drupal$theme;
+
+      for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
+        args[_key - 1] = arguments[_key];
+      }
+
+      return (_Drupal$theme = Drupal.theme)[func].apply(_Drupal$theme, args);
     }
   };