PluginProbe
ZIP AI – AI Website Builder & AI Agent / trunk
ZIP AI – AI Website Builder & AI Agent vtrunk
0.0.13 0.0.12 0.0.11 0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / inc / core / aos-hover-handover.php

aos-hover-handover.php in ZIP AI – AI Website Builder & AI Agent trunk, at inc/core/aos-hover-handover.php

63 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Aos Hover Handover — a card's own hover eases again after its scroll entrance.
4 *
5 * Spectra runs scroll entrances with AOS, which keeps `transition-property:
6 * opacity, transform` on an element after its entrance has played, so the
7 * element's own hover (translate, scale, box-shadow) snaps instead of easing.
8 * When a play-once entrance ends, its `data-aos*` attributes come off and the
9 * element's own transition is back. Only an entrance marked play-once
10 * (`data-aos-once="true"`) is handed over: AOS replays by default, and a replaying
11 * entrance keeps its attributes. It rides Spectra's own AOS init, so it prints only
12 * on a page where Spectra loads AOS, and AOS itself is off under reduced motion.
13 *
14 * @since 0.0.13
15 * @package zip-ai
16 */
17
18 namespace ZipAI\MCP\Classes\Core;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * Attaches the handover to Spectra's AOS init — see the file header.
26 */
27 class Aos_Hover_Handover {
28
29 /**
30 * Spectra's AOS init script, registered and enqueued on `wp_footer` (priority 10).
31 *
32 * @var string
33 */
34 const AOS_INIT_HANDLE = 'spectra-aos-init';
35
36 /**
37 * The handover: when the entrance's own opacity or transform transition ends on
38 * the element (not a pseudo-element), a played play-once entrance gives the
39 * element its transition back.
40 *
41 * @var string
42 */
43 const SCRIPT = "document.addEventListener('transitionend',function(e){var el=e.target;if(e.pseudoElement||(e.propertyName!=='opacity'&&e.propertyName!=='transform')||!el.classList||!el.classList.contains('aos-animate')||!el.hasAttribute('data-aos')||el.getAttribute('data-aos-once')!=='true')return;Array.prototype.slice.call(el.attributes).forEach(function(a){if(a.name.indexOf('data-aos')===0)el.removeAttribute(a.name);});});";
44
45 /**
46 * Hook registration: after Spectra enqueues its init (priority 10), before
47 * footer scripts print (priority 20).
48 */
49 public static function init(): void {
50 add_action( 'wp_footer', array( __CLASS__, 'attach' ), 11 );
51 }
52
53 /**
54 * Attach the handover to Spectra's AOS init when this page loads it.
55 */
56 public static function attach(): void {
57 if ( ! wp_script_is( self::AOS_INIT_HANDLE, 'enqueued' ) ) {
58 return;
59 }
60 wp_add_inline_script( self::AOS_INIT_HANDLE, self::SCRIPT, 'after' );
61 }
62 }
63