Mask.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. "progress": false,
  11. "html": ""
  12. },
  13. initialize: function(options){
  14. this.setOptions(options);
  15. this.path = o2.session.path+"/widget/$Mask/";
  16. this.cssPath = o2.session.path+"/widget/$Mask/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this._createMaskNodes();
  19. },
  20. _createMaskNodes: function(){
  21. this.container = new Element("div", {
  22. "styles": this.css.container
  23. });
  24. this.container.setStyle("z-index", this.options.zIndex);
  25. this.maskBar = new Element("iframe", {
  26. "styles": this.css.mask
  27. });
  28. this.maskBar.setStyle("z-index", this.options.zIndex);
  29. this.backgroundBar = new Element("div", {
  30. "styles": this.css.backgroundBar
  31. });
  32. this.backgroundBar.setStyle("z-index", this.options.zIndex+1);
  33. this.maskBar.inject(this.container);
  34. this.backgroundBar.inject(this.container);
  35. if (this.options.loading){
  36. this.loadBar = new Element("div", {
  37. "styles": this.css.loadingBar,
  38. "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\">"+
  39. ( this.options.html ? this.options.html : "loading..." ) +
  40. "</td></tr></table>"
  41. });
  42. this.loadBar.setStyle("z-index", this.options.zIndex+2);
  43. this.loadBar.inject(this.container);
  44. }
  45. if (this.options.progress){
  46. this.progressNode = new Element("div", {"styles": this.css.progressNode}).inject(this.container);
  47. this.progressNode.setStyle("z-index", this.options.zIndex+2);
  48. }
  49. },
  50. hide: function(callBack){
  51. var morph = new Fx.Morph(this.container, {duration: 500});
  52. morph.start({
  53. "opacity": 0
  54. }).chain(function(){
  55. this.container.destroy();
  56. if (callBack) callBack();
  57. }.bind(this));
  58. },
  59. load: function(){
  60. if (this.fireEvent("queryLoad")){
  61. this.container.inject($(document.body));
  62. if (!this.options.loading){
  63. if (this.loadBar) this.loadBar.setStyle("display", "none");
  64. }else{
  65. this.loadBar.setStyle("display", "block");
  66. //var size = $(window).getSize();
  67. var size = this.container.getSize();
  68. var tmpLeft = (size.x-120)/2;
  69. if( tmpLeft<0 )tmpLeft = 0;
  70. var tmpTop = (size.y-30)/2;
  71. if (tmpTop<=0) tmpTop = (window.screen.height-30)/2;
  72. this.loadBar.setStyle("left", ""+tmpLeft+"px");
  73. this.loadBar.setStyle("top", ""+tmpTop+"px");
  74. }
  75. this.fireEvent("postLoad");
  76. }
  77. },
  78. loadNode: function(node){
  79. if (this.fireEvent("queryLoad")){
  80. this.container.inject($(node));
  81. if (!this.options.loading){
  82. if (this.loadBar) this.loadBar.setStyle("display", "none");
  83. }else{
  84. this.loadBar.setStyle("display", "block");
  85. var size = $(node).getSize();
  86. var tmpLeft = (size.x-120)/2;
  87. if( tmpLeft<0 )tmpLeft = 0;
  88. //var tmpLeft = (size.x)/2;
  89. var tmpTop = (size.y-30)/2;
  90. if (tmpTop<=0) tmpTop = (window.screen.height-30)/2-100;
  91. this.loadBar.setStyle("left", ""+tmpLeft+"px");
  92. this.loadBar.setStyle("top", ""+tmpTop+"px");
  93. }
  94. this.fireEvent("postLoad");
  95. }
  96. }
  97. });