appstart.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* appjet:version 0.1 */
  2. /* appjet:library */
  3. // (c) 2010, Herbert Vojčík
  4. // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php)
  5. // Fake 'storage' to point to 'storage[appjet.appName]'
  6. // Must be imported before storage (the best is to import it first).
  7. var old = appjet._native.runLibrary;
  8. appjet._native.runLibrary = function () {
  9. var lib = Function.prototype.apply.call(old, this, arguments);
  10. lib.storage = lib.storage[appjet.appName];
  11. return lib;
  12. };
  13. try { import({}, "storage"); } finally { appjet._native.runLibrary = old; }
  14. import("lib-app/globals");
  15. var _hdrWrite = page.body.write,
  16. _dir;
  17. function appRun (dir, callback) {
  18. setupAppDir(dir);
  19. setupAppPresenter();
  20. setupAppView();
  21. setupAppModel();
  22. if (callback) callback();
  23. appGo();
  24. }
  25. function setupAppDir (dir) { _dir = dir; }
  26. function setupAppPresenter () {
  27. if (request.isGet && request.path !== '/') {
  28. var _oldFbInit = fb.init;
  29. fb.init = function() {
  30. request.method = "POST";
  31. try {
  32. _oldFbInit.apply(this, arguments);
  33. } finally {
  34. request.method = "GET";
  35. }
  36. };
  37. }
  38. fb.init();
  39. import(_dir + "presenter");
  40. import("lib-app/dispatch-plus");
  41. page.setPresenter(dispatchPlus);
  42. }
  43. function setupAppView () {
  44. dispatchInject(function post_callback_ui_ () {
  45. import({}, _dir + "view-gallery").show(true);
  46. });
  47. dispatchInject(function get_callback_ui_ () {
  48. page.setMode("html");
  49. _hdrWrite = page.head.write;
  50. request.method = "POST";
  51. import({}, _dir + "view-gallery").show();
  52. });
  53. import(_dir + "view");
  54. page.setView(getView());
  55. }
  56. function setupAppModel () {
  57. import(_dir + "model");
  58. page.setModel(getModel());
  59. }
  60. function appGo () {
  61. mvp();
  62. _hdrWrite(["<style type='text/css'>", getCss(), "</style>", ""].join("\r\n"));
  63. }