header.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. clearTimeout($(window).data('timeout'))
  51. lychee.imageview.removeClass('full')
  52. header.dom().removeClass('header--hidden')
  53. return true
  54. }
  55. header.hide = function(e, delay = 500) {
  56. if (visible.photo() && !visible.sidebar() && !visible.contextMenu() && basicModal.visible()===false) {
  57. clearTimeout($(window).data('timeout'))
  58. $(window).data('timeout', setTimeout(function() {
  59. lychee.imageview.addClass('full')
  60. header.dom().addClass('header--hidden')
  61. }, delay))
  62. return true
  63. }
  64. return false
  65. }
  66. header.setTitle = function(title = 'Untitled') {
  67. let $title = header.dom('.header__title')
  68. let html = lychee.html`$${ title }${ build.iconic('caret-bottom') }`
  69. $title.html(html)
  70. return true
  71. }
  72. header.setMode = function(mode) {
  73. if (mode==='albums' && lychee.publicMode===true) mode = 'public'
  74. switch (mode) {
  75. case 'public':
  76. header.dom().removeClass('header--view')
  77. header.dom('.header__toolbar--albums, .header__toolbar--album, .header__toolbar--photo').removeClass('header__toolbar--visible')
  78. header.dom('.header__toolbar--public').addClass('header__toolbar--visible')
  79. return true
  80. break
  81. case 'albums':
  82. header.dom().removeClass('header--view')
  83. header.dom('.header__toolbar--public, .header__toolbar--album, .header__toolbar--photo').removeClass('header__toolbar--visible')
  84. header.dom('.header__toolbar--albums').addClass('header__toolbar--visible')
  85. return true
  86. break
  87. case 'album':
  88. let albumID = album.getID()
  89. header.dom().removeClass('header--view')
  90. header.dom('.header__toolbar--public, .header__toolbar--albums, .header__toolbar--photo').removeClass('header__toolbar--visible')
  91. header.dom('.header__toolbar--album').addClass('header__toolbar--visible')
  92. // Hide download button when album empty
  93. if (album.json.content===false) $('#button_archive').hide()
  94. else $('#button_archive').show()
  95. // Hide download button when not logged in and album not downloadable
  96. if (lychee.publicMode===true && album.json.downloadable==='0') $('#button_archive').hide()
  97. if (albumID==='s' || albumID==='f' || albumID==='r') {
  98. $('#button_info_album, #button_trash_album, #button_share_album').hide()
  99. } else if (albumID==='0') {
  100. $('#button_info_album, #button_share_album').hide()
  101. $('#button_trash_album').show()
  102. } else {
  103. $('#button_info_album, #button_trash_album, #button_share_album').show()
  104. }
  105. return true
  106. break
  107. case 'photo':
  108. header.dom().addClass('header--view')
  109. header.dom('.header__toolbar--public, .header__toolbar--albums, .header__toolbar--album').removeClass('header__toolbar--visible')
  110. header.dom('.header__toolbar--photo').addClass('header__toolbar--visible')
  111. return true
  112. break
  113. }
  114. return false
  115. }
  116. header.setEditable = function(editable) {
  117. let $title = header.dom('.header__title')
  118. // Hide editable icon when not logged in
  119. if (lychee.publicMode===true) editable = false
  120. if (editable) $title.addClass('header__title--editable')
  121. else $title.removeClass('header__title--editable')
  122. return true
  123. }