Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 14 roky
před 14 roky
před 14 roky
před 14 roky
před 14 roky
před 14 roky
před 14 roky
před 14 roky
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // library to mange assets (js, css, models, html) etc in the app.
  2. // will try and get from localStorge if latest are available
  3. // or will load them via xmlhttp
  4. // depends on wn.versions to manage versioning
  5. wn.assets = {
  6. // keep track of executed assets
  7. executed_ : {},
  8. // check if the asset exists in
  9. // localstorage
  10. exists: function(src) {
  11. if('localStorage' in window
  12. && localStorage.getItem(src))
  13. return true
  14. },
  15. // add the asset to
  16. // localstorage
  17. add: function(src, txt) {
  18. if('localStorage' in window) {
  19. localStorage.setItem(src, txt);
  20. }
  21. },
  22. get: function(src) {
  23. return localStorage.getItem(src);
  24. },
  25. extn: function(src) {
  26. return src.split('.').slice(-1)[0];
  27. },
  28. html_src: function(src) {
  29. if(src.indexOf('/')!=-1) {
  30. var t = src.split('/').slice(0,-1);
  31. t.push('src');
  32. t = t.join('/') +'/' + a.split('/').slice(-1)[0];
  33. } else {
  34. var t = 'src/' + src;
  35. }
  36. return t;
  37. },
  38. // load an asset via
  39. // xmlhttp
  40. load: function(src) {
  41. var t = wn.assets.extn(src)=='html' ? wn.assets.html_src(src) : src;
  42. wn.xmlhttp.get(t, function(txt) {
  43. // add it to localstorage
  44. wn.assets.add(src, txt);
  45. }, 'q=' & Math.floor(Math.random()*1000) , false)
  46. },
  47. // pass on to the handler to set
  48. execute: function(src) {
  49. if(!wn.assets.exists(src)) {
  50. wn.assets.load(src);
  51. }
  52. var type = wn.assets.extn(src);
  53. if(wn.assets.handler[type]) {
  54. wn.assets.handler[type](wn.assets.get(src), src);
  55. wn.assets.executed_[src] = 1;
  56. }
  57. },
  58. // handle types of assets
  59. // and launch them in the
  60. // app
  61. handler: {
  62. js: function(txt, src) {
  63. wn.dom.eval(txt);
  64. },
  65. css: function(txt, src) {
  66. var se = document.createElement('style');
  67. se.type = "text/css";
  68. if (se.styleSheet) {
  69. se.styleSheet.cssText = txt;
  70. } else {
  71. se.appendChild(document.createTextNode(txt));
  72. }
  73. document.getElementsByTagName('head')[0].appendChild(se);
  74. },
  75. html: function(txt, src) {
  76. // make the html content page
  77. var page = wn.dom.add($('.outer .inner').get(0), 'div', 'content', null, txt);
  78. page.setAttribute("_src", src);
  79. }
  80. }
  81. }