// ViewSelector.js // Javascript Behaviour for the View Selector Control // Copyright (c) by Matthias Hertel, http://www.mathertel.de // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx // ----- // 21.08.2005 created by Matthias Hertel. // 21.05.2006 using visual effects - buttons. // 16.09.2006 context on event-methods is now set to the bound object. // 21.10.2006 persisting properties removed. use the the PropPersist AJAX Control instead. // 18.11.2006 correct reload when using the browser back. // 21.12.2007 fixing Firefox // 18.12.2007 Simplifications and documentation. jcl.ViewSelectorBehaviour = { // Properties eventname: "view", /// <summary>The local or complete event name that is used for publishing OpenAjax events.</summary> currentView: "", views: "", init: function () { var n, objs; this.eventname = jcl.BuildFullEventname(this); OpenAjax.hub.subscribe(this.eventname, this._handleEvent, this); if (! jcl.isIE) { objs = this.getElementsByTagName("A"); for (n = 0; n < objs.length; n++) if (objs[n].attributes["view"] != null) objs[n].view = objs[n].attributes["view"].value; objs = this.getElementsByTagName("SPAN"); for (n = 0; n < objs.length; n++) if (objs[n].attributes["view"] != null) objs[n].view = objs[n].attributes["view"].value; } // if }, // init afterinit: function () { // publish an initial event if none was already publish. if (this.currentView == "") { OpenAjax.hub.publish(this.eventname, this.views.split(';')[0].split(':')[0]); } // if }, // afterinit // Events onclick: function (evt) { evt = evt || window.event; var src = evt.srcElement; if ((src.tagName == "A") && (src.href.indexOf('#') > 0)) { this.select(src.href.split('#')[1]); evt.cancelBubble = true; evt.returnValue = false; } else if ((! jcl.isIE) && (src.tagName == "SPAN") && (src.attributes["view"] != null)) { this.select(src.attributes["view"].value); evt.cancelBubble = true; evt.returnValue = false; } else if ((src.tagName == "SPAN") && (src.view != null)) { this.select(src.view); evt.cancelBubble = true; evt.returnValue = false; } // if }, // onclick // Methods select: function (viewName) { OpenAjax.hub.publish(this.eventname, viewName); }, // select _handleEvent: function (prop, value) { var objs, n; if (value != this.currentView) { this.currentView = value; objs = this.getElementsByTagName("A"); for (n = 0; n < objs.length; n++) objs[n].className = ((objs[n].view == value) ? "VEButton disabled" : "VEButton"); objs = this.getElementsByTagName("SPAN"); for (n = 0; n < objs.length; n++) objs[n].className = ((objs[n].view == value) ? "VEButton selected" : "VEButton"); } // if } // _handleEvent } // jcl.ViewSelectorBehaviour
This page is part of the http://www.mathertel.de/AJAXEngine/default.aspx project. For updates and discussions see The AJAX Engine blog.
For updates and discussions see http://ajaxaspects.blogspot.com/.