-
Notifications
You must be signed in to change notification settings - Fork 487
/
osem.js
154 lines (135 loc) · 4.89 KB
/
osem.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
$(function () {
/**
* Update the number of words in the biography text field every time the user
* releases a key on the keyboard
*/
$("#user_biography").bind('keyup', function() {
word_count(this, 'bio_length', 150);
} );
/**
* Displays a modal with the questions of the registration.
*/
$(document).ready(function(){
$(".question-btn").click(function(){
var id = $(this).data('id');
$("#question-modal-body").empty();
$("#question-modal-body").html($(".question" + id).clone().show());
$("#question-modal-header").text('Questions for ' + $(this).data('name'));
$('#questions').modal('show');
});
});
/**
* Toggles email template help below email body textarea field.
*/
$(document).ready( function() {
$(".template-help").hide();
$(".template_help_link").click(function() {
var id = $(this).data('name');
$("#" + id).toggle();
});
});
/**
* Randomize order of parallel elements by shuffling the decks
* Adapted from https://stackoverflow.com/questions/7070054
*/
$(document).ready( function() {
$.each($(".shuffle-deck"), function(index, deck) {
for(var i = deck.children.length; i >= 0; i--) {
deck.appendChild(deck.children[Math.random() * i | 0]);
}
});
});
$(".select-help-toggle").change(function () {
var id = $(this).attr('id');
$('.' + id).collapse('hide');
$('#' + $(this).val() + '-help.' + id).collapse('show');
});
$('.dropdown-toggle').dropdown();
/**
* Adds the default template as value to the regarding email textarea field.
*/
$(".load_template").on('click', function () {
var subject_input_id = $(this).data('subject-input-id');
var subject_input_text = $(this).data('subject-text');
var body_input_id = $(this).data('body-input-id');
var body_input_text = $(this).data('body-text');
$('#' + subject_input_id).val(subject_input_text);
$('#' + body_input_id).val(body_input_text);
});
/**
* Toggle the required attribute on click on_send_email radio button.
*/
$('.send_on_radio').click(function () {
toggle_required_for_mail_subjects($(this))
});
/**
* Adds required attribute to on_send_email radio button if necessary.
*/
$('.send_on_radio').each(function () {
toggle_required_for_mail_subjects($(this))
});
/**
* Toggle the required attribute helper function.
*/
function toggle_required_for_mail_subjects($this) {
var name = $this.data('name');
if ($this.is(':checked')) {
$('#' + name).prop('required', true);
} else {
$('#' + name).removeAttr('required');
}
}
$(".comment-reply-link").click(function(){
$(".comment-reply", $(this).parent()).toggle();
return false;
});
$(".comment-reply").hide();
$(".user-details-popover").popover();
$("#comments-div").hide();
$('a:contains("Add track")').click(function () {
setTimeout(function () {
$("div.nested-fields:last div:nth-of-type(2) input").val(get_color());
},
5)
});
$('a:contains("Add difficulty_level")').click(function () {
setTimeout(function () {
$("div.nested-fields:last div:nth-of-type(3) input").val(get_color());
},
5)
});
$('a:contains("Add event_type")').click(function () {
setTimeout(function () {
$("div.nested-fields:last div:nth-of-type(5) input").val(get_color());
},
5)
});
});
function get_color() {
var colors = ['#000000', '#0000FF', '#00FF00', '#FF0000', '#FFFF00', '#9900CC',
'#CC0066', '#00FFFF', '#FF00FF', '#C0C0C0', '#00008B', '#FFD700',
'#FFA500', '#FF1493', '#FF00FF', '#F0FFFF', '#EE82EE', '#D2691E',
'#C0C0C0', '#A52A2A', '#9ACD32', '#9400D3', '#8B008B', '#8B0000',
'#87CEEB', '#808080', '#800080', '#008B8B', '#006400'
];
return colors[Math.floor(Math.random() * colors.length)];
}
function word_count(text, divId, maxcount) {
var area = document.getElementById(text.id)
Countable.once(area, function(counter) {
$('#' + divId).text(counter.words);
if (counter.words > maxcount)
$('#' + divId).css('color', 'red');
else
$('#' + divId).css('color', 'black');
});
};
/* Commodity function for modal windows */
window.build_dialog = function(selector, content) {
// Close it and remove content if it's already open
$("#" + selector).modal('hide');
$("#" + selector).remove();
// Add new content and pops it up
$("body").append("<div id=\"" + selector + "\" class=\"modal fade\" role=\"dialog\">\n" + content + "</div>");
$("#" + selector).modal();
}