Widget.js 2.9 KB

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