View source
<?php
function animations_endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return substr($haystack, -$length) === $needle;
}
function animations_library_info_build() {
$libs = [];
$config = \Drupal::config('animations.config');
foreach ($config
->get("animations_dependencies") as $key => $library) {
if (animations_endsWith($library["file"], "css")) {
$libs['animations.' . $key] = [
'css' => [
'base' => [
'/libraries/' . $key . '/' . $library["file"] => [],
],
],
];
}
else {
if (animations_endsWith($library["file"], "js")) {
$libs['animations.' . $key] = [
'js' => [
'/libraries/' . $key . '/' . $library["file"] => [],
],
];
}
}
}
return $libs;
}
function animations_page_attachments(array &$page) {
$config = \Drupal::config('animations.config');
foreach ($config
->get("animations_dependencies") as $key => $library) {
$page['#attached']['library'][] = 'animations/animations.' . $key;
}
$page['#attached']['library'][] = 'animations/animations';
$config = \Drupal::config('animations.config');
$page['#attached']['drupalSettings']['animations'] = $config
->get("animations");
}
function animations_help($path, $arg) {
$output = "";
switch ($path) {
case "help.page.animations":
$output = t('The module provides an easy way to include common animations into your website. <br />In order to add a new animation:<br />1. Go to "Configure".<br />2. Expand the desired animation tab.<br />3. Fill in your css selectors (each one on a new line). The animation will be applied to the filled css selectors. ');
break;
}
return $output;
}