Mask.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. o2.widget.Mask = new Class({
  4. Implements: [Options, Events],
  5. Extends: o2.widget.Common,
  6. options: {
  7. "style": "default",
  8. "zIndex": 100,
  9. "loading": true
  10. },
  11. initialize: function(options){
  12. this.setOptions(options);
  13. this.path = o2.session.path+"/widget/$Mask/";
  14. this.cssPath = o2.session.path+"/widget/$Mask/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. this._createMaskNodes();
  17. },
  18. _createMaskNodes: function(){
  19. this.container = new Element("div", {
  20. "styles": this.css.container
  21. });
  22. this.container.setStyle("z-index", this.options.zIndex);
  23. this.maskBar = new Element("iframe", {
  24. "styles": this.css.mask
  25. });
  26. this.maskBar.setStyle("z-index", this.options.zIndex);
  27. this.backgroundBar = new Element("div", {
  28. "styles": this.css.backgroundBar
  29. });
  30. this.backgroundBar.setStyle("z-index", this.options.zIndex+1);
  31. this.loadBar = new Element("div", {
  32. "styles": this.css.loadingBar,
  33. "html": "<table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr valign=\"middle\" height=\"30\"><td align=\"right\"><img src=\""+o2.session.path+"/widget/$Mask/"+this.options.style+"/loading.gif\" /></td><td align=\"center\">loading...</td></tr></table>"
  34. });
  35. this.loadBar.setStyle("z-index", this.options.zIndex+2);
  36. this.maskBar.inject(this.container);
  37. this.backgroundBar.inject(this.container);
  38. this.loadBar.inject(this.container);
  39. },
  40. hide: function(callBack){
  41. var morph = new Fx.Morph(this.container, {duration: 500});
  42. morph.start({
  43. "opacity": 0
  44. }).chain(function(){
  45. this.container.destroy();
  46. if (callBack) callBack();
  47. }.bind(this));
  48. },
  49. load: function(){
  50. if (this.fireEvent("queryLoad")){
  51. this.container.inject($(document.body));
  52. if (!this.options.loading){
  53. this.loadBar.setStyle("display", "none");
  54. }else{
  55. this.loadBar.setStyle("display", "block");
  56. //var size = $(window).getSize();
  57. var size = this.container.getSize();
  58. var tmpLeft = (size.x-120)/2;
  59. var tmpTop = (size.y-30)/2;
  60. if (tmpTop<=0) tmpTop = (window.screen.height-30)/2;
  61. this.loadBar.setStyle("left", ""+tmpLeft+"px");
  62. this.loadBar.setStyle("top", ""+tmpTop+"px");
  63. }
  64. this.fireEvent("postLoad");
  65. }
  66. },
  67. loadNode: function(node){
  68. if (this.fireEvent("queryLoad")){
  69. this.container.inject($(node));
  70. if (!this.options.loading){
  71. this.loadBar.setStyle("display", "none");
  72. }else{
  73. this.loadBar.setStyle("display", "block");
  74. var size = $(node).getSize();
  75. //var tmpLeft = (size.x-120)/2;
  76. var tmpLeft = (size.x)/2;
  77. var tmpTop = (size.y-30)/2;
  78. if (tmpTop<=0) tmpTop = (window.screen.height-30)/2-100;
  79. this.loadBar.setStyle("left", ""+tmpLeft+"px");
  80. this.loadBar.setStyle("top", ""+tmpTop+"px");
  81. }
  82. this.fireEvent("postLoad");
  83. }
  84. }
  85. });