[jQuery] Writing a plugin

2008-11-21 Thread halcyonandon

Hi,

I'm new to JQuery, but I need to convert some regular, working,
javascript code into a JQuery plugin.  I'll need to expand on this
code once its in plugin form, but for now its just converting this
existing code into a working JQuery plugin.  I've reviewed the
documentation on plugin authoring, but it doesnt give a lot of
examples.

I was hoping someone could show me how a snippet of my code would look
as a JQuery plugin to put me on the right track.

function initTabs() {
if (document.getElementById && document.createTextNode) {
var n = document.getElementById('tbs');
var as = n.getElementsByTagName("a");
for (var i = 0; i < as.length; i++) {
as[i].onclick = function() {
showTab(this);
return false;
};
as[i].onfocus = function() {
this.blur();
};
if (i == 0)
currentLink = as[i];
}
if (document.getElementById(currentTab)) {
document.getElementById(currentTab).style.display =
'block';
}
}
}

Thank you for your time.


[jQuery] Writing a plugin - tips needed

2007-10-16 Thread sgrover

I'm working on a jQuery plugin, which is primarily a series of utility 
functions.  I need to worry about namespace problems, so I have opted 
for the option to add an object to the base jQuery object.

i.e.

jQuery.myObj = { . . .  };

What I'm not clear on is if this is the best approach.  Thus far 
everything is working fine, but that jQuery.fn.myObj approach and the 
jQuery.fn.extend() method are a little over my head (so far).  Are these 
better approaches to be using?

The methods I'm creating return various values - ints, dates, etc.  So I 
don't think the jQuery.fn.myObj approach would work here - it would 
break chaining.

So, I'm looking for any guidance you may be able to offer.  I'm the type 
that will plow through this anyways and make a choice where need be, but 
a second opinion is ALWAYS appreciated.. Just in case I'm doing things 
wrong... :)  Thanks in advance.

Shawn