Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jQuery with vanilla JS #2130

Merged
merged 66 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
82d1fae
[WIP] Replace jQuery in Closeable
yucheng11122017 Feb 1, 2023
52342df
Remove jQuery from Closeable
yucheng11122017 Feb 1, 2023
2ff9906
Remove jQuery from Retriever
yucheng11122017 Feb 1, 2023
1532420
Remove jQuery instances from Retriever
yucheng11122017 Feb 1, 2023
6937925
Remove jQuery from PanelBase
yucheng11122017 Feb 2, 2023
a7e5971
Refactor function in Retriever
yucheng11122017 Feb 2, 2023
e48443b
Remove jQuery from index.js
yucheng11122017 Feb 2, 2023
37a6892
Change function to use correct length function
yucheng11122017 Feb 2, 2023
17cdd39
Remove jQuery from Float.js
yucheng11122017 Feb 2, 2023
efda1c0
Remove unecessary comment
yucheng11122017 Feb 2, 2023
5e21e9a
Remove jQuery from eslintrc
yucheng11122017 Feb 2, 2023
bf16406
Remove $
yucheng11122017 Feb 5, 2023
f6ef275
Comment why id is deleted
yucheng11122017 Feb 5, 2023
fe6a12b
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Feb 12, 2023
f048dd1
[WIP] Remove jQuery from assets
yucheng11122017 Feb 13, 2023
60b5e0d
Change to use clientHeight instead of height
yucheng11122017 Feb 13, 2023
f11f660
Change use querySelector instead of querySelectorAll
yucheng11122017 Feb 13, 2023
d78c3f8
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Mar 4, 2023
f82b473
Change to use headerEl instead of selector
yucheng11122017 Mar 4, 2023
b388667
Remove class from each element in headerSelector
yucheng11122017 Mar 5, 2023
b527aad
Change to use height which doesn't include padding
yucheng11122017 Mar 5, 2023
f56998c
Change overflow for each element in headerSelector
yucheng11122017 Mar 5, 2023
5cb6ebf
Change style and class for each element in headerSelector
yucheng11122017 Mar 5, 2023
77d976d
Remove uncessary tempdom
yucheng11122017 Mar 5, 2023
638110c
Change to use clientHeight instead of height
yucheng11122017 Mar 5, 2023
4f9a500
Change class for closeable
yucheng11122017 Mar 5, 2023
7e3fd89
Change calculation of headerHeight to remove padding length
yucheng11122017 Mar 5, 2023
cb46a98
Change calculation of headerHeight
yucheng11122017 Mar 5, 2023
1192fcb
Remove jQuery from script and pageConfig
yucheng11122017 Mar 5, 2023
0b3d0c2
Remove jQuery from testcases
yucheng11122017 Mar 5, 2023
df95142
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Mar 10, 2023
a93bec9
Remove jQuery from documentation
yucheng11122017 Mar 11, 2023
ccecb7e
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Mar 11, 2023
d90f617
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 2, 2023
9843dee
Update test cases
yucheng11122017 Apr 2, 2023
02226a8
Change to add to class list instead of set attribute
yucheng11122017 Apr 2, 2023
22ecfda
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 2, 2023
30c82d5
Update test cases
yucheng11122017 Apr 2, 2023
1ba27fa
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 2, 2023
2fee39b
Merge branch 'master' of https://github.com/yucheng11122017/markbind …
yucheng11122017 Apr 2, 2023
2bb3213
Merge branch 'master' of https://github.com/yucheng11122017/markbind …
yucheng11122017 Apr 2, 2023
3a5fc40
Update test cases
yucheng11122017 Apr 2, 2023
4076102
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 2, 2023
b6fb8c9
Update test cases
yucheng11122017 Apr 2, 2023
d9e8b12
Remove merge conflict
yucheng11122017 Apr 2, 2023
083cc63
Remove function removing id in header
yucheng11122017 Apr 2, 2023
edbf947
Revert "Update test cases"
yucheng11122017 Apr 3, 2023
918b1a7
Update html test cases
yucheng11122017 Apr 3, 2023
12618e7
Replace deteted line
yucheng11122017 Apr 3, 2023
c7a7708
Replace missing line
yucheng11122017 Apr 3, 2023
04707a9
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 6, 2023
657e1a4
Remove jQuery from codeBlockWrapButtons
yucheng11122017 Apr 6, 2023
f5c6a13
Change to use querySelector instead of querySelectorAll
yucheng11122017 Apr 6, 2023
941e9d7
[WIP] Refactor Closeable
yucheng11122017 Apr 6, 2023
9bcfe09
Merge branch 'master' into removeJquery
tlylt Apr 9, 2023
1640520
Remove script tag in retriever to prevent vue warnings
yucheng11122017 Apr 12, 2023
754279e
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 12, 2023
82ce26d
Add comment explining why script tags are removed in Retriever
yucheng11122017 Apr 12, 2023
b4866df
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 13, 2023
466dceb
Add further clarification on why it is alright to remove script tags
yucheng11122017 Apr 13, 2023
745ff4c
Remove if statement for adding class
yucheng11122017 Apr 14, 2023
9b7f525
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 14, 2023
1b9f5e8
Change selector to only remove script in svg tags
yucheng11122017 Apr 14, 2023
7a18861
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 15, 2023
251f73e
Merge branch 'master' into removeJquery
yucheng11122017 Apr 15, 2023
4b378e5
Merge branch 'master' of https://github.com/MarkBind/markbind into re…
yucheng11122017 Apr 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core-web/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
},
'extends': ['../../.eslintrc.js'],
'globals': {
'jQuery': 'readonly',
'Vue': 'readonly',
'baseUrl': 'readonly',
},
Expand Down
22 changes: 11 additions & 11 deletions packages/core-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,27 @@ function scrollToUrlAnchorHeading() {
}

