Prepare for Badge ARIA support
- fire "chageText" event when text is set on CTabItem and ToolItem. Same
event is already fired for Button.
- add Badges.getBadge function that returns badge element text
- set badge element text to empty string when badge is removed
Change-Id: I8532a5e0fb295f945987421115c36d45cc06c1e7
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/CTabItem.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/CTabItem.js
index 4a33d53..3a71bb8 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/CTabItem.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/CTabItem.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2016 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2002, 2017 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -63,6 +63,7 @@
this._rawText = value;
this._mnemonicIndex = null;
this._applyText( false );
+ this.dispatchSimpleEvent( "changeText" );
},
setImage : function( value ) {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ToolItem.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ToolItem.js
index e25b857..8254174 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ToolItem.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ToolItem.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 EclipseSource and others.
+ * Copyright (c) 2009, 2017 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -80,6 +80,7 @@
this._rawText = value;
this._mnemonicIndex = null;
this._applyText( false );
+ this.dispatchSimpleEvent( "changeText" );
},
computeBadgePosition : function() {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/util/Badges.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/util/Badges.js
index 991e18d..2289658 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/util/Badges.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/util/Badges.js
@@ -33,25 +33,38 @@
} else {
this._removeBadge( widget );
}
+ widget.dispatchSimpleEvent( "changeBadge" );
+ },
+
+ getBadge : function( widget ) {
+ var badge = widget.getUserData( BADGE_ELEMENT );
+ if( badge ) {
+ return $( badge ).text();
+ }
+ return null;
},
_getBadgeElement : function( widget ) {
- if( widget.getUserData( BADGE_ELEMENT ) == null ) {
- widget.enableEnhancedBorder();
- var badge = document.createElement( "div" );
- $( badge ).css( {
- "position" : "absolute",
- "textAlign" : "center",
- "lineHeight" : LINE_HEIGHT_FACTOR
- } );
- widget.setUserData( BADGE_ELEMENT, badge );
+ var badge = widget.getUserData( BADGE_ELEMENT );
+ if( badge ) {
+ return badge;
}
- return widget.getUserData( BADGE_ELEMENT );
+ widget.enableEnhancedBorder();
+ badge = document.createElement( "div" );
+ $( badge ).css( {
+ "position" : "absolute",
+ "textAlign" : "center",
+ "lineHeight" : LINE_HEIGHT_FACTOR
+ } );
+ widget.setUserData( BADGE_ELEMENT, badge );
+ return badge;
},
_removeBadge : function( widget ) {
- if( widget.getUserData( BADGE_ELEMENT ) != null ) {
- $( widget.getUserData( BADGE_ELEMENT ) ).detach();
+ var badge = widget.getUserData( BADGE_ELEMENT );
+ if( badge ) {
+ $( badge ).text( "" );
+ $( badge ).detach();
}
},
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/spec/Badges.spec.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/spec/Badges.spec.js
index 496d773..848673e 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/spec/Badges.spec.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/spec/Badges.spec.js
@@ -213,4 +213,19 @@
} );
+ describe( "getBadge", function() {
+
+ it( "returns null initially", function() {
+ expect( Badges.getBadge( widget ) ).toBe( null );
+ } );
+
+ it( "returns badge element text", function() {
+ Badges.setBadge( widget, "bar" );
+ TestUtil.flush();
+
+ expect( Badges.getBadge( widget ) ).toBe( "bar" );
+ } );
+
+ } );
+
} );