From 32e6aea13b6798a96aeb8ce1aed495355f45cad8 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 13 Jun 2022 15:40:55 +0300 Subject: [PATCH 1/5] Remove use of jquery for DOM manipulation --- nbgitpuller/static/js/index.js | 46 +++++++++++++++------------------ nbgitpuller/templates/page.html | 7 +++++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/nbgitpuller/static/js/index.js b/nbgitpuller/static/js/index.js index 042aefd6..5fe65604 100644 --- a/nbgitpuller/static/js/index.js +++ b/nbgitpuller/static/js/index.js @@ -24,9 +24,9 @@ GitSync.prototype.addHandler = function(event, cb) { GitSync.prototype._emit = function(event, data) { if (this.callbacks[event] == undefined) { return; } - $.each(this.callbacks[event], function(i, ev) { + for(let ev of this.callbacks[event]) { ev(data); - }); + } }; @@ -68,28 +68,25 @@ function GitSyncView(termSelector, progressSelector, termToggleSelector) { this.term.loadAddon(this.fit); this.visible = false; - this.$progress = $(progressSelector); + this.progress = document.querySelector(progressSelector); - this.$termToggle = $(termToggleSelector); - this.termSelector = termSelector; + this.termToggle = document.querySelector(termToggleSelector); + this.termElement = document.querySelector(termSelector); - var that = this; - this.$termToggle.click(function() { - that.setTerminalVisibility(!that.visible); - }); + this.termToggle.onclick = () => this.setTerminalVisibility(!this.visible) } GitSyncView.prototype.setTerminalVisibility = function(visible) { if (visible) { - $(this.termSelector).parent().removeClass('hidden'); + this.termElement.parentElement.classList.remove('hidden'); } else { - $(this.termSelector).parent().addClass('hidden'); + this.termElement.parentElement.classList.add('hidden'); } this.visible = visible; if (visible) { // See https://github.com/jupyterhub/nbgitpuller/pull/46 on why this is here. if (!this.term.element) { - this.term.open($(this.termSelector)[0]); + this.term.open(this.termElement); } this.fit.fit(); } @@ -97,27 +94,27 @@ GitSyncView.prototype.setTerminalVisibility = function(visible) { } GitSyncView.prototype.setProgressValue = function(val) { - this.$progress.attr('aria-valuenow', val); - this.$progress.css('width', val + '%'); + this.progress.setAttribute('aria-valuenow', val); + $(this.progress).css('width', val + '%'); }; GitSyncView.prototype.getProgressValue = function() { - return parseFloat(this.$progress.attr('aria-valuenow')); + return parseFloat(this.progress.getAttribute('aria-valuenow')); }; GitSyncView.prototype.setProgressText = function(text) { - this.$progress.children('span').text(text); + this.progress.querySelector('span').innerText = text; }; GitSyncView.prototype.getProgressText = function() { - return this.$progress.children('span').text(); + return this.progress.querySelector('span').innerText; }; GitSyncView.prototype.setProgressError = function(isError) { if (isError) { - this.$progress.addClass('progress-bar-danger'); + this.progress.classList.add('progress-bar-danger'); } else { - this.$progress.removeClass('progress-bar-danger'); + this.progress.classList.remove('progress-bar-danger'); } }; @@ -127,14 +124,15 @@ var get_body_data = function(key) { * we should never have any encoded URLs anywhere else in code * until we are building an actual request */ - var val = $('body').data(key); - if (typeof val === 'undefined') - return val; + if(!document.body.hasAttribute('data-' + key)) { + return undefined; + } + let val = document.body.getAttribute('data-' + key); return decodeURIComponent(val); }; var gs = new GitSync( - get_body_data('baseUrl'), + get_body_data('base-url'), get_body_data('repo'), get_body_data('branch'), get_body_data('depth'), @@ -169,8 +167,6 @@ gs.addHandler('error', function(data) { }); gs.start(); -$('#header, #site').show(); - // Make sure we provide plenty of appearances of progress! var progressTimers = []; progressTimers.push(setInterval(function() { diff --git a/nbgitpuller/templates/page.html b/nbgitpuller/templates/page.html index e6ef02dc..fcce7ccf 100644 --- a/nbgitpuller/templates/page.html +++ b/nbgitpuller/templates/page.html @@ -14,6 +14,13 @@ {% block meta %} {% endblock meta %} + + Date: Mon, 13 Jun 2022 18:08:56 -0700 Subject: [PATCH 2/5] Remove use of jquery for URL Search Param construction --- nbgitpuller/static/js/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nbgitpuller/static/js/index.js b/nbgitpuller/static/js/index.js index 5fe65604..08a7333e 100644 --- a/nbgitpuller/static/js/index.js +++ b/nbgitpuller/static/js/index.js @@ -32,17 +32,17 @@ GitSync.prototype._emit = function(event, data) { GitSync.prototype.start = function() { // Start git pulling handled by SyncHandler, declared in handlers.py - var syncUrlParams = { + let syncUrlParams = new URLSearchParams({ repo: this.repo, targetpath: this.targetpath - } + }); if (typeof this.depth !== 'undefined' && this.depth != undefined) { - syncUrlParams['depth'] = this.depth; + syncUrlParams.append('depth', this.depth); } if (typeof this.branch !== 'undefined' && this.branch != undefined) { - syncUrlParams['branch'] = this.branch; + syncUrlParams.append('branch', this.branch); } - var syncUrl = this.baseUrl + 'git-pull/api?' + $.param(syncUrlParams); + var syncUrl = this.baseUrl + 'git-pull/api?' + syncUrlParams.toString(); this.eventSource = new EventSource(syncUrl); var that = this; From 827539a27d1e8ee626c7b8a29f9fafa9ea99d6f5 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 13 Jun 2022 18:09:46 -0700 Subject: [PATCH 3/5] Stop using jquery for style manipulation --- nbgitpuller/static/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbgitpuller/static/js/index.js b/nbgitpuller/static/js/index.js index 08a7333e..03d54afa 100644 --- a/nbgitpuller/static/js/index.js +++ b/nbgitpuller/static/js/index.js @@ -95,7 +95,7 @@ GitSyncView.prototype.setTerminalVisibility = function(visible) { GitSyncView.prototype.setProgressValue = function(val) { this.progress.setAttribute('aria-valuenow', val); - $(this.progress).css('width', val + '%'); + this.progress.style.width = val + '%'; }; GitSyncView.prototype.getProgressValue = function() { From ff04ab45f26d2d111eac05dc2199f2921db32d6c Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 13 Jun 2022 18:10:01 -0700 Subject: [PATCH 4/5] Remove including index.js separately It gets included in bundle.js --- nbgitpuller/templates/status.html | 1 - 1 file changed, 1 deletion(-) diff --git a/nbgitpuller/templates/status.html b/nbgitpuller/templates/status.html index f4388510..2b969f59 100644 --- a/nbgitpuller/templates/status.html +++ b/nbgitpuller/templates/status.html @@ -34,7 +34,6 @@ {% block script %} {{super()}} - {% endblock %} From bd3b1ba409b77f2e88fa2a75cb8c899f2913eddf Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 13 Jun 2022 18:10:24 -0700 Subject: [PATCH 5/5] Remove jquery dependency --- package.json | 1 - webpack.config.js | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/package.json b/package.json index d57ec2d6..b6204f2f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "description": "Dependencies to build nbgitpuller/static/dist/bundle.js from nbgitpuller/static/js/index.js with webpack.", "devDependencies": { - "jquery": "^3.6.0", "webpack": "^5.45.1", "webpack-cli": "^4.7.2", "xterm": "^4.13.0", diff --git a/webpack.config.js b/webpack.config.js index 0b769d5f..f636d324 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -16,11 +16,5 @@ module.exports = { }, ] }, - devtool: 'source-map', - plugins: [ - new webpack.ProvidePlugin({ - $: 'jquery', - jQuery: 'jquery', - }), - ] + devtool: 'source-map' }