stories list script as separate js file - defer attribute (#13993)

* stories list script as separate js file - defer attribute

* change name storiesListScript for storiesList

* remove legacy function hasClass()

* add description to js pack

* remove case that triggers nothing

* Revert "remove case that triggers nothing"

 the if statement is on the element not its parents

This reverts commit f4402f5456e15da122f9820917f5965a1ebc50a4.

* remove deprecated code from storiesList pack

* remove unused code
This commit is contained in:
Julien Maury 2021-06-21 05:59:30 +02:00 committed by GitHub
parent f67e6d01d9
commit aba55f2a77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 40 deletions

View file

@ -289,10 +289,6 @@
position: relative;
@include dev-card;
&.active {
// TODO: what is this .active thingy?
opacity: 0.66;
}
&.single-article-small-pic {
vertical-align: top;
overflow: hidden;

View file

@ -0,0 +1,8 @@
/**
* @file A custom event that gets dispatched to notify search forms to synchronize their state.
*/
window.dispatchEvent(
new CustomEvent('syncSearchForms', {
detail: { querystring: location.search },
}),
);

View file

@ -90,5 +90,5 @@
<%= render "articles/sidebar_additional" %>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
<% end %>

View file

@ -56,4 +56,4 @@
</main>
<%= render "articles/search" %>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>

View file

@ -24,4 +24,4 @@
<%= render "organizations/sidebar_additional" %>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>

View file

@ -32,4 +32,4 @@
<%= render "podcast_episodes/sidebar_additional" %>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>

View file

@ -9,4 +9,4 @@
<%= render "podcast_episodes/sidebar_additional" %>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>

View file

@ -1,29 +0,0 @@
<script defer>
var isTouchDevice = ('ontouchstart' in window || navigator.maxTouchPoints > 0);
if (isTouchDevice) {
function hasClass(el, cls) {
return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className);
}
var activeLinks = document.getElementsByClassName('active');
Array.prototype.forEach.call(activeLinks, function (el) {
el.classList.remove("active");
});
document.getElementById('main-content').addEventListener('click', function (event) {
var clickedEl = event.target;
if (hasClass(clickedEl, "bm-initial") || hasClass(clickedEl, "bm-success")) {
//do nothing
} else if (hasClass(clickedEl.parentNode, "crayons-story")) {
clickedEl.parentNode.classList.add('active');
} else if (hasClass(clickedEl.parentNode.parentNode, "crayons-story")) {
clickedEl.parentNode.parentNode.classList.add('active');
} else if (hasClass(clickedEl.parentNode.parentNode.parentNode, "crayons-story")) {
clickedEl.parentNode.parentNode.parentNode.classList.add('active');
}
});
}
// A custom event that gets dispatched to notify search forms to synchronize their state.
window.dispatchEvent(new CustomEvent('syncSearchForms', { detail: { querystring: location.search } }));
</script>

View file

@ -113,5 +113,5 @@
<%= render "stories/tagged_articles/sidebar_additional" %>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
<% end %>

View file

@ -158,4 +158,4 @@
</main>
</div>
<%= render "stories/stories_list_script" %>
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>