tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/9983-encase-a-hrefmailtoa-links-in-javascriptCascade CMS: Discussion 2014-06-04T20:05:07Ztag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T16:13:48Z2014-06-04T16:14:54ZEncase <a href="mailto"></a> links in javascript<div><p>I should note that I can select the <code><a></code> nodes
and get the name and whatnot, but I am at a loss what to do next to
pick out the email address from the mailto link.</p></div>Joel Traugertag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T17:55:09Z2014-06-04T17:55:09ZEncase <a href="mailto"></a> links in javascript<div><p>Hi Joel,</p>
<p>Just to clarify, are you looking to allow your users to enter
something like <code>mailto:admissions@hsu.edu</code> as plain text
within a WYSIWYG (or text field) and then have Cascade Server
replace the text with your <code><script></code> tag and
build the actual <code><a></code> dynamically?</p>
<p>Please let me know if I am on the right track here.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T18:36:18Z2014-06-04T18:36:18ZEncase <a href="mailto"></a> links in javascript<div><p>I was thinking that they would use the "Insert/Edit Link" button
on the WYSIWYG editor to create, in the xml, <code><a
href="mailto:address@company.com">Name of
person</a></code> and have the Velocity code pick that apart
and transform it into this:</p>
<pre>
<code><script type="text/javascript">// <![CDATA[
name=('Person's ' + 'Name ' + 'Here')
email=('address@' + 'company.com')
document.write('<A href="mailto:' + email + '">' + name + '</a>')
// ]]></script>
<!--The script on this page is to help protect against spam--></code>
</pre>
<p>If this is not possible, but something else is, please
advise.</p></div>Joel Traugertag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T18:57:30Z2014-06-04T18:57:30ZEncase <a href="mailto"></a> links in javascript<div><p>Thank you for the clarification, Joel.</p>
<p>Based on your description, I believe it may be more beneficial
to use an XSLT Format that is applied to the Configuration Set or
Template. Because these Formats are applied during the final stages
of page rendering, this Format would be able to essentially
transform ALL <code><a></code> tags containing
<strong>mailto:</strong> within the <code>href</code> attribute on
the rendered page.</p>
<p>Let me see if I work on some sample code for you to try out.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T19:31:39Z2014-06-04T19:31:39ZEncase <a href="mailto"></a> links in javascript<div><p>Hi Joel,</p>
<p>When you have a moment, try attaching the following XSLT Format
to either your Page's Output, Configuration Set, or Template and
let me know how it works out for you.</p>
<pre>
<code><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<!-- This template will replace an email link with JavaScript. -->
<xsl:template match="xhtml:a[contains(@href, 'mailto:')]|a[contains(@href, 'mailto:')]">
<xsl:variable name="email" select="substring-after(@href, 'mailto:')"/>
<xsl:variable name="emailLocal" select="substring-before($email, '@')"/>
<xsl:variable name="emailDomain" select="substring-after($email, '@')"/>
<script type="text/javascript"><xsl:comment>#protect
var e = ['<xsl:value-of select="$emailLocal"/>','<xsl:value-of select="$emailDomain"/>'];
document.write('&lt;a href="mailto:' + e.join("@") + '"&gt;' + '<xsl:value-of select="."/>' + '&lt;/a&gt;');
#protect</xsl:comment></script>
<xsl:comment>The script on this page is to help protect against spam</xsl:comment>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:head|head">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet></code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T19:35:45Z2014-06-04T19:35:45ZEncase <a href="mailto"></a> links in javascript<div><p>I will try this and report back if it works like I intended.</p></div>Joel Traugertag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T19:55:03Z2014-06-04T19:55:03ZEncase <a href="mailto"></a> links in javascript<div><p>It works amazingly well.</p>
<p>There are a few slight tweaks I'd like to perform so the end
result looks better on our page code, but other than that, this is
exactly what I needed.</p>
<p>Thanks so much for your help!</p></div>Joel Traugertag:help-archives.hannonhill.com,2010-02-09:Comment/332702372014-06-04T20:05:07Z2014-06-04T20:05:07ZEncase <a href="mailto"></a> links in javascript<div><p>Thank you for following up, Hank. I am glad to hear the XSLT
Format did the trick.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffith