|
@@ -30,10 +30,15 @@ http('http://192.168.1.127/api/products/listcategories').then(function(data) {
|
|
|
function logError(err) {
|
|
function logError(err) {
|
|
|
console.log('Error: ', err);
|
|
console.log('Error: ', err);
|
|
|
}
|
|
}
|
|
|
-var sections = [
|
|
|
|
|
- 'empresa',
|
|
|
|
|
- 'productos'
|
|
|
|
|
-];
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+var sections = [{
|
|
|
|
|
+ name: 'empresa',
|
|
|
|
|
+ view: true
|
|
|
|
|
+}, {
|
|
|
|
|
+ name: 'productos',
|
|
|
|
|
+ view: false
|
|
|
|
|
+}];
|
|
|
|
|
|
|
|
function fetchProducts(category) {
|
|
function fetchProducts(category) {
|
|
|
return new Promise(function(resolve, reject) {
|
|
return new Promise(function(resolve, reject) {
|
|
@@ -105,24 +110,20 @@ function getElement(selector) {
|
|
|
|
|
|
|
|
function chooseSection(section) {
|
|
function chooseSection(section) {
|
|
|
var navbarList = getElement('ul.navbar-list > li > a');
|
|
var navbarList = getElement('ul.navbar-list > li > a');
|
|
|
- addSelectedClass(navbarList, section, selectedSection_);
|
|
|
|
|
|
|
+ sections.forEach(function (s) {
|
|
|
|
|
+ var isSelected = s.name === section;
|
|
|
|
|
+ s.view = isSelected;
|
|
|
|
|
+ selectedSection_[s.name] = isSelected;
|
|
|
|
|
+ })
|
|
|
data.getSectionData[section]();
|
|
data.getSectionData[section]();
|
|
|
}
|
|
}
|
|
|
var elements = [];
|
|
var elements = [];
|
|
|
|
|
|
|
|
-function addSelectedClass(elemList, x, opt) {
|
|
|
|
|
|
|
+function addSelectedClass(elemList, x) {
|
|
|
elemList.forEach(function(el) {
|
|
elemList.forEach(function(el) {
|
|
|
var isSelected = el.text === x;
|
|
var isSelected = el.text === x;
|
|
|
el.className = isSelected ? 'selected' : '';
|
|
el.className = isSelected ? 'selected' : '';
|
|
|
- if (opt) {
|
|
|
|
|
- opt[el.text] = isSelected;
|
|
|
|
|
- }
|
|
|
|
|
})
|
|
})
|
|
|
- if (opt) {
|
|
|
|
|
- sections.forEach(function (s) {
|
|
|
|
|
- opt[s] = s === x;
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
window.onscroll = function() {
|
|
window.onscroll = function() {
|
|
@@ -152,7 +153,7 @@ function isInViewport(element) {
|
|
|
window.onload = function() {
|
|
window.onload = function() {
|
|
|
var section = window.location.hash.substr(1)
|
|
var section = window.location.hash.substr(1)
|
|
|
if (section !== '') {
|
|
if (section !== '') {
|
|
|
- chooseSection(section);
|
|
|
|
|
|
|
+ chooseSection(section, selectedSection_);
|
|
|
}
|
|
}
|
|
|
var view = rivets.bind(app, {
|
|
var view = rivets.bind(app, {
|
|
|
sections: sections,
|
|
sections: sections,
|
|
@@ -163,7 +164,7 @@ window.onload = function() {
|
|
|
selectSection: function(event, scope) {
|
|
selectSection: function(event, scope) {
|
|
|
var newValue = event.target.text;
|
|
var newValue = event.target.text;
|
|
|
window.history.pushState({}, newValue, '#' + newValue)
|
|
window.history.pushState({}, newValue, '#' + newValue)
|
|
|
- chooseSection(newValue);
|
|
|
|
|
|
|
+ chooseSection(newValue, selectedSection_);
|
|
|
event.target.className = 'selected';
|
|
event.target.className = 'selected';
|
|
|
},
|
|
},
|
|
|
selectCategory: function(event, scope) {
|
|
selectCategory: function(event, scope) {
|