mirror of https://gitlab.com/curben/blog
refactor: Use pure JS equivalent of jQuery's $.ready()
https://stackoverflow.com/a/9899701
This commit is contained in:
parent
821ac056b7
commit
0e686c620b
|
@ -23,19 +23,35 @@
|
||||||
$('.fancybox').fancybox()
|
$('.fancybox').fancybox()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add "Copy" button to code snippet
|
})(jQuery)
|
||||||
const code = document.getElementsByClassName('code')
|
|
||||||
|
|
||||||
for (let i = 0; i < code.length; i++) {
|
// Search button function
|
||||||
|
const searchClick = document.getElementById('searchClick')
|
||||||
|
searchClick.onclick = function() {
|
||||||
|
window.open('https://gitlab.com/search?utf8=%E2%9C%93&search=' +
|
||||||
|
document.getElementById('searchTxt').value +
|
||||||
|
'&group_id=&project_id=8306723&search_code=true&repository_ref=master')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add "Copy" button to code snippet
|
||||||
|
const code = document.getElementsByClassName('code')
|
||||||
|
|
||||||
|
for (let i = 0; i < code.length; i++) {
|
||||||
const button = document.createElement('button')
|
const button = document.createElement('button')
|
||||||
button.className = 'copy-button'
|
button.className = 'copy-button'
|
||||||
button.textContent = 'Copy'
|
button.textContent = 'Copy'
|
||||||
|
|
||||||
code[i].appendChild(button)
|
code[i].appendChild(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
/*
|
||||||
// Add copy to clipboard button for code snippet
|
* Copy button and Cloudinary functions.
|
||||||
|
* Following functions only execute after
|
||||||
|
* the 'document' is ready or
|
||||||
|
* <script src> is executed.
|
||||||
|
*/
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
// Copy button
|
||||||
const copyCode = new ClipboardJS('.copy-button', {
|
const copyCode = new ClipboardJS('.copy-button', {
|
||||||
target: (trigger) => {
|
target: (trigger) => {
|
||||||
return trigger.previousElementSibling
|
return trigger.previousElementSibling
|
||||||
|
@ -60,13 +76,4 @@
|
||||||
// Initialize Cloudinary responsive function
|
// Initialize Cloudinary responsive function
|
||||||
const cl = cloudinary.Cloudinary.new({ cloud_name: 'curben' })
|
const cl = cloudinary.Cloudinary.new({ cloud_name: 'curben' })
|
||||||
cl.responsive()
|
cl.responsive()
|
||||||
})
|
}, false);
|
||||||
})(jQuery)
|
|
||||||
|
|
||||||
// Search button function
|
|
||||||
const searchClick = document.getElementById('searchClick')
|
|
||||||
searchClick.onclick = function() {
|
|
||||||
window.open('https://gitlab.com/search?utf8=%E2%9C%93&search=' +
|
|
||||||
document.getElementById('searchTxt').value +
|
|
||||||
'&group_id=&project_id=8306723&search_code=true&repository_ref=master')
|
|
||||||
}
|
|
Loading…
Reference in New Issue