Default theme (JavaScript): Fix coding standard

This commit is contained in:
Daniel Rudolf 2016-08-02 23:42:48 +02:00
parent 518d9b5aef
commit d143105279
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538
3 changed files with 26 additions and 7 deletions

View file

@ -41,4 +41,15 @@
<rule ref="PSR2">
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
</rule>
<!--
The PHP-FIG PSR-2 Coding Style doesn't fully apply to JavaScript files
Furthermore, some sniffs aren't able to handle JavaScript peculiarities
-->
<rule ref="Generic.ControlStructures.InlineControlStructure">
<exclude-pattern>*.js</exclude-pattern>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration">
<exclude-pattern>*.js</exclude-pattern>
</rule>
</ruleset>

View file

@ -9,7 +9,8 @@
* @version 1.1
*/
function main() {
function main()
{
// capability CSS classes
document.documentElement.className = 'js';
@ -39,7 +40,9 @@ function main() {
if (menuToggle.getAttribute('aria-expanded') === 'false') {
menuToggle.setAttribute('aria-expanded', 'true');
utils.slideDown(menu, null, function () {
if (event.type === 'keydown') menu.focus();
if (event.type === 'keydown') {
menu.focus();
}
});
} else {
menuToggle.setAttribute('aria-expanded', 'false');

View file

@ -20,7 +20,8 @@ utils = {};
* to stop the iteration
* @return void
*/
utils.forEach = function (object, callback) {
utils.forEach = function (object, callback)
{
var i = 0,
keys = Object.keys(object),
length = keys.length;
@ -36,7 +37,8 @@ utils.forEach = function (object, callback) {
*
* @return boolean TRUE when the browser supports sliding, FALSE otherwise
*/
utils.canSlide = function () {
utils.canSlide = function ()
{
return (Modernizr.classlist && Modernizr.requestanimationframe && Modernizr.csstransitions);
};
@ -49,7 +51,8 @@ utils.canSlide = function () {
* @param function startCallback function to call when the animation starts
* @return void
*/
utils.slideUp = function (element, finishCallback, startCallback) {
utils.slideUp = function (element, finishCallback, startCallback)
{
if (!utils.canSlide()) {
if (startCallback) startCallback();
element.className += (element.className !== '') ? ' hidden' : 'hidden';
@ -96,7 +99,8 @@ utils.slideUp = function (element, finishCallback, startCallback) {
* @param function startCallback function to call when the animation starts
* @return void
*/
utils.slideDown = function (element, finishCallback, startCallback) {
utils.slideDown = function (element, finishCallback, startCallback)
{
if (!utils.canSlide()) {
if (startCallback) startCallback();
element.className = element.className.replace(/\bhidden\b */g, '');
@ -146,6 +150,7 @@ utils.slideDown = function (element, finishCallback, startCallback) {
* @param HTMLElement element the element to check
* @return boolean TRUE when the element is visible, FALSE otherwise
*/
utils.isElementVisible = function (element) {
utils.isElementVisible = function (element)
{
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
};