Bug 1217328 - make FilterWidget.js eslint-clean. r=pbrosset
authorTom Tromey <tromey@mozilla.com>
Mon, 26 Oct 2015 06:22:00 +0100
changeset 269593 396ed517522291ed0af520e2f117c98a04217502
parent 269592 ab1666bd0cc7ac3931bcbe11481ab9ecf7c720d0
child 269594 150b4bb5d07bb86735e914e1a2afcde3fcf33a12
push id15899
push usercbook@mozilla.com
push dateTue, 27 Oct 2015 08:35:03 +0000
treeherderfx-team@10533587f045 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbrosset
bugs1217328
milestone44.0a1
Bug 1217328 - make FilterWidget.js eslint-clean. r=pbrosset
devtools/client/shared/widgets/FilterWidget.js
--- a/devtools/client/shared/widgets/FilterWidget.js
+++ b/devtools/client/shared/widgets/FilterWidget.js
@@ -6,17 +6,19 @@
 
 /**
   * This is a CSS Filter Editor widget used
   * for Rule View's filter swatches
   */
 
 const EventEmitter = require("devtools/shared/event-emitter");
 const { Cu } = require("chrome");
-const { ViewHelpers } = Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm", {});
+const { ViewHelpers } =
+      Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm",
+                {});
 const STRINGS_URI = "chrome://browser/locale/devtools/filterwidget.properties";
 const L10N = new ViewHelpers.L10N(STRINGS_URI);
 const {cssTokenizer} = require("devtools/client/shared/css-parsing-utils");
 
 loader.lazyGetter(this, "asyncStorage",
                   () => require("devtools/shared/async-storage"));
 
 const DEFAULT_FILTER_TYPE = "length";
