2012-10-02 15:48:08 +00:00
/ * *
* @ name main . js
* @ author Philipp Maurer
* @ author Tobias Reich
* @ copyright 2012 by Philipp Maurer , Tobias Reich
* /
var header = $ ( "header" ) ,
headerTitle = $ ( "#title" ) ,
content = $ ( "#content" ) ,
image _view = $ ( "#image_view" ) ,
loading = $ ( "#loading" ) ,
infobox = $ ( "#infobox" ) ,
2012-10-25 10:22:04 +00:00
api _path = "php/api.php" ,
2013-01-15 20:21:36 +00:00
version = "1.0.2" ;
2012-10-02 15:48:08 +00:00
$ ( document ) . ready ( function ( ) {
2013-01-15 20:21:36 +00:00
/* Event Name */
if ( mobileBrowser ( ) ) event _name = "touchend" ;
else event _name = "click" ;
2012-10-02 15:48:08 +00:00
/* Login */
$ ( "#password" ) . live ( "keyup" , function ( ) {
if ( $ ( this ) . val ( ) . length > 0 ) $ ( this ) . removeClass ( "error" ) ;
} ) ;
/* Add Dialog */
2013-01-15 20:21:36 +00:00
$ ( ".button_add" ) . live ( event _name , function ( ) { $ ( "body" ) . append ( buildAddModal ) } ) ;
$ ( "#add_album" ) . live ( event _name , addAlbum ) ;
$ ( "#add_photo" ) . live ( event _name , function ( ) { $ ( "#auswahl" ) . html ( "" ) ; $ ( "#upload_files" ) . click ( ) } ) ;
2012-10-02 15:48:08 +00:00
/* Toolbar Buttons */
2013-01-15 20:21:36 +00:00
$ ( "#button_signout" ) . live ( event _name , function ( ) {
2012-10-02 15:48:08 +00:00
modal = buildModal ( "Sign Out" , "Are you sure you want to leave and log out?" , [ "Sign out" , "Stay here" ] , [ "logout();" , "" ] ) ;
$ ( "body" ) . append ( modal ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( "#button_download" ) . live ( event _name , function ( ) {
2012-10-02 15:48:08 +00:00
link = $ ( "#image_view #image" ) . css ( "background-image" ) . replace ( /"/g , "" ) . replace ( /url\(|\)$/ig , "" ) ;
window . open ( link , "_newtab" ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( "#button_move" ) . live ( event _name , function ( e ) {
2012-10-02 15:48:08 +00:00
showContextMenuMove ( image _view . attr ( "data-id" ) , e . pageX , e . pageY ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( "#button_trash_album" ) . live ( event _name , function ( ) {
2012-10-02 15:48:08 +00:00
if ( content . attr ( "data-id" ) == "0" ) deleteUnsorted ( ) ;
else deleteAlbum ( ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( "#button_trash" ) . live ( event _name , function ( ) { deletePhoto ( ) } ) ;
$ ( "#button_edit_album" ) . live ( event _name , function ( ) { renameAlbum ( ) } ) ;
$ ( "#button_edit" ) . live ( event _name , function ( ) { renamePhoto ( ) } ) ;
$ ( "#button_info" ) . live ( event _name , function ( ) { showInfobox ( ) } ) ;
$ ( "#button_archive" ) . live ( event _name , function ( ) { getAlbumArchive ( ) } ) ;
$ ( "#button_sync" ) . live ( event _name , function ( ) { syncFolder ( ) } ) ;
2012-10-02 15:48:08 +00:00
/* Rename Album/Photo via Titlebar */
2013-01-15 20:21:36 +00:00
$ ( "#title.editable" ) . live ( event _name , function ( ) {
2012-10-02 15:48:08 +00:00
if ( visibleImageview ( ) ) renamePhoto ( ) ; else renameAlbum ( ) ;
} ) ;
2013-01-15 20:21:36 +00:00
2012-10-02 15:48:08 +00:00
/* Context Menu */
$ ( ".photo" ) . live ( "contextmenu" , function ( e ) {
e . preventDefault ( ) ;
showContextMenuPhoto ( $ ( this ) . attr ( "data-id" ) , e . pageX , e . pageY ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( ".contextmenu_bg" ) . live ( event _name , closeContextMenu ) ;
2012-10-02 15:48:08 +00:00
/* Star/Share Photo */
2013-01-15 20:21:36 +00:00
$ ( "#button_star" ) . live ( event _name , setPhotoStar ) ;
$ ( "#button_share" ) . live ( event _name , function ( e ) {
2012-10-02 15:48:08 +00:00
if ( $ ( "#button_share a.active" ) . length ) showContextMenuShare ( image _view . attr ( "data-id" ) , e . pageX , e . pageY ) ;
else setPhotoPublic ( e ) ;
} ) ;
2013-01-15 20:21:36 +00:00
$ ( ".copylink" ) . live ( event _name , function ( ) { $ ( this ) . select ( ) } ) ;
2012-10-02 15:48:08 +00:00
/* Upload */
$ ( "#upload_files" ) . live ( "change" , function ( ) {
closeModal ( ) ;
handleFiles ( this . files ) ;
$ ( "#upload_button" ) . click ( ) ;
} ) ;
2013-01-15 20:21:36 +00:00
2012-10-02 15:48:08 +00:00
/* Search */
$ ( "#search" ) . live ( "keyup" , function ( ) { search ( $ ( this ) . val ( ) ) } ) ;
/* Nav Forward */
$ ( ".album" ) . live ( "click" , function ( ) { setURL ( "a" + $ ( this ) . attr ( "data-id" ) ) } ) ;
$ ( ".photo" ) . live ( "click" , function ( ) { setURL ( "a" + content . attr ( "data-id" ) + "p" + $ ( this ) . attr ( "data-id" ) ) } ) ;
/* Nav Back */
2013-01-15 20:21:36 +00:00
$ ( "#button_back_home" ) . live ( event _name , function ( ) { setURL ( "" ) } ) ;
$ ( "#button_back" ) . live ( event _name , function ( ) { setURL ( "a" + content . attr ( "data-id" ) ) } ) ;
2012-10-02 15:48:08 +00:00
/* Close Modal */
2013-01-15 20:21:36 +00:00
$ ( ".message a.close" ) . live ( event _name , closeModal ) ;
2012-10-02 15:48:08 +00:00
/* Image View */
2013-01-15 20:21:36 +00:00
$ ( "#image_view a#previous" ) . live ( event _name , loadPreviousPhoto ) ;
$ ( "#image_view a#next" ) . live ( event _name , loadNextPhoto ) ;
2012-10-02 15:48:08 +00:00
/* Infobox */
2013-01-15 20:21:36 +00:00
$ ( "#infobox_overlay, #infobox .header a" ) . live ( event _name , function ( ) { hideInfobox ( ) } ) ;
$ ( "#edit_description" ) . live ( event _name , function ( ) { setPhotoDescription ( ) } ) ;
2012-10-02 15:48:08 +00:00
/* Window */
$ ( window ) . keydown ( key ) ;
$ ( window ) . bind ( "popstate" , getURL ) ;
$ ( window ) . bind ( "mouseleave" , hideControls ) ;
$ ( window ) . bind ( "mouseenter" , showControls ) ;
2013-01-15 20:21:36 +00:00
2012-10-02 15:48:08 +00:00
/* Init */
2013-01-15 20:21:36 +00:00
if ( ( BrowserDetect . browser == "Explorer" ) || ( BrowserDetect . browser == "Safari" && BrowserDetect . version < 5 ) || ( BrowserDetect . browser == "Chrome" && BrowserDetect . version < 18 ) || ( BrowserDetect . browser == "Firefox" && BrowserDetect . version < 15 ) ) {
2012-10-02 15:48:08 +00:00
modal = buildModal ( "Browser not supported" , "You are currently using an outdated or unsupported Browser. This site might not work properly. Please consider to update your Browser!" , [ "Leave" ] , [ "location.href = 'http://browsehappy.com';" ] ) ;
$ ( "body" ) . append ( modal ) ;
2013-01-15 20:21:36 +00:00
2012-10-02 15:48:08 +00:00
} else init ( ) ;
2013-01-15 20:21:36 +00:00
2012-10-02 15:48:08 +00:00
} ) ;