Common.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. o2.widget = o2.widget || {};
  2. o2.widget.css = {};
  3. o2.widget.Common = new Class({
  4. Implements: [Options, Events],
  5. options: {},
  6. initialize: function(options){
  7. this.setOptions(options);
  8. },
  9. _loadCss: function(reload){
  10. var key = encodeURIComponent(this.cssPath);
  11. if (!reload && o2.widget.css[key]){
  12. this.css = o2.widget.css[key];
  13. }else{
  14. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  15. var r = new Request.JSON({
  16. url: this.cssPath,
  17. secure: false,
  18. async: false,
  19. method: "get",
  20. noCache: false,
  21. onSuccess: function(responseJSON, responseText){
  22. this.css = responseJSON;
  23. o2.widget.css[key] = responseJSON;
  24. }.bind(this),
  25. onError: function(text, error){
  26. alert(error + text);
  27. }
  28. });
  29. // var r = new Request({
  30. // url: this.cssPath,
  31. // secure: false,
  32. // async: false,
  33. // method: "get",
  34. // noCache: false,
  35. // onSuccess: function(responseText, responseXML){
  36. // var f = eval("(function(){return function(){\n return "+responseText+"\n}})();");
  37. // this.css = f.apply(this);
  38. // o2.widget.css[key] = this.css;
  39. // }.bind(this),
  40. // onError: function(text, error){
  41. // alert(error + text);
  42. // }
  43. // });
  44. r.send();
  45. }
  46. },
  47. setLayoutStyle: function(node, classes, nodes){
  48. var styleNode = node || this.node;
  49. var elements = styleNode.getElements(".GOES");
  50. elements.each(function(item){
  51. var id = item.get("id");
  52. var styles = this.css[id];
  53. if (styles){
  54. item.setStyles(styles);
  55. }
  56. var idx = classes.indexOf(id);
  57. if (idx!=-1){
  58. this[nodes[idx]] = item;
  59. }
  60. item.removeProperty("id");
  61. }.bind(this));
  62. },
  63. setScrollBar: function(node, style, offset, callback){
  64. if (!style) style = "default";
  65. if (!offset){
  66. offset = {
  67. "V": {"x": 0, "y": 0},
  68. "H": {"x": 0, "y": 0}
  69. };
  70. };
  71. o2.require("o2.widget.ScrollBar", function(){
  72. new o2.widget.ScrollBar(node, {
  73. "style": style,
  74. "offset": offset
  75. });
  76. if (callback) callback();
  77. });
  78. return false;
  79. }
  80. });