// Place your application-specific JavaScript functions and classes here // This file is automatically included by javascript_include_tag :defaults /* * third party libraries *= require jquery-2.1.1.min.js *= require jquery-migrate-1.2.1.js *= require jquery.cycle.all.min.js *= require jquery.colorbox-min.js *= require jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js *= require jquery.scrollTo.js *= require jquery.form.js *= require jquery-validation/jquery.validate.js *= require jquery.cookie.js *= require jquery.ba-bbq.min.js *= require jquery.tokeninput.js *= require jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.js *= require inputosaurus.js *= require reflection.js *= require rails.js *= require jrails.js * noosfero libraries *= require_self *= require modal.js * views speficics *= require add-and-join.js *= require report-abuse.js *= require manage-products.js *= require catalog.js *= require autogrow.js *= require require_login.js */ // scope for noosfero stuff noosfero = { }; function noosfero_init() { // focus_first_field(); it is moving the page view when de form is down. } var __noosfero_root = null; function noosfero_root() { if (__noosfero_root == null) { __noosfero_root = jQuery('meta[property="noosfero:root"]').attr("content") || ''; } return __noosfero_root; } /* 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 ) { if (str.indexOf('@') == -1) return convToValidUsername(str); else return convToValidEmail(str); } function convToValidUsername( 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 convToValidEmail( str ) { return str.toLowerCase() .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, '' ) } 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); } } jQuery.fn.centerInForm = function () { var $ = jQuery; var form = $(this).parent('form'); this.css("position", "absolute"); this.css("top", (form.height() - this.height())/ 2 + form.scrollTop() + "px"); this.css("left", (form.width() - this.width()) / 2 + form.scrollLeft() + "px"); this.css("width", form.width() + "px"); this.css("height", form.height() + "px"); return this; } jQuery.fn.center = function () { var $ = jQuery; this.css("position", "absolute"); this.css("top", ($(window).height() - this.height())/ 2 + $(window).scrollTop() + "px"); this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px"); return this; } function show_warning(field, message) { jQuery('#'+field).effect('highlight'); jQuery('#'+message).show(); } function hide_warning(field) { jQuery('#'+field).hide(); } function enable_button(button) { button = jQuery(button) button.prop('disabled', false); button.removeClass("disabled"); } function disable_button(button) { button = jQuery(button) button.prop('disabled', true); button.addClass("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) { jQuery('#'+element_id).addClass('loading'); if (message) { jQuery('#'+element_id).html(message); } } function small_loading(element_id, message) { $('#'+element_id).addClass('small-loading'); if (message) { $('#'+element_id).text(message); } } function loading_done(element_id) { jQuery('#'+element_id).removeClass('loading'); jQuery('#'+element_id).removeClass('small-loading'); jQuery('#'+element_id).removeClass('small-loading-dark'); } function open_loading(message) { jQuery('body').prepend("