-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlanguagePickerDrawerView.js
111 lines (93 loc) · 3.09 KB
/
languagePickerDrawerView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
define([
'core/js/adapt'
], function(Adapt) {
var LanguagePickerDrawerView = Backbone.View.extend({
events: {
'click .js-languagepicker-item-btn': 'onButtonClick'
},
initialize: function () {
this.listenTo(Adapt, {
remove: this.remove,
'languagepicker:changelanguage:yes': this.onDoChangeLanguage,
'languagepicker:changelanguage:no': this.onDontChangeLanguage
});
this.render();
},
render: function () {
var data = this.model.toJSON();
var template = Handlebars.templates[this.constructor.template];
this.$el.html(template(data));
},
onButtonClick: function (event) {
var newLanguage = $(event.currentTarget).attr('data-language');
this.model.set('newLanguage', newLanguage);
var data = this.model.getLanguageDetails(newLanguage);
var promptObject = {
_classes: 'is-ltr',
title: data.warningTitle,
body: data.warningMessage,
_prompts:[
{
promptText: data._buttons.yes,
_callbackEvent: 'languagepicker:changelanguage:yes'
},
{
promptText: data._buttons.no,
_callbackEvent: 'languagepicker:changelanguage:no'
}
],
_showIcon: true
};
if (data._direction === 'rtl') {
promptObject._classes = 'is-rtl';
}
//keep active element incase the user cancels - usually navigation bar icon
//move drawer close focus to #focuser
if ($.a11y) {
// old a11y API (Framework v4.3.0 and earlier)
this.$finishFocus = $.a11y.state.focusStack.pop();
$.a11y.state.focusStack.push($('#focuser'));
} else {
this.$finishFocus = Adapt.a11y._popup._focusStack.pop();
Adapt.a11y._popup._focusStack.push($('#a11y-focuser'));
}
Adapt.once('drawer:closed', function() {
//wait for drawer to fully close
_.delay(function(){
//show yes/no popup
Adapt.once('popup:opened', function() {
//move popup close focus to #focuser
if ($.a11y) {
// old a11y API (Framework v4.3.0 and earlier)
$.a11y.state.focusStack.pop();
$.a11y.state.focusStack.push($('#focuser'));
return;
}
Adapt.a11y._popup._focusStack.pop();
Adapt.a11y._popup._focusStack.push($('#a11y-focuser'));
});
Adapt.trigger('notify:prompt', promptObject);
}, 250);
});
Adapt.trigger('drawer:closeDrawer');
},
onDoChangeLanguage: function () {
// set default language
var newLanguage = this.model.get('newLanguage');
this.model.setTrackedData();
this.model.setLanguage(newLanguage);
this.remove();
},
onDontChangeLanguage: function () {
this.remove();
// wait for notify to close fully
_.delay(function(){
// focus on navigation bar icon
this.$finishFocus.a11y_focus();
}.bind(this), 500);
}
}, {
template: 'languagePickerDrawerView'
});
return LanguagePickerDrawerView;
});