jdeerhake's posterous http://blog.jdeerhake.com Most recent posts at jdeerhake's posterous posterous.com Thu, 27 Jan 2011 23:11:00 -0800 cachedAjax (jQuery plugin) http://blog.jdeerhake.com/cachedajax-jquery-plugin http://blog.jdeerhake.com/cachedajax-jquery-plugin

v0.0.1
 01/27/2011  

About

A jQuery plugin to set up memoized Ajax calls to improve performance when fetching static resources via Ajax.  

Call the function via `jQuery.cachedAjax` and supply it with a configuration object that you would normally use with `jQuery.ajax` (save for the data).  It then returns a function that you call with a data object every time you wish to make a request.  

 

Download

jquery.cachedAjax.js (v0.0.1)

GitHub Repository

jQuery project page

 

Usage

var search = jQuery.cachedAjax({
      url : '/search',
      type : 'get',
      success : function(data) {
        console.log(data);
      }
    });

When you call `search({ q : "test" })` an Ajax request is made.  If it is successful, the result is stored in an array and your success callback is triggered with the data (with only the data).

A repeated call of `search({ q : "test" })` will simply call the success callback with the data stored in the array, no Ajax call is needed.  

To clear the cache, simply call `search.clearCache()`  

 

Issues

If you find any issues, please contact me.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/897536/4795_879805525635_12415795_49069848_2934413_n.jpg http://posterous.com/users/1kQPGOjeqwXD John Deerhake jdeerhake John Deerhake
Thu, 27 Jan 2011 21:16:00 -0800 inputHintOverlay (jQuery plugin) http://blog.jdeerhake.com/inputhintoverlay-jquery-plugin http://blog.jdeerhake.com/inputhintoverlay-jquery-plugin

Last update: 9/21/2010

About

A jQuery plugin that overlays input labels as hints to a form. It uses the title tags on each input/textarea as the label values/hints. It is called it on the form (or any parent).

$(form).inputHintOverlay()

Why use title tags? This makes it play nice with pre-filling forms from cookies (if a value is specified, the hint goes away).

Why use overlay instead of setting the value? This allows validation to work correctly and prevents the user from accidently submiting erroneous data.

Arguments to this method are adjustments to top and left of the fixed position of each overlay div. The folling would push each hint down 2px and right 5px.

$(form).inputHintOverlay(2, 5)

The class .inputHintOverlay can be used to style the hints.

 

Known Issues

  • Fails when multiple items have the same title
    • Fix coming soon
  • Incorrectly positions the overlays when the input elements are floated
    • Not-so-elegant fix: Rather than floating the inputs, wrap each in its own floated block-level element. This will fix the problem.
    • I think this problem stems from how jQuery gets the position of floated elements. I'm not sure how to fix it just yet.
  • Label fails to clear itself when you click directly on it
    • You can fix it this by added a click function to each label that hides it and triggers focus on the input box.
    • This will be fixed in the next release
  • Different positioning in Chrome
    • I've noticed that the labels sometimes have slightly different position in Chrome. Usually small, acceptable differences but I'm not sure what causes them
  • Find another bug? Please email me and let me know. Same goes for feature requests

Compatibility

  • This is known to work with jQuery 1.4.x
  • It should work just fine with earlier versions, but YMMV
  • Creates fully valid XHMTL 1.0 Strict
  • This also plays nicely with the jqTransform plugin and the jQuery Validation plugin (although you have to disable the Validation feature that uses input title attributes as an error message override)

Code

Just create a form and call the inputHintOverlay method on it. The title tag of each input will be used as the hint. Hints can be stylized using the div.inputHintOverlay class

<script type="text/javascript">
    $(document).ready(function() {
        $("form#test").inputHintOverlay(5, 6);
    });
</script>

<style type="text/css">
    .inputHintOverlay { color: #999; font-size: 12px; }
</style>

<form id="test" action="submitPage.php">
    <fieldset>
        <input type="text" id="name" title="Full Name" />
        <input type="text" id="email" title="E-Mail" />
        <textarea id="comment" title="Comment" cols="10" rows="5"></textarea>
        <input type="button" value="Submit" />
    </fieldset>
</form>

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/897536/4795_879805525635_12415795_49069848_2934413_n.jpg http://posterous.com/users/1kQPGOjeqwXD John Deerhake jdeerhake John Deerhake
Thu, 27 Jan 2011 21:14:00 -0800 bgFader (jQuery plugin) http://blog.jdeerhake.com/bgfader-jquery-plugin http://blog.jdeerhake.com/bgfader-jquery-plugin

v0.2.0

Last update: 9/27/2010

About

A jQuery plugin that allows a background to fade in or out independently

of its content.

 

 

Usage

$(myDiv).bgFader({
    'type' : 'out',  //in, out, cross
    'duration' : 300, //animation duraction - accepts jQuery defined strings (eg slow, fast) or ms
    'newBg' : '', //new aruments for CSS 'background:' short hand declaration
    'easing' : 'linear', //linear or swing (unless you have the jQuery easing plugin installed)
    'fadeTo' : '0', //Opacity level at end of animation
    'callback' : '' //Callback function when animation has completed
})

The example values provided are also the defaults (with the exception that fadeTo defaults to 1 for a fade in)

Known Issues

  • There are surely a lot of issues.
  • Curently only tested in Firefox 3 and IE8.
  • Find a bug? Please email me and let me know. Same goes for feature requests

Compatibility

  • This is known to work with jQuery 1.4.x
  • It should work just fine with earlier versions, but YMMV

Example

Coming soon.

Code

Coming soon.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/897536/4795_879805525635_12415795_49069848_2934413_n.jpg http://posterous.com/users/1kQPGOjeqwXD John Deerhake jdeerhake John Deerhake