$(document).ready(function() {
//Déroulement menu
$("#menu div.menu_dir").click(
function(){
$(this).next('.sousmenu_dir').toggle('blind',{},500);
}
);
$("form .titre").each(function(i) {
if ($(this).hasClass('required')) {
$(this).html($(this).html() + " *");
}
});
});
/********************/
/* UTILE */
/**
* Sérialize en objet JSON
*/
$.fn.serializeJSON = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
//Strip tag
this.value = $('
').html(this.value).text();
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
/**
* strpad
*/
$.strPad = function(i,l,s) {
var o = i.toString();
if (!s) { s = '0'; }
while (o.length < l) {
o = s + o;
}
return o;
};
function isMailExist (elm, value) {
$.ajax({
url : "/user/ajaxmail",
type : "post",
data : {
mail : value
},
success : function (msg) {
if (msg != '') {
if ($("#mailExist").length) {
$("#mailExist").replaceWith(msg);
} else {
$(msg).insertBefore($('#' + elm));
}
} else {
$("#mailExist").remove();
}
}
});
};
function loginExist (elm, value) {
$.ajax({
url : "/user/ajaxlogin",
type : "post",
data : {
login : value
},
success : function (msg) {
if (msg != '') {
if ($("#loginExist").length) {
$("#loginExist").replaceWith(msg);
} else {
$(msg).insertBefore($('#' + elm));
}
} else {
$("#loginExist").remove();
}
}
});
};
var fixHelperSortable = function(e, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
};
$(document).ready (function () {
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append("
" + item.category + "");
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});
});
/**
* Déserialize une chaine de caractère en objet
* @param string data
* @return object
*/
function unserialize(data)
{
var o = {};
if(data) {
data = data.split('&');
jQuery.each(data, function() {
var tmp = this.split("=");
o[tmp[0]] = unescape(tmp[1]);
});
}
return o;
}
/**
* Implémentation de JSON.stringify les Navigateurs inférieurs à IE7
* @param object obj
* @return string
*/
function toStringify( obj ) {
if (typeof JSON == "undefined") {
var t = typeof (obj);
if (t != "object" || obj === null) {
if (t == "string") obj = '"' + obj + '"';
return String(obj);
} else {
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n];
t = typeof (v);
if (t == "string") v = '"' + v + '"';
else if (t == "object" && v !== null) v = toStringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
} else return JSON.stringify (obj);
};
/**
* Tranforme un objet en json
* @param object obj
* @return json
*/
function toJSON( obj )
{
return typeof JSON !="undefined" ? JSON.parse(obj) : eval('(' + obj + ')');
}
/**
* Enlève les balises
* @param strMod
* @return
*/
function stripTags(strMod)
{
strMod = strMod.replace(/<\!--.*-->/gi, '');
return strMod.replace(/<\/?(?!\!)[^>]*>/gi, '');
}
/**
* Ouverture d'une boite de confirmation
* @param htmlContent
* @param callback
* @return
*/
function openConfirmBox( htmlContent , callback)
{
$("#popup_confirm").html( htmlContent );
var btn = new Object();
btn[translate('ok')] = function() { try { eval(callback); } catch (e) { alert("Une erreur s'est produite : " + callback); } $(this).dialog('close'); };
btn[translate('cancel')] = function() { $(this).dialog("close"); };
$("#popup_confirm").dialog({
title: translate('alert'),
resizable: false ,
minWidth: 400 ,
minHeight : 200 ,
modal: true ,
buttons: btn
});
}
/**
* Ouverture d'une boite d'alert
* @param htmlContent
* @return
*/
function openAlertBox(htmlContent, width, height)
{
$("#popup_dialog").html(htmlContent);
var btn = new Object();
btn[translate('ok')] = function() { $(this).dialog("close"); };
params = {
title: translate('alert'),
resizable: true ,
minWidth: 500 ,
modal: true ,
buttons: btn
};
if (width) {
params.width = width;
}
if (height) {
params.height = height;
}
$("#popup_dialog").dialog(params);
}
/**
* Lien vers une url
* @param url
* @return
*/
function link(url)
{
self.location.href = url;
}
/**
*
* @param elem
* @param email
* @return
*/
function mail(elem, email)
{
$(elem).attr("href", "mailto:" + email);
$(elem).text(email);
}
/**
* Enlève les espaces d'une string
* @param myString
* @return
*/
function trim (myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
/**
* Vérification du navigateur (version < IE8)
* @return
*/
function verifNavigator()
{
if ( $.browser.msie && parseInt($.browser.version, 10) < 8 ) {
$("#popup_dialog").html(translate('navigator_ie_description'));
var btn = new Object();
btn[translate('ok')] = function() { $(this).dialog("close"); };
$("#popup_dialog").dialog({
title : translate('navigator_ie'),
modal : true,
resizable : false,
buttons : btn
});
}
}
/**
* Decrypr une chaine de caractère
* @param str
* @param idElem
* @return
*/
function decrypt (str, idElem)
{
var map = new Array();
var s = "abcdefghijklmnopqrstuvwxyz";
for (i=0; i
='A' && b<='Z' || b>='a' && b<='z' ? map[b] : b);
}
if (idElem != '') {
$(document).ready(function() {
$('#' + idElem).attr('href', $('#' + idElem).attr('href') + s);
});
} else {
document.write(s);
}
}
function addslashes(ch) {
ch = ch.replace(/\\/g,"\\\\");
ch = ch.replace(/\'/g,"\\'");
ch = ch.replace(/\"/g,"\\\"");
return ch;
};
function viewRessource(elem, format, resource, container, description)
{
$('#article .fcontent .list a').removeClass('current');
$(elem).addClass('current');
$('#' + container).toggle(false);
if ($.inArray(format, ['flv', 'mp4']) != -1) {
jwplayer(container).setup({ flashplayer: "/js/jwplayer/player.swf", provider : 'video', file: resource, height: 270, width: 400 });
} else {
if ($.inArray(format, ['jpg', 'png', 'gif']) != -1) {
html = '
';
} else if ($.inArray(format, ['pdf']) != -1) {
html = '';
} else if ($.inArray(format, ['html']) != -1) {
html = '';
$('#' + container).load(resource);
} else {
html = '';
}
$('#' + container).html(html);
}
$('#' + description).html($(elem).find('textarea').val());
$('#' + container).toggle(true);
}
function initArticleFiles()
{
$('#article .ftab').click(function(event) {
$('#article .ftab').removeClass('current');
$('#article .fcontent').hide();
$(this).addClass('current');
contentId = $(this).attr('id').replace('tab', 'content');
$('#' + contentId).show();
$('#' + contentId + ' a.linkfile').click();
});
$('#article .ftab:first').click();
}
function display(link, elemId)
{
if ($('#' + elemId).is(':visible')) {
$('#' + elemId).hide();
$(link).text($(link).attr('show'));
} else {
$('#' + elemId).toggle();
$(link).text($(link).attr('hide'));
}
}
function disabledButton (elem)
{
elem.attr('disabled', 'disabled');
}
function information (info)
{
return " | " + info.LASTNAME + info.FIRSTNAME + " |
› Id : " + info.UID + " |
› " + translate('Login') + " : " + info.USERNAME + " |
› " + translate('Email') + " : " + info.MAIL + " |
› " + translate('Langue') + " : " + info.LANGUEID + " |
";
}
$.fn.sciencesconfSuggest = function(url, opts, callback){
opts = $.extend({service: 'user'}, opts);
var services = {
author: { client: 'author', ds: 'name' },
laboratories: { client: 'laboratory', ds: 'name' },
user: { client: 'user', ds: 'username' }
};
var service = services[opts.service];
opts.source = function(request, response){
$.ajax({
url: url,
dataType: 'jsonp',
data: {
q: request.term,
client: service.client,
ds: service.ds
},
success: function(data) {
response($.map(data, function(item, i){
return {
value : i,
label : item[0],
term : request.term,
client : service.client,
raw : item[1]
};
}));
},
error: function(jqXHR, textStatus, errorThrown) {
/**
* Vide
*/
response($.map(data, function(item, i){
return { value : i, label : item };
}));
}
});
};
opts.minLength = 2;
opts.delay = 500;
opts.select = function (event, ui) {
callback (ui);
$(this).val('');
event.preventDefault();
};
return this.each(function(){
$(this).live('blur', function () {
$(this).val('');
}).autocomplete(opts).data('autocomplete')._renderItem = function(ul, item) {
var reg = new RegExp ("^(" + item.term + ")(.*)", "gi"), str1 = str2 = "", icon = " ";
$.map (item.label, function (label, i) {
if (i) {
str1 = str1 + "
";
str2 = str2 + "
";
}
str1 = str1 + "" + label.replace(reg, "$1$2") + "";
str2 = str2 + "" + label + "";
});
item.label = str2 ;
return $( "" ).data( "item.autocomplete", item ).append( "" + icon + str1 + "
" ).appendTo( ul );
};
});
}