Step by step to create a jQuery tabs plugin - 1
2009-06-17 13:31
411 查看
Just as the auther of jQuery Tools said:
jQuery UI has a so-called “unified API” which uses the following syntax
for invoking methods:
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 with
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 should be presented in his own instance not the DOM node in jQuery.
I love jQuery, but i think the components based on jQuery should be more like extjs,
qooxdoo.
Maybe it’s time for me to learn how to write a jQuery plugin, and convert it to
the way used in jQuery Tools.
A simple jQuery tabs plugin
Html markup is the same as jQuery UI Tabs.
Let’s write some basic CSS rules:
And the jQuery plugin code:
The invoke code:
jQuery UI has a so-called “unified 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 with
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 should be presented in his own instance not the DOM node in jQuery.
I love jQuery, but i think the components based on jQuery should be more like extjs,
qooxdoo.
Maybe it’s time for me to learn how to write a jQuery plugin, and convert it to
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> </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 a.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(); });
相关文章推荐
- Step by step to create a jQuery tabs plugin - 1
- Step by step to create a jQuery tabs plugin - 2
- Step by step to create a jQuery tabs plugin - 2
- Step by step to create a jQuery tabs plugin - 3
- Step by step to create a jQuery tabs plugin - 3
- Step By Step Guide To Create Physical Standby Database Using RMAN Backup and Restore (Doc ID 469493.
- how to create and submit kernel patch through git step by step
- Step By Step Guide To Create Physical Standby Database Using RMAN Backup and Restore
- SharePoint 2013 Step by Step——How to Create a Lookup Column to Another Site(Cross Site)
- 怎么创建一个基本的jQuery插件 - How to Create a Basic Plugin
- Step-By-Step Guide To Create Physical Standby On Normal File System For ASM Primary using RMAN (文档 I
- Step by Step to Create your First SSIS Package -摘自网络
- jtable——A JQuery plugin to create AJAX based CRUD tables
- A Step-by-Step guide to create a simple FPM application using Feeder Class for FORM GUIBB
- mvn- step by step 2- how to create mutil moudle
- How to create a PDF viewer by step
- Step-By-Step Guide To Create Physical Standby On Normal File System For ASM Primary using RMAN
- Step by step to create/modify ramdisk.img
- Oracle 11g Active Data Guard step by step: How to create a Physical Standby Database using RMAN
- Step by Step - How to create a c++ library with NDK on Android Studio 1.5 (not experimental way)