123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- o2.widget = o2.widget || {};
- o2.widget.Toolbar = new Class({
- Implements: [Options, Events],
- Extends: o2.widget.Common,
- options: {
- "style": "default"
- },
- initialize: function(container, options, bindObject){
- this.setOptions(options);
- this.bindObject = bindObject;
- this.items = {};
- this.children = [];
- this.childrenButton = [];
- this.childrenMenu = [];
- this.path = o2.session.path+"/widget/$Toolbar/";
- this.cssPath = o2.session.path+"/widget/$Toolbar/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.node = $(container);
- this.node.onselectstart = function (){return false;};
- this.node.oncontextmenu = function (){return false;};
- },
- load: function(){
- if (this.fireEvent("queryLoad")){
- this.node.set("styles", this.css.container);
- this._loadToolbarItemNode();
- this._loadToolbarItems();
- this.fireEvent("postLoad");
- }
- },
- _loadToolbarItemNode: function(){
- var subNodes = this.node.getChildren();
- subNodes.each(function(node, idx){
- var type = node.get("MWFnodetype");
- if (type){
- if (typeOf(this[type])=="array"){
- this[type].push(node);
- }else{
- this[type] = [];
- this[type].push(node);
- }
- }
- }.bind(this));
- },
- _loadToolbarItems: function(){
- this._loadToolBarSeparator(this.MWFToolBarSeparator);
- this._loadToolBarButton(this.MWFToolBarButton);
- this._loadToolBarOnOffButton(this.MWFToolBarOnOffButton);
- this._loadToolBarMenu(this.MWFToolBarMenu);
- },
- _loadToolBarSeparator: function(nodes){
- if (nodes) {
- nodes.each(function(node, idx){
- node.set("styles", this.css.toolbarSeparator);
- }.bind(this));
- }
- },
- _loadToolBarButton: function(nodes){
- if (nodes) {
- nodes.each(function(node, idx){
- var btn = new o2.widget.ToolbarButton(node, this, this.options);
- btn.load();
- this.fireEvent("buttonLoad", [btn]);
- if (btn.buttonID){
- this.items[btn.buttonID] = btn;
- }
- this.children.push(btn);
- this.childrenButton.push(btn);
- }.bind(this));
- }
- },
- _loadToolBarOnOffButton: function(nodes){
- if (nodes) {
- nodes.each(function(node, idx){
- var btn = new o2.widget.ToolbarOnOffButton(node, this, this.options);
- btn.load();
- this.fireEvent("buttonLoad", [btn]);
- if (btn.buttonID){
- this.items[btn.buttonID] = btn;
- }
- this.children.push(btn);
- this.childrenButton.push(btn);
- }.bind(this));
- }
- },
- _loadToolBarMenu: function(nodes){
- var _self = this;
- if (nodes) {
- nodes.each(function(node, idx){
- var btn = new o2.widget.ToolbarMenu(node, this, {
- "onAddMenuItem": function(item){
- this.fireEvent("addMenuItem", [item]);
- }.bind(this),
- "onMenuQueryShow": function(menu){
- _self.fireEvent("menuQueryShow", [this, menu]);
- },
- "onMenuPostShow": function(menu){
- _self.fireEvent("menuPostShow", [this, menu]);
- },
- "onMenuQueryHide": function(menu){
- _self.fireEvent("menuQueryHide", [this, menu]);
- },
- "onMenuPostHide": function(menu){
- _self.fireEvent("menuPostHide", [this, menu]);
- },
- "onLoad": function(menu){
- _self.fireEvent("menuLoaded", [this, menu]);
- }
- });
- btn.load();
- this.fireEvent("menuLoad", [btn]);
- if (btn.buttonID){
- this.items[btn.buttonID] = btn;
- }
- this.children.push(btn);
- this.childrenMenu.push(btn);
- }.bind(this));
- }
- }
- });
- o2.widget.ToolbarButton = new Class({
- Implements: [Options, Events],
- options: {
- "text": "",
- "title": "",
- "pic": "",
- "action": "",
- "actionScript": "",
- "disable": false,
- "hide": false
- },
- initialize: function(node, toolbar, options){
- this.setOptions(options);
- this.node = $(node);
- this.toolbar = toolbar;
- this.buttonID = this.node.get("MWFnodeid") || this.node.get("id");
- if (!this.node){
- this.node = new Element("div").inject(this.toolbar.node);
- }else{
- var buttonText = this.node.get("MWFButtonText");
- if (buttonText) this.options.text = buttonText;
-
- var title = this.node.get("title");
- if (title) this.options.title = title;
-
- var buttonImage = this.node.get("MWFButtonImage");
- if (buttonImage) this.options.pic = buttonImage;
- var buttonImageOver = this.node.get("MWFButtonImageOver");
- if (buttonImageOver) this.options.pic_over = buttonImageOver;
- var buttonDisable = this.node.get("MWFButtonDisable");
- if (buttonDisable) this.options.disable = true;
-
- var buttonAction = this.node.get("MWFButtonAction");
- if (buttonAction) this.options.action = buttonAction;
- var buttonHide = this.node.get("MWFHide");
- this.options.hide = !!buttonHide;
- //var buttonActionScript = this.node.get("MWFButtonActionScript");
- //if (buttonActionScript) this.options.actionScript = buttonActionScript;
- }
- this.modifiyStyle = true;
- },
- load: function(){
- this._addButtonEvent();
- this.node.title = this.options.title;
- this.node.set("styles", this.toolbar.css.button);
- if (this.options.pic) this.picNode = this._createImageNode(this.options.pic);
- if (this.options.text) this.textNode = this._createTextNode(this.options.text);
- this.setDisable(this.options.disable);
- this.setHide(this.options.hide);
- },
- hide: function(){
- this.node.hide();
- this.options.hide = true;
- },
- show: function(){
- this.node.show();
- this.options.hide = false;
- },
- setHide: function(flag){
- if (flag){
- this.hide();
- }else{
- this.show();
- }
- },
- enable: function(){
- if (this.options.disable){
- this.setDisable(false);
- this.options.disable = false;
- }
- },
- disable: function(){
- if (!this.options.disable){
- this.setDisable(true);
- this.options.disable = true;
- }
- },
- setDisable: function(flag){
- if (flag){
- if (!this.options.disable){
- this.options.disable = true;
- this.node.set("styles", this.toolbar.css.buttonDisable);
- if (this.picNode){
- this.picNode.set("styles", this.toolbar.css.buttonImgDivDisable);
- var img = this.picNode.getElement("img");
- var src = img.get("src");
- var ext = src.substr(src.lastIndexOf("."), src.length);
- src = src.substr(0, src.lastIndexOf("."));
- src = src+"_gray"+ext;
- img.set("src", src);
- }
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDivDisable);
- }
- }else{
- if (this.options.disable){
- this.options.disable = false;
- this.node.set("styles", this.toolbar.css.button);
- if (this.picNode){
- this.picNode.set("styles", this.toolbar.css.buttonImgDiv);
- var img = this.picNode.getElement("img");
- var src = img.get("src");
- src = src.replace("_gray", "");
- img.set("src", src);
- }
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDiv);
- }
- }
- },
- _createImageNode: function(src){
- if (src){
- var div = new Element("span", {"styles": this.toolbar.css.buttonImgDiv}).inject(this.node);
- var img = this.imgNode = new Element("img", {
- "styles": this.toolbar.css.buttonImg,
- "src": src
- }).inject(div);
- return div;
- }else{
- return null;
- }
- },
- _createTextNode: function(text){
- if (text){
- var div = new Element("span", {
- "styles": this.toolbar.css.buttonTextDiv,
- "text": text
- }).inject(this.node);
- return div;
- }else{
- return null;
- }
- },
- setText: function(text){
- this.node.getLast().set("text", text);
- },
- _addButtonEvent: function(){
- this.node.addEvent("mouseover", this._buttonMouseOver.bind(this));
- this.node.addEvent("mouseout", this._buttonMouseOut.bind(this));
- this.node.addEvent("mousedown", this._buttonMouseDown.bind(this));
- this.node.addEvent("mouseup", this._buttonMouseUp.bind(this));
- this.node.addEvent("click", this._buttonClick.bind(this));
- },
- _buttonMouseOver: function(){
- if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonOver);};
- if( this.options.pic_over )if (!this.options.disable && this.imgNode){this.imgNode.set("src", this.options.pic_over);};
- },
- _buttonMouseOut: function(){
- if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonOut);};
- if( this.options.pic_over )if (!this.options.disable && this.imgNode){this.imgNode.set("src", this.options.pic);};
- },
- _buttonMouseDown: function(){
- if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonDown);};
- },
- _buttonMouseUp: function(){
- if (this.modifiyStyle) if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonUp);};
- },
- _buttonClick: function(e){
- if (!this.options.disable){
- if (this.options.action){
- if (typeOf(this.options.action)==="string"){
- var tmparr = this.options.action.split(":");
- var action = tmparr.shift();
- var bindObj = (this.toolbar.bindObject) ? this.toolbar.bindObject : window;
- if (bindObj[action]){
- tmparr.push(this);
- tmparr.push(e);
- bindObj[action].apply(bindObj,tmparr);
- }else{
- if (window[action]){
- window[action].apply(this,tmparr);
- }
- }
- }else{
- this.options.action();
- }
- }
- }
- }
- });
- o2.widget.ToolbarOnOffButton = new Class({
- Implements: [Options, Events],
- Extends: o2.widget.ToolbarButton,
- on: function(){
- if (this.status !== "on"){
- if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonDown);}
- this.modifiyStyle = false;
- this.status = "on";
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDivDown);
- }
- },
- off: function(){
- if (this.status === "on"){
- if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonOut);}
- this.modifiyStyle = true;
- this.status = "off";
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDiv);
- }
- },
- _buttonClick: function(e){
- if (this.status === "on"){
- if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonOut);}
- this.modifiyStyle = true;
- this.status = "off";
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDiv);
- }else{
- if (!this.options.disable){this.node.set("styles", this.toolbar.css.buttonDown);}
- this.modifiyStyle = false;
- this.status = "on";
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDivDown);
- }
- if (!this.options.disable){
- if (this.options.action){
- if (typeOf(this.options.action)==="string"){
- var tmparr = this.options.action.split(":");
- var action = tmparr.shift();
- var bindObj = (this.toolbar.bindObject) ? this.toolbar.bindObject : window;
- tmparr.push(this.status);
- tmparr.push(this);
- if (bindObj[action]){
- tmparr.push(this);
- tmparr.push(e);
- bindObj[action].apply(bindObj,tmparr);
- }else{
- if (window[action]){
- window[action].apply(this,tmparr);
- }
- }
- }else{
- this.options.action();
- }
- }
- }
- }
- });
- o2.widget.ToolbarMenu = new Class({
- Implements: [Options, Events],
- Extends: o2.widget.ToolbarButton,
- initialize: function(node, toolbar, options){
- this.parent(node, toolbar, options);
- this.modifiyStyle = true;
- this.menu = null;
- this.buttonID = this.node.get("MWFnodeid") || this.node.get("id");
- },
- setDisable: function(flag){
- if (this.menu) this.menu.options.disable = flag;
- if (flag){
- this.node.set("styles", this.toolbar.css.buttonDisable);
- if (this.picNode){
- this.picNode.set("styles", this.toolbar.css.buttonImgDivDisable);
- var img = this.picNode.getElement("img");
- var src = img.get("src");
-
- var ext = src.substr(src.lastIndexOf("."), src.length);
- src = src.substr(0, src.lastIndexOf("."));
- src = src+"_gray"+ext;
-
- // src = src.substr(0, src.lastIndexOf("."));
- // src = src+"_gray.gif";
- img.set("src", src);
- }
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDivDisable);
- }else{
- this.node.set("styles", this.toolbar.css.button);
- if (this.picNode){
- this.picNode.set("styles", this.toolbar.css.buttonImgDiv);
- var img = this.picNode.getElement("img");
- var src = img.get("src");
- src = src.replace("_gray", "");
- img.set("src", src);
- }
- if (this.textNode) this.textNode.set("styles", this.toolbar.css.buttonTextDiv);
- }
- },
- load: function(){
- this._addButtonEvent();
- this.node.title = this.options.title;
- this.node.set("styles", this.toolbar.css.button);
- if (this.options.pic) this.picNode = this._createImageNode(this.options.pic);
- if (this.options.text) this.textNode = this._createTextNode(this.options.text);
-
- this._createDownNode();
- var toolbarMenu = this;
- o2.require("o2.widget.Menu", function(){
- this.menu = new o2.widget.Menu(this.node, {
- "style": this.toolbar.options.style,
- "bindObject": this.options.bindObject,
- "event": "click",
- "disable": toolbarMenu.options.disable,
- "onQueryShow": function(){
- var p = toolbarMenu.node.getPosition(toolbarMenu.node.getOffsetParent());
- var s = toolbarMenu.node.getSize();
- this.setOptions({
- "top": p.y+s.y-2,
- "left": p.x
- });
- toolbarMenu.fireEvent("menuQueryShow", [this]);
- return true;
- },
- "onPostShow": function(){
- var p = toolbarMenu.node.getPosition(toolbarMenu.node.getOffsetParent());
- var s = toolbarMenu.node.getSize();
- toolbarMenu.node.set("styles", {
- "background-color": this.node.getStyle("background-color"),
- "border-top": this.node.getStyle("border-top"),
- "border-right": this.node.getStyle("border-top"),
- "border-left": this.node.getStyle("border-top"),
- "border-bottom": "0"
- });
- toolbarMenu.modifiyStyle = false;
- toolbarMenu.tmpStyleNode = new Element("div.MWFtmpStyleNode",{
- "styles":{
- "position":"absolute",
- "top": p.y+s.y-2,
- "left": p.x+1,
- "width": s.x-2,
- "z-index": this.node.getStyle("z-index")+1,
- "background-color": this.node.getStyle("background-color"),
- "height": "1px",
- "overflow": "hidden"
- }
- }).inject(toolbarMenu.node);
- toolbarMenu.fireEvent("menuPostShow", [this]);
- },
- "onQueryHide": function(){
- toolbarMenu.fireEvent("menuQueryHide", [this]);
- },
- "onPostHide": function(){
- toolbarMenu.node.set("styles", toolbarMenu.toolbar.css.button);
- toolbarMenu.modifiyStyle = true;
- if (toolbarMenu.tmpStyleNode) toolbarMenu.tmpStyleNode.destroy();
- toolbarMenu.fireEvent("menuPostHide", [this]);
- }
- });
- this.menu.load();
- this.fireEvent("load", [this.menu]);
- this.addMenuItems();
- }.bind(this));
- this.setDisable(this.options.disable);
- },
- _createDownNode: function(){
- var spanNode = new Element("div",{
- "styles": this.toolbar.css.toolbarButtonDownNode
- }).inject(this.node);
- spanNode.set("html", "<img src=\""+o2.session.path+"/widget/$Toolbar/"+this.toolbar.options.style+"/downicon.gif"+"\" />");
- return spanNode;
- },
- addMenuItems: function(){
- var els = this.node.getChildren();
- els.each(function(node, idx){
- var type = node.get("MWFnodetype");
- if (type=="MWFToolBarMenuItem"){
- this._loadMenuItem(node);
- }
- if (type=="MWFToolBarMenuLine"){
- this._loadMenuLine(node);
- }
- }.bind(this));
- },
- _loadMenuItem: function(node){
- var toolBarMenu = this;
- var item = this.menu.addMenuItem(node.get("MWFButtonText"),"click",function(e){toolBarMenu._menuItemClick(node.get("MWFButtonAction"), e, this);}, node.get("MWFButtonImage"), node.get("MWFButtonDisable"));
- this.fireEvent("addMenuItem", [item]);
- },
- _menuItemClick: function(itemAction, e, item){
- if (itemAction){
- var tmparr = itemAction.split(":");
- var action = tmparr.shift();
- var bindObj = (this.toolbar.bindObject) ? this.toolbar.bindObject : window;
- if (bindObj[action]){
- tmparr.push(this);
- tmparr.push(e);
- tmparr.push(item);
- bindObj[action].apply(bindObj,tmparr);
- this.menu.hideMenu();
- }else{
- if (window[action]){
- window[action].apply(this,tmparr);
- this.menu.hideMenu();
- }
- }
- }
- },
- _loadMenuLine: function(){
- this.menu.addMenuLine();
- }
- });
|