Ajax and Ajax Frameworks

I have been a developer for nearly 20 years and a web developer for about 10 years. Over the years, I have considered creating a blog to share the things I have learned (and am learning) about web design and development, but I never seemed to have the time. When I began learning about web development using Ajax and Ajax Frameworks, I decided to take the time to create this blog.

My intention for this blog is to focus primarily on Ajax Frameworks, but since web development requires knowledge of many technologies, I will occasionally write about things such as CSS, Javascript, PHP, MySQL, Flash, etc.

Lately, I have been using JQuery as my primary Ajax tool. Although I have used other Ajax Frameworks in the past (Dojo Toolkit, Yahoo! User Interface Library, Scriptaculous/Prototype), JQuery has thus far been the easiest to learn. In my first few posts I will discuss some of the JQuery Plugins that I have created. Some of these include: a plugin for Google Maps (jquery.imGoogleMaps), Form validation and submission  (jquery.imValidateForm), Page Populater (jquery.imPagePopulate), and a plugin to create lists (jquery.imList).

While I am still learning about some of the other Ajax Frameworks, I hope that what I have learned will be helpful to others. Just remember, “When you can pull the pebbles from my hand…”

Share

JQuery Plugin: imAnimTabber

Thursday, March 12th, 2009

I decided to redesign my company site (intriguingminds.com). I hadn’t touched it in about 3-4 years, so it was long overdue. With its simplistic design, I decided to use the imUpSideDownTabber JQuery plugin that I had created a few months ago. I soon learned that, due to my design, the plugin was not robust enough for the functionality that was necessary, so I decided to create an upgrade. The new functionality was significant enough (it does more than just up-side-down-tabbing) that I decided to rename the plugin altogether (imAnimTabber). I never did like the name ‘imUpSideDownTabber’. The imAnimTabber plugin can be used to display content with the following animated options:

slide (imUpsideDownTabber)
height
width
fade
carousel

As with the imUpSideDownTabber, the tabs can be created dynamically (‘auto’ mode), but I added a ‘manual’ mode so that the plugin can function when the tabbing interface is already created (the ‘carousel’ option can only be used in ‘manual’ mode). One of the major changes in this JQuery plugin is that the tabs can be individually styled. I needed this functionality for my IntriguingMinds.com (link) site. Unlike the imUpSideDownTabber, I created a demo page so that you can see how to set it up.

First, download the plugin (the plugin can be downloaded from Google Code or JQuery Plugins).

Using the imAnimTabber

?View Code JAVASCRIPT
$(document).ready(function(){
      $("#body").imAnimTabber({
            mode:'manual',
            tabs: [{"content_id": "about", "class_name": "about", "active_tab_class": "about_sel"},
             {"content_id": "design", "class_name": "design", "active_tab_class": "design_sel"},
             {"content_id": "socialize", "class_name": "socialize", "active_tab_class": "socialize_sel"},
             {"content_id": "marketing", "class_name": "marketing", "active_tab_class": "marketing_sel"},
             {"content_id": "commerce", "class_name": "commerce", "active_tab_class": "commerce_sel"} ]
       });
});

