Skip to content

Commit 8f017c3

Browse files
authored
Merge pull request #272 from yuvipanda/no-mo-css
Remove jquery dependency
2 parents 6b9a3e6 + bd3b1ba commit 8f017c3

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

nbgitpuller/static/js/index.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ 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

3333
GitSync.prototype.start = function() {
3434
// Start git pulling handled by SyncHandler, declared in handlers.py
35-
var syncUrlParams = {
35+
let syncUrlParams = new URLSearchParams({
3636
repo: this.repo,
3737
targetpath: this.targetpath
38-
}
38+
});
3939
if (typeof this.depth !== 'undefined' && this.depth != undefined) {
40-
syncUrlParams['depth'] = this.depth;
40+
syncUrlParams.append('depth', this.depth);
4141
}
4242
if (typeof this.branch !== 'undefined' && this.branch != undefined) {
43-
syncUrlParams['branch'] = this.branch;
43+
syncUrlParams.append('branch', this.branch);
4444
}
45-
var syncUrl = this.baseUrl + 'git-pull/api?' + $.param(syncUrlParams);
45+
var syncUrl = this.baseUrl + 'git-pull/api?' + syncUrlParams.toString();
4646

4747
this.eventSource = new EventSource(syncUrl);
4848
var that = this;
@@ -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.style.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 %}

nbgitpuller/templates/status.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
{% block script %}
3636
{{super()}}
37-
<script type="module src="{{ base_url }}git-pull/static/js/index.js"></script>
3837
<script src="{{ base_url }}git-pull/static/dist/bundle.js"></script>
3938
{% endblock %}
4039

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"description": "Dependencies to build nbgitpuller/static/dist/bundle.js from nbgitpuller/static/js/index.js with webpack.",
33
"devDependencies": {
4-
"jquery": "^3.6.0",
54
"webpack": "^5.45.1",
65
"webpack-cli": "^4.7.2",
76
"xterm": "^4.13.0",

webpack.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,5 @@ module.exports = {
1616
},
1717
]
1818
},
19-
devtool: 'source-map',
20-
plugins: [
21-
new webpack.ProvidePlugin({
22-
$: 'jquery',
23-
jQuery: 'jquery',
24-
}),
25-
]
19+
devtool: 'source-map'
2620
}

0 commit comments

Comments
 (0)