What is Easy Widgets?
After I read How to Mimic the iGoogle Interface tutorial, I think that is a very simple way to use Widgets in one of my projects: Gesbit, you can see here a demo. I study the tutorial code and want to put into a jQuery plugin. After some work I finally use this plugin in Gesbit and think that maybe can be useful for other developers.
The plugin as been tested in last version of Firefox, Opera, Internet Explorer, Safari, Konqueror and Chrome browsers. Please try the examples for more details.
I want just the code now!
Is useful for you?
Plugin requisites
In order to use this plugin you need the jQuery library and the jQuery UI with sortable and draggable stuff.
Who use this plugin?
You can view an implementation of this plugin in Gesbit, a Weblog Management System writen by me. See the Gesbit demo for details.
Another uses cases
I know that this websites using EasyWidgets plugin. Look diferent cases of use in this websites.
Thanks very much for the people that choose EasyWidgets!
I can view some examples please?
Yes. Here is various examples of use of Easy Widgets plugin:
- Very basic example with no style addition
- Very basic example but with some style addition
- Movable, Collapsable, Editable, Removable links
- Movable, Collapsable,... and Callbacks in actions
- How to use images to the widget menu header links
- How to internationalize alll used plugin strings
- Like some other example in the list with other style
- Variable number (4) of columns as widgets place holders
- Variable number (2) of columns as widgets place holders
- Show how to use the widget argument to identify widgets
- Show how to use the ui argument to identify widgets
- Show how to use with the addition of "cookies feature"
- Show how to use the widget editbox class for "save changes"
- Another example of apply some style to the widget HTML
- Show the use of another Widget container instead "div"
- The "onChangePositions" and "onRefreshPositions" callbacks
- Show the "EnableWidgets" and "DisableWidgets" methods
- Show the "EnableWidgets" and "DisableWidgets" callbacks
- Show how to apply effects in certain circustamces (fade)
- Show how to apply effects in certain circustamces (slide)
- Show the methods ShowEasyWidget() and HideEasyWidget()
- ShowEasyWidget() and HideEasyWidget() related callbacks
- How to use AddEasyWidget() method to add widgets on demand
- Around the use of AddEasyWidget() method and related callbacks
- Show all public methods, callbacks and other features in action
Amazing! Can you explain more?
Easy Widgets offer you over the control about your Widgets, and this is the very basic usage of the plugin, using the default settings, that we explain bello in this same page.
// When DOM ready
$(function(){
// Prepare the Widgets
$.fn.EasyWidgets();
});
The HTML markup of Widgets
The plugin is not obstrusive, and degrade gracefully. You are responsible for print out the HTML markup of the Widgets places and Widgets. I am use a couple of PHP class in Gesbit to do this, but, the fact is that you must write something like this:
In the above example, we print two Widgets places and one Widget, that can be place in one of the places. Take a look at the class identifiers: you can change this from the Easy Widgets settings, but we use here the HTML markup corresponding to the default plugin settings.
You can determine what number of places are availables: no limit here, and no limit about the number of Widgets that can be places in the places. Now we want to explain you how can configure a Widget, using the HTML markup too, in a easy way, just like this:
In the case of the above Widget, this is collapse by default, movable, editable, collapsable, removable and want to confirm when must be close. You can use anyone of the Widget options, a combination of this or no one. In fact, you can determine too the name of the options, because this form part of the Easy Widgets settings.
Here we use "DIV" container to store Widgets, but you can use another container like "LI", simply change a configuration option (the default container is "DIV") and you can print out something like this:
As you can see, the fact is the Widgets need a place to be store, an this place can be a container like "DIV" or "UL" in this case. So, every Widget is added in their own container, that can be "DIV" or "LI", depend of your needed, but using "DIV" per default. As you can see, every Widget contain some subsections: header, editbox and content.
The header contain the title of the Widget and Easy Widgets put in every Widget headers the appropiate menu links to collapse, remove, edit the Widget, etc., depend of the Widget options. The content of the Widgets is the content of the Widget, ok? And the editbox can contain a HTML form to edit the Widget, for example, and can show by the appropiate link in the menu links header.
This is the elements of a Widgets places and for the Widgets: remember that is possible to use any number of places or Widgets. And note that we not use here "identifiers" for the Widgets, that can be useful and maybe needed, for example, if you want to use the Cookies feature of Easy Widgets. In other words maybe is needed (or simply useful) to write something like this, but is optional in any case.
The CSS style of the Widgets
This is a good point, because the Widgets can be stylize with the only limit of your imagination. Here is the default CSS rules, with the selectors names using by default in the plugin (remember that you can change this too).
As you can see some little rules is using. But all that we needed for use the plugin from scratch. You can add more rules, change the style of the exists rules, we said, with the only limit of your imagination.
Plugin internationalization
You can translate the used Easy Widgets strings in a easy way, use the appropiate option in the plugin settings. In fact you can use this options to use images instead text in the Widget header menu links, as you can see in some of the above plugin examples.
As you see, you can determine the language to use in the Widgets plugin with the "i18n" configuration settings, so, if you want to use images instead links, you can put the HTML of a image in the appropiate link text.
Plugin optional cookies
Easy Widgets can be responsible for the position of the Widgets into the places, the collapse state of the Widgets, for example. You can determine to use cookies for this and can determine all about the cookies, take a look at the default "cookies" settings for Easy Widgets:
However, by default the plugin not use cookies, because as you can see bellow, you can determine how the Widgets is showing using the HTML markup, and some server stuff. But, if you want to use cookies, you can use the appropiate option in the "behaviour" settings of the plugin.
Plugin optional behaviour
Easy Widgets have some behaviour settings that you can change for your needs:
Maybe the most relevant option in the behaviour settings is "useCookies". If you use cookies, the plugin can be responsible for store the Widgets positions and collapse and closed states, and of course the maintenence of this cookies, fixed this when a Widget is no more use, for example. In other words, the Widget store in cookies the position for a Widget, for example, and after you not print anymore this Widget: the plugin can detect this situation and clean the appropiate cookie to no store unexisting Widgets.
Plugin optional effects
The plugin can apply certain effects when occurr some events:
The effects is none by default: the plugin hide or show the widget sections only. But you can specify "slide" or "fade" effects, for example, and the plugin apply this when is needed.
Plugin optional callbacks
Easy Widgets allow to handle a lot of task in the Widget via callbacks that you can attach to the appropiate configuration settings, here is all of the available Easy Widgets callbacks:
Plugin public methods
You have this public methods to use in your Widgets. For more information we refer you to the plugin source code. But here is a little descriptions.
Note something: Many of this methods can be supplied if you use jQuery directly. The goal of this mehods is that can be deal with the appropiate cookies. So, if you not use the plugin cookies feature, you can hide all widgets with: $('.widget).hide() code, for example, instead of use the appropiate plugin public method.
- EasyWidgets
- This is the main method of the plugin. You can use when the DOM are ready to initialize the Widgets.
- AddEasyWidget
- This method permit you to add new Widgets on demand in a page. Setup the HTML, decide the Widget place and simply use this method.
- HideEasyWidget
- Hide some visible Widget based in their identifier. This method also apply the appropiate changes in the cookies related, in case that you use this.
- HideEasyWidgets
- Hide all visible Widgets. This method also apply the appropiate changes in the cookies related, in case that you use this.
- ShowEasyWidget
- Show some hidden Widget based in their identifier. This method also apply the appropiate changes in the cookies related, in case that you use this.
- ShowEasyWidgets
- Show all hidden Widgets. This method also apply the appropiate changes in the cookies related, in case that you use this.
- EnableEasyWidgets
- Enable all Widgets, that is, permit that this can be movable by the user. This method also apply the appropiate changes in the cookies related, in case that you use this.
- DisableEasyWidgets
- Disable all Widgets, in other words, not permit that this can be movable by the user. This method also apply the appropiate changes in the cookies related, in case that you use this.
Give me all the power!
As you can see, the Easy Widgets plugin can be use without any option, using the default settings, but you can determine all the plugin stuff, between the Widget container, CSS selectors to use, option name, string to use, etc., etc. Here is all the default settings of the plugin, that you change if needed, but can use directly too, or change somethings, whatever you want:
Now, please, see the plugin examples, enjoy it, test the plugin, change the default options, apply some style to the Widgets, in fact, enjoy Easy Widgets plugin and thanks a lot for your interest!
