Lungo.View.Element.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. var count = function(selector, count) {
  16. var element = lng.Dom.query(selector);
  17. if (element ) {
  18. if (count > 0) {
  19. _setBubble (element, count);
  20. } else {
  21. element.children(SELECTORS.BUBBLE).remove();
  22. }
  23. }
  24. };
  25. var _setBubble = function(element, count) {
  26. var bubbles = element.children(SELECTORS.BUBBLE);
  27. var total_bubbles = bubbles.length;
  28. if (total_bubbles > 0) {
  29. bubbles.html(count);
  30. } else {
  31. var count_html = LUNGO.Attributes.Data.Count.html;
  32. var html_binded = count_html.replace(BINDING_START + 'value' + BINDING_END, count);
  33. element.append(html_binded);
  34. }
  35. }
  36. return {
  37. count: count
  38. };
  39. })(LUNGO);