Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

64 linhas
1.3 KiB

  1. /*
  2. Modules
  3. wn.module.$import('forms') will load wn.forms, if loaded will return nothing
  4. timestamps will be loaded with the window in wn.timestamps
  5. */
  6. wn.module = {
  7. //
  8. $import: function(module_name, callback) {
  9. if(wn[module_name]) return;
  10. wn.module.load(module_name, callback);
  11. },
  12. load: function(module_name, callback) {
  13. // if loaded in local and recent
  14. alert('checking in local')
  15. if(wn.module.in_local(module_name)) {
  16. if(callback) callback();
  17. return;
  18. }
  19. alert('loading from server')
  20. wn.module.get_from_server(module_name,callback )
  21. },
  22. get_from_server : function(module_name, callback) {
  23. req = $.ajax({
  24. url: 'cgi-bin/getjsfile.cgi?module=' + module_name, // TODO use getjsfile.cgi, replace not reqd
  25. datatype:'text',
  26. success: [wn.module.accept,callback]
  27. })
  28. },
  29. in_local: function(module_name) {
  30. // check if module in local and recent
  31. var m = JSON.parse(localStorage.getItem(module_name));
  32. alert('in_local' + m.timestamp)
  33. if( m && m.timestamp == wn.timestamps[module_name]) {
  34. eval(m.code);
  35. return true;
  36. }
  37. return false
  38. },
  39. accept: function(data, status, jqXHR) {
  40. data = JSON.parse(data)
  41. for (var codename in data)
  42. {
  43. localStorage.setItem(codename, JSON.stringify({
  44. timestamp : wn.timestamps[codename],
  45. code : data[codename]
  46. }))
  47. eval(data[codename])
  48. }
  49. }
  50. }