appstart.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* appjet:version 0.1 */
  2. /* appjet:library */
  3. // Copyright (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. var _hdrWrite = page.body.write,
  15. _dir, _fb = false;
  16. function appRun (dir, callback) {
  17. setupAppDir(dir);
  18. setupAppPresenter();
  19. setupAppView();
  20. setupAppModel();
  21. if (callback) callback();
  22. appGo();
  23. }
  24. function setupAppDir (dir) { _dir = dir; }
  25. function setupAppPresenter () {
  26. import(_dir + "presenter");
  27. import("lib-app/dispatch-plus");
  28. page.setPresenter(dispatchPlus);
  29. }
  30. function setupAppView () {
  31. import(_dir + "view");
  32. page.setView(getView());
  33. }
  34. function setupAppModel () {
  35. import(_dir + "model");
  36. page.setModel(getModel());
  37. }
  38. function setupFacebook () {
  39. if (request.isGet && request.path !== '/') {
  40. var _oldFbInit = fb.init;
  41. fb.init = function() {
  42. request.method = "POST";
  43. try {
  44. _oldFbInit.apply(this, arguments);
  45. } finally {
  46. request.method = "GET";
  47. }
  48. };
  49. }
  50. fb.init();
  51. _fb = true;
  52. }
  53. function setupAppUiGallery () {
  54. if (_fb) {
  55. dispatchInject(function post_callback_ui_ () {
  56. import({}, _dir + "view-gallery").show(true);
  57. });
  58. dispatchInject(function get_ui_ () {
  59. page.setMode("html");
  60. _hdrWrite = page.head.write;
  61. request.method = "POST";
  62. import({}, _dir + "view-gallery").show();
  63. });
  64. } else throw "not yet implemented";
  65. }
  66. function appGo () {
  67. mvp();
  68. _hdrWrite(["<style type='text/css'>", getCss(), "</style>", ""].join("\r\n"));
  69. }