sibu 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -20
- data/README.md +38 -38
- data/Rakefile +36 -36
- data/app/assets/config/sibu_manifest.js +2 -2
- data/app/assets/fonts/sibu/Sibu.eot +0 -0
- data/app/assets/fonts/sibu/Sibu.svg +13 -13
- data/app/assets/fonts/sibu/Sibu.ttf +0 -0
- data/app/assets/fonts/sibu/Sibu.woff +0 -0
- data/app/assets/javascripts/cropper/cropper.js +3694 -3694
- data/app/assets/javascripts/quill/quill.js +11401 -11401
- data/app/assets/javascripts/sibu/common.js +6 -6
- data/app/assets/javascripts/sibu/sibu.js.erb +155 -155
- data/app/assets/javascripts/tabs/van11y-accessible-tab-panel-aria.js +465 -465
- data/app/assets/stylesheets/cropper/cropper.css +304 -304
- data/app/assets/stylesheets/quill/quill.snow.css +945 -945
- data/app/assets/stylesheets/sibu/defaults.scss +336 -331
- data/app/assets/stylesheets/sibu/icons.scss +40 -40
- data/app/assets/stylesheets/sibu/sibu.css +131 -131
- data/app/controllers/sibu/application_controller.rb +14 -14
- data/app/controllers/sibu/documents_controller.rb +35 -35
- data/app/controllers/sibu/images_controller.rb +78 -78
- data/app/controllers/sibu/pages_controller.rb +197 -197
- data/app/controllers/sibu/sites_controller.rb +81 -81
- data/app/helpers/sibu/application_helper.rb +11 -11
- data/app/helpers/sibu/documents_helper.rb +4 -4
- data/app/helpers/sibu/images_helper.rb +4 -4
- data/app/helpers/sibu/pages_helper.rb +194 -194
- data/app/helpers/sibu/sites_helper.rb +23 -23
- data/app/jobs/sibu/application_job.rb +4 -4
- data/app/mailers/sibu/application_mailer.rb +6 -6
- data/app/models/concerns/sibu/document_uploader.rb +8 -8
- data/app/models/concerns/sibu/image_uploader.rb +31 -31
- data/app/models/concerns/sibu/sections_concern.rb +134 -134
- data/app/models/concerns/sibu/style_uploader.rb +1 -1
- data/app/models/concerns/sibu/user_concern.rb +8 -8
- data/app/models/sibu/application_record.rb +5 -5
- data/app/models/sibu/document.rb +16 -16
- data/app/models/sibu/dynamic_style.rb +76 -76
- data/app/models/sibu/image.rb +19 -19
- data/app/models/sibu/page.rb +66 -66
- data/app/models/sibu/site.rb +97 -97
- data/app/models/sibu/site_template.rb +22 -22
- data/app/views/layouts/sibu/application.html.erb +23 -23
- data/app/views/layouts/sibu/edit_content.html.erb +262 -262
- data/app/views/layouts/sibu/site.html.erb +45 -45
- data/app/views/sibu/documents/_form.html.erb +14 -14
- data/app/views/sibu/documents/index.html.erb +37 -37
- data/app/views/sibu/documents/new.html.erb +12 -12
- data/app/views/sibu/images/_edit_form.html.erb +23 -23
- data/app/views/sibu/images/_form.html.erb +34 -34
- data/app/views/sibu/images/edit.js.erb +2 -2
- data/app/views/sibu/images/index.html.erb +13 -13
- data/app/views/sibu/images/new.html.erb +12 -12
- data/app/views/sibu/images/show.html.erb +2 -2
- data/app/views/sibu/pages/_code_edit_panel.html.erb +17 -17
- data/app/views/sibu/pages/_element_actions.html.erb +4 -4
- data/app/views/sibu/pages/_error_panel.html.erb +4 -4
- data/app/views/sibu/pages/_form.html.erb +62 -62
- data/app/views/sibu/pages/_group_edit_panel.html.erb +3 -3
- data/app/views/sibu/pages/_link_edit_panel.html.erb +50 -50
- data/app/views/sibu/pages/_map_edit_panel.html.erb +27 -27
- data/app/views/sibu/pages/_media_edit_panel.html.erb +46 -46
- data/app/views/sibu/pages/_new_section_panel.html.erb +43 -43
- data/app/views/sibu/pages/_paragraph_edit_panel.html.erb +18 -18
- data/app/views/sibu/pages/_text_edit_panel.html.erb +19 -19
- data/app/views/sibu/pages/child_element.js.erb +6 -6
- data/app/views/sibu/pages/clone_element.js.erb +6 -6
- data/app/views/sibu/pages/create_section.js.erb +6 -6
- data/app/views/sibu/pages/delete_element.js.erb +6 -6
- data/app/views/sibu/pages/delete_section.js.erb +6 -6
- data/app/views/sibu/pages/destroy.html.erb +2 -2
- data/app/views/sibu/pages/edit.html.erb +8 -8
- data/app/views/sibu/pages/edit_content.html.erb +3 -3
- data/app/views/sibu/pages/edit_element.js.erb +100 -100
- data/app/views/sibu/pages/edit_section.js.erb +7 -7
- data/app/views/sibu/pages/index.html.erb +40 -40
- data/app/views/sibu/pages/new.html.erb +8 -8
- data/app/views/sibu/pages/new_section.js.erb +19 -19
- data/app/views/sibu/pages/show.html.erb +3 -3
- data/app/views/sibu/pages/update.html.erb +2 -2
- data/app/views/sibu/pages/update_element.js.erb +5 -5
- data/app/views/sibu/pages/update_section.js.erb +5 -5
- data/app/views/sibu/sites/_form.html.erb +125 -125
- data/app/views/sibu/sites/destroy.html.erb +2 -2
- data/app/views/sibu/sites/edit.html.erb +9 -9
- data/app/views/sibu/sites/edit_styles.html.erb +8 -8
- data/app/views/sibu/sites/index.html.erb +41 -41
- data/app/views/sibu/sites/new.html.erb +18 -18
- data/app/views/sibu/sites/update.html.erb +2 -2
- data/config/initializers/constants.rb +2 -2
- data/config/initializers/shrine.rb +18 -18
- data/config/routes.rb +30 -30
- data/config/tinymce.yml +5 -5
- data/db/migrate/20180124095041_create_sibu_sites.rb +12 -12
- data/db/migrate/20180124095213_create_sibu_pages.rb +15 -15
- data/db/migrate/20180124145030_create_sibu_site_templates.rb +10 -10
- data/db/migrate/20180125231638_add_user_id_to_sites.rb +5 -5
- data/db/migrate/20180126114522_rename_url_to_path_in_pages.rb +5 -5
- data/db/migrate/20180126114628_add_domain_to_sites.rb +5 -5
- data/db/migrate/20180127211533_create_sibu_images.rb +11 -11
- data/db/migrate/20180208082317_rename_images_user_id_to_site_id.rb +5 -5
- data/db/migrate/20180208125024_rename_image_data_column.rb +5 -5
- data/db/migrate/20180210181644_add_defaults_to_site_templates.rb +6 -6
- data/db/migrate/20180214134653_add_fields_to_sites.rb +5 -5
- data/db/migrate/20180227151519_add_default_templates_to_site_templates.rb +5 -5
- data/db/migrate/20180301121902_add_style_data_to_sites.rb +5 -5
- data/db/migrate/20180301152101_add_default_styles_to_templates.rb +5 -5
- data/db/migrate/20180321144021_move_images_to_user_level.rb +7 -7
- data/db/migrate/20180321170310_add_version_to_sibu_sites.rb +7 -7
- data/db/migrate/20180405095448_create_sibu_documents.rb +10 -10
- data/db/migrate/20190110204854_add_custom_data_to_sibu_pages.rb +5 -5
- data/lib/sibu.rb +4 -4
- data/lib/sibu/engine.rb +19 -19
- data/lib/sibu/utils.rb +14 -14
- data/lib/sibu/version.rb +3 -3
- data/lib/tasks/sibu_tasks.rake +4 -4
- metadata +3 -3
@@ -1,7 +1,7 @@
|
|
1
|
-
function sibuCallback(actionName, args) {
|
2
|
-
var callback = actionName + "SibuCallback";
|
3
|
-
console.log(callback);
|
4
|
-
if(typeof window[callback] === "function") {
|
5
|
-
window[callback](args);
|
6
|
-
}
|
1
|
+
function sibuCallback(actionName, args) {
|
2
|
+
var callback = actionName + "SibuCallback";
|
3
|
+
console.log(callback);
|
4
|
+
if(typeof window[callback] === "function") {
|
5
|
+
window[callback](args);
|
6
|
+
}
|
7
7
|
}
|
@@ -1,156 +1,156 @@
|
|
1
|
-
//= require jquery
|
2
|
-
//= require jquery_ujs
|
3
|
-
//= require sibu/common
|
4
|
-
//= require ../quill/quill
|
5
|
-
//= require ../tabs/van11y-accessible-tab-panel-aria
|
6
|
-
//= require_self
|
7
|
-
|
8
|
-
var Inline = Quill.import('blots/inline');
|
9
|
-
|
10
|
-
class IconBlot extends Inline {
|
11
|
-
static create(args) {
|
12
|
-
let node = super.create();
|
13
|
-
node.setAttribute('href', args[0]);
|
14
|
-
node.setAttribute('target', '_blank');
|
15
|
-
node.setAttribute('class', args[1]);
|
16
|
-
return node;
|
17
|
-
}
|
18
|
-
|
19
|
-
static formats(node) {
|
20
|
-
return node.getAttribute('href');
|
21
|
-
}
|
22
|
-
|
23
|
-
format(name, value) {
|
24
|
-
if (name !== this.statics.blotName || !value) return super.format(name, value);
|
25
|
-
this.domNode.setAttribute('href', value);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
IconBlot.blotName = 'icon';
|
29
|
-
IconBlot.tagName = 'a';
|
30
|
-
|
31
|
-
Quill.register(IconBlot);
|
32
|
-
Quill.register(Quill.import('attributors/style/align'), true);
|
33
|
-
|
34
|
-
var Link = Quill.import('formats/link');
|
35
|
-
|
36
|
-
class CustomLink extends Link {
|
37
|
-
static create(value) {
|
38
|
-
let node = super.create(value);
|
39
|
-
value = this.sanitize(value);
|
40
|
-
node.setAttribute('href', value);
|
41
|
-
if(value.startsWith("/")) {
|
42
|
-
node.removeAttribute('target');
|
43
|
-
}
|
44
|
-
return node;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
Quill.register(CustomLink);
|
49
|
-
|
50
|
-
function initQuillEditor(container) {
|
51
|
-
var quillModules;
|
52
|
-
var modulesCallback = "sibuEditorModules";
|
53
|
-
if(typeof window[modulesCallback] === "function") {
|
54
|
-
quillModules = window[modulesCallback]();
|
55
|
-
} else {
|
56
|
-
quillModules = {
|
57
|
-
toolbar: [
|
58
|
-
['bold', 'italic', 'underline'], ['link'],
|
59
|
-
[{ 'color': [] }, { 'background': [] }],
|
60
|
-
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
|
61
|
-
[{ 'align': [] }],
|
62
|
-
['facebook', 'twitter', 'instagram', 'pinterest'],
|
63
|
-
['clean']
|
64
|
-
]
|
65
|
-
};
|
66
|
-
}
|
67
|
-
var quill = new Quill(container, {
|
68
|
-
modules: quillModules,
|
69
|
-
theme: 'snow'
|
70
|
-
});
|
71
|
-
|
72
|
-
function promptWithInit(promptText) {
|
73
|
-
var range = quill.getSelection(true);
|
74
|
-
if(range && range.length === 0) {
|
75
|
-
quill.insertText(range.index, ' ', Quill.sources.USER);
|
76
|
-
quill.setSelection(range.index, 1, Quill.sources.USER);
|
77
|
-
}
|
78
|
-
return prompt(promptText);
|
79
|
-
}
|
80
|
-
|
81
|
-
var fbButton = document.querySelector('.ql-facebook');
|
82
|
-
if(fbButton) {
|
83
|
-
fbButton.addEventListener('click', function() {
|
84
|
-
var value = promptWithInit('Adresse de la page Facebook :');
|
85
|
-
quill.format('icon', [value, 'sb-facebook']);
|
86
|
-
});
|
87
|
-
}
|
88
|
-
var twButton = document.querySelector('.ql-twitter');
|
89
|
-
if(twButton) {
|
90
|
-
twButton.addEventListener('click', function() {
|
91
|
-
var value = promptWithInit('Adresse du compte Twitter :');
|
92
|
-
quill.format('icon', [value, 'sb-twitter']);
|
93
|
-
});
|
94
|
-
}
|
95
|
-
var igButton = document.querySelector('.ql-instagram');
|
96
|
-
if(igButton) {
|
97
|
-
igButton.addEventListener('click', function() {
|
98
|
-
var value = promptWithInit('Adresse du compte Instagram :');
|
99
|
-
quill.format('icon', [value, 'sb-instagram']);
|
100
|
-
});
|
101
|
-
}
|
102
|
-
var piButton = document.querySelector('.ql-pinterest');
|
103
|
-
if(piButton) {
|
104
|
-
piButton.addEventListener('click', function() {
|
105
|
-
var value = promptWithInit('Adresse du compte Pinterest :');
|
106
|
-
quill.format('icon', [value, 'sb-pinterest']);
|
107
|
-
});
|
108
|
-
}
|
109
|
-
|
110
|
-
return quill;
|
111
|
-
}
|
112
|
-
|
113
|
-
function initCustomCenter() {
|
114
|
-
var wrapper = $(".sibu_center > img"), centerPos = $(".sibu_center > #sibu_center_pos");
|
115
|
-
displayCurrentCenter(wrapper[0], centerPos);
|
116
|
-
wrapper.click(function(e) {
|
117
|
-
var rect = e.target.getBoundingClientRect();
|
118
|
-
var x = e.clientX - rect.left;
|
119
|
-
var y = e.clientY - rect.top;
|
120
|
-
centerPos.css("top", y + "px");
|
121
|
-
centerPos.css("left", x + "px");
|
122
|
-
$("#element_class").val(`posx_${Math.floor((x / rect.width) * 10) * 10} posy_${Math.floor((y / rect.height) * 10) * 10}`);
|
123
|
-
})
|
124
|
-
}
|
125
|
-
|
126
|
-
function displayCurrentCenter(img, centerPos) {
|
127
|
-
var val = $("#element_class").val();
|
128
|
-
var rect = img.getBoundingClientRect();
|
129
|
-
if (val && val.indexOf('posx') !== -1 && val.indexOf('posy') !== -1) {
|
130
|
-
var xpos = val.slice(val.indexOf("posx_") + 5, val.indexOf("posx_") + 7);
|
131
|
-
var ypos = val.slice(val.indexOf("posy_") + 5, val.indexOf("posy_") + 7);
|
132
|
-
centerPos.css("top", Math.round(+ypos * (rect.height / 100)) + "px");
|
133
|
-
centerPos.css("left", Math.round(+xpos * (rect.width / 100)) + "px");
|
134
|
-
} else {
|
135
|
-
centerPos.css("top", (Math.round(rect.height / 2) - 15) + "px");
|
136
|
-
centerPos.css("left", (Math.round(rect.width / 2) - 7) + "px");
|
137
|
-
}
|
138
|
-
centerPos.show();
|
139
|
-
}
|
140
|
-
|
141
|
-
function refreshAfterEdit(reload, sectionId) {
|
142
|
-
var baseUrl = window.location.href.split('?')[0];
|
143
|
-
if (reload) {
|
144
|
-
if (sectionId) {
|
145
|
-
window.location.href = baseUrl + '?edit_section=' + sectionId;
|
146
|
-
} else {
|
147
|
-
window.location.href = baseUrl;
|
148
|
-
}
|
149
|
-
} else {
|
150
|
-
window.history.replaceState(null, null, window.location.pathname);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
function initSectionsPanel() {
|
155
|
-
|
1
|
+
//= require jquery
|
2
|
+
//= require jquery_ujs
|
3
|
+
//= require sibu/common
|
4
|
+
//= require ../quill/quill
|
5
|
+
//= require ../tabs/van11y-accessible-tab-panel-aria
|
6
|
+
//= require_self
|
7
|
+
|
8
|
+
var Inline = Quill.import('blots/inline');
|
9
|
+
|
10
|
+
class IconBlot extends Inline {
|
11
|
+
static create(args) {
|
12
|
+
let node = super.create();
|
13
|
+
node.setAttribute('href', args[0]);
|
14
|
+
node.setAttribute('target', '_blank');
|
15
|
+
node.setAttribute('class', args[1]);
|
16
|
+
return node;
|
17
|
+
}
|
18
|
+
|
19
|
+
static formats(node) {
|
20
|
+
return node.getAttribute('href');
|
21
|
+
}
|
22
|
+
|
23
|
+
format(name, value) {
|
24
|
+
if (name !== this.statics.blotName || !value) return super.format(name, value);
|
25
|
+
this.domNode.setAttribute('href', value);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
IconBlot.blotName = 'icon';
|
29
|
+
IconBlot.tagName = 'a';
|
30
|
+
|
31
|
+
Quill.register(IconBlot);
|
32
|
+
Quill.register(Quill.import('attributors/style/align'), true);
|
33
|
+
|
34
|
+
var Link = Quill.import('formats/link');
|
35
|
+
|
36
|
+
class CustomLink extends Link {
|
37
|
+
static create(value) {
|
38
|
+
let node = super.create(value);
|
39
|
+
value = this.sanitize(value);
|
40
|
+
node.setAttribute('href', value);
|
41
|
+
if(value.startsWith("/")) {
|
42
|
+
node.removeAttribute('target');
|
43
|
+
}
|
44
|
+
return node;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
Quill.register(CustomLink);
|
49
|
+
|
50
|
+
function initQuillEditor(container) {
|
51
|
+
var quillModules;
|
52
|
+
var modulesCallback = "sibuEditorModules";
|
53
|
+
if(typeof window[modulesCallback] === "function") {
|
54
|
+
quillModules = window[modulesCallback]();
|
55
|
+
} else {
|
56
|
+
quillModules = {
|
57
|
+
toolbar: [
|
58
|
+
['bold', 'italic', 'underline'], ['link'],
|
59
|
+
[{ 'color': [] }, { 'background': [] }],
|
60
|
+
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
|
61
|
+
[{ 'align': [] }],
|
62
|
+
['facebook', 'twitter', 'instagram', 'pinterest'],
|
63
|
+
['clean']
|
64
|
+
]
|
65
|
+
};
|
66
|
+
}
|
67
|
+
var quill = new Quill(container, {
|
68
|
+
modules: quillModules,
|
69
|
+
theme: 'snow'
|
70
|
+
});
|
71
|
+
|
72
|
+
function promptWithInit(promptText) {
|
73
|
+
var range = quill.getSelection(true);
|
74
|
+
if(range && range.length === 0) {
|
75
|
+
quill.insertText(range.index, ' ', Quill.sources.USER);
|
76
|
+
quill.setSelection(range.index, 1, Quill.sources.USER);
|
77
|
+
}
|
78
|
+
return prompt(promptText);
|
79
|
+
}
|
80
|
+
|
81
|
+
var fbButton = document.querySelector('.ql-facebook');
|
82
|
+
if(fbButton) {
|
83
|
+
fbButton.addEventListener('click', function() {
|
84
|
+
var value = promptWithInit('Adresse de la page Facebook :');
|
85
|
+
quill.format('icon', [value, 'sb-facebook']);
|
86
|
+
});
|
87
|
+
}
|
88
|
+
var twButton = document.querySelector('.ql-twitter');
|
89
|
+
if(twButton) {
|
90
|
+
twButton.addEventListener('click', function() {
|
91
|
+
var value = promptWithInit('Adresse du compte Twitter :');
|
92
|
+
quill.format('icon', [value, 'sb-twitter']);
|
93
|
+
});
|
94
|
+
}
|
95
|
+
var igButton = document.querySelector('.ql-instagram');
|
96
|
+
if(igButton) {
|
97
|
+
igButton.addEventListener('click', function() {
|
98
|
+
var value = promptWithInit('Adresse du compte Instagram :');
|
99
|
+
quill.format('icon', [value, 'sb-instagram']);
|
100
|
+
});
|
101
|
+
}
|
102
|
+
var piButton = document.querySelector('.ql-pinterest');
|
103
|
+
if(piButton) {
|
104
|
+
piButton.addEventListener('click', function() {
|
105
|
+
var value = promptWithInit('Adresse du compte Pinterest :');
|
106
|
+
quill.format('icon', [value, 'sb-pinterest']);
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
return quill;
|
111
|
+
}
|
112
|
+
|
113
|
+
function initCustomCenter() {
|
114
|
+
var wrapper = $(".sibu_center > img"), centerPos = $(".sibu_center > #sibu_center_pos");
|
115
|
+
displayCurrentCenter(wrapper[0], centerPos);
|
116
|
+
wrapper.click(function(e) {
|
117
|
+
var rect = e.target.getBoundingClientRect();
|
118
|
+
var x = e.clientX - rect.left;
|
119
|
+
var y = e.clientY - rect.top;
|
120
|
+
centerPos.css("top", y + "px");
|
121
|
+
centerPos.css("left", x + "px");
|
122
|
+
$("#element_class").val(`posx_${Math.floor((x / rect.width) * 10) * 10} posy_${Math.floor((y / rect.height) * 10) * 10}`);
|
123
|
+
})
|
124
|
+
}
|
125
|
+
|
126
|
+
function displayCurrentCenter(img, centerPos) {
|
127
|
+
var val = $("#element_class").val();
|
128
|
+
var rect = img.getBoundingClientRect();
|
129
|
+
if (val && val.indexOf('posx') !== -1 && val.indexOf('posy') !== -1) {
|
130
|
+
var xpos = val.slice(val.indexOf("posx_") + 5, val.indexOf("posx_") + 7);
|
131
|
+
var ypos = val.slice(val.indexOf("posy_") + 5, val.indexOf("posy_") + 7);
|
132
|
+
centerPos.css("top", Math.round(+ypos * (rect.height / 100)) + "px");
|
133
|
+
centerPos.css("left", Math.round(+xpos * (rect.width / 100)) + "px");
|
134
|
+
} else {
|
135
|
+
centerPos.css("top", (Math.round(rect.height / 2) - 15) + "px");
|
136
|
+
centerPos.css("left", (Math.round(rect.width / 2) - 7) + "px");
|
137
|
+
}
|
138
|
+
centerPos.show();
|
139
|
+
}
|
140
|
+
|
141
|
+
function refreshAfterEdit(reload, sectionId) {
|
142
|
+
var baseUrl = window.location.href.split('?')[0];
|
143
|
+
if (reload) {
|
144
|
+
if (sectionId) {
|
145
|
+
window.location.href = baseUrl + '?edit_section=' + sectionId;
|
146
|
+
} else {
|
147
|
+
window.location.href = baseUrl;
|
148
|
+
}
|
149
|
+
} else {
|
150
|
+
window.history.replaceState(null, null, window.location.pathname);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
function initSectionsPanel() {
|
155
|
+
|
156
156
|
}
|
@@ -1,466 +1,466 @@
|
|
1
|
-
/*
|
2
|
-
* ES2015 accessible tabs panel system, using ARIA
|
3
|
-
* Website: https://van11y.net/accessible-tab-panel/
|
4
|
-
* License MIT: https://github.com/nico3333fr/van11y-accessible-tab-panel-aria/blob/master/LICENSE
|
5
|
-
*/
|
6
|
-
'use strict';
|
7
|
-
|
8
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
9
|
-
|
10
|
-
(function (doc) {
|
11
|
-
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var TABS_JS = 'js-tabs';
|
15
|
-
var TABS_JS_LIST = 'js-tablist';
|
16
|
-
var TABS_JS_LISTITEM = 'js-tablist__item';
|
17
|
-
var TABS_JS_LISTLINK = 'js-tablist__link';
|
18
|
-
var TABS_JS_CONTENT = 'js-tabcontent';
|
19
|
-
var TABS_JS_LINK_TO_TAB = 'js-link-to-tab';
|
20
|
-
|
21
|
-
var TABS_DATA_PREFIX_CLASS = 'data-tabs-prefix-class';
|
22
|
-
var TABS_DATA_HX = 'data-hx';
|
23
|
-
var TABS_DATA_GENERATED_HX_CLASS = 'data-tabs-generated-hx-class';
|
24
|
-
var TABS_DATA_EXISTING_HX = 'data-existing-hx';
|
25
|
-
|
26
|
-
var TABS_DATA_SELECTED_TAB = 'data-selected';
|
27
|
-
|
28
|
-
var TABS_PREFIX_IDS = 'label_';
|
29
|
-
|
30
|
-
var TABS_STYLE = 'tabs';
|
31
|
-
var TABS_LIST_STYLE = 'tabs__list';
|
32
|
-
var TABS_LISTITEM_STYLE = 'tabs__item';
|
33
|
-
var TABS_LINK_STYLE = 'tabs__link';
|
34
|
-
var TABS_CONTENT_STYLE = 'tabs__content';
|
35
|
-
|
36
|
-
var TABS_HX_DEFAULT_CLASS = 'invisible';
|
37
|
-
|
38
|
-
var TABS_ROLE_TABLIST = 'tablist';
|
39
|
-
var TABS_ROLE_TAB = 'tab';
|
40
|
-
var TABS_ROLE_TABPANEL = 'tabpanel';
|
41
|
-
var TABS_ROLE_PRESENTATION = 'presentation';
|
42
|
-
|
43
|
-
var ATTR_ROLE = 'role';
|
44
|
-
var ATTR_LABELLEDBY = 'aria-labelledby';
|
45
|
-
var ATTR_HIDDEN = 'aria-hidden';
|
46
|
-
var ATTR_CONTROLS = 'aria-controls';
|
47
|
-
var ATTR_SELECTED = 'aria-selected';
|
48
|
-
|
49
|
-
var DELAY_HASH_UPDATE = 1000;
|
50
|
-
|
51
|
-
var hash = window.location.hash.replace('#', '');
|
52
|
-
|
53
|
-
//const IS_OPENED_CLASS = 'is-opened';
|
54
|
-
|
55
|
-
var findById = function findById(id) {
|
56
|
-
return doc.getElementById(id);
|
57
|
-
};
|
58
|
-
|
59
|
-
var addClass = function addClass(el, className) {
|
60
|
-
if (el.classList) {
|
61
|
-
el.classList.add(className); // IE 10+
|
62
|
-
} else {
|
63
|
-
el.className += ' ' + className; // IE 8+
|
64
|
-
}
|
65
|
-
};
|
66
|
-
|
67
|
-
/*const removeClass = (el, className) => {
|
68
|
-
if (el.classList) {
|
69
|
-
el.classList.remove(className); // IE 10+
|
70
|
-
}
|
71
|
-
else {
|
72
|
-
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); // IE 8+
|
73
|
-
}
|
74
|
-
}*/
|
75
|
-
|
76
|
-
var hasClass = function hasClass(el, className) {
|
77
|
-
if (el.classList) {
|
78
|
-
return el.classList.contains(className); // IE 10+
|
79
|
-
} else {
|
80
|
-
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); // IE 8+ ?
|
81
|
-
}
|
82
|
-
};
|
83
|
-
|
84
|
-
var setAttributes = function setAttributes(node, attrs) {
|
85
|
-
Object.keys(attrs).forEach(function (attribute) {
|
86
|
-
node.setAttribute(attribute, attrs[attribute]);
|
87
|
-
});
|
88
|
-
};
|
89
|
-
var unSelectLinks = function unSelectLinks(elts) {
|
90
|
-
elts.forEach(function (link_node) {
|
91
|
-
var _setAttributes;
|
92
|
-
|
93
|
-
setAttributes(link_node, (_setAttributes = {}, _defineProperty(_setAttributes, ATTR_SELECTED, 'false'), _defineProperty(_setAttributes, 'tabindex', '-1'), _setAttributes));
|
94
|
-
});
|
95
|
-
};
|
96
|
-
var unSelectContents = function unSelectContents(elts) {
|
97
|
-
elts.forEach(function (content_node) {
|
98
|
-
content_node.setAttribute(ATTR_HIDDEN, true);
|
99
|
-
});
|
100
|
-
};
|
101
|
-
|
102
|
-
var selectLink = function selectLink(el) {
|
103
|
-
var _setAttributes2;
|
104
|
-
|
105
|
-
var destination = findById(el.getAttribute(ATTR_CONTROLS));
|
106
|
-
setAttributes(el, (_setAttributes2 = {}, _defineProperty(_setAttributes2, ATTR_SELECTED, 'true'), _defineProperty(_setAttributes2, 'tabindex', '0'), _setAttributes2));
|
107
|
-
destination.removeAttribute(ATTR_HIDDEN);
|
108
|
-
setTimeout(function () {
|
109
|
-
el.focus();
|
110
|
-
}, 0);
|
111
|
-
// Note : removed to prevent conflicts when editing sibu elements
|
112
|
-
// setTimeout(function () {
|
113
|
-
// history.pushState(null, null, location.pathname + location.search + '#' + el.getAttribute(ATTR_CONTROLS));
|
114
|
-
// }, DELAY_HASH_UPDATE);
|
115
|
-
};
|
116
|
-
|
117
|
-
var selectLinkInList = function selectLinkInList(itemsList, linkList, contentList, param) {
|
118
|
-
var indice_trouve = undefined;
|
119
|
-
|
120
|
-
itemsList.forEach(function (itemNode, index) {
|
121
|
-
if (itemNode.querySelector('.' + TABS_JS_LISTLINK).getAttribute(ATTR_SELECTED) === 'true') {
|
122
|
-
indice_trouve = index;
|
123
|
-
}
|
124
|
-
});
|
125
|
-
unSelectLinks(linkList);
|
126
|
-
unSelectContents(contentList);
|
127
|
-
if (param === 'next') {
|
128
|
-
selectLink(linkList[indice_trouve + 1]);
|
129
|
-
setTimeout(function () {
|
130
|
-
linkList[indice_trouve + 1].focus();
|
131
|
-
}, 0);
|
132
|
-
}
|
133
|
-
if (param === 'prev') {
|
134
|
-
selectLink(linkList[indice_trouve - 1]);
|
135
|
-
setTimeout(function () {
|
136
|
-
linkList[indice_trouve - 1].focus();
|
137
|
-
}, 0);
|
138
|
-
}
|
139
|
-
};
|
140
|
-
|
141
|
-
/* gets an element el, search if it is child of parent class, returns id of the parent */
|
142
|
-
var searchParent = function searchParent(el, parentClass) {
|
143
|
-
var found = false;
|
144
|
-
var parentElement = el.parentNode;
|
145
|
-
while (parentElement && found === false) {
|
146
|
-
if (hasClass(parentElement, parentClass) === true) {
|
147
|
-
found = true;
|
148
|
-
} else {
|
149
|
-
parentElement = parentElement.parentNode;
|
150
|
-
}
|
151
|
-
}
|
152
|
-
if (found === true) {
|
153
|
-
return parentElement.getAttribute('id');
|
154
|
-
} else {
|
155
|
-
return '';
|
156
|
-
}
|
157
|
-
};
|
158
|
-
|
159
|
-
/** Find all tabs inside a container
|
160
|
-
* @param {Node} node Default document
|
161
|
-
* @return {Array}
|
162
|
-
*/
|
163
|
-
var $listTabs = function $listTabs() {
|
164
|
-
var node = arguments.length <= 0 || arguments[0] === undefined ? doc : arguments[0];
|
165
|
-
return [].slice.call(node.querySelectorAll('.' + TABS_JS));
|
166
|
-
};
|
167
|
-
|
168
|
-
/**
|
169
|
-
* Build tooltips for a container
|
170
|
-
* @param {Node} node
|
171
|
-
*/
|
172
|
-
var attach = function attach(node) {
|
173
|
-
|
174
|
-
$listTabs(node).forEach(function (tabs_node) {
|
175
|
-
|
176
|
-
var iLisible = Math.random().toString(32).slice(2, 12);
|
177
|
-
var prefixClassName = tabs_node.hasAttribute(TABS_DATA_PREFIX_CLASS) === true ? tabs_node.getAttribute(TABS_DATA_PREFIX_CLASS) + '-' : '';
|
178
|
-
var hx = tabs_node.hasAttribute(TABS_DATA_HX) === true ? tabs_node.getAttribute(TABS_DATA_HX) : '';
|
179
|
-
var hxGeneratedClass = tabs_node.hasAttribute(TABS_DATA_GENERATED_HX_CLASS) === true ? tabs_node.getAttribute(TABS_DATA_GENERATED_HX_CLASS) : TABS_HX_DEFAULT_CLASS;
|
180
|
-
var existingHx = tabs_node.hasAttribute(TABS_DATA_EXISTING_HX) === true ? tabs_node.getAttribute(TABS_DATA_EXISTING_HX) : '';
|
181
|
-
var $tabList = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LIST));
|
182
|
-
var $tabListItems = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LISTITEM));
|
183
|
-
var $tabListLinks = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LISTLINK));
|
184
|
-
var $tabListPanels = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_CONTENT));
|
185
|
-
var noTabSelected = true;
|
186
|
-
|
187
|
-
// container
|
188
|
-
addClass(tabs_node, prefixClassName + TABS_STYLE);
|
189
|
-
tabs_node.setAttribute('id', TABS_STYLE + iLisible);
|
190
|
-
|
191
|
-
// ul
|
192
|
-
$tabList.forEach(function (tabList) {
|
193
|
-
var _setAttributes3;
|
194
|
-
|
195
|
-
addClass(tabList, prefixClassName + TABS_LIST_STYLE);
|
196
|
-
setAttributes(tabList, (_setAttributes3 = {}, _defineProperty(_setAttributes3, ATTR_ROLE, TABS_ROLE_TABLIST), _defineProperty(_setAttributes3, 'id', TABS_LIST_STYLE + iLisible), _setAttributes3));
|
197
|
-
});
|
198
|
-
// li
|
199
|
-
$tabListItems.forEach(function (tabListItem, index) {
|
200
|
-
var _setAttributes4;
|
201
|
-
|
202
|
-
addClass(tabListItem, prefixClassName + TABS_LISTITEM_STYLE);
|
203
|
-
setAttributes(tabListItem, (_setAttributes4 = {}, _defineProperty(_setAttributes4, ATTR_ROLE, TABS_ROLE_PRESENTATION), _defineProperty(_setAttributes4, 'id', TABS_LISTITEM_STYLE + iLisible + '-' + (index + 1)), _setAttributes4));
|
204
|
-
});
|
205
|
-
// a
|
206
|
-
$tabListLinks.forEach(function (tabListLink) {
|
207
|
-
var _setAttributes5, _setAttributes6;
|
208
|
-
|
209
|
-
var idHref = tabListLink.getAttribute("href").replace('#', '');
|
210
|
-
var panelControlled = findById(idHref);
|
211
|
-
var linkText = tabListLink.innerText;
|
212
|
-
var panelSelected = tabListLink.hasAttribute(TABS_DATA_SELECTED_TAB) === true;
|
213
|
-
|
214
|
-
addClass(tabListLink, prefixClassName + TABS_LINK_STYLE);
|
215
|
-
setAttributes(tabListLink, (_setAttributes5 = {
|
216
|
-
'id': TABS_PREFIX_IDS + idHref
|
217
|
-
}, _defineProperty(_setAttributes5, ATTR_ROLE, TABS_ROLE_TAB), _defineProperty(_setAttributes5, ATTR_CONTROLS, idHref), _defineProperty(_setAttributes5, 'tabindex', '-1'), _defineProperty(_setAttributes5, ATTR_SELECTED, 'false'), _setAttributes5));
|
218
|
-
|
219
|
-
// panel controlled
|
220
|
-
setAttributes(panelControlled, (_setAttributes6 = {}, _defineProperty(_setAttributes6, ATTR_HIDDEN, 'true'), _defineProperty(_setAttributes6, ATTR_ROLE, TABS_ROLE_TABPANEL), _defineProperty(_setAttributes6, ATTR_LABELLEDBY, TABS_PREFIX_IDS + idHref), _setAttributes6));
|
221
|
-
addClass(panelControlled, prefixClassName + TABS_CONTENT_STYLE);
|
222
|
-
|
223
|
-
// if already selected
|
224
|
-
if (panelSelected && noTabSelected) {
|
225
|
-
noTabSelected = false;
|
226
|
-
setAttributes(tabListLink, _defineProperty({
|
227
|
-
'tabindex': '0'
|
228
|
-
}, ATTR_SELECTED, 'true'));
|
229
|
-
setAttributes(panelControlled, _defineProperty({}, ATTR_HIDDEN, 'false'));
|
230
|
-
}
|
231
|
-
|
232
|
-
// hx
|
233
|
-
if (hx !== '') {
|
234
|
-
var hx_node = document.createElement(hx);
|
235
|
-
hx_node.setAttribute('class', hxGeneratedClass);
|
236
|
-
hx_node.setAttribute('tabindex', '0');
|
237
|
-
hx_node.innerHTML = linkText;
|
238
|
-
panelControlled.insertBefore(hx_node, panelControlled.firstChild);
|
239
|
-
}
|
240
|
-
// existingHx
|
241
|
-
|
242
|
-
if (existingHx !== '') {
|
243
|
-
var $hx_existing = [].slice.call(panelControlled.querySelectorAll(existingHx + ':first-child'));
|
244
|
-
$hx_existing.forEach(function (hx_item) {
|
245
|
-
hx_item.setAttribute('tabindex', '0');
|
246
|
-
});
|
247
|
-
}
|
248
|
-
|
249
|
-
tabListLink.removeAttribute('href');
|
250
|
-
});
|
251
|
-
|
252
|
-
if (hash !== '') {
|
253
|
-
var nodeHashed = findById(hash);
|
254
|
-
if (nodeHashed !== null) {
|
255
|
-
// just in case of an dumb error
|
256
|
-
// search if hash is current tabs_node
|
257
|
-
if (tabs_node.querySelector('#' + hash) !== null) {
|
258
|
-
// search if hash is ON tabs
|
259
|
-
if (hasClass(nodeHashed, TABS_JS_CONTENT) === true) {
|
260
|
-
// unselect others
|
261
|
-
unSelectLinks($tabListLinks);
|
262
|
-
unSelectContents($tabListPanels);
|
263
|
-
// select this one
|
264
|
-
nodeHashed.removeAttribute(ATTR_HIDDEN);
|
265
|
-
var linkHashed = findById(TABS_PREFIX_IDS + hash);
|
266
|
-
setAttributes(linkHashed, _defineProperty({
|
267
|
-
'tabindex': '0'
|
268
|
-
}, ATTR_SELECTED, 'true'));
|
269
|
-
noTabSelected = false;
|
270
|
-
} else {
|
271
|
-
// search if hash is IN tabs
|
272
|
-
var panelParentId = searchParent(nodeHashed, TABS_JS_CONTENT);
|
273
|
-
if (panelParentId !== '') {
|
274
|
-
// unselect others
|
275
|
-
unSelectLinks($tabListLinks);
|
276
|
-
unSelectContents($tabListPanels);
|
277
|
-
// select this one
|
278
|
-
var panelParent = findById(panelParentId);
|
279
|
-
panelParent.removeAttribute(ATTR_HIDDEN);
|
280
|
-
var linkParent = findById(TABS_PREFIX_IDS + panelParentId);
|
281
|
-
setAttributes(linkParent, _defineProperty({
|
282
|
-
'tabindex': '0'
|
283
|
-
}, ATTR_SELECTED, 'true'));
|
284
|
-
noTabSelected = false;
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}
|
288
|
-
}
|
289
|
-
}
|
290
|
-
|
291
|
-
// if no selected => select first
|
292
|
-
if (noTabSelected === true) {
|
293
|
-
setAttributes($tabListLinks[0], _defineProperty({
|
294
|
-
'tabindex': '0'
|
295
|
-
}, ATTR_SELECTED, 'true'));
|
296
|
-
var panelFirst = findById($tabListLinks[0].getAttribute(ATTR_CONTROLS));
|
297
|
-
panelFirst.removeAttribute(ATTR_HIDDEN);
|
298
|
-
}
|
299
|
-
});
|
300
|
-
};
|
301
|
-
|
302
|
-
/* listeners */
|
303
|
-
var bindListeners = function() {
|
304
|
-
['click', 'keydown'].forEach(function (eventName) {
|
305
|
-
//let isCtrl = false;
|
306
|
-
|
307
|
-
doc.body.addEventListener(eventName, function (e) {
|
308
|
-
|
309
|
-
// click on a tab link or on something IN a tab link
|
310
|
-
var parentLink = searchParent(e.target, TABS_JS_LISTLINK);
|
311
|
-
if ((hasClass(e.target, TABS_JS_LISTLINK) === true || parentLink !== '') && eventName === 'click') {
|
312
|
-
var linkSelected = hasClass(e.target, TABS_JS_LISTLINK) === true ? e.target : findById(parentLink);
|
313
|
-
var parentTabId = searchParent(e.target, TABS_JS);
|
314
|
-
var parentTab = findById(parentTabId);
|
315
|
-
//let $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
316
|
-
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
317
|
-
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
318
|
-
|
319
|
-
// aria selected false on all links
|
320
|
-
unSelectLinks($parentListLinks);
|
321
|
-
// add aria-hidden on all tabs contents
|
322
|
-
unSelectContents($parentListContents);
|
323
|
-
// add aria selected on selected link + show linked panel
|
324
|
-
selectLink(linkSelected);
|
325
|
-
|
326
|
-
e.preventDefault();
|
327
|
-
}
|
328
|
-
|
329
|
-
// Key down on tabs
|
330
|
-
if ((hasClass(e.target, TABS_JS_LISTLINK) === true || parentLink !== '') && eventName === 'keydown') {
|
331
|
-
//let linkSelected = hasClass( e.target, TABS_JS_LISTLINK) === true ? e.target : findById( parentLink );
|
332
|
-
var parentTabId = searchParent(e.target, TABS_JS);
|
333
|
-
var parentTab = findById(parentTabId);
|
334
|
-
var $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
335
|
-
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
336
|
-
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
337
|
-
var firstLink = $parentListItems[0].querySelector('.' + TABS_JS_LISTLINK);
|
338
|
-
var lastLink = $parentListItems[$parentListItems.length - 1].querySelector('.' + TABS_JS_LISTLINK);
|
339
|
-
|
340
|
-
// strike home on a tab => 1st tab
|
341
|
-
if (e.keyCode === 36) {
|
342
|
-
unSelectLinks($parentListLinks);
|
343
|
-
unSelectContents($parentListContents);
|
344
|
-
selectLink(firstLink);
|
345
|
-
|
346
|
-
e.preventDefault();
|
347
|
-
}
|
348
|
-
// strike end on a tab => last tab
|
349
|
-
else if (e.keyCode === 35) {
|
350
|
-
unSelectLinks($parentListLinks);
|
351
|
-
unSelectContents($parentListContents);
|
352
|
-
selectLink(lastLink);
|
353
|
-
|
354
|
-
e.preventDefault();
|
355
|
-
}
|
356
|
-
// strike up or left on the tab => previous tab
|
357
|
-
else if ((e.keyCode === 37 || e.keyCode === 38) && !e.ctrlKey) {
|
358
|
-
if (firstLink.getAttribute(ATTR_SELECTED) === 'true') {
|
359
|
-
unSelectLinks($parentListLinks);
|
360
|
-
unSelectContents($parentListContents);
|
361
|
-
selectLink(lastLink);
|
362
|
-
|
363
|
-
e.preventDefault();
|
364
|
-
} else {
|
365
|
-
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'prev');
|
366
|
-
e.preventDefault();
|
367
|
-
}
|
368
|
-
}
|
369
|
-
// strike down or right in the tab => next tab
|
370
|
-
else if ((e.keyCode === 40 || e.keyCode === 39) && !e.ctrlKey) {
|
371
|
-
if (lastLink.getAttribute(ATTR_SELECTED) === 'true') {
|
372
|
-
unSelectLinks($parentListLinks);
|
373
|
-
unSelectContents($parentListContents);
|
374
|
-
selectLink(firstLink);
|
375
|
-
|
376
|
-
e.preventDefault();
|
377
|
-
} else {
|
378
|
-
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'next');
|
379
|
-
e.preventDefault();
|
380
|
-
}
|
381
|
-
}
|
382
|
-
}
|
383
|
-
|
384
|
-
// Key down in tab panels
|
385
|
-
var parentTabPanelId = searchParent(e.target, TABS_JS_CONTENT);
|
386
|
-
if (parentTabPanelId !== '' && eventName === 'keydown') {
|
387
|
-
(function () {
|
388
|
-
var linkSelected = findById(findById(parentTabPanelId).getAttribute(ATTR_LABELLEDBY));
|
389
|
-
var parentTabId = searchParent(e.target, TABS_JS);
|
390
|
-
var parentTab = findById(parentTabId);
|
391
|
-
var $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
392
|
-
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
393
|
-
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
394
|
-
var firstLink = $parentListItems[0].querySelector('.' + TABS_JS_LISTLINK);
|
395
|
-
var lastLink = $parentListItems[$parentListItems.length - 1].querySelector('.' + TABS_JS_LISTLINK);
|
396
|
-
|
397
|
-
// strike up + ctrl => go to header
|
398
|
-
if (e.keyCode === 38 && e.ctrlKey) {
|
399
|
-
setTimeout(function () {
|
400
|
-
linkSelected.focus();
|
401
|
-
}, 0);
|
402
|
-
e.preventDefault();
|
403
|
-
}
|
404
|
-
// strike pageup + ctrl => go to prev header
|
405
|
-
if (e.keyCode === 33 && e.ctrlKey) {
|
406
|
-
// go to header
|
407
|
-
linkSelected.focus();
|
408
|
-
e.preventDefault();
|
409
|
-
// then previous
|
410
|
-
if (firstLink.getAttribute(ATTR_SELECTED) === 'true') {
|
411
|
-
unSelectLinks($parentListLinks);
|
412
|
-
unSelectContents($parentListContents);
|
413
|
-
selectLink(lastLink);
|
414
|
-
} else {
|
415
|
-
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'prev');
|
416
|
-
}
|
417
|
-
}
|
418
|
-
// strike pagedown + ctrl => go to next header
|
419
|
-
if (e.keyCode === 34 && e.ctrlKey) {
|
420
|
-
// go to header
|
421
|
-
linkSelected.focus();
|
422
|
-
e.preventDefault();
|
423
|
-
// then next
|
424
|
-
if (lastLink.getAttribute(ATTR_SELECTED) === 'true') {
|
425
|
-
unSelectLinks($parentListLinks);
|
426
|
-
unSelectContents($parentListContents);
|
427
|
-
selectLink(firstLink);
|
428
|
-
} else {
|
429
|
-
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'next');
|
430
|
-
}
|
431
|
-
}
|
432
|
-
})();
|
433
|
-
}
|
434
|
-
|
435
|
-
// click on a tab link
|
436
|
-
var parentLinkToPanelId = searchParent(e.target, TABS_JS_LINK_TO_TAB);
|
437
|
-
if ((hasClass(e.target, TABS_JS_LINK_TO_TAB) === true || parentLinkToPanelId !== '') && eventName === 'click') {
|
438
|
-
var panelSelectedId = hasClass(e.target, TABS_JS_LINK_TO_TAB) === true ? e.target.getAttribute('href').replace('#', '') : findById(parentLinkToPanelId).replace('#', '');
|
439
|
-
var panelSelected = findById(panelSelectedId);
|
440
|
-
var buttonPanelSelected = findById(panelSelected.getAttribute(ATTR_LABELLEDBY));
|
441
|
-
var parentTabId = searchParent(e.target, TABS_JS);
|
442
|
-
var parentTab = findById(parentTabId);
|
443
|
-
//let $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
444
|
-
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
445
|
-
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
446
|
-
|
447
|
-
unSelectLinks($parentListLinks);
|
448
|
-
unSelectContents($parentListContents);
|
449
|
-
selectLink(buttonPanelSelected);
|
450
|
-
|
451
|
-
e.preventDefault();
|
452
|
-
}
|
453
|
-
}, true);
|
454
|
-
});
|
455
|
-
};
|
456
|
-
|
457
|
-
var onLoad = function onLoad() {
|
458
|
-
attach();
|
459
|
-
bindListeners();
|
460
|
-
document.removeEventListener('DOMContentLoaded', onLoad);
|
461
|
-
};
|
462
|
-
|
463
|
-
document.addEventListener('DOMContentLoaded', onLoad);
|
464
|
-
|
465
|
-
window.van11yAccessibleTabPanelAria = attach;
|
1
|
+
/*
|
2
|
+
* ES2015 accessible tabs panel system, using ARIA
|
3
|
+
* Website: https://van11y.net/accessible-tab-panel/
|
4
|
+
* License MIT: https://github.com/nico3333fr/van11y-accessible-tab-panel-aria/blob/master/LICENSE
|
5
|
+
*/
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
9
|
+
|
10
|
+
(function (doc) {
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var TABS_JS = 'js-tabs';
|
15
|
+
var TABS_JS_LIST = 'js-tablist';
|
16
|
+
var TABS_JS_LISTITEM = 'js-tablist__item';
|
17
|
+
var TABS_JS_LISTLINK = 'js-tablist__link';
|
18
|
+
var TABS_JS_CONTENT = 'js-tabcontent';
|
19
|
+
var TABS_JS_LINK_TO_TAB = 'js-link-to-tab';
|
20
|
+
|
21
|
+
var TABS_DATA_PREFIX_CLASS = 'data-tabs-prefix-class';
|
22
|
+
var TABS_DATA_HX = 'data-hx';
|
23
|
+
var TABS_DATA_GENERATED_HX_CLASS = 'data-tabs-generated-hx-class';
|
24
|
+
var TABS_DATA_EXISTING_HX = 'data-existing-hx';
|
25
|
+
|
26
|
+
var TABS_DATA_SELECTED_TAB = 'data-selected';
|
27
|
+
|
28
|
+
var TABS_PREFIX_IDS = 'label_';
|
29
|
+
|
30
|
+
var TABS_STYLE = 'tabs';
|
31
|
+
var TABS_LIST_STYLE = 'tabs__list';
|
32
|
+
var TABS_LISTITEM_STYLE = 'tabs__item';
|
33
|
+
var TABS_LINK_STYLE = 'tabs__link';
|
34
|
+
var TABS_CONTENT_STYLE = 'tabs__content';
|
35
|
+
|
36
|
+
var TABS_HX_DEFAULT_CLASS = 'invisible';
|
37
|
+
|
38
|
+
var TABS_ROLE_TABLIST = 'tablist';
|
39
|
+
var TABS_ROLE_TAB = 'tab';
|
40
|
+
var TABS_ROLE_TABPANEL = 'tabpanel';
|
41
|
+
var TABS_ROLE_PRESENTATION = 'presentation';
|
42
|
+
|
43
|
+
var ATTR_ROLE = 'role';
|
44
|
+
var ATTR_LABELLEDBY = 'aria-labelledby';
|
45
|
+
var ATTR_HIDDEN = 'aria-hidden';
|
46
|
+
var ATTR_CONTROLS = 'aria-controls';
|
47
|
+
var ATTR_SELECTED = 'aria-selected';
|
48
|
+
|
49
|
+
var DELAY_HASH_UPDATE = 1000;
|
50
|
+
|
51
|
+
var hash = window.location.hash.replace('#', '');
|
52
|
+
|
53
|
+
//const IS_OPENED_CLASS = 'is-opened';
|
54
|
+
|
55
|
+
var findById = function findById(id) {
|
56
|
+
return doc.getElementById(id);
|
57
|
+
};
|
58
|
+
|
59
|
+
var addClass = function addClass(el, className) {
|
60
|
+
if (el.classList) {
|
61
|
+
el.classList.add(className); // IE 10+
|
62
|
+
} else {
|
63
|
+
el.className += ' ' + className; // IE 8+
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
/*const removeClass = (el, className) => {
|
68
|
+
if (el.classList) {
|
69
|
+
el.classList.remove(className); // IE 10+
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); // IE 8+
|
73
|
+
}
|
74
|
+
}*/
|
75
|
+
|
76
|
+
var hasClass = function hasClass(el, className) {
|
77
|
+
if (el.classList) {
|
78
|
+
return el.classList.contains(className); // IE 10+
|
79
|
+
} else {
|
80
|
+
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); // IE 8+ ?
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
var setAttributes = function setAttributes(node, attrs) {
|
85
|
+
Object.keys(attrs).forEach(function (attribute) {
|
86
|
+
node.setAttribute(attribute, attrs[attribute]);
|
87
|
+
});
|
88
|
+
};
|
89
|
+
var unSelectLinks = function unSelectLinks(elts) {
|
90
|
+
elts.forEach(function (link_node) {
|
91
|
+
var _setAttributes;
|
92
|
+
|
93
|
+
setAttributes(link_node, (_setAttributes = {}, _defineProperty(_setAttributes, ATTR_SELECTED, 'false'), _defineProperty(_setAttributes, 'tabindex', '-1'), _setAttributes));
|
94
|
+
});
|
95
|
+
};
|
96
|
+
var unSelectContents = function unSelectContents(elts) {
|
97
|
+
elts.forEach(function (content_node) {
|
98
|
+
content_node.setAttribute(ATTR_HIDDEN, true);
|
99
|
+
});
|
100
|
+
};
|
101
|
+
|
102
|
+
var selectLink = function selectLink(el) {
|
103
|
+
var _setAttributes2;
|
104
|
+
|
105
|
+
var destination = findById(el.getAttribute(ATTR_CONTROLS));
|
106
|
+
setAttributes(el, (_setAttributes2 = {}, _defineProperty(_setAttributes2, ATTR_SELECTED, 'true'), _defineProperty(_setAttributes2, 'tabindex', '0'), _setAttributes2));
|
107
|
+
destination.removeAttribute(ATTR_HIDDEN);
|
108
|
+
setTimeout(function () {
|
109
|
+
el.focus();
|
110
|
+
}, 0);
|
111
|
+
// Note : removed to prevent conflicts when editing sibu elements
|
112
|
+
// setTimeout(function () {
|
113
|
+
// history.pushState(null, null, location.pathname + location.search + '#' + el.getAttribute(ATTR_CONTROLS));
|
114
|
+
// }, DELAY_HASH_UPDATE);
|
115
|
+
};
|
116
|
+
|
117
|
+
var selectLinkInList = function selectLinkInList(itemsList, linkList, contentList, param) {
|
118
|
+
var indice_trouve = undefined;
|
119
|
+
|
120
|
+
itemsList.forEach(function (itemNode, index) {
|
121
|
+
if (itemNode.querySelector('.' + TABS_JS_LISTLINK).getAttribute(ATTR_SELECTED) === 'true') {
|
122
|
+
indice_trouve = index;
|
123
|
+
}
|
124
|
+
});
|
125
|
+
unSelectLinks(linkList);
|
126
|
+
unSelectContents(contentList);
|
127
|
+
if (param === 'next') {
|
128
|
+
selectLink(linkList[indice_trouve + 1]);
|
129
|
+
setTimeout(function () {
|
130
|
+
linkList[indice_trouve + 1].focus();
|
131
|
+
}, 0);
|
132
|
+
}
|
133
|
+
if (param === 'prev') {
|
134
|
+
selectLink(linkList[indice_trouve - 1]);
|
135
|
+
setTimeout(function () {
|
136
|
+
linkList[indice_trouve - 1].focus();
|
137
|
+
}, 0);
|
138
|
+
}
|
139
|
+
};
|
140
|
+
|
141
|
+
/* gets an element el, search if it is child of parent class, returns id of the parent */
|
142
|
+
var searchParent = function searchParent(el, parentClass) {
|
143
|
+
var found = false;
|
144
|
+
var parentElement = el.parentNode;
|
145
|
+
while (parentElement && found === false) {
|
146
|
+
if (hasClass(parentElement, parentClass) === true) {
|
147
|
+
found = true;
|
148
|
+
} else {
|
149
|
+
parentElement = parentElement.parentNode;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
if (found === true) {
|
153
|
+
return parentElement.getAttribute('id');
|
154
|
+
} else {
|
155
|
+
return '';
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
/** Find all tabs inside a container
|
160
|
+
* @param {Node} node Default document
|
161
|
+
* @return {Array}
|
162
|
+
*/
|
163
|
+
var $listTabs = function $listTabs() {
|
164
|
+
var node = arguments.length <= 0 || arguments[0] === undefined ? doc : arguments[0];
|
165
|
+
return [].slice.call(node.querySelectorAll('.' + TABS_JS));
|
166
|
+
};
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Build tooltips for a container
|
170
|
+
* @param {Node} node
|
171
|
+
*/
|
172
|
+
var attach = function attach(node) {
|
173
|
+
|
174
|
+
$listTabs(node).forEach(function (tabs_node) {
|
175
|
+
|
176
|
+
var iLisible = Math.random().toString(32).slice(2, 12);
|
177
|
+
var prefixClassName = tabs_node.hasAttribute(TABS_DATA_PREFIX_CLASS) === true ? tabs_node.getAttribute(TABS_DATA_PREFIX_CLASS) + '-' : '';
|
178
|
+
var hx = tabs_node.hasAttribute(TABS_DATA_HX) === true ? tabs_node.getAttribute(TABS_DATA_HX) : '';
|
179
|
+
var hxGeneratedClass = tabs_node.hasAttribute(TABS_DATA_GENERATED_HX_CLASS) === true ? tabs_node.getAttribute(TABS_DATA_GENERATED_HX_CLASS) : TABS_HX_DEFAULT_CLASS;
|
180
|
+
var existingHx = tabs_node.hasAttribute(TABS_DATA_EXISTING_HX) === true ? tabs_node.getAttribute(TABS_DATA_EXISTING_HX) : '';
|
181
|
+
var $tabList = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LIST));
|
182
|
+
var $tabListItems = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LISTITEM));
|
183
|
+
var $tabListLinks = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_LISTLINK));
|
184
|
+
var $tabListPanels = [].slice.call(tabs_node.querySelectorAll('.' + TABS_JS_CONTENT));
|
185
|
+
var noTabSelected = true;
|
186
|
+
|
187
|
+
// container
|
188
|
+
addClass(tabs_node, prefixClassName + TABS_STYLE);
|
189
|
+
tabs_node.setAttribute('id', TABS_STYLE + iLisible);
|
190
|
+
|
191
|
+
// ul
|
192
|
+
$tabList.forEach(function (tabList) {
|
193
|
+
var _setAttributes3;
|
194
|
+
|
195
|
+
addClass(tabList, prefixClassName + TABS_LIST_STYLE);
|
196
|
+
setAttributes(tabList, (_setAttributes3 = {}, _defineProperty(_setAttributes3, ATTR_ROLE, TABS_ROLE_TABLIST), _defineProperty(_setAttributes3, 'id', TABS_LIST_STYLE + iLisible), _setAttributes3));
|
197
|
+
});
|
198
|
+
// li
|
199
|
+
$tabListItems.forEach(function (tabListItem, index) {
|
200
|
+
var _setAttributes4;
|
201
|
+
|
202
|
+
addClass(tabListItem, prefixClassName + TABS_LISTITEM_STYLE);
|
203
|
+
setAttributes(tabListItem, (_setAttributes4 = {}, _defineProperty(_setAttributes4, ATTR_ROLE, TABS_ROLE_PRESENTATION), _defineProperty(_setAttributes4, 'id', TABS_LISTITEM_STYLE + iLisible + '-' + (index + 1)), _setAttributes4));
|
204
|
+
});
|
205
|
+
// a
|
206
|
+
$tabListLinks.forEach(function (tabListLink) {
|
207
|
+
var _setAttributes5, _setAttributes6;
|
208
|
+
|
209
|
+
var idHref = tabListLink.getAttribute("href").replace('#', '');
|
210
|
+
var panelControlled = findById(idHref);
|
211
|
+
var linkText = tabListLink.innerText;
|
212
|
+
var panelSelected = tabListLink.hasAttribute(TABS_DATA_SELECTED_TAB) === true;
|
213
|
+
|
214
|
+
addClass(tabListLink, prefixClassName + TABS_LINK_STYLE);
|
215
|
+
setAttributes(tabListLink, (_setAttributes5 = {
|
216
|
+
'id': TABS_PREFIX_IDS + idHref
|
217
|
+
}, _defineProperty(_setAttributes5, ATTR_ROLE, TABS_ROLE_TAB), _defineProperty(_setAttributes5, ATTR_CONTROLS, idHref), _defineProperty(_setAttributes5, 'tabindex', '-1'), _defineProperty(_setAttributes5, ATTR_SELECTED, 'false'), _setAttributes5));
|
218
|
+
|
219
|
+
// panel controlled
|
220
|
+
setAttributes(panelControlled, (_setAttributes6 = {}, _defineProperty(_setAttributes6, ATTR_HIDDEN, 'true'), _defineProperty(_setAttributes6, ATTR_ROLE, TABS_ROLE_TABPANEL), _defineProperty(_setAttributes6, ATTR_LABELLEDBY, TABS_PREFIX_IDS + idHref), _setAttributes6));
|
221
|
+
addClass(panelControlled, prefixClassName + TABS_CONTENT_STYLE);
|
222
|
+
|
223
|
+
// if already selected
|
224
|
+
if (panelSelected && noTabSelected) {
|
225
|
+
noTabSelected = false;
|
226
|
+
setAttributes(tabListLink, _defineProperty({
|
227
|
+
'tabindex': '0'
|
228
|
+
}, ATTR_SELECTED, 'true'));
|
229
|
+
setAttributes(panelControlled, _defineProperty({}, ATTR_HIDDEN, 'false'));
|
230
|
+
}
|
231
|
+
|
232
|
+
// hx
|
233
|
+
if (hx !== '') {
|
234
|
+
var hx_node = document.createElement(hx);
|
235
|
+
hx_node.setAttribute('class', hxGeneratedClass);
|
236
|
+
hx_node.setAttribute('tabindex', '0');
|
237
|
+
hx_node.innerHTML = linkText;
|
238
|
+
panelControlled.insertBefore(hx_node, panelControlled.firstChild);
|
239
|
+
}
|
240
|
+
// existingHx
|
241
|
+
|
242
|
+
if (existingHx !== '') {
|
243
|
+
var $hx_existing = [].slice.call(panelControlled.querySelectorAll(existingHx + ':first-child'));
|
244
|
+
$hx_existing.forEach(function (hx_item) {
|
245
|
+
hx_item.setAttribute('tabindex', '0');
|
246
|
+
});
|
247
|
+
}
|
248
|
+
|
249
|
+
tabListLink.removeAttribute('href');
|
250
|
+
});
|
251
|
+
|
252
|
+
if (hash !== '') {
|
253
|
+
var nodeHashed = findById(hash);
|
254
|
+
if (nodeHashed !== null) {
|
255
|
+
// just in case of an dumb error
|
256
|
+
// search if hash is current tabs_node
|
257
|
+
if (tabs_node.querySelector('#' + hash) !== null) {
|
258
|
+
// search if hash is ON tabs
|
259
|
+
if (hasClass(nodeHashed, TABS_JS_CONTENT) === true) {
|
260
|
+
// unselect others
|
261
|
+
unSelectLinks($tabListLinks);
|
262
|
+
unSelectContents($tabListPanels);
|
263
|
+
// select this one
|
264
|
+
nodeHashed.removeAttribute(ATTR_HIDDEN);
|
265
|
+
var linkHashed = findById(TABS_PREFIX_IDS + hash);
|
266
|
+
setAttributes(linkHashed, _defineProperty({
|
267
|
+
'tabindex': '0'
|
268
|
+
}, ATTR_SELECTED, 'true'));
|
269
|
+
noTabSelected = false;
|
270
|
+
} else {
|
271
|
+
// search if hash is IN tabs
|
272
|
+
var panelParentId = searchParent(nodeHashed, TABS_JS_CONTENT);
|
273
|
+
if (panelParentId !== '') {
|
274
|
+
// unselect others
|
275
|
+
unSelectLinks($tabListLinks);
|
276
|
+
unSelectContents($tabListPanels);
|
277
|
+
// select this one
|
278
|
+
var panelParent = findById(panelParentId);
|
279
|
+
panelParent.removeAttribute(ATTR_HIDDEN);
|
280
|
+
var linkParent = findById(TABS_PREFIX_IDS + panelParentId);
|
281
|
+
setAttributes(linkParent, _defineProperty({
|
282
|
+
'tabindex': '0'
|
283
|
+
}, ATTR_SELECTED, 'true'));
|
284
|
+
noTabSelected = false;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
// if no selected => select first
|
292
|
+
if (noTabSelected === true) {
|
293
|
+
setAttributes($tabListLinks[0], _defineProperty({
|
294
|
+
'tabindex': '0'
|
295
|
+
}, ATTR_SELECTED, 'true'));
|
296
|
+
var panelFirst = findById($tabListLinks[0].getAttribute(ATTR_CONTROLS));
|
297
|
+
panelFirst.removeAttribute(ATTR_HIDDEN);
|
298
|
+
}
|
299
|
+
});
|
300
|
+
};
|
301
|
+
|
302
|
+
/* listeners */
|
303
|
+
var bindListeners = function() {
|
304
|
+
['click', 'keydown'].forEach(function (eventName) {
|
305
|
+
//let isCtrl = false;
|
306
|
+
|
307
|
+
doc.body.addEventListener(eventName, function (e) {
|
308
|
+
|
309
|
+
// click on a tab link or on something IN a tab link
|
310
|
+
var parentLink = searchParent(e.target, TABS_JS_LISTLINK);
|
311
|
+
if ((hasClass(e.target, TABS_JS_LISTLINK) === true || parentLink !== '') && eventName === 'click') {
|
312
|
+
var linkSelected = hasClass(e.target, TABS_JS_LISTLINK) === true ? e.target : findById(parentLink);
|
313
|
+
var parentTabId = searchParent(e.target, TABS_JS);
|
314
|
+
var parentTab = findById(parentTabId);
|
315
|
+
//let $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
316
|
+
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
317
|
+
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
318
|
+
|
319
|
+
// aria selected false on all links
|
320
|
+
unSelectLinks($parentListLinks);
|
321
|
+
// add aria-hidden on all tabs contents
|
322
|
+
unSelectContents($parentListContents);
|
323
|
+
// add aria selected on selected link + show linked panel
|
324
|
+
selectLink(linkSelected);
|
325
|
+
|
326
|
+
e.preventDefault();
|
327
|
+
}
|
328
|
+
|
329
|
+
// Key down on tabs
|
330
|
+
if ((hasClass(e.target, TABS_JS_LISTLINK) === true || parentLink !== '') && eventName === 'keydown') {
|
331
|
+
//let linkSelected = hasClass( e.target, TABS_JS_LISTLINK) === true ? e.target : findById( parentLink );
|
332
|
+
var parentTabId = searchParent(e.target, TABS_JS);
|
333
|
+
var parentTab = findById(parentTabId);
|
334
|
+
var $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
335
|
+
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
336
|
+
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
337
|
+
var firstLink = $parentListItems[0].querySelector('.' + TABS_JS_LISTLINK);
|
338
|
+
var lastLink = $parentListItems[$parentListItems.length - 1].querySelector('.' + TABS_JS_LISTLINK);
|
339
|
+
|
340
|
+
// strike home on a tab => 1st tab
|
341
|
+
if (e.keyCode === 36) {
|
342
|
+
unSelectLinks($parentListLinks);
|
343
|
+
unSelectContents($parentListContents);
|
344
|
+
selectLink(firstLink);
|
345
|
+
|
346
|
+
e.preventDefault();
|
347
|
+
}
|
348
|
+
// strike end on a tab => last tab
|
349
|
+
else if (e.keyCode === 35) {
|
350
|
+
unSelectLinks($parentListLinks);
|
351
|
+
unSelectContents($parentListContents);
|
352
|
+
selectLink(lastLink);
|
353
|
+
|
354
|
+
e.preventDefault();
|
355
|
+
}
|
356
|
+
// strike up or left on the tab => previous tab
|
357
|
+
else if ((e.keyCode === 37 || e.keyCode === 38) && !e.ctrlKey) {
|
358
|
+
if (firstLink.getAttribute(ATTR_SELECTED) === 'true') {
|
359
|
+
unSelectLinks($parentListLinks);
|
360
|
+
unSelectContents($parentListContents);
|
361
|
+
selectLink(lastLink);
|
362
|
+
|
363
|
+
e.preventDefault();
|
364
|
+
} else {
|
365
|
+
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'prev');
|
366
|
+
e.preventDefault();
|
367
|
+
}
|
368
|
+
}
|
369
|
+
// strike down or right in the tab => next tab
|
370
|
+
else if ((e.keyCode === 40 || e.keyCode === 39) && !e.ctrlKey) {
|
371
|
+
if (lastLink.getAttribute(ATTR_SELECTED) === 'true') {
|
372
|
+
unSelectLinks($parentListLinks);
|
373
|
+
unSelectContents($parentListContents);
|
374
|
+
selectLink(firstLink);
|
375
|
+
|
376
|
+
e.preventDefault();
|
377
|
+
} else {
|
378
|
+
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'next');
|
379
|
+
e.preventDefault();
|
380
|
+
}
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
// Key down in tab panels
|
385
|
+
var parentTabPanelId = searchParent(e.target, TABS_JS_CONTENT);
|
386
|
+
if (parentTabPanelId !== '' && eventName === 'keydown') {
|
387
|
+
(function () {
|
388
|
+
var linkSelected = findById(findById(parentTabPanelId).getAttribute(ATTR_LABELLEDBY));
|
389
|
+
var parentTabId = searchParent(e.target, TABS_JS);
|
390
|
+
var parentTab = findById(parentTabId);
|
391
|
+
var $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
392
|
+
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
393
|
+
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
394
|
+
var firstLink = $parentListItems[0].querySelector('.' + TABS_JS_LISTLINK);
|
395
|
+
var lastLink = $parentListItems[$parentListItems.length - 1].querySelector('.' + TABS_JS_LISTLINK);
|
396
|
+
|
397
|
+
// strike up + ctrl => go to header
|
398
|
+
if (e.keyCode === 38 && e.ctrlKey) {
|
399
|
+
setTimeout(function () {
|
400
|
+
linkSelected.focus();
|
401
|
+
}, 0);
|
402
|
+
e.preventDefault();
|
403
|
+
}
|
404
|
+
// strike pageup + ctrl => go to prev header
|
405
|
+
if (e.keyCode === 33 && e.ctrlKey) {
|
406
|
+
// go to header
|
407
|
+
linkSelected.focus();
|
408
|
+
e.preventDefault();
|
409
|
+
// then previous
|
410
|
+
if (firstLink.getAttribute(ATTR_SELECTED) === 'true') {
|
411
|
+
unSelectLinks($parentListLinks);
|
412
|
+
unSelectContents($parentListContents);
|
413
|
+
selectLink(lastLink);
|
414
|
+
} else {
|
415
|
+
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'prev');
|
416
|
+
}
|
417
|
+
}
|
418
|
+
// strike pagedown + ctrl => go to next header
|
419
|
+
if (e.keyCode === 34 && e.ctrlKey) {
|
420
|
+
// go to header
|
421
|
+
linkSelected.focus();
|
422
|
+
e.preventDefault();
|
423
|
+
// then next
|
424
|
+
if (lastLink.getAttribute(ATTR_SELECTED) === 'true') {
|
425
|
+
unSelectLinks($parentListLinks);
|
426
|
+
unSelectContents($parentListContents);
|
427
|
+
selectLink(firstLink);
|
428
|
+
} else {
|
429
|
+
selectLinkInList($parentListItems, $parentListLinks, $parentListContents, 'next');
|
430
|
+
}
|
431
|
+
}
|
432
|
+
})();
|
433
|
+
}
|
434
|
+
|
435
|
+
// click on a tab link
|
436
|
+
var parentLinkToPanelId = searchParent(e.target, TABS_JS_LINK_TO_TAB);
|
437
|
+
if ((hasClass(e.target, TABS_JS_LINK_TO_TAB) === true || parentLinkToPanelId !== '') && eventName === 'click') {
|
438
|
+
var panelSelectedId = hasClass(e.target, TABS_JS_LINK_TO_TAB) === true ? e.target.getAttribute('href').replace('#', '') : findById(parentLinkToPanelId).replace('#', '');
|
439
|
+
var panelSelected = findById(panelSelectedId);
|
440
|
+
var buttonPanelSelected = findById(panelSelected.getAttribute(ATTR_LABELLEDBY));
|
441
|
+
var parentTabId = searchParent(e.target, TABS_JS);
|
442
|
+
var parentTab = findById(parentTabId);
|
443
|
+
//let $parentListItems = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTITEM));
|
444
|
+
var $parentListLinks = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_LISTLINK));
|
445
|
+
var $parentListContents = [].slice.call(parentTab.querySelectorAll('.' + TABS_JS_CONTENT));
|
446
|
+
|
447
|
+
unSelectLinks($parentListLinks);
|
448
|
+
unSelectContents($parentListContents);
|
449
|
+
selectLink(buttonPanelSelected);
|
450
|
+
|
451
|
+
e.preventDefault();
|
452
|
+
}
|
453
|
+
}, true);
|
454
|
+
});
|
455
|
+
};
|
456
|
+
|
457
|
+
var onLoad = function onLoad() {
|
458
|
+
attach();
|
459
|
+
bindListeners();
|
460
|
+
document.removeEventListener('DOMContentLoaded', onLoad);
|
461
|
+
};
|
462
|
+
|
463
|
+
document.addEventListener('DOMContentLoaded', onLoad);
|
464
|
+
|
465
|
+
window.van11yAccessibleTabPanelAria = attach;
|
466
466
|
})(document);
|