Skip to content

Commit

Permalink
Add Masonry library
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Jul 31, 2024
1 parent 18e0b2f commit 3731c45
Showing 1 changed file with 63 additions and 38 deletions.
101 changes: 63 additions & 38 deletions framework/library/astroid/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Document
protected $minify_html = false;
protected static $_fontawesome = false;
protected static $_fancybox = false;
protected static $_masonry = false;
protected static $_slick = false;
protected static $_layout_paths = [];
protected $type = null;
protected $modules = null;
Expand All @@ -60,7 +62,7 @@ public function getType()
return $this->type;
}

public function addLayoutPath($path)
public function addLayoutPath($path): void
{
self::$_layout_paths[] = $path;
}
Expand Down Expand Up @@ -116,7 +118,7 @@ public function include($section, $data = [], $return = false)
echo trim($content);
}

public function compress()
public function compress(): void
{
$app = Factory::getApplication();
$body = $app->getBody();
Expand All @@ -133,7 +135,7 @@ public function compress()
$app->setBody($body);
}

public function isFrontendEditing()
public function isFrontendEditing(): bool
{
if (!Framework::isSite()) {
return false;
Expand Down Expand Up @@ -219,7 +221,7 @@ function addProtocol($url)
}


public function minifyCSS($html)
public function minifyCSS($html): array|string
{
Framework::getDebugger()->log('Minifying CSS');
$stylesheets = [];
Expand Down Expand Up @@ -381,7 +383,7 @@ public function minifyJS($html)
return $html;
}

public function minifyHTML($html)
public function minifyHTML($html): array|string|null
{
Framework::getDebugger()->log('Minifying HTML');
$level = Framework::getTemplate()->getParams()->get('minify_html_level', 'basic');
Expand Down Expand Up @@ -476,7 +478,7 @@ public function minifyHTML($html)
return trim($html);
}

public function _replace($rx, $replacement, $code, $callback = null)
public function _replace($rx, $replacement, $code, $callback = null): array|string|null
{
if ($callback === null) {
return preg_replace($rx, $replacement, $code);
Expand Down Expand Up @@ -515,7 +517,7 @@ public function _minifyAssets($m)
return $m[0];
}

private function _assetsHash()
private function _assetsHash(): string
{
$assets = [];
$assets[] = \json_encode($this->_styles);
Expand All @@ -529,7 +531,7 @@ private function _assetsHash()
return md5(serialize($assets));
}

public function position($position, $style = 'none')
public function position($position, $style = 'none'): string
{
if (empty($position)) {
return '';
Expand All @@ -547,7 +549,7 @@ public function position($position, $style = 'none')
return $return;
}

public function hasModule($position, $module)
public function hasModule($position, $module): bool
{
return in_array($module, array_column(ModuleHelper::getModules($position), 'module'));
}
Expand Down Expand Up @@ -582,7 +584,7 @@ public function loadModule($content)
return $content;
}

private function _modulePosition($position)
private function _modulePosition($position): false|string
{
$this->modules[$position] = '';
$document = Factory::getDocument();
Expand All @@ -599,7 +601,7 @@ private function _modulePosition($position)
return $this->modules[$position];
}

private function _moduleId($id)
private function _moduleId($id): false|string
{
$this->modules[$id] = '';
$document = Factory::getDocument();
Expand Down Expand Up @@ -664,7 +666,7 @@ private function _positionLayouts()
return $return;
}

protected function checkDev()
protected function checkDev(): void
{
$params = Framework::getTemplate()->getParams();
if ($params->exists('developemnt_mode')) {
Expand All @@ -675,15 +677,15 @@ protected function checkDev()
$this->_dev = ($dev ? true : false);
}

public function isDev()
public function isDev(): bool
{
if ($this->_dev === null) {
$this->checkDev();
}
return $this->_dev;
}

public function addMeta($name, $content, $attribs = [])
public function addMeta($name, $content, $attribs = []): void
{
$this->_metas[$name] = [
'name' => $name,
Expand All @@ -692,7 +694,7 @@ public function addMeta($name, $content, $attribs = [])
];
}

public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => 'text/css'])
public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => 'text/css']): void
{
$this->_links[md5($href)] = [
'href' => $href,
Expand All @@ -701,7 +703,7 @@ public function addLink($href = '', $rel = 'stylesheet', $attribs = ['type' => '
];
}

public function renderMeta()
public function renderMeta(): string
{
$html = '';
foreach ($this->_metas as $meta) {
Expand All @@ -720,7 +722,7 @@ public function renderMeta()
return $html;
}

public function renderLinks()
public function renderLinks(): string
{
$html = '';
foreach ($this->_links as $link) {
Expand All @@ -739,7 +741,7 @@ public function renderLinks()
return $html;
}

public function beutifyURL($url)
public function beutifyURL($url): array|string
{
$url = str_replace('?' . Helper::joomlaMediaVersion(), '', $url);
$url = str_replace(Uri::root(), '', $url);
Expand All @@ -754,7 +756,7 @@ public function beutifyURL($url)
return $url;
}

public function addScript($url, $position = 'head', $options = [], $attribs = [], $type = '')
public function addScript($url, $position = 'head', $options = [], $attribs = [], $type = ''): void
{
if (!is_array($url)) {
$url = [$url];
Expand All @@ -771,7 +773,7 @@ public function addScript($url, $position = 'head', $options = [], $attribs = []
}
}

public function getScripts($position = 'head')
public function getScripts($position = 'head'): string
{
$html = '';
foreach ($this->_javascripts[$position] as $javascript) {
Expand All @@ -783,7 +785,7 @@ public function getScripts($position = 'head')
return $html;
}

public function getCustomTags($position = 'head')
public function getCustomTags($position = 'head'): string
{
$content = '';
foreach ($this->_customtags[$position] as $tag) {
Expand All @@ -792,7 +794,7 @@ public function getCustomTags($position = 'head')
return $content;
}

public function addScriptOptions($key, $options, $merge = true)
public function addScriptOptions($key, $options, $merge = true): static
{
if (empty($this->scriptOptions[$key])) {
$this->scriptOptions[$key] = [];
Expand All @@ -816,7 +818,7 @@ public function getScriptOptions($key = null)
return $this->scriptOptions;
}

protected function _systemUrl($url, $version = true)
protected function _systemUrl($url, $version = true): string
{
$config = Factory::getApplication()->getConfig();
$params = Helper::getPluginParams();
Expand Down Expand Up @@ -848,7 +850,7 @@ protected function _systemUrl($url, $version = true)
return $url.$postfix ;
}

public function addScriptDeclaration($content, $position = 'head', $type = 'text/javascript')
public function addScriptDeclaration($content, $position = 'head', $type = 'text/javascript'): void
{
if (empty($content)) {
return;
Expand All @@ -859,15 +861,15 @@ public function addScriptDeclaration($content, $position = 'head', $type = 'text
$this->_scripts[$position][] = $script;
}

public function addStyleDeclaration($content, $device = 'desktop')
public function addStyleDeclaration($content, $device = 'desktop'): void
{
if (empty($content)) {
return;
}
$this->_styles[$device][] = trim($content);
}

public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' => 'text/css'], $shifted = 0)
public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' => 'text/css'], $shifted = 0): void
{
if (!is_array($url)) {
$url = [$url];
Expand All @@ -886,7 +888,7 @@ public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' =>
}
}

public function addCustomTag($content, $position = 'head')
public function addCustomTag($content, $position = 'head'): void
{
if (empty($content)) {
return;
Expand All @@ -897,15 +899,15 @@ public function addCustomTag($content, $position = 'head')
}
}

public function loadFontAwesome()
public function loadFontAwesome(): void
{
if (self::$_fontawesome) {
return;
}
Helper\Font::loadFontAwesome();
}

public function loadFancyBox()
public function loadFancyBox(): void
{
if (self::$_fancybox) {
return;
Expand All @@ -916,13 +918,35 @@ public function loadFancyBox()
self::$_fancybox = true;
}

public function moveFile(&$array, $a, $b)
public function loadMasonry(): void
{
if (!self::$_masonry) {
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('masonry', 'astroid/masonry.pkgd.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
self::$_masonry = true;
}
}

public function loadSlick($obj = '', $config = ''): void
{
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
if (!self::$_slick) {
$wa->registerAndUseStyle('slick.css', 'astroid/slick.min.css');
$wa->registerAndUseScript('slick.js', 'astroid/slick.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
self::$_slick = true;
}
if (!empty($obj) && !empty($config)) {
$wa->addInlineScript('jQuery(document).ready(function(){jQuery(\''.$obj.'\').slick({'.$config.'})});');
}
}

public function moveFile(&$array, $a, $b): void
{
$out = array_splice($array, $a, 1);
array_splice($array, $b, 0, $out);
}

public function getStylesheets()
public function getStylesheets(): string
{
$keys = array_keys($this->_stylesheets);
foreach ($keys as $index => $key) {
Expand All @@ -943,7 +967,7 @@ public function getStylesheets()
return $content;
}

public function renderScss($path)
public function renderScss($path): void
{
ini_set('memory_limit', '1024M');
Framework::getDebugger()->log('Rendering Scss');
Expand Down Expand Up @@ -1071,7 +1095,7 @@ public function renderScss($path)
Helper::putContents($path, $css->getCss());
}

public function renderCss()
public function renderCss(): string
{
/* if (Framework::isSite()) {
$template = Framework::getTemplate();
Expand All @@ -1090,7 +1114,7 @@ public function renderCss()
return $cssScript;
}

public function getBodyClass($extra_class = '')
public function getBodyClass($extra_class = ''): string
{
$template = Framework::getTemplate();

Expand Down Expand Up @@ -1160,7 +1184,7 @@ public function getBodyClass($extra_class = '')
return implode(' ', $class);
}

public function isBuilder()
public function isBuilder(): bool
{
$jinput = Factory::getApplication()->input;
$option = $jinput->get('option', '');
Expand Down Expand Up @@ -1193,7 +1217,7 @@ public static function getDir($dir, $extension = null, &$results = array())
return $results;
}

public static function scssHash()
public static function scssHash(): string
{
$params = Helper::getPluginParams();
$debug = $params->get('astroid_debug', 0);
Expand All @@ -1220,7 +1244,7 @@ public static function scssHash()
return md5($name);
}

public function astroidCSS()
public function astroidCSS(): void
{
$getPluginParams = Helper::getPluginParams();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
Expand Down Expand Up @@ -1292,7 +1316,8 @@ public function astroidCustomCSS() {
}
}

public function astroidInlineCSS() {
public function astroidInlineCSS(): string
{
// css on page
$getPluginParams = Helper::getPluginParams();
$astroid_inline_css = $getPluginParams->get('astroid_inline_css', 0);
Expand Down

0 comments on commit 3731c45

Please sign in to comment.