Skip to content

Commit

Permalink
Created new plugin to automatically generate tipsy based tooltips for…
Browse files Browse the repository at this point in the history
… our forms.
  • Loading branch information
baphled committed Jun 17, 2010
1 parent 196438f commit 15384f7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions public/javascripts/jquery.formtastic.tooltips.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function($) {
/**
* A simplistic plugin for generating tipsy based tooltips for forms
*
* This plugin relies on formatastic's markup structure to generate the tooltips from the inline-hints elements
*
* @useage $('fieldset.inputs > ol li').generateFormatasticTooltips()
*
* @author Yomi Colledge
**/
$.fn.generateFormatasticTooltips = function(options) {
var opts = $.extend({}, $.fn.animateIconPanel.defaults, options);

return $(this).each(function() {
var $inputWrapper = $(this).find(opts.hintElement),
hint = $inputWrapper.html();

if (null != hint) {
$inputWrapper.hide();
$input = $('>input, >textarea', this);
$input.tipsy({trigger: 'focus', gravity: 'w', fallback: hint});
}
});

// private function for debugging
function debug($obj) {
if (window.console && window.console.log) {
window.console.log($obj);
}
}
};

// default options
$.fn.generateFormatasticTooltips.defaults = {
hintElement:'p.inline-hints'
};

})(jQuery);

0 comments on commit 15384f7

Please sign in to comment.