Lungo.View.Resize.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Resize all <article>s from determinated <section> based on a CSS property.
  29. *
  30. * @method article
  31. *
  32. * @param {object} Object reference of a determinated <section>
  33. * @param {string} Selector that refers to a section element
  34. * @param {string} CSS property
  35. * @param {string} Element reference for resizing
  36. */
  37. var article = function(section, selector, property, reference) {
  38. var element = section.children(selector);
  39. var ARTICLE = 'article';
  40. if (element.length > 0) {
  41. var reference_dimension = element[reference]();
  42. section.children(ARTICLE).style(property, reference_dimension + 'px');
  43. }
  44. };
  45. /**
  46. * Sets toolbars width, using total screen width
  47. *
  48. * @method toolbars
  49. */
  50. var toolbars = function() {
  51. var toolbar = '.toolbar nav';
  52. var all_toolbars = lng.dom(toolbar);
  53. for (var i = 0, len = all_toolbars.length; i < len; i++) {
  54. var toolbar = lng.dom(all_toolbars[i]);
  55. var toolbar_children = toolbar.children();
  56. var toolbar_children_width = (toolbar.width() / toolbar_children.length);
  57. toolbar_children.style('width', toolbar_children_width + 'px');
  58. }
  59. };
  60. var _resizeScrollContainerWidth = function(container, child) {
  61. var scroll_width = (container.children().length * child.width());
  62. container.style('width', scroll_width + 'px');
  63. };
  64. var _resizeScrollContainerHeight = function(scroll, container, child) {
  65. var total_children = container.children().length;
  66. var children_in_scroll_width = Math.floor(scroll.width() / child.width());
  67. var total_rows = Math.ceil(total_children / children_in_scroll_width);
  68. var scroll_height = (total_rows * child.height());
  69. container.style('height', scroll_height + 'px');
  70. };
  71. return {
  72. scroll: scroll,
  73. article: article,
  74. toolbars: toolbars
  75. };
  76. })(LUNGO);