Hey all,
I've just discovered Jquery this last weekend and I am now converting all of
my in-house Javascript to use it. I played with most of the others but
didn't really like any of them; then I found Jquery and was instantly hooked
- the website is right, it does make javascript fun.
Anyway, I've started digging into some of the plugins and got around to
making my own. I do a lot of form validation (are certain fields provided,
etc.). I need to regularly check textbox/textarea fields for data so I did
the following plugin:
$.fn.isEmpty = function() {
var isempty = true;
this.each(
function() {
if (this.value.length != 0) {
isempty = false;
}
}
);
return isempty;
}
Any thoughts on ways I could improve this?
And not really a plugin but some simple Javascript that uses jquery to
generate a message on screen that fades away on its own (it gets its
stylings from CSS). Feel free to use it and/or suggest improvements:
var Msg = {
FadeIn : 750,
FadeOut : 1500,
FadeDelay : 2200,
// Show a formatted box on the screen - arguments:
// lft : Left position (optional - if not
provided, uses CSS default)
// tp : Top position (optional - if not
provided, uses CSS default)
// fin : Fade In Speed (optional - if not
provided, use default)
// fout : Fade Out Speed (optional - if not provided,
use default)
// delay : How long to delay between fade in and
starting fade out
(optional - if not provided, use default)
Show : function(msg, tp, lft, fin, fout, delay)
{
// Create the div tag we're going to display
$('body').append("<div class='message'>" + msg + "</div>");
// Get the necessary tag
var jq = $('div.message');
// Clicking anywhere within the message will cause it to close
before fade
out effect finishes
jq.click(function() { $(this).unclick().remove() });
// Set some defaults if they haven't been passed in
delay = delay || Msg.FadeDelay;
fout = fout || Msg.FadeOut;
fin = fin || Msg.FadeIn;
// Use the defaults from CSS
lft = lft || jq.css("left");
tp = tp || jq.css("top");
// If no message provided, use a default one
msg = msg || "Message not provided.";
// Now display it
jq.css({ left : lft, top: tp }).fadeIn(fin, function() {
setTimeout("$('div.message').fadeOut(" + fout + ",
function() {
$(this).unclick().remove();} );", delay); });
}
};
--
View this message in context:
http://www.nabble.com/Tiny-plugin-example%2C-message-box-tf2955841.html#a8268666
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/