Appunti ad una mente congestionata

23 marzo 2010

A jQuery notification area

I was searching a jQuery lib that allows me to create a sort of notification area and that I could simply integrate in my project. After a log googleing session and the test of about ten library, I focused my attention on jBar, a concise library that simply do what I wont! Just an aspect didn't satisfied my needs: the capability to directly invoke the applet to show a message in consequence to an event and not only with user interaction.

Obviously I modified the code to match my needs and here I'm posting the result.

So the difference from the original jBar library and my hack is the capability to be invoked on request.

The modifications are limited to the jBar JavaScript code (obviously) and a small addition to the CSS and the demo page. You can download the hacked lib here, following I describe my mods.

To better positioning the notification area and to allow it to be shorter than the window width, I inserted a container jbar-container in which the JS lib will annidiate the jBar. So we have to add the CSS definition for jbar-container and modify the jbar one as follow:


.jbar-container {
position: absolute;
left: 0;
width: 100%;
display: none;
}

.jbar{
height:50px;
margin-left: auto;
margin-right: auto;
width:80%;
background-color: #fff;
position:relative;
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=95);
opacity: 0.95;
-moz-opacity: 0.95;
text-align:center;
z-index:9999999;
padding:0px;
}


To allow the JS library to correctly insert the bar, we have to add a DIV on top of our page, so, just after the <BODY> tag, put:


<div class="jbar-container"></div>


The hack to the JavaScript code is essentially limited to extract the code in jBthis.click(function(e){ ... function and put it in an external function so we can call it directly upon necessity. Moreover I added the possibility to pass the function a message to display. You can look at the code, it is more simple than to explain!
Share:

2 commenti:

  1. How should I call the jbar without using an element?

    RispondiElimina
  2. I received my first business loans when I was a teenager and that supported my business very much. But, I need the small business loan as well.

    RispondiElimina