Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / color / color.js
index 1b036c3aa1bf05de327b243e34151a2adcb969fc..5cc0b9be12d94d407f4ca737336601b70796e1ed 100644 (file)
       var farb = $.farbtastic('.color-placeholder');
 
       var reference = settings.color.reference;
-      for (i in reference) {
-        if (reference.hasOwnProperty(i)) {
-          reference[i] = farb.RGBToHSL(farb.unpack(reference[i]));
-        }
-      }
+      Object.keys(reference || {}).forEach(function (color) {
+        reference[color] = farb.RGBToHSL(farb.unpack(reference[color]));
+      });
 
       var height = [];
       var width = [];
 
-      for (i in settings.gradients) {
-        if (settings.gradients.hasOwnProperty(i)) {
-          $('.color-preview').once('color').append('<div id="gradient-' + i + '"></div>');
-          var gradient = $('.color-preview #gradient-' + i);
+      Object.keys(settings.gradients || {}).forEach(function (i) {
+        $('.color-preview').once('color').append('<div id="gradient-' + i + '"></div>');
+        var gradient = $('.color-preview #gradient-' + i);
 
-          height.push(parseInt(gradient.css('height'), 10) / 10);
+        height.push(parseInt(gradient.css('height'), 10) / 10);
 
-          width.push(parseInt(gradient.css('width'), 10) / 10);
+        width.push(parseInt(gradient.css('width'), 10) / 10);
 
-          for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) {
-            gradient.append('<div class="gradient-line"></div>');
-          }
+        for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) {
+          gradient.append('<div class="gradient-line"></div>');
         }
-      }
+      });
 
       form.find('#edit-scheme').on('change', function () {
         var schemes = settings.color.schemes;
         var colorScheme = this.options[this.selectedIndex].value;
         if (colorScheme !== '' && schemes[colorScheme]) {
           colors = schemes[colorScheme];
-          for (var fieldName in colors) {
-            if (colors.hasOwnProperty(fieldName)) {
-              callback($('#edit-palette-' + fieldName), colors[fieldName], false, true);
-            }
-          }
+          Object.keys(colors || {}).forEach(function (fieldName) {
+            callback($('#edit-palette-' + fieldName), colors[fieldName], false, true);
+          });
           preview();
         }
       });
@@ -67,7 +61,7 @@
         Drupal.color.callback(context, settings, form, farb, height, width);
       }
 
-      function shift_color(given, ref1, ref2) {
+      function shiftColor(given, ref1, ref2) {
         var d = void 0;
 
         given = farb.RGBToHSL(farb.unpack(given));
               if (!locks[j - 1] || $(locks[j - 1]).is('.is-unlocked')) {
                 break;
               }
-              matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+              matched = shiftColor(color, reference[input.key], reference[inputs[j].key]);
               callback(inputs[j], matched, false);
             }
             for (j = i - 1;; --j) {
               if (!locks[j] || $(locks[j]).is('.is-unlocked')) {
                 break;
               }
-              matched = shift_color(color, reference[input.key], reference[inputs[j].key]);
+              matched = shiftColor(color, reference[input.key], reference[inputs[j].key]);
               callback(inputs[j], matched, false);
             }