Skip to content

Commit

Permalink
next/prev button completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Junaid committed Feb 12, 2015
1 parent 3643d1f commit a98642a
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions lib/app/js/controllers/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ angular.module('sgApp')
});

function previousSection() {
var sections, result, mod;
var sections, result, mod, sec, i, m;
if (!Styleguide.sections.data) {
return;
}
Expand All @@ -28,18 +28,39 @@ angular.module('sgApp')
result = sections.filter(function(item) {
return reference === item.reference;
});

sec = result[0];
m = modifier;
if (result.length > 0) {
if (modifier <= 1) {
return false;
if (!modifier || modifier <= 1) {
if (sections.indexOf(result[0]) <= 0) {
return false;
} else {
i = sections.indexOf(result[0]) - 1;
for (i; i >= 0; i--) {
sec = sections[i];
if (sec.hasOwnProperty('modifiers')) {
if (sec.modifiers.length > 0) {
break;
} else if (sec.hasOwnProperty('markup') && sec.markup) {
return sec.reference;
}
}
}
if (sec.modifiers.length > 0) {
m = sec.modifiers.length + 1;
} else {
return false;
}
}
}
mod = result[0].reference + '-' + (parseInt(modifier) - 1);

mod = sec.reference + '-' + (parseInt(m) - 1);
}
return mod;
}

function nextSection() {
var sections, result, mod;
var sections, result, mod, sec, i, m;
if (!Styleguide.sections.data) {
return;
}
Expand All @@ -49,12 +70,32 @@ angular.module('sgApp')
result = sections.filter(function(item) {
return reference === item.reference;
});

sec = result[0];
m = modifier;
if (result.length > 0) {
if (modifier >= result[0].modifiers.length) {
return false;
if (!modifier || modifier >= sec.modifiers.length) {
if (sections.indexOf(result[0]) > sections.length) {
return false;
} else {
i = sections.indexOf(result[0]) + 1;
for (i; i < sections.length; i++) {
sec = sections[i];
if (sec.hasOwnProperty('modifiers')) {
if (sec.modifiers.length > 0) {
m = 0;
break;
} else if (sec.hasOwnProperty('markup') && sec.markup) {
return sec.reference;
}
}
}
if (sec.modifiers.length === 0) {
return false;
}
}
}
mod = result[0].reference + '-' + (parseInt(modifier) + 1);

mod = sec.reference + '-' + (parseInt(m) + 1);
}
return mod;
}
Expand Down

0 comments on commit a98642a

Please sign in to comment.