<?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>Blog For .NET &#187; javascript</title>
	<atom:link href="http://www.blogfor.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blogfor.net</link>
	<description>welcome to the blogosphere</description>
	<lastBuildDate>Sun, 02 May 2010 17:20:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery UI Dialog vs. IE6</title>
		<link>http://www.blogfor.net/2010/04/06/jquery-ui-dialog-vs-ie6/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jquery-ui-dialog-vs-ie6</link>
		<comments>http://www.blogfor.net/2010/04/06/jquery-ui-dialog-vs-ie6/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 20:42:03 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery.live]]></category>

		<guid isPermaLink="false">http://www.blogfor.net/?p=253</guid>
		<description><![CDATA[I&#8217;ve recently started using the jQuery UI Dialog.  I think Scott G. has done an amazing job on the control, unfortunately there a few minor issues i&#8217;m having.  I think they originate from a funky wrapping element around the main content, this is a problem for another post.  What i needed today [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently started using the <a href="http://jqueryui.com/demos/dialog/">jQuery UI Dialog</a>.  I think Scott G. has done an amazing job on the control, unfortunately there a few minor issues i&#8217;m having.  I think they originate from a funky wrapping element around the main content, this is a problem for another post.  What i needed today was a quick/easy way to hide/show &lt;SELECT&gt; tags when modal dialogs were being shown and hidden.</p>
<p>Here is a short list of my requirements:</p>
<ul>
<li>Only one Dialog will ever be visible at any time</li>
<li>Multiple Dialog instances may live on the page at any given time</li>
<li>A predefined class provides behavior cues <i><strong>ie6-dialog-zfix</strong></i> and elements in question will be decorated with <i><strong>ie6-dialog-zfix</strong></i> </li>
</ul>
<p>The code shows the power of jQuery&#8217;s <a href="http://api.jquery.com/live/">Live</a> function.  Using the <a href="http://api.jquery.com/live/">live</a> function allows the code to work on ANY dialog event, regardless of when it&#8217;s initialized.  There may be a better way to do this like <a href="http://paulirish.com/2010/duck-punching-with-jquery/">duck punch</a> the dialog control but this was quick and very light.</p>
<p>The entire code is wrapped in lambda to provide a sort of &#8220;namespace&#8221; and help prevent variable collisions, pretty common practice in jQuery land.</p>
<pre name="code" class="javascript">
// IE6 Dialog Form Element Z-Fix
(function($){

	var elements = [],
		inputSelector = ".ie6-dialog-zfix:visible";

	// Only attach the fixes in IE6
	if ( $.browser.msie &#038;&#038; $.browser.version.substr(0,1) < 7 ) {
		$(".ui-dialog").live('dialogopen', function() {
			elements = $(inputSelector).css("visibility", "hidden");
		});
		$(".ui-dialog").live('dialogclose', function() {
			if(elements.length) {
				elements.css("visibility", "visible");
			}
		});
	}
})(jQuery);
</pre>
<p>The above code will set <i><a href="http://www.w3schools.com/CSS/pr_class_visibility.asp">visibility: hidden</a></i> on all visible elements with .ie6-dialog-zfix class when any dialog is shown, references to these elements will be cached and visibility will be set to visibile when any dialog is closed.  Notice my requirements assume only one dialog will ever be active at any given time.</p>
<p>This code could easily be turned into a plug-in but i don't really have a need for that at the moment. I presenting an idea not a production quality solution.  The main goal here is to find whats causing my overlay/ie6 issues and fix that.  </p>
<p>Thanks for listening, please leave your feedback.  If people are interested I can clean this up and provide some better examples.  Maybe even make a plug-in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blogfor.net/2010/04/06/jquery-ui-dialog-vs-ie6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Client-Side Template</title>
		<link>http://www.blogfor.net/2009/03/13/simple-client-side-template/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simple-client-side-template</link>
		<comments>http://www.blogfor.net/2009/03/13/simple-client-side-template/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 04:45:00 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nant]]></category>
		<category><![CDATA[asp.net ajax]]></category>
		<category><![CDATA[telerik]]></category>

		<guid isPermaLink="false">http://www.blogfor.net/?p=81</guid>
		<description><![CDATA[I needed an easy way to move a singleton chunk of HTML around the page.  More specifically i needed to insert an event driven piece of HTML into the telerik rad tree view node.  All i needed to do was, 1. create a DIV, the template,  that i could move into other elements. 2. Create [...]]]></description>
			<content:encoded><![CDATA[<p>I needed an easy way to move a singleton chunk of HTML around the page.  More specifically i needed to insert an event driven piece of HTML into the <a href="http://www.telerik.com/products/aspnet-ajax/treeview.aspx">telerik rad tree view</a> node.  All i needed to do was, 1. create a DIV, the template,  that i could move into other elements. 2. Create one hidden DIV to store the template when it isn&#8217;t being shown.  Javascript is pretty slick sometimes, er, atleast it works well for things like managing the DOM!  The few lines of code show the power of this control.</p>
<p>When you want to move the template around you can use the following methods.<br />
<strong> Usage </strong></p>
<pre name="code" class="javascript">//inserts the template into the content
var contentElement = $get("conatiner1");
contentElement.appendChild(Samples.Template.get_template());

//inserts the template into the hidden storage container.
Samples.Template.storeTemplate();</pre>
<p>One of the nice things is that i can attach eventhandlers onto the elements in the template and they remain after moving the template around the DOM. I&#8217;ve only tested this in IE6/7 and FF 2/3, but it works great!  Here is the asp.net ajax behavior which lets you manage the template through a singleton object.</p>
<p><strong> The Javascript Object </strong></p>
<pre name="code" class="javascript">Type.registerNamespace("Samples");

/////////////////////////
//  base class
////////////////////////
Samples.NodeTemplate = function(storageName, templateName) {
    this._storage = null;
    this._storageName = storageName;
    this._templateName = templateName;
};
Samples.NodeTemplate.prototype = {

    onDisabledChanged: function(disabled) { },

    get_template: function() {
        return $get(this._templateName);
    },

    get_storage: function() {
    ///
    /// returns an element where the template is hidden when not inserted into the tree
    ///
        if (!this._storage) {
            this._storage = $get(this._storageName);
        }
        return this._storage;
    },

    get_disabled: function() {
        return this._disabled;
    },
    set_disabled: function(value) {
        if (this._disabled != value) {
            this._disabled = value;
            this.onDisabledChanged(value);
        }
    },

    storeTemplate: function() {
    ///
    /// Finds the template container by id and returns it to the storage area
    ///
        this.get_storage().appendChild(this.get_template());

    }
};
Samples.NodeTemplate.registerClass('Samples.NodeTemplate');

/////////////////////////
//  Singleton Template class
////////////////////////
Samples._Template = function(storageName, templateName) {
    Samples._Template.initializeBase(this, [storageName, templateName]);
};
Samples._Template.prototype = {

    onDisabledChanged: function(disabled) {
        ///
        /// overridable method to handle any changes required on disabled
        ///
        this.get_iconElement().disabled = disabled;
    },

    get_iconElement: function() {
        //would prolly be best to use a helper method since childnodes '
        //differs on a per browser basis, but works for this example
        return this.get_template().childNodes[0];
    }
};
Samples._Template.registerClass('Samples._Template', Samples.NodeTemplate);
//creating instance with a hardcoded id
Samples.Template = new Samples._Template("storage", "template");</pre>
<p>Well, this code is setup to work with a pretty specific use case but the base class can be extended into a wide range of neat DOM manipulation tools.  This little template is used to choose a type and submit.  A simple use case, when you need to turn a region into edit mode you can use this little guy to act as your singleton edit region.  Moving it into place whenever you need to, of course you&#8217;ll still have to bind data and wire up event handlers, but that&#8217;s another blog.  The mark-up below shows it can handle asp.net controls, assuming they don&#8217;t change over runtime.  it&#8217;s also important to note that you&#8217;ll need to manage the clientstate, if you need to support postbacks anyways.</p>
<p><strong> The HTML </strong></p>
<pre name="code" class="html">
<form id="form1">
<div id="container1" style="border: 1px solid red; height: 50px; width: 450px;">
<input onclick="this.parentNode.appendChild(Samples.Template.get_template()); return false;" type="submit" value="move here" /></div>
<div id="container2" style="border: 1px solid blue; height: 50px; width: 450px;">
<input onclick="this.parentNode.appendChild(Samples.Template.get_template()); return false;" type="submit" value="no move it here" /></div>
<input onclick="Samples.Template.storeTemplate(); return false;" type="submit" value="store it away" />
<div id="storage" style="display: none;">
<div id="template">
<input id="generate" onclick="return false;" type="submit" value="Generate" />
<input id="cancel" onclick="return false;" type="submit" value="Cancel" /></div>
</div>
</form>
</pre>
<p>Two things i really like about this code.  1. The power of code is seen in the usage, the behavior is just an overweight static set of helper methods. 2. This feels good to use.  Sure, it could be optimized a ton, but i&#8217;m not going to for this blog. 3.Javascript singletons are always interesting.</p>
<p><a href="http://www.blogfor.net/wp-content/uploads/2009/03/nodetemplate2.zip"><br />
DOWNLOAD THE EXAMPLE CODE HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blogfor.net/2009/03/13/simple-client-side-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ScrollTo using the ajax control toolkit animation framework</title>
		<link>http://www.blogfor.net/2008/04/06/scrollto-using-the-ajax-control-toolkit-animation-framework/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=scrollto-using-the-ajax-control-toolkit-animation-framework</link>
		<comments>http://www.blogfor.net/2008/04/06/scrollto-using-the-ajax-control-toolkit-animation-framework/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 18:44:58 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ajaxcontroltoolkit]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[asp.net ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.blogfor.net/?p=4</guid>
		<description><![CDATA[I&#8217;ve been digging deep into the asp.net ajax javascript framework and wanted to share one of the cool controls i was able to make using the asp.net ajax library and the AjaxControlToolkit animation framework.  The guys over at codeplex have put together a pretty nice animation framework.  It&#8217;s been pretty hard for me [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been digging deep into the asp.net ajax javascript framework and wanted to share one of the cool controls i was able to make using the asp.net ajax library and the AjaxControlToolkit animation framework.  The guys over at codeplex have put together a pretty nice animation framework.  It&#8217;s been pretty hard for me to find any useful reference material on the animation framework outside of using it really server side.  I wasn&#8217;t able to find anything about creating your own custom animation classes although the animation framework has obviously a ton of sample code.  Eventually i found my best resource to be VS2008 javascript intellisense with the aniamtion framework referenced into my class. Enough of the details, i could rant all day an may do so later but lets get into some of the cool stuff.</p>
<p><strong>javascript references for intellisense</strong></p>
<pre name="code" class="javascript">
/// <reference name="MicrosoftAjax.debug.js"></reference>
/// <reference name="MicrosoftAjaxTimer.debug.js"></reference>
/// <reference name="MicrosoftAjaxWebForms.debug.js"></reference>
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit"></reference>
/// <reference name="AjaxControlToolkit.Common.Common.js" assembly="AjaxControlToolkit"></reference>
/// <reference name="AjaxControlToolkit.Common.DateTime.js" assembly="AjaxControlToolkit"></reference>
/// <reference name="AjaxControlToolkit.Animation.AnimationBehavior.js" assembly="AjaxControlToolkit"></reference>

/// <reference name="AjaxControlToolkit.Animation.Animations.js" assembly="AjaxControlToolkit"></reference></pre>
<p>specifically this sample doesn&#8217;t use the intellisense from all of these references but this is generally what i start with as my js references for any javascript class i&#8217;m looking to create. And yes, the intellisense builder requires that the js file references be in an order of dependence.  Ok, now we can finally move on to what i&#8217;m actually trying to blog about. The scroll to animation.</p>
<pre name="code" class="javascript">
Type.registerNamespace("boudreau");boudreau.scrollTo = function(element) {
    boudreau.scrollTo.initializeBase(this, [element]);
       this.animation = null;
}
boudreau.scrollTo.prototype = {
    initialize: function() {
    ///<summary>
    /// creates our animation and adds a click handler.
    ///</summary>
        boudreau.scrollTo.callBaseMethod(this, 'initialize');
        this.animation = new $AA.InterpolatedAnimation(this.get_element(), 2, 25, "scrollTop");
// Important: Notice that the value is passed as a function.
        // This overrides the animation's getAnimatedValue function.
        this.animation.getAnimatedValue = this.__getAnimatedValue;
    },

dispose: function() {
    ///<summary>
    /// Does the cleanup work
    //</summary>
        this.animation.dispose();
        boudreau.scrollTo.callBaseMethod(this, 'dispose');
    },

scrollTo : function( target ) {
    ///<summary>
    /// scrolls the container to to the target element.
    ///</summary>

        var container = this.get_element();
        // If we wanted the item to scroll to the middle of the
        // container we set offset = middle.
        var middle = ($common.getContentSize(container).height / 2.0 );

        // For now we just use a 40 pixel offset so it isn't hugging
        // the top of the container.
        var offset = 40;

        //set start and ending positions of the scroll window.
        this.animation.set_startValue(container.scrollTop);
        this.animation.set_endValue(target.offsetTop - 40);

        //let the framework do it's job.
        this.animation.play();

    },

__getAnimatedValue : funtion ( percentage ) {
        ///<summary>
        ///  This method is run in the context of the animation object.  Therefore it's
        ///  important to understand that when this function is executing that "this"
        ///  referes to the animation object, NOT the boudreau.scrollTo object.
        ///  Besides that this function performs a simple linear interpolation.
        ///</summary>
        ///<remarks>
        /// It's important to note the reason we have to define this function is that it's a
        ///  MustOverride on the InterpolatedAnimation object.
        ///  The reason i used InterpolatedAnimation is so that i could
        ///  implement a non-linear animation.
        ///</remarks>

        return this.get_startValue() + (this.get_endValue() - this.get_startValue()) * (percentage * / 100);

    }

}

boudreau.scrollTo.registerClass('boudreau.scrollTo', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();</pre>
<p><strong>That&#8217;s the code. </strong><br />
If you aren&#8217;t comfortable with prototypical development in javascript then you&#8217;ll you should brush up on that.  [Blog Link, WWW Link?] But if you are then lets dive into the details.</p>
<p><strong>The Behavior</strong><br />
<em>scrollTo object</em> derives from microsoft&#8217;s Sys.UI.Behavior which is used to extend the functionality of a particular DOM element. This behavior acts on the scrollable container you define as the target element. If someone asked me what this behavior did i&#8217;d tell them &#8221; It&#8217;s a javascript object that holds a reference to a DOM element,  the container, (This is what we get from microsoft ajax library.) The javascript object knows hows to scroll, with animation, to a given target element inside the container. &#8221;  If you can decipher that you&#8217;ve got it.   On to the gory details.</p>
<p><strong>The constructor &#8211; new $AA.InterpolatedAnimation()</strong><br />
In the <em>init</em> method we define a new InterpolatedAnimation first off $AA is a shorthand for AjaxControlToolkit.Animation, it saves us some 20 chars to type, and download for that matter.   The constructor used above takes some 7 parameters but we are only passing in 4 because i&#8217;m happy with the default values for the others for now.  The first, the target element, is the object that should contain the scrollBar you want to animate.  The second and third are fps and duration respectively (which i won&#8217;t discuss cause they are pretty self explanitory.) the fourth parameter is the property of the the target element you want to animate using the InterpolatedAnimation.  Kind of important to understand what&#8217;s going on here, this parameter is what the interpolated animation updates when it is told to .play().  So, in our case we want to animate the scrollTop property of the target element.  scrollTop is just a javascript property that gets/sets the top of the content area in a scrollable window.  Alright, that&#8217;s creating the animation.  Hopefully you see what&#8217;s going on here, lets recap.  We are creating an interpolated animation object inside of our behavior and telling it what property on what element we want to animate.  Next we&#8217;ll look at the scrollTo function and see how the behavior does the work.</p>
<p><strong>The worker &#8211; scrollTo()</strong><br />
the<em> scrollTo()</em> method does all the work of finding and scrolling to the correct distance inside the container.  At the end we hope to see that our target element is 40 px below the scrollTop of the container content window.  First we define the properties on the animation that will be interpolated, the start and end scrollTop value of the container.  These two properties on the InterpolatedAnimation are the values you want the animation to interpolate across. (remember how we set scrollTop as the property in the constructor.) Our InterpolatedAnimation  is going to interpolate the values between start_value and end_value on the container element (the scrollable element) and update the property scrollTop with the value at each step in the animation.  This is how it works, if you don&#8217;t understand the previous explanation read it again, it&#8217;s the magic and hopefully you can tell there is no real <em>magic</em> at all!</p>
<pre name="code" class="javascript">
// For now we just use a 40 pixel offset so it isn't hugging
// the top of the container.
var offset = 40;

//set start and ending positions of the scroll window.
this.animation.set_startValue(container.scrollTop);
this.animation.set_endValue(target.offsetTop - 40);

this.animation.play();</pre>
<p>So that&#8217;s pretty much it, after you</p>
<pre name="code" class="javascript">$create(boudreau.scrollTo, null,null,null, $get(scrollableElementId))</pre>
<p>a scrollTo behavior on a scrollable element you use</p>
<pre name="code" class="javascript">
$find(scrollableElementId).scrollTo(element_to_scroll_to_in_container)</pre>
<p>to produce a nice smooth scroll to the target element inside the scrollable container.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blogfor.net/2008/04/06/scrollto-using-the-ajax-control-toolkit-animation-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
