Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

123 Zeilen
2.5 KiB

  1. // Copyright 2013 Web Notes Technologies Pvt Ltd
  2. // License: MIT. See license.txt
  3. // library to mange assets (js, css, models, html) etc in the app.
  4. // will try and get from localStorge if latest are available
  5. // depends on wn.versions to manage versioning
  6. wn.require = function(items) {
  7. if(typeof items === "string") {
  8. items = [items];
  9. }
  10. var l = items.length;
  11. for(var i=0; i< l; i++) {
  12. var src = items[i];
  13. //if(!(src in wn.assets.executed_)) {
  14. // check if available in localstorage
  15. wn.assets.execute(src);
  16. //}
  17. }
  18. }
  19. wn.assets = {
  20. // keep track of executed assets
  21. executed_ : {},
  22. check: function() {
  23. // if version is different then clear localstorage
  24. if(window._version_number != localStorage.getItem("_version_number")) {
  25. localStorage.clear();
  26. localStorage.setItem("_version_number", window._version_number)
  27. console.log("Cleared App Cache.");
  28. }
  29. },
  30. // check if the asset exists in
  31. // localstorage
  32. exists: function(src) {
  33. if('localStorage' in window
  34. && localStorage.getItem(src) && (wn.boot ? !wn.boot.developer_mode : true))
  35. return true
  36. },
  37. // add the asset to
  38. // localstorage
  39. add: function(src, txt) {
  40. if('localStorage' in window) {
  41. try {
  42. localStorage.setItem(src, txt);
  43. } catch(e) {
  44. console.log("Local Storage quota exceeded?")
  45. }
  46. }
  47. },
  48. get: function(src) {
  49. return localStorage.getItem(src);
  50. },
  51. extn: function(src) {
  52. if(src.indexOf('?')!=-1) {
  53. src = src.split('?').slice(-1)[0];
  54. }
  55. return src.split('.').slice(-1)[0];
  56. },
  57. // load an asset via
  58. load: function(src) {
  59. // this is virtual page load, only get the the source
  60. // *without* the template
  61. var t = src;
  62. wn.set_loading();
  63. $.ajax({
  64. url: t,
  65. data: {
  66. q: Math.floor(Math.random()*1000)
  67. },
  68. dataType: 'text',
  69. success: function(txt) {
  70. // add it to localstorage
  71. wn.assets.add(src, txt);
  72. },
  73. async: false
  74. });
  75. wn.done_loading();
  76. },
  77. // pass on to the handler to set
  78. execute: function(src) {
  79. if(!wn.assets.exists(src)) {
  80. wn.assets.load(src);
  81. }
  82. var type = wn.assets.extn(src);
  83. if(wn.assets.handler[type]) {
  84. wn.assets.handler[type](wn.assets.get(src), src);
  85. wn.assets.executed_[src] = 1;
  86. }
  87. },
  88. // handle types of assets
  89. // and launch them in the
  90. // app
  91. handler: {
  92. js: function(txt, src) {
  93. wn.dom.eval(txt);
  94. },
  95. css: function(txt, src) {
  96. wn.dom.set_style(txt);
  97. }
  98. }
  99. }
  100. wn.markdown = function(txt) {
  101. if(!wn.md2html) {
  102. wn.require('lib/js/lib/showdown.js');
  103. wn.md2html = new Showdown.converter();
  104. }
  105. return wn.md2html.makeHtml(txt);
  106. }