Infobar v1.1.1

A jQuery plugin made by jerone.

Intro

InfoBar is an IE-like bar at the top of the website. It is the same bar you get when a pop-up is blocked, special content is needed or if you want to download a file.

This script mimics the InfoBar with the same colors, an X to close it and even a context menu is available.
The whole script is written as a jQuery plugin and has support for other useful plugins.

Some of the features are:

  • Shows always at top and on top of the window.
  • HTML in the custom message is allowed.
  • Hover support for IE6. A new class (".hover") is added when hovered.
  • By supporting the jQuery Cookie plugin, closing an InfoBar is remembered.
  • It's possible to add a context menu for more options. Only text is allowed, but it's possible to add a small icon. Clicking the item executes a custom function or opens a defined website.
  • No style is added in the script itself, so all is fully changable with CSS.
  • Cross browser. Tested working in all major browsers: Internet Explorer 6 - 8, Firefox 1 - 3.5, Opera 9 & 10, Chrome 1 - 3 and Safari 4. It should work with newer browsers and may work with older browsers, no promise until tested.

Options

  • infoBar Datatype: jQuery plugin Default: -
    Returns: jQuery Status: Optional
    Description: The function to add an infobar on top.
    Example:-
    Arguments:
    • txt Datatype: String HTML Default: " "
      Returns: - Status: Mandatory
      Description: The message you want to show in the InfoBar. Can contain HTML. Special characters need to be converted to entities.
      Example:
      "An <em>InfoBar</em> with support for <a href='http://en.wikipedia.org/wiki/HTML'>HTML</a>."
    • options Datatype: Object Default: -
      Returns: - Status: Optional
      Description: Some optional options for more features.
      Example:-
      Options:
      • ID Datatype: String / null Default: A random number
        Returns: - Status: Optional
        Description: Possible to set your own id for the InfoBar. If none is provided a random number is used.
        The ID is only mandatory when cookie support is enabled.
        Example:-
      • type Datatype: jQuery.infoBar.type Default: jQuery.infoBar.type.warning
        Returns: - Status: Optional
        Description: There are a few predefined types of the InfoBar. Each type has another InfoBar image.
        The following types are available:
        • exclamation
        • error
        • help
        • ok
        • warning
        All types are styled in the included stylesheet, named with their type name.
        Example:
        type: jQuery.infoBar.type.exclamation
      • menu Datatype: Array [ Object ] Default: -
        Returns: - Status: Optional
        Description: A list of menu items for the context menu.
        The context menu has a few options itself to specify your own text, add an icon and execute a custom function.
        Example: The following code below adds 3 menu items to the context-menu. Each has some text, an icon and a url to a site. The last item has a custom function instead of a link.
        menu: [
        	{ txt: "Download Firefox", icon: "firefox.png", fn: "http://getfirefox.com" },
        	{ txt: "Download Opera", icon: "opera.png", fn: "http://opera.com" },
        	{ txt: "Download Chrome", icon: "chrome.png", fn: function() { window.open("http://google.com/chrome"); } }
        ]
        Arguments:
        • txt Datatype: String Default: "&nbsp;"
          Returns: - Status: Mandatory
          Description: The text shown in the menu item.
          Example:-
        • icon Datatype: String IMAGE Default: -
          Returns: - Status: Optional
          Description: An icon shown before the text in the menu item. Any picture will do, but 16*16 pixels is used for the size.
          Example:
          icon: "image.jpg"
        • fn Datatype: Function / String Default: -
          Returns: Boolean Status: Optional
          Description: A custom function executed when the menu item is clicked. If fn is a string it will be automatic opened as a url.
          If the custom function returns False, the context-menu and InfoBar won't be hidden.
          Example: The following example will return a boolean when the user clicks the confirm box. If the use chooses "No", a False will be returned and the context-menu and InfoBar won't be hidden.
          fn: function() { 
          	var answer = confirm("Are you sure you want to go to Infobar hompage?");
          	if (answer)
          		window.open("http://tinyurl.com/jqueryinfobar");
          	return answer;
          }
      • hide Datatype: Boolean Default: False
        Returns: - Status: Optional
        Description: Hide the InfoBar at start up.
        With the normal .show() command, it is possible to show the InfoBar again after setting this option to True.
        Example:-
      • cookie Datatype: Boolean Default: True
        Returns: - Status: Optional
        Description: To remember the state of the InfoBar (shown/hidden), support is added for the jQuery Cookie plugin to save it's state.
        The ID parameter is mandatory for saving.
        Example:-
      • zOrder Datatype: Integer Default: 1
        Returns: - Status: Optional
        Description: Not yet implemented.
        Example:-

Usage

Place the following code in the head of your page.

<!-- InfoBar StyleSheet -->
<link type="text/css" rel="stylesheet" href="jquery-infobar.css" media="screen" />

<!-- Mandatory JavaScript files -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="jquery-infobar.js"></script>
<!-- Optional plugins -->
<script type="text/javascript" src="jquery-cookie.js"></script>

<!-- InfoBar definition -->
<script type="text/javascript">
	(function($) {
		$(function() {
			$.infoBar("test 1");
			
			$.infoBar("test 2", { ID: "test", menu: [
				{ txt: "Download Firefox", icon: "firefox.png", fn: "http://getfirefox.com" },
				{ txt: "Download Opera", icon: "opera.png", fn: "http://opera.com" },
				{ txt: "Download Chrome", icon: "chrome.png", fn: function() { window.open("http://google.com/chrome"); } }
			]});
		});
	})(jQuery);
</script>

The InfoBar plugin must be called after the document is loaded.

 

Do you want to have the InfoBar fixed to the top of the page in IE6? Add the following code to your site.

<!--[if gte IE 5.5]>
<![if lt IE 7]>
<style type="text/css">
	.infobar {
		left: expression( ( 20 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' );
		top: expression( ( 10 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
	}
</style>
<![endif]>
<![endif]-->

Or you can use another jQuery plugin I made: jQuery fixFixed.
Add the following code after the InfoBar:

.fixFixed(["top", "left", "right"]);

Download

A zip archive for this plugin is available here: jquery-infobar-1.1.1.zip (size: 41kb).

The zip archive contains the following files:

Changelog

  • version 1.1.1 (20-7-2009):
    • Added minified script version;
  • version 1.1 (19-7-2009):
  • version 1.0 (1-7-2009):
    • Initial release;

FAQ

Which versions of jQuery is this plugin compatible with?
This plugin is compatible with jQuery 1.3 and higher.

Which browsers is this plugin compatible with?
Tested working in Internet Explorer 6 - 8, Firefox 1 - 3.5, Opera 9 & 10, Chrome 1 - 3 and Safari 4. It should work with newer browsers and can work with older browsers, no promise until tested.

Does the plugin work with any other plugins?
Infobar has integrated support for jQuery Cookie plugin.

But because the plugin returns the container of the Infobar, you can do anything with it.

Is there a VSDoc file available for this plugin?
Yes, there's a VSDoc file available on the download page.

What is VSDoc?
VSDoc is documentation format for Visual Studio. By using this file information is added to JavaScript Intellisense. This is only available in VS2008.

Todo

  • ...
Search

Site Search

Search

Google Search

Ads