<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; javascript</title>
	<atom:link href="http://blog.jayway.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Tue, 20 Jul 2010 08:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating a TinyMce plugin for a Wicket application</title>
		<link>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/</link>
		<comments>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:17:19 +0000</pubDate>
		<dc:creator>Rickard Nilsson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2009</guid>
		<description><![CDATA[I'm currently working on a web project based on Wicket. In this web project there was a request for a web based word processor. TinyMce fits the bill perfectly and as it happens is also integrated in Wicket. Lucky me! Another request required me to make my own plugin for TinyMce. Only, it turned out [...]]]></description>
			<content:encoded><![CDATA[<p>I'm currently working on a web project based on Wicket. In this web project there was a request for a web based word processor. TinyMce fits the bill perfectly and as it happens is also integrated in Wicket. Lucky me! </p>
<p>Another request required me to make my own plugin for TinyMce. Only, it turned out it's not the simplest thing to do, adding a plugin to TinyMce when it's integrated to Wicket. There is almost no help on how to do this so, after having fiddled with this for some time I thought I should help all other plugin creators out there.</p>
<p>Here we'll make a very redundant BoldMakerPlugin just because it's so easy to se it working. I'm assuming that you've got Wicket and also that you have managed to get TinyMce running, if you haven't it's just a matter of cut and paste from <a href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-tinymce">WicketStuffs TinyMce page</a>. </p>
<p>To create a plugin you will need two files. Your plugin java file and an editor_plugin_src.js file. I placed my java file among the other wicket java files under src/main/java and named it BoldMakerPlugin.java. This is what it looks like.</p>
<p><code></p>
<pre class="java">&nbsp;
<span style="color: #a1a100;">import wicket.contrib.tinymce.settings.Plugin;</span>
<span style="color: #a1a100;">import wicket.contrib.tinymce.settings.PluginButton;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BoldMakerPlugin <span style="color: #000000; font-weight: bold;">extends</span> Plugin<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> PluginButton boldMakerButton;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> BoldMakerPlugin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;boldmaker&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//decides which plugin folder to look in.</span>
		boldMakerButton = <span style="color: #000000; font-weight: bold;">new</span> PluginButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;boldmakerbutton&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> PluginButton getBoldMakerButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> boldMakerButton;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p></code></p>
<p>Next I have to fool the TinyMce main script that my plugins JavaScript file is actually located in the same location as the other scripts. I do this by creating a package structure that is similar to what the TinyMce jar file uses. In this case I create a package called wicket.contrib.tinymce.tiny_mce.plugins.boldmaker and put it in src/main/resources. The last package should be similar to whatever you insert into your superclass from your java file.</p>
<p>In this location I put my editor_plugin_src.js file. Mine looks like this:</p>
<p><CODE></p>
<pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> DOM = tinymce.<span style="color: #006600;">DOM</span>;
&nbsp;
	tinymce.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'tinymce.plugins.BoldMakerPlugin'</span>, <span style="color: #66cc66;">&#123;</span>
		init : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>ed, url<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> t = <span style="color: #000066; font-weight: bold;">this</span>, s = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
			t.<span style="color: #006600;">editor</span> = ed;
&nbsp;
			<span style="color: #009900; font-style: italic;">// Register commands</span>
			ed.<span style="color: #006600;">addCommand</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'mceBoldMaker'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> win, de = DOM.<span style="color: #006600;">doc</span>.<span style="color: #006600;">documentElement</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #009900; font-style: italic;">// Register buttons</span>
			ed.<span style="color: #006600;">addButton</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'boldmakerbutton'</span>, <span style="color: #66cc66;">&#123;</span>title : <span style="color: #3366CC;">'Test'</span>, cmd : <span style="color: #3366CC;">'mceBoldMaker'</span>, image : url + <span style="color: #3366CC;">'/../test/img/example.gif'</span>,
         	   onclick: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         	   		ed.<span style="color: #006600;">selection</span>.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&lt;b&gt;&quot;</span> + ed.<span style="color: #006600;">selection</span>.<span style="color: #006600;">getContent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">&quot;&lt;/b&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
            	<span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// Register plugin</span>
	tinymce.<span style="color: #006600;">PluginManager</span>.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'boldmaker'</span>, tinymce.<span style="color: #006600;">plugins</span>.<span style="color: #006600;">BoldMakerPlugin</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p></CODE></p>
<p>Don't worry if you don't have a button image just yet, it'll be an invisible button with the plugin functionality.</p>
<p>After having done this you should compress it using some kind of JavaScript compressor. I used the one on <a href="http://javascriptcompressor.com/">http://javascriptcompressor.com/</a><br />
Create a new file, name it “editor_plugin.js” and paste your newly compressed JavaScript into it.</p>
<p>I'm adding my plugin in a InPlaceEditComponent instead of in a TextArea but the basics are the same. Add your plugin to the TinyMCESettings, add the settings to the component and then add your component to your page.</p>
<p><CODE></p>
<pre class="java">&nbsp;
InPlaceEditComponent component = <span style="color: #000000; font-weight: bold;">new</span> InPlaceEditComponent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;editable&quot;</span>, <span style="color: #ff0000;">&quot;
&lt;h4 class='headline' style='color: black; font-weight: bold; font-family: sans-serif; font-size: 80%;'&gt;Insert headline here&lt;/h4&gt;
&nbsp;
&quot;</span> +
<span style="color: #ff0000;">&quot;&lt;span class='standardText' style='color: black; font-family: sans-serif; font-size: 80%;'&gt;Insert text here&lt;/span&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
TinyMCESettings settings=component.<span style="color: #006600;">getSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
BoldMakerPlugin boldMakerPlugin=<span style="color: #000000; font-weight: bold;">new</span> BoldMakerPlugin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
settings.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span>boldMakerPlugin.<span style="color: #006600;">getBoldMakerButton</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Toolbar.<span style="color: #006600;">first</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3APosition+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Position</span></a>.<span style="color: #006600;">before</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
component.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InPlaceEditBehavior<span style="color: #66cc66;">&#40;</span>settings, component<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
item.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span>component<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p></CODE></p>
<p>If you've done everything correctly you should now be able to run your application and get your very first plugin working.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wicket Javascript Internals dissected</title>
		<link>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/</link>
		<comments>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 13:20:25 +0000</pubDate>
		<dc:creator>Nino Martinez</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=290</guid>
		<description><![CDATA[SO you need to do something special with a javascript and you want to integrate that with wicket. In my last article I looked at this from the wicket side and wrote about what you can do to push something out from wicket. But what if you want to interact? Then you will have to take a peek at wickets javascript internals. If you are working on an ajax component you get these wicket javascript source files included as default [...]]]></description>
			<content:encoded><![CDATA[<p>SO you need to do something special with a javascript and you want to integrate that with wicket. In my <a href="http://ninomartinez.wordpress.com/2008/09/09/apache-wicket-javascript-integration/">last article</a> I looked at this from the wicket side and wrote about what you can do to push something out from wicket. But what if you want to interact? Then you will have to take a peek at wickets javascript internals. If you are working on an ajax component you get these wicket javascript source files included as default:</p>
<ol>
<li>wicket-event.js</li>
<li>wicket-ajax.js</li>
</ol>
<h3>wicket-event.js</h3>
<p>This file contains everything Wicket needs for event handling, but also methods for detecting browser like Wicket.Browser.isIELessThan7() which could come in handy if youre doing your own script, no need to write it again.. </p>
<h3>wicket-ajax.js</h3>
<p>This file hold everything Wicket needs for doing ajax. So it's a big file containing a lot of interesting possibilities.</p>
<p>The most interesting method are wicketAjaxGet its the way to contact the server doing ajax. It's signature are this:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> wicketAjaxGet<span style="color: #66cc66;">&#40;</span>url, successHandler, failureHandler, precondition, channel<span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>The first parameter are the url for wicketAjaxGet to call server side with, it usually gets generated from serverside, and you can add parameters to it and get them server side. Furthermore it takes 3 functions and a channel. Channel are also usually populated for you so dont think about that. The functions however are called either on sucess, failure or as a precondition. These supply very nice options for you if you need to do something special with the result of the wicketAjaxGet you can put in callbacks. Small example from the mooTip ajax integration:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> mootipAjaxtooltip022<span style="color: #66cc66;">&#40;</span>callback<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> content=<span style="color: #3366CC;">''</span>;wicketAjaxGet<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'?wicket:interface=:0:tooltip02::IBehaviorListener:1:'</span>,
 <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> tip=document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'mooTipContent'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span>;
 <span style="color: #003366; font-weight: bold;">var</span> callbackInside=callback;
 <span style="color: #003366; font-weight: bold;">var</span> runCallback=  callbackInside.<span style="color: #006600;">pass</span><span style="color: #66cc66;">&#40;</span>tip<span style="color: #66cc66;">&#41;</span>;
 runCallback<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
, <span style="color: #003366; font-weight: bold;">null</span>,<span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>As you can see, if you count the parameters, I put in a success method for wicket to call once the request has finished, in this case it sets up a tooltip and displays it, by a method thats passed along using the content of the dom element called 'mooTipContent'.</p>
<p>Theres also lighter methods like for example wicketHide and wicketshow. Methods for manipulating visibility of dom objects. Theres many more functions in there. But these should get you going.</p>
<h3>The complete package</h3>
<p>A small example that shows a invisible veil when a abstractajaxTimerEventBehavior is called:</p>
<pre class="javascript">&nbsp;
css/html:
#veil<span style="color: #66cc66;">&#123;</span>
position:absolute;top:<span style="color: #CC0000;">0</span>;left:<span style="color: #CC0000;">0</span>;
 width:<span style="color: #CC0000;">100</span>%;height:<span style="color: #CC0000;">100</span>%;
 z-index: <span style="color: #CC0000;">99</span>;
 <span style="color: #009900; font-style: italic;">/*cursor: wait;*/</span>
 <span style="color: #66cc66;">&#125;</span>
&lt;<span style="color: #3366CC;">&quot;p id=&quot;</span>veil<span style="color: #3366CC;">&quot; style='display: none;' &quot;</span>&gt;&lt;<span style="color: #3366CC;">&quot;/p&quot;</span>&gt;
Java:
		AbstractAjaxTimerBehavior ajaxTimerBehavior = <span style="color: #003366; font-weight: bold;">new</span> AbstractAjaxTimerBehavior<span style="color: #66cc66;">&#40;</span>
				Duration.<span style="color: #006600;">seconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			@Override
			<span style="color: #003366; font-weight: bold;">protected</span> CharSequence getCallbackScript<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// TODO Auto-generated method stub</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;wicketShow('veil');&quot;</span> + <span style="color: #003366; font-weight: bold;">super</span>.<span style="color: #006600;">getCallbackScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			@Override
			<span style="color: #003366; font-weight: bold;">protected</span> CharSequence getSuccessScript<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// TODO Auto-generated method stub</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;wicketHide('veil');&quot;</span> + <span style="color: #003366; font-weight: bold;">super</span>.<span style="color: #006600;">getSuccessScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
....
&nbsp;</pre>
<p>And thats it, now you should be ready to do your own stuff <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
