Author: fdesbois Date: 2010-06-17 15:09:30 +0000 (Thu, 17 Jun 2010) New Revision: 544 Log: Evo #2333 : Use proper Javascript NewsHider class to hide news details Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java trunk/wao-ui/src/main/webapp/js/wao.js Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java 2010-06-17 13:48:37 UTC (rev 543) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java 2010-06-17 15:09:30 UTC (rev 544) @@ -35,6 +35,7 @@ import org.apache.tapestry5.Asset2; import org.apache.tapestry5.PersistenceConstants; import org.apache.tapestry5.RenderSupport; +import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; import org.apache.tapestry5.annotations.IncludeStylesheet; import org.apache.tapestry5.annotations.Log; import org.apache.tapestry5.annotations.Path; @@ -58,6 +59,7 @@ */ @RequiresAuthentication @IncludeStylesheet("context:css/news.css") + at IncludeJavaScriptLibrary("context:js/NewsHider.js") public class Index { @Inject @@ -92,9 +94,10 @@ @Inject private RenderSupport renderSupport; - public void beginRender() { + public void afterRender() { // Hide news details depends on an anchor named 'details' in news.getContent() - renderSupport.addScript("hideNewsDetails();"); + renderSupport.addScript("newsHider = new NewsHider();\n" + + "newsHider.hideAllNewsDetails();"); } @Log Modified: trunk/wao-ui/src/main/webapp/js/wao.js =================================================================== --- trunk/wao-ui/src/main/webapp/js/wao.js 2010-06-17 13:48:37 UTC (rev 543) +++ trunk/wao-ui/src/main/webapp/js/wao.js 2010-06-17 15:09:30 UTC (rev 544) @@ -103,48 +103,48 @@ // } //} -function toggleNewsDetails(element) { - $(element).toggleClassName('hidden'); -} - -function hideNewsDetails() { - var allNews = $('so-news').select('div.news-content'); - // Tapestry.debug('nb news : ' + contentsArray.length); - - for (j = 0; j < allNews.length; j++) { - var news = allNews[j]; - // Select all paragraphs in the news - // Tapestry.debug('nb paragraphs in news : ' + paragraphs.length); - var paragraphs = news.select('p'); - - for (i = 0; i < paragraphs.length; i++) { - var paragraph = paragraphs[i]; - - // Check the firstDescendant in the paragraph, we take only anchor called 'details' - if (paragraph.firstDescendant() && paragraph.firstDescendant().match('a[name="details"]')) { - var anchor = paragraph.firstDescendant(); - // Tapestry.debug('find anchor : ' + anchor); - - // Prepare the hidden block - var detailsContent = document.createElement('div'); - detailsContent.id = 'news-details-content-' + j; - detailsContent.addClassName('hidden'); - - // Update params of the anchor to be clickable - anchor.update('Lire la suite...'); - anchor.addClassName('news-details-link'); - anchor.writeAttribute('onclick', 'toggleNewsDetails("' + detailsContent.id + '")'); - - // Retrieve siblings paragraphs to wrap them into the hidden detailsContent - var otherParagraphs = paragraph.nextSiblings(); - for (k = 0; k < otherParagraphs.length; k++) { - detailsContent.appendChild(otherParagraphs[k]); - } - - // append the hidden block to the news - news.appendChild(detailsContent); - break; - } - } - } -} +//function toggleNewsDetails(element) { +// $(element).toggleClassName('hidden'); +//} +// +//function hideNewsDetails() { +// var allNews = $('so-news').select('div.news-content'); +// // Tapestry.debug('nb news : ' + contentsArray.length); +// +// for (j = 0; j < allNews.length; j++) { +// var news = allNews[j]; +// // Select all paragraphs in the news +// // Tapestry.debug('nb paragraphs in news : ' + paragraphs.length); +// var paragraphs = news.select('p'); +// +// for (i = 0; i < paragraphs.length; i++) { +// var paragraph = paragraphs[i]; +// +// // Check the firstDescendant in the paragraph, we take only anchor called 'details' +// if (paragraph.firstDescendant() && paragraph.firstDescendant().match('a[name="details"]')) { +// var anchor = paragraph.firstDescendant(); +// // Tapestry.debug('find anchor : ' + anchor); +// +// // Prepare the hidden block +// var detailsContent = document.createElement('div'); +// detailsContent.id = 'news-details-content-' + j; +// detailsContent.addClassName('hidden'); +// +// // Update params of the anchor to be clickable +// anchor.update('Lire la suite...'); +// anchor.addClassName('news-details-link'); +// anchor.writeAttribute('onclick', 'toggleNewsDetails("' + detailsContent.id + '")'); +// +// // Retrieve siblings paragraphs to wrap them into the hidden detailsContent +// var otherParagraphs = paragraph.nextSiblings(); +// for (k = 0; k < otherParagraphs.length; k++) { +// detailsContent.appendChild(otherParagraphs[k]); +// } +// +// // append the hidden block to the news +// news.appendChild(detailsContent); +// break; +// } +// } +// } +//}