main.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * @name main.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2012 by Philipp Maurer, Tobias Reich
  6. */
  7. var header = $("header"),
  8. headerTitle = $("#title"),
  9. content = $("#content"),
  10. image_view = $("#image_view"),
  11. loading = $("#loading"),
  12. infobox = $("#infobox"),
  13. api_path = "php/api.php",
  14. version = "1.0.2";
  15. $(document).ready(function(){
  16. /* Event Name */
  17. if (mobileBrowser()) event_name = "touchend";
  18. else event_name = "click";
  19. /* Login */
  20. $("#password").live("keyup", function() {
  21. if ($(this).val().length>0) $(this).removeClass("error");
  22. });
  23. /* Add Dialog */
  24. $(".button_add").live(event_name, function() { $("body").append(buildAddModal) });
  25. $("#add_album").live(event_name, addAlbum);
  26. $("#add_photo").live(event_name, function() { $("#auswahl").html(""); $("#upload_files").click() });
  27. /* Toolbar Buttons */
  28. $("#button_signout").live(event_name, function() {
  29. modal = buildModal("Sign Out", "Are you sure you want to leave and log out?", ["Sign out", "Stay here"], ["logout();", ""]);
  30. $("body").append(modal);
  31. });
  32. $("#button_download").live(event_name, function() {
  33. link = $("#image_view #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
  34. window.open(link,"_newtab");
  35. });
  36. $("#button_move").live(event_name, function(e) {
  37. showContextMenuMove(image_view.attr("data-id"), e.pageX, e.pageY);
  38. });
  39. $("#button_trash_album").live(event_name, function() {
  40. if (content.attr("data-id")=="0") deleteUnsorted();
  41. else deleteAlbum();
  42. });
  43. $("#button_trash").live(event_name, function() { deletePhoto() });
  44. $("#button_edit_album").live(event_name, function() { renameAlbum() });
  45. $("#button_edit").live(event_name, function() { renamePhoto() });
  46. $("#button_info").live(event_name, function() { showInfobox() });
  47. $("#button_archive").live(event_name, function() { getAlbumArchive() });
  48. $("#button_sync").live(event_name, function() { syncFolder() });
  49. /* Rename Album/Photo via Titlebar */
  50. $("#title.editable").live(event_name, function() {
  51. if (visibleImageview()) renamePhoto(); else renameAlbum();
  52. });
  53. /* Context Menu */
  54. $(".photo").live("contextmenu", function(e) {
  55. e.preventDefault();
  56. showContextMenuPhoto($(this).attr("data-id"), e.pageX, e.pageY);
  57. });
  58. $(".contextmenu_bg").live(event_name, closeContextMenu);
  59. /* Star/Share Photo */
  60. $("#button_star").live(event_name, setPhotoStar);
  61. $("#button_share").live(event_name, function(e) {
  62. if ($("#button_share a.active").length) showContextMenuShare(image_view.attr("data-id"), e.pageX, e.pageY);
  63. else setPhotoPublic(e);
  64. });
  65. $(".copylink").live(event_name, function() { $(this).select() });
  66. /* Upload */
  67. $("#upload_files").live("change", function() {
  68. closeModal();
  69. handleFiles(this.files);
  70. $("#upload_button").click();
  71. });
  72. /* Search */
  73. $("#search").live("keyup", function() { search($(this).val()) });
  74. /* Nav Forward */
  75. $(".album").live("click", function() { setURL("a" + $(this).attr("data-id")) });
  76. $(".photo").live("click", function() { setURL("a" + content.attr("data-id") + "p" + $(this).attr("data-id")) });
  77. /* Nav Back */
  78. $("#button_back_home").live(event_name, function() { setURL("") });
  79. $("#button_back").live(event_name, function() { setURL("a" + content.attr("data-id")) });
  80. /* Close Modal */
  81. $(".message a.close").live(event_name, closeModal);
  82. /* Image View */
  83. $("#image_view a#previous").live(event_name, loadPreviousPhoto);
  84. $("#image_view a#next").live(event_name, loadNextPhoto);
  85. /* Infobox */
  86. $("#infobox_overlay, #infobox .header a").live(event_name, function() { hideInfobox() });
  87. $("#edit_description").live(event_name, function() { setPhotoDescription() });
  88. /* Window */
  89. $(window).keydown(key);
  90. $(window).bind("popstate", getURL);
  91. $(window).bind("mouseleave", hideControls);
  92. $(window).bind("mouseenter", showControls);
  93. /* Init */
  94. if ((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Safari"&&BrowserDetect.version<5)||(BrowserDetect.browser=="Chrome"&&BrowserDetect.version<18)||(BrowserDetect.browser=="Firefox"&&BrowserDetect.version<15)) {
  95. 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';"]);
  96. $("body").append(modal);
  97. } else init();
  98. });