diff --git a/static/js/application.js b/static/js/application.js
index 6a2e883917..876a926ff3 100644
--- a/static/js/application.js
+++ b/static/js/application.js
@@ -52,11 +52,12 @@
function Navigation() {}
Navigation.bind = function() {
- var navigation;
+ var active, navigation;
if ($('#accordion').length) {
navigation = new Navigation;
+ active = $('#accordion ul:has(li.active)').index('#accordion ul');
$('#accordion').bind('accordionchange', navigation.log).accordion({
- active: $('#accordion ul:has(li.active)').index('#accordion ul'),
+ active: active >= 0 ? active : 1,
header: 'h3',
autoHeight: false
});
diff --git a/templates/coffee/spec/courseware_spec.coffee b/templates/coffee/spec/courseware_spec.coffee
index 5a5cabac0e..5933e3e686 100644
--- a/templates/coffee/spec/courseware_spec.coffee
+++ b/templates/coffee/spec/courseware_spec.coffee
@@ -12,14 +12,25 @@ describe 'Courseware', ->
describe 'bind', ->
describe 'when the #accordion exists', ->
- it 'activate the accordion with correct active section', ->
- spyOn $.fn, 'accordion'
- $('#accordion').append('
')
- Courseware.Navigation.bind()
- expect($('#accordion').accordion).toHaveBeenCalledWith
- active: 1
- header: 'h3'
- autoHeight: false
+ describe 'when there is an active section', ->
+ it 'activate the accordion with correct active section', ->
+ spyOn $.fn, 'accordion'
+ $('#accordion').append('')
+ Courseware.Navigation.bind()
+ expect($('#accordion').accordion).toHaveBeenCalledWith
+ active: 1
+ header: 'h3'
+ autoHeight: false
+
+ describe 'when there is no active section', ->
+ it 'activate the accordian with section 1 as active', ->
+ spyOn $.fn, 'accordion'
+ $('#accordion').append('')
+ Courseware.Navigation.bind()
+ expect($('#accordion').accordion).toHaveBeenCalledWith
+ active: 1
+ header: 'h3'
+ autoHeight: false
it 'binds the accordionchange event', ->
Courseware.Navigation.bind()
diff --git a/templates/coffee/spec/courseware_spec.js b/templates/coffee/spec/courseware_spec.js
index 195ea7b73b..7070fa0028 100644
--- a/templates/coffee/spec/courseware_spec.js
+++ b/templates/coffee/spec/courseware_spec.js
@@ -16,14 +16,28 @@
});
describe('bind', function() {
describe('when the #accordion exists', function() {
- it('activate the accordion with correct active section', function() {
- spyOn($.fn, 'accordion');
- $('#accordion').append('');
- Courseware.Navigation.bind();
- return expect($('#accordion').accordion).toHaveBeenCalledWith({
- active: 1,
- header: 'h3',
- autoHeight: false
+ describe('when there is an active section', function() {
+ return it('activate the accordion with correct active section', function() {
+ spyOn($.fn, 'accordion');
+ $('#accordion').append('');
+ Courseware.Navigation.bind();
+ return expect($('#accordion').accordion).toHaveBeenCalledWith({
+ active: 1,
+ header: 'h3',
+ autoHeight: false
+ });
+ });
+ });
+ describe('when there is no active section', function() {
+ return it('activate the accordian with section 1 as active', function() {
+ spyOn($.fn, 'accordion');
+ $('#accordion').append('');
+ Courseware.Navigation.bind();
+ return expect($('#accordion').accordion).toHaveBeenCalledWith({
+ active: 1,
+ header: 'h3',
+ autoHeight: false
+ });
});
});
it('binds the accordionchange event', function() {
diff --git a/templates/coffee/src/courseware.coffee b/templates/coffee/src/courseware.coffee
index 7772c1e533..a4c93ec0b4 100644
--- a/templates/coffee/src/courseware.coffee
+++ b/templates/coffee/src/courseware.coffee
@@ -6,8 +6,9 @@ class window.Courseware
@bind: ->
if $('#accordion').length
navigation = new Navigation
+ active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', navigation.log).accordion
- active: $('#accordion ul:has(li.active)').index('#accordion ul')
+ active: if active >= 0 then active else 1
header: 'h3'
autoHeight: false
$('#open_close_accordion a').click navigation.toggle