Skip to content

Commit 32e6aea

Browse files
committed
Remove use of jquery for DOM manipulation
1 parent 1454a31 commit 32e6aea

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

nbgitpuller/static/js/index.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ GitSync.prototype.addHandler = function(event, cb) {
2424

2525
GitSync.prototype._emit = function(event, data) {
2626
if (this.callbacks[event] == undefined) { return; }
27-
$.each(this.callbacks[event], function(i, ev) {
27+
for(let ev of this.callbacks[event]) {
2828
ev(data);
29-
});
29+
}
3030
};
3131

3232

@@ -68,56 +68,53 @@ function GitSyncView(termSelector, progressSelector, termToggleSelector) {
6868
this.term.loadAddon(this.fit);
6969

7070
this.visible = false;
71-
this.$progress = $(progressSelector);
71+
this.progress = document.querySelector(progressSelector);
7272

73-
this.$termToggle = $(termToggleSelector);
74-
this.termSelector = termSelector;
73+
this.termToggle = document.querySelector(termToggleSelector);
74+
this.termElement = document.querySelector(termSelector);
7575

76-
var that = this;
77-
this.$termToggle.click(function() {
78-
that.setTerminalVisibility(!that.visible);
79-
});
76+
this.termToggle.onclick = () => this.setTerminalVisibility(!this.visible)
8077
}
8178

8279
GitSyncView.prototype.setTerminalVisibility = function(visible) {
8380
if (visible) {
84-
$(this.termSelector).parent().removeClass('hidden');
81+
this.termElement.parentElement.classList.remove('hidden');
8582
} else {
86-
$(this.termSelector).parent().addClass('hidden');
83+
this.termElement.parentElement.classList.add('hidden');
8784
}
8885
this.visible = visible;
8986
if (visible) {
9087
// See https://github.com/jupyterhub/nbgitpuller/pull/46 on why this is here.
9188
if (!this.term.element) {
92-
this.term.open($(this.termSelector)[0]);
89+
this.term.open(this.termElement);
9390
}
9491
this.fit.fit();
9592
}
9693

9794
}
9895

9996
GitSyncView.prototype.setProgressValue = function(val) {
100-
this.$progress.attr('aria-valuenow', val);
101-
this.$progress.css('width', val + '%');
97+
this.progress.setAttribute('aria-valuenow', val);
98+
$(this.progress).css('width', val + '%');
10299
};
103100

104101
GitSyncView.prototype.getProgressValue = function() {
105-
return parseFloat(this.$progress.attr('aria-valuenow'));
102+
return parseFloat(this.progress.getAttribute('aria-valuenow'));
106103
};
107104

108105
GitSyncView.prototype.setProgressText = function(text) {
109-
this.$progress.children('span').text(text);
106+
this.progress.querySelector('span').innerText = text;
110107
};
111108

112109
GitSyncView.prototype.getProgressText = function() {
113-
return this.$progress.children('span').text();
110+
return this.progress.querySelector('span').innerText;
114111
};
115112

116113
GitSyncView.prototype.setProgressError = function(isError) {
117114
if (isError) {
118-
this.$progress.addClass('progress-bar-danger');
115+
this.progress.classList.add('progress-bar-danger');
119116
} else {
120-
this.$progress.removeClass('progress-bar-danger');
117+
this.progress.classList.remove('progress-bar-danger');
121118
}
122119
};
123120

@@ -127,14 +124,15 @@ var get_body_data = function(key) {
127124
* we should never have any encoded URLs anywhere else in code
128125
* until we are building an actual request
129126
*/
130-
var val = $('body').data(key);
131-
if (typeof val === 'undefined')
132-
return val;
127+
if(!document.body.hasAttribute('data-' + key)) {
128+
return undefined;
129+
}
130+
let val = document.body.getAttribute('data-' + key);
133131
return decodeURIComponent(val);
134132
};
135133

136134
var gs = new GitSync(
137-
get_body_data('baseUrl'),
135+
get_body_data('base-url'),
138136
get_body_data('repo'),
139137
get_body_data('branch'),
140138
get_body_data('depth'),
@@ -169,8 +167,6 @@ gs.addHandler('error', function(data) {
169167
});
170168
gs.start();
171169

172-
$('#header, #site').show();
173-
174170
// Make sure we provide plenty of appearances of progress!
175171
var progressTimers = [];
176172
progressTimers.push(setInterval(function() {

nbgitpuller/templates/page.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
{% block meta %}
1616
{% endblock meta %}
17+
18+
<style>
19+
/* These are hidden by default in page.css for some reason */
20+
#header, #site {
21+
display: block;
22+
}
23+
</style>
1724
</head>
1825

1926
<body class="{% block bodyclasses %}{% endblock %}" {% block params %} {% if logged_in and token %}

0 commit comments

Comments
 (0)