Lungo.Resource.coffee 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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) ->
  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
  23. ###
  24. ###
  25. _load = (resource) ->
  26. try
  27. response = _loadSyncResource(resource)
  28. _pushResourceInBody response
  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 = (section) ->
  39. lng.dom(ELEMENT.BODY).append section if lng.Core.toType(section) is "string"
  40. load: load