|
From: <vla...@us...> - 2008-01-10 18:53:57
|
Revision: 244
http://equanda.svn.sourceforge.net/equanda/?rev=244&view=rev
Author: vladimirt
Date: 2008-01-10 10:53:54 -0800 (Thu, 10 Jan 2008)
Log Message:
-----------
added text truncate component
Modified Paths:
--------------
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/services/EquandaModule.java
Added Paths:
-----------
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Truncate.java
trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.css
trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.js
Added: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Truncate.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Truncate.java (rev 0)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Truncate.java 2008-01-10 18:53:54 UTC (rev 244)
@@ -0,0 +1,141 @@
+/**
+ * This file is part of the equanda project. The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the
+ * License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights
+ * and limitations under the License. Alternatively, the contents of this file may be used under the terms of either the
+ * GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or
+ * later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you
+ * wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow
+ * others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions
+ * above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the
+ * provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the
+ * LGPL.
+ */
+
+package org.equanda.tapestry5.components;
+
+import org.apache.tapestry.Asset;
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.PageRenderSupport;
+import org.apache.tapestry.TapestryConstants;
+import org.apache.tapestry.annotations.AfterRender;
+import org.apache.tapestry.annotations.BeginRender;
+import org.apache.tapestry.annotations.Environmental;
+import org.apache.tapestry.annotations.Mixin;
+import org.apache.tapestry.annotations.Parameter;
+import org.apache.tapestry.annotations.Path;
+import org.apache.tapestry.corelib.mixins.DiscardBody;
+import org.apache.tapestry.corelib.mixins.RenderInformals;
+import org.apache.tapestry.dom.Element;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.annotations.Symbol;
+
+/**
+ * Text Truncate Component
+ *
+ * @author <a href="mailto:vla...@gm...">Vladimir Tkachenko</a>
+ */
+public class Truncate {
+
+ @Parameter(required = true, defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX)
+ private String text;
+
+ @Parameter(defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX)
+ private Integer length;
+
+ @Parameter(defaultPrefix = TapestryConstants.LITERAL_BINDING_PREFIX)
+ private String suffix;
+
+ @Inject
+ @Symbol("truncate.component.default.length")
+ private int defaultLength;
+
+ @Inject
+ @Symbol("truncate.component.default.suffix")
+ private String defaultSuffix;
+
+ @Mixin
+ @SuppressWarnings("unused")
+ private RenderInformals renderInformals;
+
+ @Mixin
+ @SuppressWarnings("unused")
+ private DiscardBody discardBody;
+
+ @Environmental
+ private PageRenderSupport pageRenderSupport;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ @Path("classpath:/org/equanda/tapestry5/resources/truncate.js")
+ private Asset script;
+
+ @Inject
+ @Path("classpath:/org/equanda/tapestry5/resources/truncate.css")
+ private Asset style;
+
+
+ public String getId() {
+ return resources.getId();
+ }
+
+
+ public String getText() {
+ return text;
+ }
+
+
+ public String getTruncatedText() {
+ int len = getLengthValue();
+ return text != null && text.length() > len ? ( text.substring( 0, len - getSuffixValue().length() ) + getSuffixValue() ) : text;
+ }
+
+
+ private int getLengthValue() {
+ return length != null && length > 0 ? length : defaultLength;
+ }
+
+
+ private String getSuffixValue() {
+ return suffix != null ? suffix : defaultSuffix;
+ }
+
+
+ @BeginRender
+ void doBeginRender( MarkupWriter writer ) {
+ pageRenderSupport.addScriptLink( script );
+ pageRenderSupport.addStylesheetLink( style, null );
+ writer.element( "span", "id", getId() ).text( getTruncatedText() );
+ writer.end();
+ }
+
+
+ @AfterRender
+ void doAfterRender( MarkupWriter writer ) {
+ if( text != null && text.length() > getLengthValue() ) {
+ Element root = writer.getDocument().getRootElement();
+ Element body = null;
+ if( root != null ) {
+ if( root.getName().equals( "html" ) ) {
+ body = root.find( "body" );
+ }
+ }
+ String[] args = new String[] { "class", "equanda_truncate_content", "id", getId() + "_text", "style",
+ "visibility: hidden; top: -1000px; left: 0;" };
+ if( body != null ) {
+ Element element = body.element( "div", args );
+ element.text( getText() );
+ } else {
+ Element element = writer.element( "div", (Object[]) args );
+ element.text( getText() );
+ writer.end();
+ }
+ pageRenderSupport.addScript( "equandaTruncateInit('%s'); ", resources.getId() );
+ }
+ }
+
+}
Modified: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/services/EquandaModule.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/services/EquandaModule.java 2008-01-10 12:38:20 UTC (rev 243)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/services/EquandaModule.java 2008-01-10 18:53:54 UTC (rev 244)
@@ -59,5 +59,11 @@
configuration.add(Double.class, new DoubleTranslator());
configuration.add( Timestamp.class, new TimestampTranslator());
}
+
+
+ public static void contributeFactoryDefaults( MappedConfiguration<String, String> configuration ) {
+ configuration.add( "truncate.component.default.length", "30" );
+ configuration.add( "truncate.component.default.suffix", "..." );
+ }
}
Added: trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.css
===================================================================
--- trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.css (rev 0)
+++ trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.css 2008-01-10 18:53:54 UTC (rev 244)
@@ -0,0 +1,11 @@
+.equanda_truncate_content{
+ position: absolute;
+ padding: 5px;
+ border: 1px solid black;
+ font: normal 12px Verdana;
+ line-height: 18px;
+ z-index: 100;
+ background-color: white;
+ width: 250px;
+ filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=140,Strength=4);
+}
Added: trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.js
===================================================================
--- trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.js (rev 0)
+++ trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/truncate.js 2008-01-10 18:53:54 UTC (rev 244)
@@ -0,0 +1,84 @@
+var disappearDelay = 250;
+var verticalOffset = 0;
+var isIE = document.all;
+
+function equandaGetPositionOffset( what, offsettype ){
+ var totaloffset = ( offsettype == "left" ) ? what.offsetLeft : what.offsetTop;
+ var parentEl = what.offsetParent;
+ while( parentEl != null ){
+ totaloffset = ( offsettype == "left" ) ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
+ parentEl = parentEl.offsetParent;
+ }
+ return totaloffset;
+}
+
+function equandaShowHide( obj, e ){
+ textObject.style.left = textObject.style.top = "-500px";
+ if( e.type == "mouseover" ){
+ obj.visibility = "visible";
+ }
+}
+
+function equandaCompatibleObject(){
+ return ( document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
+}
+
+function equandaClearBrowserEdge( obj, targetEdge ){
+ if( targetEdge == "rightedge" ){
+ edgeoffsetx = 0;
+ var windowedge = isIE && !window.opera ? equandaCompatibleObject().scrollLeft + equandaCompatibleObject().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15;
+ textObject.contentmeasure = textObject.offsetWidth;
+ if( windowedge - textObject.x < textObject.contentmeasure ){
+ edgeoffsetx = textObject.contentmeasure - obj.offsetWidth;
+ }
+ return edgeoffsetx;
+ } else {
+ edgeoffsety = 0;
+ var topedge = isIE && !window.opera ? equandaCompatibleObject().scrollTop : window.pageYOffset;
+ var windowedge = isIE && !window.opera ? equandaCompatibleObject().scrollTop + equandaCompatibleObject().clientHeight - 15 : window.pageYOffset+window.innerHeight - 18;
+ textObject.contentmeasure = textObject.offsetHeight;
+ if( windowedge - textObject.y < textObject.contentmeasure ){
+ edgeoffsety = textObject.contentmeasure + obj.offsetHeight + ( verticalOffset * 2 );
+ }
+ return edgeoffsety;
+ }
+}
+
+function equandaShowText( obj, e ){
+ if( window.event ){
+ event.cancelBubble = true;
+ } else if( e.stopPropagation ){
+ e.stopPropagation();
+ }
+ if( typeof textObject != "undefined" ){
+ textObject.style.visibility = "hidden";
+ }
+ equandaClearHide();
+ textObject = document.getElementById( obj.getAttribute( "id" ) + "_text" );
+ equandaShowHide( textObject.style, e );
+ textObject.x = equandaGetPositionOffset( obj, "left" );
+ textObject.y = equandaGetPositionOffset( obj, "top" ) + verticalOffset;
+ textObject.style.left = textObject.x - equandaClearBrowserEdge( obj, "rightedge" ) + "px";
+ textObject.style.top = textObject.y - equandaClearBrowserEdge( obj, "bottomedge" ) + obj.offsetHeight + "px";
+}
+
+function equandaHideWithDelay(){
+ delayhide = setTimeout( "textObject.style.visibility = 'hidden'; textObject.style.left = 0;", disappearDelay );
+}
+
+function equandaClearHide(){
+ if( typeof delayhide != "undefined" ){
+ clearTimeout( delayhide );
+ }
+}
+
+function equandaTruncateInit( id ){
+ var e = document.getElementById( id );
+ if( e != null ){
+ e.onmouseover = function(e){
+ var ev = window.event ? window.event : e;
+ equandaShowText( this, ev );
+ }
+ e.onmouseout = equandaHideWithDelay;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|