1<?php 2 3 4namespace ComboStrap; 5 6 7class Hover 8{ 9 /** 10 * Smooth animation 11 * on hover animation 12 */ 13 const COMBO_HOVER_EASING_CLASS = "combo-hover-easing"; 14 /** 15 * Supported Animation name of hover 16 * float and grow are not in 17 */ 18 const HOVER_ANIMATIONS = ["shrink", "pulse", "pulse-grow", "pulse-shrink", "push", "pop", "bounce-in", "bounce-out", "rotate", "grow-rotate", "sink", "bob", "hang", "skew", "skew-forward", "skew-backward", "wobble-horizontal", "wobble-vertical", "wobble-to-bottom-right", "wobble-to-top-right", "wobble-top", "wobble-bottom", "wobble-skew", "buzz", "buzz-out", "forward", "backward", "fade", "back-pulse", "sweep-to-right", "sweep-to-left", "sweep-to-bottom", "sweep-to-top", "bounce-to-right", "bounce-to-left", "bounce-to-bottom", "bounce-to-top", "radial-out", "radial-in", "rectangle-in", "rectangle-out", "shutter-in-horizontal", "shutter-out-horizontal", "shutter-in-vertical", "shutter-out-vertical", "icon-back", "hollow", "trim", "ripple-out", "ripple-in", "outline-out", "outline-in", "round-corners", "underline-from-left", "underline-from-center", "underline-from-right", "reveal", "underline-reveal", "overline-reveal", "overline-from-left", "overline-from-center", "overline-from-right", "grow-shadow", "float-shadow", "glow", "shadow-radial", "box-shadow-outset", "box-shadow-inset", "bubble-top", "bubble-right", "bubble-bottom", "bubble-left", "bubble-float-top", "bubble-float-right", "bubble-float-bottom", "bubble-float-left", "curl-top-left", "curl-top-right", "curl-bottom-right", "curl-bottom-left"]; 19 const ON_HOVER_SNIPPET_ID = "onhover"; 20 const ON_HOVER_ATTRIBUTE = "onhover"; 21 22 /** 23 * Process hover animation 24 * @param TagAttributes $attributes 25 */ 26 public static function processOnHover(&$attributes) 27 { 28 if ($attributes->hasComponentAttribute(self::ON_HOVER_ATTRIBUTE)) { 29 $hover = strtolower($attributes->getValueAndRemove(self::ON_HOVER_ATTRIBUTE)); 30 $hoverAnimations = preg_split("/\s/", $hover); 31 32 $comboDataHoverClasses = ""; 33 $snippetManager = PluginUtility::getSnippetManager(); 34 foreach ($hoverAnimations as $hover) { 35 36 if (in_array($hover, self::HOVER_ANIMATIONS)) { 37 $snippetManager->attachTagsForBar(self::ON_HOVER_SNIPPET_ID) 38 ->setCritical(false) 39 ->setTags( 40 array("link" => 41 [ 42 array( 43 "rel" => "stylesheet", 44 "href" => "https://cdnjs.cloudflare.com/ajax/libs/hover.css/2.3.1/css/hover-min.css", 45 "integrity" => "sha512-csw0Ma4oXCAgd/d4nTcpoEoz4nYvvnk21a8VA2h2dzhPAvjbUIK6V3si7/g/HehwdunqqW18RwCJKpD7rL67Xg==", 46 "crossorigin" => "anonymous" 47 ) 48 ] 49 )); 50 $attributes->addClassName("hvr-$hover"); 51 52 } else { 53 54 /** 55 * The combo hover effect 56 */ 57 if (in_array($hover, ["float", "grow"])) { 58 $hover = "combo-" . $hover; 59 } 60 61 /** 62 * Shadow translation between animation name 63 * and class 64 */ 65 switch ($hover) { 66 case "shadow": 67 $hover = Shadow::getDefaultClass(); 68 break; 69 case "shadow-md": 70 $hover = Shadow::MEDIUM_ELEVATION_CLASS; 71 break; 72 case "shadow-lg": 73 $hover = "shadow"; 74 break; 75 case "shadow-xl": 76 $hover = "shadow-lg"; 77 break; 78 } 79 80 /** 81 * Add it to the list of class 82 */ 83 $comboDataHoverClasses .= " " . $hover; 84 85 } 86 87 } 88 if (!empty($comboDataHoverClasses)) { 89 90 // Grow, float and easing are in the css 91 $snippetManager 92 ->attachCssSnippetForBar(self::ON_HOVER_SNIPPET_ID) 93 ->setCritical(false); 94 95 // Smooth Transition in and out of hover 96 $attributes->addClassName(self::COMBO_HOVER_EASING_CLASS); 97 98 $attributes->addHtmlAttributeValue("data-hover-class", trim($comboDataHoverClasses)); 99 100 // The javascript that manage the hover effect by adding the class in the data-hover class 101 $snippetManager->attachJavascriptSnippetForBar(self::ON_HOVER_SNIPPET_ID); 102 103 } 104 105 } 106 107 } 108} 109