2016-06-18 22:44:36 +01:00
$ ( document ) . ready ( function ( ) {
2019-07-13 18:41:44 -04:00
function appendLink ( id ) {
2019-07-13 21:38:38 -04:00
$ ( id ) . next ( 'div' ) . find ( '.link' ) . empty ( ) ;
$ ( id ) . next ( '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>" ) ;
2019-07-13 18:41:44 -04:00
}
function moveToRecipe ( id ) {
document . getElementById ( id . substring ( 1 ) ) . checked = true ;
$ ( 'html, body' ) . animate ( { scrollTop : $ ( id ) . offset ( ) . top } , 1000 ) ;
appendLink ( id )
}
2017-10-12 22:14:47 -04:00
// open recipe window if a hash is found in URL
2019-07-13 18:41:44 -04:00
if ( window . location . hash ) {
2017-10-18 17:17:55 -04:00
id = window . location . hash
2019-07-13 18:41:44 -04:00
moveToRecipe ( id )
2016-06-18 22:44:36 +01:00
}
2017-10-12 22:14:47 -04:00
// add hash URL when recipe is opened
2017-10-18 16:02:04 -04:00
$ ( 'label[class="recipe"]' ) . on ( "click" , function ( ) {
id = $ ( this ) . attr ( "for" ) ;
2017-10-18 20:56:35 -04:00
window . location . hash = ( '#' + id )
2019-07-13 18:41:44 -04:00
appendLink ( '#' + id )
} )
2016-06-18 22:44:36 +01:00
2019-07-13 17:52:49 -04:00
// open recipe when clicked
$ ( 'a' ) . on ( "click" , function ( ) {
intralink = $ ( this ) . attr ( "href" )
if ( intralink [ 0 ] == "#" ) {
2019-07-13 18:41:44 -04:00
moveToRecipe ( intralink )
2019-07-13 17:52:49 -04:00
}
} )
2019-12-17 22:49:06 +13:00
// Collapse all recipes when button is clicked
$ ( '#toggle-expand-collapse-all' ) . on ( "click" , function ( ) {
var checkboxes = $ ( 'input[type=checkbox]' ) ;
var anyRecipesOpen = $ ( checkboxes ) . is ( ':checked' ) ;
2018-04-16 15:22:12 -04:00
2019-12-17 22:49:06 +13:00
if ( anyRecipesOpen ) {
// Collapse all
$ ( 'input[type=checkbox]' ) . each ( function ( ) {
this . checked = false ;
} ) ;
} else new Promise ( function ( resolve , reject ) {
// Expand all
$ ( 'input[type=checkbox]' ) . each ( function ( ) {
this . checked = true ;
} ) ;
} ) ;
} ) ;
2016-06-18 22:44:36 +01:00
} ) ;