|
From: <tri...@us...> - 2007-11-23 11:40:22
|
Revision: 160
http://equanda.svn.sourceforge.net/equanda/?rev=160&view=rev
Author: triathlon98
Date: 2007-11-23 03:39:54 -0800 (Fri, 23 Nov 2007)
Log Message:
-----------
EQ-86 tabs component
Added Paths:
-----------
trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Tabs.java
trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/Tabs.tml
trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/domtab.js
Added: trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Tabs.java
===================================================================
--- trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Tabs.java (rev 0)
+++ trunk/equanda-tapestry5/src/main/java/org/equanda/tapestry5/components/Tabs.java 2007-11-23 11:39:54 UTC (rev 160)
@@ -0,0 +1,168 @@
+/**
+ * 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.*;
+import org.apache.tapestry.annotations.*;
+import org.apache.tapestry.ioc.annotations.Inject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tabs component
+ *
+ * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a>
+ */
+@SupportsInformalParameters
+public class Tabs
+{
+ private static final int MAX_PANELS = 50; // max number of supported tabs
+
+ @Inject
+ @Path( "classpath:/org/equanda/tapestry5/resources/domtab.js" )
+ private Asset script;
+
+ @Environmental
+ private PageRenderSupport pageRenderSupport;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Parameter
+ private Block titleIcon;
+
+ @Parameter
+ Block emptyBlock;
+
+ private TwoBlocks panel;
+ private int index;
+
+ @BeginRender
+ void doBeginRender( MarkupWriter writer )
+ {
+ pageRenderSupport.addScriptLink( script );
+ }
+
+ @AfterRender
+ void doAfterRender( MarkupWriter writer )
+ {
+ pageRenderSupport.addScript( "equandaAccordionInit('%s'); ", resources.getId() );
+ }
+
+ public String getId()
+ {
+ return resources.getId();
+ }
+
+ public Block getTitleIcon()
+ {
+ return titleIcon;
+ }
+
+ public void setTitleIcon( Block titleIcon )
+ {
+ this.titleIcon = titleIcon;
+ }
+
+ public TwoBlocks getPanel()
+ {
+ return panel;
+ }
+
+ public void setPanel( TwoBlocks panel )
+ {
+ this.panel = panel;
+ }
+
+ public List<TwoBlocks> getPanels()
+ {
+ List<TwoBlocks> list = new ArrayList<TwoBlocks>();
+ for ( int i = 0; i < MAX_PANELS ; i++ )
+ {
+ String index = Integer.toString( i + 1 );
+ if ( resources.isBound( "title" + index ) && resources.isBound( "content" + index ) )
+ {
+ list.add( new TwoBlocks( i + 1 ) );
+ }
+ }
+ return list;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public void setIndex( int index )
+ {
+ this.index = index;
+ }
+
+ public class TwoBlocks
+ {
+ private Block title, content;
+ private boolean active;
+
+ public TwoBlocks( int index )
+ {
+ active = ( 1 == index );
+ title = resources.getBlockParameter( "title" + index );
+ if ( null == title ) title = emptyBlock; // should not happen as parameter is bound
+ content = resources.getBlockParameter( "content" + index );
+ if ( null == content ) content = emptyBlock; // should not happen as parameter is bound
+ }
+
+ public Block getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle( Block title )
+ {
+ this.title = title;
+ }
+
+ public Block getContent()
+ {
+ return content;
+ }
+
+ public void setContent( Block content )
+ {
+ this.content = content;
+ }
+
+ public boolean isActive()
+ {
+ return active;
+ }
+
+ public void setActive( boolean active )
+ {
+ this.active = active;
+ }
+ }
+}
Added: trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/Tabs.tml
===================================================================
--- trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/Tabs.tml (rev 0)
+++ trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/components/Tabs.tml 2007-11-23 11:39:54 UTC (rev 160)
@@ -0,0 +1,17 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+<div class="domtab" id="${id}">
+ <ul class="domtabs">
+ <t:loop source="Panels" value="Panel" index="Index">
+ <li><a href="#${id}t${index}">
+ <t:delegate to="titleIcon"/>
+ <t:delegate to="panel.title"/>
+ </a></li>
+ </t:loop>
+ </ul>
+ <t:loop source="Panels" value="Panel" index="Index">
+ <div><a name="${id}t${index}" id="${id}t${index}"><t:delegate to="panel.content"/></a></div>
+ </t:loop>
+</div>
+
+</html>
\ No newline at end of file
Added: trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/domtab.js
===================================================================
--- trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/domtab.js (rev 0)
+++ trunk/equanda-tapestry5/src/main/resources/org/equanda/tapestry5/resources/domtab.js 2007-11-23 11:39:54 UTC (rev 160)
@@ -0,0 +1,256 @@
+/*
+ DOMtab Version 3.1415927
+ Updated March the First 2006
+ written by Christian Heilmann
+ check blog for updates: http://www.wait-till-i.com
+ free to use, not free to resell
+*/
+
+domtab={
+ tabClass:'domtab', // class to trigger tabbing
+ listClass:'domtabs', // class of the menus
+ activeClass:'active', // class of current link
+ contentElements:'div', // elements to loop through
+ backToLinks:/#top/, // pattern to check "back to top" links
+ printID:'domtabprintview', // id of the print all link
+ showAllLinkText:'show all content', // text for the print all link
+ prevNextIndicator:'doprevnext', // class to trigger prev and next links
+ prevNextClass:'prevnext', // class of the prev and next list
+ prevLabel:'previous', // HTML content of the prev link
+ nextLabel:'next', // HTML content of the next link
+ prevClass:'prev', // class for the prev link
+ nextClass:'next', // class for the next link
+ init:function(){
+ var temp;
+ if(!document.getElementById || !document.createTextNode){return;}
+ var tempelm=document.getElementsByTagName('div');
+ for(var i=0;i<tempelm.length;i++){
+ if(!domtab.cssjs('check',tempelm[i],domtab.tabClass)){continue;}
+ domtab.initTabMenu(tempelm[i]);
+ domtab.removeBackLinks(tempelm[i]);
+ if(domtab.cssjs('check',tempelm[i],domtab.prevNextIndicator)){
+ domtab.addPrevNext(tempelm[i]);
+ }
+ domtab.checkURL();
+ }
+ if(document.getElementById(domtab.printID)
+ && !document.getElementById(domtab.printID).getElementsByTagName('a')[0]){
+ var newlink=document.createElement('a');
+ newlink.setAttribute('href','#');
+ domtab.addEvent(newlink,'click',domtab.showAll,false);
+ newlink.onclick=function(){return false;} // safari hack
+ newlink.appendChild(document.createTextNode(domtab.showAllLinkText));
+ document.getElementById(domtab.printID).appendChild(newlink);
+ }
+ },
+ checkURL:function(){
+ var id;
+ var loc=window.location.toString();
+ loc=/#/.test(loc)?loc.match(/#(\w.+)/)[1]:'';
+ if(loc==''){return;}
+ var elm=document.getElementById(loc);
+ if(!elm){return;}
+ var parentMenu=elm.parentNode.parentNode.parentNode;
+ parentMenu.currentSection=loc;
+ parentMenu.getElementsByTagName(domtab.contentElements)[0].style.display='none';
+ domtab.cssjs('remove',parentMenu.getElementsByTagName('a')[0].parentNode,domtab.activeClass);
+ var links=parentMenu.getElementsByTagName('a');
+ for(i=0;i<links.length;i++){
+ if(!links[i].getAttribute('href')){continue;}
+ if(!/#/.test(links[i].getAttribute('href').toString())){continue;}
+ id=links[i].href.match(/#(\w.+)/)[1];
+ if(id==loc){
+ var cur=links[i].parentNode.parentNode;
+ domtab.cssjs('add',links[i].parentNode,domtab.activeClass);
+ break;
+ }
+ }
+ domtab.changeTab(elm,1);
+ elm.focus();
+ cur.currentLink=links[i];
+ cur.currentSection=loc;
+ },
+ showAll:function(e){
+ document.getElementById(domtab.printID).parentNode.removeChild(document.getElementById(domtab.printID));
+ var tempelm=document.getElementsByTagName('div');
+ for(var i=0;i<tempelm.length;i++){
+ if(!domtab.cssjs('check',tempelm[i],domtab.tabClass)){continue;}
+ var sec=tempelm[i].getElementsByTagName(domtab.contentElements);
+ for(var j=0;j<sec.length;j++){
+ sec[j].style.display='block';
+ }
+ }
+ var tempelm=document.getElementsByTagName('ul');
+ for(i=0;i<tempelm.length;i++){
+ if(!domtab.cssjs('check',tempelm[i],domtab.prevNextClass)){continue;}
+ tempelm[i].parentNode.removeChild(tempelm[i]);
+ i--;
+ }
+ domtab.cancelClick(e);
+ },
+ addPrevNext:function(menu){
+ var temp;
+ var sections=menu.getElementsByTagName(domtab.contentElements);
+ for(var i=0;i<sections.length;i++){
+ temp=domtab.createPrevNext();
+ if(i==0){
+ temp.removeChild(temp.getElementsByTagName('li')[0]);
+ }
+ if(i==sections.length-1){
+ temp.removeChild(temp.getElementsByTagName('li')[1]);
+ }
+ temp.i=i; // h4xx0r!
+ temp.menu=menu;
+ sections[i].appendChild(temp);
+ }
+ },
+ removeBackLinks:function(menu){
+ var links=menu.getElementsByTagName('a');
+ for(var i=0;i<links.length;i++){
+ if(!domtab.backToLinks.test(links[i].href)){continue;}
+ links[i].parentNode.removeChild(links[i]);
+ i--;
+ }
+ },
+ initTabMenu:function(menu){
+ var id;
+ var lists=menu.getElementsByTagName('ul');
+ for(var i=0;i<lists.length;i++){
+ if(domtab.cssjs('check',lists[i],domtab.listClass)){
+ var thismenu=lists[i];
+ break;
+ }
+ }
+ if(!thismenu){return;}
+ thismenu.currentSection='';
+ thismenu.currentLink='';
+ var links=thismenu.getElementsByTagName('a');
+ for(i=0;i<links.length;i++){
+ if(!/#/.test(links[i].getAttribute('href').toString())){continue;}
+ id=links[i].href.match(/#(\w.+)/)[1];
+ if(document.getElementById(id)){
+ domtab.addEvent(links[i],'click',domtab.showTab,false);
+ links[i].onclick=function(){return false;} // safari hack
+ domtab.changeTab(document.getElementById(id),0);
+ }
+ }
+ id=links[0].href.match(/#(\w.+)/)[1];
+ if(document.getElementById(id)){
+ domtab.changeTab(document.getElementById(id),1);
+ thismenu.currentSection=id;
+ thismenu.currentLink=links[0];
+ domtab.cssjs('add',links[0].parentNode,domtab.activeClass);
+ }
+ },
+ createPrevNext:function(){
+ // this would be so much easier with innerHTML, darn you standards fetish!
+ var temp=document.createElement('ul');
+ temp.className=domtab.prevNextClass;
+ temp.appendChild(document.createElement('li'));
+ temp.getElementsByTagName('li')[0].appendChild(document.createElement('a'));
+ temp.getElementsByTagName('a')[0].setAttribute('href','#');
+ temp.getElementsByTagName('a')[0].innerHTML=domtab.prevLabel;
+ temp.getElementsByTagName('li')[0].className=domtab.prevClass;
+ temp.appendChild(document.createElement('li'));
+ temp.getElementsByTagName('li')[1].appendChild(document.createElement('a'));
+ temp.getElementsByTagName('a')[1].setAttribute('href','#');
+ temp.getElementsByTagName('a')[1].innerHTML=domtab.nextLabel;
+ temp.getElementsByTagName('li')[1].className=domtab.nextClass;
+ domtab.addEvent(temp.getElementsByTagName('a')[0],'click',domtab.navTabs,false);
+ domtab.addEvent(temp.getElementsByTagName('a')[1],'click',domtab.navTabs,false);
+ // safari fix
+ temp.getElementsByTagName('a')[0].onclick=function(){return false;}
+ temp.getElementsByTagName('a')[1].onclick=function(){return false;}
+ return temp;
+ },
+ navTabs:function(e){
+ var li=domtab.getTarget(e);
+ var menu=li.parentNode.parentNode.menu;
+ var count=li.parentNode.parentNode.i;
+ var section=menu.getElementsByTagName(domtab.contentElements);
+ var links=menu.getElementsByTagName('a');
+ var othercount=(li.parentNode.className==domtab.prevClass)?count-1:count+1;
+ section[count].style.display='none';
+ domtab.cssjs('remove',links[count].parentNode,domtab.activeClass);
+ section[othercount].style.display='block';
+ domtab.cssjs('add',links[othercount].parentNode,domtab.activeClass);
+ var parent=links[count].parentNode.parentNode;
+ parent.currentLink=links[othercount];
+ parent.currentSection=links[othercount].href.match(/#(\w.+)/)[1];
+ domtab.cancelClick(e);
+ },
+ changeTab:function(elm,state){
+ do{
+ elm=elm.parentNode;
+ } while(elm.nodeName.toLowerCase()!=domtab.contentElements)
+ elm.style.display=state==0?'none':'block';
+ },
+ showTab:function(e){
+ var o=domtab.getTarget(e);
+ if(o.parentNode.parentNode.currentSection!=''){
+ domtab.changeTab(document.getElementById(o.parentNode.parentNode.currentSection),0);
+ domtab.cssjs('remove',o.parentNode.parentNode.currentLink.parentNode,domtab.activeClass);
+ }
+ var id=o.href.match(/#(\w.+)/)[1];
+ o.parentNode.parentNode.currentSection=id;
+ o.parentNode.parentNode.currentLink=o;
+ domtab.cssjs('add',o.parentNode,domtab.activeClass);
+ domtab.changeTab(document.getElementById(id),1);
+ document.getElementById(id).focus();
+ domtab.cancelClick(e);
+ },
+/* helper methods */
+ getTarget:function(e){
+ var target = window.event ? window.event.srcElement : e ? e.target : null;
+ if (!target){return false;}
+ if (target.nodeName.toLowerCase() != 'a'){target = target.parentNode;}
+ return target;
+ },
+ cancelClick:function(e){
+ if (window.event){
+ window.event.cancelBubble = true;
+ window.event.returnValue = false;
+ return;
+ }
+ if (e){
+ e.stopPropagation();
+ e.preventDefault();
+ }
+ },
+ addEvent: function(elm, evType, fn, useCapture){
+ if (elm.addEventListener)
+ {
+ elm.addEventListener(evType, fn, useCapture);
+ return true;
+ } else if (elm.attachEvent) {
+ var r = elm.attachEvent('on' + evType, fn);
+ return r;
+ } else {
+ elm['on' + evType] = fn;
+ }
+ },
+ cssjs:function(a,o,c1,c2){
+ switch (a){
+ case 'swap':
+ o.className=!domtab.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
+ break;
+ case 'add':
+ if(!domtab.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
+ break;
+ case 'remove':
+ var rep=o.className.match(' '+c1)?' '+c1:c1;
+ o.className=o.className.replace(rep,'');
+ break;
+ case 'check':
+ var found=false;
+ var temparray=o.className.split(' ');
+ for(var i=0;i<temparray.length;i++){
+ if(temparray[i]==c1){found=true;}
+ }
+ return found;
+ break;
+ }
+ }
+}
+domtab.addEvent(window, 'load', domtab.init, false);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|