Skip to content

Commit e939e17

Browse files
committed
Merge branch 'release/v1.1.1'
2 parents fe58c29 + 59c364f commit e939e17

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v1.1.1
2+
## 11/03/2017
3+
4+
1. [](#bugfix)
5+
* enable `onPageContentProcessed` and `onTwigSiteVariables` directly in `onPluginsInitialized`. Otherwise it would not work, if another plugin uses the same hooks (like grav-plugin-shortcode-core).
6+
2. [](#improved)
7+
* only include css and js files, if the plugin is active on current page
8+
9+
110
# v1.1.0
211
## 10/27/2017
312

blueprints.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Simple Responsive Tables
2-
version: 1.1.0
2+
version: 1.1.1
33
description: Wraps tables in a div, enabling them to be scrolled vertically on small screens.
44
icon: table
55
author:

simple-responsive-tables.php

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Grav\Plugin;
33

4+
use Grav\Common\Page\Page;
45
use Grav\Common\Plugin;
56
use RocketTheme\Toolbox\Event\Event;
67

@@ -40,38 +41,29 @@ public function onPluginsInitialized()
4041

4142
// Enable the main event we are interested in
4243
$this->enable([
43-
'onPageInitialized' => ['onPageInitialized', 0]
44+
'onPageContentProcessed' => ['onPageContentProcessed', 0],
45+
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
4446
]);
4547
}
4648

47-
public function onPageInitialized()
48-
{
49-
if ($this->isAdmin()) {
50-
return;
51-
}
52-
53-
/** @var Page $page */
54-
$page = $this->grav['page'];
55-
56-
$config = $this->mergeConfig($page);
57-
$active = $config->get('active', $config->get('process'));
58-
59-
if ($active) {
60-
$this->enable([
61-
'onPageContentProcessed' => ['onPageContentProcessed', 0],
62-
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
63-
]);
64-
}
65-
}
66-
6749
/**
50+
* Process shortcodes after Grav's processing, but before caching
6851
* Find tables in page content and wrap it with two divs
52+
* @param Event $event
6953
* @return void
7054
*/
7155
public function onPageContentProcessed(Event $event)
7256
{
7357
/** @var Page $page */
74-
$page = $this->grav['page'];
58+
$page = $event['page'];
59+
$config = $this->mergeConfig($page);
60+
61+
$this->active = $config->get('active', $config->get('process'));
62+
63+
// if the plugin is not active (either global or on page) exit
64+
if (!$this->active) {
65+
return;
66+
}
7567

7668
$raw_content = $page->content();
7769

@@ -89,7 +81,9 @@ public function onPageContentProcessed(Event $event)
8981
*/
9082
public function onTwigSiteVariables()
9183
{
92-
$this->grav['assets']->add('plugin://simple-responsive-tables/assets/css/simple-responsive-tables.css');
93-
$this->grav['assets']->add('plugin://simple-responsive-tables/assets/js/simple-responsive-tables.js');
84+
if($this->active) {
85+
$this->grav['assets']->add('plugin://simple-responsive-tables/assets/css/simple-responsive-tables.css');
86+
$this->grav['assets']->add('plugin://simple-responsive-tables/assets/js/simple-responsive-tables.js');
87+
}
9488
}
9589
}

0 commit comments

Comments
 (0)