This repository was archived by the owner on Jun 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbootstrap3.php
More file actions
128 lines (113 loc) · 3.75 KB
/
bootstrap3.php
File metadata and controls
128 lines (113 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Bootstrap 3 Demo Template Package
*
* @copyright Copyright (C) 2015 Michael Babker. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Bootstrap 3 Template System Plugin
*/
class PlgSystemBootstrap3 extends JPlugin
{
/**
* Application object
*
* @var JApplicationCms
*/
protected $app;
/**
* Array containing information for loaded files
*
* @var array
*/
protected static $loaded = array();
/**
* Listener for onAfterInitialise event
*
* @return void
*/
public function onAfterInitialise()
{
// Only for site
if (!$this->app->isSite())
{
return;
}
// Register listeners for JHtml helpers
if (!JHtml::isRegistered('bootstrap.loadCss'))
{
JHtml::register('bootstrap.loadCss', 'PlgSystemBootstrap3::loadCss');
}
if (!JHtml::isRegistered('bootstrap.carousel'))
{
JHtml::register('bootstrap.carousel', 'PlgSystemBootstrap3::carousel');
}
}
/**
* Overrides JHtmlBootstrap::carousel() to add JavaScript support for Bootstrap's carousel plugin
*
* This method adds support for the wrap and keyboard options
*
* @param string $selector Common class for the carousels.
* @param array $params An array of options for the carousel.
* Options for the carousel can be:
* - interval number The amount of time to delay between automatically cycling an item.
* If false, carousel will not automatically cycle.
* - pause string Pauses the cycling of the carousel on mouseenter and resumes the cycling
* of the carousel on mouseleave.
* - wrap boolean Whether the carousel should cycle continuously or have hard stops.
* - keyboard boolean Whether the carousel should react to keyboard events.
*
* @return void
*/
public static function carousel($selector = 'carousel', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
JHtml::_('bootstrap.framework');
// Setup options object
$opt['interval'] = isset($params['interval']) ? (int) $params['interval'] : 5000;
$opt['pause'] = isset($params['pause']) ? $params['pause'] : 'hover';
$opt['wrap'] = isset($params['wrap']) ? (bool) $params['wrap'] : true;
$opt['keyboard'] = isset($params['keyboard']) ? (bool) $params['keyboard'] : true;
$options = json_encode($opt);
// Attach the carousel to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('.$selector').carousel($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
return;
}
/**
* Overrides JHtmlBootstrap::loadCss() to loads CSS files needed by Bootstrap
*
* This method removes support for the bootstrap-responsive and bootstrap-extended CSS files
*
* @param boolean $includeMainCss If true, main bootstrap.css files are loaded
* @param string $direction rtl or ltr direction. If empty, ltr is assumed
* @param array $attribs Optional array of attributes to be passed to JHtml::_('stylesheet')
*
* @return void
*/
public static function loadCss($includeMainCss = true, $direction = 'ltr', $attribs = array())
{
// Load Bootstrap main CSS
if ($includeMainCss)
{
JHtml::_('stylesheet', 'jui/bootstrap.min.css', $attribs, true);
}
// Load Bootstrap RTL CSS
if ($direction === 'rtl')
{
JHtml::_('stylesheet', 'jui/bootstrap-rtl.css', $attribs, true);
}
}
}