generated from backdrop-contrib/module_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvi.js
executable file
·53 lines (42 loc) · 1.6 KB
/
tvi.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
/**
* @file
* TVI module behavior.
*/
(function($) {
Drupal.behaviors.tvi_initialize = {
attach: function(context, settings) {
// -----------------------------------------------------------------------
// Properties
var current_display = $('#tvi-display-selector', context).val();
var all_displays = $('#tvi-display-selector', context).children('option');
// ------------------------------------------------------------------------
// Handlers
var set_active_option = function() {
$('#tvi-display-selector', context).val(current_display);
};
// -----------------------------------------------------------------------
var view_change_handler = function() {
var view_name = $('#tvi-view-selector', context).val();
if (!view_name) {
view_name = $('#tvi-view-selector option:first', context).val();
$('#tvi-view-selector', context).val(view_name);
}
// Load new view displays.
var ds = $('#tvi-display-selector', context).html('');
all_displays.each(function(i,item) {
if ($(item).attr('value').indexOf(view_name + ':') == 0) {
ds.append($(item));
}
});
ds.val($('[selected]', ds).val());
};
// -----------------------------------------------------------------------
// Start
// Javascript is enabled.
$('.javascript-warning', context).hide();
// Reload displays when views are changed.
$('#tvi-view-selector', context).change(view_change_handler);
view_change_handler();
}
};
})(jQuery);