From e6e3c6be295cd3e5318978335a7ac4d37d21bf61 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 6 Sep 2019 14:53:08 +0100 Subject: [PATCH 1/7] replace jQuery with native logic --- app/components/api-token-row.js | 5 +++-- app/templates/components/api-token-row.hbs | 6 ++++-- .../components/api-token-row-test.js | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 tests/integration/components/api-token-row-test.js diff --git a/app/components/api-token-row.js b/app/components/api-token-row.js index eb8255a63ef..9c628e44148 100644 --- a/app/components/api-token-row.js +++ b/app/components/api-token-row.js @@ -7,8 +7,9 @@ export default Component.extend({ serverError: null, didInsertElement() { - if (this.get('api_token.isNew')) { - this.$('input').focus(); + let input = this.element.querySelector('input'); + if (input.focus) { + input.focus(); } }, diff --git a/app/templates/components/api-token-row.hbs b/app/templates/components/api-token-row.hbs index 8eeaf0a4dfa..03ad410e751 100644 --- a/app/templates/components/api-token-row.hbs +++ b/app/templates/components/api-token-row.hbs @@ -6,8 +6,10 @@ placeholder="New token name" disabled=api_token.isSaving value=api_token.name - autofocus=true - enter="saveToken"}} + autofocus="autofocus" + enter="saveToken" + data-test-focused-input=true + }} {{else}} {{ api_token.name }} {{/if}} diff --git a/tests/integration/components/api-token-row-test.js b/tests/integration/components/api-token-row-test.js new file mode 100644 index 00000000000..e02f4469acd --- /dev/null +++ b/tests/integration/components/api-token-row-test.js @@ -0,0 +1,19 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import hbs from 'htmlbars-inline-precompile'; + +module('Integration | Component | api-token-row', function(hooks) { + setupRenderingTest(hooks); + + test('input is focused if token is new', async function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + this.set('api_token', { + isNew: true, + }); + + await render(hbs`{{api-token-row api_token=api_token}}`); + assert.dom('[data-test-focused-input]').isFocused(); + }); +}); From 133432390cf0e3c0ea5e586f64896c8168539807 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 6 Sep 2019 15:00:17 +0100 Subject: [PATCH 2/7] use native DOM instead of jQuery --- app/components/crate-readme.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/components/crate-readme.js b/app/components/crate-readme.js index afe36ac80c5..a22e17c0283 100644 --- a/app/components/crate-readme.js +++ b/app/components/crate-readme.js @@ -2,18 +2,12 @@ import Component from '@ember/component'; export default Component.extend({ rendered: '', + didRender() { this._super(...arguments); - this.$('pre > code').each(function() { - window.Prism.highlightElement(this); - }); - this.scrollToFragment(); - }, - scrollToFragment() { - if (location.hash) { - let anchor_id = location.hash.substr(1); - document.getElementById(anchor_id).scrollIntoView(); - } + this.element.querySelectorAll('pre > code').forEach(function(node) { + window.Prism.highlightElement(node); + }); }, }); From afd9079cb70a669d440491bee5b0e3de7c4c7435 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sat, 26 Oct 2019 17:02:30 +0100 Subject: [PATCH 3/7] replace jQuery with native DOM --- app/components/rl-dropdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index be9b398f7a7..10e4ffe4723 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -22,8 +22,8 @@ export default Component.extend({ click(event) { let closeOnChildClick = this.closeOnChildClick; let propagateClicks = this.propagateClicks; - let $target = $(event.target); - let $c = this.$(); + let $target = event.target; + let $c = this.element; if ($target !== $c) { if ((closeOnChildClick === true || closeOnChildClick === 'true') && $target.closest($c).length) { From 26fe82ea7381cbb54d6bf6e020a5005c57a62ae4 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sat, 26 Oct 2019 17:02:57 +0100 Subject: [PATCH 4/7] remove unused code --- app/components/rl-dropdown.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index 10e4ffe4723..9f8d5ef3d9b 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -17,11 +17,8 @@ export default Component.extend({ closeOnChildClick: false, - propagateClicks: true, - click(event) { let closeOnChildClick = this.closeOnChildClick; - let propagateClicks = this.propagateClicks; let $target = event.target; let $c = this.element; @@ -32,9 +29,5 @@ export default Component.extend({ this.set('isExpanded', false); } } - - if (propagateClicks === false || propagateClicks === 'false') { - event.stopPropagation(); - } }, }); From e0de9c7f6ec4b1e0ad8119751b5b61008d3f7d69 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sat, 26 Oct 2019 17:03:52 +0100 Subject: [PATCH 5/7] make closeOnChildClick default to 'a:link' --- app/components/rl-dropdown.js | 4 +--- app/templates/application.hbs | 6 +++--- app/templates/categories.hbs | 2 +- app/templates/category/index.hbs | 2 +- app/templates/crates.hbs | 2 +- app/templates/keyword/index.hbs | 2 +- app/templates/keywords.hbs | 2 +- app/templates/me/crates.hbs | 2 +- app/templates/me/following.hbs | 2 +- app/templates/search.hbs | 2 +- app/templates/team.hbs | 2 +- app/templates/user.hbs | 2 +- 12 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index 9f8d5ef3d9b..649013418ae 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -15,10 +15,8 @@ export default Component.extend({ isExpanded: alias('dropdownContainer.dropdownExpanded'), - closeOnChildClick: false, - click(event) { - let closeOnChildClick = this.closeOnChildClick; + let closeOnChildClick = 'a:link'; let $target = event.target; let $c = this.element; diff --git a/app/templates/application.hbs b/app/templates/application.hbs index 7ceb2e7cc56..3f9fa6ca4f2 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -40,7 +40,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" id="doc-links" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" id="doc-links" class="dropdown"}}
  • Getting Started
  • Guide
  • Specifying Dependencies
  • @@ -66,7 +66,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown current-user-links" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown current-user-links"}}
  • {{#link-to 'dashboard'}}Dashboard{{/link-to}}
  • {{#link-to 'me'}}Account Settings{{/link-to}}
  • {{#link-to 'me.pending-invites'}}Owner Invites{{/link-to}}
  • @@ -87,7 +87,7 @@ Menu {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName='ul' class='dropdown current-user-links' closeOnChildClick='a:link'}} + {{#rl-dropdown tagName='ul' class='dropdown current-user-links'}}
  • {{#link-to "crates"}}Browse All Crates{{/link-to}}
  • {{#if session.currentUser}}
  • {{#link-to 'dashboard'}}Dashboard{{/link-to}}
  • diff --git a/app/templates/categories.hbs b/app/templates/categories.hbs index b3ae63b6e5e..84541644726 100644 --- a/app/templates/categories.hbs +++ b/app/templates/categories.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/category/index.hbs b/app/templates/category/index.hbs index 537ce8c60d8..a5dc2aa3ca0 100644 --- a/app/templates/category/index.hbs +++ b/app/templates/category/index.hbs @@ -56,7 +56,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/crates.hbs b/app/templates/crates.hbs index bca965170e6..c9d2f7d77fc 100644 --- a/app/templates/crates.hbs +++ b/app/templates/crates.hbs @@ -44,7 +44,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params page=1 sort="alpha")}} Alphabetical diff --git a/app/templates/keyword/index.hbs b/app/templates/keyword/index.hbs index dccefc5fe28..f6a4f69f276 100644 --- a/app/templates/keyword/index.hbs +++ b/app/templates/keyword/index.hbs @@ -24,7 +24,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/keywords.hbs b/app/templates/keywords.hbs index 10751d85297..3e6ec64ea9e 100644 --- a/app/templates/keywords.hbs +++ b/app/templates/keywords.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/me/crates.hbs b/app/templates/me/crates.hbs index c5dfd9e7041..526b4441532 100644 --- a/app/templates/me/crates.hbs +++ b/app/templates/me/crates.hbs @@ -25,7 +25,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/me/following.hbs b/app/templates/me/following.hbs index de3047b1a8e..3ba95f6d3d6 100644 --- a/app/templates/me/following.hbs +++ b/app/templates/me/following.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/search.hbs b/app/templates/search.hbs index 89282b73454..35ba03851b0 100644 --- a/app/templates/search.hbs +++ b/app/templates/search.hbs @@ -36,7 +36,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params page=1 sort="relevance")}} Relevance diff --git a/app/templates/team.hbs b/app/templates/team.hbs index d0821752c04..cddc243c0f4 100644 --- a/app/templates/team.hbs +++ b/app/templates/team.hbs @@ -39,7 +39,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/user.hbs b/app/templates/user.hbs index be98992d829..b61f30f6e0c 100644 --- a/app/templates/user.hbs +++ b/app/templates/user.hbs @@ -30,7 +30,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical From ae0f5a5965e0cd245da9285fa6238acd2c7a9d83 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sat, 26 Oct 2019 17:04:51 +0100 Subject: [PATCH 6/7] remove conditional logic that does nothing --- app/components/rl-dropdown.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index 649013418ae..b36ae054914 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -20,12 +20,12 @@ export default Component.extend({ let $target = event.target; let $c = this.element; - if ($target !== $c) { - if ((closeOnChildClick === true || closeOnChildClick === 'true') && $target.closest($c).length) { - this.set('isExpanded', false); - } else if (closeOnChildClick && $target.closest(closeOnChildClick, $c).length) { - this.set('isExpanded', false); - } + if ($target === $c) { + return; + } + + if ($target.closest(closeOnChildClick, $c).length) { + this.set('isExpanded', false); } }, }); From c6c87e137a15864aaf438c86d13cbae2d033bb99 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Sat, 26 Oct 2019 17:29:10 +0100 Subject: [PATCH 7/7] remove unused import --- app/components/rl-dropdown.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index b36ae054914..f0752a797f5 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -1,7 +1,6 @@ import Component from '@ember/component'; import { alias } from '@ember/object/computed'; import { computed } from '@ember/object'; -import $ from 'jquery'; import RlDropdownContainer from './rl-dropdown-container';