1
|
|
|
Amarkal.settings.sections = { |
|
|
|
|
2
|
|
|
$links: null, |
3
|
|
|
$loader: null, |
4
|
|
|
data: null, |
5
|
|
|
activeSection: null, |
6
|
|
|
init: function() { |
7
|
|
|
this.data = JSON.parse($('#sections-config').text()); |
8
|
|
|
this.$links = $('.amarkal-settings-sections li'); |
9
|
|
|
this.$loader = $('#amarkal-settings-loader'); |
10
|
|
|
this.$form = $('#amarkal-settings-form'); |
11
|
|
|
this.$fields = this.$form.find('.amarkal-settings-field'); |
12
|
|
|
|
13
|
|
|
this.initSections(); |
14
|
|
|
}, |
15
|
|
|
initSections: function() { |
16
|
|
|
if(typeof this.data === 'object' && Object.keys(this.data).length > 0) { |
17
|
|
|
var _this = this; |
18
|
|
|
this.$links.on('click', function(){ |
19
|
|
|
_this.activate($(this).attr('data-slug')); |
20
|
|
|
}); |
21
|
|
|
this.activateInitialSection(); |
22
|
|
|
this.$loader.hide(); |
23
|
|
|
} |
24
|
|
|
else { |
25
|
|
|
Amarkal.settings.fields.showAll(); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
}, |
28
|
|
|
activateInitialSection: function() { |
29
|
|
|
if('' !== window.location.hash) { |
30
|
|
|
this.activate(window.location.hash.substring(1)); |
31
|
|
|
} |
32
|
|
|
else { |
33
|
|
|
this.activate($(this.$links[0]).attr('data-slug')); |
34
|
|
|
} |
35
|
|
|
}, |
36
|
|
|
activate: function(sectionSlug) { |
37
|
|
|
if(this.activeSection === sectionSlug) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
this.activeSection = sectionSlug; |
41
|
|
|
|
42
|
|
|
this.$links |
43
|
|
|
.removeClass('active') |
44
|
|
|
.filter('[data-slug="'+sectionSlug+'"]') |
45
|
|
|
.addClass('active'); |
46
|
|
|
|
47
|
|
|
Amarkal.settings.header.setSectionTitle(this.getTitle(sectionSlug)); |
|
|
|
|
48
|
|
|
Amarkal.settings.header.setSectionSubtitle(this.getSubtitle(sectionSlug)); |
49
|
|
|
Amarkal.settings.fields.hideAll(); |
50
|
|
|
Amarkal.settings.fields.show(this.getSectionFields(sectionSlug)); |
51
|
|
|
|
52
|
|
|
window.location = '#'+sectionSlug; |
53
|
|
|
}, |
54
|
|
|
deactivate: function() { |
55
|
|
|
var sectionSlug = this.activeSection; |
|
|
|
|
56
|
|
|
this.$links.removeClass('active'); |
57
|
|
|
Amarkal.settings.fields.hideAll(); |
|
|
|
|
58
|
|
|
this.activeSection = null; |
59
|
|
|
}, |
60
|
|
|
flag: function(type, slug) { |
61
|
|
|
this.$links.filter('[data-slug="'+slug+'"]').addClass('flag-'+type); |
62
|
|
|
}, |
63
|
|
|
unflag: function(type, slug) { |
64
|
|
|
this.$links.filter('[data-slug="'+slug+'"]').removeClass('flag-'+type); |
65
|
|
|
}, |
66
|
|
|
unflagAll: function() { |
67
|
|
|
this.$links.removeClass('flag-error flag-notice'); |
68
|
|
|
}, |
69
|
|
|
getTitle: function(slug) { |
70
|
|
|
return this.data[slug].title; |
71
|
|
|
}, |
72
|
|
|
getSubtitle: function(slug) { |
73
|
|
|
return this.data[slug].subtitle; |
74
|
|
|
}, |
75
|
|
|
getSectionFields: function(slug) { |
76
|
|
|
return this.$fields.filter('[data-section="'+slug+'"]'); |
77
|
|
|
}, |
78
|
|
|
changed: function(slug) { |
79
|
|
|
var changed = false; |
80
|
|
|
this.getSectionFields(slug).each(function(){ |
81
|
|
|
if($(this).find('.amarkal-ui-component').amarkalUIComponent('changed')) { |
|
|
|
|
82
|
|
|
changed = true; |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
}); |
86
|
|
|
return changed; |
87
|
|
|
} |
88
|
|
|
}; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.