2012-10-02 15:48:08 +00:00
/ * *
* @ name main . js
* @ author Philipp Maurer
* @ author Tobias Reich
2013-05-03 11:57:08 +00:00
* @ copyright 2013 by Philipp Maurer , Tobias Reich
2012-10-02 15:48:08 +00:00
* /
$ ( document ) . ready ( function ( ) {
2013-09-03 09:59:30 +00:00
/* Init */
lychee . init ( ) ;
2013-01-15 20:21:36 +00:00
/* Event Name */
2013-09-03 09:59:30 +00:00
var event _name = ( mobileBrowser ( ) ) ? "touchend" : "click" ;
2013-01-15 20:21:36 +00:00
2013-09-03 09:59:30 +00:00
/* Notifications */
if ( window . webkitNotifications ) window . webkitNotifications . requestPermission ( ) ;
/* Tooltips */
if ( ! mobileBrowser ( ) ) $ ( ".tools" ) . tipsy ( { gravity : 'n' } ) ;
/* Header */
2013-05-03 11:57:08 +00:00
$ ( "#button_share" ) . on ( event _name , function ( e ) {
2013-09-03 09:59:30 +00:00
if ( photo . json . public == 1 || photo . json . public == 2 ) contextMenu . sharePhoto ( photo . getID ( ) , e ) ;
else photo . setPublic ( photo . getID ( ) , e ) ;
2012-10-02 15:48:08 +00:00
} ) ;
2013-06-17 18:40:04 +00:00
$ ( "#button_share_album" ) . on ( event _name , function ( e ) {
2013-09-03 09:59:30 +00:00
if ( album . json . public == 1 ) contextMenu . shareAlbum ( album . getID ( ) , e ) ;
2013-09-08 17:50:31 +00:00
else modal . show ( "Share Album" , "All photos inside this album will be public and visible for everyone. Existing public photos will have the same sharing permission as this album. Are your sure you want to share this album? <input class='password' type='password' placeholder='password (optional)' value=''>" , [ [ "Share Album" , function ( ) { album . setPublic ( album . getID ( ) , e ) } ] , [ "Cancel" , function ( ) { } ] ] ) ;
2013-06-17 18:40:04 +00:00
} ) ;
2013-09-03 09:59:30 +00:00
$ ( "#button_signout" ) . on ( event _name , lychee . logout ) ;
$ ( "#button_download" ) . on ( event _name , function ( ) { window . open ( photo . getDirectLink ( ) , "_newtab" ) } ) ;
$ ( "#button_trash_album" ) . on ( event _name , function ( ) { album . delete ( album . getID ( ) ) } ) ;
$ ( "#button_move" ) . on ( event _name , function ( e ) { contextMenu . move ( photo . getID ( ) , e ) } ) ;
$ ( "#button_trash" ) . on ( event _name , function ( ) { photo . delete ( ) } ) ;
$ ( "#button_edit_album" ) . on ( event _name , function ( ) { album . setTitle ( ) } ) ;
$ ( "#button_edit" ) . on ( event _name , function ( ) { photo . setTitle ( photo . getID ( ) ) } ) ;
$ ( "#button_info" ) . on ( event _name , function ( ) { view . photo . showInfobox ( ) } ) ;
$ ( "#button_archive" ) . on ( event _name , function ( ) { album . getArchive ( album . getID ( ) ) } ) ;
$ ( "#button_star" ) . on ( event _name , function ( ) { photo . setStar ( photo . getID ( ) ) } ) ;
2013-05-03 11:57:08 +00:00
/* Search */
$ ( "#search" ) . on ( "keyup click" , function ( ) { search . find ( $ ( this ) . val ( ) ) } ) ;
/* Back Buttons */
$ ( "#button_back_home" ) . on ( event _name , function ( ) { lychee . goto ( "" ) } ) ;
2013-09-03 09:59:30 +00:00
$ ( "#button_back" ) . on ( event _name , function ( ) { lychee . goto ( "a" + album . getID ( ) ) } ) ;
2013-05-03 11:57:08 +00:00
/* Image View */
2013-09-03 09:59:30 +00:00
lychee . imageview
. on ( event _name , "a#previous" , function ( ) {
if ( photo . json && photo . json . previousPhoto ) lychee . goto ( "a" + album . getID ( ) + "p" + photo . json . previousPhoto )
} )
. on ( event _name , "a#next" , function ( ) {
if ( photo . json && photo . json . nextPhoto ) lychee . goto ( "a" + album . getID ( ) + "p" + photo . json . nextPhoto )
} ) ;
2013-05-03 11:57:08 +00:00
/* Infobox */
$ ( "#infobox" )
2013-09-03 09:59:30 +00:00
. on ( event _name , ".header a" , function ( ) { view . photo . hideInfobox ( ) } )
. on ( event _name , "#edit_title" , function ( ) { photo . setTitle ( photo . getID ( ) ) } )
. on ( event _name , "#edit_description" , function ( ) { photo . setDescription ( photo . getID ( ) ) } ) ;
2013-05-03 11:57:08 +00:00
/* Keyboard */
Mousetrap
2013-09-03 09:59:30 +00:00
. bind ( 'n' , function ( e ) { if ( ! visible . message ( ) ) $ ( "body" ) . append ( build . addModal ) } )
2013-05-03 11:57:08 +00:00
. bind ( 'u' , function ( e ) { $ ( "#auswahl" ) . html ( "" ) ; $ ( "#upload_files" ) . click ( ) } )
2013-09-03 09:59:30 +00:00
. bind ( 's' , function ( e ) { if ( visible . photo ( ) ) $ ( "#button_star" ) . click ( ) } )
. bind ( 'f' , function ( e ) { if ( visible . photo ( ) ) $ ( "#button_download" ) . click ( ) } )
. bind ( 'command+backspace' , function ( e ) { if ( visible . photo ( ) && ! visible . message ( ) ) photo . delete ( ) } )
. bind ( 'left' , function ( e ) { if ( visible . photo ( ) ) $ ( "#imageview a#previous" ) . click ( ) } )
. bind ( 'right' , function ( e ) { if ( visible . photo ( ) ) $ ( "#imageview a#next" ) . click ( ) } )
. bind ( 'i' , function ( e ) {
if ( visible . infobox ( ) ) view . photo . hideInfobox ( ) ;
else if ( visible . photo ( ) ) view . photo . showInfobox ( ) ;
} ) ;
2013-05-03 11:57:08 +00:00
Mousetrap . bindGlobal ( 'enter' , function ( e ) {
if ( $ ( ".message .button.active" ) . length ) $ ( ".message .button.active" ) . addClass ( "pressed" ) . click ( )
2012-10-02 15:48:08 +00:00
} ) ;
2013-01-15 20:21:36 +00:00
2013-09-03 09:59:30 +00:00
Mousetrap . bindGlobal ( [ 'esc' , 'command+up' ] , function ( e ) {
2012-10-02 15:48:08 +00:00
e . preventDefault ( ) ;
2013-09-03 09:59:30 +00:00
if ( visible . message ( ) ) modal . close ( ) ;
else if ( visible . contextMenu ( ) ) contextMenu . close ( ) ;
else if ( visible . infobox ( ) ) view . photo . hideInfobox ( ) ;
else if ( visible . photo ( ) ) lychee . goto ( "a" + album . getID ( ) ) ;
else if ( visible . album ( ) ) lychee . goto ( "" ) ;
2013-05-03 11:57:08 +00:00
else if ( visible . albums ( ) && $ ( "#search" ) . val ( ) . length != 0 ) search . reset ( ) ;
2012-10-02 15:48:08 +00:00
} ) ;
2013-05-03 11:57:08 +00:00
/* Document */
$ ( document )
2013-01-15 20:21:36 +00:00
2013-05-03 11:57:08 +00:00
/* Login */
2013-09-03 09:59:30 +00:00
. on ( event _name , "#button_signin" , function ( ) { lychee . loginDialog ( ) } )
2013-05-03 11:57:08 +00:00
. on ( "keyup" , "#password" , function ( ) { if ( $ ( this ) . val ( ) . length > 0 ) $ ( this ) . removeClass ( "error" ) } )
2013-01-15 20:21:36 +00:00
2013-09-03 09:59:30 +00:00
/* Header */
. on ( event _name , "#title.editable" , function ( ) {
if ( visible . photo ( ) ) photo . setTitle ( photo . getID ( ) ) ;
else album . setTitle ( ) ;
} )
2012-10-02 15:48:08 +00:00
2013-05-03 11:57:08 +00:00
/* Navigation */
. on ( "click" , ".album" , function ( ) { lychee . goto ( "a" + $ ( this ) . attr ( "data-id" ) ) } )
2013-09-03 09:59:30 +00:00
. on ( "click" , ".photo" , function ( ) { lychee . goto ( "a" + album . getID ( ) + "p" + $ ( this ) . attr ( "data-id" ) ) } )
2012-10-02 15:48:08 +00:00
2013-05-03 11:57:08 +00:00
/* Modal */
2013-09-03 09:59:30 +00:00
. on ( event _name , ".message .close" , modal . close )
. on ( event _name , ".message .button:first" , function ( ) { modal . fns [ 0 ] ( ) ; modal . close ( ) ; } )
. on ( event _name , ".message .button:last" , function ( ) { modal . fns [ 1 ] ( ) ; modal . close ( ) ; } )
2012-10-02 15:48:08 +00:00
2013-05-03 11:57:08 +00:00
/* Add Dialog */
. on ( event _name , ".button_add" , function ( ) { $ ( "body" ) . append ( build . addModal ) } )
2013-09-03 09:59:30 +00:00
. on ( event _name , "#add_album" , album . add )
. on ( event _name , "#add_link" , function ( ) { photo . add . url ( ) } )
2013-05-03 11:57:08 +00:00
. on ( event _name , "#add_photo" , function ( ) { $ ( "#auswahl" ) . html ( "" ) ; $ ( "#upload_files" ) . click ( ) } )
2012-10-02 15:48:08 +00:00
2013-05-03 11:57:08 +00:00
/* Upload */
2013-09-03 09:59:30 +00:00
. on ( "change" , "#upload_files" , function ( ) { modal . close ( ) ; photo . add . files ( this . files ) ; } )
2013-01-15 20:21:36 +00:00
2013-05-03 11:57:08 +00:00
/* Context Menu */
. on ( "contextmenu" , ".photo" , contextMenu . photo )
. on ( "contextmenu" , ".album" , contextMenu . album )
. on ( event _name , ".contextmenu_bg" , contextMenu . close )
2013-01-15 20:21:36 +00:00
2013-05-03 11:57:08 +00:00
/* Infobox */
2013-09-03 09:59:30 +00:00
. on ( event _name , "#infobox_overlay" , function ( ) { view . photo . hideInfobox ( ) } )
2013-01-15 20:21:36 +00:00
2013-05-03 11:57:08 +00:00
/* Controls */
2013-09-03 09:59:30 +00:00
. bind ( "mouseenter" , view . header . show )
. bind ( "mouseleave" , view . header . hide )
2013-01-15 20:21:36 +00:00
2013-06-17 18:40:04 +00:00
/* Upload */
. on ( "dragover" , function ( e ) { e . preventDefault ( ) ; } , false )
. on ( "drop" , function ( e ) {
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
2013-09-03 09:59:30 +00:00
photo . add . files ( e . originalEvent . dataTransfer . files ) ;
2013-06-17 18:40:04 +00:00
return true ;
} ) ;
2013-01-15 20:21:36 +00:00
2013-09-03 09:59:30 +00:00
/* Run */
lychee . run ( ) ;
2013-01-15 20:21:36 +00:00
2013-06-17 18:40:04 +00:00
} ) ;