sidebar.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @description This module takes care of the sidebar.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. sidebar = {
  6. _dom: $('#sidebar')
  7. }
  8. sidebar.dom = function(selector) {
  9. if (selector===undefined||selector===null||selector==='') return sidebar._dom;
  10. return sidebar._dom.find(selector);
  11. }
  12. sidebar.bind = function() {
  13. // This function should be called after building and appending
  14. // the sidebars content to the DOM
  15. // Event Name
  16. var eventName = ('ontouchend' in document.documentElement) ? 'touchend' : 'click';
  17. sidebar.dom('#edit_title').on(eventName, function() {
  18. if (visible.photo()) photo.setTitle([photo.getID()]);
  19. else if (visible.album()) album.setTitle([album.getID()]);
  20. });
  21. sidebar.dom('#edit_description').on(eventName, function() {
  22. if (visible.photo()) photo.setDescription(photo.getID());
  23. else if (visible.album()) album.setDescription(album.getID());
  24. });
  25. sidebar.dom('#edit_tags') .on(eventName, function() { photo.editTags([photo.getID()]) });
  26. sidebar.dom('#tags .tag span') .on(eventName, function() { photo.deleteTag(photo.getID(), $(this).data('index')) });
  27. return true;
  28. }
  29. sidebar.toggle = function() {
  30. if (visible.sidebar()||
  31. visible.sidebarbutton()) {
  32. header.dom('.button--info').toggleClass('active')
  33. lychee.content.toggleClass('sidebar');
  34. sidebar.dom().toggleClass('active');
  35. return true;
  36. }
  37. return false;
  38. }
  39. sidebar.setSelectable = function(selectable = true) {
  40. // Attributes/Values inside the sidebar are selectable by default.
  41. // Selection needs to be deactivated to prevent an unwanted selection
  42. // while using multiselect.
  43. if (selectable===true) sidebar.dom().removeClass('notSelectable');
  44. else sidebar.dom().addClass('notSelectable');
  45. }
  46. sidebar.changeAttr = function(attr, value, editable = false) {
  47. if (attr===undefined||attr===null||attr==='') return false;
  48. // This will add an edit-icon next to the value when editable is true.
  49. // The id of the edit-icon always starts with 'edit_' followed by the name of the attribute.
  50. if (editable===true) value = value + ' ' + build.editIcon('edit_' + attr);
  51. sidebar.dom('.attr_' + attr).html(value);
  52. // The new edit-icon needs an event, therefore the binding function
  53. // should be executed again after changing the value
  54. if (editable===true) sidebar.bind();
  55. return true;
  56. }