Just as the auther of jquery tools said:
Jquery UI has a so-called "uniied API" which uses the following syntax
For invoking methods:
// Call select method for tabs $ ("Ul. Example"). tabs ("select", 1 );
API methods are called by supplying the method name as a string followed by method arguments. To be honest, I think that this kind API design is fundamentally wrong. It has the following problems:
- The syntax is unique to jquery UI and people outside the UI community are not accustomed to it
- The syntax is cubersome. for example, if you want to perform method chaining you have to write the following: $ ("ul. example "). tabs ("select", 1 ). tabs ("disable", 2 );
- The JavaScript engine cannot see typos. Writing "selecct" does not look
Like an error to a browser, making it harder to debug.
I dislike the jquery UI's unified API either. There is another article supporting jquery UI's unified API:
With jquery UI, all the Plugins work with jquery and it's philosophy. Working
John resig's supervision and incite. Working together. Returning a seperate API
Has some potential, but not the way it is implimented here.
In my opinion, a component is a collection of nodes, properties, events and methods,
Which shoshould be presented in his own instance not the DOM node in jquery.
I love jquery, but I think the components based on jquery shoshould be more like extjs,
Qooxdoo.
Maybe it's time for me to learn how to write a jquery plugin, and convert it
The Way Used in jquery tools.
A simple jquery tabs plugin
HTML markup is the same as jquery UI tabs.
<Div class = "tabs"> <ul> <li> <a href = "javascript :; "> Tab 1 </a> </LI> <li> <a href =" javascript :; "> Tab 2 </a> </LI> <li> <a href =" javascript :; "> tab 3 </a> </LI> </ul> <div> pane 1 content </div> <div> pane 2 content </div> <div> pane 3 content </div>
Let's write some basic CSS rules:
. Tabs ul {list-style-type: none; padding: 0px; margin: 0px ;}. tabs Li {display: inline ;}. tabs Li a {text-Decoration: none ;}. tabs. current {background-color: # CCC ;}
And the jquery plugin code:
(Function ($) {$. FN. tabs = function () {var tabs = This. children ("Ul "). find ("LI> A"); var panes = This. children ("Div"); var current = 0; function clicktab (INDEX) {current = index; tabs. removeclass ("current "). eq (current ). addclass ("current"); panes. hide (). eq (current ). show () ;}clicktab (0); tabs. click (function () {clicktab (tabs. index (this) ;}); return this ;}) (jquery );
The invoke code:
$ (Function () {$ ("Div. Tabs"). tabs ();});