header.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @description This module takes care of the header.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. header = {
  6. _dom: $('.header')
  7. }
  8. header.dom = function(selector) {
  9. if (selector==null || selector==='') return header._dom
  10. return header._dom.find(selector)
  11. }
  12. header.bind = function() {
  13. // Event Name
  14. let eventName = lychee.getEventName()
  15. header.dom('.header__title').on(eventName, function(e) {
  16. if ($(this).hasClass('header__title--editable')===false) return false
  17. if (visible.photo()) contextMenu.photoTitle(album.getID(), photo.getID(), e)
  18. else contextMenu.albumTitle(album.getID(), e)
  19. })
  20. header.dom('#button_share').on(eventName, function(e) {
  21. if (photo.json.public==='1' || photo.json.public==='2') contextMenu.sharePhoto(photo.getID(), e)
  22. else photo.setPublic(photo.getID(), e)
  23. })
  24. header.dom('#button_share_album').on(eventName, function(e) {
  25. if (album.json.public==='1') contextMenu.shareAlbum(album.getID(), e)
  26. else album.setPublic(album.getID(), true, e)
  27. })
  28. header.dom('#button_signin') .on(eventName, lychee.loginDialog)
  29. header.dom('#button_settings') .on(eventName, contextMenu.settings)
  30. header.dom('#button_info_album') .on(eventName, sidebar.toggle)
  31. header.dom('#button_info') .on(eventName, sidebar.toggle)
  32. header.dom('.button_add') .on(eventName, contextMenu.add)
  33. header.dom('#button_more') .on(eventName, function(e) { contextMenu.photoMore(photo.getID(), e) })
  34. header.dom('#button_move') .on(eventName, function(e) { contextMenu.move([ photo.getID() ], e) })
  35. header.dom('.header__hostedwith') .on(eventName, function() { window.open(lychee.website) })
  36. header.dom('#button_trash_album') .on(eventName, function() { album.delete([ album.getID() ]) })
  37. header.dom('#button_trash') .on(eventName, function() { photo.delete([ photo.getID() ]) })
  38. header.dom('#button_archive') .on(eventName, function() { album.getArchive(album.getID()) })
  39. header.dom('#button_star') .on(eventName, function() { photo.setStar([ photo.getID() ]) })
  40. header.dom('#button_back_home') .on(eventName, function() { lychee.goto() })
  41. header.dom('#button_back') .on(eventName, function() { lychee.goto(album.getID()) })
  42. header.dom('.header__search').on('keyup click', function() { search.find($(this).val()) })
  43. header.dom('.header__clear').on(eventName, function() {
  44. header.dom('.header__search').focus()
  45. search.reset()
  46. })
  47. return true
  48. }
  49. header.show = function() {
  50. lychee.imageview.removeClass('full')
  51. header.dom().removeClass('header--hidden')
  52. return true
  53. }
  54. header.hide = function(e) {
  55. if (visible.photo() && !visible.sidebar() && !visible.contextMenu() && basicModal.visible()===false) {
  56. lychee.imageview.addClass('full')
  57. header.dom().addClass('header--hidden')
  58. return true
  59. }
  60. return false
  61. }
  62. header.setTitle = function(title = 'Untitled') {
  63. let $title = header.dom('.header__title')
  64. let html = lychee.html`$${ title }${ build.iconic('caret-bottom') }`
  65. $title.html(html)
  66. return true
  67. }
  68. header.setMode = function(mode) {
  69. if (mode==='albums' && lychee.publicMode===true) mode = 'public'
  70. switch (mode) {
  71. case 'public':
  72. header.dom().removeClass('header--view')
  73. header.dom('.header__toolbar--albums, .header__toolbar--album, .header__toolbar--photo').removeClass('header__toolbar--visible')
  74. header.dom('.header__toolbar--public').addClass('header__toolbar--visible')
  75. return true
  76. break
  77. case 'albums':
  78. header.dom().removeClass('header--view')
  79. header.dom('.header__toolbar--public, .header__toolbar--album, .header__toolbar--photo').removeClass('header__toolbar--visible')
  80. header.dom('.header__toolbar--albums').addClass('header__toolbar--visible')
  81. return true
  82. break
  83. case 'album':
  84. let albumID = album.getID()
  85. header.dom().removeClass('header--view')
  86. header.dom('.header__toolbar--public, .header__toolbar--albums, .header__toolbar--photo').removeClass('header__toolbar--visible')
  87. header.dom('.header__toolbar--album').addClass('header__toolbar--visible')
  88. // Hide download button when album empty
  89. if (album.json.content===false) $('#button_archive').hide()
  90. else $('#button_archive').show()
  91. // Hide download button when not logged in and album not downloadable
  92. if (lychee.publicMode===true && album.json.downloadable==='0') $('#button_archive').hide()
  93. if (albumID==='s' || albumID==='f' || albumID==='r') {
  94. $('#button_info_album, #button_trash_album, #button_share_album').hide()
  95. } else if (albumID==='0') {
  96. $('#button_info_album, #button_share_album').hide()
  97. $('#button_trash_album').show()
  98. } else {
  99. $('#button_info_album, #button_trash_album, #button_share_album').show()
  100. }
  101. return true
  102. break
  103. case 'photo':
  104. header.dom().addClass('header--view')
  105. header.dom('.header__toolbar--public, .header__toolbar--albums, .header__toolbar--album').removeClass('header__toolbar--visible')
  106. header.dom('.header__toolbar--photo').addClass('header__toolbar--visible')
  107. return true
  108. break
  109. }
  110. return false
  111. }
  112. header.setEditable = function(editable) {
  113. let $title = header.dom('.header__title')
  114. // Hide editable icon when not logged in
  115. if (lychee.publicMode===true) editable = false
  116. if (editable) $title.addClass('header__title--editable')
  117. else $title.removeClass('header__title--editable')
  118. return true
  119. }