﻿<?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>Programming By A Tool &#187; UI</title>
	<atom:link href="http://byatool.com/category/ui/feed/" rel="self" type="application/rss+xml" />
	<link>http://byatool.com</link>
	<description>This is my recorded stumbling through ASP.Net, Framework 3.5, C# 3.0, Ajax, Javascript, and Love.  Stay, learn, destroy.  It's your life.</description>
	<lastBuildDate>Thu, 03 May 2012 17:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>jQuery Validate Date/Check If Is Date</title>
		<link>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/</link>
		<comments>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 18:04:31 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1794</guid>
		<description><![CDATA[Far as I can tell, and that&#8217;s pretty far even though I do wonder if you can actually measure telling in distance, there isn&#8217;t a method directly used for validating a date in jquery. I find this rather odd. Not odd like how people keep watching Uwe Bol movies, more like odd that no one [...]]]></description>
			<content:encoded><![CDATA[<p>Far as I can tell, and that&#8217;s pretty far even though I do wonder if you can actually measure telling in distance, there isn&#8217;t a method directly used for validating a date in jquery. I find this rather odd. Not odd like how people keep watching Uwe Bol movies, more like odd that no one has tried to make a time machine to prevent them from ever appearing.</p>
<p>Anyways, bad movies&#8230; horrible movies&#8230; worst movies of all time aside, there is a date checking method, just not directly in jquery. It&#8217;s actually in the jquery.ui.datepicker.js file which is <a href="http://jqueryui.com/download">part of the UI files.</a> Basically I grabbed that file and used the parseDate method on it coupled with a try catch. After all, a failure in the parseDate method throws an exception, and we don&#8217;t like those. No we don&#8217;t. (Which begs the question as why it throws an exception instead of just returning a null date.)</p>
<pre><span style="color: #0000ff;">function</span> isValidDate(controlName, format){
    <span style="color: #0000ff;">var</span> isValid = <span style="color: #0000ff;">true</span>;

    <span style="color: #0000ff;">try</span>{
        jQuery.datepicker.parseDate(format, jQuery(<span style="color: #ff0000;">'#'</span> + controlName).val(), <span style="color: #0000ff;">null</span>);
    }
    <span style="color: #0000ff;">catch</span>(error){
        isValid = false;
    }

    <span style="color: #0000ff;">return</span> isValid;
}</pre>
<p>Very simple, and it works. You could ask why I didn&#8217;t just roll my own date method, and then I would ask you how ambitious do you think I am? Then you would punch me because I answered your question with a question like a complete tool bag. Then I would cry. And THEN I would answer your original question. Fact is, I trust that the method created for the DatePicker is in fact well tested, otherwise the whole jquery thing just isn&#8217;t worth trusting seeing as it&#8217;s a part of their core library. And that I just refuse to believe.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Find a Form Action Using Jquery</title>
		<link>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/</link>
		<comments>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 16:59:04 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1699</guid>
		<description><![CDATA[This is pretty useful for people trying to pass in a generated action to a javascript file.Â  Eh? SKIP IF YOU DON&#8217;T CARE ABOUT A REASON FOR USING THIS: Say you are using the jQuery post method to send things back to the server but all the code for that is in a seperate javascript [...]]]></description>
			<content:encoded><![CDATA[<p>This is pretty useful for people trying to pass in a generated action to a javascript file.Â  Eh?</p>
<h1><span style="color: #ff0000;">SKIP IF YOU DON&#8217;T CARE ABOUT A REASON FOR USING THIS:</span></h1>
<p>Say you are using the jQuery post method to send things back to the server but all the code for that is in a seperate javascript file.Â  Well you can&#8217;t really do this:</p>
<pre>jQuery.ajax({
      type:<span style="color: #800000;">'POST'</span>,
      url: <span style="color: #ff9900;">&lt;%=</span> someMethodForCreatingAUrl(<span style="color: #ff0000;">'controller'</span>, <span style="color: #ff0000;">'action'</span>) <span style="color: #ff9900;">%&gt;</span>,
      dataType:'json',
      data:{
        email: user.userName,
        password: user.password
      },
      success: function(result){
        onSuccess(result);
      },
      error:function (xhr, ajaxOptions, thrownError){
        alert(xhr.status);
      }
    });</pre>
<p>if that is in the javascript file.</p>
<p>What you can do is this on the html file:</p>
<pre>  &lt;<span style="color: #800000;">form</span> <span style="color: #0000ff;">id=</span><span style="color: #ff0000;">"formCreateUser"</span> <span style="color: #0000ff;">name=</span><span style="color: #ff0000;">"formCreateUser"</span> <span style="color: #0000ff;">method=</span><span style="color: #ff0000;">"post"</span> <span style="color: #0000ff;">action=</span>"${someMethodForCreatingAUrl('controller', 'action')}"&gt;</pre>
<p>And in the javascript file:</p>
<h1><span style="color: #ff0000;">ANSWER:</span></h1>
<pre>  <span style="color: #0000ff;">var</span> formAction = jQuery(ELEMENT_LOGIN_FORM).attr(<span style="color: #ff0000;">'action'</span>);</pre>
<p>And there you go. You have the action.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Modal Dialog : Hide That Stupid X Button / Windows Close Button</title>
		<link>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/</link>
		<comments>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:05:18 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Modal Dialog]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1213</guid>
		<description><![CDATA[This is quick one, so hold on to your&#8230; whatever. Want to get rid of that X at the top right of the modal &#8220;Control&#8221;? Well here it is: (The bold part, moron) jQuery('#WaitingDiv').dialog({ autoOpen: false, bgiframe: false, height: 150, width: 200, modal: true, open: function(event, ui) { jQuery('.ui-dialog-titlebar-close').hide(); } }); And that&#8217;s really it. [...]]]></description>
			<content:encoded><![CDATA[<p>This is quick one, so hold on to your&#8230; whatever.</p>
<p>Want to get rid of that X at the top right of the modal &#8220;Control&#8221;?  Well here it is:  (The bold part, moron)</p>
<pre>     jQuery(<span style="color: #800000;">'#WaitingDiv'</span>).dialog({
          autoOpen: false,
          bgiframe: false,
          height: 150,
          width: 200,
          modal: true,
         <strong> open: function(event, ui) { jQuery(<span style="color: #800000;">'.ui-dialog-titlebar-close'</span>).hide();</strong> }
        });
</pre>
<p>And that&#8217;s really it.  Just thought I&#8217;d pass that on to you, the consumer.</p>
<p>On a side note, the big movie thing is the <a href=" http://www.huffingtonpost.com/2010/01/11/spider-man-4-off-spider-m_n_419264.html">canceling of Spiderman 4 or at least going in a new direction</a>.  As much as I don&#8217;t care, it might lead to my dream come true:</p>
<p>A spiderman movie based on the SNES classic: Spider-Man &amp; Venom: Maximum Carnage.  Uwe Boll, are you out there?</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery &#8211; Check All Checkboxes Toggle Method Thingy</title>
		<link>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/</link>
		<comments>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 23:20:11 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1203</guid>
		<description><![CDATA[So here&#8217;s a quick on for all you boys and girls&#8230; and anything else I might have missed. Say you want to check all check boxes in a grid or whatever, but you want it to toggle. So if if it&#8217;s time to check all, all get checked and then the next time the button [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s a quick on for all you boys and girls&#8230; and anything else I might have missed.<br />
Say you want to check all check boxes in a grid or whatever, but you want it to toggle.  So if if it&#8217;s time to check all, all get checked and then the next time the button is clicked it will uncheck.  Now you could do this in three methods, maybe two but that&#8217;s why you&#8217;re a mouth breather.</p>
<p>Special people like me do it in one.</p>
<pre>    <span style="color: #0000ff;">function</span> toggleCheckboxes(buttonId, checkBoxNamePrefix, checked)
    {
      <span style="color: #008000;">//Get all checkboxes with the prefix name and check/uncheck</span>
      jQuery(<span style="color: #800000;">'[id*=' + checkBoxNamePrefix + ']'</span>).attr(<span style="color: #800000;">'checked'</span>, checked);

      <span style="color: #008000;">//remove any click handlers from the button</span>
      <span style="color: #008000;">//  Why?  Because jQuery(buttonId).click() will just add another handler</span>
      jQuery(buttonId).unbind(<span style="color: #800000;">'click'</span>); 

      <span style="color: #008000;">//Add the new click handler</span>
      jQuery(buttonId).click(
        <span style="color: #0000ff;">function</span>() {
          toggleCheckboxes(buttonId, checkBoxNamePrefix, !checked);
        }
      );
    }</pre>
<p>And POW!  What?  You want to know how to use it?  Fine, but only because I&#8217;m nice.</p>
<pre>   jQuery(<span style="color: #800000;">'#buttonName'</span>).click(
     <span style="color: #0000ff;">function</span>() {
       toggleCheckboxes(<span style="color: #800000;">'#buttonName'</span>,<span style="color: #800000;"> 'someCheckBoxName'</span>, <span style="color: #0000ff;">true</span>);
     }
   );</pre>
<p>And in case you were still wondering why I used .unbind and didn&#8217;t understand the comment, it&#8217;s because using just .click will add another handler to the button. So next click you will get both check and uncheck all.  Kind of hurts the effectiveness.</p>
<p>And there you have it.  Once again I have filled your life with meaning.  Couldn&#8217;t be easier.  Or maybe it could but that&#8217;s not my problem now is it?  Go back to doing something useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Grab Bag &#8211; Whole bunch of jQuery Functionality</title>
		<link>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/</link>
		<comments>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 21:06:32 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1125</guid>
		<description><![CDATA[You could look at this post as a self serving block that I will use to save stuff I don&#8217;t want to remember later. Or you could see it as a knowledge transfer that you the reader can learn from because I am a generous and giving tool. Whatever, I really don&#8217;t care. I won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>You could look at this post as a self serving block that I will use to save stuff I don&#8217;t want to remember later.</p>
<p>Or you could see it as a knowledge transfer that you the reader can learn from because I am a generous and giving tool.</p>
<p>Whatever, I really don&#8217;t care.  I won&#8217;t sleep any differently.  I just don&#8217;t feel like making 1000 posts of jquery stupidity.</p>
<p>I&#8217;ll add more as I come across them.</p>
<h2>Checkbox</h2>
<p><strong>How To Check a CheckBox</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">false</span>);</pre>
<p><strong>How To Know if a Checkbox is Checked</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).is(<span style="color: #800000;">':checked'</span>)</pre>
<p><strong>How To Find a Bunch of Like Named Checkboxes that are Checked</strong></p>
<pre>  jQuery(<span style="color: #800000;">'[id*=someCheckBox_]:checked'</span>);</pre>
<h2>Drop Down Lists</h2>
<p><strong>How to Add an Item/Option to a Drop Down List</strong></p>
<pre> jQuery(<span style="color: #800000;">'#DropDownListId'</span>).append(jQuery(<span style="color: #800000;">'&lt;option&gt;'</span>).val(1).html(<span style="color: #800000;">"SomeText"</span>));</pre>
<p>Odd Note:  Apparently jquery is smart enough to set the attributes on the option AND close the option with &lt;/option&gt;</p>
<p><strong>How to Remove an Item/Option from a Drop Down List</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId option[value=\'3\']'</span>).remove();</pre>
<p><strong>How to Sort a Drop Down List by Option Text</strong></p>
<pre>  <span style="color: #0000ff;">var</span> sortedList = jQuery(<span style="color: #800000;">'#someDropDownList option'</span>).sort(
    <span style="color: #0000ff;">function</span> (first, second) {
      <span style="color: #0000ff;">return</span> first.text == second.text ? 0 : first.text &lt; second.text ? -1 : 1;
    }
  );

  jQuery(<span style="color: #800000;">'#someDropDownList'</span>).html(sortedList);</pre>
<h2>Elements</h2>
<p><strong> How to Filter Out an Element in a List</strong></p>
<pre>  someElementList.filter(<span style="color: #800000;">'[id=someId]'</span>);</pre>
<p>Example:</p>
<pre><span style="color: #008000;">  //Uncheck all id like someId_ and check only where id = someId_1</span>
<span style="color: #0000ff;">  var</span> someElementList = someElement.children(<span style="color: #800000;">'[id*=someId_]'</span>);
  someElementList.attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">false</span>);
  someElementList.filter(<span style="color: #800000;">'[id=someId_1]'</span>).attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">true</span>);</pre>
<p><strong>How To Find an Element Based on a Like Name/Using Wildcards</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#SomeTable'</span>).children(<span style="color: #800000;">'tr[id*=SomeRowId]'</span>);</pre>
<p><strong>How To Know if a Something is Hidden</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).is(<span style="color: #800000;">':hidden'</span>)</pre>
<p>Possible Use:</p>
<pre> <span style="color: #0000ff;">function</span> showOrHide(element) {
    <span style="color: #0000ff;">if</span>(jQuery(element).is(<span style="color: #800000;">':hidden'</span>)) {
      jQuery(element).show();
    }
    <span style="color: #0000ff;">else</span> {
      jQuery(element).hide();
    }
  }</pre>
<p><strong>How to Disable an Input/Select</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId'</span>).attr(<span style="color: #800000;">'disabled'</span>, <span style="color: #800000;">'disabled'</span>);</pre>
<p><strong>How to Enable an Input/Select</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId'</span>).removeAttr(<span style="color: #800000;">'disabled'</span>);</pre>
<p><strong>How to Know if an Element Exists</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#ElementId'</span>).length &gt; 0</pre>
<p>Possible use:</p>
<pre>  <span style="color: #0000ff;">function</span> elementExists(elementId) {
    <span style="color: #0000ff;">return</span> jQuery(elementId).length &gt; 0;
  }</pre>
<h2>String</h2>
<p><strong>How To Remove the First Character from a String</strong></p>
<pre>  someString.substring(1, someString.length)</pre>
<h2>Tables</h2>
<p><strong>How to Add a Row to a Table</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#TableId &gt; tbody:last'</span>).append(<span style="color: #800000;">'&lt;tr&gt;...&lt;/tr&gt;'</span>)</pre>
<p><strong>How to Remove a Table Row</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#TableId &gt; tbody:last'</span>).children(someSortOfRowId).remove();</pre>
<h2>Methods</h2>
<p><strong>How to Post With a Link</strong></p>
<pre>  <span style="color: #0000ff;">function</span> postToUrl(path, params)
  {
    <span style="color: #0000ff;">var</span> method = "post"; 

    <span style="color: #0000ff;">var</span> form = document.createElement(<span style="color: #800000;">"form"</span>);
    form.setAttribute(<span style="color: #800000;">"method"</span>, method);
    form.setAttribute(<span style="color: #800000;">"action"</span>, path);
    for(<span style="color: #0000ff;">var</span> key <span style="color: #0000ff;">in</span> params)
    {
        var hiddenField = document.createElement(<span style="color: #800000;">"input"</span>);
        hiddenField.setAttribute(<span style="color: #800000;">"type"</span>, <span style="color: #800000;">"hidden"</span>);
        hiddenField.setAttribute(<span style="color: #800000;">"name"</span>, key);
        hiddenField.setAttribute(<span style="color: #800000;">"value"</span>, params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);    

    form.submit();
  }</pre>
<p>Use:</p>
<pre>&lt;a href="javascript:postToUrl('/SomeController/SomeAction/', { 'id', '1' })"&gt;link&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery: Find All Checked Checkboxes</title>
		<link>http://byatool.com/ui/jquery-find-all-checked-checkboxes/</link>
		<comments>http://byatool.com/ui/jquery-find-all-checked-checkboxes/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 15:14:27 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=909</guid>
		<description><![CDATA[So this is sort of a repeat of another post, but I figured it has some use on its own. Say you have this: &#60;div&#62; &#60;input type="checkbox" name="JqueryIdList" value="1" /&#62; &#60;input type="checkbox" name="JqueryIdList" value="2" /&#62; &#60;input type="checkbox" name="JqueryIdList" value="3" /&#62; &#60;input type="checkbox" name="JqueryIdList" value="4" /&#62; &#60;/div&#62; &#60;div onclick="getIds('JqueryIdList');"&#62; CLICK &#60;/div&#62; And you need the getIds [...]]]></description>
			<content:encoded><![CDATA[<p>So this is sort of a repeat of another post, but I figured it has some use on its own.</p>
<p>Say you have this:</p>
<pre>  &lt;<span style="color: #800000;">div</span>&gt;
    &lt;<span style="color: #800000;">input</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="checkbox"</span> <span style="color: #ff0000;">name</span><span style="color: #0000ff;">="JqueryIdList"</span> <span style="color: #ff0000;">value</span><span style="color: #0000ff;">="1"</span>  /&gt;
    &lt;<span style="color: #800000;">input</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="checkbox"</span> <span style="color: #ff0000;">name</span><span style="color: #0000ff;">="JqueryIdList"</span> <span style="color: #ff0000;">value</span><span style="color: #0000ff;">="2"</span> /&gt;
    &lt;<span style="color: #800000;">input</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="checkbox"</span> <span style="color: #ff0000;">name</span><span style="color: #0000ff;">="JqueryIdList"</span> <span style="color: #ff0000;">value</span><span style="color: #0000ff;">="3"</span> /&gt;
    &lt;<span style="color: #800000;">input</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="checkbox"</span> <span style="color: #ff0000;">name</span><span style="color: #0000ff;">="JqueryIdList"</span> <span style="color: #ff0000;">value</span><span style="color: #0000ff;">="4"</span> /&gt;
  &lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">onclick</span><span style="color: #0000ff;">="getIds('JqueryIdList');"</span>&gt;
    CLICK
  &lt;/<span style="color: #800000;">div</span>&gt;</pre>
<p>And you need the getIds method to find all the checked checkboxes from that markup. Well it&#8217;s actually fairly simple, or at least it wil be once I enlighten you. I should get paid for this&#8230;</p>
<pre>  <span style="color: #0000ff;">function</span> getIds(checkList)
  {
    <span style="color: #0000ff;">var</span> idList = <span style="color: #0000ff;">new</span> <span style="color: #008080;">Array</span>();
    <span style="color: #0000ff;">var</span> loopCounter = 0;
    <span style="color: #008000;">//find all the checked checkboxes</span>
    jQuery(<span style="color: #800000;">"input[name="</span> + checkList + <span style="color: #800000;">"]:checked"</span>).each
    (
      <span style="color: #0000ff;">function</span>()
      {
        <span style="color: #008000;">//fill the array with the values</span>
        idList[loopCounter] = jQuery(<span style="color: #0000ff;">this</span>).val();
        loopCounter += 1;
      }
    );
    ...
  }</pre>
<p>The important part is this:</p>
<pre>
 jQuery(<span style="color: #800000;">"input[name="</span> + checkList + <span style="color: #800000;">"]:checked"</span>).</pre>
<p>As you can see, it is very simple.  Give it the name of the checkboxes, add on the &#8220;:checked&#8221; and boom you have a list of checked checkboxes.  Could it be more simple?  I think not.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-find-all-checked-checkboxes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery: Holy Smokes I Like This Link</title>
		<link>http://byatool.com/ui/jquery-holy-smokes-i-like-this-link/</link>
		<comments>http://byatool.com/ui/jquery-holy-smokes-i-like-this-link/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 13:11:07 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Good Link]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=877</guid>
		<description><![CDATA[Good old Stackoverflow. Wasn&#8217;t sure how to post this without looking like I&#8217;m trying to get search engine hits. However, wanted to pass this one on anyhow. How to center a div using jQuery. Have used it. Works brilliantly. Although the: this.css("position","absolute"); May be overkill since any &#8220;pop up&#8221; div I create already has that [...]]]></description>
			<content:encoded><![CDATA[<p>Good old Stackoverflow. Wasn&#8217;t sure how to post this without looking like I&#8217;m trying to get search engine hits. However, wanted to pass this one on anyhow.</p>
<p><a href="http://stackoverflow.com/questions/210717/what-is-the-best-way-to-center-a-div-on-the-screen-using-jquery">How to center a div using jQuery</a>.</p>
<p>Have used it. Works brilliantly. Although the:</p>
<pre>  <span style="color: #0000ff;">this</span>.css(<span style="color: #ff0000;">"position"</span>,<span style="color: #ff0000;">"absolute"</span>);</pre>
<p>May be overkill since any &#8220;pop up&#8221; div I create already has that in the style where personally I think it should be.</p>
<p>How does it work? Well break down the &#8220;top&#8221; part:</p>
<pre>  <span style="color: #0000ff;">this</span>.css(<span style="color: #ff0000;">"top"</span>, ( jQuery(window).height() - <span style="color: #0000ff;">this</span>.height() ) / 2+jQuery(window).scrollTop() + <span style="color: #ff0000;">"px"</span>);</pre>
<p>To</p>
<pre>   jQuery(window).height() - <span style="color: #0000ff;">this</span>.height() ) / 2</pre>
<p>But why not just divide the height by 2? Well say the height of the window is 800 and your item is 600 high. If you just placed the item at 800 / 2, the bottom of the item would end up 1000. (800/2 = 400&#8230; 600 tall item + 400 starting point = 1000). So subtracting the item&#8217;s height from the window height and THEN dividing by two ensures that that item, provided it is no taller than the window, will end up within the 800 tall window.</p>
<pre>  + jQuery(window).scrollTop()</pre>
<p>Now what if the user has scrolled the widow down? Well adjust for that. using the scrollTop(), the item can be started at the correct point adjusted with the scroll. Nice huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-holy-smokes-i-like-this-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript:  Scope and Learning Something New Everyday.</title>
		<link>http://byatool.com/ui/javascript-scope-and-learning-something-new-everyday/</link>
		<comments>http://byatool.com/ui/javascript-scope-and-learning-something-new-everyday/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 14:17:20 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=863</guid>
		<description><![CDATA[Course for me it doesn&#8217;t take much to learn something new, but let&#8217;s not get into that. So pop quiz, and one that doesn&#8217;t involve a hostage and shooting. jQuery(document).ready ( function() { for(var loopCounter = 0; loopCounter &#60; 3; loopCounter++) { var tempThing = loopCounter; alert('in' + tempThing); jQuery(".someButton").click ( function() { alert('out' + [...]]]></description>
			<content:encoded><![CDATA[<p>Course for me it doesn&#8217;t take much to learn something new, but let&#8217;s not get into that.</p>
<p>So pop quiz, and one that doesn&#8217;t involve a hostage and shooting.</p>
<pre>jQuery(document).ready
(
  <span style="color: #0000ff;">function</span>()
  {
    <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; 3; loopCounter++)
    {
      <span style="color: #0000ff;">var</span> tempThing = loopCounter;
      alert(<span style="color: #ff0000;">'in'</span> + tempThing); 

      jQuery(<span style="color: #800000;">".someButton"</span>).click
      (
        <span style="color: #0000ff;">function</span>()
        {
          alert(<span style="color: #ff0000;">'out'</span> + tempThing);
        }
      );
    }
  }
);
....
  &lt;<span style="color: #800000;">button</span> <span style="color: #0000ff;">class</span><span style="color: #ff0000;">="someButton"</span>&gt;click!&lt;/<span style="color: #800000;">button</span>&gt;</pre>
<p>What happens when you click that button? Well for one it will alert three times but what will it print out?</p>
<p>The first alert (in the loop) does what you would expect. It gives 0, 1, 2. But what about the button click? Well that&#8217;s a little different. It gives 2, 2, 2&#8230; Wait what? The f&#8212; is that? That makes no real sense.</p>
<p>Given that this was C#, it would output 0, 1, 2 because we would know that every loop the tempThing field is a new field. Sure it has the same name in code, but every iteration would create a new space in memory for a new tempThing. And then with closures, a reference would be made to that tempThing so that when the method actually runs, the values are what they should be. Javascript does something a little different. Go figure, right? Can&#8217;t do anything like anyone else&#8230; anyone else being C#.</p>
<p>Now what does happen is it does give you the correct value of tempThing. What you didn&#8217;t know (Assuming you didn&#8217;t know because if you are reading this you either are really bored or don&#8217;t know&#8230; or both) is that tempThing is global to that method. Turns out variables are global to the current scope no matter if in a loop or not. tempThing, no matter where in that function is created/instantiated/ect is the same tempThing through out the method. So what&#8217;s happening is that the first time in the loop it&#8217;s being created and every iteration after it&#8217;s just being updated with the current loopCounter value.</p>
<p>How do you solve this? Well you have to make a method to create a method to set the value. AWESOME!!111</p>
<pre>jQuery(document).ready
(
  <span style="color: #0000ff;">function</span>()
  {
    <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; 3; loopCounter++)
    {
      alert(<span style="color: #ff0000;">'in'</span> + tempThing); 

      jQuery(<span style="color: #800000;">".someButton"</span>).click
      (
        createReturnMethod(loopCounter)
      );
    }
  }

);

<span style="color: #008000;">//This is used to create a new method scope so that
</span><span style="color: #008000;">//tempThing is unique to each call.</span>
<span style="color: #0000ff;">function</span> createReturnMethod(loopCounter)
{
  <span style="color: #0000ff;">var</span> tempThing = loopCounter;

  <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">function</span>(event)
  {
    alert(<span style="color: #ff0000;">'out'</span> + tempThing);
  };
}</pre>
<p>As you can see, I created a method to create a method to be run on click. Because tempThing is now in the second method&#8217;s scope, it will be different for every time this method is called. Magic!</p>
<p>Here&#8217;s a thought, if only you can prevent forest fires then you really should get on that.  People have lost a lot of money because of your slacking.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/javascript-scope-and-learning-something-new-everyday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Whack-A-Mole&#8230; Timer, Hide, Slide, and Fun</title>
		<link>http://byatool.com/ui/jquery-whack-a-mole-timer-hide-slide-and-fun/</link>
		<comments>http://byatool.com/ui/jquery-whack-a-mole-timer-hide-slide-and-fun/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 14:12:16 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Stupid]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=857</guid>
		<description><![CDATA[So I&#8217;ll just straight up file this under &#8220;I really shouldn&#8217;t have&#8221; and not bother asking for forgiveness. For some reason I had it in my mind I wanted to see if I could take the stuff I learned from this guy and this guy and see if I could make a simple Whack A [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ll just straight up file this under &#8220;I really shouldn&#8217;t have&#8221; and not bother asking for forgiveness.  For some reason I had it in my mind I wanted to see if I could take the stuff I learned from <a href="http://byatool.com/index.php/ui/jquery-slide-menu-with-pop-up-divs-yay/">this guy</a> and <a href="http://byatool.com/index.php/ui/jquery-slide-and-pairing-a-divs-hover-with-a-divs-slide/">this guy</a> and see if I could make a simple Whack A Mole game with just jquery and the three include files. (jquery, jquery UI, and jquery Timer)  Not thinking of the massive consequences such a thing might bring, I pushed on in the name of science.  </p>
<p>So with no further build up or stupidity (I used that all up in building this game) I give you <a href="http://www.byatool.com/Hosted/LiveDemos/WhackAMole/WhackAMole.htm">jQuery WHACK A MOLE</a> which oddly enough has somehow clawed it&#8217;s way into my <a href="http://www.iamwebproject.com/BAT/WhackAMole.zip">hosting here.</a>  So if you&#8217;re foolish enough to actually want to know how it works, there are plenty of comments in the script files.  Just don&#8217;t blame me for any loss of intelligence.</p>
<p>I might actually take this to the next horrifying level and make it an mvc application.  Not sure I&#8230; no&#8230; THE WORLD can take it.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-whack-a-mole-timer-hide-slide-and-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Slide Menu With Pop Up Divs.  Yay!</title>
		<link>http://byatool.com/ui/jquery-slide-menu-with-pop-up-divs-yay/</link>
		<comments>http://byatool.com/ui/jquery-slide-menu-with-pop-up-divs-yay/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 20:48:30 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Dynamic Controls]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=851</guid>
		<description><![CDATA[So you may have seen this post about how I came to create such a wonderful menu with no real purpose as of yet. Well that menu has been improved and can be downloaded here. Remember that question you never asked? Well once again I&#8217;ve answered it. To take the normal sliding menu farther I [...]]]></description>
			<content:encoded><![CDATA[<p>So you may have seen <a href="http://byatool.com/index.php/ui/jquery-slide-menu-another-cause-i-can-experiment/">this post</a> about how I came to create such a wonderful menu with no real purpose as of yet. Well that <a href="http://byatool.com/Hosted/LiveDemos/SlideMenuHoverDivs/SlideMenuHoverDivs.htm">menu has been improved</a> and can be <a href="http://iamwebproject.com/BAT/SlideMenuHoverDivs.zip">downloaded here</a>.</p>
<p>Remember that question you never asked? Well once again I&#8217;ve answered it.</p>
<p>To take the normal sliding menu farther I thought I should have something happen when hovering over the menu items. Novel! Well as you can see if you clicked on the link above (Sorry, can&#8217;t repost the link. Links are expensive.) the menu items have large counter parts that show up when hovered over and don&#8217;t go away until the counter part or the main item is left. What does this all mean? I DON&#8217;T KNOW but I&#8217;ll find out eventually. It&#8217;s in the cards man, it&#8217;s in the cards&#8230;</p>
<p>Ok so additions&#8230; For the style sheet, I added a class:</p>
<pre><span style="color: #800000;">.menuItemBig
</span>{
  <span style="color: #ff0000;">height</span>:<span style="color: #0000ff;">100px</span>;
  <span style="color: #ff0000;">margin</span><span style="color: #ff0000;">-right</span>:<span style="color: #0000ff;">5px</span>;
  <span style="color: #ff0000;">position</span>:<span style="color: #0000ff;">absolute</span>;
  <span style="color: #ff0000;">width</span>:<span style="color: #0000ff;">100px</span>;
  <span style="color: #ff0000;">z-index</span>:<span style="color: #0000ff;">100</span>;
}</pre>
<p>And have included a child div to the menu item:</p>
<p><strong>Before</strong></p>
<pre>  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem</span> <span style="color: #0000ff;">floatLeft</span> <span style="color: #0000ff;">blue</span>"&gt;1&lt;/<span style="color: #800000;">div</span>&gt;</pre>
<p><strong>Now</strong></p>
<pre>  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft blue"</span>&gt;
    1
    &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItemBig red"</span>&gt;THIS IS THE BIG ITEM 1&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;/<span style="color: #800000;">div</span>&gt;</pre>
<p>I added two methods:</p>
<pre><span style="color: #008000;">//
</span><span style="color: #008000;">// mouseenter: Find any menuItemBig within the given element and show</span>
<span style="color: #008000;">//             Reset the position of the menuItemBig element to appear</span>
<span style="color: #008000;">//             to be in the middle of the parent element</span>
<span style="color: #008000;">// mouseleave: Hide the child menuItemBig</span>
<span style="color: #008000;">//</span>
<span style="color: #0000ff;">function</span> setOnHoverForMenuItems(items)
{
  jQuery(items)
  .each
  (
    <span style="color: #0000ff;">function</span> ()
    {
      jQuery(<span style="color: #0000ff;">this</span>).mouseenter
      (
        <span style="color: #0000ff;">function</span>()
        {
          <span style="color: #008000;">//Why the positioning?  I wanted the child div to show up in the</span>
          <span style="color: #008000;">// middle of the parent div which is done by putting the child's left side</span>
          <span style="color: #008000;">// to half of the width of the parent over from the parent's left side</span>
          <span style="color: #0000ff;">var</span> parentPosition = jQuery(<span style="color: #0000ff;">this</span>).position();
          <span style="color: #0000ff;">var</span> bigItems = jQuery(<span style="color: #0000ff;">this</span>).children(<span style="color: #800000;">".menuItemBig"</span>);
          bigItems.css({ left: parentPosition.left - (jQuery(<span style="color: #0000ff;">this</span>).width() /2), top: parentPosition.top + 10  });
          bigItems.show();
        }
      );

      jQuery(<span style="color: #0000ff;">this</span>).mouseleave
      (
        <span style="color: #0000ff;">function</span>()
        {
          jQuery(<span style="color: #0000ff;">this</span>).children(<span style="color: #800000;">".menuItemBig"</span>).hide();
        }
      );
    }
  );
}</pre>
<p>Why not hover? *EDIT* It should be hover.  Turns out an issue I was having with hover was not actually an issue with it&#8230;  *END EDIT*</p>
<p>The other method I added was a simple one:</p>
<pre><span style="color: #008000;">//</span>
<span style="color: #008000;">// Used to find any element of menuItemBig</span>
<span style="color: #008000;">//</span>
<span style="color: #0000ff;">function</span> hideAllBigItems(bigItemParentItems)
{
  jQuery(bigItemParentItems).children(<span style="color: #800000;">".menuItemBig"</span>).hide();
}</pre>
<p>And where did I use these? I appended them to the setChildrenDivs method:</p>
<pre><span style="color: #0000ff;">function</span> setChildrenDivs(mainHolder)
{
  <span style="color: #0000ff;">var</span> menuItems = getMenuItems(mainHolder);

  <span style="color: #0000ff;">for</span> (var loopCounter = 0; loopCounter &lt; menuItems.length; loopCounter++)
  {
    <span style="color: #0000ff;">if</span>(loopCounter &gt; maximumToShow - 1)
    {
      jQuery(menuItems[loopCounter]).hide();
    }
  }

  setPager(jQuery(mainHolder).children(<span style="color: #800000;">".leftPager"</span>), getLastVisible, getNextInLineBack);
  setPager(jQuery(mainHolder).children(<span style="color: #800000;">".rightPager"</span>),getFirstVisible, getNextInLineFront);
  <span style="color: #ff0000;">setOnHoverForMenuItems(menuItems);</span>
  <span style="color: #ff0000;">hideAllBigItems(menuItems);</span>
}</pre>
<p>So in all, this didn&#8217;t take much at all, thanks to mouseleave. Next up&#8230; not sure. No idea if I will take this any further.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-slide-menu-with-pop-up-divs-yay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Slide Menu&#8230;  Another Cause I Can Experiment</title>
		<link>http://byatool.com/ui/jquery-slide-menu-another-cause-i-can-experiment/</link>
		<comments>http://byatool.com/ui/jquery-slide-menu-another-cause-i-can-experiment/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 17:00:41 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Menu]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=827</guid>
		<description><![CDATA[So for no real reason at all I had it in my mind that I wanted to make a horizontal menu with jQuery that would work like that weird scrolling menu thing that Macs have. No idea what it&#8217;s called. So basically I don&#8217;t need it, have no reason for it, but damnit I&#8217;m going [...]]]></description>
			<content:encoded><![CDATA[<p>So for no real reason at all I had it in my mind that I wanted to make a horizontal menu with jQuery that would work like that weird scrolling menu thing that Macs have.  No idea what it&#8217;s called.  So basically I don&#8217;t need it, have no reason for it, but damnit I&#8217;m going to make it happen and I did it with only 3 things from <a href="http://www.jquery.com">jquery.com</a>; 1.3.2, ui 1.7.2, and jquery.timer . Now this is still rough in the sense it has no real styling but it works tried and true functionality wise.</p>
<p>The main idea is that there are two scroll arrows, one on each side, and X amount of divs. Now at the start, a certain amount of divs are hidden (global variable). When hovering over the left pager, for example, it causes one on the right to hide while one on the left appears giving the feeling of the items sliding.</p>
<p><a href="http://www.byatool.com/Hosted/LiveDemos/SlideMenu/SlideMenu.htm">EXAMPLE HERE!!11</a></p>
<p>The markup is simple, a holder with x number of elements that are &#8220;menuitems&#8221; and two pager divs.</p>
<pre>&lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="mainHolder"</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="leftPager green floatLeft"</span>&gt;&lt;&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft blue"</span>&gt;1&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft red"</span>&gt;2&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft yellow"</span>&gt;3&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft blue"</span>&gt;4&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft red"</span>&gt;5&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft yellow"</span>&gt;6&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="menuItem floatLeft blue"</span>&gt;7&lt;/<span style="color: #800000;">div</span>&gt;
  &lt;<span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="rightPager green floatLeft"</span>&gt;&gt;&lt;/<span style="color: #800000;">div</span>&gt;
&lt;/<span style="color: #800000;">div</span>&gt;</pre>
<p>I think from the classes you can tell what you need to know about them.</p>
<p>First thing we need from jQuery is methods to find various elements in the container when paging.</p>
<pre><span style="color: #008000;">//When using the left pager, it's important to find the first visible element
</span><span style="color: #008000;">//then find the item before it so that it can be shown.</span>
<span style="color: #0000ff;">function</span> getNextInLineBack(menuItems)
{
  <span style="color: #0000ff;">var</span> oneBefore = <span style="color: #0000ff;">null</span>;

  <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; menuItems.length; loopCounter++)
  {
    <span style="color: #0000ff;">if</span>(jQuery(menuItems[loopCounter]).is(<span style="color: #ff0000;">":visible"</span>) &amp;&amp; loopCounter &gt; 0)
    {
      oneBefore = jQuery(menuItems[loopCounter - 1 ]);
      <span style="color: #0000ff;">break</span>;
    }
  }

  <span style="color: #0000ff;">return</span> oneBefore;
}

<span style="color: #008000;">//Find the first visible element from the beginning.
</span><span style="color: #008000;">//This will be needed when paging right since it will have to be hidden</span>
<span style="color: #0000ff;">function</span> getFirstVisible(menuItems)
{
  <span style="color: #0000ff;">var</span> firstVisible = <span style="color: #0000ff;">null</span>;

  <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; menuItems.length; loopCounter++)
  {
    <span style="color: #0000ff;">if</span>(jQuery(menuItems[loopCounter]).is(<span style="color: #ff0000;">":visible"</span>) &amp;&amp; loopCounter &lt; menuItems.length - maximumToShow)
    {
        firstVisible = menuItems[loopCounter];
        <span style="color: #0000ff;">break</span>;
    }
  }
  <span style="color: #0000ff;">return</span> firstVisible;
} 

<span style="color: #008000;">//Get the last possible visible item
</span><span style="color: #008000;">/</span><span style="color: #008000;">/If the item is in an index less than the maximum number to show, then null is returned since there has to be no more or less than the maximumToShow.
</span><span style="color: #0000ff;">function</span> getLastVisible(menuItems)
{
  <span style="color: #0000ff;">var</span> lastVisible = <span style="color: #0000ff;">null</span>;
  <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = menuItems.length - 1; loopCounter &gt; maximumToShow - 1; loopCounter--)
  {
    <span style="color: #0000ff;">if</span>(jQuery(menuItems[loopCounter]).is(<span style="color: #ff0000;">":visible"</span>))
    {
      lastVisible = menuItems[loopCounter];
      <span style="color: #0000ff;">break</span>;
    }
  }

  <span style="color: #0000ff;">return</span> lastVisible;
}

<span style="color: #008000;">//Find the first visible from the end
</span><span style="color: #008000;">//Pretty simple, this will be important when paging left since this</span>
<span style="color: #008000;">//will be the next item to be hidden</span>
<span style="color: #0000ff;">function</span> getNextInLineFront(menuItems)
{
  <span style="color: #0000ff;">var</span> lastOne = <span style="color: #0000ff;">null</span>;

  <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = menuItems.length-1; loopCounter &gt; -1; loopCounter--)
  {
    <span style="color: #0000ff;">if</span>(jQuery(menuItems[loopCounter]).is(<span style="color: #ff0000;">":visible"</span>))
    {
      lastOne = menuItems[loopCounter + 1];
      <span style="color: #0000ff;">break</span>;
    }
  }

  <span style="color: #0000ff;">return</span> lastOne;
}</pre>
<p>Next is a method that is just used to stop having to repeat the same thing over and over when needing a list of all the menu items.</p>
<pre><span style="color: #0000ff;">function</span> getMenuItems(mainHolder)
{
  <span style="color: #0000ff;">return</span> jQuery(mainHolder).children(<span style="color: #ff0000;">".menuItem"</span>);
}</pre>
<p>Next is the method to handle what item to show and what item to hide when the pager has the mouse over it. Instead of having methods for the right and left pager, I just ended up having the methods for finding the item to hide and show sent through as parameters.</p>
<pre><span style="color: #0000ff;">function</span> showHideOnHover(pager, timer, getHideMethod, getShowMethod)
{
  <span style="color: #008000;">//This is just candy for changing the color of the pager when the mouse</span>
  <span style="color: #008000;">//is over it</span>
  jQuery(pager).removeClass(<span style="color: #ff0000;">"green"</span>);
  jQuery(pager).addClass(<span style="color: #ff0000;">"orange"</span>);

  <span style="color: #008000;">//Remember those methods I passed through, well here they</span>
  <span style="color: #008000;">//are in use.  I'm using them to get the item to hide and the item</span>
  <span style="color: #008000;">//to show along with the list of items.</span>
  <span style="color: #0000ff;">var</span> menuItems = getMenuItems(jQuery(pager).parent());
  <span style="color: #0000ff;">var</span> hide = getHideMethod(menuItems);
  <span style="color: #0000ff;">var</span> show = getShowMethod(menuItems);

  <span style="color: #008000;">//If neither is null, then go ahead and show/hide</span>
  <span style="color: #008000;">//If either one is null, something isn't right and the timer</span>
  <span style="color: #008000;">//needs to be stopped.... timer??  Well I'll get to that</span>
  <span style="color: #008000;">//next.</span>
  <span style="color: #0000ff;">if</span>(show != <span style="color: #0000ff;">null</span> &amp;&amp; hide != <span style="color: #0000ff;">null</span>)
  {
    jQuery(hide).hide( <span style="color: #ff0000;">"slide"</span>, { direction: <span style="color: #ff0000;">"right"</span> } , 0);
    jQuery(show).show( <span style="color: #ff0000;">"slide"</span>, { direction: <span style="color: #ff0000;">"left"</span> } , 100);
  }
  else
  {
    timer.stop();
  }
}</pre>
<p>Now for the method above the last one, this one involves the timer passed in the last method. This method actually sets the mouseover/mouseout events (aka hover). When mouseover, the timer is created and the showHideOnHover method is called every 500 units, that&#8217;s we&#8217;ll call tools, (Not sure how much that is, seems like a half second) after the first time it&#8217;s called. On mouseout, the timer is stopped, nulled out, and the pager changes it&#8217;s color.</p>
<pre><span style="color: #0000ff;">function</span> setPager(pager, hideMethod, showMethod)
{
  <span style="color: #008000;">//Making the timer variable "global" to the events so that I know
</span>  <span style="color: #008000;">//I have the same timer for both mouseover and mouseout.</span>
  <span style="color: #0000ff;">var</span> newTimer;
  pager.hover
  (
    <span style="color: #008000;">//Mouseover method
</span>    function()
    {
      var first = true;
      <span style="color: #008000;">//This sets the timer, consequently starting the method for the first time.
</span>      <span style="color: #008000;">//Why timer doesn't have a start method I don't know.  Ask jquery.com.
</span>      <span style="color: #008000;">//The first thing is just so that the first time around it runs right away,
</span>      <span style="color: #008000;">//then each call afterwards comes every 500 tools.
</span>      newTimer = jQuery.timer
                      (
                         0, <span style="color: #008000;">//First time through, runs after 0 tools.</span>
                         function(timer)
                         {
                           showHideOnHover(pager, timer, hideMethod, showMethod);
                           <span style="color: #008000;">//If this is the first time through, reset</span>
                           <span style="color: #008000;">//timer to run every 500 tools.</span>
                           <span style="color: #0000ff;">if</span>(first)
                           {
                              timer.reset(500);
                              first = <span style="color: #0000ff;">false</span>;
                           }
                         }
                       );
    },

    <span style="color: #008000;">//Mouseout method
</span>    <span style="color: #0000ff;">function</span>()
    {
      <span style="color: #008000;">//mouse is done, stop the timer</span>
      newTimer.stop();
      newTimer = <span style="color: #0000ff;">null</span>;
      jQuery(pager).addClass(<span style="color: #ff0000;">"green"</span>);
      jQuery(pager).removeClass(<span style="color: #ff0000;">"orange"</span>)
    }
  );
}</pre>
<p>Now for the method above the one&#8230; above. This is used to set the children of the passed in holder.</p>
<pre><span style="color: #0000ff;">function</span> setChildrenDivs(mainHolder)
{
  <span style="color: #008000;">//Get the items for the holder
</span>  <span style="color: #0000ff;">var</span> menuItems = getMenuItems(mainHolder);

  <span style="color: #008000;">//Hide all the items after the first X items (maximumToShow)</span>
  <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; menuItems.length; loopCounter++)
  {
    if(loopCounter &gt; maximumToShow - 1)
    {
      jQuery(menuItems[loopCounter]).hide();
    }
  }

  <span style="color: #008000;">//set the pagers.</span>
  setPager(jQuery(mainHolder).children(<span style="color: #ff0000;">".leftPager"</span>), getLastVisible, getNextInLineBack);
  setPager(jQuery(mainHolder).children(<span style="color: #ff0000;">".rightPager"</span>),getFirstVisible, getNextInLineFront);
}</pre>
<p>FINALLY THE END! This is the document.ready method used to set this whole joke in motion. maximumToShow is just how many items to show at a time and is global.</p>
<pre><span style="color: #0000ff;">var</span> maximumToShow = 5;

jQuery(document).ready
(
  <span style="color: #0000ff;">function</span>()
  {
    <span style="color: #008000;">//Find every holder on the page and set everything in motion.
</span>    <span style="color: #0000ff;">var</span> mainHolders = jQuery(<span style="color: #ff0000;">".mainHolder"</span>);
    <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; mainHolders.length; loopCounter++)
    {
      setChildrenDivs(mainHolders[loopCounter]);
    }
  }
);</pre>
<p>Why the timer? If you haven&#8217;t figured that out yet, well it&#8217;s because I had issues with how to get the menu to keep doing it&#8217;s thing as long as the user had his/her mouse over a pager. I didn&#8217;t want this to be a click menu because, let&#8217;s be honest, that would be much easier. So as is, the timer is started the moment the mouse is over a pager and hides/shows an item. Then every 500 tools the mouse is over the pager, it continues the hide/show until it runs out of items to show/hide. (End of the list)</p>
<p>Uhg that&#8217;s annoying to type out even with cut and paste so <a href="http://www.iamwebproject.com/BAT/SlideMenu.zip">I will host it here</a>.</p>
<p>I suppose the next part of this would have the items blow up or something when hovering over them but that should be much easier than this was.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-slide-menu-another-cause-i-can-experiment/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery Slide and Pairing a Div&#8217;s Hover With a Div&#8217;s Slide</title>
		<link>http://byatool.com/ui/jquery-slide-and-pairing-a-divs-hover-with-a-divs-slide/</link>
		<comments>http://byatool.com/ui/jquery-slide-and-pairing-a-divs-hover-with-a-divs-slide/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 19:19:31 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=749</guid>
		<description><![CDATA[So this could be filed under &#8220;I did it because I can&#8221; (which is a really good mantra in science&#8230;) and am not sure I&#8217;ll use it but it is useful in the concept. LIVE EXAMPLE HERE The idea is to set the hover on one div to show/hide another div WITHOUT having to use [...]]]></description>
			<content:encoded><![CDATA[<p>So this could be filed under &#8220;I did it because I can&#8221; (which is a really good mantra in science&#8230;) and am not sure I&#8217;ll use it but it is useful in the concept.</p>
<p><a href="http://www.byatool.com/Hosted/LiveDemos/SlideOnHover/SlideOnHover.htm">LIVE EXAMPLE HERE</a></p>
<p>The idea is to set the hover on one div to show/hide another div WITHOUT having to use some kind of id/name trick (as in setting the id to &#8220;divHide1&#8243;) and to have it be completely self setting in the .ready method. Why would this be at all useful? Say you want to roll through a list of things and generate the divs, but want to defer the jQuery until the page has loaded. And you don&#8217;t want to have to resort to:</p>
<pre>    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">id</span>="someDiv&lt;%= someId %&gt;"<span style="color: #0000ff;">&gt;</span><span style="color: #0000ff;">&lt;/</span>div<span style="color: #0000ff;">&gt;</span></pre>
<p>like structure where you parse some identifier from the id property. Mostly because you have no idea how many someDiv1s there could be on the page. It could be a highly reused name (someDiv) and that could lead to a mess.</p>
<p>Also the reason &#8216;cuz. If you have any more questions of why after that answer, well you&#8217;re just being annoying.</p>
<p>Anywho, here&#8217;s the actual html for structure.</p>
<pre>   <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="mainDiv"</span><span style="color: #0000ff;">&gt;</span>
      <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="showDiv"</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="oneTop"&gt;</span>
        Kaneda?
      <span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">/</span><span style="color: #800000;">div</span><span style="color: #0000ff;">&gt;</span>
      <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="slideDiv"</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="one"&gt;</span>
        What do you see?!
      <span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">/</span><span style="color: #800000;">div</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">/</span><span style="color: #800000;">div</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">div</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="clear"</span><span style="color: #0000ff;">&gt;&lt;</span><span style="color: #0000ff;">/</span><span style="color: #800000;">div</span><span style="color: #0000ff;">&gt;</span></pre>
<p>Now I get that this isn&#8217;t off a foreach, but it doesn&#8217;t take much to figure out that it&#8217;s easily made into a loop if you just loop it over and over. Why? Because first there are no ids or names so that you can&#8217;t have two of the same name and also because that chunk is self contained.</p>
<p>So what is going on there? Simple, you have a parent container that holds a div to hold and a div to hover over and the other that will be shown/hidden.</p>
<p>Here&#8217;s the styles involved just incase you care:</p>
<pre>    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">style</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text/css"&gt;</span>
        <span style="color: #800000;">.clear
</span>        {
        	<span style="color: #ff0000;">clear</span>:<span style="color: #0000ff;">both</span>;
        }

        <span style="color: #800000;">.leftDiv</span>
        {
        	<span style="color: #ff0000;">float</span>:<span style="color: #0000ff;">left</span>;
        }

        <span style="color: #800000;">.mainDiv</span>
        {
        	<span style="color: #ff0000;">margin</span>:<span style="color: #0000ff;">5px</span>;
        	<span style="color: #ff0000;">height</span>:<span style="color: #0000ff;">200px</span>;
        }

        <span style="color: #800000;">.rightDiv</span>
        {
        	<span style="color: #ff0000;">float</span>:<span style="color: #0000ff;">left</span>;
        }

        <span style="color: #800000;">.showDiv</span>
        {
        	<span style="color: #ff0000;">float</span>:<span style="color: #0000ff;">left</span>;
        	<span style="color: #ff0000;">margin-right</span>:<span style="color: #0000ff;">5px</span>;
        	<span style="color: #ff0000;">height</span>:<span style="color: #0000ff;">200px</span>;
        	<span style="color: #ff0000;">background-color</span>:<span style="color: #0000ff;">Silver</span>;
        }

        <span style="color: #800000;">.slideDiv</span>
        {
        	<span style="color: #ff0000;">background-color</span>:<span style="color: #0000ff;">Teal</span>;
        	<span style="color: #ff0000;">height</span>:<span style="color: #0000ff;">200px</span>;
        	<span style="color: #ff0000;">position</span>:<span style="color: #0000ff;">absolute</span>;
        	<span style="color: #ff0000;">float</span>:<span style="color: #0000ff;">left</span>;
        	<span style="color: #ff0000;">z-index</span>:<span style="color: #0000ff;">100</span>;
        }
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">style</span><span style="color: #0000ff;">&gt;</span></pre>
<p>That doesn&#8217;t entirely matter, but it does to show the div &#8220;sliding&#8221; over another div. Kind of a little somethin&#8217; somethin&#8217; I threw in at no extra cost. Now for the jQuery:</p>
<p>First the method for setting the mouse over and out events for the show div, we turn to .hover:</p>
<pre>    <span style="color: #0000ff;">function</span> setHover(currentSlideDiv, currentStableDiv)
    {
      currentStableDiv.hover
      (
        <span style="color: #008000;">//first parameter is the method for showing the div on mouse over
</span>        <span style="color: #0000ff;">function</span>()
        {
          if (currentSlideDiv.is(<span style="color: #800000;">":hidden"</span>))
          {
            currentSlideDiv.show(<span style="color: #800000;">"slide"</span>, { direction: <span style="color: #800000;">"left"</span> }, 100);
          }
        },
        <span style="color: #008000;">//second parameter is the method for hiding the div on mouse out
</span>        <span style="color: #0000ff;">function</span>()
        {
          if (currentSlideDiv.is(<span style="color: #800000;">":visible"</span>))
          {
            currentSlideDiv.hide(<span style="color: #800000;">"slide"</span>, { direction: <span style="color: #800000;">"left"</span> }, 100);
          }
        }
      );
    };</pre>
<p>Now for the method that actually uses these:</p>
<pre>    <span style="color: #008000;">//This is used to take in one of the main divs and set all the
</span>    <span style="color: #008000;">//show and slide divs within.</span>
    <span style="color: #0000ff;">function</span> setChildrenDivs(mainDiv)
    {
      <span style="color: #008000;">//get all the show and slide dvis within the main div
</span>      <span style="color: #0000ff;">var</span> mainChildrenStableDiv = jQuery(mainDiv).children(<span style="color: #800000;">".showDiv"</span>);
      <span style="color: #0000ff;">var</span> mainChildrenSlide = jQuery(mainDiv).children(<span style="color: #800000;">".slideDiv"</span>);

      <span style="color: #008000;">//loop through the list of show divs</span>
      <span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; mainChildrenStableDiv.length; loopCounter++)
      {
        <span style="color: #008000;">//Get the show div and it's corresponding slide div using the
</span>        <span style="color: #008000;">//two lists and the current counter.</span>
        <span style="color: #0000ff;">var</span> currentStableDiv = jQuery(mainChildrenStableDiv[loopCounter]);
        <span style="color: #0000ff;">var</span> currentSlideDiv = jQuery(mainChildrenSlide[loopCounter]);

         <span style="color: #008000;">//This is to make sure the slide is where it should be.
</span>         <span style="color: #008000;">//to the right of the show div.</span>
         <span style="color: #0000ff;">var</span> containerPosition = jQuery(currentStableDiv).position();
         jQuery(currentSlideDiv).css({ left: containerPosition.left + currentStableDiv.width() });
        <span style="color: #008000;">//Set the mouse over and the mouse out on the show div</span>
        setHover(currentSlideDiv, currentStableDiv);
      }
    }</pre>
<p>Now the final touch, the .ready method:</p>
<pre>    jQuery(document).ready
    (
      <span style="color: #0000ff;">function</span>()
      {
        <span style="color: #008000;">//hide all the slide divs
</span>        jQuery(<span style="color: #800000;">".slideDiv"</span>).hide();

        <span style="color: #008000;">//find all the parent divs
</span>        <span style="color: #0000ff;">var</span> mainDivs = jQuery(<span style="color: #800000;">".mainDiv"</span>);

        <span style="color: #008000;">//set the children</span>
        for (var loopCounter = 0; loopCounter &lt; mainDivs.length; loopCounter++)
        {
          setChildrenDivs(mainDivs[loopCounter]);
        }
      }
    );</pre>
<p>And boom, now you have multiple show/hide (Slide in this instance). Now if I could just find a use for it&#8230;</p>
<p>Oh yeah and you&#8217;ll need <a href="http://jquery.com/">jQuery 1.3.2</a> and <a href="http://jqueryui.com/">jQuery ui 1.7.2</a> to use this.  At least those are the versions I know this works with.</p>
<p><strong>Update:  Due to popular demand&#8230; one person&#8230; <a href="http://www.byatool.com/Hosted/LiveDemos/SlideOnHover.zip">Source can be found here.</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-slide-and-pairing-a-divs-hover-with-a-divs-slide/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC, jQuery, JSon, and paging&#8230;  how&#8217;s that for a SOE title?</title>
		<link>http://byatool.com/ui/aspnet-mvc-jquery-json-and-paging-hows-that-for-a-soe-title/</link>
		<comments>http://byatool.com/ui/aspnet-mvc-jquery-json-and-paging-hows-that-for-a-soe-title/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 15:44:11 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=721</guid>
		<description><![CDATA[One of the things I&#8217;ve come to realize is how easy it easy to do a lot of things with these three buzzwords. In fact, I&#8217;m pretty convinced it&#8217;s so easy that it&#8217;s actually complex and I am a genius. Not buying it? Neither am I. So for an experiement the other day I decided [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I&#8217;ve come to realize is how easy it easy to do a lot of things with these three buzzwords. In fact, I&#8217;m pretty convinced it&#8217;s so easy that it&#8217;s actually complex and I am a genius. Not buying it? Neither am I.</p>
<p>So for an experiement the other day I decided to try my hand at some sort of dynamic grid using jQuery&#8217;s ajax fun and JSon. Just so happens that this works really well with MVC&#8217;s REST like makeup. Don&#8217;t know what REST is? On a very tool level, it&#8217;s using a url and a command to tell the server what to do. So something like:</p>
<p>www.byatool.com/users/dostuff</p>
<p>Could mean either get all users (if using get) or create a user (If using post). And yes that is probably a ridiculously simplistic view so I&#8217;d suggest consulting the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">Wikitruth</a>. In an MVC sense this would be:</p>
<p>Controller: Users<br />
Action: dostuff</p>
<p>Now most likely your Get All Users action isn&#8217;t going to the same as your Add A User action, but it was just a stupid example ok?</p>
<p>However, with jQuery what this means is you have a simple url that it can call and get information from, making it incredibly easy to set up a dynamic grid.</p>
<p>So first off, lets say I have a Forum controller with an action of IndexJquery&#8230; yeah I know cheesy name, but it gets the job done. Basically the method IndexJquery would have to take in a page number and optionally (And for this example) how many items to show along with a sort. With that it should return a JSon &#8220;object&#8221; that will be in this example holds first page, last page, next page, previous page, sortBy, and some kind of list of stuff. (For the two people actually reading this, comment if you want the c# code. It&#8217;s really just basic MVC stuff.)</p>
<p>The markup for this is pretty simple. I have a div to hold the grid, four directional divs that work as buttons (First, Previous, Next, Last), and two div &#8220;butons&#8221; for how many items to show.</p>
<pre>    &lt;div&gt;
        &lt;div id="divHolder"&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;div id="divFirstPage" class="divLink floatLeft"&gt;
            &lt;&lt;
        &lt;/div&gt;
        &lt;div id="divPreviousPage" class="divLink floatLeft"&gt;
            &lt;
        &lt;/div&gt;
        &lt;div id="divNextPage" class="divLink floatLeft"&gt;
            &gt;
        &lt;/div&gt;
        &lt;div id="divLastPage" class="divLink floatLeft"&gt;
            &gt;&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="clear"&gt;&lt;/div&gt;
    &lt;div&gt;
        &lt;div id="divAmountToShowOne" class="divLink floatLeft"&gt;
            1
        &lt;/div&gt;
        &lt;div id="divAmountToShowFive" class="divLink floatLeft"&gt;
            5
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="clear"&gt;&lt;/div&gt;</pre>
<p>As you can see exactly as advertised.</p>
<p>Ready for the call? It&#8217;s waaaaay hard:</p>
<pre>        <span style="color: #0000ff;">function</span> getGrid(pageNumberIn, amountToShowIn, sortByIn)
        {
            jQuery.getJSON
            (
               <span style="color: #008000;">//This is the url for the information I need
</span>               <span style="color: #800000;">"http://www.someurl.com/Forum/IndexJquery/"</span>,
               <span style="color: #008000;">//this is the construction of the "object" to send... really this just
               //means that I have a method somewhere looking for pageNumber,
               //amountToShow, and sortBy</span>
               {
                   pageNumber: pageNumberIn,
                   amountToShow: amountToShowIn,
                   sortBy: sortByIn
               },
               <span style="color: #008000;">//This is the method to call once this ajax transaction has completed...
</span>               <span style="color: #008000;">//transaction may not be the best word.  Basically it has to be a method
</span>               <span style="color: #008000;">//that takes in the result from the getJSon call
</span>               returned
            );
        }</pre>
<p>Next would be the script to actually create the grid. Looks verbose, but most likely thats because I didn&#8217;t refactor much.</p>
<pre>    <span style="color: #0000ff;">function</span> returned(jsonObject)
    {
        <span style="color: #008000;">//Have to remove all the previous click event handlers since because
</span>        <span style="color: #008000;">//this is all client side, there's no "refresh" and therefore the object
</span>        <span style="color: #008000;">//is still in memory.  So even though I might call the method to get the
</span>        <span style="color: #008000;">//information, the "objects" are still in memory.</span>
        jQuery(<span style="color: #800000;">"#divFirstPage"</span>).unbind(<span style="color: #800000;">"click"</span>);
        jQuery(<span style="color: #800000;">"#divLastPage"</span>).unbind(<span style="color: #800000;">"click"</span>);
        jQuery(<span style="color: #800000;">"#divNextPage"</span>).unbind(<span style="color: #800000;">"click"</span>);
        jQuery(<span style="color: #800000;">"#divPreviousPage"</span>).unbind(<span style="color: #800000;">"click"</span>);
        jQuery(<span style="color: #800000;">"#divAmountToShowOne"</span>).unbind(<span style="color: #800000;">"click"</span>);
        jQuery(<span style="color: #800000;">"#divAmountToShowFive"</span>).unbind(<span style="color: #800000;">"click"</span>);

        <span style="color: #008000;">//Ok so now that the event is not being listened to, set up the listeners</span>
        <span style="color: #008000;">//The idea is to call that getGrid method and pass in the values straight</span>
        <span style="color: #008000;">//off the previously returned json object.  Using jQuery's easy .click method
</span>        <span style="color: #008000;">//makes this so simple.
</span>        jQuery(<span style="color: #800000;">"#divFirstPage"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(jsonObject.FirstPage, jsonObject.AmountToShow, jsonObject.SortBy); })
        jQuery(<span style="color: #800000;">"#divPreviousPage"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(jsonObject.PreviousPage, jsonObject.AmountToShow, jsonObject.SortBy); })
        jQuery(<span style="color: #800000;">"#divNextPage"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(jsonObject.NextPage, jsonObject.AmountToShow, jsonObject.SortBy); })
        jQuery(<span style="color: #800000;">"#divLastPage"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(jsonObject.LastPage, jsonObject.AmountToShow, jsonObject.SortBy); })
        jQuery(<span style="color: #800000;">"#divAmountToShowOne"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(0, 1, jsonObject.SortBy); })
        jQuery(<span style="color: #800000;">"#divAmountToShowFive"</span>).click(<span style="color: #0000ff;">function</span>() { getGrid(0, 5, jsonObject.SortBy); })

        <span style="color: #008000;">//Again since this is client side, the divHolder "object" still is holding
</span>        <span style="color: #008000;">//the previous results.  These have to be cleared.
</span>        jQuery(<span style="color: #800000;">"#divHolder"</span>).children().remove();

        <span style="color: #008000;">//Create the table and loop through the list.
</span>        <span style="color: #0000ff;">var</span> mytable = document.createElement(<span style="color: #800000;">"table"</span>);
        <span style="color: #0000ff;">var</span> mytablebody = document.createElement(<span style="color: #800000;">"tbody"</span>);

        <span style="color: #0000ff;">for</span> (loopCounter = 0; loopCounter &lt; jsonObject.ListForViewing.length; loopCounter++)
        {
           <span style="color: #0000ff;">var</span> currentItem = something.ListForViewing[loopCounter];
           <span style="color: #0000ff;">var</span> mycurrent_row = document.createElement(<span style="color: #800000;">"tr"</span>);

           <span style="color: #0000ff;">var</span> mycurrent_cell = document.createElement(<span style="color: #800000;">"td"</span>);
           <span style="color: #0000ff;">var</span> currentText = document.createTextNode(currentItem.ForumName);
           mycurrent_cell.appendChild(currentText);
           mycurrent_row.appendChild(mycurrent_cell);

           mytablebody.appendChild(mycurrent_row);
        }

        mytable.appendChild(mytablebody);
        <span style="color: #008000;">//Don't forget to add the table to the div!!11
</span>        jQuery(<span style="color: #800000;">"#divHolder"</span>).append(mytable);
        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;
    }</pre>
<p>And boom. So easy even a ca&#8230; tool can do it. Now if you want this grid to come preloaded, it&#8217;s pretty easy:</p>
<pre>
    jQuery(document).ready
    (
        <span style="color: #0000ff;">function</span> setPage()
        {
            getGrid(0, 10, null);
        }
    )</pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/aspnet-mvc-jquery-json-and-paging-hows-that-for-a-soe-title/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Stop the IPhone / Safari from Minimzing a Page</title>
		<link>http://byatool.com/ui/stop-the-iphone-safari-from-minimzing-a-page/</link>
		<comments>http://byatool.com/ui/stop-the-iphone-safari-from-minimzing-a-page/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 16:40:25 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=579</guid>
		<description><![CDATA[Real quick one, but I thought this was crazy useful. If you&#8217;re developing a web based app that might be used by IPhone users, there is a simple way to stop the IPhone from shrinking the page onload. Thanks to Mark W on The Stack Hath Runith Over there is a simple solution. &#60;head runat="server"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Real quick one, but I thought this was crazy useful.</p>
<p>If you&#8217;re developing a web based app that might be used by IPhone users, there is a simple way to stop the IPhone from shrinking the page <span class="showItLink" xmlns:comment="Which causes the ultra annoying need to resize.">onload</span>. Thanks to <a href="http://markwunsch.com">Mark W</a> on <a href="http://www.stackoverflow.com">The Stack Hath Runith Over</a> there is a simple solution.</p>
<pre>  &lt;head runat="server"&gt;
     &lt;title&gt;I LOVE TITLES!&lt;/title&gt;
     &lt;meta name="viewport" content="width=420" /&gt;</pre>
<p>That one beautiful metatag makes life worth living again&#8230; until the next Street Fighter movie comes out. Then life is back in the forfeit container. Here&#8217;s a link to more options:<br />
<a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/chapter_4_section_5.html#//apple_ref/doc/uid/TP40006509-SW26">BYEBYE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/stop-the-iphone-safari-from-minimzing-a-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Add a Pop Up Div to a Link Dynamically</title>
		<link>http://byatool.com/ui/556/</link>
		<comments>http://byatool.com/ui/556/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 14:50:31 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=556</guid>
		<description><![CDATA[So as an exercise to learn more about jQuery, I decided to redo this little gem using jQuery. Have to say though only technically XHTML compliant, it worked out much better and with less code. So the idea is to have something really easy for non programmers (You know, lesser people) to be able to [...]]]></description>
			<content:encoded><![CDATA[<p>So as an exercise to learn more about jQuery, I decided to redo this <a href="http://byatool.com/index.php/ui/add-a-pop-up-div-to-a-link-dynamically">little gem</a> using jQuery. Have to say though only technically XHTML compliant, it worked out much better and with less code. So the idea is to have something really easy for non programmers (You know, lesser people) to be able to have a pop up comment added to some chunk of text on a web site. What I came up with before was ok but kind of annoying since it looked like this:</p>
<pre>&lt;<span style="color: #800000;">a</span> <span style="color: #ff0000;">onclick</span><span style="color: #0000ff;">="return ShowCommentForPost('1', this, 'THIS IS SO STUPID!');"</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">="www.byatool.com"</span>&gt;word.&lt;<span style="color: #800000;">/a</span>&gt;</pre>
<p>Kind of annoying since I would have to explain that &#8217;1&#8242; is the name and it has to be unique for every one of <a class="showItLink" href="http://www.byatool.com" xmlns:comment="Hahaha... yeah they'll make them unique.  Really.  People aren't lazy.">these</a>, this isn&#8217;t really understood by those people, and well it just seems more complicated then it needs to be. So what if I told you it could look like this?</p>
<pre>&lt;<span style="color: #800000;">a</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">="http://www.byatool.com"</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="showItLink"</span> <span style="color: #ff0000;">xmlns:comment</span><span style="color: #0000ff;">="hihihi"</span>&gt;HI&lt;<span style="color: #800000;">/a</span>&gt;</pre>
<p>Gorsh, that seems even better and it works in both IE and Firefox&#8230; which might be a first for this site and anything javascript. First let&#8217;s get the css out of the way, shall we?</p>
<pre>    .<span style="color: #800000;">showItLink</span>
    {
    }

    .<span style="color: #800000;">postComment</span>
    {
        <span style="color: #ff0000;">background-color</span>:<span style="color: #0000ff;">Gray</span>;
        <span style="color: #ff0000;">border-color</span>:<span style="color: #0000ff;">Black</span>;
        <span style="color: #ff0000;">border-style</span>:<span style="color: #0000ff;">dotted</span>;
        <span style="color: #ff0000;">border-width</span>:<span style="color: #0000ff;">thin</span>;
        <span style="color: #ff0000;">color</span>:<span style="color: #0000ff;">White</span>;
        <span style="color: #ff0000;">margin-right</span>:<span style="color: #0000ff;">3px</span>;
        <span style="color: #ff0000;">padding</span>:<span style="color: #0000ff;">3px</span>;
        <span style="color: #ff0000;">position</span>:<span style="color: #0000ff;">absolute</span>;
        <span style="color: #ff0000;">text-decoration</span>:<span style="color: #0000ff;">none</span>;
        <span style="color: #ff0000;">z-index</span>:<span style="color: #0000ff;">50</span>;
    }</pre>
<p>Most of the is just for looks, but like the older example I&#8217;ve called upon the power of <a href="http://byatool.com/index.php/ui/jquery-position-absolute-and-how-to-make-it-all-work">position:absolute</a> and z-index well that&#8217;s just pulling it in front of everything else.</p>
<p>Next part will be the actual code, and if you take the method <a class="showItLink" href="http://www.byatool.com" xmlns:comment="ANOTHER PLUG AHHHHH!!!11">from</a> <a href="http://byatool.com/index.php/ui/jquery-position-absolute-and-how-to-make-it-all-work">THE POSITION ABSOLUTE POST</a></p>
<pre>    <span style="color: #0000ff;">function</span> SetTopAndLeft(parentContainer, elementToSet)
    {
        <span style="color: #0000ff;">var</span> containerPosition;

        containerPosition = $(parentContainer).position();
        $(elementToSet).css({ top: containerPosition.top + 10, left: containerPosition.left + 10 });
    }</pre>
<p>and add in a simple span creation method:</p>
<pre>    <span style="color: #0000ff;">function</span> CreateDiv(innerText, cssClass)
    {
        <span style="color: #0000ff;">var</span> spanToAdd;

        spanToAdd = document.createElement(<span style="color: #ff0000;">'span'</span>);
        spanToAdd.className = cssClass;
        spanToAdd.innerHTML = innerText;

        <span style="color: #0000ff;">return</span> spanToAdd;
    }</pre>
<p>you&#8217;re ready for the actual fun part&#8230; making sure something pops up when the link is clicked.</p>
<pre>jQuery(document).ready  <span style="color: #008000;">//Everything inside this will load as soon as the DOM is loaded and before the page contents are loaded.</span><a href="http://www.learningjquery.com/2006/09/introducing-document-ready"><span style="color: #008000;">*</span></a>
(
    <span style="color: #0000ff;">function</span>()  //this is the start of an anonymous method
    {
        jQuery(<span style="color: #800000;">".showItLink"</span>).click <span style="color: #008000;">//find all things with the .showItLink class and assign the click event to the next anonymous method
        </span>(
            <span style="color: #0000ff;">function</span>(event) <span style="color: #008000;">//this is the start of an anonymous method for the click event</span>
            {
                <span style="color: #0000ff;">var</span> containerPosition;
                <span style="color: #0000ff;">var</span> createdSpan;
                <span style="color: #0000ff;">var</span> comment;

                comment = jQuery(this).attr(<span style="color: #800000;">"xmlns:comment"</span>);  <span style="color: #008000;">//Get the value from the comment attribute on the link.</span>
                createdSpan = jQuery(this).children(<span style="color: #800000;">".postComment"</span>); <span style="color: #008000;">//Find a possible span already attached to the link if it exists.  The span is of class 'postComment'</span>

                <span style="color: #0000ff;">if</span> (createdSpan.length == 0)  <span style="color: #008000;">//span doesn't exist</span>
                {
                    createdSpan= CreateDiv(comment, <span style="color: #800000;">"postComment"</span>);  <span style="color: #008000;">//create the span</span>
                    jQuery(this).append(createdSpan);  <span style="color: #008000;">//Add the span to the link</span>
                    jQuery(this).children(<span style="color: #800000;">".postComment"</span>).hide();  <span style="color: #008000;">//Make sure the new span is hidden
</span>                }
                SetTopAndLeft(this, createdSpan);  <span style="color: #008000;">//Set the position of the span</span>
                jQuery(createdDiv).toggle();  <span style="color: #008000;">//This will hide if it's showing, show if it's hidden... kind of nice huh?</span>

                event.preventDefault();  <span style="color: #008000;">//Equivalent to false.  Need this for Firefox.</span>
            }
        );
    }
);</pre>
<p>And boom you have something that works. Hooray.</p>
<p>Couple things of note:</p>
<p>.Hide &#8211; At first I though this would screw up my class for the span by removing the current class and adding display:none. Turns out it doesn&#8217;t harm the original class. Kind of nice.</p>
<p>.Toggle() &#8211; This is really nice. It will hide if it is showing and show if hidden. Stupid easy to use and is pretty effective. Just like .Hide, the class of the element is not harmed.</p>
<p>$ versus jQuery &#8211; Some people might notice that I am not using the short hand $ for my jQuery calls. Turns out that it might be safer this way. There are other javascript libraries that use the $ short hand like prototype. I ran into this with <a class="showItLink" href="http://byatool.com" xmlns:comment="Go figure...">WordPress </a>since it uses both jQuery and Prototype and blocks jQuery from using $ since it could conflict with other libraries. Weeeee!</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/556/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

