2020-05-13 15:35:16 +02:00
function scrollTo ( element , to , duration ) {
var start = element . scrollTop ,
change = to - start ,
currentTime = 0 ,
increment = 20 ;
2016-06-18 23:44:36 +02:00
2020-05-13 15:35:16 +02:00
var animateScroll = function ( ) {
currentTime += increment ;
var val = Math . easeInOutQuad ( currentTime , start , change , duration ) ;
element . scrollTop = val ;
if ( currentTime < duration ) {
setTimeout ( animateScroll , increment ) ;
}
}
animateScroll ( )
}
//t = current time, b = start value, c = change in value, d = duration
Math . easeInOutQuad = function ( t , b , c , d ) {
t /= d / 2 ;
if ( t < 1 ) return c / 2 * t * t + b ;
t -- ;
return - c / 2 * ( t * ( t - 2 ) - 1 ) + b ;
}
function appendLink ( id ) {
2020-05-13 23:12:28 +02:00
const link = document . getElementById ( id ) . nextElementSibling . querySelector ( '.link' )
2020-05-13 15:35:16 +02:00
if ( link ) {
link . innerHTML = ( "<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>" )
2019-07-14 00:41:44 +02:00
}
2020-05-13 15:35:16 +02:00
}
2019-07-14 00:41:44 +02:00
2020-05-13 15:35:16 +02:00
function moveToRecipe ( id ) {
document . getElementById ( id ) . checked = true ;
scrollTo ( document . body , 0 , 1000 ) ;
appendLink ( id )
}
// open recipe window if a hash is found in URL
if ( window . location . hash ) {
id = window . location . hash . slice ( 1 )
moveToRecipe ( id )
}
// add hash URL when recipe is opened
2020-05-13 23:12:28 +02:00
const recipes = document . querySelectorAll ( 'label[class="recipe"]' )
2020-05-13 15:35:16 +02:00
recipes . forEach ( function ( item , i ) {
item . addEventListener ( "click" , function ( ) {
id = this . getAttribute ( "for" ) ;
window . location . hash = ( id )
2019-07-14 00:41:44 +02:00
appendLink ( id )
2020-05-13 15:35:16 +02:00
} )
} )
// open recipe when clicked
2020-05-13 23:12:28 +02:00
const links = document . querySelectorAll ( 'a' )
2020-05-13 15:35:16 +02:00
links . forEach ( function ( item , i ) {
item . addEventListener ( "click" , function ( ) {
intralink = this . getAttribute ( "href" )
if ( intralink [ 0 ] == "#" ) {
moveToRecipe ( intralink . substring ( 1 ) )
2019-07-14 00:41:44 +02:00
}
2020-05-13 15:35:16 +02:00
} )
} )
2019-07-14 00:41:44 +02:00
2020-05-13 15:35:16 +02:00
function getCheckedBoxes ( checkboxes ) {
var checkboxesChecked = [ ] ;
for ( var i = 0 ; i < checkboxes . length ; i ++ ) {
if ( checkboxes [ i ] . checked ) {
checkboxesChecked . push ( checkboxes [ i ] ) ;
}
2016-06-18 23:44:36 +02:00
}
2020-05-13 15:35:16 +02:00
return checkboxesChecked . length > 0 ? checkboxesChecked : null ;
}
2016-06-18 23:44:36 +02:00
2020-05-13 15:35:16 +02:00
// Collapse all recipes when button is clicked
document . getElementById ( 'toggle-expand-collapse-all' ) . addEventListener ( "click" , function ( ) {
2020-05-13 23:12:28 +02:00
const checkboxes = document . querySelectorAll ( 'input[type=checkbox]' )
2020-05-13 15:35:16 +02:00
var checked = getCheckedBoxes ( checkboxes ) ;
2016-06-18 23:44:36 +02:00
2020-05-13 15:35:16 +02:00
if ( checked ) {
// Collapse all
document . querySelectorAll ( 'input[type=checkbox]' ) . forEach ( function ( item , i ) {
item . checked = false ;
} )
} else {
// Expand all
document . querySelectorAll ( 'input[type=checkbox]' ) . forEach ( function ( item , i ) {
item . checked = true ;
} )
}
} )
2019-07-13 23:52:49 +02:00