Lungo.View.Resize.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. *
  3. *
  4. * @namespace LUNGO.View
  5. * @class Resize
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  9. */
  10. LUNGO.View.Resize = (function(lng, undefined) {
  11. /**
  12. * Rezise a <scroll> element
  13. *
  14. * @method scroll
  15. *
  16. * @param {object} Object reference of a determinated <section>
  17. */
  18. var scroll = function(scroll) {
  19. var container = scroll.children().first();
  20. var child = container.children().first();
  21. if (lng.View.Scroll.isHorizontal(scroll)) {
  22. _resizeScrollContainerWidth(container, child);
  23. } else {
  24. _resizeScrollContainerHeight(scroll, container, child);
  25. }
  26. };
  27. /**
  28. * Sets toolbars width, using total screen width
  29. *
  30. * @method toolbars
  31. */
  32. var toolbars = function() {
  33. var toolbar = '.toolbar nav, .groupbar';
  34. var all_toolbars = lng.dom(toolbar);
  35. for (var i = 0, len = all_toolbars.length; i < len; i++) {
  36. var toolbar = lng.dom(all_toolbars[i]);
  37. var toolbar_children = toolbar.children();
  38. var toolbar_children_width = (toolbar.width() / toolbar_children.length);
  39. toolbar_children.style('width', toolbar_children_width + 'px');
  40. }
  41. };
  42. var _resizeScrollContainerWidth = function(container, child) {
  43. var scroll_width = (container.children().length * child.width());
  44. container.style('width', scroll_width + 'px');
  45. };
  46. var _resizeScrollContainerHeight = function(scroll, container, child) {
  47. var total_children = container.children().length;
  48. var children_in_scroll_width = Math.floor(scroll.width() / child.width());
  49. var total_rows = Math.ceil(total_children / children_in_scroll_width);
  50. var scroll_height = (total_rows * child.height());
  51. container.style('height', scroll_height + 'px');
  52. };
  53. return {
  54. scroll: scroll,
  55. toolbars: toolbars
  56. };
  57. })(LUNGO);