function detectAndApplyHeaderStyles() {
jQuery(':header').each((index, heading) => {
document.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach((heading) => {
if (heading.id) {
jQuery(heading).removeAttr('id'); // to avoid duplicated id problem
tlylt marked this conversation as resolved.
Show resolved Hide resolved
heading.removeAttribute('id');
}
});

const headerSelector = jQuery('header[sticky]');
}); // to avoid duplicated id problem
const headerSelector = document.querySelectorAll('header[sticky]');
tlylt marked this conversation as resolved.
Show resolved Hide resolved
if (headerSelector.length === 0) {
return;
}
const [headerEl] = headerSelector;

let headerHeight = headerSelector.height();
let headerHeight = headerSelector.height;
yucheng11122017 marked this conversation as resolved.
Show resolved Hide resolved
function updateHeaderHeight() {
headerHeight = headerSelector.height();
headerHeight = headerSelector.height;
document.documentElement.style.setProperty('--sticky-header-height', `${headerHeight}px`);
}

let isHidden = false;
function showHeader() {
isHidden = false;
headerSelector.removeClass('hide-header');
headerSelector.classList.remove('hide-header');
}
headerEl.addEventListener('transitionend', () => {
// reset overflow when header shows again to allow content
Expand All @@ -56,8 +55,8 @@ function detectAndApplyHeaderStyles() {
function hideHeader() {
yucheng11122017 marked this conversation as resolved.
Show resolved Hide resolved
isHidden = true;
// hide header overflow when user scrolls to support transition effect
headerSelector.css('overflow', 'hidden');
headerSelector.addClass('hide-header');
headerSelector.style.overflow = 'hidden';
headerSelector.classList.add('hide-header');
}

// Handles window resizes + dynamic content (e.g. dismissing a box within)
Expand Down Expand Up @@ -128,7 +127,8 @@ function detectAndApplyHeaderStyles() {
}

function updateSearchData(vm) {
jQuery.getJSON(`${baseUrl}/siteData.json`)
fetch(`${baseUrl}/siteData.json`)
.then(response => response.json())
.then((siteData) => {
vm.searchData = siteData.pages;
});
Expand Down
1 change: 0 additions & 1 deletion packages/vue-components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
'plugin:vue/recommended',
],
'globals': {
'jQuery': 'readonly',
'Vue': 'readonly',
},
'rules': {
Expand Down
20 changes: 12 additions & 8 deletions packages/vue-components/src/Retriever.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ export default {
if (this.hasFetchedCopy) {
return;
}
jQuery.get(this.srcWithoutHash)
.done((response) => {
let result = response;
fetch(this.srcWithoutHash)
.then(response => response.text())
.then((htmlText) => {
let result = htmlText;
if (this.hash) {
const tempDom = jQuery('<temp>').append(jQuery.parseHTML(result));
const appContainer = jQuery(`#${this.hash}`, tempDom);
result = appContainer.html();
const htmlResult = document.implementation.createHTMLDocument('');
htmlResult.body.innerHTML = result;
const tempDom = document.createElement('temp');
Array.from(htmlResult.body.childNodes).forEach(child => tempDom.append(child));
const appContainer = tempDom.querySelectorAll(`#${this.hash}`);
yucheng11122017 marked this conversation as resolved.
Show resolved Hide resolved
result = appContainer.innerHTML;
tlylt marked this conversation as resolved.
Show resolved Hide resolved
}
this.hasFetchedCopy = true;
// result is empty / undefined
Expand Down Expand Up @@ -92,9 +96,9 @@ export default {
new TempComponent().$mount(this.$el);
this.$emit('src-loaded');
})
.fail((error) => {
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error.responseText);
console.error(error);
this.$el.innerHTML = '<strong>Error</strong>: Failed to retrieve content from source: '
+ `<em>${this.srcWithoutHash}</em>`;
this.$emit('src-loaded');
Expand Down
47 changes: 27 additions & 20 deletions packages/vue-components/src/directives/Closeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,53 @@ module.exports = {
bind(el) {
function onClose() {
el.dataset.isShown = 'false';
$showLabel.show();
$closeButton.hide();
$content.get()[0].style.display = 'none';
showLabel.style.display = '';
closeButton.style.display = 'none';
content.style.display = 'none';
}

function onShow() {
el.dataset.isShown = 'true';
$showLabel.hide();
$content.get()[0].style.display = '';
showLabel.style.display = 'none';
content.style.display = '';
}

function onMouseOver() {
if (el.dataset.isShown === 'false') {
return;
}
$closeButton.show();
closeButton.style.display = '';
}

function onMouseOut() {
if (el.dataset.isShown === 'false') {
return;
}
$closeButton.hide();
closeButton.style.display = 'none';
}

el.dataset.isShown = 'true';
el.style.position = 'relative';
const message = el.getAttribute('alt') || 'Expand Content';
const $content = jQuery(`<div class="content"></div>`);
jQuery(el).contents().appendTo($content);
jQuery(el).empty();
jQuery(el).append($content);
jQuery(el).attr('class', `${el.className} closeable-wrapper`);
const $closeButton = jQuery('<span class="closeable-button label label-default hidden-print" style="display: none; position: absolute; top: 0; left: 0; cursor: pointer;background: #d9534f;"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></span>');
jQuery(el).append($closeButton);
const $showLabel = jQuery(`<a class="closeable-show hidden-print" style="display: none; cursor: pointer;text-decoration: underline">${message}</a>`);
jQuery(el).append($showLabel);
$closeButton.click(onClose);
$showLabel.click(onShow);
jQuery(el).on('mouseover', onMouseOver);
jQuery(el).on('mouseout', onMouseOut);
const content = document.createElement('div');
el.classList.add('content');
Array.from(el.children).forEach(child => content.append(child));
el.replaceChildren();
el.append(content);
el.setAttribute('class', `${el.className} closeable-wrapper`);
const closeButton = document.createElement('span');
closeButton.classList.add('closeable-button', 'label', 'label-default', 'hidden-print');
closeButton.style.cssText += 'display: none; position: absolute; top: 0; left: 0; cursor: pointer;background: #d9534f';
closeButton.innerHTML = '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>';
el.append(closeButton);
const showLabel = document.createElement('a');
showLabel.classList.add('closeable-show', 'hidden-print');
showLabel.style.cssText += 'display: none; cursor: pointer;text-decoration: underline';
showLabel.innerHTML = message;
el.append(showLabel);
closeButton.addEventListener('click', onClose);
showLabel.addEventListener('click', onShow);
el.addEventListener('mouseover', onMouseOver);
el.addEventListener('mouseout', onMouseOut);
tlylt marked this conversation as resolved.
Show resolved Hide resolved
}
};
8 changes: 4 additions & 4 deletions packages/vue-components/src/directives/Float.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
bind () {
jQuery(this.el).wrap(function () {
return `<div></div>`;
});
bind() {
const wrappingElement = document.createElement('div');
this.el.replaceWith(wrappingElement);
wrappingElement.appendChild(this.el);
},
update(direction) {
this.el.style.float = direction;
Expand Down
6 changes: 2 additions & 4 deletions packages/vue-components/src/panels/PanelBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ export default {
requestAnimationFrame(() => {
// To enable behaviour of auto window scrolling during panel collapse
if (this.$el.getBoundingClientRect().top < 0) {
const headerHeight = jQuery('header[sticky]').height() || 0;
jQuery('html').animate({
scrollTop: window.scrollY + this.$el.getBoundingClientRect().top - headerHeight - 3,
}, 500, 'swing');
const headerHeight = document.querySelector('header[sticky]').length || 0;
tlylt marked this conversation as resolved.
Show resolved Hide resolved
window.scrollTo(0, window.scrollY + this.$el.getBoundingClientRect().top - headerHeight - 3);
}
this.$refs.panel.style.maxHeight = `${this.collapsedPanelHeight}px`;
});
Expand Down