Widget.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. MWF.require("MWF.xDesktop.Widget", null, false);
  2. MWF.xApplication.Common.Widget = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "appName": "Common",
  8. "name": "Widget",
  9. "width": "400",
  10. "height": "400",
  11. "position": {"right": 10, "bottom": 10}
  12. },
  13. initialize: function(desktop, options){
  14. this.setOptions(options);
  15. this.desktop = desktop;
  16. this.path = "/x_component_"+this.options.appName.replace(/\./g, "_")+"/$"+this.options.name.replace(/\./g, "/")+"/";
  17. this.cssPath = this.path+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. },
  20. fireAppEvent: function(when){
  21. this.fireEvent(when);
  22. if (this[("on-"+when).camelCase()]) this[("on-"+when).camelCase()]();
  23. },
  24. load : function(isCurrent){
  25. this.fireAppEvent("queryLoad");
  26. this.loadWidget();
  27. },
  28. loadContent: function(callback){
  29. if (callback) callback();
  30. },
  31. loadWidget: function(){
  32. this.fireAppEvent("queryLoadWidget");
  33. var options = {
  34. "title": this.options.title,
  35. "width": this.options.width,
  36. "height": this.options.height,
  37. "position": this.options.position,
  38. "onQueryClose": function(){
  39. this.fireAppEvent("rueryClose");
  40. }.bind(this),
  41. "onPostClose": function(){
  42. this.desktop.closeWidget(this);
  43. this.fireAppEvent("postClose");
  44. }.bind(this),
  45. "onScroll": function(y){
  46. this.fireEvent("scroll", [y]);
  47. }.bind(this),
  48. "onOpen": function(e){
  49. this.openApplication(e);
  50. }.bind(this),
  51. "onDragComplete": function(el, e){
  52. this.fireEvent("dragComplete", [el, e]);
  53. }.bind(this)
  54. };
  55. this.widget = new MWF.xDesktop.Widget(this.desktop, options);
  56. this.fireAppEvent("loadWidget");
  57. this.widget.load();
  58. this.fireAppEvent("postLoadWidget");
  59. this.fireAppEvent("queryLoadContent");
  60. this.content = this.widget.contentNode;
  61. this.loadContent(function(){
  62. this.fireAppEvent("postLoadContent");
  63. }.bind(this));
  64. this.fireAppEvent("postLoad");
  65. },
  66. openApplication: function(e){
  67. this.desktop.openApplication(e, this.options.appName);
  68. },
  69. //widget事件
  70. onQueryLoad: function(){},
  71. onQueryLoadWidget: function(){},
  72. onLoadWidget: function(){},
  73. onPostLoadWidget: function(){},
  74. onQueryLoadContent: function(){},
  75. onPostLoadContent: function(){},
  76. onPostLoad: function(){},
  77. onQueryClose: function(){},
  78. onPostClose: function(){}
  79. });