You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_theme.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /** Construct example theme that extends some other theme
  2. * typically the DefaultTheme.
  3. *
  4. * @param themeRoot The base URL of theme resources.
  5. * @param defaultTheme Theme to be extended.
  6. *
  7. */
  8. function ExampleTheme(themeRoot, defaultTheme) {
  9. this.themeName = "ExampleTheme";
  10. this.root = themeRoot;
  11. this.parent = defaultTheme;
  12. // Tell the parent where to look for theme icons
  13. this.parent.iconRoot = this.root;
  14. }
  15. /** Register all renderers to a ajax client.
  16. *
  17. * @param client The ajax client instance.
  18. */
  19. ExampleTheme.prototype.registerTo = function(client) {
  20. // We register our own customlayout handler.
  21. // This way the layouts can be in different place.
  22. client.registerRenderer(this,"customlayout",null,this.renderCustomLayout);
  23. }
  24. ExampleTheme.prototype.renderCustomLayout = function(renderer,uidl,target,layoutInfo) {
  25. // Shortcuts
  26. var theme = renderer.theme;
  27. var parentTheme = theme.parent;
  28. // Get style
  29. var style = uidl.getAttribute("style");
  30. if (style == null) return null;
  31. // Load the layout
  32. var url = theme.root + style + ".html";
  33. var text = renderer.client.loadDocument(url,false);
  34. if (text == null) return null;
  35. // Create containing element
  36. var main = parentTheme.createPaintableElement(renderer,uidl,target);
  37. var n = parentTheme.createElementTo(main, "div");
  38. n.setAttribute("id",uidl.getAttribute("id"));
  39. n.innerHTML=text;
  40. var divs = n.getElementsByTagName("div");
  41. for (var i=0; i<divs.length; i++) {
  42. var div = divs.item(i);
  43. var name = div.getAttribute("location");
  44. if (name != null) {
  45. for (var j=0; j < uidl.childNodes.length; j++) {
  46. var c = uidl.childNodes.item(j);
  47. if (c.nodeType == Node.ELEMENT_NODE
  48. && c.nodeName == "location"
  49. && c.getAttribute("name") == name) {
  50. for (var k=0; k<c.childNodes.length; k++) {
  51. var cc = c.childNodes.item(k);
  52. if (cc.nodeType == Node.ELEMENT_NODE) {
  53. var parent = div.parentNode;
  54. // TODO
  55. if (parent != null) {
  56. parentTheme.removeAllChildNodes(div);
  57. var newNode = renderer.client.renderUIDL(cc,div);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }