Author: vmassol Date: 2008-02-26 15:15:39 +0100 (Tue, 26 Feb 2008) New Revision: 7958
Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/XWikiLinkFilter.java xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/skin.js xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/xwiki.js xwiki-products/xwiki-enterprise/trunk/wiki/src/main/resources/XWiki/XWikiSyntax Log: XSALBATROSS-17: Add Javascript function to open links having a rel attribute in separate windows XWIKI-2154: XWiki syntax links specifying a target generate non XHTML syntax XE-197: Include the XWiki Syntax page in the default wiki rather than link to the live xwiki.org web site * Fixed invalid XHTML for link Modified: xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/XWikiLinkFilter.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/XWikiLinkFilter.java 2008-02-26 13:11:57 UTC (rev 7957) +++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/filter/XWikiLinkFilter.java 2008-02-26 14:15:39 UTC (rev 7958) @@ -132,13 +132,13 @@ buffer.append(Util.escapeURL(href)); buffer.append("\""); if(target != null){ - buffer.append(" target=\"" + target + "\""); + buffer.append(" " + constructRelAttribute(target)); } else { XWikiContext xcontext = (XWikiContext)context.getRenderContext().get("xcontext"); XWiki xwiki = xcontext.getWiki(); String defaulttarget = xwiki.Param("xwiki.render.externallinks.defaulttarget", ""); if (!defaulttarget.equals("")) { - buffer.append(" target=\"" + defaulttarget + "\""); + buffer.append(" " + constructRelAttribute(defaulttarget)); } } buffer.append(">"); @@ -223,7 +223,7 @@ if(target != null){ int where = buffer.lastIndexOf(" href=\""); if(where >= 0) { - buffer.insert(where, " target=\"" + target + "\""); + buffer.insert(where, " " + constructRelAttribute(target)); } } } @@ -263,4 +263,10 @@ } } + private String constructRelAttribute(String target) + { + // We prefix with "_" since a target can be any token and we need to + // differentiate with other valid rel tokens. + return "rel=\"_" + target + "\""; + } } Modified: xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/skin.js =================================================================== --- xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/skin.js 2008-02-26 13:11:57 UTC (rev 7957) +++ xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/skin.js 2008-02-26 14:15:39 UTC (rev 7958) @@ -57,6 +57,7 @@ var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); + externalLinks(); } window.onunload = function(e) { @@ -129,9 +130,9 @@ function checkAdvancedContent(message) { result = false; - if (!document.forms.edit) { - return true; - } + if (!document.forms.edit) { + return true; + } data = document.forms.edit.content.value; myRE = new RegExp("</?(html|body|img|a|i|b|embed|script|form|input|textarea|object|font|li|ul|ol|table|center|hr|br|p) ?([^>]*)>", "ig") results = data.match(myRE) Modified: xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/xwiki.js =================================================================== --- xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/xwiki.js 2008-02-26 13:11:57 UTC (rev 7957) +++ xwiki-platform/skins/trunk/albatross/src/main/resources/albatross/xwiki.js 2008-02-26 14:15:39 UTC (rev 7958) @@ -1,6 +1,7 @@ function hideForm(form){ form.getElementsByTagName("fieldset").item(0).className = "collapsed"; } + function toggleForm(form){ var fieldset = form.getElementsByTagName("fieldset").item(0); if(fieldset.className == "collapsed"){ @@ -19,6 +20,7 @@ element.className = element.className.replace('collapsed', 'expanded'); } } + function showsubmenu(element){ if(element.lastChild.tagName.toLowerCase() == "span"){ if(window.hidetimer){ @@ -37,6 +39,7 @@ element.lastChild.className = element.lastChild.className.replace("hidden", "visible"); } } + function hidesubmenu(element){ if(element.lastChild.tagName.toLowerCase() == "span"){ window.hideelement = element.lastChild; @@ -57,6 +60,7 @@ window.hidetimer = null; window.hideelement = null; } + function updateAttachName(form, msg) { var fname = form.filepath.value; @@ -93,6 +97,7 @@ rmClass(o, className); } } + function addClass(o, className){ if(!eltHasClass(o,className)) o.className += ' ' + className @@ -244,6 +249,7 @@ temp = temp.replace(/[^a-zA-Z0-9_]/g,""); return temp; } + function prepareName(form) { var fname = form.register_first_name.value; var lname = form.register_last_name.value; @@ -288,4 +294,30 @@ function eraseCookie(name) { createCookie(name,"",-1); -} \ No newline at end of file +} + +/* Open links marked with rel="external" in an external window and sets the target attribute to any + rel attribute starting with "_". Note that We need to do this in Javascript + as opposed to using target="_blank" since the target attribute is not valid XHTML. + */ +function externalLinks() { + if (!document.getElementsByTagName) return; + var anchors = document.getElementsByTagName("a"); + for (var i=0; i<anchors.length; i++) { + var anchor = anchors[i]; + if (anchor.hasAttribute("href") && anchor.hasAttribute("rel")) { + // Since the rel attribute can have other values we need to only take into account the ones + // starting with "_" + var values = anchor.getAttribute("rel").split(" "); + for(var j = 0; j<values.length; j++) { + if (values[j].charAt(0) == "_") { + anchor.target = values[j].substring(1); + break; + } else if (values[j] == "external") { + anchor.target = "_blank"; + break; + } + } + } + } +} Modified: xwiki-products/xwiki-enterprise/trunk/wiki/src/main/resources/XWiki/XWikiSyntax =================================================================== --- xwiki-products/xwiki-enterprise/trunk/wiki/src/main/resources/XWiki/XWikiSyntax 2008-02-26 13:11:57 UTC (rev 7957) +++ xwiki-products/xwiki-enterprise/trunk/wiki/src/main/resources/XWiki/XWikiSyntax 2008-02-26 14:15:39 UTC (rev 7958) @@ -425,7 +425,7 @@ <span class="wikilink"><a href="/xwiki/bin/view/UserGuide/">home</a></span> (uses current space)<br/> <span class="wikilink"><a href="/xwiki/bin/view/Main/">Web Home</a></span><br/> <span class="wikilink"><a href="/xwiki/bin/view/Main/">home</a></span><br/> - <span class="wikilink"><a target="_blank" href="/xwiki/bin/view/Main/">home</a></span> + <span class="wikilink"><a href="/xwiki/bin/view/Main/" rel="__blank">home</a></span> </td> </tr> </table> _______________________________________________ notifications mailing list notifications@xwiki.org http://lists.xwiki.org/mailman/listinfo/notifications