<?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>Peter Gerritsen&#039;s blog &#187; JavaScript</title>
	<atom:link href="http://blog.petergerritsen.nl/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.petergerritsen.nl</link>
	<description>about .Net and SharePoint development</description>
	<lastBuildDate>Wed, 28 Jul 2010 08:28:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Building an AJAX web part with jQuery (Part 3)</title>
		<link>http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 13:36:35 +0000</pubDate>
		<dc:creator>Peter Gerritsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MOSS]]></category>

		<guid isPermaLink="false">http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/</guid>
		<description><![CDATA[In part 1 of this series I explained a bit about the context and goal of creating an AJAX web part without using ASP.Net AJAX. I also showed the steps necessary for creating services that return data in the JSON format. In part 2 I showed you how to call these services from JavaScript and render the HTML for the [...]<p><a href="http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/">Building an AJAX web part with jQuery (Part 3)</a> is a post from: <a href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In <a  href="http://blog.petergerritsen.nl/2009/03/30/building-an-ajax-web-part-with-jquery-part-1/">part 1</a> of this series I explained a bit about the context and goal of creating an AJAX web part without using ASP.Net AJAX. I also showed the steps necessary for creating services that return data in the JSON format. In <a  href="http://blogs.tamtam.nl/peterg/2009/03/31/BuildingAnAJAXWebPartWithJQueryPart2.aspx" target="_blank">part 2</a> I showed you how to call these services from JavaScript and render the HTML for the data. In this last part I’ll show you how to use the jQuery UI and validation plugins.</p>
<h4>jQuery UI</h4>
<p>The <a  href="http://jqueryui.com/home" target="_blank">jQuery UI</a> plugin provides some useful widgets and effects to use in your jQuery based scripts. It also offers an advanced theme framework, so you don’t have to write all the css by yourself. You can use one of the included theme’s or roll your own with the <a  href="http://jqueryui.com/themeroller/" target="_blank">ThemeRoller</a>.</p>
<p>I’ve decided to use the UI plugin for tree things in my web part:</p>
<ul>
<li> Datepicker widget to specify the orderdate</li>
<li> Dialog widget to show confirmation dialogs, edit forms and validation messages</li>
<li> Highlighting effect to focus the users attention to changing data, such as the shoppingcart</li>
</ul>
<p><strong>Datepicker</strong></p>
<p>The datepicker enhances a standard text input box with a datapicker that slides out when the textbox receives focus. It contains different options for specifying the allowed dates, year/month selection and more. When it’s shown it will look like this:</p>
<p><a  href="http://blog.petergerritsen.nl/wp-content/uploads/snipping20.png" class="thickbox no_icon" rel="gallery-558" title="image"><img style="border-width: 0px; display: inline;" title="image" src="http://blog.petergerritsen.nl/wp-content/uploads/snipping21.png" border="0" alt="image" /></a></p>
<p>Linking it to your input box is very simple. I use the following code:</p>
<pre class="brush: javascript">
$(&quot;#bpvorderdate&quot;).datepicker({
showOn: &#039;button&#039;,
minDate: +1, dateFormat: &#039;dd/mm/yy&#039;,
buttonImage: &#039;/_layouts/images/calendar.gif&#039;,
buttonImageOnly: true
});
</pre>
<p>In this case, the user has to press a button (in this case an imagebutton) to open the datepicker.</p>
<p><strong>Dialogs</strong></p>
<p>Dialogs are a very useful way to give feedback to the user or asking for confirmation. In my web part I want to show a confirmation dialog when a user presses the delete icon next to a product in the shoppingcart or the “clear shoppingcart” button. The user will be presented with the following dialog:</p>
<p><a  href="http://blog.petergerritsen.nl/wp-content/uploads/snipping22.png" class="thickbox no_icon" rel="gallery-558" title="image"><img style="border-width: 0px; display: inline;" title="image" src="http://blog.petergerritsen.nl/wp-content/uploads/snipping23.png" border="0" alt="image" /></a></p>
<p>Showing this is very easy. First we create a function that is called when the page is initialized:</p>
<pre class="brush: javascript">
function initializeDeleteItemDialog() {
var doOk= function() {
var paramsdata = {
&quot;productId&quot; : $(&quot;#bpvremoveitemid&quot;).val()
}
$.ajax({
type: &quot;POST&quot;, url: &quot;/_layouts/intranet2009/bpvshoppingcart.asmx/DeleteItem&quot;,
data: JSON.stringify(paramsdata),
contentType: &quot;application/json;charset=utf-8&quot;,
dataType: &quot;json&quot;,
success:rendershoppingcart,
error: showError
});

$(&quot;#bpvremoveitemdialog&quot;).dialog(&quot;close&quot;);
}
var doCancel = function()
{
$(&quot;#bpvremoveitemdialog&quot;).dialog(&quot;close&quot;);
}
var dialogOpts = {
modal: true,
buttons: {&quot;Bewaren&quot;: doCancel, &quot;Verwijderen&quot;: doOk},
autoOpen: false
}
$(&quot;#bpvremoveitemdialog&quot;).dialog(dialogOpts);
}
</pre>
<p>We first specify the code to execute when the user presses the Ok button. In this case we’ll call the DeleteItem method of the shoppingcart web service and then close the dialog. The Cancel button will close the dialog straight away. In the dialog options we specify the buttons with their callback. Then we hook up the dialog to the html element we want to show. The html is written out in the Render method of the web part:</p>
<pre class="brush: javascript">
writer.WriteLine(“&lt;div id=\”bpvremoveitemdialog\” title=\”Product verwijderen?\”&gt;”);
writer.WriteLine(“Weet u zeker dat u dit product uit uw winkelwagen wilt verwijderen?”);
writer.WriteLine(“&lt;input type=\”hidden\” id=\”bpvremoveitemid\”/&gt;”);
writer.WriteLine(“&lt;/div&gt;”);
</pre>
<p>To open the dialog we just have to call the dialog method again with “open” as parameter:</p>
<pre class="brush: javascript">
function removeProduct(element) {
$(&quot;#bpvremoveitemid&quot;).val($(element).attr(&quot;productid&quot;) );
$(&quot;#bpvremoveitemdialog&quot;).dialog(&quot;open&quot;);
}
</pre>
<p><strong>Validation</strong></p>
<p>Validation of your inputs is supposed to be really easy with the <a  href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">validation plugin</a>. Unfortunately this doesn’t count when you combine it with ASP.Net Webforms. With the validation plugin you attach the validation to a form within your html. Because ASP.Net Webforms uses one form tag for the entire page, this doesn’t allow you to set validation to a group of elements that would normally be contained within their own form tag. The solution I came up with for now only validates 1 element at a time.<br />
If you now of a way to assign one validation and remove it again before assigning a new validation, let me know.</p>
<p>First we hook up all the validations we want on the form and we specify a custom validation<br />
rule, called dutchDate:</p>
<pre class="brush: javascript">
$.validator.addMethod(
&quot;dutchDate&quot;, function(value,element)
{ return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/);},
&quot;Voer een datum in van het formaat dd/mm/yyyy&quot; );
$(&quot;form&quot;).validate({
onsubmit: false,
onfocusout: false,
onkeyup: false,
onclick: false,
showErrors: showValidationError,
rules: {
bpvproductamount: {
required: true,
number: true
},
bpvproductid: {
required: true
},
bpvorderdate: {
required: true,
dutchDate: true
}
},
messages: {
bpvproductamount: {
required: &quot;Aantal is een verplicht veld&quot;,
number: &quot;Aantal moet een getal zijn&quot;
},
bpvproductid: {
required: &quot;U heeft geen product geselecteerd&quot; },
bpvorderdate: {
required: &quot;Bezorg-/ophaaldatum is een verplicht veld&quot;,
dutchDate: &quot;Bezorg-/ophaaldatum moet in het formaat dd/mm/yyyy zijn&quot;
}
}
});
</pre>
<p>I only want the validation to occur when I call it on specific elements from code, so we specify false on every event it normally triggers on. When there are errors,  I want to call a showValidationError function that shows the errors in a dialog box. Then we specify the rules and the messages we want to show when the rule isn’t matched. “bpvproductamount” equals the name attribute of the input element.</p>
<p>To call the validation we use the element method of the validation plugin:</p>
<pre class="brush: javascript">
if ($(&quot;form&quot;).validate().element(&quot;#txtbpvproductid&quot;) &amp;&amp; $(&quot;form&quot;).validate().element(&quot;#txtbpvproductamount&quot;))
{
// valid, so perfom actions
}
</pre>
<p>As soon as an element doesn’t pass validation, the method we attached to the showErrors event is called. Unfortunately this means only one error at a time will popup if multiple  elements don’t pass validation. To show the validation messages, we’ll make use of the Dialog widget once again:</p>
<pre class="brush: javascript">
function showValidationError(errorMap, errorList)
{
var message = &quot;&quot;;
var i;
for(i=0; i &lt; errorList.length; i++) {
message += errorList[i].message + &quot;&lt;br /&gt;&quot;;
}
if (message.length &gt; 0) {
showMessage(message);
}
}
</pre>
<h4>Conclusion</h4>
<p>Building an AJAX web part with jQuery (and some plugins) can result in a very responsive UI with a good user experience. In the end, I don’t think building a web part with ASP.Net AJAX would have taken me less time as well. I’m not happy with the validation though. Although the jQuery validation plugin is very useful in most web frameworks (including ASP.Net MVC), it seems that it doesn’t combine well with web forms. But I haven’t been able to find a better plugin for it.</p>
<!-- RO Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Twitter"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/twitter.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Twitter" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to Twitter" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.myspace.com/Modules/PostTo/Pages/?t=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29&#038;c=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/" title="Add 'Building an AJAX web part with jQuery (Part 3)' to MySpace"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/myspace.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to MySpace" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to MySpace" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/&#038;title=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Del.icio.us"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/delicious.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Del.icio.us" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to Del.icio.us" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&#038;url=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/&#038;title=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29" title="Add 'Building an AJAX web part with jQuery (Part 3)' to digg"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/digg.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to digg" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to digg" /></a><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/&#038;t=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29" title="Add 'Building an AJAX web part with jQuery (Part 3)' to FaceBook"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/facebook.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to FaceBook" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to FaceBook" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Technorati"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/technorati.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Technorati" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to Technorati" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/&#038;title=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Stumble Upon"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/stumbleupon.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Stumble Upon" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to Stumble Upon" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&#038;output=popup&#038;bkmk=http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/&#038;title=Building+an+AJAX+web+part+with+jQuery+%28Part+3%29" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Google Bookmarks"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/google.png" title="Add 'Building an AJAX web part with jQuery (Part 3)' to Google Bookmarks" alt="Add 'Building an AJAX web part with jQuery (Part 3)' to Google Bookmarks" /></a></div>
<!-- RO Social Bookmarks END --><p><a  href="http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/">Building an AJAX web part with jQuery (Part 3)</a> is a post from: <a  href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
<div class="fblike" style="height:25px; height:25px; overflow:hidden;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.petergerritsen.nl%2F2009%2F03%2F31%2Fbuilding-an-ajax-web-part-with-jquery-part-3%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allow Transparency="true" style="border:none; overflow:hidden; width:320px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://blog.petergerritsen.nl/2009/03/31/building-an-ajax-web-part-with-jquery-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a template plugin for jQuery to parse JSON data</title>
		<link>http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 11:47:50 +0000</pubDate>
		<dc:creator>Peter Gerritsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/</guid>
		<description><![CDATA[When you’re building an AJAX control in .Net there a a few possibilities. One of them is using AJAX.Net updatepanels. This saves you from writing tedious javascript code to refresh parts of you page. With the arrival of javascript libraries such as jQuery it’s much easier to create the AJAX functionality you want with javascript. However, you still have [...]<p><a href="http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/">Using a template plugin for jQuery to parse JSON data</a> is a post from: <a href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>When you’re building an AJAX control in .Net there a a few possibilities. One of them is using AJAX.Net updatepanels. This saves you from writing tedious javascript code to refresh parts of you page. With the arrival of javascript libraries such as jQuery it’s much easier to create the AJAX functionality you want with javascript. However, you still have to write quite a lot of DOM manipulation code and use string concatenation<br />
to process any JSON results and render the correct HTML.</p>
<p>Fortunately some javascript template engines are developed to make this easier. These engines come in all shapes and sizes, ranging from engines with an own templating syntax to simple data binding engines.</p>
<p>On the first side of the spectrum, there are engines such as <a  href="http://jtemplates.tpython.com/" target="_blank">jTemplates</a>, this one uses python like syntax to create the instructions. On the other end engines like <a  href="http://wiki.github.com/raid-ox/chain.js" target="_blank">Chain.js</a> and <a  href="http://beebole.com/pure/" target="_blank">PURE</a> live, these can be considered more a databinding egines. The last ones make use of classnames for the databinding, like in the following Chain.js example:</p>
<pre class="brush: html">
&lt;div id=&quot;quickdemo&quot;&gt;
	&lt;div class=&quot;item&quot;&gt;
		&lt;span class=&quot;library&quot;&gt;Library Name&lt;/span&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<pre class="brush: javascript">
$(&#039;#quickdemo&#039;).items( [
		{library:&#039;Prototype&#039;},
		{library:&#039;jQuery&#039;},
		{library:&#039;Dojo&#039;},
		{library:&#039;MooTools&#039;}
	]).chain();
</pre>
<p>In this case the library field in the JSON objects is put into the element with “library” in de classname. The nice thing about Chain.js is the fact that it monitors the items collection for changes. Adding or removing items from script, automatically updates the generated HTML. So filtering and sorting can be very easily accomplished, some very easy to follow examples are available on the companion website.</p>
<p>PURE uses the same classnames based system for the databinding. Consider the following example:</p>
<pre class="brush: html">
&lt;ol class=&quot;siteList reference@id&quot;&gt;
	&lt;li class=&quot;sites&quot;&gt;
		&lt;a class=&quot;name url@href&quot; href=&quot;http://beebole.com&quot;&gt;Beebole&lt;/a&gt;
	&lt;/li&gt;
&lt;/ol&gt;
</pre>
<pre class="brush: javascript">
var data = {
	&quot;reference&quot;: &quot;3456&quot;,
	&quot;sites&quot;: [{
			&quot;name&quot;: &quot;Beebole&quot;,
			&quot;url&quot;: &quot;http://beebole.com&quot;
		},
		{
			&quot;name&quot;: &quot;BeeLit&quot;,
			&quot;url&quot;: &quot;http://beeLit.com&quot;
		},
		{
			&quot;name&quot;: &quot;PURE&quot;,
			&quot;url&quot;: http://beebole.com/pure
		}]
	};
	$(&#039;ol.siteList&#039;).autoRender(data);
</pre>
<p>The <em>url@href</em> and <em>reference@id</em> classnames provide a way to set attributes of the databound elements.</p>
<p>But what if you don’t want to decorate your HTML elements with extra classnames to support the databinding? Or you want to handle some events of the generated elements?</p>
<p>For this PURE supports directives. You create your directives and pass them into the autoRender or render functions. Consider the following example:</p>
<pre class="brush: html">
&lt;div style=&quot;display: none;&quot; id=&quot;bpvcategorytemplate&quot;&gt;
	&lt;ul&gt;
		&lt;li class=&quot;context&quot;&gt;
			&lt;a category=&quot;&quot; class=&quot;context context@category&quot; href=&quot;#&quot;&gt;laden...&lt;/a&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<pre class="brush: javascript">
function showProductCategories()
{
    $.getJSON(bpvweburl + &quot;/_layouts/ecabointranet2009/bpv.ashx&quot;, {type: &quot;categories&quot;}, function(data)
    {
        var categoriescontainer = $(&quot;#bpvcategoriescontainer&quot;);
        categoriescontainer.empty();

        var list = categoriescontainer.append($(&quot;#bpvcategorytemplate&quot;).html());

        var directive = {&#039;a.context[onclick]&#039; : &#039;&quot;showProducts(this); return false;&quot;&#039;}

        list.autoRender( data, directive );
    });
}
</pre>
<p>Here we get some JSON from a handler, put the html from the template into a new element, and bind the JSON to that template. When binding the JSON data, we attach a javascript function to the onclick event of the generated anchor tags.</p>
<p>Much more can be accomplished by using directives, such as creating an alternating row style by setting a class during the binding of the items. For more information about using directives in PURE, read <a  href="http://wiki.github.com/pure/pure/what-is-a-directive" target="_blank">this</a> page.</p>
<p>There are loads more things possible in PURE or in the other engines, the best way to find out is to read the docs and try some things out.</p>
<!-- RO Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/" title="Add 'Using a template plugin for jQuery to parse JSON data' to Twitter"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/twitter.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to Twitter" alt="Add 'Using a template plugin for jQuery to parse JSON data' to Twitter" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.myspace.com/Modules/PostTo/Pages/?t=Using+a+template+plugin+for+jQuery+to+parse+JSON+data&#038;c=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/" title="Add 'Using a template plugin for jQuery to parse JSON data' to MySpace"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/myspace.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to MySpace" alt="Add 'Using a template plugin for jQuery to parse JSON data' to MySpace" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/&#038;title=Using+a+template+plugin+for+jQuery+to+parse+JSON+data" title="Add 'Using a template plugin for jQuery to parse JSON data' to Del.icio.us"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/delicious.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to Del.icio.us" alt="Add 'Using a template plugin for jQuery to parse JSON data' to Del.icio.us" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&#038;url=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/&#038;title=Using+a+template+plugin+for+jQuery+to+parse+JSON+data" title="Add 'Using a template plugin for jQuery to parse JSON data' to digg"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/digg.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to digg" alt="Add 'Using a template plugin for jQuery to parse JSON data' to digg" /></a><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/&#038;t=Using+a+template+plugin+for+jQuery+to+parse+JSON+data" title="Add 'Using a template plugin for jQuery to parse JSON data' to FaceBook"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/facebook.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to FaceBook" alt="Add 'Using a template plugin for jQuery to parse JSON data' to FaceBook" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/" title="Add 'Using a template plugin for jQuery to parse JSON data' to Technorati"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/technorati.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to Technorati" alt="Add 'Using a template plugin for jQuery to parse JSON data' to Technorati" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/&#038;title=Using+a+template+plugin+for+jQuery+to+parse+JSON+data" title="Add 'Using a template plugin for jQuery to parse JSON data' to Stumble Upon"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/stumbleupon.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to Stumble Upon" alt="Add 'Using a template plugin for jQuery to parse JSON data' to Stumble Upon" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&#038;output=popup&#038;bkmk=http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/&#038;title=Using+a+template+plugin+for+jQuery+to+parse+JSON+data" title="Add 'Using a template plugin for jQuery to parse JSON data' to Google Bookmarks"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/google.png" title="Add 'Using a template plugin for jQuery to parse JSON data' to Google Bookmarks" alt="Add 'Using a template plugin for jQuery to parse JSON data' to Google Bookmarks" /></a></div>
<!-- RO Social Bookmarks END --><p><a  href="http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/">Using a template plugin for jQuery to parse JSON data</a> is a post from: <a  href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
<div class="fblike" style="height:25px; height:25px; overflow:hidden;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.petergerritsen.nl%2F2009%2F03%2F13%2Fusing-a-template-plugin-for-jquery-to-parse-json-data%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allow Transparency="true" style="border:none; overflow:hidden; width:320px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://blog.petergerritsen.nl/2009/03/13/using-a-template-plugin-for-jquery-to-parse-json-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a 3D tagcloud in Silverlight (part 2)</title>
		<link>http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 09:49:04 +0000</pubDate>
		<dc:creator>Peter Gerritsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/</guid>
		<description><![CDATA[In part 1 I showed you how to create the basics for a 3D tagcloud in Silverlight. In this part I’ll show how to get the tags from your html for inserting it into a blog template, we’ll change the color of the tag based on the weight of the tag and let the hyperlink button actually function as [...]<p><a href="http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/">Creating a 3D tagcloud in Silverlight (part 2)</a> is a post from: <a href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In <a  href="http://blog.petergerritsen.nl/2009/02/14/creating-a-3d-tagcloud-in-silverlight-part-1/" target="_blank">part 1</a> I showed you how to create the basics for a 3D tagcloud in Silverlight. In this part I’ll show how to get the tags from your html for inserting it into a blog template, we’ll change the color of the tag based on the weight of the tag and let the hyperlink button actually function as a hyperlink (until now it does nothing when you click on it).</p>
<p>There are a few different ways you can pass or get information from the page the Silverlight control is hosted in:</p>
<ul>
<li> Set the initParams parameter in the Silverlight object definition</li>
<li> Read the HtmlDocument in your Silverlight code</li>
<li> Use JavaScript to call methods in your Silverlight code</li>
</ul>
<p>You can only use the first option if your hosting your Silverlight application on the same domain. When using the hosting service on silverlight.live.com, no interaction between your application and HTML page is allowed.</p>
<p>For the second option you can use the HtmlPage object in your code to traverse through the HTML DOM, basic methods such as GetElementById are available.</p>
<p>The last option is the one I’ll be using in this post. To accomplish this you need to follow a few steps:</p>
<ul>
<li> Decorate your page class with a &#8220;ScriptableType” attribute</li>
<li> Decorate the method you want to call with the “ScriptableMember” attribute and make sure it’s public</li>
<li> Register your object in the HtmlPage</li>
<li> Give your Silverlight object definition an id, so you can easily reference it from your JavaScript</li>
</ul>
<p>The reason I’m going with this technique is the flexibility it provides when you want to reuse the tagcloud in other applications. Every blog engine has a different way to generate the HTML for a tagcloud, my blog just shows a list of tags.</p>
<p>To change the color based on the weight and set the url of the HyperlinkNutton we need to make some changes to the Tag3D object I showed you in the last post:</p>
<pre class="brush: csharp">
public class Tag3D
{
public HyperlinkButton btnLink { get; set; }
private TextBlock textBlock { get; set; }
public Point3D centerPoint { get; set; }
private Color TagColor { get; set; }

public Tag3D(double x, double y, double z, string text, string url, Color tagColor, int weight)
{
centerPoint = new Point3D(x, y, z);
textBlock = new TextBlock();
textBlock.Text = string.Format(&quot;{0} ({1})&quot;, text, weight);
btnLink = new HyperlinkButton();
btnLink.Content = textBlock;
btnLink.NavigateUri = new Uri(url);
this.TagColor = tagColor;
}

public void Redraw(double xOffset, double yOffset)
{
double zFactor = ((centerPoint.Z + 300) / 450.0);
btnLink.FontSize = 30.0 * zFactor;
double alpha = zFactor * 255;
//Debug.WriteLine(&quot;Z: {0}; zFactor: {1}; alpha: {2}&quot;, centerPoint.Z, zFactor, alpha);
btnLink.Foreground = new SolidColorBrush(Color.FromArgb(Convert.ToByte(alpha), TagColor.R, TagColor.G, TagColor.B));

Canvas.SetLeft(btnLink, centerPoint.X + xOffset - (btnLink.ActualWidth / 2));
Canvas.SetTop(btnLink, -centerPoint.Y + yOffset - (btnLink.ActualHeight/ 2));
Canvas.SetZIndex(btnLink, Convert.ToInt32(centerPoint.Z));
}
}
</pre>
<p>In the constructor we now pass in the url and a Color to show when the tag is the most important (I chose to use a scale of 1 to 10, with 10 being the most important).<br />
The url is simply assigned to the NavigateUrl property of the HyperlinkButton. The Color is used when setting the new Foreground Brush. I also made some modifications in the calculations of the font size and alpha of the Brush to make it look a bit more realistic.<br />
To let the JavaScript in the page add the tags I’ve created a AddTag method and decorated it with the ScriptableMember attribute:</p>
<pre class="brush: csharp">
[ScriptableMember()]
public void AddTag(string tag, string url, int weight)
{
if (weight &gt; 10)
weight = 10;

Color color = new Color();

color.R = Convert.ToByte(Math.Round(209.0 * ( weight / 10.0)));

color.G = Convert.ToByte(Math.Round(18.0 * (weight / 10.0)));

color.B = Convert.ToByte(Math.Round(65.0 * (weight / 10.0)));

tagBlocks.Add(new Tag3D(0.0, 0.0, 0.0, tag, url, color));
}
</pre>
<p>In this method we calculate the Color of the tag based on the weight. Then we add a new tag to the tagBlocks List&lt;Tag3D&gt;.</p>
<p>After calling this method a couple of times we need to place the tags and display them. I’ve changed the FillTags method shown in the previous post and renamed it to ProcessTags to make the name a bit more meaningful:</p>
<pre class="brush: csharp">
[ScriptableMember()]
public void ProcessTags()
{

double radius = RootCanvas.Width / 3;

int max = tagBlocks.Count;

double phi = 0;

double theta = 0;

for (int i = 1; i &lt; max + 1; i++)

{

phi = Math.Acos(-1.0 + (2.0 * i – 1.0) / max);

theta = Math.Sqrt(max * Math.PI) * phi;

double x = radius * Math.Cos(theta) * Math.Sin(phi);

double y = radius * Math.Sin(theta) * Math.Sin(phi);

double z = radius * Math.Cos(phi);
Tag3D tag = tagBlocks[i -1];

tag.centerPoint = new Point3D(x, y, z);

tag.Redraw(RootCanvas.Width / 2, RootCanvas.Height / 2);

RootCanvas.Children.Add(tag.btnLink);
}
}
</pre>
<p>We need one more thing to make the methods callable from JavaScript. Register the<br />
object with the HtmlPage in the constructor:</p>
<pre class="brush: csharp">
HtmlPage.RegisterScriptableObject(&quot;TagCloud&quot;, this);
</pre>
<p>No you can call the methods from JavaScript:</p>
<pre class="brush: javascript">
function addTags() {
var control = document.getElementById(&quot;Xaml1&quot;);
control.content.TagCloud.AddTag(&quot;Silverlight&quot;, &quot;http://silverlight.net&quot;, 5);
control.content.TagCloud.AddTag(&quot;Tagcloud&quot;, &quot;http://blogs.tamtam.nl&quot;, 2);
control.content.TagCloud.AddTag(&quot;Tam Tam&quot;, &quot;http://www.tamtam.nl&quot;, 10);
control.content.TagCloud.AddTag(&quot;Axelerate3D&quot;, &quot;http://www.codeplex.com&quot;, 8);
control.content.TagCloud.AddTag(&quot;WPF&quot;, &quot;http://www.microsoft.com&quot;, 1);
control.content.TagCloud.AddTag(&quot;SharePoint&quot;, &quot;http://www.microsoft.com&quot;, 4);
control.content.TagCloud.ProcessTags(); }
</pre>
<p>I’m just attaching some code to the onclick of a button and hard-coding the tags. Normally you would handle the onload of the document (or better yet the $(document).ready in jQuery) and get your tags from the Html to pass them to the Silverlight object.</p>
<p>And that wraps it up for this tutorial.</p>
<!-- RO Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Twitter"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/twitter.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Twitter" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Twitter" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.myspace.com/Modules/PostTo/Pages/?t=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29&#038;c=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to MySpace"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/myspace.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to MySpace" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to MySpace" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/&#038;title=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Del.icio.us"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/delicious.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Del.icio.us" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Del.icio.us" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&#038;url=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/&#038;title=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to digg"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/digg.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to digg" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to digg" /></a><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/&#038;t=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to FaceBook"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/facebook.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to FaceBook" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to FaceBook" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Technorati"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/technorati.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Technorati" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Technorati" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/&#038;title=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Stumble Upon"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/stumbleupon.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Stumble Upon" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Stumble Upon" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&#038;output=popup&#038;bkmk=http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/&#038;title=Creating+a+3D+tagcloud+in+Silverlight+%28part+2%29" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Google Bookmarks"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/google.png" title="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Google Bookmarks" alt="Add 'Creating a 3D tagcloud in Silverlight (part 2)' to Google Bookmarks" /></a></div>
<!-- RO Social Bookmarks END --><p><a  href="http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/">Creating a 3D tagcloud in Silverlight (part 2)</a> is a post from: <a  href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
<div class="fblike" style="height:25px; height:25px; overflow:hidden;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.petergerritsen.nl%2F2009%2F02%2F19%2Fcreating-a-3d-tagcloud-in-silverlight-part-2%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allow Transparency="true" style="border:none; overflow:hidden; width:320px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://blog.petergerritsen.nl/2009/02/19/creating-a-3d-tagcloud-in-silverlight-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript errors after implementing a custom site design</title>
		<link>http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss</link>
		<comments>http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 11:44:11 +0000</pubDate>
		<dc:creator>Peter Gerritsen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MOSS]]></category>

		<guid isPermaLink="false">http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/</guid>
		<description><![CDATA[Most of the times we create and develop a custom design for the portals and websites we build. This can actually lead to some rather odd JavaScript error messages saying some object is undefined when dragging and dropping web parts or using the list item edit menu. Believe it or not, this is most of [...]<p><a href="http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/">JavaScript errors after implementing a custom site design</a> is a post from: <a href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Most of the times we create and develop a custom design for the portals and websites we build.</p>
<p>This can actually lead to some rather odd JavaScript error messages saying some object is undefined when dragging and dropping web parts or using the list item edit menu.</p>
<p>Believe it or not, this is most of the times due to the custom style sheet and not to any custom JavaScript.</p>
<p>The reason for this is that the build in JavaScript of MOSS use a property offsetParent of a DOM-element to perform some &#8220;magic&#8221;. <strong>offsetParent</strong> returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element. In some of our custom designs this sometimes returns null and the script throws the &#8220;object undefined&#8221; error.</p>
<p>The easiest solution to prevent this, is to absolute-position the body by include the following statement in your css:</p>
<p><span style="font-family: courier new;">body { position: absolute !important; } </span></p>
<p>This can off course lead to some css issues, so positioning a wrapper is also an option.</p>
<!-- RO Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/" title="Add 'JavaScript errors after implementing a custom site design' to Twitter"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/twitter.png" title="Add 'JavaScript errors after implementing a custom site design' to Twitter" alt="Add 'JavaScript errors after implementing a custom site design' to Twitter" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.myspace.com/Modules/PostTo/Pages/?t=JavaScript+errors+after+implementing+a+custom+site+design&#038;c=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/" title="Add 'JavaScript errors after implementing a custom site design' to MySpace"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/myspace.png" title="Add 'JavaScript errors after implementing a custom site design' to MySpace" alt="Add 'JavaScript errors after implementing a custom site design' to MySpace" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/&#038;title=JavaScript+errors+after+implementing+a+custom+site+design" title="Add 'JavaScript errors after implementing a custom site design' to Del.icio.us"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/delicious.png" title="Add 'JavaScript errors after implementing a custom site design' to Del.icio.us" alt="Add 'JavaScript errors after implementing a custom site design' to Del.icio.us" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&#038;url=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/&#038;title=JavaScript+errors+after+implementing+a+custom+site+design" title="Add 'JavaScript errors after implementing a custom site design' to digg"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/digg.png" title="Add 'JavaScript errors after implementing a custom site design' to digg" alt="Add 'JavaScript errors after implementing a custom site design' to digg" /></a><br /><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/&#038;t=JavaScript+errors+after+implementing+a+custom+site+design" title="Add 'JavaScript errors after implementing a custom site design' to FaceBook"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/facebook.png" title="Add 'JavaScript errors after implementing a custom site design' to FaceBook" alt="Add 'JavaScript errors after implementing a custom site design' to FaceBook" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/" title="Add 'JavaScript errors after implementing a custom site design' to Technorati"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/technorati.png" title="Add 'JavaScript errors after implementing a custom site design' to Technorati" alt="Add 'JavaScript errors after implementing a custom site design' to Technorati" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/&#038;title=JavaScript+errors+after+implementing+a+custom+site+design" title="Add 'JavaScript errors after implementing a custom site design' to Stumble Upon"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/stumbleupon.png" title="Add 'JavaScript errors after implementing a custom site design' to Stumble Upon" alt="Add 'JavaScript errors after implementing a custom site design' to Stumble Upon" /></a><a  class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&#038;output=popup&#038;bkmk=http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/&#038;title=JavaScript+errors+after+implementing+a+custom+site+design" title="Add 'JavaScript errors after implementing a custom site design' to Google Bookmarks"><img src="http://blog.petergerritsen.nl/wp-content/plugins/ro-social-bookmarks/google.png" title="Add 'JavaScript errors after implementing a custom site design' to Google Bookmarks" alt="Add 'JavaScript errors after implementing a custom site design' to Google Bookmarks" /></a></div>
<!-- RO Social Bookmarks END --><p><a  href="http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/">JavaScript errors after implementing a custom site design</a> is a post from: <a  href="http://blog.petergerritsen.nl">Peter Gerritsen&#039;s blog</a></p>
<div class="fblike" style="height:25px; height:25px; overflow:hidden;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.petergerritsen.nl%2F2009%2F01%2F31%2Fjavascript-errors-after-implementing-a-custom-site-design%2F&amp;layout=standard&amp;show_faces=false&amp;width=320&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allow Transparency="true" style="border:none; overflow:hidden; width:320px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://blog.petergerritsen.nl/2009/01/31/javascript-errors-after-implementing-a-custom-site-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