@@ -302,34 +304,37 @@ CSSFilterEditorWidget.prototype = {
     // the value can be incremented/decremented simply.
     // For other types of filters (e.g. drop-shadow) we need to check
     // if the keypress happened close to a number first.
     if (filter.unit) {
       let startValue = parseFloat(e.target.value);
       let value = startValue + direction * multiplier;
 
       const [min, max] = this._definition(filter.name).range;
-      value = value < min ? min :
-              value > max ? max : value;
+      if (value < min) {
+        value = min;
+      } else if (value > max) {
+        value = max;
+      }
 
       input.value = fixFloat(value);
 
       this.updateValueAt(index, value);
     } else {
       let selectionStart = input.selectionStart;
       let num = getNeighbourNumber(input.value, selectionStart);
       if (!num) {
         return;
       }
 
       let {start, end, value} = num;
 
       let split = input.value.split("");
-      let computed = fixFloat(value + direction * multiplier),
-          dotIndex = computed.indexOf(".0");
+      let computed = fixFloat(value + direction * multiplier);
+      let dotIndex = computed.indexOf(".0");
       if (dotIndex > -1) {
         computed = computed.slice(0, -2);
 
         selectionStart = selectionStart > start + dotIndex ?
                                           start + dotIndex :
                                           selectionStart;
       }
       split.splice(start, end - start, computed);
@@ -338,20 +343,20 @@ CSSFilterEditorWidget.prototype = {
       input.value = value;
       this.updateValueAt(index, value);
       input.setSelectionRange(selectionStart, selectionStart);
     }
     e.preventDefault();
   },
 
   _input: function(e) {
-    let filterEl = e.target.closest(".filter"),
-        index = this._getFilterElementIndex(filterEl),
-        filter = this.filters[index],
-        def = this._definition(filter.name);
+    let filterEl = e.target.closest(".filter");
+    let index = this._getFilterElementIndex(filterEl);
+    let filter = this.filters[index];
+    let def = this._definition(filter.name);
 
     if (def.type !== "string") {
       e.target.value = fixFloat(e.target.value);
     }
     this.updateValueAt(index, e.target.value);
   },
 
   _mouseDown: function(e) {
@@ -361,19 +366,19 @@ CSSFilterEditorWidget.prototype = {
     if (e.target.tagName.toLowerCase() === "i") {
       this.isReorderingFilter = true;
       filterEl.startingY = e.pageY;
       filterEl.classList.add("dragging");
 
       this.el.classList.add("dragging");
     // label-dragging
     } else if (e.target.classList.contains("devtools-draglabel")) {
-      let label = e.target,
-          input = filterEl.querySelector("input"),
-          index = this._getFilterElementIndex(filterEl);
+      let label = e.target;
+      let input = filterEl.querySelector("input");
+      let index = this._getFilterElementIndex(filterEl);
 
       this._dragging = {
         index, label, input,
         startX: e.pageX
       };
 
       this.isDraggingLabel = true;
     }
@@ -418,34 +423,37 @@ CSSFilterEditorWidget.prototype = {
     if (this.isReorderingFilter) {
       this._dragFilterElement(e);
     } else if (this.isDraggingLabel) {
       this._dragLabel(e);
     }
   },
 
   _dragFilterElement: function(e) {
-    const rect = this.filtersList.getBoundingClientRect(),
-          top = e.pageY - LIST_PADDING,
-          bottom = e.pageY + LIST_PADDING;
+    const rect = this.filtersList.getBoundingClientRect();
+    let top = e.pageY - LIST_PADDING;
+    let bottom = e.pageY + LIST_PADDING;
     // don't allow dragging over top/bottom of list
     if (top < rect.top || bottom > rect.bottom) {
       return;
     }
 
     const filterEl = this.filtersList.querySelector(".dragging");
 
     const delta = e.pageY - filterEl.startingY;
     filterEl.style.top = delta + "px";
 
     // change is the number of _steps_ taken from initial position
     // i.e. how many elements we have passed
     let change = delta / LIST_ITEM_HEIGHT;
-    change = change > 0 ? Math.floor(change) :
-             change < 0 ? Math.ceil(change) : change;
+    if (change > 0) {
+      change = Math.floor(change);
+    } else if (change < 0) {
+      change = Math.ceil(change);
+    }
 
     const children = this.filtersList.children;
     const index = [...children].indexOf(filterEl);
     const destination = index + change;
 
     // If we're moving out, or there's no change at all, stop and return
     if (destination >= children.length || destination < 0 || change === 0) {
       return;
@@ -484,18 +492,21 @@ CSSFilterEditorWidget.prototype = {
 
     dragging.lastX = e.pageX;
     const delta = e.pageX - dragging.startX;
     const startValue = parseFloat(input.value);
     let value = startValue + delta * multiplier;
 
     const filter = this.filters[dragging.index];
     const [min, max] = this._definition(filter.name).range;
-    value = value < min ? min :
-            value > max ? max : value;
+    if (value < min) {
+      value = min;
+    } else if (value > max) {
+      value = max;
+    }
 
     input.value = fixFloat(value);
 
     dragging.startX = e.pageX;
 
     this.updateValueAt(dragging.index, value);
   },
 
@@ -546,18 +557,18 @@ CSSFilterEditorWidget.prototype = {
   _togglePresets: function() {
     this.el.classList.toggle("show-presets");
     this.emit("render");
   },
 
   _savePreset: function(e) {
     e.preventDefault();
 
-    let name = this.addPresetInput.value,
-        value = this.getCssValue();
+    let name = this.addPresetInput.value;
+    let value = this.getCssValue();
 
     if (!name || !value || value === "none") {
       this.emit("preset-save-error");
       return;
     }
 
     this.getPresets().then(presets => {
       let index = presets.findIndex(preset => preset.name === name);
@@ -588,19 +599,19 @@ CSSFilterEditorWidget.prototype = {
 
     let base = this._filterItemMarkup;
 
     for (let filter of this.filters) {
       const def = this._definition(filter.name);
 
       let el = base.cloneNode(true);
 
-      let [name, value] = el.children,
-          label = name.children[1],
-          [input, unitPreview] = value.children;
+      let [name, value] = el.children;
+      let label = name.children[1];
+      let [input, unitPreview] = value.children;
 
       let min, max;
       if (def.range) {
         [min, max] = def.range;
       }
 
       label.textContent = filter.name;
       input.value = filter.value;
@@ -610,21 +621,21 @@ CSSFilterEditorWidget.prototype = {
         case "angle":
         case "length":
           input.type = "number";
           input.min = min;
           if (max !== Infinity) {
             input.max = max;
           }
           input.step = "0.1";
-        break;
+          break;
         case "string":
           input.type = "text";
           input.placeholder = def.placeholder;
-        break;
+          break;
       }
 
       // use photoshop-style label-dragging
       // and show filters' unit next to their <input>
       if (def.type !== "string") {
         unitPreview.textContent = filter.unit;
 
         label.classList.add("devtools-draglabel");
@@ -632,17 +643,18 @@ CSSFilterEditorWidget.prototype = {
       } else {
         // string-type filters have no unit
         unitPreview.remove();
       }
 
       this.filtersList.appendChild(el);
     }
 
-    let lastInput = this.filtersList.querySelector(`.filter:last-of-type input`);
+    let lastInput =
+        this.filtersList.querySelector(`.filter:last-of-type input`);
     if (lastInput) {
       lastInput.focus();
       // move cursor to end of input
       const end = lastInput.value.length;
       lastInput.setSelectionRange(end, end);
     }
 
     this.emit("render");
@@ -935,18 +947,18 @@ function tokenizeFilterValue(css) {
   *         start: The number's starting index
   *         end: The number's ending index
   */
 function getNeighbourNumber(string, index) {
   if (!/\d/.test(string)) {
     return null;
   }
 
-  let left = /-?[0-9.]*$/.exec(string.slice(0, index)),
-      right = /-?[0-9.]*/.exec(string.slice(index));
+  let left = /-?[0-9.]*$/.exec(string.slice(0, index));
+  let right = /-?[0-9.]*/.exec(string.slice(index));
 
   left = left ? left[0] : "";
   right = right ? right[0] : "";
 
   if (!right && !left) {
     return null;
   }