SimpleToolbar.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. o2.widget.SimpleToolbar = new Class({
  2. Extends: o2.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default"
  6. },
  7. initialize: function(container, options, bindObject){
  8. this.setOptions(options);
  9. this.bindObject = bindObject;
  10. this.items = [];
  11. this.children = [];
  12. this.childrenButton = [];
  13. this.childrenMenu = [];
  14. this.path = o2.session.path+"/widget/$SimpleToolbar/";
  15. this.cssPath = o2.session.path+"/widget/$SimpleToolbar/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.node = $(container);
  18. this.node.onselectstart = function (){return false;};
  19. this.node.oncontextmenu = function (){return false;};
  20. },
  21. load: function(){
  22. if (this.fireEvent("queryLoad")){
  23. this.node.set("styles", this.css.container);
  24. this._loadToolbarItemNode();
  25. this._loadToolbarItems();
  26. this.fireEvent("postLoad");
  27. }
  28. },
  29. _loadToolbarItemNode: function(){
  30. var subNodes = this.node.getChildren();
  31. subNodes.each(function(node, idx){
  32. var type = node.get("MWFnodetype");
  33. if (type){
  34. if (typeOf(this[type])=="array"){
  35. this[type].push(node);
  36. }else{
  37. this[type] = [];
  38. this[type].push(node);
  39. }
  40. }
  41. }.bind(this));
  42. },
  43. _loadToolbarItems: function(){
  44. //this._loadToolBarSeparator(this.MWFToolBarSeparator);
  45. this._loadToolBarButton(this.MWFToolBarButton);
  46. //this._loadToolBarMenu(this.MWFToolBarMenu);
  47. },
  48. _loadToolBarButton: function(nodes){
  49. if (nodes) {
  50. nodes.each(function(node, idx){
  51. var btn = new o2.widget.SimpleToolbarButton(node, this, this.options);
  52. btn.load();
  53. this.fireEvent("buttonLoad", [btn]);
  54. if (btn.buttonID){
  55. this.items[btn.buttonID] = btn;
  56. }
  57. this.children.push(btn);
  58. this.childrenButton.push(btn);
  59. }.bind(this));
  60. }
  61. }
  62. });
  63. o2.widget.SimpleToolbarButton = new Class({
  64. Implements: [Options, Events],
  65. options: {
  66. "text": "",
  67. "title": "",
  68. "pic": "",
  69. "pic_over": "",
  70. "action": "",
  71. "actionScript": "",
  72. "disable": false
  73. },
  74. initialize: function(node, toolbar, options){
  75. this.setOptions(options);
  76. this.node = $(node);
  77. this.toolbar = toolbar;
  78. this.buttonID = this.node.MWFnodeid || this.node.id;
  79. if (!this.node){
  80. this.node = new Element("div").inject(this.toolbar.node);
  81. }else{
  82. var buttonText = this.node.get("MWFButtonText");
  83. if (buttonText) this.options.text = buttonText;
  84. var title = this.node.get("title");
  85. if (title) this.options.title = title;
  86. var buttonImage = this.node.get("MWFButtonImage");
  87. if (buttonImage) this.options.pic = buttonImage;
  88. var buttonImageOver = this.node.get("MWFButtonImageOver");
  89. if (buttonImageOver) this.options.pic_over = buttonImageOver;
  90. var buttonDisable = this.node.get("MWFButtonDisable");
  91. if (buttonDisable) this.options.disable = true;
  92. var buttonAction = this.node.get("MWFButtonAction");
  93. if (buttonAction) this.options.action = buttonAction;
  94. //var buttonActionScript = this.node.get("MWFButtonActionScript");
  95. //if (buttonActionScript) this.options.actionScript = buttonActionScript;
  96. }
  97. this.modifiyStyle = true;
  98. },
  99. load: function(){
  100. this._addButtonEvent();
  101. this.node.title = this.options.title;
  102. this.node.set("styles", this.toolbar.css.button);
  103. if (this.options.pic) this.picNode = this._createImageNode(this.options.pic);
  104. if (this.options.text) this.textNode = this._createTextNode(this.options.text);
  105. this.setDisable(this.options.disable);
  106. },
  107. enable: function(){
  108. if (this.options.disable){
  109. this.setDisable(false);
  110. this.options.disable = false;
  111. }
  112. },
  113. disable: function(){
  114. if (!this.options.disable){
  115. this.setDisable(true);
  116. this.options.disable = true;
  117. }
  118. },
  119. setDisable: function(flag){
  120. if (flag){
  121. this.node.set("styles", this.toolbar.css.buttonDisable);
  122. if (this.picNode){
  123. this.picNode.set("styles", this.toolbar.css.buttonImgDivDisable);
  124. var img = this.picNode.getElement("img");
  125. var src = img.get("src");
  126. var ext = src.substr(src.lastIndexOf("."), src.length);
  127. src = src.substr(0, src.lastIndexOf("."));
  128. src = src+"_gray"+ext;
  129. this.src_gray = src;
  130. img.set("src", src);
  131. }
  132. if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDivDisable);
  133. }else{
  134. this.node.set("styles", this.toolbar.css.button);
  135. if (this.picNode){
  136. this.picNode.set("styles", this.toolbar.css.buttonImgDiv);
  137. var img = this.picNode.getElement("img");
  138. var src = img.get("src");
  139. src = src.replace("_gray", "");
  140. this.src_gray = src;
  141. img.set("src", src);
  142. }
  143. if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDiv);
  144. }
  145. },
  146. _createImageNode: function(src){
  147. if (src){
  148. var div = new Element("span", {"styles": this.toolbar.css.buttonImgDiv}).inject(this.node);
  149. var img = this.img = new Element("img", {
  150. "styles": this.toolbar.css.buttonImg,
  151. "src": src
  152. }).inject(div);
  153. return div;
  154. }else{
  155. return null;
  156. }
  157. },
  158. _createTextNode: function(text){
  159. if (text){
  160. var div = new Element("span", {
  161. "styles": this.toolbar.css.buttonTextDiv,
  162. "text": text
  163. }).inject(this.node);
  164. return div;
  165. }else{
  166. return null;
  167. }
  168. },
  169. _addButtonEvent: function(){
  170. this.node.addEvent("mouseover", this._buttonMouseOver.bind(this));
  171. this.node.addEvent("mouseout", this._buttonMouseOut.bind(this));
  172. this.node.addEvent("mousedown", this._buttonMouseDown.bind(this));
  173. this.node.addEvent("mouseup", this._buttonMouseUp.bind(this));
  174. this.node.addEvent("click", this._buttonClick.bind(this));
  175. },
  176. _buttonMouseOver: function(){
  177. if (this.modifiyStyle) if (!this.options.disable){
  178. if(this.options.pic_over)this.img.set("src",this.options.pic_over)
  179. this.node.set("styles", this.toolbar.css.buttonOver);
  180. };
  181. },
  182. _buttonMouseOut: function(){
  183. if (this.modifiyStyle) if (!this.options.disable){
  184. this.img.set("src",this.options.pic)
  185. this.node.set("styles", this.toolbar.css.buttonOut);
  186. };
  187. },
  188. _buttonMouseDown: function(){
  189. if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonDown);};
  190. },
  191. _buttonMouseUp: function(){
  192. if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonUp);};
  193. },
  194. _buttonClick: function(e){
  195. if (!this.options.disable){
  196. if (this.options.action){
  197. var tmparr = this.options.action.split(":");
  198. var action = tmparr.shift();
  199. var bindObj = (this.toolbar.bindObject) ? this.toolbar.bindObject : window;
  200. if (bindObj[action]){
  201. tmparr.push(this);
  202. tmparr.push(e);
  203. bindObj[action].apply(bindObj,tmparr);
  204. }else{
  205. if (window[action]){
  206. window[action].apply(this,tmparr);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. });