<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Really Simple Live Comment Preview</title>
	<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview</link>
	<description>Getting to know the library of choice for unobtrusive JavaScript</description>
	<pubDate>Fri, 29 Aug 2008 00:03:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: vik</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1877</link>
		<dc:creator>vik</dc:creator>
		<pubDate>Thu, 25 Jan 2007 18:07:35 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1877</guid>
		<description>Muy Cool, se ve &lt;strong&gt; bien...&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>Muy Cool, se ve <strong> bien&#8230;</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: justatest</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1611</link>
		<dc:creator>justatest</dc:creator>
		<pubDate>Sun, 21 Jan 2007 21:37:50 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1611</guid>
		<description>Bold
Kursiv
Link
Code
Em
Paragraf
Gjennomstrek
sterk</description>
		<content:encoded><![CDATA[<p>Bold<br />
Kursiv<br />
Link<br />
Code<br />
Em<br />
Paragraf<br />
Gjennomstrek<br />
sterk</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: test</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1547</link>
		<dc:creator>test</dc:creator>
		<pubDate>Fri, 19 Jan 2007 12:35:02 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-1547</guid>
		<description>&lt;b&gt;Bold&lt;/b&gt;
&lt;i&gt;Kursiv&lt;/i&gt;
&lt;a href="" rel="nofollow"&gt;Link&lt;/a&gt;
&lt;code&gt;Code&lt;/code&gt;
&lt;em&gt;Em&lt;/em&gt;
Paragraf
&lt;strike&gt;Gjennomstrek&lt;/strike&gt;
&lt;strong&gt;sterk&lt;/strong&gt;
&lt;blockquote cite=""&gt; heisann &lt;/blockquote&gt;
sdsd</description>
		<content:encoded><![CDATA[<p><b>Bold</b><br />
<i>Kursiv</i><br />
<a href="" rel="nofollow">Link</a><br />
<code>Code</code><br />
<em>Em</em><br />
Paragraf<br />
<strike>Gjennomstrek</strike><br />
<strong>sterk</strong></p>
<blockquote cite=""><p> heisann </p></blockquote>
<p>sdsd</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-329</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Sun, 17 Dec 2006 21:30:43 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-329</guid>
		<description>Mooffie,

Wow, thank you so much for your detailed, carefully constructed comment! 
&lt;blockquote&gt;&lt;p&gt;That is, DIVs and TABLEs are illegal inside P.&lt;/p&gt;&lt;/blockquote&gt;
Of course! D'oh! I should have known that's what was going on there.
&lt;blockquote&gt;&lt;p&gt;BTW, you regexp catches "&#60;script" but it fails to catch "&#x3c;Script", "&#x3c; script", "onevent='...'" and "href='javascript:...'".&lt;/p&gt;&lt;/blockquote&gt;
True. It was clearly not a robust solution. And I agree that using WordPress's (or any other blog platform/CMS's) parser would be better. I guess that's one of the reasons I call this "Really Simple." :)
&lt;blockquote&gt;&lt;p&gt;You should mention, that for almost any event there is a corresponding oneevent(). Why is this so important? So that people know this is not a special case. I hate libraries with unnecessary special cases.&lt;/blockquote&gt;
You are correct here, too. I will update the entry to include that information. It might also be worth noting that the syntax for the "one..." events might be changing when 1.1 is released.
&lt;blockquote&gt;&lt;p&gt;Hmmm... I don't get it. The first line gets rid of any \n. So the second line doesn't see them.&lt;/p&gt;&lt;/blockquote&gt;
Ah, you're right again. If I switch the order, though, I can prevent the appearance of multiple (3 or more) line breaks. that's what I had intended, and it worked at one point, so I must have switched them around at some point inadvertently. Good catch!
&lt;blockquote&gt;&lt;p&gt;(And you may have to replace any "\n" with "\r?\n". And there are Macs too...)&lt;/p&gt;&lt;/blockquote&gt;
I can do that. It works fine on my Macs with just the "\n", but there might be some edge cases that don't work.
&lt;blockquote&gt;&lt;p&gt;Why is a "\" preceeding the "&#60;" ? Another issue of your highlighter?&lt;/p&gt;&lt;/blockquote&gt;
Nope, must have been a typo. 

Thanks again, Mooffie, for leaving such an excellent reply! I really appreciate the suggestions.</description>
		<content:encoded><![CDATA[<p>Mooffie,</p>
<p>Wow, thank you so much for your detailed, carefully constructed comment! </p>
<blockquote><p>That is, DIVs and TABLEs are illegal inside P.</p>
</blockquote>
<p>Of course! D&#8217;oh! I should have known that&#8217;s what was going on there.</p>
<blockquote><p>BTW, you regexp catches &#8220;&lt;script&#8221; but it fails to catch &#8220;&#x3c;Script&#8221;, &#8220;&#x3c; script&#8221;, &#8220;onevent=&#8217;&#8230;&#8217;&#8221; and &#8220;href=&#8217;javascript:&#8230;&#8217;&#8221;.</p>
</blockquote>
<p>True. It was clearly not a robust solution. And I agree that using WordPress&#8217;s (or any other blog platform/CMS&#8217;s) parser would be better. I guess that&#8217;s one of the reasons I call this &#8220;Really Simple.&#8221; <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>You should mention, that for almost any event there is a corresponding oneevent(). Why is this so important? So that people know this is not a special case. I hate libraries with unnecessary special cases.</p>
</blockquote>
<p>You are correct here, too. I will update the entry to include that information. It might also be worth noting that the syntax for the &#8220;one&#8230;&#8221; events might be changing when 1.1 is released.</p>
<blockquote><p>Hmmm&#8230; I don&#8217;t get it. The first line gets rid of any \n. So the second line doesn&#8217;t see them.</p>
</blockquote>
<p>Ah, you&#8217;re right again. If I switch the order, though, I can prevent the appearance of multiple (3 or more) line breaks. that&#8217;s what I had intended, and it worked at one point, so I must have switched them around at some point inadvertently. Good catch!</p>
<blockquote><p>(And you may have to replace any &#8220;\n&#8221; with &#8220;\r?\n&#8221;. And there are Macs too&#8230;)</p>
</blockquote>
<p>I can do that. It works fine on my Macs with just the &#8220;\n&#8221;, but there might be some edge cases that don&#8217;t work.</p>
<blockquote><p>Why is a &#8220;\&#8221; preceeding the &#8220;&lt;&#8221; ? Another issue of your highlighter?</p>
</blockquote>
<p>Nope, must have been a typo. </p>
<p>Thanks again, Mooffie, for leaving such an excellent reply! I really appreciate the suggestions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mooffie</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-319</link>
		<dc:creator>Mooffie</dc:creator>
		<pubDate>Sun, 17 Dec 2006 11:31:44 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-319</guid>
		<description>Karl,

Thank you for creating this useful website.

&lt;blockquote&gt;I initially created the preview box immediately after the textarea, still within the paragraph, but Internet Explorer 6 did not like that one bit. The preview text wouldn't appear [...]
&lt;/blockquote&gt;

Because block-level elements are not allowed inside P.
That is, DIVs and TABLEs are illegal inside P.

&lt;blockquote&gt;[...] but I can't see how there would be any more of a security issue here than, say, if someone had the Grease Monkey Firefox extension installed.
&lt;/blockquote&gt;

I believe you're correct. I'm using Opera, which allows me to easily edit-and-reload any page I see.

BTW, you regexp catches "&#60;script" but it fails to catch "&#60;Script", "&#60;&#160;script", "on&lt;em&gt;event&lt;/em&gt;='...'" and "href='javascript:...'".

Mary said:
&lt;blockquote&gt;[...] it would be easy to use jQuery to pass the comment preview to a script, which could run KSES (the markup cleaning script WordPress uses) on the comment preview, and then include it in the page source.
&lt;/blockquote&gt;

Marry, this is an excellent idea. But not only beacause of some possible security hole.

This idea, of round-tripping to the server to get the displayed HTML, has an important advantage:

HTML is not the only format for user input. I'm using Drupal, where lots of other "input formats" are possible. Users can use Wiki, AsciiMath, BBCode, Tex, Textile, SmartyPants, CSV, Opus, whatever, and the browser itself &lt;em&gt;doesn't know&lt;/em&gt; these languages.

In fact, HTML is not even WordPress' input format! WordPress' input format is: &lt;em&gt;filtered HTML&lt;/em&gt;. That is, not all tags are allowed. I could type a TABLE tag here and see it in the preview box, but WordPress would throw it out anyway...

And I believe WordPress also converts URLs into links and smilies into icons. You don't see this in the preview. In other words, your preview is very "low fidelity".

So Marry's idea is good for CMSs like WordPress too.

&lt;blockquote&gt;Fortunately, jQuery has a "onefocus" event handler, which, as the name makes painfully clear, is executed only once
&lt;/blockquote&gt;

You should mention, that for almost &lt;em&gt;any&lt;/em&gt; event there is a corresponding one&lt;em&gt;event&lt;/em&gt;(). Why is this so important? So that people know this is &lt;em&gt;not a special case&lt;/em&gt;. I hate libraries with unnecessary special cases.

&lt;blockquote&gt;We're going to make everything inside the comment textarea appear inside the "live-preview" DIV as  it is being typed.
[...]
for this type of job. I used keyup
&lt;/blockquote&gt;

My Opera, for some reason, doesn't trigger this event for "special" keys like BACKSPACE, ENTER and... SPACE. Word has it that BACKSPACE does't trigger &lt;em&gt;keyup&lt;/em&gt; on IE either (sorry I can't verify this claim).

This problem doesn't seem to occur for the &lt;em&gt;keydown&lt;/em&gt; and &lt;em&gt;keypress&lt;/em&gt; events. Are these two events triggered before or after the textarea's content is modified? If before, Mary's &lt;em&gt;timeout&lt;/em&gt; idea would solve the problem. 

&lt;blockquote&gt;$comment = $comment.replace(/\n/g, "&#60;br /&#62;");
$comment = $comment.replace(/\n\n+/g, '&#60;br /&#62;&#60;br /&#62;');
&lt;/blockquote&gt;

Hmmm... I don't get it. The first line gets rid of any \n. So the second line doesn't see them.

(And you may have to replace any "\n" with "\r?\n". And there are Macs too...)

&lt;blockquote&gt;replace(/(\&#38;lt;\/?)script/g,
&lt;/blockquote&gt;

Why is a "\" preceeding the "&#38;lt;" ? Another issue of your highligher?
BTW, if you use "\x3C" instead of "&#38;lt;" users won't have to change anything after they paste your code.</description>
		<content:encoded><![CDATA[<p>Karl,</p>
<p>Thank you for creating this useful website.</p>
<blockquote><p>I initially created the preview box immediately after the textarea, still within the paragraph, but Internet Explorer 6 did not like that one bit. The preview text wouldn&#8217;t appear [&#8230;]
</p></blockquote>
<p>Because block-level elements are not allowed inside P.<br />
That is, DIVs and TABLEs are illegal inside P.</p>
<blockquote><p>[&#8230;] but I can&#8217;t see how there would be any more of a security issue here than, say, if someone had the Grease Monkey Firefox extension installed.
</p></blockquote>
<p>I believe you&#8217;re correct. I&#8217;m using Opera, which allows me to easily edit-and-reload any page I see.</p>
<p>BTW, you regexp catches &#8220;&lt;script&#8221; but it fails to catch &#8220;&lt;Script&#8221;, &#8220;&lt;&nbsp;script&#8221;, &#8220;on<em>event</em>=&#8217;&#8230;&#8217;&#8221; and &#8220;href=&#8217;javascript:&#8230;&#8217;&#8221;.</p>
<p>Mary said:</p>
<blockquote><p>[&#8230;] it would be easy to use jQuery to pass the comment preview to a script, which could run KSES (the markup cleaning script WordPress uses) on the comment preview, and then include it in the page source.
</p></blockquote>
<p>Marry, this is an excellent idea. But not only beacause of some possible security hole.</p>
<p>This idea, of round-tripping to the server to get the displayed HTML, has an important advantage:</p>
<p>HTML is not the only format for user input. I&#8217;m using Drupal, where lots of other &#8220;input formats&#8221; are possible. Users can use Wiki, AsciiMath, BBCode, Tex, Textile, SmartyPants, CSV, Opus, whatever, and the browser itself <em>doesn&#8217;t know</em> these languages.</p>
<p>In fact, HTML is not even WordPress&#8217; input format! WordPress&#8217; input format is: <em>filtered HTML</em>. That is, not all tags are allowed. I could type a TABLE tag here and see it in the preview box, but WordPress would throw it out anyway&#8230;</p>
<p>And I believe WordPress also converts URLs into links and smilies into icons. You don&#8217;t see this in the preview. In other words, your preview is very &#8220;low fidelity&#8221;.</p>
<p>So Marry&#8217;s idea is good for CMSs like WordPress too.</p>
<blockquote><p>Fortunately, jQuery has a &#8220;onefocus&#8221; event handler, which, as the name makes painfully clear, is executed only once
</p></blockquote>
<p>You should mention, that for almost <em>any</em> event there is a corresponding one<em>event</em>(). Why is this so important? So that people know this is <em>not a special case</em>. I hate libraries with unnecessary special cases.</p>
<blockquote><p>We&#8217;re going to make everything inside the comment textarea appear inside the &#8220;live-preview&#8221; DIV as  it is being typed.<br />
[&#8230;]<br />
for this type of job. I used keyup
</p></blockquote>
<p>My Opera, for some reason, doesn&#8217;t trigger this event for &#8220;special&#8221; keys like BACKSPACE, ENTER and&#8230; SPACE. Word has it that BACKSPACE does&#8217;t trigger <em>keyup</em> on IE either (sorry I can&#8217;t verify this claim).</p>
<p>This problem doesn&#8217;t seem to occur for the <em>keydown</em> and <em>keypress</em> events. Are these two events triggered before or after the textarea&#8217;s content is modified? If before, Mary&#8217;s <em>timeout</em> idea would solve the problem. </p>
<blockquote><p>$comment = $comment.replace(/\n/g, &#8220;&lt;br /&gt;&#8221;);<br />
$comment = $comment.replace(/\n\n+/g, &#8216;&lt;br /&gt;&lt;br /&gt;&#8217;);
</p></blockquote>
<p>Hmmm&#8230; I don&#8217;t get it. The first line gets rid of any \n. So the second line doesn&#8217;t see them.</p>
<p>(And you may have to replace any &#8220;\n&#8221; with &#8220;\r?\n&#8221;. And there are Macs too&#8230;)</p>
<blockquote><p>replace(/(\&amp;lt;\/?)script/g,
</p></blockquote>
<p>Why is a &#8220;\&#8221; preceeding the &#8220;&amp;lt;&#8221; ? Another issue of your highligher?<br />
BTW, if you use &#8220;\x3C&#8221; instead of &#8220;&amp;lt;&#8221; users won&#8217;t have to change anything after they paste your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-224</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Wed, 13 Dec 2006 16:44:15 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-224</guid>
		<description>Wanted to see my live preview... very interesting... jQuery makes a lot of things possible, even for non-Javascript programmers like myself!

Rick</description>
		<content:encoded><![CDATA[<p>Wanted to see my live preview&#8230; very interesting&#8230; jQuery makes a lot of things possible, even for non-Javascript programmers like myself!</p>
<p>Rick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jammodotnet</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-185</link>
		<dc:creator>jammodotnet</dc:creator>
		<pubDate>Fri, 08 Dec 2006 17:23:35 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-185</guid>
		<description>this is really neat.
i run expression engine for a few of my sites.

id like to try to implement this technique to display a live comment preview, complete with the commenter's information that would be inserted INTO the post itself (ie: name, time/date stamp, etc).

i love jQuery more and more.
:)</description>
		<content:encoded><![CDATA[<p>this is really neat.<br />
i run expression engine for a few of my sites.</p>
<p>id like to try to implement this technique to display a live comment preview, complete with the commenter&#8217;s information that would be inserted INTO the post itself (ie: name, time/date stamp, etc).</p>
<p>i love jQuery more and more.<br />
 <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kevin</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-167</link>
		<dc:creator>kevin</dc:creator>
		<pubDate>Wed, 06 Dec 2006 20:25:18 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-167</guid>
		<description>thats's pretty awesome. nice &lt;a href="#" rel="nofollow"&gt;job&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>thats&#8217;s pretty awesome. nice <a href="#" rel="nofollow">job</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikolei</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-160</link>
		<dc:creator>Nikolei</dc:creator>
		<pubDate>Tue, 05 Dec 2006 15:10:20 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-160</guid>
		<description>Cool. :)</description>
		<content:encoded><![CDATA[<p>Cool. <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mary</title>
		<link>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-137</link>
		<dc:creator>Mary</dc:creator>
		<pubDate>Fri, 24 Nov 2006 04:58:55 +0000</pubDate>
		<guid>http://www.learningjquery.com/2006/11/really-simple-live-comment-preview#comment-137</guid>
		<description>I'm not &lt;em&gt;entirely&lt;/em&gt; certain what the commenter's reference to "Koolaid" is supposed to mean, but my response is: If I am wrong, correct me. If you don't understand what I'm talking about, then you've got no business saying anything about it, now do you? :)

Karl,

The difference is that users don't &lt;em&gt;typically&lt;/em&gt; use GreaseMonkey to silently &lt;em&gt;attack&lt;/em&gt; third-party sites (visit one site to execute scripts on another). There may be those who do, but we certainly don't want to make this kind of thing easier for them (like making it look like &lt;em&gt;your site&lt;/em&gt; is the one doing the attacking, rather than the actual bozo). Instead of me trying to repeat what others have explained better, you can do &lt;a href="http://google.com/search?q=cross+site+request+forgery" rel="nofollow"&gt;a Google search on the topic&lt;/a&gt; and you'll find out the principles of how it works, if you're not familiar with it. Brian Miller has given a nice summary above of how it could be done here.

As to Brian's proposed solution: off the top of my head, that would certainly work, I think.

My suggestion was based upon my own perspective, that it would be easy to use jQuery to pass the comment preview to a script, which could run KSES (the markup cleaning script WordPress uses) on the comment preview, and &lt;em&gt;then&lt;/em&gt; include it in the page source. If done &lt;em&gt;that&lt;/em&gt; way, you could save on server requests by either putting a timeout on the preview, or by adding a Preview button (clicking the button runs/updates the live preview on the page). You can see the latter being done in &lt;a href="http://getvanilla.com/" rel="nofollow"&gt;Vanilla&lt;/a&gt;, for example. I personally find it just as convenient as a letter-by-letter update.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not <em>entirely</em> certain what the commenter&#8217;s reference to &#8220;Koolaid&#8221; is supposed to mean, but my response is: If I am wrong, correct me. If you don&#8217;t understand what I&#8217;m talking about, then you&#8217;ve got no business saying anything about it, now do you? <img src='http://www.learningjquery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Karl,</p>
<p>The difference is that users don&#8217;t <em>typically</em> use GreaseMonkey to silently <em>attack</em> third-party sites (visit one site to execute scripts on another). There may be those who do, but we certainly don&#8217;t want to make this kind of thing easier for them (like making it look like <em>your site</em> is the one doing the attacking, rather than the actual bozo). Instead of me trying to repeat what others have explained better, you can do <a href="http://google.com/search?q=cross+site+request+forgery" rel="nofollow">a Google search on the topic</a> and you&#8217;ll find out the principles of how it works, if you&#8217;re not familiar with it. Brian Miller has given a nice summary above of how it could be done here.</p>
<p>As to Brian&#8217;s proposed solution: off the top of my head, that would certainly work, I think.</p>
<p>My suggestion was based upon my own perspective, that it would be easy to use jQuery to pass the comment preview to a script, which could run KSES (the markup cleaning script WordPress uses) on the comment preview, and <em>then</em> include it in the page source. If done <em>that</em> way, you could save on server requests by either putting a timeout on the preview, or by adding a Preview button (clicking the button runs/updates the live preview on the page). You can see the latter being done in <a href="http://getvanilla.com/" rel="nofollow">Vanilla</a>, for example. I personally find it just as convenient as a letter-by-letter update.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