Options (Note: in the example above, “#body” is the parent container for the entire interface).

  1. mode: The options for mode are ‘manual’ or ‘auto’. The default is ‘auto’. Use ‘auto’ mode if you want the imAnimTabber plugin to create the tabs for you.  Remember if you plan to use the ‘carousel’ option, the plugin must be set for manual mode.
  2. tab_container: As the name suggests, this container holds the tabs. This option mandatory in ‘auto’ mode or when using the ‘carousel’ option. It is not needed if the tabs are individually styled (more on this later).  Make sure that you have styles this container as well as the ‘a’ tag within the container.
  3. #tab_cntnr {
         width:600px;
         float:left;
         background-color:#727272;
    }
     
    #tab_cntnr a {
         display:block;
         text-decoration:none;
         float:right;
         width:75px;
         height:26px;
         color:#fff;
         background: url(images/menu_tab.jpg) no-repeat;
         text-align:center;
         font: bold 10px Helvetica, Arial, sans-serif;
         margin-right:5px;
         padding-top:3px;
    }
  4. active_tab_class: The option is the class of a selected tab. Use this option if all of the tabs will use the same class when selected. This option can’t be used with the ‘carousel’ option. If I set the active_tab_class to ‘selected’, I can style the ‘a’ tag accordingly:
  5. #tab_cntnr a.selected {
         color:#2d2d2d;
         background: url(images/menu_tab_over.jpg) no-repeat;
    }
  6. attribute: Use this option to specify how you want the content to appear when the relevant tab is clicked. The options are slide, height, width, or fade. The default attribute is slide. The slide attribute should be used if you want to use the up-side-down tabbing functionality. Note: the ‘carousel’ option is set differently (more on this later). Also, if the width or fade options are used, make sure to set which content is to be initially displayed by setting “selected”: true.
  7. ?View Code JAVASCRIPT
    {"content_id": "about", "class_name": "about", "active_tab_class": "about_sel", "selected": true}
  8. speed: Use this option to control the speed of the animation. ‘slow’ is the default, but you can use any value that is accepted by JQuery’s animation object (slow, normal, fast, 2500, etc).
  9. queue: Use this option to control the order in which the animation occurs. The options are true (the default) or false. When set to true, the next selected content will not display until the previous content has finished animating. When set to false, the ‘on’ and ‘off’ animation will occur at the same time. This option is not needed when using the ‘carousel’ option.
  10. tabs: This option is the most significant change from the imUpSideDownTabber plugin in that it as more options. Use this option to link the tabs with the content. This option is not used with the ‘carousel’ option. Options:
    • caption: Used only in ‘auto’ mode. It is the text that is displayed on the tab.
    • content_id: The id of the content div that will be displayed when the tab is clicked.
    • class_name: Use this option to style the tabs individually. When using this option, the ‘tab_container’ option is not needed. On my intriguingminds.com site, I created 5 buttons using different colors, so each has a separate class.
    • active_tab_class: Again, use this option to style the ‘selected’ tabs individually. This option will override the master active_tab_class option described above. The plugin first checks to see if this option exists. If it does not exist, then the plugin will use the master active_tab_class option. (one or the other must exist).
  11. carousel: Use this option to create a carousel effect. I needed this option for my Intriguingminds.com (link) site. While there are other JQuery Carousel plugins, adding this option to the imAnimTabber plugin wasn’t difficult because much of the functionality was the same. Note: When using the carousel option, the tabs can’t be styled individually, so be sure to use the master active_tab_class if you want the tab to look differently when selected. To setup the carousel effect, you need the following options:
    • slide_container: This is the container that holds all of the ‘slides’ (and does the actual sliding). Note: When styling the ‘slides’, make sure to use float: “left” for each slide.
    • slide_parent: This is the container for the slide_container. The slide_container will move inside the slide parent (the individual slides don’t move, that is why each slide must be styled with float: “left”). It is important when styling the slide_parent to set the overflow = hidden.

    • num_slides: The number of total slides.

Examples

Example 1

This example could be used for an UpSideDownTabber. The ‘slide’ option is set by default and the mode is set to ‘auto’ by default. I changed the ‘queue’ option to false so that animation will occur simultaneously.

?View Code JAVASCRIPT
$("#slider").imAnimTabber({
     tab_container: 'tab_cntnr',
     active_tab_class: 'selected',
     //don't need set attribute option - 'slide is the default
     //attribute: 'slide',
     tabs: [{"caption": "Recent", "content_id": "Recent"},
           {"caption": "Links", "content_id": "Links"},
           {"caption": "About", "content_id": "about"} ],
          queue: false
});

Example 2
This is an example of using the imAnimTabber to create a carousel effect.

?View Code JAVASCRIPT
$("#portfolio").imAnimTabber({
     mode:'manual',
     active_tab_class: "selected",
     //tab_container must be used with carousel option
     tab_container: 'design_menu',
     //carousel only works in manual mode. Also, can't style tabs individually
     carousel: {"slide_container": "detailContainer", "slide_parent": "portfolio", "num_slides": 4}
});

To view demos of this plugin, click here. You can download the plugin from Google Code. The demo will also show you how to setup the styles for the plugin. You’ll notice in the demo style sheet that I added:

:focus { -moz-outline-style: none; }

