Mask.js 3.3 KB

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