Skip to content

Commit 3248b4d

Browse files
committed
Auto merge of #1880 - rust-lang:jquery-integration, r=carols10cents
Replace jQuery logic with native DOM
2 parents ad3b3f1 + c6c87e1 commit 3248b4d

File tree

16 files changed

+50
-44
lines changed

16 files changed

+50
-44
lines changed

app/components/api-token-row.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export default Component.extend({
77
serverError: null,
88

99
didInsertElement() {
10-
if (this.get('api_token.isNew')) {
11-
this.$('input').focus();
10+
let input = this.element.querySelector('input');
11+
if (input.focus) {
12+
input.focus();
1213
}
1314
},
1415

app/components/crate-readme.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ import Component from '@ember/component';
22

33
export default Component.extend({
44
rendered: '',
5+
56
didRender() {
67
this._super(...arguments);
7-
this.$('pre > code').each(function() {
8-
window.Prism.highlightElement(this);
9-
});
10-
this.scrollToFragment();
11-
},
128

13-
scrollToFragment() {
14-
if (location.hash) {
15-
let anchor_id = location.hash.substr(1);
16-
document.getElementById(anchor_id).scrollIntoView();
17-
}
9+
this.element.querySelectorAll('pre > code').forEach(function(node) {
10+
window.Prism.highlightElement(node);
11+
});
1812
},
1913
});

app/components/rl-dropdown.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Component from '@ember/component';
22
import { alias } from '@ember/object/computed';
33
import { computed } from '@ember/object';
4-
import $ from 'jquery';
54

65
import RlDropdownContainer from './rl-dropdown-container';
76

@@ -15,26 +14,17 @@ export default Component.extend({
1514

1615
isExpanded: alias('dropdownContainer.dropdownExpanded'),
1716

18-
closeOnChildClick: false,
19-
20-
propagateClicks: true,
21-
2217
click(event) {
23-
let closeOnChildClick = this.closeOnChildClick;
24-
let propagateClicks = this.propagateClicks;
25-
let $target = $(event.target);
26-
let $c = this.$();
18+
let closeOnChildClick = 'a:link';
19+
let $target = event.target;
20+
let $c = this.element;
2721

28-
if ($target !== $c) {
29-
if ((closeOnChildClick === true || closeOnChildClick === 'true') && $target.closest($c).length) {
30-
this.set('isExpanded', false);
31-
} else if (closeOnChildClick && $target.closest(closeOnChildClick, $c).length) {
32-
this.set('isExpanded', false);
33-
}
22+
if ($target === $c) {
23+
return;
3424
}
3525

36-
if (propagateClicks === false || propagateClicks === 'false') {
37-
event.stopPropagation();
26+
if ($target.closest(closeOnChildClick, $c).length) {
27+
this.set('isExpanded', false);
3828
}
3929
},
4030
});

app/templates/application.hbs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<span class='arrow'></span>
4141
{{/rl-dropdown-toggle}}
4242

43-
{{#rl-dropdown tagName="ul" id="doc-links" class="dropdown" closeOnChildClick="a:link"}}
43+
{{#rl-dropdown tagName="ul" id="doc-links" class="dropdown"}}
4444
<li><a href='https://doc.rust-lang.org/cargo/getting-started/'>Getting Started</a></li>
4545
<li><a href='https://doc.rust-lang.org/cargo/guide/'>Guide</a></li>
4646
<li><a href='https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html'>Specifying Dependencies</a></li>
@@ -66,7 +66,7 @@
6666
<span class='arrow'></span>
6767
{{/rl-dropdown-toggle}}
6868

69-
{{#rl-dropdown tagName="ul" class="dropdown current-user-links" closeOnChildClick="a:link"}}
69+
{{#rl-dropdown tagName="ul" class="dropdown current-user-links"}}
7070
<li>{{#link-to 'dashboard'}}Dashboard{{/link-to}}</li>
7171
<li>{{#link-to 'me'}}Account Settings{{/link-to}}</li>
7272
<li>{{#link-to 'me.pending-invites'}}Owner Invites{{/link-to}}</li>
@@ -87,7 +87,7 @@
8787
Menu
8888
<span class='arrow'></span>
8989
{{/rl-dropdown-toggle}}
90-
{{#rl-dropdown tagName='ul' class='dropdown current-user-links' closeOnChildClick='a:link'}}
90+
{{#rl-dropdown tagName='ul' class='dropdown current-user-links'}}
9191
<li>{{#link-to "crates"}}Browse All Crates{{/link-to}}</li>
9292
{{#if session.currentUser}}
9393
<li>{{#link-to 'dashboard'}}Dashboard{{/link-to}}</li>

app/templates/categories.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<span class='arrow'></span>
2424
{{/rl-dropdown-toggle}}
2525

26-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
26+
{{#rl-dropdown tagName="ul" class="dropdown"}}
2727
<li>
2828
{{#link-to (query-params sort="alpha")}}
2929
Alphabetical

app/templates/category/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<span class='arrow'></span>
5757
{{/rl-dropdown-toggle}}
5858

59-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
59+
{{#rl-dropdown tagName="ul" class="dropdown"}}
6060
<li>
6161
{{#link-to (query-params sort="alpha")}}
6262
Alphabetical

app/templates/components/api-token-row.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
placeholder="New token name"
77
disabled=api_token.isSaving
88
value=api_token.name
9-
autofocus=true
10-
enter="saveToken"}}
9+
autofocus="autofocus"
10+
enter="saveToken"
11+
data-test-focused-input=true
12+
}}
1113
{{else}}
1214
{{ api_token.name }}
1315
{{/if}}

app/templates/crates.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<span class='arrow'></span>
4545
{{/rl-dropdown-toggle}}
4646

47-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
47+
{{#rl-dropdown tagName="ul" class="dropdown"}}
4848
<li>
4949
{{#link-to (query-params page=1 sort="alpha")}}
5050
Alphabetical

app/templates/keyword/index.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<span class='arrow'></span>
2525
{{/rl-dropdown-toggle}}
2626

27-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
27+
{{#rl-dropdown tagName="ul" class="dropdown"}}
2828
<li>
2929
{{#link-to (query-params sort="alpha")}}
3030
Alphabetical

app/templates/keywords.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<span class='arrow'></span>
2424
{{/rl-dropdown-toggle}}
2525

26-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
26+
{{#rl-dropdown tagName="ul" class="dropdown"}}
2727
<li>
2828
{{#link-to (query-params sort="alpha")}}
2929
Alphabetical

app/templates/me/crates.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<span class='arrow'></span>
2626
{{/rl-dropdown-toggle}}
2727

28-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
28+
{{#rl-dropdown tagName="ul" class="dropdown"}}
2929
<li>
3030
{{#link-to (query-params sort="alpha")}}
3131
Alphabetical

app/templates/me/following.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<span class='arrow'></span>
2424
{{/rl-dropdown-toggle}}
2525

26-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
26+
{{#rl-dropdown tagName="ul" class="dropdown"}}
2727
<li>
2828
{{#link-to (query-params sort="alpha")}}
2929
Alphabetical

app/templates/search.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<span class='arrow'></span>
3737
{{/rl-dropdown-toggle}}
3838

39-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
39+
{{#rl-dropdown tagName="ul" class="dropdown"}}
4040
<li>
4141
{{#link-to (query-params page=1 sort="relevance")}}
4242
Relevance

app/templates/team.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<span class='arrow'></span>
4040
{{/rl-dropdown-toggle}}
4141

42-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
42+
{{#rl-dropdown tagName="ul" class="dropdown"}}
4343
<li>
4444
{{#link-to (query-params sort="alpha")}}
4545
Alphabetical

app/templates/user.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<span class='arrow'></span>
3131
{{/rl-dropdown-toggle}}
3232

33-
{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
33+
{{#rl-dropdown tagName="ul" class="dropdown"}}
3434
<li>
3535
{{#link-to (query-params sort="alpha")}}
3636
Alphabetical
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('Integration | Component | api-token-row', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('input is focused if token is new', async function(assert) {
10+
// Set any properties with this.set('myProperty', 'value');
11+
// Handle any actions with this.set('myAction', function(val) { ... });
12+
this.set('api_token', {
13+
isNew: true,
14+
});
15+
16+
await render(hbs`{{api-token-row api_token=api_token}}`);
17+
assert.dom('[data-test-focused-input]').isFocused();
18+
});
19+
});

0 commit comments

Comments
 (0)