Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / color / preview.es6.js
index 357a62680bc833f02d42b45ac5ae346ec5479c3f..cfc5e76b78d2e12423768c21ddcafab8d1ceef2f 100644 (file)
       form.find('#text a, #text h2').css('color', form.find('.color-palette input[name="palette[link]"]').val());
 
       function gradientLineColor(i, element) {
-        for (const k in accum) {
-          if (accum.hasOwnProperty(k)) {
-            accum[k] += delta[k];
-          }
-        }
+        Object.keys(accum || {}).forEach((k) => {
+          accum[k] += delta[k];
+        });
         element.style.backgroundColor = farb.pack(accum);
       }
 
       // Set up gradients if there are some.
-      let color_start;
-      let color_end;
-      for (const i in settings.gradients) {
-        if (settings.gradients.hasOwnProperty(i)) {
-          color_start = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[0]}]"]`).val());
-          color_end = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[1]}]"]`).val());
-          if (color_start && color_end) {
-            delta = [];
-            for (const j in color_start) {
-              if (color_start.hasOwnProperty(j)) {
-                delta[j] = (color_end[j] - color_start[j]) / (settings.gradients[i].vertical ? height[i] : width[i]);
-              }
-            }
-            accum = color_start;
-            // Render gradient lines.
-            form.find(`#gradient-${i} > div`).each(gradientLineColor);
-          }
+      let colorStart;
+      let colorEnd;
+      Object.keys(settings.gradients || {}).forEach((i) => {
+        colorStart = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[0]}]"]`).val());
+        colorEnd = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[1]}]"]`).val());
+        if (colorStart && colorEnd) {
+          delta = [];
+          Object.keys(colorStart || {}).forEach((colorStartKey) => {
+            delta[colorStartKey] = (colorEnd[colorStartKey] - colorStart[colorStartKey]) / (settings.gradients[i].vertical ? height[i] : width[i]);
+          });
+          accum = colorStart;
+          // Render gradient lines.
+          form.find(`#gradient-${i} > div`).each(gradientLineColor);
         }
-      }
+      });
     },
   };
 }(jQuery, Drupal));