mirror of
https://github.com/amiaopensource/ffmprovisr.git
synced 2025-01-27 10:25:01 +01:00
Move repeated JS into functions
This commit is contained in:
parent
c32a7f44ad
commit
07fe8bf966
31
js/js.js
31
js/js.js
@ -1,28 +1,37 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
// open recipe window if a hash is found in URL
|
function appendLink(id) {
|
||||||
if(window.location.hash) {
|
console.log(id)
|
||||||
id = window.location.hash
|
|
||||||
document.getElementById(id.substring(1)).checked = true;
|
|
||||||
$('html, body').animate({ scrollTop: $(id).offset().top}, 1000);
|
|
||||||
$(id).closest('div').find('.link').empty();
|
$(id).closest('div').find('.link').empty();
|
||||||
$(id).closest('div').find('.link').append("<small>Link to this command: <a href='https://amiaopensource.github.io/ffmprovisr/index.html"+window.location.hash+"'>https://amiaopensource.github.io/ffmprovisr/index.html"+window.location.hash+"</a></small>");
|
$(id).closest('div').find('.link')
|
||||||
|
.append("<small>Link to this command: <a href='https://amiaopensource.github.io/ffmprovisr/index.html" + id + "'>https://amiaopensource.github.io/ffmprovisr/index.html" + id + "</a></small>");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveToRecipe(id) {
|
||||||
|
document.getElementById(id.substring(1)).checked = true;
|
||||||
|
$('html, body').animate({ scrollTop: $(id).offset().top }, 1000);
|
||||||
|
appendLink(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// open recipe window if a hash is found in URL
|
||||||
|
if (window.location.hash) {
|
||||||
|
id = window.location.hash
|
||||||
|
moveToRecipe(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add hash URL when recipe is opened
|
// add hash URL when recipe is opened
|
||||||
$('label[class="recipe"]').on("click", function(){
|
$('label[class="recipe"]').on("click", function(){
|
||||||
id = $(this).attr("for");
|
id = $(this).attr("for");
|
||||||
window.location.hash = ('#' + id)
|
window.location.hash = ('#' + id)
|
||||||
$('#' + id).closest('div').find('.link').empty();
|
appendLink('#' + id)
|
||||||
$('#' + id).closest('div').find('.link').append("<small>Link to this command: <a href='https://amiaopensource.github.io/ffmprovisr/index.html"+window.location.hash+"'>https://amiaopensource.github.io/ffmprovisr/index.html"+window.location.hash+"</a></small>");
|
})
|
||||||
});
|
|
||||||
|
|
||||||
// open recipe when clicked
|
// open recipe when clicked
|
||||||
$('a').on("click", function(){
|
$('a').on("click", function(){
|
||||||
intralink = $(this).attr("href")
|
intralink = $(this).attr("href")
|
||||||
if (intralink[0] == "#") {
|
if (intralink[0] == "#") {
|
||||||
document.getElementById(intralink.substring(1)).checked = true;
|
moveToRecipe(intralink)
|
||||||
$('html, body').animate({ scrollTop: $(intralink).offset().top }, 1000);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user