Skip to content

Commit

Permalink
Fix #2, improve code quality, bump FullPage.js-version
Browse files Browse the repository at this point in the history
  • Loading branch information
OleVik committed Jun 3, 2018
1 parent 62da0fb commit 7f14448
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v1.2.0
## 03-06-2018

1. [](#new)
* Bumped FullPage.js-version to 2.9.7
2. [](#improved)
* Inline documentation
3. [](#bugfix)
* Prevent caching to fix #2

# v1.1.0-beta.1
## 11-02-2018

Expand Down
42 changes: 36 additions & 6 deletions Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@
use Grav\Common\Page\Page;
use Grav\Common\Page\Collection;

/**
* Fullpage-plugin Utilities
*/
class Utilities
{
/**
* Plugin configuration
*
* @var array
*/
protected $config;

/**
* Instantiate Fullpage Utilities
*/

/**
* Instantiate Fullpage Utilities
*
* @param array $config Plugin configuration
*/
public function __construct($config)
{
$this->config = $config;
}

/**
* Creates page-structure recursively
* @param string $route Route to page
* @param string $mode Reserved collection-mode for handling child-pages
*
* @param string $route Route to page
* @param string $mode Reserved collection-mode for handling child-pages
* @param integer $depth Reserved placeholder for recursion depth
*
* @return array Page-structure with children
*/
public function buildTree($route, $mode = false, $depth = 0)
Expand Down Expand Up @@ -94,7 +106,9 @@ public function buildTree($route, $mode = false, $depth = 0)

/**
* Create HTML to use with fullPage.js
*
* @param array $pages Page-structure with children
*
* @return string HTML-structure
*/
public function buildContent($pages)
Expand Down Expand Up @@ -202,7 +216,9 @@ public function interpretShortcodes($content)

/**
* Generate menu with anchors and titles from pages
*
* @param array $tree Page-structure with children
*
* @return array Slide-anchors with titles
*/
public function buildMenu($tree)
Expand All @@ -221,7 +237,9 @@ public function buildMenu($tree)

/**
* Format styles for inlining
*
* @param array $styles Array of quote-enclosed properties and values
*
* @return string CSS-styles
*/
public function applyStyles($styles)
Expand Down Expand Up @@ -251,8 +269,11 @@ public function applyStyles($styles)

/**
* Find contrasting color from 50%-equation
*
* @param string $hexcolor Hexadecimal color-value
*
* @return string black|white
*
* @see https://24ways.org/2010/calculating-color-contrast
*/
public function getContrast50($hexcolor)
Expand All @@ -262,8 +283,11 @@ public function getContrast50($hexcolor)

/**
* Find contrasting color from YIQ-equation
*
* @param string $hexcolor Hexadecimal color-value
*
* @return string black|white
*
* @see https://24ways.org/2010/calculating-color-contrast
*/
public function getContrastYIQ($hexcolor)
Expand All @@ -277,10 +301,13 @@ public function getContrastYIQ($hexcolor)

/**
* Flatten a multidimensional array to one dimension, optionally preserving keys
* @param array $array Array to flatten
*
* @param array $array Array to flatten
* @param integer $preserveKeys 0 (default) to not preserve keys, 1 to preserve string keys only, 2 to preserve all keys
* @param array &$out Internal parameter for recursion
* @param array $out Internal parameter for recursion
*
* @return array Flattened array
*
* @see https://stackoverflow.com/a/7256477/603387
*/
public function flattenArray($array, $preserveKeys = 0, &$out = array())
Expand All @@ -299,10 +326,13 @@ public function flattenArray($array, $preserveKeys = 0, &$out = array())

/**
* Insert string within string
* @param string $str Original string
*
* @param string $str Original string
* @param string $insert String to insert
* @param int $index Position to insert to
* @param int $index Position to insert to
*
* @return string Original string with new string inserted
*
* @see https://stackoverflow.com/a/30820401/603387
*/
public function stringInsert($str, $insert, $index)
Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: FullPage
version: 1.0.0
testing: true
version: 1.2.0
testing: false
description: Fullscreen navigational slideshows through fullPage.js
icon: arrows-alt
author:
Expand Down
2 changes: 1 addition & 1 deletion css/jquery.fullpage.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 28 additions & 5 deletions fullpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@
use Grav\Common\Page\Collection;
use RocketTheme\Toolbox\Event\Event;

require('Utilities.php');
require 'Utilities.php';
use Fullpage\Utilities;

/**
* Creates slides using fullPage.js
*
* Class FullPageJsPlugin
*
* @package Grav\Plugin
* @return void
* @return void
* @license MIT License by Ole Vik
*/
class FullPagePlugin extends Plugin
{

/**
* [$options description]
* Grav cache setting
*
* @var [type]
*/
protected $options;
protected $cache;

/**
* Register intial event
*
* @return array
*/
public static function getSubscribedEvents()
Expand All @@ -40,6 +44,7 @@ public static function getSubscribedEvents()

/**
* Declare config from plugin-config
*
* @return array Plugin configuration
*/
public function config()
Expand All @@ -55,20 +60,27 @@ public function config()

/**
* Initialize the plugin and events
*
* @param Event $event RocketTheme events
*
* @return void
*/
public function onPluginsInitialized(Event $event)
{
if ($this->isAdmin()) {
return;
}
$this->grav['config']->set('system.cache.enabled', false);
$this->enable([
'onPageContentProcessed' => ['pageIteration', 0],
'onTwigTemplatePaths' => ['templates', 0]
'onTwigTemplatePaths' => ['templates', 0],
'onShutdown' => ['onShutdown', 0]
]);
}

/**
* Construct the page
*
* @return void
*/
public function pageIteration()
Expand Down Expand Up @@ -141,10 +153,21 @@ public function pageIteration()

/**
* Add templates-directory to Twig paths
*
* @return void
*/
public function templates()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}

/**
* Reset cache on shutdown
*
* @return void
*/
public function onShutdown()
{
$this->grav['config']->set('system.cache.enabled', $this->cache);
}
}
4 changes: 2 additions & 2 deletions js/jquery.fullpage.min.js

Large diffs are not rendered by default.

0 comments on commit 7f14448

Please sign in to comment.