You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2007/03/22 22:55:51 UTC
svn commit: r521513 - in /incubator/xap/trunk/codebase/src/xap/bridges:
basic/AbstractWidgetBridge.js xap/LabelBridge.js
Author: mturyn
Date: Thu Mar 22 15:55:50 2007
New Revision: 521513
URL: http://svn.apache.org/viewvc?view=rev&rev=521513
Log:
Added machinery for "class" attribute. Relatively simple, [add|remove]StyleState must do what it previously did with the
default style (e.g. "xapRadioButton") with a list of other style classes.
The only complication is for Label and decendant classes: their substructure requires that we do things to
both the "root" dom node and the "contents" node...we should generalise this and put the necessary machinery
in AbstractWidgetBridge.
Modified:
incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js
incubator/xap/trunk/codebase/src/xap/bridges/xap/LabelBridge.js
Modified: incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js?view=diff&rev=521513&r1=521512&r2=521513
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/basic/AbstractWidgetBridge.js Thu Mar 22 15:55:50 2007
@@ -113,15 +113,31 @@
} //If we needed to initialise the maps.==first use of this bridge class in session
this.createPeer();
-
+
+
+ // Create the array of class name stubs
+ // that will be used to locate classes
+ // appropriate to specific events, so
+ // a mouse-over on a widget associated
+ // with tagname "myTag" and specified
+ // class "aSpecialClass" will add the
+ // classes "myTagMouseOVer" and "aSpecialClassMouseOver"
+ this.setStyleClassNames( new Array(0) );
if (this.getRootDomNode() && this.getCssStyleName()){
- dojo.html.addClass(this.getRootDomNode(),this.getCssStyleName());
+ // This is the base style class for this tag,
+ // e.g. "xapRadioButton":
+ this.setClassAttribute( this.getCssStyleName() ) ;
+
+ // Additional classes can be added with the
+ // "class" attribute, a list of space-separated
+ // strings; this would also be handled via
+ // "setClassAttribute", which will be called
+ // as a consequence of
+ // this.parseInitialAttributes() below:
}
this.parseInitialAttributes( this.getElement() );
this.parseInitialChildren( this.getElement() );
xap.taghandling.AbstractTagImpl.prototype.init.call( this );
-
-
}
xap.bridges.basic.AbstractWidgetBridge.prototype.unload = function() {
@@ -282,21 +298,75 @@
return null;
}
+xap.bridges.basic.AbstractWidgetBridge.prototype.getStyleClassNames = function(){
+ return this._styleClassNames ;
+}
+xap.bridges.basic.AbstractWidgetBridge.prototype.setStyleClassNames = function(aStringArray){
+ this._styleClassNames = aStringArray ;
+}
+
xap.bridges.basic.AbstractWidgetBridge.prototype.getCssStyleName = function(){
+ // This result should be normally be cached as the first element
+ // in the array backing up this.getStyleClassNames(), "this._styleClassNames"
+ // as of this writing:
var nodeName = this.getElement().nodeName;
return "xap" + nodeName.substring(0,1).toUpperCase() + nodeName.substring(1);
- //TODO cache this?
}
-xap.bridges.basic.AbstractWidgetBridge.prototype.addStyleState = function( stateName ){
- if (this.getRootDomNode() && this.getCssStyleName()){
- dojo.html.addClass(this.getRootDomNode(),this.getCssStyleName() + stateName);
+/**
+ * @param nodeName{string} If given, turns a class name like
+ * "xapFooMouseOver" into "xapFooHeaderMouseOver":
+ *
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.addStyleState = function( pStateName, pNode,pNodeLabel ){
+ var node = pNode ;
+ if( !pNode ){
+ node = this.getRootDomNode() ;
+ }
+
+ var nodeLabel = pNodeLabel ;
+ if( !pNodeLabel ){
+ nodeLabel = "" ;
+ }
+ var classNameStubs = this.getStyleClassNames() ;
+ if (this.getRootDomNode() && classNameStubs){
+ for( var ii=0; ii<classNameStubs.length; ++ii){
+ // For example:
+ // "xapButton" + "Contents"+"MouseOver"
+ // or
+ // "xapButton" + ""+"MouseOver"
+ dojo.html.addClass(
+ node,
+ classNameStubs[ii]+nodeLabel + pStateName);
+ }
}
}
-xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleState = function( stateName ){
- if (this.getRootDomNode() && this.getCssStyleName()){
- dojo.html.removeClass(this.getRootDomNode(),this.getCssStyleName() + stateName);
+/**
+ * @param nodeName{string} If given, turns a class name like
+ * "xapFooMouseOver" into "xapFooHeaderMouseOver":
+ *
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleState = function( pStateName, pNode,pNodeLabel ){
+ var node = pNode ;
+ if( !pNode ){
+ node = this.getRootDomNode() ;
+ }
+ var nodeName = pNodeLabel ;
+ if( !pNodeLabel ){
+ nodeLabel = "" ;
+ }
+ var classNameStubs = this.getStyleClassNames() ;
+ if (this.getRootDomNode() && classNameStubs){
+ for( var ii=0; ii<classNameStubs.length; ++ii){
+ // For example:
+ // "xapButton" + "Contents"+"MouseOver"
+ // or
+ // "xapButton" + ""+"MouseOver"
+ dojo.html.removeClass(
+ node,
+ classNameStubs[ii]+nodeLabel + pStateName);
+ }
}
}
@@ -428,7 +498,9 @@
* Automatically glue all the peer's "onX..." events to
* a method on the bridge that runs our fireEvent("onX...");
* preference a particular, generally widget-specific method,
- * to our own "onCommand".
+ * to our own "onCommand". Generally not used these days, but
+ * a reasonable quick-and-dirty way of implementing a bridge's
+ * connections, so suitable for one-offs:
**/
xap.bridges.basic.AbstractWidgetBridge.prototype.autoAttachBridgeEventsToPeerEvents = function(){
@@ -529,7 +601,7 @@
}
xap.bridges.basic.AbstractWidgetBridge.prototype.initialiseAttributeMaps = function(){
- // Initialise the default name-to[gs]etter map used under attributeSet:
+ // Initialise the default name-to[gs]etter map used under attributeSet:
//TODO is this once per object? or once per class?
this.constructor._nameToSetterMap = new Object() ;
@@ -546,7 +618,7 @@
}
xap.bridges.basic.AbstractWidgetBridge.prototype.getNewAllowedAttributes = function(){
- return ["x","y","width","height","backgroundColor",
+ return ["x","y","width","height","backgroundColor","class",
"borderWidth","borderColor","borderStyle","margin",
"padding","color","textDecoration","fontFamily",
"fontStyle","fontWeight", "fontSize", "textAlign",
@@ -585,9 +657,10 @@
if (this._oldDisplay){
rootNode.style.display = this._oldDisplay;
delete this.oldDisplay;
+ } else {
+ //otherwise just do the best we can
+ rootNode.style.display = "";
}
- //otherwise just do the best we can
- else rootNode.style.display = "";
}
}
}
@@ -773,6 +846,84 @@
}
}
+
+/**
+ * Adds one or more base classes to the list of classes to apply to
+ * the widget['s root dom node]. These are used for base styles, and also
+ * to create lookups for other styles, so a mouse hovering over a
+ * widget with styles "baseFoo myFoo" will get "baseFooMouseOver" and
+ * "myFooMouseOver" applied.
+ * @param pClassStr{string} one or more base class names, space-separated
+ * if more than one.
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.addClassAttribute = function( pClassStr ){
+ // Allow users to be sloppy---multiple and/or leading and/or trailing
+ // spaces are allowed:
+ var classStr = pClassStr.replace(/^\s+|\s+$/,"").replace(/\s+/," ") ;
+ var arrClassStr = classStr.split(" ") ;
+ this.setStyleClassNames(Array.concat(this.getStyleClassNames(), arrClassStr)) ;
+ var rootNode = this.getRootDomNode() ;
+ if( rootNode ){
+ // Add in the new styles---assumes the old ones
+ // already have been:
+ // TODO: Check this assumption:
+ for( var idx=0; idx<arrClassStr.length ; ++idx){
+ dojo.html.addClass(rootNode,arrClassStr[idx]);
+ }
+ }
+}
+
+
+/**
+ * When we "set" the class from an explicit class attribute,
+ * we're really adding it to the base class:
+ *
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.setClassAttribute
+ = xap.bridges.basic.AbstractWidgetBridge.prototype.addClassAttribute ;
+
+/**
+ * The style states allowed to be concatenated
+ * with (e.g.) xapButton to create (e.g.) "xapButtonFocused"
+ * ---empty string is for the base state.
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.getAllowedStyleStates = function(){
+ return ["","Disabled", "Focused", "MouseDown", "MouseOver"] ;
+}
+
+
+/**
+ * Removes a style class from our list of them, and from the dom node:
+ * @param pClassStr{string} name of class to remove
+**/
+xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleClass = function( pClassStr ){
+ // Allow users to be sloppy---multiple and/or leading
+ // and/or trailing spaces are allowed:
+ var classStr = pClassStr.replace(/^\s+|\s+$/,"").replace(/\s+/," ") ;
+ var arrClassesToRemove = classStr.split(" ") ;
+ var iClasses = this.getStyleClassNames() ;
+ var oClasses = new Array(0) ;
+ // Remove the one to remove from the list of base style states:
+ for( var idOrig=0; idOrig < iClasses.length; ++idOrig){
+ if( iClasses[idOrig] != classStr ){
+ oClasses.push(iClasses[idOrig]) ;
+ }
+ }
+ this.setStyleClassNames(oClasses) ;
+ // Now actually remove the style from the html dom node:
+ var rootNode = this.getRootDomNode() ;
+ var possibleStates=this.getAllowedStyleStates() ;
+ if( rootNode){
+ for( var ii=0; ii<possibleStates.length; ++possibleStates){
+ dojo.html.removeClass(
+ rootNode,
+ classStr + possibleStates[ii]
+ );
+ }
+ }
+}
+
+
xap.bridges.basic.AbstractWidgetBridge.prototype._requestFocus = function(){
var rootNode = this.getRootDomNode();
if (rootNode && rootNode.focus){
@@ -934,12 +1085,15 @@
xap.bridges.basic.AbstractWidgetBridge.prototype.attributeRemovers = new Object() ;
+
xap.bridges.basic.AbstractWidgetBridge.prototype.onAttributeRemoved = function(event){
var node = this.getRootDomNode() ;
var attributeName = event.getName() ;
+
+
if (this.attributeRemovers[attributeName]){
- this.attributeRemovers[attributeName].call(this) ;
+ this.attributeRemovers[attributeName].call(this,event) ;
return ;
}
Modified: incubator/xap/trunk/codebase/src/xap/bridges/xap/LabelBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/xap/LabelBridge.js?view=diff&rev=521513&r1=521512&r2=521513
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/xap/LabelBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/xap/LabelBridge.js Thu Mar 22 15:55:50 2007
@@ -31,7 +31,6 @@
xap.bridges.xap.LabelBridge.prototype.init = function() {
xap.bridges.basic.AbstractWidgetBridge.prototype.init.call(this);
var innerContent = this.getPeer().getLabelContents();
- dojo.html.addClass(innerContent,this.getContentClassName());
}
xap.bridges.xap.LabelBridge.prototype.obtainPeer = function() {
@@ -43,22 +42,20 @@
}
-xap.bridges.xap.LabelBridge.prototype.getContentClassName = function( ) {
- var nodeName = this.getElement().nodeName;
- nodeName = "xap" + nodeName.substring(0,1).toUpperCase() + nodeName.substring(1) + "Contents";
- return nodeName;
+xap.bridges.xap.LabelBridge.prototype.getContentNodeLabel = function( ) {
+ return "Contents";
}
xap.bridges.xap.LabelBridge.prototype.addStyleState = function(stateName){
- xap.bridges.basic.AbstractWidgetBridge.prototype.addStyleState.call(this,stateName);
+ xap.bridges.xap.LabelBridge.superclass.addStyleState.call(this,stateName);
var innerContent = this.getPeer().getLabelContents();
- dojo.html.addClass(innerContent,this.getContentClassName()+stateName);
+ xap.bridges.xap.LabelBridge.superclass.addStyleState.call(this,stateName,innerContent,this.getContentNodeLabel());
}
xap.bridges.xap.LabelBridge.prototype.removeStyleState = function(stateName){
- xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleState.call(this,stateName);
- var innerContent = this.getPeer().getLabelContents();
- dojo.html.removeClass(innerContent,this.getContentClassName()+stateName);
+// xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleState.call(this,stateName);
+// var innerContent = this.getPeer().getLabelContents();
+// xap.bridges.basic.AbstractWidgetBridge.prototype.removeStyleState.call(this,stateName,innerContent,this.getContentNodeLabel());
}
xap.bridges.xap.LabelBridge.prototype.getNewAllowedAttributes = function() {