by Matthew Evans (matt @ putu)
- What is it?
- Why should I use it?
- Documentation
This is a pretty simple "framework" to help create a list of repeating timers that don't require any JavaScript.
It might be easier to use than something else, maybe.
Generates a list of timers from a given data source.
Keys:
- id: a unique identifier for the list. This must be different to other EverySecond timer lists, or else the CSS definitions will clash.
- dataFile: the path to the data file we want to use (JSON).
- per: defines what the timer's based on. Y = year, D = day.
- transitionTime: the duration of the transition from the resting state to the showing state. (seconds)
- showDuration: how long the loop should remain in the showing state. (seconds)
- restingCSS: PHP array representation of the CSS for the resting state.
- showingCSS: PHP array representation of the CSS for the showing state.
Defaults:
[
'id' => 'everySecond',
'dataFile' => 'data.json',
'per' => 'Y',
'transitionTime' => 0.2,
'showDuration' => 2.5,
'restingCSS' => [],
'showingCSS' => []
]
Determines whether or not the list should be displayed in a random order.
Gives the ability to have a custom data file structure: each element of the array must be a key-value pair. The key defines a variable name (title and delay are required) and the value defines which index per row in the data file corresponds to that variable.
Example:
data.json:
{
// title, delay, colour
["timerTitle", 0.2, "#f09"],
...
}
index.php:
...
$everySecondGenerator = new EverySecond([
...
]);
$everySecondGenerator->render([
'title => 0,
'delay' => 1,
'colour' > 2
], true);
Sets the config to $config
The config to be set. See constructor EverySecond for more details.
Returns the configuration array.
Returns the time in seconds that $per refers to.
Loads the data from the specified data file into the data member.
Creates a DOM object from a template with an automatically-generated CSS animation definition for the delay loop.
Configures the timer.
Keys:
- id: a unique identifier for the list. This must be different to other EverySecond timer, or else the CSS definitions will clash.
- title: the title for the timer
- delay: how often the timer hsould be in the showing state. (seconds)
- transitionTime: the duration of the transition from the resting state to the showing state. (seconds)
- showDuration: how long the loop should remain in the showing state. (seconds)
- restingCSS: PHP array representation of the CSS for the resting state.
- showingCSS: PHP array representation of the CSS for the showing state.
- template (optional): a custom template for the timer.
Defaults:
[
'id' => 'everySecondItem',
'title' => 'EverySecond Item',
'delay' => 60.0,
'transitionTime' => 0.2,
'showDuration' => 2.5,
'restingCSS' => [],
'showingCSS' => [],
'template' => '
<div class="es-timer">
<div class="es-timer__body" style="animation: animation_{{ id }} {{ delay }}s infinite;">
<div class="es-timer__title">
{{ title }}
</div>
<div class="es-loading-bar es-timer__loading-bar" style="animation-duration: {{ delay }}s;">
<div class="es-loading-bar__text">Every {{ delay }}s</div>
</div>
</div>
</div>'
]
Renders the CSS rules and HTML for the timer after processing the template.
Sets the config for the timer.
The configuration array. See constructor CSSTimer($config) for default values.
Returns the timer's config array.
Returns a string representation of the CSS definitions of the timer's animation loop's keyframes.
Determines whether or not the output should be wrapped within <style></style>
tags.
Returns a string representation of the HTML for the timer.
Returns a list from a JSON array.
{
["title", 0.5],
...
}
becomes
[
["title", 0.5],
...
]
A simple class for parsing templates.
Parses PHP template variables into their values defined in the context.
The template HTML to be parsed.
An array containing the template's variables' values as key => value pairs.
Usage
<?=$variable?>
Example:
$fwigger = new Fwigger();
$html = '
<p><?=$myText?></p>
<p><?=round($theNumber, 1)?></p>
';
$context = [
'myText' => 'Hello, world!',
'theNumber => 3.141
];
echo $fwigger->parse($html, $context);
will output
Hello, world!
3.1
Transforms an array representation of CSS properties/values into a string representation.
The array containing the property-value pairs.
Usage example:
$fwigger = new Fwigger();
$theCSSArray = [
'background' => 'pink',
'color' => '#fff',
'font' => [
size: '12pt',
family: 'Arial'
]
];
echo $fwigger-parseCSSArray($theCSSArray);
will output
background: pink;
color: #fff;
font-size: 12pt;
font-family: Arial;