footer.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* appjet:version 0.1 */
  2. /* appjet:library */
  3. // Copyright (c) 2009, Herbert Vojčík
  4. // Licensed by MIT license (http://www.opensource.org/licenses/mit-license.php)
  5. var _re = /<div[^>]*id=['"]appjetfooter['"][^>]*>/;
  6. /**@ignore*/
  7. function replaceTheFooter(f) {
  8. var _oldrender = page.render;
  9. /**@ignore*/
  10. page.render = function() {
  11. page.render = _oldrender;
  12. var result = page.render();
  13. var index = _findFooterIndex(result);
  14. if (index !== -1) { result[index] = f(result[index]); }
  15. return result;
  16. };
  17. function _findFooterIndex(array) {
  18. for (var i = array.length - 1; i >= 0; --i) {
  19. if (array[i].match(_re)) {
  20. return i;
  21. }
  22. }
  23. return -1;
  24. }
  25. }
  26. /**
  27. * At render time, inserts the content provided
  28. * by the supplied function into the footer.
  29. */
  30. function extendTheFooter(f) {
  31. replaceTheFooter(function(footer) {
  32. return footer.replace(_re, function(a) {
  33. return a+toHTML(DIV(f()));
  34. });
  35. });
  36. }
  37. /**
  38. * Hides the footer at render time.
  39. */
  40. function hideTheFooter(f) {
  41. replaceTheFooter(function() { return ""; });
  42. }
  43. /* appjet:server */
  44. import(appjet.appName);
  45. extendTheFooter(function() {
  46. return SPAN(
  47. "Server time is: ",
  48. new Date(),
  49. " ",
  50. SPAN({style:"color:silver"}, "(this line extends the footer)")
  51. );
  52. });
  53. //hideTheFooter();