Widget.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. MWF.xDesktop.Widget = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "style": "default",
  5. "title": "widget",
  6. "width": "400",
  7. "height": "400",
  8. "position": {"right": 10, "bottom": 10},
  9. "html": "",
  10. "text": "",
  11. "url": "",
  12. "content": null
  13. },
  14. initialize: function(desktop, options){
  15. this.setOptions(options);
  16. this.desktop = desktop;
  17. this.css = this.desktop.css;
  18. },
  19. load: function(){
  20. this.fireEvent("queryLoad");
  21. this.node = new Element("div#widget", {"styles": this.css.widgetNode}).inject(this.desktop.desktopNode);
  22. this.node.setStyles({
  23. "width": ""+this.options.width+"px",
  24. "height": ""+this.options.height+"px"
  25. });
  26. this.titleNode = new Element("div", {"styles": this.css.widgetTitleNode}).inject(this.node);
  27. this.titleOpenNode = new Element("div", {"styles": this.css.widgetTitleOpenNode}).inject(this.titleNode);
  28. this.titleCloseNode = new Element("div", {"styles": this.css.widgetTitleCloseNode}).inject(this.titleNode);
  29. this.titleTextNode = new Element("div", {
  30. "styles": this.css.widgetTitleTextNode,
  31. "text": this.options.title
  32. }).inject(this.titleNode);
  33. this.contentScrollNode = new Element("div", {"styles": this.css.widgetContentScrollNode}).inject(this.node);
  34. this.contentNode = new Element("div", {"styles": this.css.widgetContentNode}).inject(this.contentScrollNode);
  35. this.setSize();
  36. this.setEvent();
  37. this.fireEvent("queryLoadContent");
  38. this.loadContent();
  39. this.fireEvent("postLoadContent");
  40. this.fireEvent("postLoad");
  41. },
  42. setSize: function(){
  43. this.node.setStyles({
  44. "height": ""+this.options.height+"px",
  45. "width": ""+this.options.width+"px",
  46. "z-index": 10
  47. });
  48. if (this.options.position.top || this.options.position.top==0) this.node.setStyle("top", ""+this.options.position.top+"px");
  49. if (this.options.position.left || this.options.position.left==0) this.node.setStyle("left", ""+this.options.position.left+"px");
  50. if (this.options.position.right || this.options.position.right==0) this.node.setStyle("right", ""+this.options.position.right+"px");
  51. if (this.options.position.bottom || this.options.position.bottom==0) this.node.setStyle("bottom", ""+this.options.position.bottom+"px");
  52. var nodeSize = this.node.getComputedSize();
  53. var titleSize = this.titleNode.getSize();
  54. var mt = this.titleNode.getStyle("margin-top").toFloat();
  55. var mb = this.titleNode.getStyle("margin-bottom").toFloat();
  56. var smt = this.contentScrollNode.getStyle("margin-top").toFloat();
  57. var smb = this.contentScrollNode.getStyle("margin-bottom").toFloat();
  58. var y = nodeSize.height-nodeSize["padding-bottom"]-nodeSize["padding-top"]-titleSize.y-mt-mb-smt-smb;
  59. this.contentScrollNode.setStyle("height", ""+y+"px");
  60. MWF.require("MWF.widget.ScrollBar", function(){
  61. new MWF.widget.ScrollBar(this.contentScrollNode, {
  62. "style":"xDesktop_Widget", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  63. "onScroll": function(y){
  64. this.fireEvent("scroll", [y]);
  65. }.bind(this)
  66. });
  67. }.bind(this));
  68. },
  69. setEvent: function(){
  70. this.node.makeDraggable({
  71. "handle": this.titleTextNode,
  72. "container": this.desktop.desktopNode,
  73. "onComplete": function(el, e){
  74. this.fireEvent("dragComplete", [el, e]);
  75. }.bind(this)
  76. });
  77. this.titleCloseNode.addEvent("click", function(){this.close();}.bind(this));
  78. this.titleOpenNode.addEvent("click", function(){this.open();}.bind(this));
  79. },
  80. close: function(){
  81. this.fireEvent("queryClose");
  82. this.node.destroy();
  83. this.fireEvent("postClose");
  84. },
  85. open: function(){
  86. this.fireEvent("open");
  87. },
  88. loadContent: function(){
  89. }
  90. });