-
Notifications
You must be signed in to change notification settings - Fork 9
/
infinite_scroll.php
127 lines (100 loc) · 4.31 KB
/
infinite_scroll.php
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
<?php
// no direct access
defined('_JEXEC') or die;
//START INFINITE SCROLL ----->
class plgSystemInfinite_Scroll extends JPlugin
{
protected $count;
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->count = 0;
}
public function onBeforeRender()
{
$doc = JFactory::getDocument();
$app = JFactory::getApplication();
$params = $this->params;
$cats = $params->get('categories');
$layout = $app->input->get('layout');
$use_plugin = false;
if ($app->isSite()) {
$use_plugin = true;
}
//Only run if the layout is set to blog
if ($layout == "blog" && $use_plugin) {
$cat_id = $app->input->get('id');
//Use the plugin if this category is selected or if no categories are selected
$use_plugin = (in_array($cat_id, $cats) || (count($cats) == 0)) ? true : false;
}
if (!$use_plugin) {
return false;
} else {
$inputs = $app->input->getArray(array(
'Itemid' => 'int',
'option' => 'string',
'view' => 'string',
'layout' => 'string',
'id' => 'int',
//'start' => 'int'
));
$buffer = $doc->getBuffer();
$context = $inputs['option'] . "." . $inputs['layout'];
$limit = $app->getUserStateFromRequest($context . '.limit', 'limit', 5, 'uint');
$limitStart = 0;
$urlsegs = array();
foreach ($inputs as $k => $v) {
if ($v) {
$urlsegs[] = "$k=$v";
}
}
$url = JURI::root() . "?" . implode('&', $urlsegs) . "&start=";
$buffer['component'][""] .= "<div class='infiniteNavigation'></div><a href='$url' class='infiniteScrollNextLink'> </a></div>";
$doc->setBuffer($buffer['component'][""], 'component', '');
if ($params->get('preset') == "Beez5") {
$config['container_selector'] = "body";
$config['item_selector'] = ".items-row";
$config['content_selector'] = ".blog";
} elseif ($params->get('preset') == "Beez2") {
$config['container_selector'] = "body";
$config['item_selector'] = ".item";
$config['content_selector'] = ".blog";
} else {
$config['container_selector'] = $params->get('container_selector');
$config['item_selector'] = $params->get('item_selector');
$config['content_selector'] = $params->get('content_selector');
}
if ($this->count === 0) {
switch ($params->get('jquery_loading')) {
case 0:
$doc->addScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
$doc->addScriptDeclaration('jQuery.noConflict();');
case 1:
$doc->addScript(JURI::root() . '/plugins/system/infinite_scroll/js/jquery.min.js');
$doc->addScriptDeclaration('jQuery.noConflict();');
break;
case 2:
break;
}
$doc->addScript(JURI::root(true) . '/plugins/system/infinite_scroll/js/jquery.infinitescroll.min.js');
$content = "
window.InfiniteConfig = {
container : '" . $config['container_selector'] . "',
nextSelector: '" . $params->get('next_selector') . "',
itemSelector: '" . $config['item_selector'] . "',
contentSelector: '" . $config['content_selector'] . "',
baseURL : '/localhost',
url : '$url',
limitStart : $limitStart,
limit : $limit,
finishedMsg : '" . $params->get('end_msg') ."',
msgText : '" . $params->get('loading_msg') ."'
}
";
$doc->addScriptDeclaration($content);
}
$this->count++;
return true;
}
}
}