<?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>Hacking at 0300 &#187; jQuery</title>
	<atom:link href="http://bililite.nfshost.com/blog/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://bililite.nfshost.com/blog</link>
	<description>Thoughts on web design and programming from a very occasional volunteer webmaster</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>New jQuery Plugin: showPassword</title>
		<link>http://bililite.nfshost.com/blog/2011/12/13/new-jquery-plugin-showpassword/</link>
		<comments>http://bililite.nfshost.com/blog/2011/12/13/new-jquery-plugin-showpassword/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 20:10:36 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2179</guid>
		<description><![CDATA[I put yesterday's unmask password plugin together with the code to automatically create a checkbox to control it, and removed the dependency on jQuery UI. Download the code. Example &#60;input type=&#34;password&#34; id=&#34;password&#34;/&#62; $('#password').showPassword('Show Characters as I Type'); Use $('[type=password]').showPassword(string) creates a checkbox as above with string as the label. If the checkbox is checked then [...]]]></description>
			<content:encoded><![CDATA[<p>I put yesterday's <a href="/blog/2011/12/12/unmask-password-plugin/" title="Unmask Password Plugin">unmask password plugin</a> together with the code to automatically create a checkbox to control it, and removed the dependency on jQuery UI.</p>
<p><a href="/inc/jquery.showPassword.js">Download the code</a>.</p>
<script src="/inc/jquery.showPassword.js"></script>
<h4>Example</h4>
<pre><code class="demo language-html">&lt;input type=&quot;password&quot; id=&quot;password&quot;/&gt;</code></pre>
<pre><code class="demo language-javascript">$('#password').showPassword('Show Characters as I Type');</code></pre>
<h4>Use</h4>
<p><code class="language-javascript">$('[type=password]').showPassword(string)</code> creates a checkbox as above with <code>string</code> as the label. If the checkbox is checked then the password field is unmasked. <code class="language-javascript">$('type=password').showPassword(true)</code> unmasks the field directly, and <code class="language-javascript">$('type=password').showPassword(false)</code> restores masking.</p>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/12/13/new-jquery-plugin-showpassword/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unmask Password Plugin</title>
		<link>http://bililite.nfshost.com/blog/2011/12/12/unmask-password-plugin/</link>
		<comments>http://bililite.nfshost.com/blog/2011/12/12/unmask-password-plugin/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 23:40:43 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2151</guid>
		<description><![CDATA[I hate password masking&#8212;hiding what I'm typing to prevent someone from looking over my shoulder at my passwords. I know when I'm in public and when I'm alone in the house, and it should be my choice to actually see what I'm typing, since it has to have some nonsense combination of characters. Even Jakob [...]]]></description>
			<content:encoded><![CDATA[<p>I hate password masking&mdash;hiding what I'm typing to prevent someone from looking over my shoulder at my passwords. I know when I'm in public and when I'm alone in the house, and it should be my choice to actually see what I'm typing, since it has to have <a href="http://xkcd.com/936/">some nonsense combination of characters</a>. Even <a href="http://www.useit.com/alertbox/passwords.html">Jakob Nielsen agrees with me</a>.</p>
<p>The logical thing to do is to have a <a href="http://lea.verou.me/2009/06/on-password-masking-and-usability/">checkbox that would show the characters</a>, and the easiest way to do that is to change the <code>type</code> of the <code>input</code> element from <code>password</code> to <code>text</code>.</p>
<p>For most browsers, this is <a href="http://stackoverflow.com/questions/540851/jquery-change-element-type-from-hidden-to-input#answer-3057767">nontrivial but doable</a>. You have to <code><a href="http://api.jquery.com/detach/">detach</a></code> the element first in order to change its <code>type</code>. But in Internet Explorer, there's no way to change it. One solution is to create a new <code>input</code> element with <code>type</code> <code>text</code> and copy all the other attributes into it, but that seems like overkill. All we need is a way for the user to see what he is typing, so a tooltip-like overlay would work.</p>
<p>This is what I came up with (note that it requires <a href="http://jqueryui.com/demos/position/">jQuery UI <code>position</code></a>:</p>
<pre><code class="demo language-html">&lt;input type=&quot;password&quot; id=&quot;password&quot;/&gt;
&lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;check&quot;/&gt; Show characters as I type&lt;/label&gt;</code></pre>
<pre><code class="demo language-javascript">try{
  $('&lt;input type=&quot;password&quot;&gt;').detach().attr('type', 'text');
  $.fn.showPassword = function(shouldShow){
    var type =  shouldShow ? 'text' : 'password';
    return this.each(function(){
      /* from http://stackoverflow.com/questions/540851/jquery-change-element-type-from-hidden-to-input */
      marker = $('&lt;span /&gt;').insertBefore(this);
      $(this).detach().attr('type', type).insertAfter(marker);
      marker.remove(); 
    });
  };
}catch(e){
  $.fn.showPassword = function(shouldShow){
    return this.each(function(){
      if (shouldShow){
        var span = $(this).siblings('.showPassword');
        if (span.length &gt; 0){
          span.show();
        }else{
          span = $('&lt;span&gt;').addClass('showPassword').css({
            opacity: 0.9,
            background: 'white',
            position: 'absolute',
            fontFamily: 'sans-serif',
            paddingLeft: '2px'
          }).position({
            at: 'left bottom',
            of: this,
            my: 'left top'
          }).text(this.value).insertBefore(this);
          $(this).keyup(function(){ span.text(this.value); });
        }
      }else{
        $(this).siblings('.showPassword').hide();
      }
    });
  };
}
$('#check').change(function(){
  $('#password').showPassword($(this).is(':checked'));
});</code></pre>
<p>Try this in Internet Explorer as well as a standards browser. The details are different, but the functionality is the same.</p>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/12/12/unmask-password-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 validator plugin</title>
		<link>http://bililite.nfshost.com/blog/2011/12/06/html5-validator-plugin/</link>
		<comments>http://bililite.nfshost.com/blog/2011/12/06/html5-validator-plugin/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 19:47:00 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2105</guid>
		<description><![CDATA[tl;dr Download the code. Use $.validateHTML5(callback), where callback (result, data) is a function that is called with the result, a string that can be "valid" if the page validated, "invalid" if it did not, "warning" if it validated but is "in some way questionable", or "not validated" if some error occurred. data is the actual [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript" src="/inc/jquery.validateHTML5.js"></script>
<h3>tl;dr</h3>
<p><a href="/inc/jquery.validateHTML5.js">Download the code</a>. Use <code class="language-javascript">$.validateHTML5(callback)</code>, where <code class="language-javascript">callback (result, data)</code> is a function that is called with the <code>result</code>, a string that can be <code class="language-javascript">"valid"</code> if the page validated, <code class="language-javascript">"invalid"</code> if it did not, <code class="language-javascript">"warning"</code> if it validated but is "in some way questionable", or <code class="language-javascript">"not validated"</code> if some error occurred. <code>data</code> is the actual <a href="http://wiki.whatwg.org/wiki/Validator.nu_JSON_Output"><code>JSON</code> output</a> from the validator.</p>
<span id="more-2105"></span>
<h3>Discussion</h3>
<p>Lots of sites have links like <code class="language-html">&lt;a href="http://validator.w3.org/check/referer"&gt;Valid HTML&lt;/a&gt;</code>, which <em>claims</em> that the site is valid and allows you to click the link and check it, but it would be nice to have some way of actually validating the page that is being shown. Nice for me as the author, at least. I'm not sure anyone else cares.</p>
<p>Luckily, I've been doing everything recently in <a href="http://html5.org/">HTML5</a>, and <a href="http://html5.validator.nu/">Validator.nu</a> has a <a href="http://wiki.whatwg.org/wiki/Validator.nu_JSON_Output">web service API with JSON output</a> that we can use programmatically. We don't want to do this on the server side, since that takes time that our users don't need to waste. Also (I did this when playing around with it) you can end up in an infinite loop, where my server GETs the validator output, which GETs the page from the server, which GETs the validator output, which GETs the page from the server, <i>ad infinitum</i>.</p>
<p>So we want to send the page without validating it and then use <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">AJAX</a> to validate it. Fortunately, the validator allows <a href="http://en.wikipedia.org/wiki/JSONP">JSONP</a>, so we don't have to worry about same-origin security. Unfortunately, the <a href="http://wiki.whatwg.org/wiki/Validator.nu_JSON_Output">documentation wiki</a> is wrong about exactly what is returned, so it took some experimentation to get it to work.</p>
<p><a href="/blog/blogfiles/validatortest.php">See the example</a>.</p>
<p>The <a href="http://validator.w3.org/">W3C validator</a> has a validator and does have a <a href="http://validator.w3.org/docs/api.html">web service</a>, but the only documented output format is SOAP. <code>output=json</code> works to produce JSON, but I can't find a way to get JSONP.</p>
]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/12/06/html5-validator-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minor update to flexcal</title>
		<link>http://bililite.nfshost.com/blog/2011/11/27/minor-update-to-flexcal/</link>
		<comments>http://bililite.nfshost.com/blog/2011/11/27/minor-update-to-flexcal/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 00:22:59 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Judaism]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2097</guid>
		<description><![CDATA[Updated flexcal to 1.2.1; nothing major, just changed the Hebrew numbers to use the technically correct Unicode code points HEBREW PUNCTUATION GERESH (&#38;#x05F3; &#x05F3;) and HEBREW PUNCTUATION GERSHAYIM (&#38;#x05F4; &#x05F4;) rather than single and double quotes. Also similarly updated the Hebrew keyboard.]]></description>
			<content:encoded><![CDATA[<p>Updated <a href="/blog/2009/04/03/new-jquery-widget-flexcal/" title="New jQuery Widget: flexcal"><code>flexcal</code></a> to 1.2.1; nothing major, just changed the Hebrew numbers to use the <a href="http://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet">technically correct Unicode code points</a> HEBREW PUNCTUATION GERESH (&amp;#x05F3; <strong>&#x05F3;</strong>) and HEBREW PUNCTUATION GERSHAYIM (&amp;#x05F4; <strong>&#x05F4;</strong>) rather than single and double quotes. Also similarly updated the <a href="/blog/2009/01/02/new-ui-widgets-textpopup-and-hebrewkeyboard/" title="New UI widgets: textpopup and hebrewKeyboard">Hebrew keyboard</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/11/27/minor-update-to-flexcal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>flexcal package</title>
		<link>http://bililite.nfshost.com/blog/2011/11/07/flexcal-package/</link>
		<comments>http://bililite.nfshost.com/blog/2011/11/07/flexcal-package/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 22:35:48 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2079</guid>
		<description><![CDATA[There's been some interest in putting flexcal and all its dependencies into a single file (that would be jquery.ui.subclass.js, jquery.textpopup.js, jquery.flexcal.js, and flexcal.html). The problem with putting it all into a ZIP file is keeping it updated; I don't have an automated make-like system and there's no way I'm going to remember to keep the [...]]]></description>
			<content:encoded><![CDATA[<p>There's been some interest in putting <a href="/blog/2009/04/03/new-jquery-widget-flexcal/" title="New jQuery Widget: flexcal"><code>flexcal</code></a> and all its dependencies into a single file (that would be <code>jquery.ui.subclass.js</code>, <code>jquery.textpopup.js</code>, <code>jquery.flexcal.js</code>, and <code>flexcal.html</code>). The problem with putting it all into a ZIP file is keeping it updated; I don't have an automated <code>make</code>-like system and there's no way I'm going to remember to keep the package up to date. So I created a PHP script based on Patrick Hunlock's <a href="http://www.hunlock.com/blogs/Supercharged_Javascript">Supercharged Javascript</a> to pull the javascript together automatically, together with a script to create the HTML template (so no AJAX is needed and no <code>flexcal.html</code>).</p>
<p><a href="/inc/package.php/jquery.flexcal-package.js">Download the code</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/11/07/flexcal-package/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A flexcal Example</title>
		<link>http://bililite.nfshost.com/blog/2011/10/30/a-flexcal-example/</link>
		<comments>http://bililite.nfshost.com/blog/2011/10/30/a-flexcal-example/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 11:17:38 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2031</guid>
		<description><![CDATA[I've had some questions about extending flexcal so I created one that combines filtering, output formatting and drop-down menus. The filtering will only allow dates going back 17 years, and the calendar will start on that date. The formatting will use European dates (d/m/y). The drop-down menus will be the ones from the original post, [...]]]></description>
			<content:encoded><![CDATA[<script src="/inc/package.php/jquery.flexcal-package.js"></script>
<p>I've had some questions about extending <a href="http://bililite.nfshost.com/blog/2009/04/03/new-jquery-widget-flexcal/" title="New jQuery Widget: flexcal"><code>flexcal</code></a> so I created one that combines filtering, output formatting and drop-down menus.</p>
<p>The filtering will only allow dates going back 17 years, and the calendar will start on that date. The formatting will use European dates (d/m/y). The drop-down menus will be the ones from the original post, but instead of using aspect-oriented programming (<code class="language-javascript">flexcal('after', '_adjustHTML', function (cal){...</code>) we will subclass the original widget.</p>
<span id="more-2031"></span>
<p>Utility routines to create drop down menus (&lt;select&gt; elements):</p>
<pre><code class="language-javascript demo">function option(d, l10n, cal, isMonth, selected){
  return [
    '&lt;option',
    selected ? ' selected="selected"' : '',
    ' value="', d.toString(), '"&gt;',
    isMonth ? l10n.monthNames[cal.m] : l10n.years(cal.y), 
    '&lt;/option&gt;'
  ].join('');
}
window.monthSelect = function(currentdate, l10n){
  var f = l10n.calendar;
  var currentcal = f(currentdate), ret = [option(currentdate, l10n, currentcal , true, true)], d = currentdate;
  for (var cal = currentcal; d = cal.prev, cal = f(d), cal.y == currentcal.y; ){
    ret.unshift(option(d, l10n, cal, true, false));
  }
  for (cal = currentcal; d = cal.next, cal = f(d), cal.y == currentcal.y; ){
    ret.push(option(d, l10n, cal, true, false));
  }
  return $('&lt;select&gt;').html(ret.join(''));
};
window.yearSelect = function(currentdate, l10n, n){
  var f = l10n.calendar;
  var currentcal = f(currentdate), ret = [option(currentdate, l10n, currentcal , false, true)], d = currentdate;
  for (var i = 0, cal = currentcal; d = cal.prevYear, cal = f(d), i < n; ++i){
    ret.unshift(option(d, l10n, cal, false, false));
  }
  for (var i = 0, cal = currentcal; d = cal.nextYear, cal = f(d), i < n; ++i){
    ret.push(option(d, l10n, cal, false, false));
  }
  return $('&lt;select&gt;').html(ret.join(''));
};</code></pre>
<pre><code class="language-html demo">&lt;input id="fancyflexcalexample"/&gt;</code></pre>
<p>Create the actual calendar:</p>
<pre><code class="language-javascript demo">var startdate = new Date;
startdate.setFullYear(startdate.getFullYear()-17);
$.ui.flexcal.subclass('ui.fancyflexcal', {
  format: function(d){
    // use the utility function from jquery UI
    return $.datepicker.formatDate (this.options.dateFormat,d);
  },
  _adjustHTML: function(cal){
    this._super(cal);
    cal.find('.ui-datepicker-month').html(monthSelect(this.options.current, this.o.l10n));
    cal.find('.ui-datepicker-year').html(yearSelect(this.options.current, this.o.l10n, 5));
    var self = this;
    cal.find('select').bind('change', function(){
      self._setDate(new Date($(this).val()))
    }); 
  },
  options: {
    'class': 'multicalendar', // we'll need the extra room even with only one calendar
    dateFormat: 'dd/mm/yy'
  }
}); 
$('#fancyflexcalexample').fancyflexcal({
    position: 'bl',
    calendars: ['en','he-jewish'],
    filter: function(d) {return d >= startdate}, // filter is an option; set it in the instance
    current: startdate
});</code></pre>
<h2>Some Subtlety</h2>
<p>This works as long as we're only setting the date using the calendar: the output format is what we expect. But we may want to allow the user to type a date into the input box and have it reflected in the calendar. We can watch the input box:</p>
<pre><code class="language-html demo">&lt;input id="fancyflexcalexample2"/&gt;</code></pre>
<pre><code class="language-javascript demo">$('#fancyflexcalexample2').fancyflexcal({
    position: 'bl',
    'class': 'multicalendar',
    calendars: ['en','he-jewish'],
    filter: function(d) {return d >= startdate}, // filter is an option; set it in the instance
    current: startdate
}).keyup(function(){
  $(this).fancyflexcal('option','current',this.value);
});</code></pre>
<p>But this doesn't work right: the input to the calendar simply uses <code class="language-javascript">new Date(this.element.val())</code> internally and according to the <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf">standard</a> (section 15.9.1.15), the Date element accepts ISO format for dates (yy-mm-dd) and
<blockquote>If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.</blockquote> and all the browser I have use the 'm/d/yy' format, not the 'd/m/yy' format we want.</p>
<p>To make this work, we need to override the internal methods for date strings. <code>_createDate(d,oldd)</code> returns a <code>Date</code> object from <code>d</code>; if it is not a valid date, returns <code>oldd</code> (if <code>oldd</code> is falsey then returns <code>new Date</code>). <code>_date2string(d)</code> returns the string representation of the <code>Date d</code> for use <em>internally</em>, as opposed to <code>format(d)</code> which returns the string representation of the <code>Date d</code> for output. The only requirement is that <code>_createDate(_date2string(d))==d</code>; <code>_createDate</code> has to understand the string that <code>_date2string</code> returns.</p>
<p>We can use <code>datepicker</code>'s utility routines as well:</p>
<pre><code class="language-html demo">&lt;input id="fancierflexcalexample"/&gt;</code></pre>
<pre><code class="language-javascript demo">$.ui.fancyflexcal.subclass('ui.fancierflexcal', {
  _createDate: function(d, oldd){
    // $.datepicker.parseDate either throws an error or returns null for invalid arguments
    try{
      return $.datepicker.parseDate (this.options.dateFormat, d) || this._super(d,oldd);
    }catch(e){
      return this._super(d,oldd);
    }
  },
  _date2string: function(d){
    return $.datepicker.formatDate (this.options.dateFormat, d);
  }
});
$('#fancierflexcalexample').fancierflexcal({
    position: 'bl',
    'class': 'multicalendar',
    calendars: ['en','he-jewish'],
    filter: function(d) {return d >= startdate}, // filter is an option; set it in the instance
    current: startdate
}).keyup(function(){
  $(this).fancierflexcal('option','current',this.value);
});</code></pre>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/10/30/a-flexcal-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated flexcal and textpopup, again</title>
		<link>http://bililite.nfshost.com/blog/2011/10/28/updated-flexcal-and-textpopup-again/</link>
		<comments>http://bililite.nfshost.com/blog/2011/10/28/updated-flexcal-and-textpopup-again/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 07:39:20 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=2019</guid>
		<description><![CDATA[In a major burst of middle-of-the-night hacking, I've updated flexcal to better handle changing options after instantiation and added a current option, representing the currently highlighted date. I also updated textpopup with a new option, box that allows you to set the popup's container, useful for inline widgets. The flexcal API examples use it for [...]]]></description>
			<content:encoded><![CDATA[<p>In a major burst of middle-of-the-night hacking, I've updated <a href="/blog/2009/04/03/new-jquery-widget-flexcal/" title="New jQuery Widget: flexcal"><code>flexcal</code></a> to better handle changing options after instantiation and added a <code>current</code> option, representing the currently highlighted date. I also updated <a href="/blog/2009/01/02/new-ui-widgets-textpopup-and-hebrewkeyboard/" title="New UI widgets: textpopup and hebrewKeyboard"><code>textpopup</code></a> with a new option, <code>box</code> that allows you to set the popup's container, useful for inline widgets. The <a href="/blog/2011/10/26/the-flexcal-api-and-an-inline-flexcal/" title="The flexcal API and an inline flexcal"><code>flexcal</code> API examples</a> use it for an inline datepicker.</p>]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/10/28/updated-flexcal-and-textpopup-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The flexcal API and an inline flexcal</title>
		<link>http://bililite.nfshost.com/blog/2011/10/26/the-flexcal-api-and-an-inline-flexcal/</link>
		<comments>http://bililite.nfshost.com/blog/2011/10/26/the-flexcal-api-and-an-inline-flexcal/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 21:08:04 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=1876</guid>
		<description><![CDATA[My flexcal plugin exposes a few useful methods, which I have not documented elsewhere. They are called, like all jQuery UI widget methods, by creating the widget: cal = $('input.date').flexcal() then invoking the method: cal.flexcal('setDate', '10/25/2011'). Getters box Returns the &#60;div&#62; element that contains the calendar. Also useful for forcing the creation of the calendar; [...]]]></description>
			<content:encoded><![CDATA[<script src="/inc/jquery.ui.subclass.js"></script>
<script src="/inc/jquery.textpopup.js"></script>
<script src="/inc/jquery.flexcal.js"></script>
<p>My <a href="/blog/2009/04/03/new-jquery-widget-flexcal/"><code>flexcal</code></a> plugin exposes a few useful methods, which I have not documented elsewhere. They are called, like all jQuery UI widget methods, by creating the widget: <code class="language-javascript">cal = $('input.date').flexcal()</code> then invoking the method:  <code class="language-javascript">cal.flexcal('setDate', '10/25/2011')</code>.</p>
<span id="more-1876"></span>
<h3>Getters</h3>
<div class="prelike"><dl>
<dt><code>box</code></dt>
<dd>Returns the &lt;div&gt; element that contains the calendar. Also useful for forcing the creation of the calendar; it is only created when it is shown (<a href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy instantiation</a>). Therefore, trying to manipulate the calendar before it is shown can cause errors. Use <code class="language-javascript">$('input.date').flexcal().flexcal('box')</code> to force instantiation.</dd>
<dt><code>format</code></dt>
<dd>Takes a <code>Date</code> object and returns the string representation of it; <code class="language-javascript">$('input.date').flexcal('format', new Date)</code> returns <code>'10/25/2011'</code> for the day I wrote this. One the methods that are useful to override; the default function is available as <code>$.ui.flexcal.date2string</code>.</dd>
</dl></div>
<h3>Setters</h3>
<div class="prelike"><dl>
<dt>commit</dt>
<dd>"Commits" the currently highlighted date&mdash;sets the value of the input element to <code>format(getDate())</code>, hides the calendar, and triggers the <code>commit</code> event.</dd>
<dt>hide</dt>
<dd>Hides the calendar.</dd>
<dt>position</dt>
<dd>Move the calendar to the position represented by <code class="language-javascript">flexcal('option', 'position')</code>. Note that <code class="language-javascript">flexcal('option', 'position', 'tl')</code> changes the option value but <em>does not move the calendar</em>. You have to call <code class="language-javascript">flexcal('position')</code> to actually move it. This may be bad design and I may change this in the future.</dd>
<dt>show</dt>
<dd>Shows the calendar.</dd>
</dl></div>
<p>Plus, setting the options with <code>option</code> changes the calendar on the fly (except for <code>url</code>, which is evaluated only at creation; if you need to reset the HTML of the calendar, destroy it and instantiate a new one). Thus, <code class="language-javascript">$('input.date').flexcal('option', 'current', '1/1/2011')</code> sets the highlighted date (displaying the appropriate month).</p>
<h3>An inline <code>flexcal</code></h3>
<p>A quick inline datepicker, subclassed from <code>flexcal</code>, for use with the examples. It requires that the associated &lt;div&gt; be absolutely sized in height, which is not ideal.</p>
<pre><code class="language-javascript demo">$.ui.flexcal.subclass('ui.inlineflexcal', {
  _init: function(){
    this.options.box = this.options.box || this.element;
    this.show();
  },
  options: {
    position: {at: 'bottom', my: 'bottom'},
    speed: 0,
    hideOnOutsideClick: false
  }, 
  commit: function(d){
    this.element.val(this.format(d));
    this._setDate(d);
    this._trigger('commit', 0, d);
  }
});</code></pre>
<pre><code class="language-html demo">&lt;div&gt;&lt;input id=&quot;example1&quot;/&gt;&lt;br/&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#example1').inlineflexcal({box: $('#example1').parent()});</code></pre>

<h3>Examples</h3>
<h4>filter, current</h4>
<pre><code class="language-html demo">&lt;span&gt;Start Date:&lt;/span&gt;
&lt;div id=&quot;date1&quot; style="display: inline-block"&gt;&lt;/div&gt;
&lt;span&gt;End Date:&lt;/span&gt;
&lt;div id=&quot;date2&quot; style="display: inline-block"&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#date1').inlineflexcal({
	commit: function(event, data){
		var startdate = data;
		var enddate = $('#date2').inlineflexcal('option', 'current');
		$('#date2').inlineflexcal('option', 'current', Math.max(startdate, enddate));
	}
});
$('#date2').inlineflexcal({
	filter: function (d){
		return d &gt;= $('#date1').inlineflexcal('option','current');
	}
});
</code></pre>

<h4>box, position</h4>
<pre><code class="language-html demo">&lt;span&gt;Drag the calendar!&lt;/span&gt; &lt;input type=&quot;button&quot; id=&quot;button2&quot; value=&quot;Restore Position&quot;/&gt;
&lt;div id=&quot;example2&quot;&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#example2').inlineflexcal({reposition: false});
$('#example2').inlineflexcal('box').draggable().css('border', '10px inset purple');
$('#button2').click(function(){
  $('#example2').inlineflexcal('position'); // restore the correct position
});</code></pre>

<h4>Show/Hide</h4>
<pre><code class="language-html demo">&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio3&quot;/&gt; Hide&lt;/label&gt;
&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio3&quot; checked=&quot;checked&quot;/&gt; Show&lt;/label&gt;
&lt;div id=&quot;example3&quot;&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#example3').inlineflexcal();
$('[name=radio3]').first().change(function() {
  if ($(this).is(':checked')) $('#example3').inlineflexcal('hide');
});
$('[name=radio3]').last().change(function() {
  if ($(this).is(':checked')) $('#example3').inlineflexcal('show');
});</code></pre>

<h4>l10n</h4>
<pre><code class="language-html demo">&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio4&quot; checked=&quot;checked&quot;/&gt; Decimal&lt;/label&gt;
&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio4&quot;/&gt; Hex&lt;/label&gt;
&lt;div id=&quot;example4&quot;&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#example4').inlineflexcal();
$('[name=radio4]').first().change(function() {
  if ($(this).is(':checked')) $('#example4').inlineflexcal('option', 'l10n', 'en');
});
$('[name=radio4]').last().change(function() {
  if ($(this).is(':checked')) $('#example4').inlineflexcal('option', 'l10n', {
	dayNamesMin: ['s','m','t','w', 't', 'f','s'],
	dates: function(n){
		return n.toString(16);
	},
	years: function(n){
		return n.toString(16);
	}
  });
});</code></pre>

<h4>tab, hidetabs</h4>
<pre><code class="language-html demo">&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;check5&quot;/&gt; Hide Tabs&lt;/label&gt;&lt;br/&gt;
&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio5&quot; checked=&quot;checked&quot;/&gt; English&lt;/label&gt;
&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio5&quot;/&gt; Jewish&lt;/label&gt;
&lt;label&gt;&lt;input type=&quot;radio&quot; name=&quot;radio5&quot;/&gt; &amp;#1506;&amp;#1489;&amp;#1512;&amp;#1497;&amp;#1514;&lt;/label&gt;
&lt;div id=&quot;example5&quot;&gt;&lt;/div&gt;</code></pre>
<pre><code class="language-javascript demo">$('#example5').inlineflexcal({
  calendars: ['en', 'jewish', 'he-jewish'],
  'class': 'multicalendar',
  'set': function() {
    $('[name=radio5]').eq($('#example5').inlineflexcal('option', 'tab')).prop(&quot;checked&quot;,true);
  }
});
$('[name=check5]').change(function(){
	$('#example5').inlineflexcal('option', 'hidetabs', $(this).prop('checked'));
});
$('[name=radio5]').change(function() {
  $('#example5').inlineflexcal('option', 'tab', $('[name=radio5]').index(this));
});</code></pre>

]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/10/26/the-flexcal-api-and-an-inline-flexcal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated flexcal</title>
		<link>http://bililite.nfshost.com/blog/2011/10/24/updated-flexcal-2/</link>
		<comments>http://bililite.nfshost.com/blog/2011/10/24/updated-flexcal-2/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 06:28:58 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=1872</guid>
		<description><![CDATA[For those following flexcal, my jQuery UI date picker, I've just released version 1.3. It fixes a bug in the setDate routine that would cause it to fail if called before the calendar was shown, and added date filtering. See the original post (now updated) for details.]]></description>
			<content:encoded><![CDATA[For those following <a href="/blog/2009/04/03/new-jquery-widget-flexcal/">flexcal</a>, my jQuery UI date picker, I've just released version 1.3. It fixes a bug in the <code>setDate</code> routine that would cause it to fail if called before the calendar was shown, and added date filtering. See the <a href="/blog/2009/04/03/new-jquery-widget-flexcal/">original post</a> (now updated) for details.]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/10/24/updated-flexcal-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated flexcal</title>
		<link>http://bililite.nfshost.com/blog/2011/08/07/updated-flexcal/</link>
		<comments>http://bililite.nfshost.com/blog/2011/08/07/updated-flexcal/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 23:05:52 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Judaism]]></category>

		<guid isPermaLink="false">http://bililite.nfshost.com/blog/?p=1854</guid>
		<description><![CDATA[For those following this, I corrected some typos (???? spelled wrong; numbers should not use the ????? form) in the Hebrew calendar. flexcal now stands at version 1.2]]></description>
			<content:encoded><![CDATA[For those following this, I corrected some typos (???? spelled wrong; numbers should not use the ????? form) in the Hebrew calendar. <a href="/inc/jquery.flexcal.js"><code>flexcal</code></a> now stands at version 1.2]]></content:encoded>
			<wfw:commentRss>http://bililite.nfshost.com/blog/2011/08/07/updated-flexcal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

