Skip to content

Commit

Permalink
feat: add scrollclass snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 26, 2023
1 parent c184414 commit 3b6f981
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Alfred.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@
$(document).on("keydown keyup", function (e) {
pressed = false;
$(".alfred").removeClass("alfred-disabled");
if ($hovered.closest(".alfredelements").length) return;
try {
if ($hovered.closest(".alfredelements").length) return;
} catch (error) {}
if (!e.shiftKey) return;
pressed = true;
let $alfred = $hovered.closest(".alfred");
Expand Down
9 changes: 7 additions & 2 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function getModuleInfo()
{
return [
'title' => 'RockFrontend',
'version' => '2.19.0',
'version' => '2.20.0',
'summary' => 'Module for easy frontend development',
'autoload' => true,
'singular' => true,
Expand Down Expand Up @@ -1928,7 +1928,7 @@ private function configSettings($inputfields)
$f = $this->wire->modules->get('InputfieldMarkup');
$f->entityEncodeText = false;
$f->label = 'Javascript Snippets';
$f->notes = 'To use snippets just add them to $rockfrontend->scripts()->add(...) in your main markup file.';
$f->notes = 'To use snippets just add them to $rockfrontend->scripts()->add("/url/to/script.js", "defer") in your main markup file.';
$f->wrapClass = 'script-checkboxes';
$f->value = '';
foreach ($this->wire->files->find(__DIR__ . "/scripts") as $script) {
Expand Down Expand Up @@ -2062,6 +2062,11 @@ private function downloadCDN()

private function drop($str)
{
$str = str_replace(
["/**\n", " * ", "\n */"],
"",
$str
);
return "<div class='uk-inline'>
<span uk-icon='info' class='uk-margin-small-left'></span>
<div class='uk-card uk-card-body uk-card-default' uk-drop>"
Expand Down
21 changes: 21 additions & 0 deletions scripts/rf-scrollclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Add/remove class on scroll position
* Usage:
* <a href='#' rf-scrollclass='show@300'>Add class "show" at 300px scrollposition</a>
*/
(function () {
let scrollElements = document.querySelectorAll("[rf-scrollclass]");
for (i = 0; i < scrollElements.length; i++) {
let el = scrollElements[i];
let attr = el.getAttribute("rf-scrollclass");
let parts = attr.split("@");
if (parts.length != 2) return;
let cls = parts[0];
let y = parts[1] * 1;
window.addEventListener("scroll", function () {
scrollpos = window.scrollY;
if (scrollpos >= y) el.classList.add(cls);
else el.classList.remove(cls);
});
}
})();
1 change: 1 addition & 0 deletions scripts/rf-scrollclass.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b6f981

Please sign in to comment.