header.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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===undefined||selector===null||selector==='') return header._dom;
  10. return header._dom.find(selector);
  11. }
  12. header.show = function() {
  13. var newMargin = -1*($('#imageview #image').height()/2)+20;
  14. clearTimeout($(window).data('timeout'));
  15. lychee.imageview.removeClass('full');
  16. header.dom().removeClass('hidden');
  17. // Adjust position or size of photo
  18. if ($('#imageview #image.small').length>0) $('#imageview #image').css('margin-top', newMargin);
  19. else $('#imageview #image').removeClass('full');
  20. }
  21. header.hide = function(e, delay) {
  22. var newMargin = -1*($('#imageview #image').height()/2);
  23. if (delay===undefined) delay = 500;
  24. if (visible.photo()&&!visible.infobox()&&!visible.contextMenu()&&!visible.message()) {
  25. clearTimeout($(window).data('timeout'));
  26. $(window).data('timeout', setTimeout(function() {
  27. lychee.imageview.addClass('full');
  28. header.dom().addClass('hidden');
  29. // Adjust position or size of photo
  30. if ($('#imageview #image.small').length>0) $('#imageview #image').css('margin-top', newMargin);
  31. else $('#imageview #image').addClass('full');
  32. }, delay));
  33. }
  34. }
  35. header.setTitle = function(title) {
  36. var $title = header.dom('#title'),
  37. title = title || 'Untitled';
  38. $title.html(title + build.iconic('caret-bottom'));
  39. }
  40. header.setMode = function(mode) {
  41. var albumID = album.getID();
  42. switch (mode) {
  43. case 'albums':
  44. header.dom().removeClass('view');
  45. $('#tools_album, #tools_photo').hide();
  46. $('#tools_albums').show();
  47. break;
  48. case 'album':
  49. header.dom().removeClass('view');
  50. $('#tools_albums, #tools_photo').hide();
  51. $('#tools_album').show();
  52. // Hide download button when album empty
  53. album.json.content === false ? $('#button_archive').hide() : $('#button_archive').show();
  54. // Hide download button when not logged in and album not downloadable
  55. if (lychee.publicMode===true&&album.json.downloadable==='0') $('#button_archive').hide();
  56. if (albumID==='s'||albumID==='f'||albumID==='r') {
  57. $('#button_info_album, #button_trash_album, #button_share_album').hide();
  58. } else if (albumID==='0') {
  59. $('#button_info_album, #button_share_album').hide();
  60. $('#button_trash_album').show();
  61. } else {
  62. $('#button_info_album, #button_trash_album, #button_share_album').show();
  63. }
  64. break;
  65. case 'photo':
  66. header.dom().addClass('view');
  67. $('#tools_albums, #tools_album').hide();
  68. $('#tools_photo').show();
  69. break;
  70. }
  71. }
  72. header.setEditable = function(editable) {
  73. var $title = header.dom('#title');
  74. // Hide editable icon when not logged in
  75. if (lychee.publicMode===true) editable = false;
  76. if (editable) $title.addClass('editable');
  77. else $title.removeClass('editable');
  78. }