Lungo.View.Element.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Initialize the <articles> layout of a certain <section>
  3. *
  4. * @namespace LUNGO.View
  5. * @class Element
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. */
  9. LUNGO.View.Element = (function(lng, undefined) {
  10. var SELECTORS = {
  11. BUBBLE: '.bubble.count'
  12. };
  13. var BINDING_START = '{{';
  14. var BINDING_END = '}}';
  15. /**
  16. * Set a counter to the element
  17. *
  18. * @method count
  19. *
  20. * @param {string} Element query selector
  21. * @param {number} Value for counter
  22. */
  23. var count = function(selector, count) {
  24. var element = lng.dom(selector);
  25. if (element ) {
  26. if (count > 0) {
  27. _setBubble(element, count);
  28. } else {
  29. element.children(SELECTORS.BUBBLE).remove();
  30. }
  31. }
  32. };
  33. var _setBubble = function(element, count) {
  34. var bubbles = element.children(SELECTORS.BUBBLE);
  35. var total_bubbles = bubbles.length;
  36. if (total_bubbles > 0) {
  37. bubbles.html(count);
  38. } else {
  39. var count_html = LUNGO.Attributes.Data.Count.html;
  40. var html_binded = count_html.replace(BINDING_START + 'value' + BINDING_END, count);
  41. element.append(html_binded);
  42. }
  43. };
  44. return {
  45. count: count
  46. };
  47. })(LUNGO);