MooTabs with Ajax

MooTabs with Ajax

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
389 views

MooTabs is a tiny(3kb) class for MooTools. As the name suggests, it’s main purpose is to help out with the creation of simple tab navigation.
As of version 1.2, you can also set tab content via an Ajax request. See the documentation below for more info!

Dependencies

MooTabs 1.2 will only work with MooTools 1.1.
Click here to get a list of the dependencies! Also, it is recommended to grab Window.DomReady, to declare the mootabs object after the DOM is ready obviously.
See the demo link below.
As you can see, the look of MooTabs is very easy to modify. Just start from the basic CSS file, or from one of the example style (You can download the CSS file used in each examples) and go from there to create your very unique MooTabs that suites your needs!

The big change in version 1.2 is the new Ajax Tabs option! You can now retrive tab content via Ajax. Check out the documentation below to learn more about it!
Also, there are 2 new methods, mootabs.getNext() and mootabs.getPrevious(), again, check out the docs below! Although it’s pretty self-explanatory!

Some differences to note in the parameters:
-”height” and “width” options has been changed from Integer to String so you can use width like “300px” or “50%” depending on what you need.
-new option: “duration”, an integer that consists of the duration of the animation on tab switch.
-new option: “activateOnLoad”, a string, can be set to ‘first’, ‘none’ or any tab’s title, this is the tab that will be activated on first load.
-new parameter to the “mootabs.activate()” method, called “skipAnim”. It’s an optional parameter and the default is set to false. As you might have guessed, if set to true, there will be no animation on tab switching.

Documentation
What to include

MooTabs is very easy to use, all you have to do is to include MooTools 1.1 as you usually do, next, include mootabs1.2.js and finally, load the CSS file you want to use.

For Example:

<link rel="stylesheet" href="mootabs1.2.css" type="text/css" media="screen" title="no title" charset="utf-8" />

      <script src="mootools.v1.1.js" type="text/javascript" charset="utf-8"></script>

      <script src="mootabs1.2.js" type="text/javascript" charset="utf-8"></script>

he HTML part

Now comes the html markup. Again, it’s pretty straight forward. The tabs consist of:
1) A main DIV (ID can be anything, but remember it!)
2) An unordered list (Class has to be set to “mootabs_title”)
3) A set of DIV that will become the Tab Panels (Class has to be set to “mootabs_panel”)

Here’s a concrete example, I will go into details about each part after.

  <div id="myTabs">

      <ul>

      <li title="Tab1">Tab 1 Label</li>

      <li title="Tab2">Tab 2 Label</li>

      <li title="Tab3">Tab 3 Label</li>

     </ul>

      <div id="Tab1">

      Tab 1 Content

      </div>

      <div id="Tab2">

      Tab 2 Content

      </div>

      <div id="Tab3">

      Tab 3 Content

      </div>

      </div>

1) The main DIV is the container of the whole tab interface, nothing really fancy here, as long as you remember the ID you gave it. (Line 1 in the example)

2) The unordered list consist of the Tabs themselves (i.e. NOT the panels, but the clickable tabs). To associate a Tab with it’s Panel, you have to define the “title” attribute of the list item (

  • ). The title of the
  • element needs to be the same as the ID of the panel linked to it. The label of the Tab is the innerHTML content of the list item. (Lines 2 to 6 in the example)

    3) The set of divs consists of your tab panels. The class has to be set to “mootabs_panel” and the ID of the panel has to be the same as the list item (

  • )’s title. (Lines 7 to 15 in the example)

    The Javascript Part

    This is probably the easiest part. All you have to do here is to declare a new “mootabs” object with the parameters that you want (I will give a list don’t worry). Make sure you declare the object AFTER the DOM is ready, so eighter in the Body after your main DIV container, or, what I would strongly suggest, inside the , using the domread events of MooTools.

    The following example demonstrate it:

          <script type="text/javascript" charset="utf-8">
    
          window.addEvent('domready', init);
    
          function init() {
    
          myTabs1 = new mootabs('id_of_container', {options});
    
          }
    
          </script>
    

    Place the previous code in the of your document, after the include part.
    A full list of possible options/parameters will be given below.
    The Style(CSS) part

    This might be the trickiest part. Customizing the look of the tabs require a certain knowledge of CSS and I will not go into depth on that subject as the purpose of this page is not to give a full-blown CSS lesson. What I would suggest though is to look at the 3 examples of tabs on this page (see the Demo In Action section), they each use a different CSS file that you can download and they should be a good starting point.

    Some important classes to keep in mind:
    -mootabs_title: the base class for the unordered list, not much to do here
    -mootabs_title li: the class for the li elements of the unordered list, this one is fun to mess with…
    -mootabs_title li.active: the class for the currently active tab, again, have fun with this one…
    -mootabs_panel: the class for the panel divs, note that you have to leave “display:none” there since the tabs are hidden by default!
    -mootabs_panel.active: the class for the active panel div, again leave the “display:block” here so the panel shows up when it’s activated! Feel free to mess with the colors, font etc..

    In most cases, you can play with the fonts and colors without any consequences, but if you start messing with the position, display, height, etc.. I can’t guarantee that the result will look good (or that it will work at all!). This is why I would suggest you to read up a bit on CSS if you are new to it, before you start styling the tabs.
    A quick word on Ajax

    If you wish to use Ajax to retrive tab’s content, you have to keep the following in mind; what the script will do is to make an ajax request (via GET) to the url you specified in the options, with the GET parameter “tab” containing the tab’s title.
    For example, if your tab is titled “Tab2″, the script will send a GET request with the following parameter “?tab=Tab2″
    So in your server-side script/controller, all you have to do is to catch the value of the GET parameter named “tab”, you can then supply the requested content.
    I really don’t want to insist to much on the method to proceed here since everyone works differently (and of course it also depends if your server-side script is in PHP, ASP or anything else…) but I suggest you take a look at the Ajax Example above and look at it’s source to get a better grasp at the concept.

    Demo: http://www.silverscripting.com/mootabs/basicAjax.html

    Download:http://www.silverscripting.com/mootabs/mootabs1.2.rar

    Source: http://www.silverscripting.com/mootabs/

  • http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/stumbleupon_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/delicious_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/blinklist_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/furl_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/technorati_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/magnolia_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/google_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/myspace_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/facebook_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/sphinn_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/mixx_32.png http://www.ajaxupdates.com/wp-content/plugins/sociofluid/images/twitter_32.png

    Related Listings:

    1. Sliding Tabs using Moo Tools Plugin The script relies on width and height of tabs and...
    2. Tabs with Moo tools plugin This is MooTabs! Using a slightly modified CSS file and...
    3. Ajax Based Tab Script When user clicks a tab the Ajax will communicate with...
    4. Sliding Tabs using Mootools Sliding Tabs is a mootools 1.11 plugin which adds a...
    5. MOOdalBox – A modal box (inline popup) MOOdalBox: A modal box (inline popup), used to display remote...

    Do you like this post?

    Email:     

    Tags: , , , , , , , , , , , , , , , , ,

    No Comments »

    No comments yet.

    RSS feed for comments on this post. TrackBack URL

    Leave a comment



    Web Design & CSS (Templates) - TOP.ORG