dot-hugo/assets/js/script.js

151 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-01-06 10:40:05 +00:00
(function ($) {
2019-09-04 11:35:48 +00:00
'use strict';
2019-01-06 10:40:05 +00:00
2019-09-04 11:35:48 +00:00
// Background-images
$('[data-background]').each(function () {
$(this).css({
'background-image': 'url(' + $(this).data('background') + ')'
2019-01-06 10:40:05 +00:00
});
2019-09-04 11:35:48 +00:00
});
2019-01-06 10:40:05 +00:00
2019-09-04 11:35:48 +00:00
// Accordions
$('.collapse').on('shown.bs.collapse', function () {
$(this).parent().find('.ti-plus').removeClass('ti-plus').addClass('ti-minus');
}).on('hidden.bs.collapse', function () {
$(this).parent().find('.ti-minus').removeClass('ti-minus').addClass('ti-plus');
});
// match height
$(function () {
$('.match-height').matchHeight({
byRow: true,
property: 'height',
target: null,
remove: false
2019-01-06 10:40:05 +00:00
});
2019-09-04 11:35:48 +00:00
});
// Get Parameters from some url
var getUrlParameter = function getUrlParameter(sPageURL) {
var url = sPageURL.split('?');
var obj = {};
if (url.length == 2) {
var sURLVariables = url[1].split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
obj[sParameterName[0]] = sParameterName[1];
}
return obj;
} else {
return undefined;
}
};
// Execute actions on images generated from Markdown pages
var images = $(".content img").not(".inline");
// Wrap image inside a featherlight (to get a full size view in a popup)
images.wrap(function () {
var image = $(this);
if (!image.parent("a").length) {
return "<a href='" + image[0].src + "' data-featherlight='image'></a>";
}
});
// Change styles, depending on parameters set to the image
images.each(function (index) {
var image = $(this)
var o = getUrlParameter(image[0].src);
if (typeof o !== "undefined") {
var h = o["height"];
var w = o["width"];
var c = o["classes"];
image.css("width", function () {
if (typeof w !== "undefined") {
return w;
} else {
return "auto";
}
});
image.css("height", function () {
if (typeof h !== "undefined") {
return h;
} else {
return "auto";
}
});
if (typeof c !== "undefined") {
var classes = c.split(',');
for (i = 0; i < classes.length; i++) {
image.addClass(classes[i]);
}
}
}
});
// tab
$('.tab-content').find('.tab-pane').each(function (idx, item) {
var navTabs = $(this).closest('.code-tabs').find('.nav-tabs'),
title = $(this).attr('title');
navTabs.append('<li class="nav-item"><a class="nav-link" href="#">' + title + '</a></li>');
});
$('.code-tabs ul.nav-tabs').each(function () {
$(this).find("li:first").addClass('active');
})
$('.code-tabs .tab-content').each(function () {
$(this).find("div:first").addClass('active');
});
$('.nav-tabs a').click(function (e) {
e.preventDefault();
var tab = $(this).parent(),
tabIndex = tab.index(),
tabPanel = $(this).closest('.code-tabs'),
tabPane = tabPanel.find('.tab-pane').eq(tabIndex);
tabPanel.find('.active').removeClass('active');
tab.addClass('active');
tabPane.addClass('active');
});
2019-01-06 10:40:05 +00:00
2020-04-05 06:48:34 +00:00
// search
$('#search').keyup(function () {
if (this.value) {
$(this).addClass('active')
} else {
$(this).removeClass('active')
}
})
$('#search').focusout(function () {
$(this).removeClass('active')
})
// Download page to pdf format
window.onload = function() {
var generatePDF = document.getElementById('generatePDF');
if (typeof(generatePDF) != 'undefined' && generatePDF != null) {
generatePDF.addEventListener("click", () => {
const content = this.document.getElementById("content");
console.log(content);
console.log(window);
var opt = {
margin: 1,
filename: document.querySelector('#title').innerHTML,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().from(content).set(opt).save();
})
}
})(jQuery);