application.js
1.88 KB
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
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function noosfero_init() {
// focus_first_field(); it is moving the page view when de form is down.
}
/* If applicable, find the first field in which the user can type and move the
* keyboard focus to it.
*
* ToDo: focus only inside the view box to do not roll the page.
*/
function focus_first_field() {
form = document.forms[0];
if (form == undefined) {
return;
}
for (var i = 0; i < form.elements.length; i++) {
field = form.elements[i];
if (field.type == 'text' || field.type == 'textarea') {
try {
field.focus();
return;
} catch(e) { }
}
}
}
/* * * Convert a string to a valid login name * * */
function convToValidLogin( str ) {
return convToValidIdentifier(str, '')
}
/* * * Convert a string to a valid login name * * */
function convToValidIdentifier( str, sep ) {
return str.toLowerCase()
.replace( /@.*$/, "" )
.replace( /á|à|ã|â/g, "a" )
.replace( /é|ê/g, "e" )
.replace( /í/g, "i" )
.replace( /ó|ô|õ|ö/g, "o" )
.replace( /ú|ũ|ü/g, "u" )
.replace( /ñ/g, "n" )
.replace( /ç/g, "c" )
.replace( /[^-_a-z0-9.]+/g, sep )
}
function updateUrlField(name_field, id) {
url_field = $(id);
url_field.value = convToValidIdentifier(name_field.value, "-");
warn_value_change(url_field);
}
function show_warning(field, message) {
new Effect.Highlight(field, {duration:3});
$(message).show();
}
function hide_warning(field) {
$(field).hide();
}
function enable_button(button) {
button.enable();
button.removeClassName("disabled");
}
function disable_button(button) {
button.disable();
button.addClassName("disabled");
}