ggpopover.js - jQuery Plugin
Overview
It's a simple jQuery popover plugin extended from Twitter Bootstrap's popover plugin that supports 4 positions, background color, title backgorund-color, font color and border color without using images.
Data Attributes "data-"
You can use the HTML5 data-
attributes (provided in the API reference) of any HTML element to set the different properties of ggpopover.js.
<a href="#_" data-toggle="popover" data-placement="right" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?"> Click to toggle popover </a>
This plugin uses the HTML5 data-api that enables to maintain the validaity of HTML code elements w.r.t W3C validation standards.
jQuery API method
The popover plugin generates content and markup on demand, and by default places popovers after their trigger element. Trigger the popover via JavaScript:
// code to initialize with defaults $('[data-toggle="popover"]').ggpopover(); // "content-textcolor" parameter with value "#000000" $('[data-toggle="popover"]').ggpopover({ 'content-textcolor' : '#000000' }); // multiple parameters $('[data-toggle="popover"]').ggpopover({ 'content-textcolor' : "#000000", placement : "top" });
API uses the default JSON based { key: value }
comma-separated pairs of options to set the popover properties.
Integration
CSS
Include the ggpopover.css inside the <head>
tags as shown below:
<link href="css/ggpopover.css" rel="stylesheet" />
JavaScript
Add the ggpopover.js at the bottom of your HTML page just above the closing </body>
tag.
<script type="text/javascript" src="js/ggpopover.js"></script>
HTML
After you are done with including CSS and JavaScript files you can add the following HTML markup in your page body:
<a href="#_" data-toggle="popover" data-placement="right" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?"> Click to toggle popover </a>
Usage
When you are done with adding above HTML markup code, you can call the ggpopover method over that tag:
$('[data-toggle="popover"]').ggpopover();
You can insert the above code below the included ggpopover.js script.
API Reference
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-title-backcolor=""
.
Name | type | default | description |
---|---|---|---|
animation | boolean | true | apply a CSS fade transition to the popover |
html | boolean | false | Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks. |
placement | string | function | 'top' | how to position the popover - top | bottom | left | right | auto.
When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right. |
selector | string | false | If a selector is provided, popover objects will be delegated to the specified targets. |
title | string | function | '' | default title value if title attribute isn't present |
bordercolor | string | '#cccccc' | Color name or Hex-code for setting the border color. |
arrowcolor | string | '#ffffff' | Color name or Hex-code for setting the arrow color. |
title-backcolor | string | '#f7f7f7' | Color name or Hex-code for setting the background color of title. |
title-bordercolor | string | '#ebebeb' | Color name or Hex-code for setting the border color of title. |
title-textcolor | string | '#000000' | Color name or Hex-code for setting the font color of title. |
content-backcolor | string | '#ffffff' | Color name or Hex-code for setting the background color of content. |
content-textcolor | string | '#000000' | Color name or Hex-code for setting the font color of content. |
trigger | string | 'hover focus' | how popover is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space. |
delay | number | object | 0 |
delay showing and hiding the popover (ms) - does not apply to manual trigger type If a number is supplied, delay is applied to both hide/show Object structure is: |
Data attributes for individual popovers
Options for individual popovers can alternatively be specified through the use of data attributes, as explained above.
Examples
Here are positions and color examples for ggpopover.js
Positions
Example - data-placement
Colors
title-backcolor | title-bordercolor | title-textcolor | content-backcolor | content-textcolor | bordercolor | arrowcolor | preview |
---|---|---|---|---|---|---|---|
#0099cc | #0099cc | #ffffff | #0099cc | preview | |||
#6633cc | #6633cc | #ffffff | #6633cc | preview | |||
#990099 | #990099 | #ffffff | #990099 | preview | |||
#0066cc | #0066cc | #ffffff | #0066cc | preview | |||
#cc3333 | #cc3333 | #ffffff | #cc3333 | preview | |||
#009900 | #009900 | #ffffff | #009900 | preview | |||
#cc6633 | #cc6633 | #ffffff | #cc6633 | preview | |||
#ccffff | #33ffff | #333333 | #33ffff | preview | |||
#ccccff | #9999ff | #333333 | #9999ff | preview | |||
#ffcccc | #ff9999 | #333333 | #ff9999 | preview | |||
#99ccff | #4d8ed0 | #333333 | #4d8ed0 | preview | |||
#ffcc99 | #cc9999 | #333333 | #cc9999 | preview | |||
#cccccc | #bbbbbb | #444444 | #eeeeee | #888888 | #bbbbbb | #eeeeee | preview |
#990099 | #990099 | #ffffff | #f1ddf1 | #990099 | #f1ddf1 | preview | |
#0066cc | #0066cc | #ffffff | #e0ebf6 | #0066cc | #e0ebf6 | preview | |
#cc3333 | #cc3333 | #ffffff | #f8ecec | #cc3333 | #f8ecec | preview |