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