Skip to content

Commit

Permalink
Proper popover shortcode.
Browse files Browse the repository at this point in the history
Popover still possible from buttons using data- properties.
  • Loading branch information
MWDelaney committed Sep 21, 2013
1 parent 524cb25 commit 9bb8847
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ The plugin doesn't support all Bootstrap elements yet, but most of them.
### JavaScript
* [Tabs](#tabs)
* [Tooltip](#tooltip)
* [Popover](#popover)
* [Collapse (Accordion)](#collapse)
* [Modals](#modals)
* [Modal](#modal)


# Usage
Expand Down Expand Up @@ -263,7 +264,7 @@ size | Modifies the amount of padding inside the well | optional | sm, lg | norm

[Bootstrap wells documentation](http://getbootstrap.com/components/#wells)

## Components
## Javascript

### Tabs
[tabs]
Expand Down Expand Up @@ -296,6 +297,19 @@ html | Insert HTML into the tooltip | optional | true, false | false

[Bootstrap tooltip documentation](http://getbootstrap.com/javascript/#tooltips)

### Popover
[popover title="I'm the title" content="And here's some amazing content. It's very engaging. right?" placement="right"] … [/popover]

Parameter | Description | Required | Values | Default
--- | --- | --- | --- | ---
title | The title of the popover | optional | any text | none
content | The text of the popover | required | any text | none
placement | The placement of the popover | optional | left, top, bottom, right | top
animation | apply a CSS fade transition to the tooltip | optional | any text | none
html | Insert HTML into the tooltip | optional | true, false | false

[Bootstrap popover documentation](http://getbootstrap.com/javascript/#popovers)

### Collapse (Accordion)
[collapsibles]
[collapse title="Collapse 1" state="active"]
Expand All @@ -316,7 +330,7 @@ active | Whether the tab is expanded at load time | optional | active | false

[Bootstrap collapse documentation](http://getbootstrap.com/javascript/#collapse)

### Modals
### Modal
[modal text="This is my modal" title="Modal Title Goes Here" xclass="btn btn-primary btn-large"]
[modal-footer]
Expand All @@ -330,5 +344,4 @@ text | Text of the modal trigger link | required | any text | none
title | Title of the modal popup | required | any text | none
xclass | Any extra classes you want to add to the trigger link | optional | any text | none

[Bootstrap modal documentation](http://getbootstrap.com/javascript/#modals)

[Bootstrap modal documentation](http://getbootstrap.com/javascript/#modals)
48 changes: 40 additions & 8 deletions bootstrap-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function add_shortcodes() {
add_shortcode('tabs', array( $this, 'bs_tabs' ));
add_shortcode('tab', array( $this, 'bs_tab' ));
add_shortcode('tooltip', array( $this, 'bs_tooltip' ));
add_shortcode('popover', array( $this, 'bs_popover' ));
add_shortcode('panel', array( $this, 'bs_panel' ));
add_shortcode('media', array( $this, 'bs_media' ));
add_shortcode('media-object', array( $this, 'bs_media_object' ));
Expand All @@ -86,7 +87,6 @@ function add_shortcodes() {
add_shortcode('modal', array( $this, 'bs_modal' ));
add_shortcode('modal-footer', array( $this, 'bs_modal_footer' ));


}


Expand Down Expand Up @@ -632,13 +632,8 @@ function bs_tooltip( $atts, $content = null ) {
'html' => 'false'
);
extract( shortcode_atts( $defaults, $atts ) );
$classes = 'bs-tooltip';
$data .= ' title="' . $title . '" ';
$data .= ' data-toggle="tooltip" ';
$data .= ($animation) ? 'data-animation="' . $animation . '" ' : '';
$data .= ($placement) ? 'data-placement="' . $placement . '" ' : '';
$data .= ($html) ? 'data-html="' . $html . '" ' : '';

$classes = 'bs-tooltip';

$dom = new DOMDocument;
$dom->loadXML($content);
if(!$dom->documentElement) {
Expand All @@ -656,6 +651,43 @@ function bs_tooltip( $atts, $content = null ) {
return $return;
}

/*--------------------------------------------------------------------------------------
*
* bs_popover
*
*
*-------------------------------------------------------------------------------------*/

function bs_popover( $atts, $content = null ) {

$defaults = array(
'title' => false,
'content' => '',
'placement' => 'top',
'animation' => 'true',
'html' => 'false'
);
extract( shortcode_atts( $defaults, $atts ) );
$classes = 'bs-popover';

$dom = new DOMDocument;
$dom->loadXML($content);
if(!$dom->documentElement) {
$element = $dom->createElement('span', $content);
$dom->appendChild($element);
}
$dom->documentElement->setAttribute('class', $dom->documentElement->getAttribute('class') . ' ' . $classes);
if($title) { $dom->documentElement->setAttribute('data-original-title', $title ); }
$dom->documentElement->setAttribute('data-content', $content );
if($animation) { $dom->documentElement->setAttribute('data-animation', $animation ); }
if($placement) { $dom->documentElement->setAttribute('data-placement', $placement ); }
if($html) { $dom->documentElement->setAttribute('data-html', $html ); }

$return = $dom->saveXML();

return $return;
}


/*--------------------------------------------------------------------------------------
*
Expand Down

0 comments on commit 9bb8847

Please sign in to comment.