Skip to content

Commit

Permalink
Merge pull request #381 from m52go/move-js
Browse files Browse the repository at this point in the history
Separate javascript into page-specific files and remove unused code
m52go authored Aug 18, 2020
2 parents b7d1216 + ec7f8ea commit ede2115
Showing 6 changed files with 78 additions and 76 deletions.
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@
<script defer src="/js/jquery-3.3.1.min.js"></script>
<script defer src="/js/popper.min.js"></script>
<script defer src="/js/bootstrap.min.js"></script>
<script defer src="/js/scripts.js"></script>
<script defer src="/js/site.js"></script>

{% unless page.layout == "post" %}
<!-- Schema.org JSON-LD Markup for Search Engine Optimization -->
3 changes: 3 additions & 0 deletions _layouts/page_faq.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
layout: page
---

<script defer src="/js/faq.js"></script>

{% assign item = site.data[page.lang].faq %}
<div itemscope itemtype="https://schema.org/FAQPage">
<h1>{{ item.hFAQ }}</h1>
2 changes: 2 additions & 0 deletions _layouts/page_home.html
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
layout: default
---

<script defer src="/js/home.js"></script>

{% assign item = site.data[page.lang].homepage_content %}
<div class="container fadeIn">
<main class="bd-masthead" id="content" role="main">
56 changes: 56 additions & 0 deletions js/faq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$( document ).ready( function() {

//FAQ Accordion
$('.accordion').each(function() {

$(this).find('.accordion-toggle').click(function(event) {
event.preventDefault();

$(".accordion-toggle").not($(this)).removeClass('accordion-toggle-active');

if($(this).hasClass('accordion-toggle-active')){
$(this).removeClass('accordion-toggle-active');
}else{
$(this).addClass('accordion-toggle-active');
}

$(this).next().slideToggle('fast');
$(".accordion-content").not($(this).next()).slideUp('fast');

if($(this).attr('id') !== undefined) {
//add hash to url
if(history.pushState) {
history.pushState(null, null, '#' + $(this).attr('id'));
} else {
location.hash = '#' + $(this).attr('id');
}
}
});
});

if( window.location.hash ) {
showAccordionItem();
}

$( ".accordion-content a" ).on( "click", function() {
var address = $(this).attr('href');
if( address.charAt(0) === '#' ) {
showAccordionItem( address );
};
return;
});

function showAccordionItem( anchorAddress ) {

var address = anchorAddress ? anchorAddress : window.location.hash;

$("html, body").animate( {
scrollTop: ( $( address ).offset().top - 100 )
}, 1000 );

$( address ).addClass( 'accordion-toggle-active' ).next().slideToggle( 'fast' );

return;
}

});
78 changes: 3 additions & 75 deletions js/scripts.js → js/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$( document ).ready( function() {


/**************************************************
detect os to show correct download links
**************************************************/
@@ -55,10 +54,6 @@ $( document ).ready( function() {
}
});

$( '.dl-win64, .dl-mac, .dl-deb64, .dl-rpm64' ).on( 'click', function() {
sendAnalytic( $(this).attr('class').split('-').pop().split(" ").shift() );
});

//change dom to show downloads for the specific os
function showOSDownloads( os ) {
$( '.dl-' + os ).addClass( 'selected' );
@@ -72,20 +67,15 @@ $( document ).ready( function() {
downloadLink = downloadLink.replace( /<site_url_placeholder>/g, siteURL );
} else {
downloadLink = downloadLink.replace( /<bisq_version_placeholder>/g, bisqVersion );
sendAnalytic( osName );
}
location.href = downloadLink;
return;
}

//add virtual pageview and event tracking for download attempts
function sendAnalytic( platform ) {
ga( 'send', 'pageview', location.pathname + 'release' );
ga( 'send', 'event', 'Release Build', 'download', platform );
return;
}
/**************************************************
hover actions for the "how to get started" section
**************************************************/

//How to get started
$('.step').on({
mouseenter: function () {
$('.step').css('opacity', 0.5),
@@ -95,66 +85,4 @@ $( document ).ready( function() {
},
mouseout: function () {}
});


//FAQ Accordion
$('.accordion').each(function() {

$(this).find('.accordion-toggle').click(function(event) {
event.preventDefault();

$(".accordion-toggle").not($(this)).removeClass('accordion-toggle-active');

if($(this).hasClass('accordion-toggle-active')){
$(this).removeClass('accordion-toggle-active');
}else{
$(this).addClass('accordion-toggle-active');
}

$(this).next().slideToggle('fast');
$(".accordion-content").not($(this).next()).slideUp('fast');

if($(this).attr('id') !== undefined) {
//add hash to url
if(history.pushState) {
history.pushState(null, null, '#' + $(this).attr('id'));
} else {
location.hash = '#' + $(this).attr('id');
}
}
});
});

if( window.location.hash ) {
showAccordionItem();
}

$( ".accordion-content a" ).on( "click", function() {
var address = $(this).attr('href');
if( address.charAt(0) === '#' ) {
showAccordionItem( address );
};
return;
});

function showAccordionItem( anchorAddress ) {

var address = anchorAddress ? anchorAddress : window.location.hash;

$("html, body").animate( {
scrollTop: ( $( address ).offset().top - 100 )
}, 1000 );

$( address ).addClass( 'accordion-toggle-active' ).next().slideToggle( 'fast' );

return;
}


$( ".mode-toggle" ).on( "click", function() {
$("body").toggleClass("dark-mode");
$("body").hasClass("dark-mode") ? Cookies.set("darkmode", 1) : Cookies.set("darkmode", 0);
return;
});

});
13 changes: 13 additions & 0 deletions js/site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$( document ).ready( function() {

/**************************************************
dark mode toggle
**************************************************/

$( ".mode-toggle" ).on( "click", function() {
$("body").toggleClass("dark-mode");
$("body").hasClass("dark-mode") ? Cookies.set("darkmode", 1) : Cookies.set("darkmode", 0);
return;
});

});

0 comments on commit ede2115

Please sign in to comment.