Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually all those <code>return</code> statements are confusing the issue, but they offer a hint to the solution.</p> <pre><code>if (direction) { this.close(); } else { if (this.content.getBoundingClientRect().left &gt; viewport / 2 &amp;&amp; pulled === true) { this.close(); return; // We'll never `this.open()` if this is true anyway, so combine the booleans. } this.open(); } </code></pre> <p>How about:</p> <pre><code>if (direction || (this.content.getBoundingClientRect().left &gt; viewport / 2 &amp;&amp; pulled === true)) { this.close(); } else { this.open(); } </code></pre> <p>And as for:</p> <pre><code>if (this.content.getBoundingClientRect().left &gt; viewport / 2) { if (this.isEmpty(delta) || delta.x &gt; 0) { this.close(); return; // Combine the booleans! } this.open(); return; } </code></pre> <p>Simplify:</p> <pre><code>if ((this.isEmpty(delta) || delta.x &gt; 0) || !this.content.getBoundingClientRect().left &gt; viewport / 2) { this.close(); } else { this.open(); } </code></pre> <p>(Aside: The original post left out a closing brace. If you (OP) intended that the function continues past your post, then this answer is wrong (but you should've made that clearer))</p> <p>Result: We've eliminated two (repeated) decisions:</p> <pre><code>function () { var duration = +new Date() - start.time, isPastHalf = Number(duration) &lt; 250 &amp;&amp; Math.abs(delta.x) &gt; 20 || Math.abs(delta.x) &gt; viewport / 2, direction = delta.x &lt; 0; if (!isScrolling) { if (isPastHalf) { if (direction || (this.content.getBoundingClientRect().left &gt; viewport / 2 &amp;&amp; pulled === true)) { this.close(); } else { this.open(); } } else { if ((this.isEmpty(delta) || delta.x &gt; 0) || !this.content.getBoundingClientRect().left &gt; viewport / 2) { this.close(); } else { this.open(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload