1
0
mirror of https://github.com/picocms/pico-theme.git synced 2025-01-17 20:28:26 +01:00
php-pico-theme/js/pico.js
Daniel Rudolf e81eafcd68
Extract default theme from picocms/Pico repo
This repo is a copy of the picocms/Pico repo (https://github.com/picocms/Pico) at commit 82a342ba445122182b898a2c1800f03c8d16f18c with rewritten history. Only commits which are relevant for the themes/default/ directory (82a342ba44/themes/default/) were preserved. The command used to create this repo can be found at http://stackoverflow.com/a/37037151.

Pico is licensed under the MIT License (82a342ba44/LICENSE.md).
2017-05-01 18:56:54 +02:00

71 lines
2.3 KiB
JavaScript

/**
* Pico's Default Theme - JavaScript helper
*
* Pico is a stupidly simple, blazing fast, flat file CMS.
*
* @author Daniel Rudolf
* @link http://picocms.org
* @license http://opensource.org/licenses/MIT The MIT License
* @version 2.0
*/
function main()
{
// capability CSS classes
document.documentElement.className = 'js';
// wrap tables
var tables = document.querySelectorAll('#main > .container > table');
for (var i = 0; i < tables.length; i++) {
if (!/\btable-responsive\b/.test(tables[i].parentElement.className)) {
var tableWrapper = document.createElement('div');
tableWrapper.className = 'table-responsive';
tables[i].parentElement.insertBefore(tableWrapper, tables[i]);
tableWrapper.appendChild(tables[i]);
}
}
// responsive menu
var menu = document.getElementById('nav'),
menuToggle = document.getElementById('nav-toggle'),
toggleMenuEvent = function (event) {
if (event.type === 'keydown') {
if ((event.keyCode != 13) && (event.keyCode != 32)) {
return;
}
}
event.preventDefault();
if (menuToggle.getAttribute('aria-expanded') === 'false') {
menuToggle.setAttribute('aria-expanded', 'true');
utils.slideDown(menu, null, function () {
if (event.type === 'keydown') {
menu.focus();
}
});
} else {
menuToggle.setAttribute('aria-expanded', 'false');
utils.slideUp(menu);
}
},
onResizeEvent = function () {
if (utils.isElementVisible(menuToggle)) {
menu.className = 'hidden';
menuToggle.addEventListener('click', toggleMenuEvent);
menuToggle.addEventListener('keydown', toggleMenuEvent);
} else {
menu.className = '';
menu.removeAttribute('data-slide-id');
menuToggle.removeEventListener('click', toggleMenuEvent);
menuToggle.removeEventListener('keydown', toggleMenuEvent);
}
};
window.addEventListener('resize', onResizeEvent);
onResizeEvent();
}
main();