Skip to content

Commit

Permalink
Code optimizations (using client shortcuts).
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed May 8, 2019
1 parent 5967f0a commit dcdc4e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BearFramework\Addons::register('bearcms/embed-element-addon', __DIR__, [
'require' => [
'bearcms/bearframework-addon',
'bearframework/localization-addon'
'bearframework/localization-addon',
'ivopetkov/client-shortcuts-bearframework-addon'
]
]);
3 changes: 1 addition & 2 deletions components/embedElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
}
?><html>
<head>
<style id="responsively-lazy-style">.responsively-lazy:not(img){position:relative;height:0;}.responsively-lazy:not(img)>img{position:absolute;top:0;left:0;width:100%;height:100%}img.responsively-lazy{width:100%;}</style>
<script id="responsively-lazy-script" src="<?= $context->assets->getURL('assets/responsivelyLazy.min.js', ['cacheMaxAge' => 999999999, 'version' => 2]) ?>" async/>
<link rel="client-shortcuts-embed" name="-bearcms-embed-element-responsively-lazy">
</head>
<body><?= $content ?></body>
</html>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"php": ">=7.1",
"bearcms/bearframework-addon": "1.*",
"bearframework/localization-addon": "0.2.*",
"ivopetkov/html5-dom-document-php": "2.*"
"ivopetkov/html5-dom-document-php": "2.*",
"ivopetkov/client-shortcuts-bearframework-addon": "0.1.*"
},
"autoload": {
"files": ["autoload.php"]
Expand Down
15 changes: 15 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,20 @@
]
]);
};

$app->clientShortcuts
->add('-bearcms-embed-element-responsively-lazy', function(IvoPetkov\BearFrameworkAddons\ClientShortcut $shortcut) use ($context) {
$shortcut->requirements[] = [
'type' => 'file',
'url' => $context->assets->getURL('assets/responsivelyLazy.min.js', ['cacheMaxAge' => 999999999, 'version' => 2]),
'async' => true,
'mimeType' => 'text/javascript'
];
$shortcut->requirements[] = [
'type' => 'text',
'value' => '.responsively-lazy:not(img){position:relative;height:0;}.responsively-lazy:not(img)>img{position:absolute;top:0;left:0;width:100%;height:100%}img.responsively-lazy{width:100%;}',
'mimeType' => 'text/css'
];
});
};
});

0 comments on commit dcdc4e1

Please sign in to comment.