tabs: add functionality to operate with href

tabs: add functionality to operate with href

The tabs plugin is provided with the option to operate with a numerical index to identify the tabs.

This numerical index identifies which tab is going to be subject to an array of methods: enable, disable, elect, and so on.

Developing a web application, I noticed that this system was not fit for the specific needs: I needed to define runtime-generated IDs for the tabs, which would be dynamically generated, and could be in any order. Also, deleting a tab in the middle of the group would reindex all tabs after it.

Each tab has an <a> link, which href points to a <div> with the id property equal to the <a>'s href. Knowing that according to the spec each id must be unique, a properly formed tabs widget will also have unique hrefs.

This means that I can safely look for the href, and from that infer the tab index inside the tabs widget, to operate with random-generated tabs in a random order, and which said order can change during runtime.

Even if the tabs user does not have all these requirements, he/she may wish to operate using tab hrefs as a coding style option.

Instead of splattering some copy-paste code all over the functions which could benefit from this behaviour, a helper function can achieve the same result and be reused on all concerned functions, needing only a one-liner on each function which can benefit from this.


helper function is called _getIndex, and does all the magic, always returning a typeof number. If there is an attempt to operate on a nonexistent href, it returns NaN.
functions altered to use it: enable, disable, select, remove and load.