You can now access all recents development in our Google Code for gWidgets page and join our gWidgets Google Groups for discussion and support!

Overview

gWidgets is a collection of simple javascript "widgets" with AJAX capability. Open-source license.

gWidgets is a simple, unobtrusive and light (roughly 20k) javascript library that delivers "widgets" for your website. It is one convenient package with several widgets included in one file and sharing common features. So far we have 4 widgets, but more will come soon.

gExpander: a simple way to show/hide (toggle) inline/ajax content.

gTab: tab solution for inline/ajax content.

gBox: simple modal window for image and inline/ajax content.

gTip: tooltip solution for inline/ajax content.

Yes I know, you can already find similar widgets around the internet but my concerns in gWidgets are:

Technically speaking, follow me...

If you already use Prototype , it can be a good solution for you: 4 widgets in roughly 20k so far (including Base.js).

Demo

Of course we put a demo for you to see before downloading. You will see in this other demo that it is possible to put widgets inside other widgets as well as specific parameters.

How to use

Requirements - Of course it uses Prototype, it optionally uses Scriptaculous effects.js if available, and finally it uses Base.js (4k only) to easily and nicely create OOP due to lake of simple solution in Prototype yet (I read somewhere they plan to integrate a Base approach on v2 of Prototype).

Browsers - Because yes, we have to talk about those "guys". It works well in Firefox 1.5+, Safari, Opera9+ and IE6+ (IE5 and IE7?...due to a lack of pc around me to test..yes it can happen!).

gWidgets are mainly composed by 3 different parts: one javascript file (the brain), one css file (the style) and some images.

Part One - copy all three folders (js/, css/ and images/) inside the zip into your website.

Part Two - add the following lines into your html head tag:






Of course you can modify the src to adapt to your configuration.

Part Three (Optional) - You can change the css to look the way you want and if you want to change some of the script parameters, here is the list of currently available parameters:

  • declarative: if you insert declarative, then you must declare your gwidgets manually (e.g. 'new gExpander('idofelement')')
  • msgError: message to display in case of ajax error (default:'Sorry, it seems there is a communication problem with our server, try later...'),
  • msgWaiting: message display while loading ajax content (default:'Please wait while loading...'),
  • msgClose: text to show a close button in gBox modal window (default:'close')
  • pathImg: path to access images (default:'images/'),
  • arrowLeft: image for gExpander (default: 'arrow-left-action.gif'),
  • arrowBottom: image for gExpander (default: 'arrow-bottom-action.gif'),
  • loadingImg: indicator image while ajax content loads (default: 'loading.gif'),
  • defaultWidth and defaultHeight: default modal window size if nothing is specified in the url (default: 450 and 350),
  • toggleEffect: scriptaculous toggle effect (Effect.toggle), will be used only if scriptaculous effects.js is available (default: 'appear')
  • useRefresh: for ajax content, gWidget will show a small refresh icon to reload the content (default: true)
  • eventOn: default event handler to show gtip (default: mouseover), can be global or local
  • eventOff: default event handler to hide gtip (default: mouseout)
  • tipTitle: show/hide the gtip title (default true)
Here is how to insert them into your page:

gExpander is a very simple widget to toggle visibility of a inline block or, if a url is avalaible, an ajax content.

You simply create a link with the class 'gexpander' and the script will take care of the rest.
For an inline content:

your link to control the container visibility
for a remote content:
your link to control the container visibility
Notes:
  • For the href attribute you must at least specify the #container name which specify the id of the block you want to toggle visibility.
  • If you specify a url before the #container, then the expander will do an XHR (ajax) request to get the content and input it inside the container.
  • If the container does not exist in the page, it will be created (a div tag) just below the controller (link with gexpander class).
  • Inside your controller link you can put any type of content (text, image,...)

gTab is a tab widget (you are using it right now to read this content!) to conveniently group inline content or, if a url is avalaible, ajax content.

You create a div tag with the class 'gtab' with the following structure:

Notes:
  • For the href attribute you must at least specify the #container name which specify the if of the tab to show.
  • If you specify a url before the #container, then the tab will do an XHR (ajax) request to get the content and input it inside the container.
As usual you can change the css to get your own look-and-feel.

gBox is a modal window system for content either inline or remote. It acts also as a "lightbox"-like if the link href is an image (jpg, gif or png).

You create a link with the class 'gbox' and the script will take care of the rest.
For an inline content (it will move the container inside the modal window and show it):

show me!
for a remote content:
show me!
for an image (it will show the big size image in the modal window, resized to fit inside your browser window if necessary):
show my image
Notes:
  • For the href attribute you must: for an inline content, specify the #container name which specify the id of the block you want to show in your modal window (if the container does not exist in the page, it will show you an error), for a remote content, specify the url,
  • Inside your controller link you can put any type of content (text, image,...),
  • If you put a title attribute inside your link, it will be used as the modal window title.
You can also specify a few parameters to control the width and height of your window if you wish:
show me!

gTip is another tooltip solution for content either inline or remote.

You create a link with the class 'gtip' and the script will take care of the rest. You can also create a tooltip on any element adding a 'gtip' attribute to give the url. If you want a tooltip on a link where you want to keep the click on the link, you can use the attribute 'gtip' rather than the href.
The tooltip will be by default on the right unless there is not enough space then it will be positioned on the right of the element.
For an inline content (it will copy the content inside the tooltip and show it):

show me!
	
for a remote content:
show me!
or
show me!
Notes:
  • For the href attribute you must: for an inline content, specify the #container name which specify the id of the block you want to show in your tooltip, for a remote content, specify the url,
  • If you put a title attribute inside your link/tag, it will be used as the tooltip title.
You can also specify a few parameters to control the width and height of your tooltip if you wish:
show me!

Download

gWidgets v0.8.0

GPL and MIT licenses

For those interested, these widgets are also available as helper for Symfony

Support

I have setup a forum to easily discuss about it, feel free to join and share your comments, request new features,... You can as well subscribe to my blog RSS feed to get informed on new releases

I am also very open to share the development if you are willing to help on develop these widgets, feel free to contact me.

For the future, I am thinking to improve the code (I guess you will see that it can be improved a lot...) as well as adding new widgets.

Of course if you feel in a good mood, you can always support this project by a small donation, it will help me to continue to learn and to improve stuff along the line.

Todo List

If you ask "is there any bugs?", the answer is simply: "YES"...

Links

All those widgets are not new as such but I believe they bring a few different things and definitively cover my needs. Part of my code is inspired by some very good widgets already available and I want to acknowledge their work, namely: Fabtabulous! and jQuery Tabs plugin for the gTab. For gBox, Prototype Window and Thickbox and of course the first of all of them Lightbox JS.