muzich.js 57KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. /*
  2. * Scripts de Muzi.ch
  3. * Rédigé et propriété de Sevajol Bastien (http://www.bux.fr) sauf si mention
  4. * contraire sur la fonction.
  5. *
  6. */
  7. // Messages flashs
  8. var myMessages = ['info','warning','error','success']; // define the messages types
  9. function hideAllMessages()
  10. {
  11. var messagesHeights = new Array(); // this array will store height for each
  12. for (i=0; i<myMessages.length; i++)
  13. {
  14. messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
  15. $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
  16. }
  17. }
  18. $(document).ready(function(){
  19. // Initially, hide them all
  20. hideAllMessages();
  21. $('.message').animate({top:"0"}, 500);
  22. // When message is clicked, hide it
  23. $('.message a.message-close').click(function(){
  24. $(this).parent('.message').animate({top: -$(this).outerHeight()-50}, 700);
  25. return false;
  26. });
  27. });
  28. function findKeyWithValue(arrayt, value)
  29. {
  30. for(i in arrayt)
  31. {
  32. if (arrayt[i] == value)
  33. {
  34. return i;
  35. }
  36. }
  37. return "";
  38. }
  39. function json_to_array(json_string)
  40. {
  41. if (json_string.length)
  42. {
  43. return eval("(" + json_string + ")");
  44. }
  45. return new Array();
  46. }
  47. function strpos (haystack, needle, offset) {
  48. // Finds position of first occurrence of a string within another
  49. //
  50. // version: 1109.2015
  51. // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  52. // + improved by: Onno Marsman
  53. // + bugfixed by: Daniel Esteban
  54. // + improved by: Brett Zamir (http://brett-zamir.me)
  55. // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
  56. var i = (haystack + '').indexOf(needle, (offset || 0));
  57. return i === -1 ? false : i;
  58. }
  59. /**
  60. * Converts the given data structure to a JSON string.
  61. * Argument: arr - The data structure that must be converted to JSON
  62. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  63. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  64. * http://www.openjs.com/scripts/data/json_encode.php
  65. */
  66. function array2json(arr) {
  67. var parts = [];
  68. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  69. for(var key in arr) {
  70. var value = arr[key];
  71. if(typeof value == "object") { //Custom handling for arrays
  72. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  73. else parts[key] = array2json(value); /* :RECURSION: */
  74. } else {
  75. var str = "";
  76. if(!is_list) str = '"' + key + '":';
  77. //Custom handling for multiple data types
  78. if(typeof value == "number") str += value; //Numbers
  79. else if(value === false) str += 'false'; //The booleans
  80. else if(value === true) str += 'true';
  81. else str += '"' + value + '"'; //All other things
  82. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  83. parts.push(str);
  84. }
  85. }
  86. var json = parts.join(",");
  87. if(is_list) return '[' + json + ']';//Return numerical JSON
  88. return '{' + json + '}';//Return associative JSON
  89. }
  90. function isInteger(s) {
  91. return (s.toString().search(/^-?[0-9]+$/) == 0);
  92. }
  93. function inArray(array, p_val) {
  94. var l = array.length;
  95. for(var i = 0; i < l; i++) {
  96. if(array[i] == p_val) {
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. if(typeof(String.prototype.trim) === "undefined")
  103. {
  104. String.prototype.trim = function()
  105. {
  106. return String(this).replace(/^\s+|\s+$/g, '');
  107. };
  108. }
  109. function str_replace (search, replace, subject, count) {
  110. // Replaces all occurrences of search in haystack with replace
  111. //
  112. // version: 1109.2015
  113. // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  114. // + improved by: Gabriel Paderni
  115. // + improved by: Philip Peterson
  116. // + improved by: Simon Willison (http://simonwillison.net)
  117. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
  118. // + input by: Onno Marsman
  119. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  120. // + tweaked by: Onno Marsman
  121. // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  122. // + input by: Oleg Eremeev
  123. // + improved by: Brett Zamir (http://brett-zamir.me)
  124. // + bugfixed by: Oleg Eremeev
  125. // % 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
  126. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  127. // * returns 1: 'Kevin.van.Zonneveld'
  128. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  129. // * returns 2: 'hemmo, mars' var i = 0,
  130. j = 0,
  131. temp = '',
  132. repl = '',
  133. sl = 0, fl = 0,
  134. f = [].concat(search),
  135. r = [].concat(replace),
  136. s = subject,
  137. ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
  138. s = [].concat(s);
  139. if (count) {
  140. this.window[count] = 0;
  141. }
  142. for (i = 0, sl = s.length; i < sl; i++) {
  143. if (s[i] === '') {
  144. continue;
  145. }for (j = 0, fl = f.length; j < fl; j++) {
  146. temp = s[i] + '';
  147. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  148. s[i] = (temp).split(f[j]).join(repl);
  149. if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
  150. }
  151. }
  152. }
  153. return sa ? s : s[0];
  154. }
  155. function explode (delimiter, string, limit) {
  156. // 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.
  157. //
  158. // version: 1109.2015
  159. // discuss at: http://phpjs.org/functions/explode // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  160. // + improved by: kenneth
  161. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  162. // + improved by: d3x
  163. // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: explode(' ', 'Kevin van Zonneveld');
  164. // * returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
  165. // * example 2: explode('=', 'a=bc=d', 2);
  166. // * returns 2: ['a', 'bc=d']
  167. var emptyArray = {0: ''
  168. };
  169. // third argument is not required
  170. if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {return null;
  171. }
  172. if (delimiter === '' || delimiter === false || delimiter === null) {
  173. return false;}
  174. if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
  175. return emptyArray;
  176. }
  177. if (delimiter === true) {
  178. delimiter = '1';
  179. }
  180. if (!limit) {
  181. return string.toString().split(delimiter.toString());
  182. }
  183. // support for limit argument
  184. var splitted = string.toString().split(delimiter.toString());var partA = splitted.splice(0, limit - 1);
  185. var partB = splitted.join(delimiter.toString());
  186. partA.push(partB);
  187. return partA;
  188. }
  189. // fonction de nettoyage des tags
  190. function remove_tags(form_name)
  191. {
  192. tagsAddeds[form_name] = new Array();
  193. $('form[name="'+form_name+'"] ul.tagbox li.tag').remove();
  194. $('form[name="'+form_name+'"] input.tagBox_tags_ids').val('');
  195. $('div#tags_prompt_'+form_name+' ul.tagbox li.input input[type="text"]')
  196. .val(string_tag_prompt_input_help)
  197. ;
  198. }
  199. $(document).ready(function(){
  200. // Controle du focus sur la page
  201. function onBlur() {
  202. document.body.className = 'blurred';
  203. }
  204. function onFocus(){
  205. document.body.className = 'focused';
  206. do_action_body_focused();
  207. }
  208. if (/*@cc_on!@*/false) { // check for Internet Explorer
  209. document.onfocusin = onFocus;
  210. document.onfocusout = onBlur;
  211. } else {
  212. window.onfocus = onFocus;
  213. window.onblur = onBlur;
  214. }
  215. // Bouton de personalisation du filtre
  216. // Aucun tags
  217. $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
  218. $('img.elements_more_loader').show();
  219. $('ul.elements').html('');
  220. var form = $('form[name="search"]');
  221. remove_tags(form.attr('name'));
  222. form.submit();
  223. });
  224. // tags préférés
  225. $('.tags_prompt input.mytags').live("click", function(){
  226. $('img.elements_more_loader').show();
  227. $('ul.elements').html('');
  228. var form = $(this).parents('form[name="search"]');
  229. $.getJSON(url_get_favorites_tags, function(response) {
  230. if (response.status == 'mustbeconnected')
  231. {
  232. $(location).attr('href', url_index);
  233. }
  234. remove_tags(form.attr('name'));
  235. // if (tags.length)
  236. // {
  237. var inputTag = $("div#tags_prompt_"+form.attr('name')+" input.form-default-value-processed");
  238. for (i in response.tags)
  239. {
  240. $('input#tags_selected_tag_'+form.attr('name')).val(i);
  241. inputTag.val(response.tags[i]);
  242. // Et on execute l'évènement selectTag de l'input
  243. inputTag.trigger("selectTag");
  244. }
  245. form.submit();
  246. //}
  247. });
  248. });
  249. // Tag cliqué dans la liste d'éléments
  250. $('ul.element_tags li a.element_tag').live('click', function(){
  251. // Si il y a une liste de tags (comme sur la page favoris, profil)
  252. var id;
  253. if ($('ul#favorite_tags').length)
  254. {
  255. id = str_replace('element_tag', '', $(this).attr('id'));
  256. var link = $('ul#favorite_tags li a[href="#'+id+'"]');
  257. list_tag_clicked(link, true);
  258. }
  259. if ($('form[name="search"]').length)
  260. {
  261. $('img.elements_more_loader').show();
  262. $('ul.elements').html('');
  263. var form = $('form[name="search"]');
  264. id = str_replace('element_tag', '', $(this).attr('id'));
  265. remove_tags('search');
  266. var inputTag = $("div#tags_prompt_search input.form-default-value-processed");
  267. $('input#tags_selected_tag_search').val(id);
  268. inputTag.val($(this).html());
  269. inputTag.trigger("selectTag");
  270. form.submit();
  271. }
  272. });
  273. function element_last_opened(li)
  274. {
  275. $('li.element').removeClass('shadows');
  276. li.addClass('shadows');
  277. }
  278. // Affichage un/des embed
  279. // 1328283150_media-playback-start.png
  280. // 1328283201_emblem-symbolic-link.png
  281. $('a.element_embed_open_link').live("click", function(){
  282. var li = $(this).parents('li.element');
  283. element_last_opened(li);
  284. li.find('a.element_embed_close_link').show();
  285. li.find('a.element_embed_open_link_text').hide();
  286. li.find('div.element_embed').show();
  287. return false;
  288. });
  289. $('a.element_name_embed_open_link').live("click", function(){
  290. var li = $(this).parents('li.element');
  291. element_last_opened(li);
  292. li.find('a.element_embed_close_link').show();
  293. li.find('a.element_embed_open_link_text').hide();
  294. li.find('div.element_embed').show();
  295. return false;
  296. });
  297. // Fermeture du embed si demandé
  298. $('a.element_embed_close_link').live("click", function(){
  299. var li = $(this).parents('li.element');
  300. li.removeClass('shadows');
  301. li.find('div.element_embed').hide();
  302. li.find('a.element_embed_open_link_text').show();
  303. $(this).hide();
  304. return false;
  305. });
  306. // Affichage du "play" ou du "open" (image png)
  307. $('li.element a.a_thumbnail, li.element img.open, li.element img.play').live({
  308. mouseenter:
  309. function()
  310. {
  311. var td = $(this).parent('td');
  312. var a = td.find('a.a_thumbnail');
  313. if (a.hasClass('embed'))
  314. {
  315. td.find('img.play').show();
  316. }
  317. else
  318. {
  319. td.find('img.open').show();
  320. }
  321. },
  322. mouseleave:
  323. function()
  324. {
  325. var td = $(this).parent('td');
  326. var a = td.find('a.a_thumbnail');
  327. if (a.hasClass('embed'))
  328. {
  329. td.find('img.play').hide();
  330. }
  331. else
  332. {
  333. td.find('img.open').hide();
  334. }
  335. }
  336. }
  337. );
  338. // Mise en favoris
  339. $('a.favorite_link').live("click", function(){
  340. var link = $(this);
  341. // Pour ne pas attendre la fin du chargement ajax:
  342. var img = link.find('img');
  343. if (!link.hasClass('loading'))
  344. {
  345. if (img.attr('src') == '/bundles/muzichcore/img/favorite_bw.png')
  346. {
  347. img.attr('src', '/bundles/muzichcore/img/favorite.png');
  348. }
  349. else
  350. {
  351. img.attr('src', '/bundles/muzichcore/img/favorite_bw.png');
  352. }
  353. }
  354. link.addClass('loading');
  355. $.getJSON($(this).attr('href'), function(response) {
  356. if (response.status == 'mustbeconnected')
  357. {
  358. $(location).attr('href', url_index);
  359. }
  360. var img = link.find('img');
  361. link.attr('href', response.link_new_url);
  362. img.attr('src', response.img_new_src);
  363. img.attr('title', response.img_new_title);
  364. link.removeClass('loading');
  365. });
  366. return false;
  367. });
  368. // Affichage du bouton Modifier et Supprimer
  369. $('ul.elements li.element').live({
  370. mouseenter:
  371. function()
  372. {
  373. $(this).find('a.element_edit_link').show();
  374. $(this).find('a.element_remove_link').show();
  375. },
  376. mouseleave:
  377. function()
  378. {
  379. if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
  380. {
  381. $(this).find('a.element_edit_link').hide();
  382. }
  383. if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
  384. {
  385. $(this).find('a.element_remove_link').hide();
  386. }
  387. }
  388. }
  389. );
  390. // Plus d'éléments
  391. var last_id = null;
  392. $('a.elements_more').click(function(){
  393. var link = $(this);
  394. var last_element = $('ul.elements li.element:last-child');
  395. var id_last = str_replace('element_', '', last_element.attr('id'));
  396. var invertcolor = 0;
  397. if (last_element.hasClass('even'))
  398. {
  399. invertcolor = 1;
  400. }
  401. $('img.elements_more_loader').show();
  402. $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
  403. if (response.status == 'mustbeconnected')
  404. {
  405. $(location).attr('href', url_index);
  406. }
  407. if (response.count)
  408. {
  409. $('ul.elements').append(response.html);
  410. $('img.elements_more_loader').hide();
  411. }
  412. if (response.end || response.count < 1)
  413. {
  414. $('img.elements_more_loader').hide();
  415. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  416. response.message+'</p></div>');
  417. link.hide();
  418. }
  419. });
  420. return false;
  421. });
  422. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  423. // Filtre et affichage éléments ajax
  424. $('form[name="search"] input[type="submit"]').click(function(){
  425. $('ul.elements').html('');
  426. $('div.no_elements').hide();
  427. $('img.elements_more_loader').show();
  428. });
  429. $('form[name="search"]').ajaxForm(function(response) {
  430. if (response.status == 'mustbeconnected')
  431. {
  432. $(location).attr('href', url_index);
  433. }
  434. $('ul.elements').html(response.html);
  435. if (response.count)
  436. {
  437. $('img.elements_more_loader').hide();
  438. $('span.elements_more').show();
  439. $('a.elements_more').show();
  440. }
  441. if (response.count < 1)
  442. {
  443. $('img.elements_more_loader').hide();
  444. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  445. response.message+'</p></div>');
  446. $('a.elements_more').hide()
  447. ;
  448. }
  449. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  450. });
  451. // Suppression d'un element
  452. $('a.element_remove_link').jConfirmAction({
  453. question : string_element_delete_confirm_sentence,
  454. yesAnswer : string_element_delete_confirm_yes,
  455. cancelAnswer : string_element_delete_confirm_no,
  456. onYes: function(link){
  457. var li = link.parents('li.element');
  458. li.find('img.element_loader').show();
  459. $.getJSON(link.attr('href'), function(response){
  460. if (response.status == 'mustbeconnected')
  461. {
  462. $(location).attr('href', url_index);
  463. }
  464. if (response.status == 'success')
  465. {
  466. li.remove();
  467. }
  468. else
  469. {
  470. li.find('img.element_loader').hide();
  471. }
  472. });
  473. return false;
  474. },
  475. onOpen: function(link){
  476. var li = link.parents('li.element');
  477. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  478. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  479. },
  480. onClose: function(link){
  481. var li = link.parents('li.element');
  482. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  483. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  484. li.find('a.element_edit_link').hide();
  485. li.find('a.element_remove_link').hide();
  486. }
  487. });
  488. var elements_edited = new Array();
  489. // Ouverture du formulaire de modification
  490. $('a.element_edit_link').live('click', function(){
  491. var link = $(this);
  492. var li = link.parents('li.element');
  493. // On garde en mémoire l'élément édité en cas d'annulation
  494. elements_edited[li.attr('id')] = li.html();
  495. var div_loader = li.find('div.loader');
  496. li.html(div_loader);
  497. li.find('img.element_loader').show();
  498. $.getJSON($(this).attr('href'), function(response) {
  499. if (response.status == 'mustbeconnected')
  500. {
  501. $(location).attr('href', url_index);
  502. }
  503. // On prépare le tagBox
  504. li.html(response.html);
  505. // Pour le click sur l'input de saisie de tag
  506. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  507. var options = new Array();
  508. options.form_name = response.form_name;
  509. options.tag_init = response.tags;
  510. ajax_query_timestamp = null;
  511. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  512. // On rend ce formulaire ajaxFormable
  513. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  514. var li = $(this).parents('li.element');
  515. li.prepend(div_loader);
  516. li.find('img.element_loader').show();
  517. });
  518. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  519. if (response.status == 'mustbeconnected')
  520. {
  521. $(location).attr('href', url_index);
  522. }
  523. var li = $('li#'+response.dom_id);
  524. if (response.status == 'success')
  525. {
  526. li.html(response.html);
  527. delete(elements_edited[li.attr('id')]);
  528. }
  529. else if (response.status == 'error')
  530. {
  531. li.find('img.element_loader').hide();
  532. li.find('ul.error_list').remove();
  533. var ul_errors = $('<ul>').addClass('error_list');
  534. for (i in response.errors)
  535. {
  536. ul_errors.append($('<li>').append(response.errors[i]));
  537. }
  538. li.prepend(ul_errors);
  539. }
  540. });
  541. });
  542. return false;
  543. });
  544. // Annulation d'un formulaire de modification d'élément
  545. $('form.edit_element input.cancel_edit').live('click', function(){
  546. var li = link.parents('li.element');
  547. li.html(elements_edited[li.attr('id')]);
  548. delete(elements_edited[li.attr('id')]);
  549. });
  550. ////////////////// TAG PROMPT ///////////////
  551. var ajax_query_timestamp = null;
  552. var tag_text_help = $('input.tag_text_help').val();
  553. // Les deux clicks ci-dessous permettent de faire disparaitre
  554. // la div de tags lorsque l'on clique ailleurs
  555. $('html').click(function() {
  556. if ($("div.search_tag_list").is(':visible'))
  557. {
  558. $("div.search_tag_list").hide();
  559. }
  560. });
  561. $("div.search_tag_list, div.search_tag_list a.more").live('click', function(event){
  562. event.stopPropagation();
  563. $("div.search_tag_list").show();
  564. });
  565. function autocomplete_tag(input, form_name)
  566. {
  567. // Il doit y avoir au moin un caractère
  568. if ((input.val().length > 0) && (input.val() != string_tag_prompt_input_help))
  569. {
  570. // on met en variable l'input
  571. var inputTag = input;
  572. // On récupére la div de tags
  573. var divtags = $("#search_tag_"+form_name);
  574. // Si la fenêtre de tags est caché
  575. if (!divtags.is(':visible'))
  576. {
  577. // On la replace
  578. var position = input.position();
  579. divtags.css('left', Math.round(position.left) + 5);
  580. divtags.css('top', Math.round(position.top) + 28);
  581. // Et on l'affiche
  582. divtags.show();
  583. }
  584. // On affiche le loader
  585. $('#tag_loader_'+form_name).show();
  586. // On cache la liste de tags
  587. var search_tag_list = divtags.find('ul.search_tag_list');
  588. // On supprime les anciens li
  589. search_tag_list.find('li').remove();
  590. search_tag_list.hide();
  591. // Et on affiche une info
  592. var span_info = divtags.find('span.info');
  593. span_info.show();
  594. // TODO: multilingue !
  595. span_info.text(str_replace('%string_search%', input.val(), string_search_tag_title));
  596. // C'est en fonction du nb de resultats qu'il sera affiché
  597. divtags.find('a.more').hide();
  598. // On récupère le timestamp pour reconnaitre la dernière requête effectué
  599. ajax_query_timestamp = new Date().getTime();
  600. // Récupération des tags correspondants
  601. $.ajax({
  602. type: 'POST',
  603. url: url_search_tag+'/'+ajax_query_timestamp,
  604. dataType: 'json',
  605. data: {'string_search':input.val()},
  606. success: function(data) {
  607. if (data.status == 'mustbeconnected')
  608. {
  609. $(location).attr('href', url_index);
  610. }
  611. // Ce contrôle permet de ne pas continuer si une requete
  612. // ajax a été faite depuis.
  613. if (data.timestamp == ajax_query_timestamp)
  614. {
  615. var status = data.status;
  616. var tags = data.data;
  617. // Si on spécifie une erreur
  618. if (status == 'error')
  619. {
  620. // On l'affiche a l'utilisateur
  621. span_info.text(data.error);
  622. }
  623. // Si c'est un succés
  624. else if (status == 'success')
  625. {
  626. if (tags.length > 0)
  627. {
  628. var more = false;
  629. // Pour chaque tags retournés
  630. for (i in tags)
  631. {
  632. var tag_name = tags[i]['name'];
  633. var tag_id = tags[i]['id'];
  634. var t_string = tag_name
  635. // On construit un li
  636. var r_string = $.trim(input.val());
  637. var re = new RegExp(r_string, "i");
  638. t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
  639. var li_tag =
  640. $('<li>').append(
  641. $('<a>').attr('id','searched_tag_'+tag_id+'_'+tag_name)
  642. .attr('href', '#')
  643. // qui réagit quand on clique dessus
  644. .click(function(e){
  645. // On récupère le nom du tag
  646. var name = $(this).attr('id').substr(13,$(this).attr('id').length);
  647. name = name.substr(strpos(name, '_')+1, name.length);
  648. var id = $(this).attr('id').substr(13,$(this).attr('id').length);
  649. id = str_replace(name, '', id);
  650. id = str_replace('_', '', id);
  651. $('input#tags_selected_tag_'+form_name).val(id);
  652. inputTag.val(name);
  653. // Et on execute l'évènement selectTag de l'input
  654. inputTag.trigger("selectTag");
  655. // On cache la liste puisque le choix vient d'être fait
  656. divtags.hide();
  657. inputTag.val(tag_text_help);
  658. return false;
  659. })
  660. .append(t_string)
  661. );
  662. // Si on depasse les 30 tags
  663. if (i > 30)
  664. {
  665. more = true;
  666. // On le cache
  667. li_tag.hide();
  668. }
  669. // On ajout ce li a la liste
  670. search_tag_list.append(li_tag);
  671. }
  672. if (more)
  673. {
  674. divtags.find('a.more').show();
  675. }
  676. span_info.show();
  677. span_info.text(data.message);
  678. // Et on affiche la liste
  679. search_tag_list.show();
  680. }
  681. else
  682. {
  683. span_info.show();
  684. span_info.text(data.message);
  685. search_tag_list.show();
  686. // Dans ce cas ou aucun tag n'a été trouvé, la proposition
  687. // d'ajout s'affichecf en dessous
  688. //span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  689. }
  690. // Si le tag ne semble pas connu en base
  691. if (!data.same_found)
  692. {
  693. // Cette variable nous permettra de stocker le lien nouveau tag
  694. var link_add_tag = null;
  695. li_tag =
  696. $('<li>').addClass('new').append(
  697. $('<a>').attr('href','#new#'+$.trim(input.val()))
  698. // qui réagit quand on clique dessus
  699. .click(function(e){
  700. // Effet fade-in du fond opaque
  701. $('body').append($('<div>').attr('id', 'fade'));
  702. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  703. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  704. // On met le lien cliqué dans la variabke prévu
  705. link_add_tag = $(this);
  706. // En premier lieux on fait apparaître la fenêtre de confirmation
  707. var popup = $('<div>')
  708. .attr('id', 'add_tag')
  709. .addClass('popin_block')
  710. .css('width', '400px')
  711. //.append($('<h2>').append(string_tag_add_title))
  712. .append($('<form>')
  713. .attr('action', url_add_tag)
  714. .attr('method', 'post')
  715. .attr('name', 'add_tag')
  716. .ajaxForm(function(response) {
  717. /*
  718. *
  719. */
  720. if (response.status == 'mustbeconnected')
  721. {
  722. $(location).attr('href', url_index);
  723. }
  724. if (response.status == 'success')
  725. {
  726. var tag_id = response.tag_id;
  727. var tag_name = response.tag_name;
  728. $('input#tags_selected_tag_'+form_name).val(tag_id);
  729. inputTag.val(tag_name);
  730. // Et on execute l'évènement selectTag de l'input
  731. inputTag.trigger("selectTag");
  732. // On cache la liste puisque le choix vient d'être fait
  733. divtags.hide();
  734. inputTag.val(tag_text_help);
  735. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
  736. $('#fade').fadeOut(400, function(){$('#fade').remove();});
  737. $('#add_tag').remove();
  738. }
  739. if (response.status == 'error')
  740. {
  741. $('form[name="add_tag"]').find('ul.error_list').remove();
  742. var ul_errors = $('<ul>').addClass('error_list');
  743. for (i in response.errors)
  744. {
  745. ul_errors.append($('<li>').append(response.errors[i]));
  746. }
  747. $('form[name="add_tag"]').prepend(ul_errors);
  748. }
  749. return false;
  750. })
  751. .append($('<div>').addClass('tag')
  752. .append($('<ul>')
  753. .append($('<li>').addClass('button')
  754. .append($(this).text()))))
  755. .append($('<p>').append(string_tag_add_text))
  756. .append($('<p>').append(string_tag_add_argument))
  757. .append($('<textarea>').attr('name', 'argument'))
  758. .append($('<div>').addClass('inputs')
  759. .append($('<input>')
  760. .attr('type', 'button')
  761. .attr('value', string_tag_add_inputs_cancel)
  762. .addClass('button')
  763. .click(function(){
  764. $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  765. $('#add_tag').remove();
  766. return false;
  767. })
  768. )
  769. .append($('<input>')
  770. .attr('type', 'submit')
  771. .attr('value', string_tag_add_inputs_submit)
  772. .addClass('button')
  773. .click(function(){
  774. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
  775. })
  776. )
  777. .append($('<input>').attr('type', 'hidden').attr('name', 'tag_name').val($(this).text()))
  778. ))
  779. ;
  780. // Il faut ajouter le popup au dom avant de le positionner en css
  781. // Sinon la valeur height n'est pas encore calculable
  782. $('body').prepend(popup);
  783. //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
  784. var popMargTop = (popup.height() + 50) / 2;
  785. var popMargLeft = (popup.width() + 50) / 2;
  786. //On affecte le margin
  787. $(popup).css({
  788. 'margin-top' : -popMargTop,
  789. 'margin-left' : -popMargLeft
  790. });
  791. return false;
  792. })
  793. .append($.trim(input.val()))
  794. );
  795. search_tag_list.append(li_tag);
  796. }
  797. }
  798. // On cache le loader
  799. $('#tag_loader_'+form_name).hide();
  800. }
  801. }
  802. });
  803. //$.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, );
  804. }
  805. }
  806. var last_keypress = 0;
  807. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  808. {
  809. if (!timed)
  810. {
  811. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  812. // et on met a jour l'id de la dernière pressé
  813. last_keypress = new Date().getTime();
  814. var this_time_id = last_keypress;
  815. }
  816. else
  817. {
  818. // Si elle a été redirigé, on met son id dans cette variable
  819. var this_time_id = time_id;
  820. }
  821. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  822. if (time_id != last_keypress && timed)
  823. {
  824. // elle disparait
  825. }
  826. else
  827. {
  828. //
  829. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  830. {
  831. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  832. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  833. // elle doit attendre au cas ou soit pressé.
  834. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  835. }
  836. else
  837. {
  838. // il n'y a plus a attendre, on envoie la demande de tag.
  839. autocomplete_tag(input, form_name);
  840. }
  841. }
  842. }
  843. // Autocompletion de tags
  844. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  845. var form_name = $(this).parents('form').attr('name');
  846. var code = (e.keyCode ? e.keyCode : e.which);
  847. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  848. {
  849. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  850. }
  851. });
  852. // Un click sur ce lien affiche tout les tags cachés de la liste
  853. $('div.search_tag_list a.more').live('click', function(){
  854. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  855. $(this).show();
  856. });
  857. $(this).hide();
  858. return false;
  859. });
  860. $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
  861. $('ul.tagbox li.input input[type="text"]').formDefaults();
  862. ////////////////// FIN TAG PROMPT ///////////////
  863. // Suppression d'un element
  864. $('a.group_remove_link').jConfirmAction({
  865. question : "Supprimer ce groupe ?",
  866. yesAnswer : "Oui",
  867. cancelAnswer : "Non",
  868. onYes: function(link){
  869. window.location = link.attr('href');
  870. return false;
  871. },
  872. onOpen: function(){},
  873. onClose: function(){}
  874. });
  875. // Selection Réseau global / Mon réseau
  876. $('div.select_network a').live('click', function(){
  877. var divSelect = $(this).parent('div');
  878. if ($(this).hasClass('all_network'))
  879. {
  880. divSelect.find('a.all_network').addClass('active');
  881. divSelect.find('a.my_network').removeClass('active');
  882. divSelect.find('select').val('network_public');
  883. }
  884. else
  885. {
  886. divSelect.find('a.my_network').addClass('active');
  887. divSelect.find('a.all_network').removeClass('active');
  888. divSelect.find('select').val('network_personal');
  889. }
  890. });
  891. // Ajout d'un element #ajouter
  892. $('form[name="add"] input[type="submit"]').live('click', function(){
  893. $('form[name="add"]').find('img.tag_loader').show();
  894. });
  895. $('form[name="add"]').ajaxForm(function(response) {
  896. if (response.status == 'mustbeconnected')
  897. {
  898. $(location).attr('href', url_index);
  899. }
  900. $('form[name="add"] img.tag_loader').hide();
  901. if (response.status == 'success')
  902. {
  903. $('form[name="add"]').find('ul.error_list').remove();
  904. $('ul.elements').prepend(response.html);
  905. $('form[name="add"] input[type="text"]').val('');
  906. if ($('form[name="search"]').length)
  907. {
  908. $('form[name="search"]').slideDown();
  909. }
  910. remove_tags('add');
  911. recolorize_element_list();
  912. $('div#element_add_box').slideUp();
  913. if (response.groups.length)
  914. {
  915. // Des groupes sont proposés pour diffuser cet élément
  916. $('div#added_element_to_group').slideDown();
  917. for (i in response.groups)
  918. {
  919. var group = response.groups[i];
  920. $('ul#groups_to_add_element').html('');
  921. $('ul#groups_to_add_element')
  922. .append($('<li>')
  923. .append($('<a>')
  924. .addClass('added_element_add_to_group')
  925. .attr('href', group.url)
  926. .append(group.name)
  927. )
  928. )
  929. ;
  930. }
  931. }
  932. else
  933. {
  934. $('a#element_add_link').show();
  935. }
  936. }
  937. else if (response.status == 'error')
  938. {
  939. $('form[name="add"]').find('ul.error_list').remove();
  940. var ul_errors = $('<ul>').addClass('error_list');
  941. for (i in response.errors)
  942. {
  943. ul_errors.append($('<li>').append(response.errors[i]));
  944. }
  945. $('form[name="add"]').prepend(ul_errors);
  946. }
  947. return false;
  948. });
  949. // Check périodique
  950. // TODO.
  951. /////////////////////
  952. var tags_ids_for_filter = new Array();
  953. // Filtre par tags (show, favorite)
  954. function refresh_elements_with_tags_selected(link)
  955. {
  956. // Puis on fait notre rekékéte ajax.
  957. $('ul.elements').html('');
  958. $('div.no_elements').hide();
  959. $('img.elements_more_loader').show();
  960. $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
  961. if (response.status == 'mustbeconnected')
  962. {
  963. $(location).attr('href', url_index);
  964. }
  965. $('ul.elements').html(response.html);
  966. if (response.count)
  967. {
  968. $('img.elements_more_loader').hide();
  969. $('span.elements_more').show();
  970. $('a.elements_more').show();
  971. }
  972. });
  973. return false;
  974. }
  975. function list_tag_clicked(link, erease)
  976. {
  977. if (erease)
  978. {
  979. $('ul#favorite_tags a.tag').removeClass('active');
  980. }
  981. // Ensuite on l'active ou le désactive
  982. if (link.hasClass('active'))
  983. {
  984. link.removeClass('active');
  985. }
  986. else
  987. {
  988. link.addClass('active');
  989. }
  990. // On construit notre liste de tags
  991. tags_ids_for_filter = new Array();
  992. $('ul#favorite_tags a.tag.active').each(function(index){
  993. var id = str_replace('filtering_tag_', '', $(this).attr('id'));
  994. tags_ids_for_filter[id] = id;
  995. });
  996. // On adapte le lien afficher plus de résultats
  997. var a_more = $('a.elements_more');
  998. a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
  999. return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
  1000. }
  1001. $('ul#favorite_tags a.tag').click(function(){
  1002. list_tag_clicked($(this));
  1003. });
  1004. last_keypress = 0;
  1005. function check_timelaps_and_find_with_tags(link, time_id, timed)
  1006. {
  1007. if (!timed)
  1008. {
  1009. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  1010. // et on met a jour l'id de la dernière pressé
  1011. last_keypress = new Date().getTime();
  1012. var this_time_id = last_keypress;
  1013. }
  1014. else
  1015. {
  1016. // Si elle a été redirigé, on met son id dans cette variable
  1017. var this_time_id = time_id;
  1018. }
  1019. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  1020. if (time_id != last_keypress && timed)
  1021. {
  1022. // elle disparait
  1023. }
  1024. else
  1025. {
  1026. //
  1027. if ((new Date().getTime() - last_keypress) < 800 || timed == false)
  1028. {
  1029. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  1030. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  1031. // elle doit attendre au cas ou soit pressé.
  1032. setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
  1033. }
  1034. else
  1035. {
  1036. // il n'y a plus a attendre, on envoie la demande de tag.
  1037. return refresh_elements_with_tags_selected(link);
  1038. }
  1039. }
  1040. return null;
  1041. }
  1042. ////////////////////////////////////////
  1043. /// Gestion de nouveaux éléments
  1044. var do_check_new_elements = false;
  1045. function check_new_elements()
  1046. {
  1047. if ($('ul.elements li').length)
  1048. {
  1049. // Si l'utilisateur a quitté la page on reporte le check
  1050. if ($('body.blurred').length)
  1051. {
  1052. // on passe la variable a vrai de façon a ce que lorsque la page
  1053. // et ré affiché on lance le check
  1054. do_check_new_elements = true;
  1055. }
  1056. else
  1057. {
  1058. var url = url_element_new_count
  1059. +'/'
  1060. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1061. ;
  1062. $.getJSON(url, function(response){
  1063. if (response.status == 'mustbeconnected')
  1064. {
  1065. $(location).attr('href', url_index);
  1066. }
  1067. if (response.status == 'success' && response.count)
  1068. {
  1069. $('div.display_more_elements').show();
  1070. $('div.display_more_elements span').html(response.message);
  1071. }
  1072. setTimeout(check_new_elements, 150000);
  1073. });
  1074. do_check_new_elements = false;
  1075. }
  1076. }
  1077. }
  1078. if ($('div.display_more_elements').length)
  1079. {
  1080. setTimeout(check_new_elements, 150000);
  1081. }
  1082. $('a.show_new_elements').live('click', function(){
  1083. var url = url_element_new_get
  1084. +'/'
  1085. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1086. ;
  1087. $('img.elements_new_loader').show();
  1088. $.getJSON(url, function(response){
  1089. if (response.status == 'mustbeconnected')
  1090. {
  1091. $(location).attr('href', url_index);
  1092. }
  1093. if (response.status == 'success')
  1094. {
  1095. if (response.count)
  1096. {
  1097. $('div.display_more_elements').show();
  1098. $('div.display_more_elements span').html(response.message);
  1099. }
  1100. else
  1101. {
  1102. $('div.display_more_elements').hide();
  1103. }
  1104. $('ul.elements').prepend(response.html);
  1105. recolorize_element_list();
  1106. }
  1107. $('img.elements_new_loader').hide();
  1108. });
  1109. });
  1110. function recolorize_element_list()
  1111. {
  1112. $('ul.elements li.element').each(function(index){
  1113. if ((index & 1) == 1)
  1114. {
  1115. $(this).removeClass('even');
  1116. $(this).removeClass('odd');
  1117. $(this).addClass('odd');
  1118. }
  1119. else
  1120. {
  1121. $(this).removeClass('odd');
  1122. $(this).removeClass('even');
  1123. $(this).addClass('even');
  1124. }
  1125. });
  1126. }
  1127. /*
  1128. * Action a effectuer lorsque l'utilisateur met le focus sur la page
  1129. */
  1130. function do_action_body_focused()
  1131. {
  1132. if (do_check_new_elements)
  1133. {
  1134. check_new_elements();
  1135. }
  1136. }
  1137. /*
  1138. * Commentaires d'élément
  1139. */
  1140. // Afficher les commentaires
  1141. $('td.element_content a.display_comments').live('click', function(){
  1142. display_comments($(this).parents('li.element'));
  1143. });
  1144. $('td.element_content a.hide_comments').live('click', function(){
  1145. hide_comments($(this).parents('li.element'));
  1146. });
  1147. function display_comments(li_element)
  1148. {
  1149. li_element.find('div.comments').slideDown();
  1150. li_element.find('a.display_comments').hide();
  1151. li_element.find('a.hide_comments').show();
  1152. }
  1153. function hide_comments(li_element)
  1154. {
  1155. li_element.find('div.comments').slideUp();
  1156. li_element.find('a.display_comments').show();
  1157. li_element.find('a.hide_comments').hide();
  1158. }
  1159. // Ajouter un commentaire
  1160. $('li.element a.add_comment').live('click', function(){
  1161. display_add_comment($(this).parents('li.element'));
  1162. });
  1163. $('form.add_comment input[type="submit"]').live('click', function(){
  1164. $(this).parents('div.comments').find('img.comments_loader').show();
  1165. });
  1166. function display_add_comment(li_element)
  1167. {
  1168. display_comments(li_element);
  1169. li_element.find('a.add_comment').hide();
  1170. li_element.find('form.add_comment').show();
  1171. li_element.find('form.add_comment').ajaxForm(function(response) {
  1172. if (response.status == 'mustbeconnected')
  1173. {
  1174. $(location).attr('href', url_index);
  1175. }
  1176. li_element.find('img.comments_loader').hide();
  1177. if (response.status == 'success')
  1178. {
  1179. li_element.find('form.add_comment').find('ul.error_list').remove();
  1180. li_element.find('div.comments ul.comments').append(response.html);
  1181. hide_add_comment(li_element);
  1182. }
  1183. else if (response.status == 'error')
  1184. {
  1185. li_element.find('form.add_comment').find('ul.error_list').remove();
  1186. var ul_errors = $('<ul>').addClass('error_list');
  1187. for (i in response.errors)
  1188. {
  1189. ul_errors.append($('<li>').append(response.errors[i]));
  1190. }
  1191. li_element.find('form.add_comment').prepend(ul_errors);
  1192. }
  1193. return false;
  1194. });
  1195. }
  1196. $('form.add_comment input.cancel').live('click', function(){
  1197. var li_element = $(this).parents('li.element');
  1198. hide_add_comment(li_element);
  1199. });
  1200. function hide_add_comment(li_element)
  1201. {
  1202. li_element.find('a.add_comment').show();
  1203. li_element.find('form.add_comment').hide();
  1204. li_element.find('form.add_comment textarea').val('');
  1205. }
  1206. // Modifier et supprimer
  1207. // Affichage du bouton Modifier et Supprimer
  1208. $('ul.comments li.comment').live({
  1209. mouseenter:
  1210. function()
  1211. {
  1212. $(this).find('a.comment_edit_link').show();
  1213. $(this).find('a.comment_remove_link').show();
  1214. },
  1215. mouseleave:
  1216. function()
  1217. {
  1218. if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
  1219. {
  1220. $(this).find('a.comment_edit_link').hide();
  1221. }
  1222. if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
  1223. {
  1224. $(this).find('a.comment_remove_link').hide();
  1225. }
  1226. }
  1227. }
  1228. );
  1229. // Supprimer
  1230. $('a.comment_remove_link').jConfirmAction({
  1231. question : string_comment_delete_confirm_sentence,
  1232. yesAnswer : string_comment_delete_confirm_yes,
  1233. cancelAnswer : string_comment_delete_confirm_no,
  1234. onYes: function(link){
  1235. var li = link.parents('li.comment');
  1236. li.find('img.comment_loader').show();
  1237. $.getJSON(link.attr('href'), function(response){
  1238. li.find('img.comment_loader').hide();
  1239. if (response.status == 'mustbeconnected')
  1240. {
  1241. $(location).attr('href', url_index);
  1242. }
  1243. if (response.status == 'success')
  1244. {
  1245. li.remove();
  1246. }
  1247. });
  1248. return false;
  1249. },
  1250. onOpen: function(link){
  1251. var li = link.parents('li.comment');
  1252. li.find('a.comment_edit_link').addClass('mustBeDisplayed');
  1253. li.find('a.comment_remove_link').addClass('mustBeDisplayed');
  1254. },
  1255. onClose: function(link){
  1256. var li = link.parents('li.comment');
  1257. li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
  1258. li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
  1259. li.find('a.comment_edit_link').hide();
  1260. li.find('a.comment_remove_link').hide();
  1261. }
  1262. });
  1263. var comments_edited = new Array();
  1264. // Modification
  1265. // Ouverture du formulaire de modification
  1266. $('a.comment_edit_link').live('click', function(){
  1267. var link = $(this);
  1268. var li = link.parents('li.comment');
  1269. // On garde en mémoire l'élément édité en cas d'annulation
  1270. comments_edited[li.attr('id')] = li.html();
  1271. var loader = li.find('img.comment_loader');
  1272. li.html(loader);
  1273. li.find('img.comment_loader').show();
  1274. $.getJSON($(this).attr('href'), function(response) {
  1275. if (response.status == 'mustbeconnected')
  1276. {
  1277. $(location).attr('href', url_index);
  1278. }
  1279. li.html(response.html);
  1280. // On rend ce formulaire ajaxFormable
  1281. $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
  1282. var li_current = $(this).parents('li.comment');
  1283. li_current.prepend(loader);
  1284. li_current.find('img.comment_loader').show();
  1285. });
  1286. li.find('form.edit_comment').ajaxForm(function(response){
  1287. li = $('li#'+response.dom_id);
  1288. li.find('img.comment_loader').hide();
  1289. if (response.status == 'mustbeconnected')
  1290. {
  1291. $(location).attr('href', url_index);
  1292. }
  1293. if (response.status == 'success')
  1294. {
  1295. li.html(response.html);
  1296. delete(comments_edited[li.attr('id')]);
  1297. }
  1298. else if (response.status == 'error')
  1299. {
  1300. li.find('ul.error_list').remove();
  1301. var ul_errors = $('<ul>').addClass('error_list');
  1302. for (i in response.errors)
  1303. {
  1304. ul_errors.append($('<li>').append(response.errors[i]));
  1305. }
  1306. li.prepend(ul_errors);
  1307. }
  1308. });
  1309. });
  1310. return false;
  1311. });
  1312. // Annulation d'un formulaire de modification d'un comment
  1313. $('form.edit_comment input.cancel').live('click', function(){
  1314. var li = $(this).parents('li.comment');
  1315. li.html(comments_edited[li.attr('id')]);
  1316. delete(comments_edited[li.attr('id')]);
  1317. });
  1318. /*
  1319. * Ajout d'un tag en favoris a partir d'un élément
  1320. */
  1321. $('li.element_tag').live({
  1322. mouseenter:
  1323. function()
  1324. {
  1325. $(this).find('a.tag_to_favorites').show();
  1326. $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
  1327. },
  1328. mouseleave:
  1329. function()
  1330. {
  1331. if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
  1332. {
  1333. $(this).find('a.tag_to_favorites').hide();
  1334. $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
  1335. }
  1336. }
  1337. }
  1338. );
  1339. $('a.tag_to_favorites').jConfirmAction({
  1340. question : string_tag_addtofav_confirm_sentence,
  1341. yesAnswer : string_tag_addtofav_confirm_yes,
  1342. cancelAnswer : string_tag_addtofav_confirm_no,
  1343. onYes: function(link){
  1344. $.getJSON(link.attr('href'), function(response){
  1345. if (response.status == 'mustbeconnected')
  1346. {
  1347. $(location).attr('href', url_index);
  1348. }
  1349. });
  1350. $('div.question').fadeOut();
  1351. return false;
  1352. },
  1353. onOpen: function(link){
  1354. var li = link.parents('li.element_tag');
  1355. li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
  1356. },
  1357. onClose: function(link){
  1358. var li = link.parents('li.element_tag');
  1359. li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
  1360. li.find('a.element_tag').removeClass('element_tag_large_for_fav');
  1361. li.find('a.tag_to_favorites').hide();
  1362. }
  1363. });
  1364. /*
  1365. * Ajout dans un groupe de l'élément envoyé
  1366. */
  1367. $('a.added_element_add_to_group').live('click', function(){
  1368. var loader = $('div#added_element_to_group').find('img.loader');
  1369. loader.show();
  1370. $.getJSON($(this).attr('href'), function(response) {
  1371. loader.hide();
  1372. if (response.status == 'mustbeconnected')
  1373. {
  1374. $(location).attr('href', url_index);
  1375. }
  1376. if (response.status == 'success')
  1377. {
  1378. $('li#'+response.dom_id).html(response.html);
  1379. }
  1380. $('div#added_element_to_group').slideUp();
  1381. $('a#element_add_link').show();
  1382. });
  1383. return false;
  1384. });
  1385. $('div#added_element_to_group a.cancel').live('click', function(){
  1386. $('div#added_element_to_group').slideUp();
  1387. $('a#element_add_link').show();
  1388. return false;
  1389. });
  1390. /*
  1391. * Report / signalement d'un élément
  1392. */
  1393. $('a.element_report').jConfirmAction({
  1394. question : string_elementreport_confirm_sentence,
  1395. yesAnswer : string_elementreport_confirm_yes,
  1396. cancelAnswer : string_elementreport_confirm_no,
  1397. onYes: function(link){
  1398. $.getJSON(link.attr('href'), function(response){
  1399. if (response.status == 'mustbeconnected')
  1400. {
  1401. $(location).attr('href', url_index);
  1402. }
  1403. });
  1404. $('div.question').fadeOut();
  1405. return false;
  1406. },
  1407. onOpen: function(link){
  1408. },
  1409. onClose: function(link){
  1410. }
  1411. });
  1412. /*
  1413. * Vote sur element
  1414. */
  1415. $('li.element a.vote').live('click', function(){
  1416. var img = $(this).find('img');
  1417. var link = $(this);
  1418. img.attr('src', url_img_ajax_loader);
  1419. $.getJSON(link.attr('href'), function(response){
  1420. if (response.status == 'mustbeconnected')
  1421. {
  1422. $(location).attr('href', url_index);
  1423. }
  1424. if (response.status == 'success')
  1425. {
  1426. link.attr('href', response.data.a.href);
  1427. img.attr('src', response.data.img.src);
  1428. link.parents('td.right').find('li.score span.score').html(response.data.element.points);
  1429. }
  1430. });
  1431. return false;
  1432. });
  1433. // Enlever les ids du ElementSearch
  1434. $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
  1435. $('img.elements_more_loader').show();
  1436. $('ul.elements').html('');
  1437. var link = $(this);
  1438. $.getJSON(link.attr('href'), function(response){
  1439. if (response.status == 'mustbeconnected')
  1440. {
  1441. $(location).attr('href', url_index);
  1442. }
  1443. if (response.status == 'success')
  1444. {
  1445. $('form[name="search"]').submit();
  1446. $('div.more_filters a.new_comments').hide();
  1447. $('div.more_filters a.new_favorites').hide();
  1448. $('div.more_filters a.new_tags').hide();
  1449. }
  1450. });
  1451. return false;
  1452. });
  1453. /*
  1454. *
  1455. * Proposition de tags sur un élément
  1456. *
  1457. */
  1458. // Ouverture du formulaire de modification
  1459. $('a.element_propose_tags').live('click', function(){
  1460. var link = $(this);
  1461. var li = link.parents('li.element');
  1462. li.find('img.element_loader').show();
  1463. $.getJSON($(this).attr('href'), function(response) {
  1464. if (response.status == 'mustbeconnected')
  1465. {
  1466. $(location).attr('href', url_index);
  1467. }
  1468. li.find('img.element_loader').hide();
  1469. if (response.status == 'success')
  1470. {
  1471. // On prépare le tagBox
  1472. var table = li.find('table:first');
  1473. li.find('div.tag_proposition').remove();
  1474. table.after(response.html);
  1475. // Pour le click sur l'input de saisie de tag
  1476. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  1477. var options = new Array();
  1478. options.form_name = response.form_name;
  1479. options.tag_init = response.tags;
  1480. ajax_query_timestamp = null;
  1481. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  1482. // On rend ce formulaire ajaxFormable
  1483. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  1484. li = $(this).parents('li.element');
  1485. li.find('img.element_loader').show();
  1486. });
  1487. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  1488. if (response.status == 'mustbeconnected')
  1489. {
  1490. $(location).attr('href', url_index);
  1491. }
  1492. if (response.status == 'success')
  1493. {
  1494. li = $('li#'+response.dom_id);
  1495. li.find('img.element_loader').hide();
  1496. li.find('form')
  1497. li.find('div.tag_proposition').remove();
  1498. }
  1499. else if (response.status == 'error')
  1500. {
  1501. li.find('img.element_loader').hide();
  1502. li.find('ul.error_list').remove();
  1503. var ul_errors = $('<ul>').addClass('error_list');
  1504. for (i in response.errors)
  1505. {
  1506. ul_errors.append($('<li>').append(response.errors[i]));
  1507. }
  1508. li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
  1509. }
  1510. });
  1511. }
  1512. });
  1513. return false;
  1514. });
  1515. // Annulation d'un formulaire de modification d'élément
  1516. $('div.tag_proposition input.cancel').live('click', function(){
  1517. $(this).parents('div.tag_proposition').slideUp();
  1518. });
  1519. // Ouvrir les propositions de tags de l'élément
  1520. $('a.element_view_propositions_link').live('click', function(){
  1521. var link = $(this);
  1522. li = link.parents('li.element');
  1523. li.find('img.element_loader').show();
  1524. $.getJSON($(this).attr('href'), function(response) {
  1525. if (response.status == 'mustbeconnected')
  1526. {
  1527. $(location).attr('href', url_index);
  1528. }
  1529. li.find('img.element_loader').hide();
  1530. if (response.status == 'success')
  1531. {
  1532. var table = li.find('table:first');
  1533. li.find('div.tags_proposition_view').remove();
  1534. table.after(response.html);
  1535. }
  1536. });
  1537. return false;
  1538. });
  1539. $('a.accept_tag_propotision').live('click', function(){
  1540. var link = $(this);
  1541. var li = link.parents('li.element');
  1542. li.find('img.element_loader').show();
  1543. $.getJSON($(this).attr('href'), function(response) {
  1544. if (response.status == 'mustbeconnected')
  1545. {
  1546. $(location).attr('href', url_index);
  1547. }
  1548. li.find('img.element_loader').hide();
  1549. if (response.status == 'success')
  1550. {
  1551. li.html(response.html);
  1552. }
  1553. });
  1554. return false;
  1555. });
  1556. //
  1557. $('a.refuse_tag_propositions').live('click', function(){
  1558. var link = $(this);
  1559. var li = link.parents('li.element');
  1560. li.find('img.element_loader').show();
  1561. $.getJSON($(this).attr('href'), function(response) {
  1562. if (response.status == 'mustbeconnected')
  1563. {
  1564. $(location).attr('href', url_index);
  1565. }
  1566. li.find('img.element_loader').hide();
  1567. if (response.status == 'success')
  1568. {
  1569. li.find('div.tags_proposition_view').remove();
  1570. }
  1571. });
  1572. return false;
  1573. });
  1574. /*
  1575. * Proposition de tag sur un élément FIN
  1576. */
  1577. /*
  1578. * Report / signalement d'un commentaire
  1579. */
  1580. $('a.comment_report').jConfirmAction({
  1581. question : string_commentreport_confirm_sentence,
  1582. yesAnswer : string_commentreport_confirm_yes,
  1583. cancelAnswer : string_commentreport_confirm_no,
  1584. onYes: function(link){
  1585. $.getJSON(link.attr('href'), function(response){
  1586. if (response.status == 'mustbeconnected')
  1587. {
  1588. $(location).attr('href', url_index);
  1589. }
  1590. });
  1591. $('div.question').fadeOut();
  1592. return false;
  1593. },
  1594. onOpen: function(link){
  1595. },
  1596. onClose: function(link){
  1597. }
  1598. });
  1599. });