Common.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. o2.widget = o2.widget || {};
  2. o2.widget.css = 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: o2.filterUrl(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. r.send();
  30. }
  31. },
  32. setLayoutStyle: function(node, classes, nodes){
  33. var styleNode = node || this.node;
  34. var elements = styleNode.getElements(".GOES");
  35. elements.each(function(item){
  36. var id = item.get("id");
  37. var styles = this.css[id];
  38. if (styles){
  39. item.setStyles(styles);
  40. }
  41. var idx = classes.indexOf(id);
  42. if (idx!=-1){
  43. this[nodes[idx]] = item;
  44. }
  45. item.removeProperty("id");
  46. }.bind(this));
  47. },
  48. setScrollBar: function(node, style, offset, callback){
  49. if (!style) style = "default";
  50. if (!offset){
  51. offset = {
  52. "V": {"x": 0, "y": 0},
  53. "H": {"x": 0, "y": 0}
  54. };
  55. };
  56. o2.require("o2.widget.ScrollBar", function(){
  57. var scrollBar = new o2.widget.ScrollBar(node, {
  58. "style": style,
  59. "offset": offset
  60. });
  61. if (callback) callback(scrollBar);
  62. });
  63. return false;
  64. }
  65. });