Lungo.Resource.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ###
  2. Load Resources
  3. @namespace Lungo
  4. @class Resource
  5. @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  6. ###
  7. Lungo.Resource = do(lng = Lungo, $$ = Quo) ->
  8. ELEMENT = lng.Constants.ELEMENT
  9. ERROR = lng.Constants.ERROR
  10. ###
  11. Start loading async sections (local & remote)
  12. @method start
  13. ###
  14. load = (resource, container) ->
  15. if lng.Core.toType(resource) is "array"
  16. i = 0
  17. len = resource.length
  18. while i < len
  19. _load resource[i]
  20. i++
  21. else
  22. _load resource, container
  23. ###
  24. @todo
  25. ###
  26. _load = (resource, container) ->
  27. try
  28. _pushResourceInBody _loadSyncResource(resource), container
  29. catch error
  30. lng.Core.log 3, error.message
  31. _loadSyncResource = (url) ->
  32. $$.ajax
  33. url: url
  34. async: false
  35. dataType: "html"
  36. error: ->
  37. console.error ERROR.LOADING_RESOURCE + url
  38. _pushResourceInBody = (markup, container) ->
  39. if lng.Core.toType(markup) is "string"
  40. container = (if container then container else ELEMENT.BODY)
  41. lng.dom(container).append markup
  42. load: load