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:
parent
f67e6d01d9
commit
aba55f2a77
10 changed files with 15 additions and 40 deletions
|
|
@ -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;
|
||||
|
|
|
|||
8
app/javascript/packs/storiesList.js
Normal file
8
app/javascript/packs/storiesList.js
Normal 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 },
|
||||
}),
|
||||
);
|
||||
|
|
@ -90,5 +90,5 @@
|
|||
<%= render "articles/sidebar_additional" %>
|
||||
</div>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -56,4 +56,4 @@
|
|||
</main>
|
||||
<%= render "articles/search" %>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
|
|
|
|||
|
|
@ -24,4 +24,4 @@
|
|||
<%= render "organizations/sidebar_additional" %>
|
||||
</div>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@
|
|||
<%= render "podcast_episodes/sidebar_additional" %>
|
||||
</div>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@
|
|||
<%= render "podcast_episodes/sidebar_additional" %>
|
||||
</div>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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 %>
|
||||
|
|
|
|||
|
|
@ -158,4 +158,4 @@
|
|||
</main>
|
||||
</div>
|
||||
|
||||
<%= render "stories/stories_list_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "storiesList", defer: true %>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue