Redaxscript\Modules\LazyLoad\LazyLoad::render PHP Метод

render() публичный статический Метод

render
С версии: 2.2.0
public static render ( mixed $file = null, array $optionArray = [] ) : string
$file mixed
$optionArray array
Результат string
    public static function render($file = null, $optionArray = [])
    {
        $output = null;
        /* device related images */
        if (is_array($file)) {
            /* process source */
            foreach ($file as $key => $value) {
                if (in_array($key, self::$_configArray['device']) && Registry::get('my' . ucfirst($key))) {
                    $file = $value;
                }
            }
        }
        /* collect output */
        if (file_exists($file)) {
            $imageElement = new Html\Element();
            $imageElement->init('img', ['alt' => $optionArray['alt'], 'class' => self::$_configArray['className']['image'], 'src' => self::$_configArray['placeholder']]);
            /* collect image output */
            $output = $imageElement->copy()->addClass($optionArray['className'])->attr('data-src', $file);
            /* placeholder */
            if (self::$_configArray['placeholder']) {
                /* calculate image ratio */
                $imageDimensions = getimagesize($file);
                $imageRatio = $imageDimensions[1] / $imageDimensions[0] * 100;
                /* placeholder */
                $placeholderElement = new Html\Element();
                $placeholderElement->init('div', ['class' => self::$_configArray['className']['placeholder'], 'style' => 'padding-bottom:' . $imageRatio . '%']);
                /* collect output */
                $output = $placeholderElement->html($output);
            }
            /* noscript fallback */
            $output .= '<noscript>' . $imageElement . '</noscript>';
        } else {
            self::setNotification('error', Language::get('file_not_found') . Language::get('colon') . ' ' . $file . Language::get('point'));
        }
        return $output;
    }