<?php
namespace Website\Widgets\Container; use Moto; use Twig_Markup; class Widget extends Moto\System\Widgets\AbstractContainerWidget { protected $_name = 'container'; protected static $_defaultProperties = array( 'anchor' => '', 'stickyEnabled' => false, 'stickyHidden' => false, 'bgParallaxed' => false, 'bgFixed' => false, 'viewportHeight' => false, 'justify' => false, ); protected $_templateType = 'templates'; protected $_widgetId = true; public $customAttributes = []; public function getCustomAttributes() { return $this->customAttributes; } public function preRender() { parent::preRender(); if ($this->getPropertyValue('stickyEnabled')) { $sticky = []; if ($this->getPropertyValue('stickyHidden')) { $sticky['hidden'] = true; } $this->customAttributes['data-moto-sticky'] = (object) $sticky; } if ($this->getPropertyValue('bgParallaxed')) { $this->customAttributes['data-stellar-background-ratio'] = '0.5'; } $this->customAttributes['data-css-name'] = $this->getPropertyValue('cssName'); return; $style = new Moto\Application\Styles\StyleModel(); $style->class_name = $this->getPropertyValue('cssName'); $style->name = $this->getPropertyValue('cssName'); $style->type = 'widget'; $style->properties = $this->getPropertyValue('styles'); $twig = Moto\Render::getInstance(); $content = $twig->render('@lessTemplates/styler.less.twig', array( 'items' => [$style] )); Moto\Hook::on(Moto\Hook::RENDER_WEBSITE_BODY_BOTTOM, function($event, $value) use ($content) { $value .= "\n" . '<style>' . $content . '</style>' . "\n"; return $value; }); } public function exportStyles() { $styles = $this->getPropertyValue('styles.desktop.base'); if ($this->isPreRenderMode()) { $css = '{{ StyleHelper.generateLessFromArray(' . json_encode($styles) . ') }}'; } else { $css = $this->_getStyleHelper()->generateLessFromArray($styles); } $css = trim($css); if (!strlen($css)) { return ''; } $code = '<style>.' . $this->getPropertyValue('cssName') . ' { ' . $css . '} </style>'; return new Twig_Markup($code, 'UTF-8'); } public function isBackgroundVideoSet() { return $this->getPropertyValue('bgVideo.track.webm.path') || $this->getPropertyValue('bgVideo.track.mp4.path'); } } 