Skip to content

Commit

Permalink
Renamed the new property (it's now negated). Added some selector cach…
Browse files Browse the repository at this point in the history
…ing. Re-added the 'toggleSpeed' var which had gone awol
  • Loading branch information
Barry McKay committed Jul 12, 2016
1 parent 5dee8f9 commit 687ff02
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ guide the learner’s interaction with the component.
>**_classes** (string): An optional class that will be applied to the Accordion Item.
**_preventItemAutoCollapse** (boolean): Used to prevent the auto-collapse of other expanded Accordion items whenever an item is clicked/expanded. Defaulted to 'false'
**_shouldCollapseItems** (boolean): Used to control the auto-collapse of other expanded Accordion items whenever an item is clicked/expanded. Defaulted to 'true'

### Accessibility
**Accordion** has been assigned a label using the [aria-label](https://github.com/adaptlearning/adapt_framework/wiki/Aria-Labels) attribute: **ariaRegion**. This label is not a visible element. It is utilized by assistive technology such as screen readers. Should the region's text need to be customised, it can be found within the **globals** object in [*properties.schema*](https://github.com/adaptlearning/adapt-contrib-accordion/blob/master/properties.schema).
Expand Down
35 changes: 23 additions & 12 deletions js/adapt-contrib-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ define(function(require) {
'click .accordion-item-title': 'toggleItem'
},

toggleSpeed: 200,

preRender: function() {
// Checks to see if the accordion should be reset on revisit
this.checkIfResetOnRevisit();
Expand Down Expand Up @@ -39,7 +41,7 @@ define(function(require) {
var accordionItem = toggleButton.parent('.accordion-item');
var isCurrentlyExpanded = toggleButton.hasClass('selected');

if (!this.model.get('_preventItemAutoCollapse')) {
if (this.model.get('_shouldCollapseItems')) {
// Close and reset all Accordion items
var allAccordionItems = this.$('.accordion-item');
var count = allAccordionItems.length;
Expand All @@ -61,29 +63,38 @@ define(function(require) {
return false;
}

$(itemEl).find('.accordion-item-body').first().stop(true, true).slideUp(this.toggleSpeed);
$(itemEl).find('button').first().removeClass('selected');
$(itemEl).find('button').first().attr('aria-expanded', false);
$(itemEl).find('.accordion-item-title-icon').first().addClass('icon-plus');
$(itemEl).find('.accordion-item-title-icon').first().removeClass('icon-minus');
var body = $('.accordion-item-body', $(itemEl)).first();
var button = $('button', $(itemEl)).first();
var icon = $('.accordion-item-title-icon', $(itemEl)).first();

body.stop(true, true).slideUp(this.toggleSpeed);
button.removeClass('selected');
button.attr('aria-expanded', false);
icon.addClass('icon-plus');
icon.removeClass('icon-minus');
},

openItem: function(itemEl) {
if (!itemEl) {
return false;
}

var body = $(itemEl).find('.accordion-item-body').first().stop(true, true).slideDown(this.toggleSpeed, function() {
var body = $('.accordion-item-body', $(itemEl)).first();
var button = $('button', $(itemEl)).first();
var icon = $('.accordion-item-title-icon', $(itemEl)).first();

body = body.stop(true, true).slideDown(this.toggleSpeed, function() {
body.a11y_focus();
});

$(itemEl).find('button').first().addClass('selected');
$(itemEl).find('button').first().attr('aria-expanded', true);
button.first().addClass('selected');
button.first().attr('aria-expanded', true);

this.setVisited(itemEl.index());
$(itemEl).find('button').first().addClass('visited');
$(itemEl).find('.accordion-item-title-icon').first().removeClass('icon-plus');
$(itemEl).find('.accordion-item-title-icon').first().addClass('icon-minus');
button.addClass('visited');

icon.removeClass('icon-plus');
icon.first().addClass('icon-minus');
},

setVisited: function(index) {
Expand Down
8 changes: 4 additions & 4 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@
}
}
},
"_preventItemAutoCollapse": {
"_shouldCollapseItems": {
"type": "boolean",
"required": false,
"default": false,
"title": "Prevent item auto-collapse",
"default": true,
"title": "Items should auto-collapse",
"inputType": {
"type": "Boolean",
"options": [true, false]
},
"validators": [],
"help": "If set to 'true', upon expansion of an accordion item, any previously expanded items will not be collapsed"
"help": "If set to 'false', upon expansion of an accordion item, any previously expanded items will not be collapsed"
}
}
}

0 comments on commit 687ff02

Please sign in to comment.