Lint mozilla-accordion.js files

This commit is contained in:
alexgibson 2016-03-29 16:22:42 +01:00
Родитель b3603eda71
Коммит d7556d772b
4 изменённых файлов: 50 добавлений и 49 удалений

Просмотреть файл

@ -182,10 +182,10 @@ Global Settings
You can configure some appearance and behavior of the library by supplying custom values for the following. Custom values should generally be set prior to ``$(document).ready()``.
``Mozilla.Accordion.GLOBAL_ONEXPAND``
``Mozilla.Accordion.globalOnExpand``
A callback function to be fired every time any section in any pager is expanded. Will be passed the expanding ``Section`` object as an argument.
``Mozilla.Accordion.GLOBAL_ONCOLLAPSE``
``Mozilla.Accordion.globalOnCollapse``
A callback function to be fired every time any section in any pager is collapsed. Will be passed the collapsing ``Section`` object as an argument.
Styling

Просмотреть файл

@ -2,14 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Create namespace
if (typeof Mozilla === 'undefined') {
var Mozilla = {};
}
// Create namespace
if (typeof Mozilla === 'undefined') {
var Mozilla = {};
}
// If accordion is present, set up global GA functions
if (typeof Mozilla.Accordion === 'function') {
Mozilla.Accordion.GLOBAL_ONEXPAND = function(section) {
Mozilla.Accordion.globalOnExpand = function(section) {
// Google Analytics event tracking
window.dataLayer.push({
@ -20,7 +20,7 @@ if (typeof Mozilla.Accordion === 'function') {
});
};
Mozilla.Accordion.GLOBAL_ONCOLLAPSE = function(section) {
Mozilla.Accordion.globalOnCollapse = function(section) {
// Google Analytics event tracking
window.dataLayer.push({

Просмотреть файл

@ -155,36 +155,36 @@ Mozilla.Accordion = function Accordion($accordion, options) {
var len = sections.length;
switch (event.which) {
case 13: // Space
case 32: // Enter or Return
// Expand or close the section
section.toggle(true, true);
event.preventDefault();
break;
case 13: // Space
case 32: // Enter or Return
// Expand or close the section
section.toggle(true, true);
event.preventDefault();
break;
case 33: // Page Up
case 36: // Home
// Find the first section in the accordion
next = sections[0];
break;
case 33: // Page Up
case 36: // Home
// Find the first section in the accordion
next = sections[0];
break;
case 34: // Page Down
case 35: // End
// Find the last section in the accordion
next = sections[len - 1];
break;
case 34: // Page Down
case 35: // End
// Find the last section in the accordion
next = sections[len - 1];
break;
case 37: // Left Arrow
case 38: // Up Arrow
// Find the previous or last section in the accordion
next = sections[(index === 0) ? len - 1 : index - 1];
break;
case 37: // Left Arrow
case 38: // Up Arrow
// Find the previous or last section in the accordion
next = sections[(index === 0) ? len - 1 : index - 1];
break;
case 39: // Right Arrow
case 40: // Down Arrow
// Find the next or first section in the accordion
next = sections[(index === len - 1) ? 0 : index + 1];
break;
case 39: // Right Arrow
case 40: // Down Arrow
// Find the next or first section in the accordion
next = sections[(index === len - 1) ? 0 : index + 1];
break;
}
if (next) {
@ -233,8 +233,8 @@ Mozilla.Accordion = function Accordion($accordion, options) {
}
// If global expand listener is defined, call it.
if (typeof Mozilla.Accordion.GLOBAL_ONEXPAND === 'function') {
Mozilla.Accordion.GLOBAL_ONEXPAND(this);
if (typeof Mozilla.Accordion.globalOnExpand === 'function') {
Mozilla.Accordion.globalOnExpand(this);
}
// Fire a custom event on the panel
@ -268,8 +268,8 @@ Mozilla.Accordion = function Accordion($accordion, options) {
}
// If global collapse listener is defined, call it.
if (typeof Mozilla.Accordion.GLOBAL_ONCOLLAPSE === 'function') {
Mozilla.Accordion.GLOBAL_ONCOLLAPSE(this);
if (typeof Mozilla.Accordion.globalOnCollapse === 'function') {
Mozilla.Accordion.globalOnCollapse(this);
}
// Fire a custom event on the panel
@ -310,8 +310,8 @@ Mozilla.Accordion.currentAccordionId = 1;
Mozilla.Accordion.currentSectionId = 1;
Mozilla.Accordion.accordions = [];
Mozilla.Accordion.GLOBAL_ONCOLLAPSE = null;
Mozilla.Accordion.GLOBAL_ONEXPAND = null;
Mozilla.Accordion.globalOnCollapse = null;
Mozilla.Accordion.globalOnExpand = null;
Mozilla.Accordion.EVENT_NAMESPACE = 'mozaccordion'; // targeted event (un)binding
// {{{ createAccordions()
@ -434,7 +434,8 @@ Mozilla.Accordion.updateBeforeUnloadListener = function() {
Mozilla.Accordion.destroyAccordions = function() {
'use strict';
var accordionIds = [], i;
var accordionIds = [];
var i;
for (i = 0; i < Mozilla.Accordion.accordions.length; i++) {
accordionIds.push(Mozilla.Accordion.accordions[i].id);

Просмотреть файл

@ -194,30 +194,30 @@ describe('mozilla-accordion.js', function () {
it('should execute global expand and collapse callbacks', function() {
var expandReturn, collapseReturn;
Mozilla.Accordion.GLOBAL_ONEXPAND = function(section) {
Mozilla.Accordion.globalOnExpand = function(section) {
expandReturn = section.title;
};
Mozilla.Accordion.GLOBAL_ONCOLLAPSE = function(section) {
Mozilla.Accordion.globalOnCollapse = function(section) {
collapseReturn = section.title;
};
spyOn(Mozilla.Accordion, 'GLOBAL_ONEXPAND').and.callThrough();
spyOn(Mozilla.Accordion, 'GLOBAL_ONCOLLAPSE').and.callThrough();
spyOn(Mozilla.Accordion, 'globalOnExpand').and.callThrough();
spyOn(Mozilla.Accordion, 'globalOnCollapse').and.callThrough();
var accordion = new Mozilla.Accordion($('#accordion1'));
var $secondHeading = accordion.sections[1].$header;
$secondHeading.trigger('click');
expect(Mozilla.Accordion.GLOBAL_ONEXPAND).toHaveBeenCalled();
expect(Mozilla.Accordion.globalOnExpand).toHaveBeenCalled();
expect(expandReturn).toEqual(accordion.sections[1].title);
$secondHeading.trigger('click');
expect(Mozilla.Accordion.GLOBAL_ONCOLLAPSE).toHaveBeenCalled();
expect(Mozilla.Accordion.globalOnCollapse).toHaveBeenCalled();
expect(collapseReturn).toEqual(accordion.sections[1].title);
Mozilla.Accordion.GLOBAL_ONEXPAND = null;
Mozilla.Accordion.GLOBAL_ONCOLLAPSE = null;
Mozilla.Accordion.globalOnExpand = null;
Mozilla.Accordion.globalOnCollapse = null;
});
});
});