12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904 |
- /*
- * Scripts de Muzi.ch
- * Rédigé et propriété de Sevajol Bastien (http://www.bux.fr) sauf si mention
- * contraire sur la fonction.
- *
- */
-
- // Messages flashs
- var myMessages = ['info','warning','error','success']; // define the messages types
-
- function hideAllMessages()
- {
- var messagesHeights = new Array(); // this array will store height for each
-
- for (i=0; i<myMessages.length; i++)
- {
- messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
- $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
- }
- }
-
- $(document).ready(function(){
-
- // Initially, hide them all
- hideAllMessages();
-
- $('.message').animate({top:"0"}, 500);
-
- // When message is clicked, hide it
- $('.message a.message-close').click(function(){
- $(this).parent('.message').animate({top: -$(this).outerHeight()-50}, 700);
- return false;
- });
-
- });
-
- function findKeyWithValue(arrayt, value)
- {
- for(i in arrayt)
- {
- if (arrayt[i] == value)
- {
- return i;
- }
- }
- return "";
- }
-
- function json_to_array(json_string)
- {
- if (json_string.length)
- {
- return eval("(" + json_string + ")");
- }
- return new Array();
- }
-
- function strpos (haystack, needle, offset) {
- // Finds position of first occurrence of a string within another
- //
- // version: 1109.2015
- // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Onno Marsman
- // + bugfixed by: Daniel Esteban
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
- var i = (haystack + '').indexOf(needle, (offset || 0));
- return i === -1 ? false : i;
- }
-
- /**
- * Converts the given data structure to a JSON string.
- * Argument: arr - The data structure that must be converted to JSON
- * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
- * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
- * http://www.openjs.com/scripts/data/json_encode.php
- */
- function array2json(arr) {
- var parts = [];
- var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
-
- for(var key in arr) {
- var value = arr[key];
- if(typeof value == "object") { //Custom handling for arrays
- if(is_list) parts.push(array2json(value)); /* :RECURSION: */
- else parts[key] = array2json(value); /* :RECURSION: */
- } else {
- var str = "";
- if(!is_list) str = '"' + key + '":';
-
- //Custom handling for multiple data types
- if(typeof value == "number") str += value; //Numbers
- else if(value === false) str += 'false'; //The booleans
- else if(value === true) str += 'true';
- else str += '"' + value + '"'; //All other things
- // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
-
- parts.push(str);
- }
- }
- var json = parts.join(",");
-
- if(is_list) return '[' + json + ']';//Return numerical JSON
- return '{' + json + '}';//Return associative JSON
- }
-
- function isInteger(s) {
- return (s.toString().search(/^-?[0-9]+$/) == 0);
- }
-
- function inArray(array, p_val) {
- var l = array.length;
- for(var i = 0; i < l; i++) {
- if(array[i] == p_val) {
- return true;
- }
- }
- return false;
- }
-
- if(typeof(String.prototype.trim) === "undefined")
- {
- String.prototype.trim = function()
- {
- return String(this).replace(/^\s+|\s+$/g, '');
- };
- }
-
- function str_replace (search, replace, subject, count) {
- // Replaces all occurrences of search in haystack with replace
- //
- // version: 1109.2015
- // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: Gabriel Paderni
- // + improved by: Philip Peterson
- // + improved by: Simon Willison (http://simonwillison.net)
- // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
- // + input by: Onno Marsman
- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + tweaked by: Onno Marsman
- // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + input by: Oleg Eremeev
- // + improved by: Brett Zamir (http://brett-zamir.me)
- // + bugfixed by: Oleg Eremeev
- // % note 1: The count parameter must be passed as a string in order // % note 1: to find a global variable in which the result will be given
- // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
- // * returns 1: 'Kevin.van.Zonneveld'
- // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
- // * returns 2: 'hemmo, mars' var i = 0,
- j = 0,
- temp = '',
- repl = '',
- sl = 0, fl = 0,
- f = [].concat(search),
- r = [].concat(replace),
- s = subject,
- ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
- s = [].concat(s);
- if (count) {
- this.window[count] = 0;
- }
- for (i = 0, sl = s.length; i < sl; i++) {
- if (s[i] === '') {
- continue;
- }for (j = 0, fl = f.length; j < fl; j++) {
- temp = s[i] + '';
- repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
- s[i] = (temp).split(f[j]).join(repl);
- if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
- }
- }
- }
- return sa ? s : s[0];
- }
-
- function explode (delimiter, string, limit) {
- // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.
- //
- // version: 1109.2015
- // discuss at: http://phpjs.org/functions/explode // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: kenneth
- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
- // + improved by: d3x
- // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: explode(' ', 'Kevin van Zonneveld');
- // * returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
- // * example 2: explode('=', 'a=bc=d', 2);
- // * returns 2: ['a', 'bc=d']
- var emptyArray = {0: ''
- };
-
- // third argument is not required
- if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {return null;
- }
-
- if (delimiter === '' || delimiter === false || delimiter === null) {
- return false;}
-
- if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
- return emptyArray;
- }
- if (delimiter === true) {
- delimiter = '1';
- }
- if (!limit) {
- return string.toString().split(delimiter.toString());
- }
- // support for limit argument
- var splitted = string.toString().split(delimiter.toString());var partA = splitted.splice(0, limit - 1);
- var partB = splitted.join(delimiter.toString());
- partA.push(partB);
- return partA;
- }
-
- // fonction de nettoyage des tags
- function remove_tags(form_name)
- {
- tagsAddeds[form_name] = new Array();
- $('form[name="'+form_name+'"] ul.tagbox li.tag').remove();
- $('form[name="'+form_name+'"] input.tagBox_tags_ids').val('');
- $('div#tags_prompt_'+form_name+' ul.tagbox li.input input[type="text"]')
- .val(string_tag_prompt_input_help)
- ;
- }
-
- $(document).ready(function(){
-
- // Controle du focus sur la page
- function onBlur() {
- document.body.className = 'blurred';
- }
-
- function onFocus(){
- document.body.className = 'focused';
- do_action_body_focused();
- }
-
- if (/*@cc_on!@*/false) { // check for Internet Explorer
- document.onfocusin = onFocus;
- document.onfocusout = onBlur;
- } else {
- window.onfocus = onFocus;
- window.onblur = onBlur;
- }
-
- // Bouton de personalisation du filtre
- // Aucun tags
- $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
- $('img.elements_more_loader').show();
- $('ul.elements').html('');
-
- var form = $('form[name="search"]');
- remove_tags(form.attr('name'));
- form.submit();
- });
-
- // tags préférés
- $('.tags_prompt input.mytags').live("click", function(){
-
- $('img.elements_more_loader').show();
- $('ul.elements').html('');
-
- var form = $(this).parents('form[name="search"]');
-
- $.getJSON(url_get_favorites_tags, function(response) {
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- remove_tags(form.attr('name'));
- // if (tags.length)
- // {
- var inputTag = $("div#tags_prompt_"+form.attr('name')+" input.form-default-value-processed");
- for (i in response.tags)
- {
- $('input#tags_selected_tag_'+form.attr('name')).val(i);
- inputTag.val(response.tags[i]);
-
- // Et on execute l'évènement selectTag de l'input
- inputTag.trigger("selectTag");
- }
-
- form.submit();
- //}
-
- });
- });
-
- // Tag cliqué dans la liste d'éléments
- $('ul.element_tags li a.element_tag').live('click', function(){
- // Si il y a une liste de tags (comme sur la page favoris, profil)
- var id;
- if ($('ul#favorite_tags').length)
- {
- id = str_replace('element_tag', '', $(this).attr('id'));
- var link = $('ul#favorite_tags li a[href="#'+id+'"]');
- list_tag_clicked(link, true);
- }
-
- if ($('form[name="search"]').length)
- {
- $('img.elements_more_loader').show();
- $('ul.elements').html('');
- var form = $('form[name="search"]');
- id = str_replace('element_tag', '', $(this).attr('id'));
- remove_tags('search');
- var inputTag = $("div#tags_prompt_search input.form-default-value-processed");
- $('input#tags_selected_tag_search').val(id);
- inputTag.val($(this).html());
- inputTag.trigger("selectTag");
- form.submit();
- }
- });
-
- // Affichage un/des embed
- // 1328283150_media-playback-start.png
- // 1328283201_emblem-symbolic-link.png
- $('a.element_embed_open_link').live("click", function(){
-
- var li = $(this).parents('li.element');
-
- li.find('a.element_embed_close_link').show();
- li.find('a.element_embed_open_link_text').hide();
- li.find('div.element_embed').show();
-
- return false;
- });
-
- $('a.element_name_embed_open_link').live("click", function(){
-
- var li = $(this).parents('li.element');
-
- li.find('a.element_embed_close_link').show();
- li.find('a.element_embed_open_link_text').hide();
- li.find('div.element_embed').show();
-
- return false;
- });
-
- // Fermeture du embed si demandé
- $('a.element_embed_close_link').live("click", function(){
-
- var li = $(this).parents('li.element');
-
- li.find('div.element_embed').hide();
- li.find('a.element_embed_open_link_text').show();
- $(this).hide();
-
- return false;
- });
-
- // Affichage du "play" ou du "open" (image png)
- $('li.element a.a_thumbnail, li.element img.open, li.element img.play').live({
- mouseenter:
- function()
- {
- var td = $(this).parent('td');
- var a = td.find('a.a_thumbnail');
- if (a.hasClass('embed'))
- {
- td.find('img.play').show();
- }
- else
- {
- td.find('img.open').show();
- }
- },
- mouseleave:
- function()
- {
- var td = $(this).parent('td');
- var a = td.find('a.a_thumbnail');
- if (a.hasClass('embed'))
- {
- td.find('img.play').hide();
- }
- else
- {
- td.find('img.open').hide();
- }
- }
- }
- );
-
- // Mise en favoris
- $('a.favorite_link').live("click", function(){
- var link = $(this);
-
- // Pour ne pas attendre la fin du chargement ajax:
- var img = link.find('img');
- if (!link.hasClass('loading'))
- {
- if (img.attr('src') == '/bundles/muzichcore/img/favorite_bw.png')
- {
- img.attr('src', '/bundles/muzichcore/img/favorite.png');
- }
- else
- {
- img.attr('src', '/bundles/muzichcore/img/favorite_bw.png');
- }
- }
-
- link.addClass('loading');
-
- $.getJSON($(this).attr('href'), function(response) {
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- var img = link.find('img');
- link.attr('href', response.link_new_url);
- img.attr('src', response.img_new_src);
- img.attr('title', response.img_new_title);
- link.removeClass('loading');
- });
- return false;
- });
-
- // Affichage du bouton Modifier et Supprimer
- $('ul.elements li.element').live({
- mouseenter:
- function()
- {
- $(this).find('a.element_edit_link').show();
- $(this).find('a.element_remove_link').show();
- },
- mouseleave:
- function()
- {
- if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
- {
- $(this).find('a.element_edit_link').hide();
- }
- if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
- {
- $(this).find('a.element_remove_link').hide();
- }
- }
- }
- );
-
- // Plus d'éléments
- var last_id = null;
- $('a.elements_more').click(function(){
- var link = $(this);
- var last_element = $('ul.elements li.element:last-child');
- var id_last = str_replace('element_', '', last_element.attr('id'));
- var invertcolor = 0;
- if (last_element.hasClass('even'))
- {
- invertcolor = 1;
- }
- $('img.elements_more_loader').show();
- $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.count)
- {
- $('ul.elements').append(response.html);
- $('img.elements_more_loader').hide();
- }
-
- if (response.end || response.count < 1)
- {
- $('img.elements_more_loader').hide();
- $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
- response.message+'</p></div>');
- link.hide();
- }
- });
- return false;
- });
-
- tag_box_input_value = $('ul.tagbox input[type="text"]').val();
-
- // Filtre et affichage éléments ajax
- $('form[name="search"] input[type="submit"]').click(function(){
- $('ul.elements').html('');
- $('div.no_elements').hide();
- $('img.elements_more_loader').show();
- });
-
- $('form[name="search"]').ajaxForm(function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- $('ul.elements').html(response.html);
-
- if (response.count)
- {
- $('img.elements_more_loader').hide();
- $('span.elements_more').show();
- $('a.elements_more').show();
- }
-
- if (response.count < 1)
- {
- $('img.elements_more_loader').hide();
- $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
- response.message+'</p></div>');
- $('a.elements_more').hide()
- ;
- }
-
- $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
-
- });
-
- // Suppression d'un element
- $('a.element_remove_link').jConfirmAction({
- question : string_element_delete_confirm_sentence,
- yesAnswer : string_element_delete_confirm_yes,
- cancelAnswer : string_element_delete_confirm_no,
- onYes: function(link){
-
- var li = $(this).parents('li.element');
- li.find('img.element_loader').show();
- $.getJSON(link.attr('href'), function(response){
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- li.remove();
- }
- else
- {
- li.find('img.element_loader').hide();
- }
- });
-
- return false;
- },
- onOpen: function(link){
- var li = $(this).parents('li.element');
- li.find('a.element_edit_link').addClass('mustBeDisplayed');
- li.find('a.element_remove_link').addClass('mustBeDisplayed');
- },
- onClose: function(link){
- var li = $(this).parents('li.element');
- li.find('a.element_edit_link').removeClass('mustBeDisplayed');
- li.find('a.element_remove_link').removeClass('mustBeDisplayed');
- li.find('a.element_edit_link').hide();
- li.find('a.element_remove_link').hide();
- }
- });
-
- var elements_edited = new Array();
- // Ouverture du formulaire de modification
- $('a.element_edit_link').live('click', function(){
-
- var link = $(this);
- var li = link.parents('li.element');
- // On garde en mémoire l'élément édité en cas d'annulation
- elements_edited[li.attr('id')] = li.html();
- var div_loader = li.find('div.loader');
- li.html(div_loader);
- li.find('img.element_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- // On prépare le tagBox
- li.html(response.html);
- // Pour le click sur l'input de saisie de tag
- li.find('ul.tagbox li.input input[type="text"]').formDefaults();
-
- var options = new Array();
- options.form_name = response.form_name;
- options.tag_init = response.tags;
-
- ajax_query_timestamp = null;
-
- $("#tags_prompt_list_"+response.form_name).tagBox(options);
-
- // On rend ce formulaire ajaxFormable
- $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
- var li = $(this).parents('li.element');
- li.prepend(div_loader);
- li.find('img.element_loader').show();
- });
- $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- var li = $('li#'+response.dom_id);
-
- if (response.status == 'success')
- {
- li.html(response.html);
- delete(elements_edited[li.attr('id')]);
- }
- else if (response.status == 'error')
- {
- li.find('img.element_loader').hide();
- li.find('ul.error_list').remove();
- var ul_errors = $('<ul>').addClass('error_list');
-
- for (i in response.errors)
- {
- ul_errors.append($('<li>').append(response.errors[i]));
- }
-
- li.prepend(ul_errors);
- }
- });
-
- });
- return false;
- });
-
- // Annulation d'un formulaire de modification d'élément
- $('form.edit_element input.cancel_edit').live('click', function(){
- var li = link.parents('li.element');
- li.html(elements_edited[li.attr('id')]);
- delete(elements_edited[li.attr('id')]);
- });
-
- ////////////////// TAG PROMPT ///////////////
-
- var ajax_query_timestamp = null;
- var tag_text_help = $('input.tag_text_help').val();
-
- // Les deux clicks ci-dessous permettent de faire disparaitre
- // la div de tags lorsque l'on clique ailleurs
- $('html').click(function() {
- if ($("div.search_tag_list").is(':visible'))
- {
- $("div.search_tag_list").hide();
- }
- });
-
- $("div.search_tag_list, div.search_tag_list a.more").live('click', function(event){
- event.stopPropagation();
- $("div.search_tag_list").show();
- });
-
- function autocomplete_tag(input, form_name)
- {
- // Il doit y avoir au moin un caractère
- if ((input.val().length > 0) && (input.val() != string_tag_prompt_input_help))
- {
-
- // on met en variable l'input
- var inputTag = input;
-
- // On récupére la div de tags
- var divtags = $("#search_tag_"+form_name);
-
- // Si la fenêtre de tags est caché
- if (!divtags.is(':visible'))
- {
- // On la replace
- var position = input.position();
- divtags.css('left', Math.round(position.left) + 5);
- divtags.css('top', Math.round(position.top) + 28);
- // Et on l'affiche
- divtags.show();
- }
- // On affiche le loader
- $('#tag_loader_'+form_name).show();
- // On cache la liste de tags
- var search_tag_list = divtags.find('ul.search_tag_list');
- // On supprime les anciens li
- search_tag_list.find('li').remove();
- search_tag_list.hide();
- // Et on affiche une info
- var span_info = divtags.find('span.info');
- span_info.show();
- // TODO: multilingue !
- span_info.text("Recherche des tags correspondants à \""+input.val()+"\" ...");
-
- // C'est en fonction du nb de resultats qu'il sera affiché
- divtags.find('a.more').hide();
-
- // On récupère le timestamp pour reconnaitre la dernière requête effectué
- ajax_query_timestamp = new Date().getTime();
-
- // Récupération des tags correspondants
- $.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, function(data) {
- if (data.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- // Ce contrôle permet de ne pas continuer si une requete
- // ajax a été faite depuis.
- if (data.timestamp == ajax_query_timestamp)
- {
- var status = data.status;
- var tags = data.data;
-
- // Si on spécifie une erreur
- if (status == 'error')
- {
- // On l'affiche a l'utilisateur
- span_info.text(data.error);
- }
- // Si c'est un succés
- else if (status == 'success')
- {
- if (tags.length > 0)
- {
- var more = false;
- // Pour chaque tags retournés
- for (i in tags)
- {
- var tag_name = tags[i]['name'];
- var tag_id = tags[i]['id'];
- var t_string = tag_name
- // On construit un li
-
- var r_string = $.trim(input.val());
- var re = new RegExp(r_string, "i");
- t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
-
-
- var li_tag =
- $('<li>').append(
- $('<a>').attr('id','searched_tag_'+tag_id+'_'+tag_name)
- .attr('href', '#')
- // qui réagit quand on clique dessus
- .click(function(e){
- // On récupère le nom du tag
- var name = $(this).attr('id').substr(13,$(this).attr('id').length);
- name = name.substr(strpos(name, '_')+1, name.length);
-
- var id = $(this).attr('id').substr(13,$(this).attr('id').length);
- id = str_replace(name, '', id);
- id = str_replace('_', '', id);
-
- $('input#tags_selected_tag_'+form_name).val(id);
- inputTag.val(name);
- // Et on execute l'évènement selectTag de l'input
- inputTag.trigger("selectTag");
- // On cache la liste puisque le choix vient d'être fait
- divtags.hide();
- inputTag.val(tag_text_help);
- return false;
- })
- .append(t_string)
- );
-
- // Si on depasse les 30 tags
- if (i > 30)
- {
- more = true;
- // On le cache
- li_tag.hide();
- }
-
- // On ajout ce li a la liste
- search_tag_list.append(li_tag);
- }
-
- if (more)
- {
- divtags.find('a.more').show();
- }
-
- span_info.show();
- span_info.text(data.message);
- // Et on affiche la liste
- search_tag_list.show();
- }
- else
- {
- span_info.show();
- span_info.text(data.message);
- search_tag_list.show();
-
- // Dans ce cas ou aucun tag n'a été trouvé, la proposition
- // d'ajout s'affichecf en dessous
-
- //span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
- }
-
- // Si le tag ne semble pas connu en base
- if (!data.same_found)
- {
- // Cette variable nous permettra de stocker le lien nouveau tag
- var link_add_tag = null;
-
- li_tag =
- $('<li>').addClass('new').append(
- $('<a>').attr('href','#new#'+$.trim(input.val()))
- // qui réagit quand on clique dessus
- .click(function(e){
-
- // Effet fade-in du fond opaque
- $('body').append($('<div>').attr('id', 'fade'));
- //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
- $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
-
- // On met le lien cliqué dans la variabke prévu
- link_add_tag = $(this);
-
- // En premier lieux on fait apparaître la fenêtre de confirmation
- var popup = $('<div>')
- .attr('id', 'add_tag')
- .addClass('popin_block')
- .css('width', '400px')
- //.append($('<h2>').append(string_tag_add_title))
- .append($('<div>').addClass('tag')
- .append($('<ul>')
- .append($('<li>').addClass('button')
- .append($(this).text()))))
- .append($('<p>').append(string_tag_add_text))
- .append($('<p>').append(string_tag_add_argument))
- .append($('<textarea>').attr('name', 'argument'))
- .append($('<div>').addClass('inputs')
- .append($('<input>')
- .attr('type', 'button')
- .attr('value', string_tag_add_inputs_cancel)
- .addClass('button')
- .click(function(){
- $('#fade').fadeOut(1000, function(){$('#fade').remove();});
- $('#add_tag').remove();
-
- return false;
- })
- )
- .append($('<input>')
- .attr('type', 'button')
- .attr('value', string_tag_add_inputs_submit)
- .addClass('button')
- .click(function(){
-
- var arguments = $('#add_tag textarea').val();
-
- $('#fade').fadeOut(400, function(){$('#fade').remove();});
- $('#add_tag').remove();
-
- // On récupère le nom du tag
- var name = link_add_tag.attr('href').substr(1,link_add_tag.attr('href').length);
- name = name.substr(strpos(name, '#')+1, name.length);
-
- link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
-
- var url;
- if (arguments)
- {
- url = url_add_tag+'/'+name+'/'+arguments;
- }
- else
- {
- url = url_add_tag+'/'+name;
- }
-
- // La on fait l'ajout en base en tant que nouveau tag
- $.getJSON(url, function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- var tag_id = response.tag_id;
- var tag_name = response.tag_name;
-
- $('input#tags_selected_tag_'+form_name).val(tag_id);
- inputTag.val(tag_name);
- // Et on execute l'évènement selectTag de l'input
- inputTag.trigger("selectTag");
- // On cache la liste puisque le choix vient d'être fait
- divtags.hide();
- inputTag.val(tag_text_help);
-
- link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
- });
-
- return false;
- })
- )
- )
- ;
-
- // Il faut ajouter le popup au dom avant de le positionner en css
- // Sinon la valeur height n'est pas encore calculable
- $('body').prepend(popup);
-
- //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
- var popMargTop = (popup.height() + 50) / 2;
- var popMargLeft = (popup.width() + 50) / 2;
-
- //On affecte le margin
- $(popup).css({
- 'margin-top' : -popMargTop,
- 'margin-left' : -popMargLeft
- });
-
- return false;
-
- })
- .append($.trim(input.val()))
- );
- search_tag_list.append(li_tag);
- }
-
- }
-
- // On cache le loader
- $('#tag_loader_'+form_name).hide();
- }
- });
-
- }
- }
-
-
- var last_keypress = 0;
-
- function check_timelaps_and_search(input, form_name, time_id, timed, info)
- {
- if (!timed)
- {
- // C'est une nouvelle touche (pas redirigé) on lui donne un id
- // et on met a jour l'id de la dernière pressé
- last_keypress = new Date().getTime();
- var this_time_id = last_keypress;
- }
- else
- {
- // Si elle a été redirigé, on met son id dans cette variable
- var this_time_id = time_id;
- }
-
- // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
- if (time_id != last_keypress && timed)
- {
- // elle disparait
- }
- else
- {
- //
- if ((new Date().getTime() - last_keypress) < 600 || timed == false)
- {
- // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
- // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
- // elle doit attendre au cas ou soit pressé.
- setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
- }
- else
- {
- // il n'y a plus a attendre, on envoie la demande de tag.
- autocomplete_tag(input, form_name);
- }
- }
- }
-
- // Autocompletion de tags
- $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
-
- var form_name = $(this).parents('form').attr('name');
- var code = (e.keyCode ? e.keyCode : e.which);
-
- if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
- {
- check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
- }
-
- });
-
- // Un click sur ce lien affiche tout les tags cachés de la liste
- $('div.search_tag_list a.more').live('click', function(){
- jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
- $(this).show();
- });
- $(this).hide();
- return false;
- });
-
- $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
- $('ul.tagbox li.input input[type="text"]').formDefaults();
-
- ////////////////// FIN TAG PROMPT ///////////////
-
- // Suppression d'un element
- $('a.group_remove_link').jConfirmAction({
- question : "Supprimer ce groupe ?",
- yesAnswer : "Oui",
- cancelAnswer : "Non",
- onYes: function(link){
- window.location = link.attr('href');
- return false;
- },
- onOpen: function(){},
- onClose: function(){}
- });
-
- // Selection Réseau global / Mon réseau
- $('div.select_network a').live('click', function(){
- var divSelect = $(this).parent('div');
- if ($(this).hasClass('all_network'))
- {
- divSelect.find('a.all_network').addClass('active');
- divSelect.find('a.my_network').removeClass('active');
- divSelect.find('select').val('network_public');
- }
- else
- {
- divSelect.find('a.my_network').addClass('active');
- divSelect.find('a.all_network').removeClass('active');
- divSelect.find('select').val('network_personal');
- }
- });
-
- // Ajout d'un element #ajouter
- $('form[name="add"] input[type="submit"]').live('click', function(){
- $('form[name="add"]').find('img.tag_loader').show();
- });
- $('form[name="add"]').ajaxForm(function(response) {
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- $('form[name="add"] img.tag_loader').hide();
- if (response.status == 'success')
- {
- $('form[name="add"]').find('ul.error_list').remove();
- $('ul.elements').prepend(response.html);
- $('form[name="add"] input[type="text"]').val('');
-
- if ($('form[name="search"]').length)
- {
- $('form[name="search"]').slideDown();
- }
- remove_tags('add');
- recolorize_element_list();
-
- $('div#element_add_box').slideUp();
-
- if (response.groups.length)
- {
- // Des groupes sont proposés pour diffuser cet élément
- $('div#added_element_to_group').slideDown();
- for (i in response.groups)
- {
- var group = response.groups[i];
- $('ul#groups_to_add_element').html('');
- $('ul#groups_to_add_element')
- .append($('<li>')
- .append($('<a>')
- .addClass('added_element_add_to_group')
- .attr('href', group.url)
- .append(group.name)
- )
- )
- ;
- }
- }
- else
- {
- $('a#element_add_link').show();
- }
-
- }
- else if (response.status == 'error')
- {
- $('form[name="add"]').find('ul.error_list').remove();
- var ul_errors = $('<ul>').addClass('error_list');
-
- for (i in response.errors)
- {
- ul_errors.append($('<li>').append(response.errors[i]));
- }
-
- $('form[name="add"]').prepend(ul_errors);
- }
-
- return false;
- });
-
- // Check périodique
- // TODO.
-
- /////////////////////
- var tags_ids_for_filter = new Array();
- // Filtre par tags (show, favorite)
- function refresh_elements_with_tags_selected(link)
- {
-
-
- // Puis on fait notre rekékéte ajax.
- $('ul.elements').html('');
- $('div.no_elements').hide();
- $('img.elements_more_loader').show();
- $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- $('ul.elements').html(response.html);
-
- if (response.count)
- {
- $('img.elements_more_loader').hide();
- $('span.elements_more').show();
- $('a.elements_more').show();
- }
- });
-
- return false;
- }
-
- function list_tag_clicked(link, erease)
- {
- if (erease)
- {
- $('ul#favorite_tags a.tag').removeClass('active');
- }
-
- // Ensuite on l'active ou le désactive
- if (link.hasClass('active'))
- {
- link.removeClass('active');
- }
- else
- {
- link.addClass('active');
- }
-
- // On construit notre liste de tags
- tags_ids_for_filter = new Array();
- $('ul#favorite_tags a.tag.active').each(function(index){
- var id = str_replace('filtering_tag_', '', $(this).attr('id'));
- tags_ids_for_filter[id] = id;
- });
-
- // On adapte le lien afficher plus de résultats
- var a_more = $('a.elements_more');
- a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
-
- return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
- }
-
- $('ul#favorite_tags a.tag').click(function(){
- list_tag_clicked($(this));
- });
-
- last_keypress = 0;
- function check_timelaps_and_find_with_tags(link, time_id, timed)
- {
- if (!timed)
- {
- // C'est une nouvelle touche (pas redirigé) on lui donne un id
- // et on met a jour l'id de la dernière pressé
- last_keypress = new Date().getTime();
- var this_time_id = last_keypress;
- }
- else
- {
- // Si elle a été redirigé, on met son id dans cette variable
- var this_time_id = time_id;
- }
-
- // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
- if (time_id != last_keypress && timed)
- {
- // elle disparait
- }
- else
- {
- //
- if ((new Date().getTime() - last_keypress) < 800 || timed == false)
- {
- // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
- // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
- // elle doit attendre au cas ou soit pressé.
- setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
- }
- else
- {
- // il n'y a plus a attendre, on envoie la demande de tag.
- return refresh_elements_with_tags_selected(link);
- }
- }
-
- return null;
- }
-
- ////////////////////////////////////////
- /// Gestion de nouveaux éléments
-
- var do_check_new_elements = false;
-
- function check_new_elements()
- {
- if ($('ul.elements li').length)
- {
- // Si l'utilisateur a quitté la page on reporte le check
- if ($('body.blurred').length)
- {
- // on passe la variable a vrai de façon a ce que lorsque la page
- // et ré affiché on lance le check
- do_check_new_elements = true;
- }
- else
- {
- var url = url_element_new_count
- +'/'
- +str_replace('element_', '', $('ul.elements li:first').attr('id'))
- ;
- $.getJSON(url, function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success' && response.count)
- {
- $('div.display_more_elements').show();
- $('div.display_more_elements span').html(response.message);
- }
-
- setTimeout(check_new_elements, 150000);
- });
- do_check_new_elements = false;
- }
-
- }
- }
-
- if ($('div.display_more_elements').length)
- {
- setTimeout(check_new_elements, 150000);
- }
-
- $('a.show_new_elements').live('click', function(){
- var url = url_element_new_get
- +'/'
- +str_replace('element_', '', $('ul.elements li:first').attr('id'))
- ;
- $('img.elements_new_loader').show();
- $.getJSON(url, function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- if (response.count)
- {
- $('div.display_more_elements').show();
- $('div.display_more_elements span').html(response.message);
- }
- else
- {
- $('div.display_more_elements').hide();
- }
-
- $('ul.elements').prepend(response.html);
- recolorize_element_list();
- }
-
- $('img.elements_new_loader').hide();
- });
- });
-
- function recolorize_element_list()
- {
- $('ul.elements li.element').each(function(index){
- if ((index & 1) == 1)
- {
- $(this).removeClass('even');
- $(this).removeClass('odd');
- $(this).addClass('odd');
- }
- else
- {
- $(this).removeClass('odd');
- $(this).removeClass('even');
- $(this).addClass('even');
- }
- });
- }
-
- /*
- * Action a effectuer lorsque l'utilisateur met le focus sur la page
- */
- function do_action_body_focused()
- {
- if (do_check_new_elements)
- {
- check_new_elements();
- }
- }
-
- /*
- * Commentaires d'élément
- */
-
- // Afficher les commentaires
- $('td.element_content a.display_comments').live('click', function(){
- display_comments($(this).parents('li.element'));
- });
-
- $('td.element_content a.hide_comments').live('click', function(){
- hide_comments($(this).parents('li.element'));
- });
-
- function display_comments(li_element)
- {
- li_element.find('div.comments').slideDown();
- li_element.find('a.display_comments').hide();
- li_element.find('a.hide_comments').show();
- }
-
- function hide_comments(li_element)
- {
- li_element.find('div.comments').slideUp();
- li_element.find('a.display_comments').show();
- li_element.find('a.hide_comments').hide();
- }
-
- // Ajouter un commentaire
- $('li.element a.add_comment').live('click', function(){
- display_add_comment($(this).parents('li.element'));
- });
-
- $('form.add_comment input[type="submit"]').live('click', function(){
- $(this).parents('div.comments').find('img.comments_loader').show();
- });
-
- function display_add_comment(li_element)
- {
- display_comments(li_element);
- li_element.find('a.add_comment').hide();
- li_element.find('form.add_comment').show();
-
- li_element.find('form.add_comment').ajaxForm(function(response) {
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li_element.find('img.comments_loader').hide();
-
- if (response.status == 'success')
- {
- li_element.find('form.add_comment').find('ul.error_list').remove();
- li_element.find('div.comments ul.comments').append(response.html);
- hide_add_comment(li_element);
- }
- else if (response.status == 'error')
- {
- li_element.find('form.add_comment').find('ul.error_list').remove();
- var ul_errors = $('<ul>').addClass('error_list');
-
- for (i in response.errors)
- {
- ul_errors.append($('<li>').append(response.errors[i]));
- }
-
- li_element.find('form.add_comment').prepend(ul_errors);
- }
-
- return false;
- });
-
- }
-
- $('form.add_comment input.cancel').live('click', function(){
- var li_element = $(this).parents('li.element');
- hide_add_comment(li_element);
- });
-
- function hide_add_comment(li_element)
- {
- li_element.find('a.add_comment').show();
- li_element.find('form.add_comment').hide();
- li_element.find('form.add_comment textarea').val('');
- }
-
- // Modifier et supprimer
- // Affichage du bouton Modifier et Supprimer
- $('ul.comments li.comment').live({
- mouseenter:
- function()
- {
- $(this).find('a.comment_edit_link').show();
- $(this).find('a.comment_remove_link').show();
- },
- mouseleave:
- function()
- {
- if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
- {
- $(this).find('a.comment_edit_link').hide();
- }
- if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
- {
- $(this).find('a.comment_remove_link').hide();
- }
- }
- }
- );
-
- // Supprimer
- $('a.comment_remove_link').jConfirmAction({
- question : string_comment_delete_confirm_sentence,
- yesAnswer : string_comment_delete_confirm_yes,
- cancelAnswer : string_comment_delete_confirm_no,
- onYes: function(link){
-
- var li = link.parents('li.comment');
- li.find('img.comment_loader').show();
-
- $.getJSON(link.attr('href'), function(response){
-
- li.find('img.comment_loader').hide();
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- li.remove();
- }
- });
-
- return false;
- },
- onOpen: function(link){
- var li = link.parents('li.comment');
- li.find('a.comment_edit_link').addClass('mustBeDisplayed');
- li.find('a.comment_remove_link').addClass('mustBeDisplayed');
- },
- onClose: function(link){
- var li = link.parents('li.comment');
- li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
- li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
- li.find('a.comment_edit_link').hide();
- li.find('a.comment_remove_link').hide();
- }
- });
-
- var comments_edited = new Array();
-
- // Modification
- // Ouverture du formulaire de modification
- $('a.comment_edit_link').live('click', function(){
-
- var link = $(this);
- var li = link.parents('li.comment');
- // On garde en mémoire l'élément édité en cas d'annulation
- comments_edited[li.attr('id')] = li.html();
- var loader = li.find('img.comment_loader');
- li.html(loader);
- li.find('img.comment_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li.html(response.html);
- // On rend ce formulaire ajaxFormable
- $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
- var li_current = $(this).parents('li.comment');
- li_current.prepend(loader);
- li_current.find('img.comment_loader').show();
- });
-
- li.find('form.edit_comment').ajaxForm(function(response){
-
- li = $('li#'+response.dom_id);
- li.find('img.comment_loader').hide();
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- li.html(response.html);
- delete(comments_edited[li.attr('id')]);
- }
- else if (response.status == 'error')
- {
- li.find('ul.error_list').remove();
- var ul_errors = $('<ul>').addClass('error_list');
-
- for (i in response.errors)
- {
- ul_errors.append($('<li>').append(response.errors[i]));
- }
-
- li.prepend(ul_errors);
- }
- });
-
- });
- return false;
- });
-
- // Annulation d'un formulaire de modification d'un comment
- $('form.edit_comment input.cancel').live('click', function(){
- var li = $(this).parents('li.comment');
- li.html(comments_edited[li.attr('id')]);
- delete(comments_edited[li.attr('id')]);
- });
-
- /*
- * Ajout d'un tag en favoris a partir d'un élément
- */
-
- $('li.element_tag').live({
- mouseenter:
- function()
- {
- $(this).find('a.tag_to_favorites').show();
- $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
- },
- mouseleave:
- function()
- {
- if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
- {
- $(this).find('a.tag_to_favorites').hide();
- $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
- }
- }
- }
- );
-
- $('a.tag_to_favorites').jConfirmAction({
- question : string_tag_addtofav_confirm_sentence,
- yesAnswer : string_tag_addtofav_confirm_yes,
- cancelAnswer : string_tag_addtofav_confirm_no,
- onYes: function(link){
-
- $.getJSON(link.attr('href'), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
- });
-
- $('div.question').fadeOut();
- return false;
- },
- onOpen: function(link){
- var li = link.parents('li.element_tag');
- li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
- },
- onClose: function(link){
- var li = link.parents('li.element_tag');
- li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
- li.find('a.element_tag').removeClass('element_tag_large_for_fav');
- li.find('a.tag_to_favorites').hide();
- }
- });
-
- /*
- * Ajout dans un groupe de l'élément envoyé
- */
-
- $('a.added_element_add_to_group').live('click', function(){
-
- var loader = $('div#added_element_to_group').find('img.loader');
- loader.show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- loader.hide();
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- $('li#'+response.dom_id).html(response.html);
- }
-
- $('div#added_element_to_group').slideUp();
- $('a#element_add_link').show();
-
- });
- return false;
- });
-
- $('div#added_element_to_group a.cancel').live('click', function(){
- $('div#added_element_to_group').slideUp();
- $('a#element_add_link').show();
- return false;
- });
-
- /*
- * Report / signalement d'un élément
- */
-
- $('a.element_report').jConfirmAction({
- question : string_elementreport_confirm_sentence,
- yesAnswer : string_elementreport_confirm_yes,
- cancelAnswer : string_elementreport_confirm_no,
- onYes: function(link){
-
- $.getJSON(link.attr('href'), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
- });
-
- $('div.question').fadeOut();
- return false;
- },
- onOpen: function(link){
-
- },
- onClose: function(link){
-
- }
- });
-
- /*
- * Vote sur element
- */
-
- $('li.element a.vote').live('click', function(){
-
- var img = $(this).find('img');
- var link = $(this);
- img.attr('src', url_img_ajax_loader);
-
- $.getJSON(link.attr('href'), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- link.attr('href', response.data.a.href);
- img.attr('src', response.data.img.src);
- link.parents('td.right').find('li.score span.score').html(response.data.element.points);
- }
-
- });
-
- return false;
- });
-
-
- // Enlever les ids du ElementSearch
- $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
-
- $('img.elements_more_loader').show();
- $('ul.elements').html('');
- var link = $(this);
-
- $.getJSON(link.attr('href'), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- $('form[name="search"]').submit();
- $('div.more_filters a.new_comments').hide();
- $('div.more_filters a.new_favorites').hide();
- $('div.more_filters a.new_tags').hide();
- }
-
- });
-
- return false;
- });
-
- /*
- *
- * Proposition de tags sur un élément
- *
- */
-
- // Ouverture du formulaire de modification
- $('a.element_propose_tags').live('click', function(){
-
- var link = $(this);
- var li = link.parents('li.element');
-
- li.find('img.element_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li.find('img.element_loader').hide();
-
- if (response.status == 'success')
- {
-
- // On prépare le tagBox
- var table = li.find('table:first');
- li.find('div.tag_proposition').remove();
- table.after(response.html);
-
- // Pour le click sur l'input de saisie de tag
- li.find('ul.tagbox li.input input[type="text"]').formDefaults();
-
- var options = new Array();
- options.form_name = response.form_name;
- options.tag_init = response.tags;
-
- ajax_query_timestamp = null;
-
- $("#tags_prompt_list_"+response.form_name).tagBox(options);
-
- // On rend ce formulaire ajaxFormable
- $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
- li = $(this).parents('li.element');
- li.find('img.element_loader').show();
- });
- $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- if (response.status == 'success')
- {
- li = $('li#'+response.dom_id);
- li.find('img.element_loader').hide();
- li.find('form')
- li.find('div.tag_proposition').remove();
- }
- else if (response.status == 'error')
- {
- li.find('img.element_loader').hide();
- li.find('ul.error_list').remove();
- var ul_errors = $('<ul>').addClass('error_list');
-
- for (i in response.errors)
- {
- ul_errors.append($('<li>').append(response.errors[i]));
- }
-
- li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
- }
-
- });
-
- }
- });
- return false;
- });
-
- // Annulation d'un formulaire de modification d'élément
- $('div.tag_proposition input.cancel').live('click', function(){
- $(this).parents('div.tag_proposition').slideUp();
- });
-
- // Ouvrir les propositions de tags de l'élément
- $('a.element_view_propositions_link').live('click', function(){
-
- var link = $(this);
- li = link.parents('li.element');
-
- li.find('img.element_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li.find('img.element_loader').hide();
-
- if (response.status == 'success')
- {
- var table = li.find('table:first');
- li.find('div.tags_proposition_view').remove();
- table.after(response.html);
- }
- });
-
- return false;
- });
-
- $('a.accept_tag_propotision').live('click', function(){
-
- var link = $(this);
- var li = link.parents('li.element');
-
- li.find('img.element_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li.find('img.element_loader').hide();
-
- if (response.status == 'success')
- {
- li.html(response.html);
- }
- });
-
- return false;
- });
-
- //
- $('a.refuse_tag_propositions').live('click', function(){
-
- var link = $(this);
- var li = link.parents('li.element');
-
- li.find('img.element_loader').show();
-
- $.getJSON($(this).attr('href'), function(response) {
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
-
- li.find('img.element_loader').hide();
-
- if (response.status == 'success')
- {
- li.find('div.tags_proposition_view').remove();
- }
- });
-
- return false;
- });
-
- /*
- * Proposition de tag sur un élément FIN
- */
-
- /*
- * Report / signalement d'un commentaire
- */
-
- $('a.comment_report').jConfirmAction({
- question : string_commentreport_confirm_sentence,
- yesAnswer : string_commentreport_confirm_yes,
- cancelAnswer : string_commentreport_confirm_no,
- onYes: function(link){
-
- $.getJSON(link.attr('href'), function(response){
-
- if (response.status == 'mustbeconnected')
- {
- $(location).attr('href', url_index);
- }
- });
-
- $('div.question').fadeOut();
- return false;
- },
- onOpen: function(link){
-
- },
- onClose: function(link){
-
- }
- });
-
- });
|