application.js
4.94 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// 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);
old_url_value = url_field.value;
new_url_value = convToValidIdentifier(name_field.value, "-");
url_field.value = new_url_value;
if (!/^\s*$/.test(old_url_value)
&& old_url_value != new_url_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");
}
function toggleDisabled(enable, element) {
if (enable) {
enable_button(element);
}
else {
disable_button(element);
}
}
/* ICON SELECTOR - LinkListBlock */
function showIconSelector(main_div) {
iconSelector = jQuery(main_div).children('.icon-selector')[0];
jQuery(iconSelector).toggle();
}
function changeIcon(iconSelected, iconName) {
iconSelector = iconSelected.parentNode;
setTimeout('iconSelector.style.display = "none"', 100);
main_div = iconSelector.parentNode;
span = main_div.getElementsByTagName('span')[0];
span.className = iconSelected.className;
iconInput = main_div.getElementsByTagName('input')[0];
iconInput.value = iconName;
}
function hideOthersIconSelector(current_div) {
jQuery('.icon-selector').not(jQuery(current_div).children('.icon-selector')).hide();
}
function loading(element_id, message) {
$(element_id).addClassName('loading');
if (message) {
$(element_id).update(message);
}
}
function loading_done(element_id) {
$(element_id).removeClassName('loading');
}
function open_loading(message) {
jQuery('body').append("<div id='overlay_loading' class='ui-widget-overlay' style='display: none'/><div id='overlay_loading_modal' style='display: none'><p>"+message+"</p><img src='/images/loading-dark.gif'/></div>");
jQuery('#overlay_loading').show();
jQuery('#overlay_loading_modal').fadeIn('slow');
}
function close_loading() {
jQuery('#overlay_loading_modal').fadeOut('slow', function() {
jQuery('#overlay_loading_modal').remove();
jQuery('#overlay_loading').remove();
});
}
function update_loading(message) {
jQuery('#overlay_loading_modal p').text(message);
}
function redirect_to(url) {
document.location=url;
}
/* Products edition */
function numbersonly(e, separator) {
var key;
var keychar;
if (window.event) {
key = window.event.keyCode;
}
else if (e) {
key = e.which;
}
else {
return true;
}
keychar = String.fromCharCode(key);
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
return true;
}
else if (keychar == separator) {
return true;
}
else
return false;
}
// transform all element with class ui_button in a jQuery UI button
function render_jquery_ui_buttons(element_id) {
if (element_id) {
element_id = '#' + element_id
jQuery(element_id).button({
icons: {
primary: jQuery(element_id).attr('data-primary-icon'),
secondary: jQuery(element_id).attr('data-secondary-icon')
}
}
)
}
else {
jQuery('.ui_button').each(function() {
jQuery(this).button({
icons: {
primary: this.getAttribute('data-primary-icon'),
secondary: this.getAttribute('data-secondary-icon')
}
}
)
})
}
}