2014-01-22 10:12:51 +00:00
/ * *
* @ name Init Module
* @ author Tobias Reich
* @ copyright 2014 by Tobias Reich
* /
$ ( document ) . ready ( function ( ) {
/* Event Name */
var event _name = ( mobileBrowser ( ) ) ? "touchend" : "click" ;
2014-01-24 12:49:01 +00:00
/* Disable ContextMenu */
$ ( document ) . bind ( "contextmenu" , function ( e ) { e . preventDefault ( ) } ) ;
2014-01-22 10:12:51 +00:00
/* Tooltips */
if ( ! mobileBrowser ( ) ) $ ( ".tools" ) . tipsy ( { gravity : 'n' , fade : false , delayIn : 0 , opacity : 1 } ) ;
2014-01-28 16:00:55 +00:00
/* Multiselect */
$ ( "#content" ) . on ( "mousedown" , multiselect . show ) ;
2014-01-28 19:44:25 +00:00
$ ( document ) . on ( "mouseup" , multiselect . getSelection ) ;
2014-01-28 16:00:55 +00:00
2014-01-22 10:12:51 +00:00
/* Header */
$ ( "#hostedwith" ) . on ( event _name , function ( ) { window . open ( lychee . website , "_newtab" ) } ) ;
$ ( "#button_signin" ) . on ( event _name , lychee . loginDialog ) ;
$ ( "#button_settings" ) . on ( event _name , contextMenu . settings ) ;
$ ( "#button_share" ) . on ( event _name , function ( e ) {
if ( photo . json . public == 1 || photo . json . public == 2 ) contextMenu . sharePhoto ( photo . getID ( ) , e ) ;
else photo . setPublic ( photo . getID ( ) , e ) ;
} ) ;
$ ( "#button_share_album" ) . on ( event _name , function ( e ) {
if ( album . json . public == 1 ) contextMenu . shareAlbum ( album . getID ( ) , e ) ;
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='text' type='password' placeholder='password (optional)' value=''>" , [ [ "Share Album" , function ( ) { album . setPublic ( album . getID ( ) , e ) } ] , [ "Cancel" , function ( ) { } ] ] ) ;
} ) ;
2014-01-24 12:49:01 +00:00
$ ( "#button_download" ) . on ( event _name , function ( ) { photo . getArchive ( photo . getID ( ) ) } ) ;
2014-02-02 14:11:46 +00:00
$ ( "#button_trash_album" ) . on ( event _name , function ( ) { album . delete ( [ album . getID ( ) ] ) } ) ;
2014-01-28 19:44:25 +00:00
$ ( "#button_move" ) . on ( event _name , function ( e ) { contextMenu . move ( [ photo . getID ( ) ] , e ) } ) ;
2014-01-28 23:43:06 +00:00
$ ( "#button_trash" ) . on ( event _name , function ( ) { photo . delete ( [ photo . getID ( ) ] ) } ) ;
2014-01-22 10:12:51 +00:00
$ ( "#button_info_album" ) . on ( event _name , function ( ) { view . infobox . show ( ) } ) ;
$ ( "#button_info" ) . on ( event _name , function ( ) { view . infobox . show ( ) } ) ;
$ ( "#button_archive" ) . on ( event _name , function ( ) { album . getArchive ( album . getID ( ) ) } ) ;
2014-01-28 19:44:25 +00:00
$ ( "#button_star" ) . on ( event _name , function ( ) { photo . setStar ( [ photo . getID ( ) ] ) } ) ;
2014-01-22 10:12:51 +00:00
/* Search */
$ ( "#search" ) . on ( "keyup click" , function ( ) { search . find ( $ ( this ) . val ( ) ) } ) ;
2014-01-28 16:00:55 +00:00
2014-01-28 13:04:09 +00:00
/* Clear Search */
2014-01-28 16:00:55 +00:00
$ ( "#clearSearch" ) . on ( event _name , function ( ) {
2014-02-25 22:37:05 +00:00
$ ( "#search" ) . focus ( ) ;
search . reset ( ) ;
2014-01-28 13:04:09 +00:00
} ) ;
2014-01-22 10:12:51 +00:00
/* Back Buttons */
$ ( "#button_back_home" ) . on ( event _name , function ( ) { lychee . goto ( "" ) } ) ;
$ ( "#button_back" ) . on ( event _name , function ( ) { lychee . goto ( album . getID ( ) ) } ) ;
/* Image View */
lychee . imageview
. on ( event _name , ".arrow_wrapper.previous" , function ( ) {
if ( album . json && album . json . content [ photo . getID ( ) ] && album . json . content [ photo . getID ( ) ] . previousPhoto !== "" ) lychee . goto ( album . getID ( ) + "/" + album . json . content [ photo . getID ( ) ] . previousPhoto )
} )
. on ( event _name , ".arrow_wrapper.next" , function ( ) {
if ( album . json && album . json . content [ photo . getID ( ) ] && album . json . content [ photo . getID ( ) ] . nextPhoto !== "" ) lychee . goto ( album . getID ( ) + "/" + album . json . content [ photo . getID ( ) ] . nextPhoto )
} ) ;
/* Infobox */
$ ( "#infobox" )
. on ( event _name , ".header a" , function ( ) { view . infobox . hide ( ) } )
2014-02-02 14:11:46 +00:00
. on ( event _name , "#edit_title_album" , function ( ) { album . setTitle ( [ album . getID ( ) ] ) } )
2014-01-22 10:12:51 +00:00
. on ( event _name , "#edit_description_album" , function ( ) { album . setDescription ( album . getID ( ) ) } )
2014-01-28 23:43:06 +00:00
. on ( event _name , "#edit_title" , function ( ) { photo . setTitle ( [ photo . getID ( ) ] ) } )
2014-02-02 14:11:46 +00:00
. on ( event _name , "#edit_description" , function ( ) { photo . setDescription ( photo . getID ( ) ) } )
. on ( event _name , "#edit_tags" , function ( ) { photo . editTags ( [ photo . getID ( ) ] ) } )
. on ( event _name , "#tags .tag span" , function ( ) { photo . deleteTag ( photo . getID ( ) , $ ( this ) . data ( 'index' ) ) } ) ;
2014-01-22 10:12:51 +00:00
/* Keyboard */
Mousetrap
. bind ( 'u' , function ( ) { $ ( "#upload_files" ) . click ( ) } )
. bind ( 's' , function ( ) { if ( visible . photo ( ) ) $ ( "#button_star" ) . click ( ) } )
. bind ( 'left' , function ( ) { if ( visible . photo ( ) ) $ ( "#imageview a#previous" ) . click ( ) } )
. bind ( 'right' , function ( ) { if ( visible . photo ( ) ) $ ( "#imageview a#next" ) . click ( ) } )
2014-03-16 20:00:00 +00:00
. bind ( 'command+backspace' , function ( ) {
if ( visible . photo ( ) && ! visible . message ( ) ) photo . delete ( [ photo . getID ( ) ] ) ;
else if ( visible . album ( ) && ! visible . message ( ) ) album . delete ( [ album . getID ( ) ] ) ;
} )
2014-01-22 10:12:51 +00:00
. bind ( 'i' , function ( ) {
if ( visible . infobox ( ) ) view . infobox . hide ( ) ;
else if ( ! visible . albums ( ) ) view . infobox . show ( ) ;
} ) ;
Mousetrap . bindGlobal ( 'enter' , function ( ) {
if ( $ ( ".message .button.active" ) . length ) $ ( ".message .button.active" ) . addClass ( "pressed" ) . click ( )
} ) ;
Mousetrap . bindGlobal ( [ 'esc' , 'command+up' ] , function ( e ) {
e . preventDefault ( ) ;
if ( visible . message ( ) && $ ( ".message .close" ) . length > 0 ) modal . close ( ) ;
else if ( visible . contextMenu ( ) ) contextMenu . close ( ) ;
else if ( visible . infobox ( ) ) view . infobox . hide ( ) ;
else if ( visible . photo ( ) ) lychee . goto ( album . getID ( ) ) ;
else if ( visible . album ( ) ) lychee . goto ( "" ) ;
else if ( visible . albums ( ) && $ ( "#search" ) . val ( ) . length !== 0 ) search . reset ( ) ;
} ) ;
2014-03-25 14:25:28 +00:00
/* Fullscreen on mobile */
if ( mobileBrowser ( ) ) {
$ ( document ) . on ( "touchend" , "#image" , function ( e ) {
if ( visible . controls ( ) ) view . header . hide ( e , 0 ) ;
2014-03-25 14:26:48 +00:00
else view . header . show ( ) ;
2014-03-25 14:25:28 +00:00
} ) ;
}
2014-01-22 10:12:51 +00:00
/* Document */
$ ( document )
/* Login */
. on ( "keyup" , "#password" , function ( ) { if ( $ ( this ) . val ( ) . length > 0 ) $ ( this ) . removeClass ( "error" ) } )
/* Header */
. on ( event _name , "#title.editable" , function ( ) {
2014-01-28 23:43:06 +00:00
if ( visible . photo ( ) ) photo . setTitle ( [ photo . getID ( ) ] ) ;
2014-02-02 14:11:46 +00:00
else album . setTitle ( [ album . getID ( ) ] ) ;
2014-01-22 10:12:51 +00:00
} )
2014-01-28 16:00:55 +00:00
2014-01-22 10:12:51 +00:00
/* Navigation */
. on ( "click" , ".album" , function ( ) { lychee . goto ( $ ( this ) . attr ( "data-id" ) ) } )
. on ( "click" , ".photo" , function ( ) { lychee . goto ( album . getID ( ) + "/" + $ ( this ) . attr ( "data-id" ) ) } )
/* Modal */
. on ( event _name , ".message .close" , modal . close )
2014-02-25 22:37:05 +00:00
. on ( event _name , ".message .button:first" , function ( ) { if ( modal . fns !== null ) modal . fns [ 0 ] ( ) ; if ( ! visible . signin ( ) ) modal . close ( ) } )
. on ( event _name , ".message .button:last" , function ( ) { if ( modal . fns !== null ) modal . fns [ 1 ] ( ) ; if ( ! visible . signin ( ) ) modal . close ( ) } )
2014-01-22 10:12:51 +00:00
/* Add Dialog */
. on ( event _name , ".button_add" , function ( e ) { contextMenu . add ( e ) } )
/* Upload */
. on ( "change" , "#upload_files" , function ( ) { modal . close ( ) ; upload . start . local ( this . files ) } )
/* Context Menu */
. on ( "contextmenu" , ".photo" , function ( e ) { contextMenu . photo ( photo . getID ( ) , e ) } )
. on ( "contextmenu" , ".album" , function ( e ) { contextMenu . album ( album . getID ( ) , e ) } )
. on ( event _name , ".contextmenu_bg" , contextMenu . close )
2014-01-24 12:49:01 +00:00
. on ( "contextmenu" , ".contextmenu_bg" , contextMenu . close )
2014-01-22 10:12:51 +00:00
/* Infobox */
. on ( event _name , "#infobox_overlay" , view . infobox . hide )
/* Upload */
. on ( "dragover" , function ( e ) { e . preventDefault ( ) ; } , false )
. on ( "drop" , function ( e ) {
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
if ( e . originalEvent . dataTransfer . files . length > 0 ) upload . start . local ( e . originalEvent . dataTransfer . files ) ;
else if ( e . originalEvent . dataTransfer . getData ( 'Text' ) . length > 3 ) upload . start . url ( e . originalEvent . dataTransfer . getData ( 'Text' ) ) ;
return true ;
} ) ;
/* Init */
lychee . init ( ) ;
} ) ;