This style will remove the selection border from around your tabs for mozilla-based browsers. For more information, see this post. I hope you enjoy. Contact me if you have any further questions.

Share

14 Responses to “JQuery Plugin: imAnimTabber”

  • KM Says:

    great plugin!
    on the demos, the tab content closes completely before a new tab opens, but on the one on this page the tab content changes dimensions without closing the content first. i can’t seem to figure out how to do this…

    also, is there a way to have the selected: true value work for the slide mode as well as fade?

    thanks…
    great stuff

  • admin Says:

    The example in the post has the queue option set to ‘false’ (the default is true). When queue is set to true, the first animation will complete before the second animation begins.
    With regards to the ‘selected: true’, I’m not sure what you are referring to. Please explain. Thanks.

  • KM Says:

    many thanks for the reply. I got the queue thing working, thanks.

    regarding the selected:true, I’m talking about the last sentence of #4, where it says for fade and width modes you have to “set which content is to be initially displayed by setting ‘selected’: true”.

    Is it possible to set a default content tab to be open on page load with the slide or height mode?

    Thanks!

  • admin Says:

    I limited the functionality to ‘fade’ and ‘width’, but I don’t remember why. I will have to test ‘selected: true’ with the other ‘slide’ and ‘height’ options and then release a new version.

  • KM Says:

    hey there again,
    i am using this plugin for a site i’m developing and I really like it. The only minor thing i’m noticing is in slide mode, if you click the tab options rapidly when the animation is active, sometimes the previous tab content section stays open along with the most recently clicked tab content. It only seems to happen with rigorous clicking, but may come up occasionally…

    Also, if you add padding to the tab content section, the slide mode doesn’t close the container all the way and you can still see text from the closing content. not a big deal, if you add an inner div container and put margin/padding on that, it resolves the problem.

    that’s all
    thanks!

  • Aaron Says:

    Can you set this to auto rotate say after 2 minutes or so, and if you click a tab out of order the delay before the auto rotate restart can be set to a little longer?

  • admin Says:

    In regards to the first part of your question, are you referring to an automatic slideshow effect? I’m not sure that I understand the second part of your question.

  • Lindsayanng Says:

    Hi there.. I am new to javascript, but I am a quick learner.. Usually I learn by downloading prescripted things and tweaking them.

    I am having an issue with your plugin, and i’m sure its not YOUR PLUGIN but something I am doing wrong. I downloaded not 1.3.2.mini and 1.2.6.mini just to see if it was my version that was not working.. but its not working!

    I have the minified jquery and your plugin in my javascript folder, I have the links in my header as they should be.. I just copied and pasted your style sheet and code to get started playing.. and everything SHOWS UP on the page, but the javascript is not working.

    YOu can see here:
    http://bscphoto.com/design/js/index3.html

    Its an exact copy of your demo, which is usually how I start, but it just in NOT seeing the javascript. I have had this issue before when working with a gallery jquery plugin, but now I cant remember how I got it to work. I am wondering if its my server..
    .-= Lindsayanng´s last blog ..Pakistani Henna Ceremony =-.

  • admin Says:

    You should get Firebug to debug your javascript code. I think your problem is that you are loading the plugin before you load JQuery – just reverse the order.

  • Antoine Says:

    Hi,

    I am trying to use your plugin as a navigation tool.
    If I click a link the content is displayed. If I click it once more, the content disappears. How can I avoid disappearance of the content on second click (or set no action for the click on the selected link)

    Thank you!

  • YUI imSliderMenu Widget | GrasshopperPebbles.com Says:

    [...] created a YUI widget that is based on my imAnimTabber JQuery Plugin. The imSliderMenu displays content by animating the height or the width of the [...]

  • admin Says:

    Sorry, I have been working on a project that was taking all of my time. Are you still having problems?

  • Phantom Says:

    How would you Put the tabs on top?

    I have not found a good source yet, to have the tabs on top and fade at the same time.

    I know its possible, I just don’t know JS that well yet

  • Akash Says:

    Hi,

    I tried using this code. It works fine in Firefox but not in IE 7 and 8.

    Can you please help me figure out a solution for that.

    Thanks.
    Akash

CommentLuv badge