var showTopper = true;
/************************************************************************************************************************************************************************************************************
*
* ONLOAD FUNCTION CALLS
*
***********************************************************************************************************************************************************************************************************/
$(function() {
// TOOLTIP INISTIALIZER - data-original-title="tooltip richiesto"
$('.tooltips').tooltip();
/* MB VIDEO EMBEDDING prima in partfoheaderfooter */
videoEmbedder();
// MANAGE BACK TO TOP in read-along context showTopper=false (partFODocumentDrawer.jsp)
if(showTopper) {
var top = $('
').attr('id', 'topper').css({ bottom: '50px', display: 'none', position: 'fixed', right: 0});
var href = $('
');
href.append('');
top.append(href);
$('body').append(top);
var firstBodyEl = document.body.firstChild;
var gtm = document.createElement('a');
gtm.name = "ww4_top";
firstBodyEl.parentNode.insertBefore(gtm, firstBodyEl);
document.addEventListener("scroll", function() {
var topper = $('#topper');
var isVisible = topper.is(':visible');
//console.debug($(window).scrollTop() + ' / ' + screen.height + ' / ' + $(window).height() );
if(!isVisible && $(window).scrollTop()> $(window).height()) {
topper.fadeIn('slow');
} else if (isVisible && $(window).scrollTop()< $(window).height()) {
topper.fadeOut('slow');
}
}, true);
}
// per non coprire il footer l'altezza della sidebar รจ ricalcolata
var contentHeight = $('#main-content').height();
var footerMargin = $('footer.footer-section').css('margin-top');
var tot = parseInt(contentHeight) +parseInt(footerMargin);
$('#sidebar').css('height', tot);
});
function ex(el) {
return el && el!='' && el!=undefined;
}
function videoEmbedder() {
// calcolo per rendere responsive l'embedding dei video
var videoWidth = (550 * getWindowDimensionW()/1200);
videoWidth = Math.floor(videoWidth);
if(videoWidth>480)
videoWidth = 480;
else if(videoWidth<150)
videoWidth = 240;
$.mb_videoEmbedder.defaults.width = videoWidth;
$("body").mb_embedMovies();
}
var heroesController = contextPath + '/applications/webwork/site_heroes/local/portlet/wp_registration/ajaxRegistrationController.jsp';
function uploadFile(resId, containerId, html, isProfilePage) {
// NB!! la entry per il file in upload (AVATAR) viene gestita ed aggiunta da $.ajaxFileUpload tramite la variabile 'fileElementId':
// non va quindi passata nei data, pena la sua duplicazione
var data = { 'CM' : 'AVATAR_UPLOAD', 'resId' : resId, 'siteId' : $('#siteId').val(), 'isProfile' : isProfilePage ? "yes" : "no" };
//can perform client side field required checking for "fileToUpload" field
$.ajaxFileUpload({
data : data,
url : heroesController,
secureuri : false,
fileElementId : 'AVATAR_upl', // $.ajaxFileUpload lo richiede
dataType : 'json',
success: function (response) {
if (response.ok) {
$("#" + containerId).html(html);
if(response.newImage) {
$('#myPhoto').attr('src', response.newImage);
}
} else {
$("#" + containerId).html(html + response.html);
}
},
error: function (data, status, e) {
$("#" + containerId).html(html + "Oh oh: something went wrong!
Image not loaded
");
}
});
return false;
}
/************************************************************************************************************************************************************************************************************
*
* FROM WEBWORK.JS & SHARED.JS
*
***********************************************************************************************************************************************************************************************************/
// ---------------------------------- form validator
function valuesConcordanceVerifier( elId01, elId02, errorMexElId) {
var el01 = $('#' + elId01);
var val01 = el01.val();
var el02 = $('#' + elId02);
var val02 = el02.val();
if(el01 && val01!='' && el02 && val02!='' && val01!=val02) {
if(ex(errorMexElId)) {
$("#" + errorMexElId).html(i18n.VALUES_DONT_MATCH).show();
}
el02.val('');
highlight(el02, errorMexElId);
el02.focus();
return false;
} else if( (el01 && val01=='') || (el02 && val02=='')) {
if(val01=='') {
highlight(el01);
el01.focus();
} else {
highlight(el02, errorMexElId);
el02.focus();
}
return false;
} else
return true;
}
function highlight($theElement, errorMexElId) {
if($theElement.attr('type')=='checkbox') {
$theElement.wrap("");
setTimeout( function(){ $theElement.unwrap(); }, 1500);
} else {
$theElement.addClass("error");
setTimeout( function(){
$theElement.removeClass('error');
if(ex(errorMexElId))
$("#" + errorMexElId).hide();
}, 3000);
}
$theElement.focus();
scrollToElement($theElement.attr('id'));
}
function scrollToElement(elId, speed) {
if(!speed)
speed = 'fast';
$('html, body').animate({
scrollTop: $("#" + elId).offset().top
}, speed);
}
/**
* FORM FUNCTIONS
*/
function getDataFromForm(formId) {
var data = {};
var form = document.getElementById(formId);
// var url = '';
// var first = true;
for (var i = 0; i < form.elements.length; i++) {
var el = form.elements[i];
var value;
var inputType = el.type;
if (inputType == "checkbox") {
data[el.name] = el.value.checked ? "yes" : "no";
} else if (inputType == 'radio') {
//alert(el.name+' '+ el.checked+' '+el.value);
if (el.checked)
value = el.value;
else
value = null;
} else
value = el.value;
if (value != null) {
/*
//url = url + (first ? '' : '&') + el.name + '=' + escape(el.value); // escape() is lesser safe than encodeURIComponent() see: http://xkr.us/articles/javascript/encode-compare/
var inputQuery = (first ? '' : '&') + el.name + '=' + encodeURIComponent(value);
console.log(inputQuery);
url = url + inputQuery;
first = false;
*/
data[el.name] = value;
}
}
// return url;
return data;
}