muzich.js 60KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032
  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 = $('a#filtering_tag_'+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. var url = link.attr('href')+'/'+id_last+'/'+invertcolor;
  403. // Cas exeptionel si on se trouve sur la global_search
  404. if ($('div#results_search_form').length)
  405. {
  406. url = link.attr('href')+id_last+'/'+$('div#results_search_form form input[type="text"]').val();
  407. }
  408. var old_form_action = $('form[name="search"]').attr('action');
  409. $('form[name="search"]').attr('action', url);
  410. $.ajax({
  411. type: 'POST',
  412. url: url,
  413. data: $('form[name="search"]').serialize(),
  414. success: function(response) {
  415. if (response.status == 'mustbeconnected')
  416. {
  417. $(location).attr('href', url_index);
  418. }
  419. if (response.count)
  420. {
  421. $('ul.elements').append(response.html);
  422. $('img.elements_more_loader').hide();
  423. recolorize_element_list();
  424. }
  425. if (response.end || response.count < 1)
  426. {
  427. $('img.elements_more_loader').hide();
  428. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  429. response.message+'</p></div>');
  430. link.hide();
  431. }
  432. },
  433. dataType: "json"
  434. });
  435. $('form[name="search"]').attr('action', old_form_action);
  436. // $.getJSON(url, function(response) {
  437. // if (response.status == 'mustbeconnected')
  438. // {
  439. // $(location).attr('href', url_index);
  440. // }
  441. //
  442. // if (response.count)
  443. // {
  444. // $('ul.elements').append(response.html);
  445. // $('img.elements_more_loader').hide();
  446. // recolorize_element_list();
  447. // }
  448. //
  449. // if (response.end || response.count < 1)
  450. // {
  451. // $('img.elements_more_loader').hide();
  452. // $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  453. // response.message+'</p></div>');
  454. // link.hide();
  455. // }
  456. // });
  457. return false;
  458. });
  459. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  460. // Filtre et affichage éléments ajax
  461. $('form[name="search"] input[type="submit"]').click(function(){
  462. $('ul.elements').html('');
  463. $('div.no_elements').hide();
  464. $('img.elements_more_loader').show();
  465. });
  466. $('form[name="search"]').ajaxForm(function(response) {
  467. if (response.status == 'mustbeconnected')
  468. {
  469. $(location).attr('href', url_index);
  470. }
  471. $('ul.elements').html(response.html);
  472. if (response.count)
  473. {
  474. $('img.elements_more_loader').hide();
  475. $('span.elements_more').show();
  476. $('a.elements_more').show();
  477. }
  478. if (response.count < 1)
  479. {
  480. $('img.elements_more_loader').hide();
  481. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  482. response.message+'</p></div>');
  483. $('a.elements_more').hide()
  484. ;
  485. }
  486. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  487. });
  488. // Suppression d'un element
  489. $('a.element_remove_link').jConfirmAction({
  490. question : string_element_delete_confirm_sentence,
  491. yesAnswer : string_element_delete_confirm_yes,
  492. cancelAnswer : string_element_delete_confirm_no,
  493. onYes: function(link){
  494. var li = link.parents('li.element');
  495. li.find('img.element_loader').show();
  496. $.getJSON(link.attr('href'), function(response){
  497. if (response.status == 'mustbeconnected')
  498. {
  499. $(location).attr('href', url_index);
  500. }
  501. if (response.status == 'success')
  502. {
  503. li.remove();
  504. }
  505. else
  506. {
  507. li.find('img.element_loader').hide();
  508. }
  509. });
  510. return false;
  511. },
  512. onOpen: function(link){
  513. var li = link.parents('li.element');
  514. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  515. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  516. },
  517. onClose: function(link){
  518. var li = link.parents('li.element');
  519. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  520. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  521. li.find('a.element_edit_link').hide();
  522. li.find('a.element_remove_link').hide();
  523. }
  524. });
  525. var elements_edited = new Array();
  526. // Ouverture du formulaire de modification
  527. $('a.element_edit_link').live('click', function(){
  528. var link = $(this);
  529. var li = link.parents('li.element');
  530. // On garde en mémoire l'élément édité en cas d'annulation
  531. elements_edited[li.attr('id')] = li.html();
  532. var div_loader = li.find('div.loader');
  533. li.html(div_loader);
  534. li.find('img.element_loader').show();
  535. $.getJSON($(this).attr('href'), function(response) {
  536. if (response.status == 'mustbeconnected')
  537. {
  538. $(location).attr('href', url_index);
  539. }
  540. // On prépare le tagBox
  541. li.html(response.html);
  542. // Pour le click sur l'input de saisie de tag
  543. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  544. var options = new Array();
  545. options.form_name = response.form_name;
  546. options.tag_init = response.tags;
  547. ajax_query_timestamp = null;
  548. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  549. // On rend ce formulaire ajaxFormable
  550. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  551. var li = $(this).parents('li.element');
  552. li.prepend(div_loader);
  553. li.find('img.element_loader').show();
  554. });
  555. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  556. if (response.status == 'mustbeconnected')
  557. {
  558. $(location).attr('href', url_index);
  559. }
  560. var li = $('li#'+response.dom_id);
  561. if (response.status == 'success')
  562. {
  563. li.html(response.html);
  564. delete(elements_edited[li.attr('id')]);
  565. }
  566. else if (response.status == 'error')
  567. {
  568. li.find('img.element_loader').hide();
  569. li.find('ul.error_list').remove();
  570. var ul_errors = $('<ul>').addClass('error_list');
  571. for (i in response.errors)
  572. {
  573. ul_errors.append($('<li>').append(response.errors[i]));
  574. }
  575. li.prepend(ul_errors);
  576. }
  577. });
  578. });
  579. return false;
  580. });
  581. // Annulation d'un formulaire de modification d'élément
  582. $('form.edit_element input.cancel_edit').live('click', function(){
  583. var li = link.parents('li.element');
  584. li.html(elements_edited[li.attr('id')]);
  585. delete(elements_edited[li.attr('id')]);
  586. });
  587. ////////////////// TAG PROMPT ///////////////
  588. var ajax_query_timestamp = null;
  589. var tag_text_help = $('input.tag_text_help').val();
  590. // Les deux clicks ci-dessous permettent de faire disparaitre
  591. // la div de tags lorsque l'on clique ailleurs
  592. $('html').click(function() {
  593. if ($("div.search_tag_list").is(':visible'))
  594. {
  595. $("div.search_tag_list").hide();
  596. }
  597. });
  598. $("div.search_tag_list, div.search_tag_list a.more").live('click', function(event){
  599. event.stopPropagation();
  600. $("div.search_tag_list").show();
  601. });
  602. function autocomplete_tag(input, form_name)
  603. {
  604. // Il doit y avoir au moin un caractère
  605. if ((input.val().length > 0) && (input.val() != string_tag_prompt_input_help))
  606. {
  607. // on met en variable l'input
  608. var inputTag = input;
  609. // On récupére la div de tags
  610. var divtags = $("#search_tag_"+form_name);
  611. // Si la fenêtre de tags est caché
  612. if (!divtags.is(':visible'))
  613. {
  614. // On la replace
  615. var position = input.position();
  616. divtags.css('left', Math.round(position.left) + 5);
  617. divtags.css('top', Math.round(position.top) + 28);
  618. // Et on l'affiche
  619. divtags.show();
  620. }
  621. // On affiche le loader
  622. $('#tag_loader_'+form_name).show();
  623. // On cache la liste de tags
  624. var search_tag_list = divtags.find('ul.search_tag_list');
  625. // On supprime les anciens li
  626. search_tag_list.find('li').remove();
  627. search_tag_list.hide();
  628. // Et on affiche une info
  629. var span_info = divtags.find('span.info');
  630. span_info.show();
  631. // TODO: multilingue !
  632. span_info.text(str_replace('%string_search%', input.val(), string_search_tag_title));
  633. // C'est en fonction du nb de resultats qu'il sera affiché
  634. divtags.find('a.more').hide();
  635. // On récupère le timestamp pour reconnaitre la dernière requête effectué
  636. ajax_query_timestamp = new Date().getTime();
  637. // Récupération des tags correspondants
  638. $.ajax({
  639. type: 'POST',
  640. url: url_search_tag+'/'+ajax_query_timestamp,
  641. dataType: 'json',
  642. data: {'string_search':input.val()},
  643. success: function(data) {
  644. if (data.status == 'mustbeconnected')
  645. {
  646. $(location).attr('href', url_index);
  647. }
  648. // Ce contrôle permet de ne pas continuer si une requete
  649. // ajax a été faite depuis.
  650. if (data.timestamp == ajax_query_timestamp)
  651. {
  652. var status = data.status;
  653. var tags = data.data;
  654. // Si on spécifie une erreur
  655. if (status == 'error')
  656. {
  657. // On l'affiche a l'utilisateur
  658. span_info.text(data.error);
  659. }
  660. // Si c'est un succés
  661. else if (status == 'success')
  662. {
  663. if (tags.length > 0)
  664. {
  665. var more = false;
  666. // Pour chaque tags retournés
  667. for (i in tags)
  668. {
  669. var tag_name = tags[i]['name'];
  670. var tag_id = tags[i]['id'];
  671. var t_string = tag_name
  672. // On construit un li
  673. var r_string = $.trim(input.val());
  674. var re = new RegExp(r_string, "i");
  675. t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
  676. var li_tag =
  677. $('<li>').append(
  678. $('<a>').attr('id','searched_tag_'+tag_id+'_'+tag_name)
  679. .attr('href', '#')
  680. // qui réagit quand on clique dessus
  681. .click(function(e){
  682. // On récupère le nom du tag
  683. var name = $(this).attr('id').substr(13,$(this).attr('id').length);
  684. name = name.substr(strpos(name, '_')+1, name.length);
  685. var id = $(this).attr('id').substr(13,$(this).attr('id').length);
  686. id = str_replace(name, '', id);
  687. id = str_replace('_', '', id);
  688. $('input#tags_selected_tag_'+form_name).val(id);
  689. inputTag.val(name);
  690. // Et on execute l'évènement selectTag de l'input
  691. inputTag.trigger("selectTag");
  692. // On cache la liste puisque le choix vient d'être fait
  693. divtags.hide();
  694. inputTag.val(tag_text_help);
  695. return false;
  696. })
  697. .append(t_string)
  698. );
  699. // Si on depasse les 30 tags
  700. if (i > 30)
  701. {
  702. more = true;
  703. // On le cache
  704. li_tag.hide();
  705. }
  706. // On ajout ce li a la liste
  707. search_tag_list.append(li_tag);
  708. }
  709. if (more)
  710. {
  711. divtags.find('a.more').show();
  712. }
  713. span_info.show();
  714. span_info.text(data.message);
  715. // Et on affiche la liste
  716. search_tag_list.show();
  717. }
  718. else
  719. {
  720. span_info.show();
  721. span_info.text(data.message);
  722. search_tag_list.show();
  723. // Dans ce cas ou aucun tag n'a été trouvé, la proposition
  724. // d'ajout s'affichecf en dessous
  725. //span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  726. }
  727. // Si le tag ne semble pas connu en base
  728. if (!data.same_found)
  729. {
  730. // Cette variable nous permettra de stocker le lien nouveau tag
  731. var link_add_tag = null;
  732. li_tag =
  733. $('<li>').addClass('new').append(
  734. $('<a>').attr('href','#new#'+$.trim(input.val()))
  735. // qui réagit quand on clique dessus
  736. .click(function(e){
  737. // Effet fade-in du fond opaque
  738. $('body').append($('<div>').attr('id', 'fade'));
  739. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  740. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  741. // On met le lien cliqué dans la variabke prévu
  742. link_add_tag = $(this);
  743. // En premier lieux on fait apparaître la fenêtre de confirmation
  744. var popup = $('<div>')
  745. .attr('id', 'add_tag')
  746. .addClass('popin_block')
  747. .css('width', '400px')
  748. //.append($('<h2>').append(string_tag_add_title))
  749. .append($('<form>')
  750. .attr('action', url_add_tag)
  751. .attr('method', 'post')
  752. .attr('name', 'add_tag')
  753. .ajaxForm(function(response) {
  754. /*
  755. *
  756. */
  757. if (response.status == 'mustbeconnected')
  758. {
  759. $(location).attr('href', url_index);
  760. }
  761. if (response.status == 'success')
  762. {
  763. var tag_id = response.tag_id;
  764. var tag_name = response.tag_name;
  765. $('input#tags_selected_tag_'+form_name).val(tag_id);
  766. inputTag.val(tag_name);
  767. // Et on execute l'évènement selectTag de l'input
  768. inputTag.trigger("selectTag");
  769. // On cache la liste puisque le choix vient d'être fait
  770. divtags.hide();
  771. inputTag.val(tag_text_help);
  772. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
  773. $('#fade').fadeOut(400, function(){$('#fade').remove();});
  774. $('#add_tag').remove();
  775. }
  776. if (response.status == 'error')
  777. {
  778. $('form[name="add_tag"]').find('ul.error_list').remove();
  779. var ul_errors = $('<ul>').addClass('error_list');
  780. for (i in response.errors)
  781. {
  782. ul_errors.append($('<li>').append(response.errors[i]));
  783. }
  784. $('form[name="add_tag"]').prepend(ul_errors);
  785. }
  786. return false;
  787. })
  788. .append($('<div>').addClass('tag')
  789. .append($('<ul>')
  790. .append($('<li>').addClass('button')
  791. .append($(this).text()))))
  792. .append($('<p>').append(string_tag_add_text))
  793. .append($('<p>').append(string_tag_add_argument))
  794. .append($('<textarea>').attr('name', 'argument'))
  795. .append($('<div>').addClass('inputs')
  796. .append($('<input>')
  797. .attr('type', 'button')
  798. .attr('value', string_tag_add_inputs_cancel)
  799. .addClass('button')
  800. .click(function(){
  801. $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  802. $('#add_tag').remove();
  803. return false;
  804. })
  805. )
  806. .append($('<input>')
  807. .attr('type', 'submit')
  808. .attr('value', string_tag_add_inputs_submit)
  809. .addClass('button')
  810. .click(function(){
  811. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
  812. })
  813. )
  814. .append($('<input>').attr('type', 'hidden').attr('name', 'tag_name').val($(this).text()))
  815. ))
  816. ;
  817. // Il faut ajouter le popup au dom avant de le positionner en css
  818. // Sinon la valeur height n'est pas encore calculable
  819. $('body').prepend(popup);
  820. //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
  821. var popMargTop = (popup.height() + 50) / 2;
  822. var popMargLeft = (popup.width() + 50) / 2;
  823. //On affecte le margin
  824. $(popup).css({
  825. 'margin-top' : -popMargTop,
  826. 'margin-left' : -popMargLeft
  827. });
  828. return false;
  829. })
  830. .append($.trim(input.val()))
  831. );
  832. search_tag_list.append(li_tag);
  833. }
  834. }
  835. // On cache le loader
  836. $('#tag_loader_'+form_name).hide();
  837. }
  838. }
  839. });
  840. //$.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, );
  841. }
  842. }
  843. var last_keypress = 0;
  844. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  845. {
  846. if (!timed)
  847. {
  848. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  849. // et on met a jour l'id de la dernière pressé
  850. last_keypress = new Date().getTime();
  851. var this_time_id = last_keypress;
  852. }
  853. else
  854. {
  855. // Si elle a été redirigé, on met son id dans cette variable
  856. var this_time_id = time_id;
  857. }
  858. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  859. if (time_id != last_keypress && timed)
  860. {
  861. // elle disparait
  862. }
  863. else
  864. {
  865. //
  866. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  867. {
  868. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  869. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  870. // elle doit attendre au cas ou soit pressé.
  871. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  872. }
  873. else
  874. {
  875. // il n'y a plus a attendre, on envoie la demande de tag.
  876. autocomplete_tag(input, form_name);
  877. }
  878. }
  879. }
  880. // Autocompletion de tags
  881. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  882. var form_name = $(this).parents('form').attr('name');
  883. var code = (e.keyCode ? e.keyCode : e.which);
  884. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  885. {
  886. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  887. }
  888. });
  889. // Un click sur ce lien affiche tout les tags cachés de la liste
  890. $('div.search_tag_list a.more').live('click', function(){
  891. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  892. $(this).show();
  893. });
  894. $(this).hide();
  895. return false;
  896. });
  897. $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
  898. $('ul.tagbox li.input input[type="text"]').formDefaults();
  899. ////////////////// FIN TAG PROMPT ///////////////
  900. // Suppression d'un element
  901. $('a.group_remove_link').jConfirmAction({
  902. question : "Supprimer ce groupe ?",
  903. yesAnswer : "Oui",
  904. cancelAnswer : "Non",
  905. onYes: function(link){
  906. window.location = link.attr('href');
  907. return false;
  908. },
  909. onOpen: function(){},
  910. onClose: function(){}
  911. });
  912. // Selection Réseau global / Mon réseau
  913. $('div.select_network a').live('click', function(){
  914. var divSelect = $(this).parent('div');
  915. if ($(this).hasClass('all_network'))
  916. {
  917. divSelect.find('a.all_network').addClass('active');
  918. divSelect.find('a.my_network').removeClass('active');
  919. divSelect.find('select').val('network_public');
  920. }
  921. else
  922. {
  923. divSelect.find('a.my_network').addClass('active');
  924. divSelect.find('a.all_network').removeClass('active');
  925. divSelect.find('select').val('network_personal');
  926. }
  927. });
  928. // Ajout d'un element #ajouter
  929. $('form[name="add"] input[type="submit"]').live('click', function(){
  930. $('form[name="add"]').find('img.tag_loader').show();
  931. });
  932. $('form[name="add"]').ajaxForm(function(response) {
  933. if (response.status == 'mustbeconnected')
  934. {
  935. $(location).attr('href', url_index);
  936. }
  937. $('form[name="add"] img.tag_loader').hide();
  938. if (response.status == 'success')
  939. {
  940. $('form[name="add"]').find('ul.error_list').remove();
  941. $('ul.elements').prepend(response.html);
  942. $('form[name="add"] input[type="text"]').val('');
  943. if ($('form[name="search"]').length)
  944. {
  945. $('form[name="search"]').slideDown();
  946. }
  947. remove_tags('add');
  948. recolorize_element_list();
  949. $('div#element_add_box').slideUp();
  950. if (response.groups.length)
  951. {
  952. // Des groupes sont proposés pour diffuser cet élément
  953. $('div#added_element_to_group').slideDown();
  954. for (i in response.groups)
  955. {
  956. var group = response.groups[i];
  957. $('ul#groups_to_add_element').html('');
  958. $('ul#groups_to_add_element')
  959. .append($('<li>')
  960. .append($('<a>')
  961. .addClass('added_element_add_to_group')
  962. .attr('href', group.url)
  963. .append(group.name)
  964. )
  965. )
  966. ;
  967. }
  968. }
  969. else
  970. {
  971. $('a#element_add_link').show();
  972. }
  973. }
  974. else if (response.status == 'error')
  975. {
  976. $('form[name="add"]').find('ul.error_list').remove();
  977. var ul_errors = $('<ul>').addClass('error_list');
  978. for (i in response.errors)
  979. {
  980. ul_errors.append($('<li>').append(response.errors[i]));
  981. }
  982. $('form[name="add"]').prepend(ul_errors);
  983. }
  984. return false;
  985. });
  986. // Check périodique
  987. // TODO.
  988. /////////////////////
  989. var tags_ids_for_filter = new Array();
  990. // Filtre par tags (show, favorite)
  991. function refresh_elements_with_tags_selected(link)
  992. {
  993. // Puis on fait notre rekékéte ajax.
  994. $('ul.elements').html('');
  995. $('div.no_elements').hide();
  996. $('img.elements_more_loader').show();
  997. $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
  998. if (response.status == 'mustbeconnected')
  999. {
  1000. $(location).attr('href', url_index);
  1001. }
  1002. $('ul.elements').html(response.html);
  1003. if (response.count)
  1004. {
  1005. $('img.elements_more_loader').hide();
  1006. $('span.elements_more').show();
  1007. $('a.elements_more').show();
  1008. }
  1009. });
  1010. return false;
  1011. }
  1012. function list_tag_clicked(link, erease)
  1013. {
  1014. if (erease)
  1015. {
  1016. $('ul#favorite_tags a.tag').removeClass('active');
  1017. }
  1018. // Ensuite on l'active ou le désactive
  1019. if (link.hasClass('active'))
  1020. {
  1021. link.removeClass('active');
  1022. }
  1023. else
  1024. {
  1025. link.addClass('active');
  1026. }
  1027. // On construit notre liste de tags
  1028. tags_ids_for_filter = new Array();
  1029. $('ul#favorite_tags a.tag.active').each(function(index){
  1030. var id = str_replace('filtering_tag_', '', $(this).attr('id'));
  1031. tags_ids_for_filter[id] = id;
  1032. });
  1033. // On adapte le lien afficher plus de résultats
  1034. var a_more = $('a.elements_more');
  1035. a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
  1036. return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
  1037. }
  1038. $('ul#favorite_tags a.tag').click(function(){
  1039. list_tag_clicked($(this));
  1040. });
  1041. last_keypress = 0;
  1042. function check_timelaps_and_find_with_tags(link, time_id, timed)
  1043. {
  1044. if (!timed)
  1045. {
  1046. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  1047. // et on met a jour l'id de la dernière pressé
  1048. last_keypress = new Date().getTime();
  1049. var this_time_id = last_keypress;
  1050. }
  1051. else
  1052. {
  1053. // Si elle a été redirigé, on met son id dans cette variable
  1054. var this_time_id = time_id;
  1055. }
  1056. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  1057. if (time_id != last_keypress && timed)
  1058. {
  1059. // elle disparait
  1060. }
  1061. else
  1062. {
  1063. //
  1064. if ((new Date().getTime() - last_keypress) < 800 || timed == false)
  1065. {
  1066. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  1067. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  1068. // elle doit attendre au cas ou soit pressé.
  1069. setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
  1070. }
  1071. else
  1072. {
  1073. // il n'y a plus a attendre, on envoie la demande de tag.
  1074. return refresh_elements_with_tags_selected(link);
  1075. }
  1076. }
  1077. return null;
  1078. }
  1079. ////////////////////////////////////////
  1080. /// Gestion de nouveaux éléments
  1081. var do_check_new_elements = false;
  1082. function check_new_elements()
  1083. {
  1084. if ($('ul.elements li').length)
  1085. {
  1086. // Si l'utilisateur a quitté la page on reporte le check
  1087. if ($('body.blurred').length)
  1088. {
  1089. // on passe la variable a vrai de façon a ce que lorsque la page
  1090. // et ré affiché on lance le check
  1091. do_check_new_elements = true;
  1092. }
  1093. else
  1094. {
  1095. var url = url_element_new_count
  1096. +'/'
  1097. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1098. ;
  1099. $.ajax({
  1100. type: 'POST',
  1101. url: url,
  1102. data: $('form[name="search"]').serialize(),
  1103. success: function(response){
  1104. if (response.status == 'mustbeconnected')
  1105. {
  1106. $(location).attr('href', url_index);
  1107. }
  1108. if (response.status == 'success' && response.count)
  1109. {
  1110. $('div.display_more_elements').show();
  1111. $('div.display_more_elements span').html(response.message);
  1112. }
  1113. setTimeout(check_new_elements, 150000);
  1114. },
  1115. dataType: "json"
  1116. });
  1117. // $.getJSON(url, function(response){
  1118. //
  1119. // if (response.status == 'mustbeconnected')
  1120. // {
  1121. // $(location).attr('href', url_index);
  1122. // }
  1123. //
  1124. // if (response.status == 'success' && response.count)
  1125. // {
  1126. // $('div.display_more_elements').show();
  1127. // $('div.display_more_elements span').html(response.message);
  1128. // }
  1129. //
  1130. // setTimeout(check_new_elements, 150000);
  1131. // });
  1132. do_check_new_elements = false;
  1133. }
  1134. }
  1135. }
  1136. if ($('div.display_more_elements').length)
  1137. {
  1138. setTimeout(check_new_elements, 150000);
  1139. }
  1140. $('a.show_new_elements').live('click', function(){
  1141. var url = url_element_new_get
  1142. +'/'
  1143. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1144. ;
  1145. $('img.elements_new_loader').show();
  1146. $.ajax({
  1147. type: 'POST',
  1148. url: url,
  1149. data: $('form[name="search"]').serialize(),
  1150. success: function(response){
  1151. if (response.status == 'mustbeconnected')
  1152. {
  1153. $(location).attr('href', url_index);
  1154. }
  1155. if (response.status == 'success')
  1156. {
  1157. if (response.count)
  1158. {
  1159. $('div.display_more_elements').show();
  1160. $('div.display_more_elements span').html(response.message);
  1161. }
  1162. else
  1163. {
  1164. $('div.display_more_elements').hide();
  1165. }
  1166. $('ul.elements').prepend(response.html);
  1167. recolorize_element_list();
  1168. }
  1169. $('img.elements_new_loader').hide();
  1170. },
  1171. dataType: "json"
  1172. });
  1173. // $.getJSON(url, function(response){
  1174. //
  1175. // if (response.status == 'mustbeconnected')
  1176. // {
  1177. // $(location).attr('href', url_index);
  1178. // }
  1179. //
  1180. // if (response.status == 'success')
  1181. // {
  1182. // if (response.count)
  1183. // {
  1184. // $('div.display_more_elements').show();
  1185. // $('div.display_more_elements span').html(response.message);
  1186. // }
  1187. // else
  1188. // {
  1189. // $('div.display_more_elements').hide();
  1190. // }
  1191. //
  1192. // $('ul.elements').prepend(response.html);
  1193. // recolorize_element_list();
  1194. // }
  1195. //
  1196. // $('img.elements_new_loader').hide();
  1197. // });
  1198. });
  1199. function recolorize_element_list()
  1200. {
  1201. $('ul.elements li.element').each(function(index){
  1202. if ((index & 1) == 1)
  1203. {
  1204. $(this).removeClass('even');
  1205. $(this).removeClass('odd');
  1206. $(this).addClass('odd');
  1207. }
  1208. else
  1209. {
  1210. $(this).removeClass('odd');
  1211. $(this).removeClass('even');
  1212. $(this).addClass('even');
  1213. }
  1214. });
  1215. }
  1216. /*
  1217. * Action a effectuer lorsque l'utilisateur met le focus sur la page
  1218. */
  1219. function do_action_body_focused()
  1220. {
  1221. if (do_check_new_elements)
  1222. {
  1223. check_new_elements();
  1224. }
  1225. }
  1226. /*
  1227. * Commentaires d'élément
  1228. */
  1229. // Afficher les commentaires
  1230. $('td.element_content a.display_comments').live('click', function(){
  1231. display_comments($(this).parents('li.element'));
  1232. });
  1233. $('td.element_content a.hide_comments').live('click', function(){
  1234. hide_comments($(this).parents('li.element'));
  1235. });
  1236. function display_comments(li_element)
  1237. {
  1238. li_element.find('div.comments').slideDown();
  1239. li_element.find('a.display_comments').hide();
  1240. li_element.find('a.hide_comments').show();
  1241. }
  1242. function hide_comments(li_element)
  1243. {
  1244. li_element.find('div.comments').slideUp();
  1245. li_element.find('a.display_comments').show();
  1246. li_element.find('a.hide_comments').hide();
  1247. }
  1248. // Ajouter un commentaire
  1249. $('li.element a.add_comment').live('click', function(){
  1250. display_add_comment($(this).parents('li.element'));
  1251. });
  1252. $('form.add_comment input[type="submit"]').live('click', function(){
  1253. $(this).parents('div.comments').find('img.comments_loader').show();
  1254. });
  1255. function display_add_comment(li_element)
  1256. {
  1257. display_comments(li_element);
  1258. li_element.find('a.add_comment').hide();
  1259. li_element.find('form.add_comment').show();
  1260. li_element.find('form.add_comment').ajaxForm(function(response) {
  1261. if (response.status == 'mustbeconnected')
  1262. {
  1263. $(location).attr('href', url_index);
  1264. }
  1265. li_element.find('img.comments_loader').hide();
  1266. if (response.status == 'success')
  1267. {
  1268. li_element.find('form.add_comment').find('ul.error_list').remove();
  1269. li_element.find('div.comments ul.comments').append(response.html);
  1270. hide_add_comment(li_element);
  1271. }
  1272. else if (response.status == 'error')
  1273. {
  1274. li_element.find('form.add_comment').find('ul.error_list').remove();
  1275. var ul_errors = $('<ul>').addClass('error_list');
  1276. for (i in response.errors)
  1277. {
  1278. ul_errors.append($('<li>').append(response.errors[i]));
  1279. }
  1280. li_element.find('form.add_comment').prepend(ul_errors);
  1281. }
  1282. return false;
  1283. });
  1284. }
  1285. $('form.add_comment input.cancel').live('click', function(){
  1286. var li_element = $(this).parents('li.element');
  1287. hide_add_comment(li_element);
  1288. });
  1289. function hide_add_comment(li_element)
  1290. {
  1291. li_element.find('a.add_comment').show();
  1292. li_element.find('form.add_comment').hide();
  1293. li_element.find('form.add_comment textarea').val('');
  1294. }
  1295. // Modifier et supprimer
  1296. // Affichage du bouton Modifier et Supprimer
  1297. $('ul.comments li.comment').live({
  1298. mouseenter:
  1299. function()
  1300. {
  1301. $(this).find('a.comment_edit_link').show();
  1302. $(this).find('a.comment_remove_link').show();
  1303. },
  1304. mouseleave:
  1305. function()
  1306. {
  1307. if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
  1308. {
  1309. $(this).find('a.comment_edit_link').hide();
  1310. }
  1311. if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
  1312. {
  1313. $(this).find('a.comment_remove_link').hide();
  1314. }
  1315. }
  1316. }
  1317. );
  1318. // Supprimer
  1319. $('a.comment_remove_link').jConfirmAction({
  1320. question : string_comment_delete_confirm_sentence,
  1321. yesAnswer : string_comment_delete_confirm_yes,
  1322. cancelAnswer : string_comment_delete_confirm_no,
  1323. onYes: function(link){
  1324. var li = link.parents('li.comment');
  1325. li.find('img.comment_loader').show();
  1326. $.getJSON(link.attr('href'), function(response){
  1327. li.find('img.comment_loader').hide();
  1328. if (response.status == 'mustbeconnected')
  1329. {
  1330. $(location).attr('href', url_index);
  1331. }
  1332. if (response.status == 'success')
  1333. {
  1334. li.remove();
  1335. }
  1336. });
  1337. return false;
  1338. },
  1339. onOpen: function(link){
  1340. var li = link.parents('li.comment');
  1341. li.find('a.comment_edit_link').addClass('mustBeDisplayed');
  1342. li.find('a.comment_remove_link').addClass('mustBeDisplayed');
  1343. },
  1344. onClose: function(link){
  1345. var li = link.parents('li.comment');
  1346. li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
  1347. li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
  1348. li.find('a.comment_edit_link').hide();
  1349. li.find('a.comment_remove_link').hide();
  1350. }
  1351. });
  1352. var comments_edited = new Array();
  1353. // Modification
  1354. // Ouverture du formulaire de modification
  1355. $('a.comment_edit_link').live('click', function(){
  1356. var link = $(this);
  1357. var li = link.parents('li.comment');
  1358. // On garde en mémoire l'élément édité en cas d'annulation
  1359. comments_edited[li.attr('id')] = li.html();
  1360. var loader = li.find('img.comment_loader');
  1361. li.html(loader);
  1362. li.find('img.comment_loader').show();
  1363. $.getJSON($(this).attr('href'), function(response) {
  1364. if (response.status == 'mustbeconnected')
  1365. {
  1366. $(location).attr('href', url_index);
  1367. }
  1368. li.html(response.html);
  1369. // On rend ce formulaire ajaxFormable
  1370. $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
  1371. var li_current = $(this).parents('li.comment');
  1372. li_current.prepend(loader);
  1373. li_current.find('img.comment_loader').show();
  1374. });
  1375. li.find('form.edit_comment').ajaxForm(function(response){
  1376. li = $('li#'+response.dom_id);
  1377. li.find('img.comment_loader').hide();
  1378. if (response.status == 'mustbeconnected')
  1379. {
  1380. $(location).attr('href', url_index);
  1381. }
  1382. if (response.status == 'success')
  1383. {
  1384. li.html(response.html);
  1385. delete(comments_edited[li.attr('id')]);
  1386. }
  1387. else if (response.status == 'error')
  1388. {
  1389. li.find('ul.error_list').remove();
  1390. var ul_errors = $('<ul>').addClass('error_list');
  1391. for (i in response.errors)
  1392. {
  1393. ul_errors.append($('<li>').append(response.errors[i]));
  1394. }
  1395. li.prepend(ul_errors);
  1396. }
  1397. });
  1398. });
  1399. return false;
  1400. });
  1401. // Annulation d'un formulaire de modification d'un comment
  1402. $('form.edit_comment input.cancel').live('click', function(){
  1403. var li = $(this).parents('li.comment');
  1404. li.html(comments_edited[li.attr('id')]);
  1405. delete(comments_edited[li.attr('id')]);
  1406. });
  1407. /*
  1408. * Ajout d'un tag en favoris a partir d'un élément
  1409. */
  1410. $('li.element_tag').live({
  1411. mouseenter:
  1412. function()
  1413. {
  1414. $(this).find('a.tag_to_favorites').show();
  1415. $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
  1416. },
  1417. mouseleave:
  1418. function()
  1419. {
  1420. if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
  1421. {
  1422. $(this).find('a.tag_to_favorites').hide();
  1423. $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
  1424. }
  1425. }
  1426. }
  1427. );
  1428. $('a.tag_to_favorites').jConfirmAction({
  1429. question : string_tag_addtofav_confirm_sentence,
  1430. yesAnswer : string_tag_addtofav_confirm_yes,
  1431. cancelAnswer : string_tag_addtofav_confirm_no,
  1432. onYes: function(link){
  1433. $.getJSON(link.attr('href'), function(response){
  1434. if (response.status == 'mustbeconnected')
  1435. {
  1436. $(location).attr('href', url_index);
  1437. }
  1438. });
  1439. $('div.question').fadeOut();
  1440. return false;
  1441. },
  1442. onOpen: function(link){
  1443. var li = link.parents('li.element_tag');
  1444. li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
  1445. },
  1446. onClose: function(link){
  1447. var li = link.parents('li.element_tag');
  1448. li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
  1449. li.find('a.element_tag').removeClass('element_tag_large_for_fav');
  1450. li.find('a.tag_to_favorites').hide();
  1451. }
  1452. });
  1453. /*
  1454. * Ajout dans un groupe de l'élément envoyé
  1455. */
  1456. $('a.added_element_add_to_group').live('click', function(){
  1457. var loader = $('div#added_element_to_group').find('img.loader');
  1458. loader.show();
  1459. $.getJSON($(this).attr('href'), function(response) {
  1460. loader.hide();
  1461. if (response.status == 'mustbeconnected')
  1462. {
  1463. $(location).attr('href', url_index);
  1464. }
  1465. if (response.status == 'success')
  1466. {
  1467. $('li#'+response.dom_id).html(response.html);
  1468. }
  1469. $('div#added_element_to_group').slideUp();
  1470. $('a#element_add_link').show();
  1471. });
  1472. return false;
  1473. });
  1474. $('div#added_element_to_group a.cancel').live('click', function(){
  1475. $('div#added_element_to_group').slideUp();
  1476. $('a#element_add_link').show();
  1477. return false;
  1478. });
  1479. /*
  1480. * Report / signalement d'un élément
  1481. */
  1482. $('a.element_report').jConfirmAction({
  1483. question : string_elementreport_confirm_sentence,
  1484. yesAnswer : string_elementreport_confirm_yes,
  1485. cancelAnswer : string_elementreport_confirm_no,
  1486. onYes: function(link){
  1487. $.getJSON(link.attr('href'), function(response){
  1488. if (response.status == 'mustbeconnected')
  1489. {
  1490. $(location).attr('href', url_index);
  1491. }
  1492. });
  1493. $('div.question').fadeOut();
  1494. return false;
  1495. },
  1496. onOpen: function(link){
  1497. },
  1498. onClose: function(link){
  1499. }
  1500. });
  1501. /*
  1502. * Vote sur element
  1503. */
  1504. $('li.element a.vote').live('click', function(){
  1505. var img = $(this).find('img');
  1506. var link = $(this);
  1507. img.attr('src', url_img_ajax_loader);
  1508. $.getJSON(link.attr('href'), function(response){
  1509. if (response.status == 'mustbeconnected')
  1510. {
  1511. $(location).attr('href', url_index);
  1512. }
  1513. if (response.status == 'success')
  1514. {
  1515. link.attr('href', response.data.a.href);
  1516. img.attr('src', response.data.img.src);
  1517. link.parents('td.right').find('li.score span.score').html(response.data.element.points);
  1518. }
  1519. });
  1520. return false;
  1521. });
  1522. // Enlever les ids du ElementSearch
  1523. $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
  1524. $('img.elements_more_loader').show();
  1525. $('ul.elements').html('');
  1526. var link = $(this);
  1527. $.getJSON(link.attr('href'), function(response){
  1528. if (response.status == 'mustbeconnected')
  1529. {
  1530. $(location).attr('href', url_index);
  1531. }
  1532. if (response.status == 'success')
  1533. {
  1534. $('form[name="search"]').submit();
  1535. $('div.more_filters a.new_comments').hide();
  1536. $('div.more_filters a.new_favorites').hide();
  1537. $('div.more_filters a.new_tags').hide();
  1538. }
  1539. });
  1540. return false;
  1541. });
  1542. /*
  1543. *
  1544. * Proposition de tags sur un élément
  1545. *
  1546. */
  1547. // Ouverture du formulaire de modification
  1548. $('a.element_propose_tags').live('click', function(){
  1549. var link = $(this);
  1550. var li = link.parents('li.element');
  1551. li.find('img.element_loader').show();
  1552. $.getJSON($(this).attr('href'), function(response) {
  1553. if (response.status == 'mustbeconnected')
  1554. {
  1555. $(location).attr('href', url_index);
  1556. }
  1557. li.find('img.element_loader').hide();
  1558. if (response.status == 'success')
  1559. {
  1560. // On prépare le tagBox
  1561. var table = li.find('table:first');
  1562. li.find('div.tag_proposition').remove();
  1563. table.after(response.html);
  1564. // Pour le click sur l'input de saisie de tag
  1565. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  1566. var options = new Array();
  1567. options.form_name = response.form_name;
  1568. options.tag_init = response.tags;
  1569. ajax_query_timestamp = null;
  1570. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  1571. // On rend ce formulaire ajaxFormable
  1572. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  1573. li = $(this).parents('li.element');
  1574. li.find('img.element_loader').show();
  1575. });
  1576. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  1577. if (response.status == 'mustbeconnected')
  1578. {
  1579. $(location).attr('href', url_index);
  1580. }
  1581. if (response.status == 'success')
  1582. {
  1583. li = $('li#'+response.dom_id);
  1584. li.find('img.element_loader').hide();
  1585. li.find('form')
  1586. li.find('div.tag_proposition').remove();
  1587. }
  1588. else if (response.status == 'error')
  1589. {
  1590. li.find('img.element_loader').hide();
  1591. li.find('ul.error_list').remove();
  1592. var ul_errors = $('<ul>').addClass('error_list');
  1593. for (i in response.errors)
  1594. {
  1595. ul_errors.append($('<li>').append(response.errors[i]));
  1596. }
  1597. li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
  1598. }
  1599. });
  1600. }
  1601. });
  1602. return false;
  1603. });
  1604. // Annulation d'un formulaire de modification d'élément
  1605. $('div.tag_proposition input.cancel').live('click', function(){
  1606. $(this).parents('div.tag_proposition').slideUp();
  1607. });
  1608. // Ouvrir les propositions de tags de l'élément
  1609. $('a.element_view_propositions_link').live('click', function(){
  1610. var link = $(this);
  1611. li = link.parents('li.element');
  1612. li.find('img.element_loader').show();
  1613. $.getJSON($(this).attr('href'), function(response) {
  1614. if (response.status == 'mustbeconnected')
  1615. {
  1616. $(location).attr('href', url_index);
  1617. }
  1618. li.find('img.element_loader').hide();
  1619. if (response.status == 'success')
  1620. {
  1621. var table = li.find('table:first');
  1622. li.find('div.tags_proposition_view').remove();
  1623. table.after(response.html);
  1624. }
  1625. });
  1626. return false;
  1627. });
  1628. $('a.accept_tag_propotision').live('click', function(){
  1629. var link = $(this);
  1630. var li = link.parents('li.element');
  1631. li.find('img.element_loader').show();
  1632. $.getJSON($(this).attr('href'), function(response) {
  1633. if (response.status == 'mustbeconnected')
  1634. {
  1635. $(location).attr('href', url_index);
  1636. }
  1637. li.find('img.element_loader').hide();
  1638. if (response.status == 'success')
  1639. {
  1640. li.html(response.html);
  1641. }
  1642. });
  1643. return false;
  1644. });
  1645. //
  1646. $('a.refuse_tag_propositions').live('click', function(){
  1647. var link = $(this);
  1648. var li = link.parents('li.element');
  1649. li.find('img.element_loader').show();
  1650. $.getJSON($(this).attr('href'), function(response) {
  1651. if (response.status == 'mustbeconnected')
  1652. {
  1653. $(location).attr('href', url_index);
  1654. }
  1655. li.find('img.element_loader').hide();
  1656. if (response.status == 'success')
  1657. {
  1658. li.find('div.tags_proposition_view').remove();
  1659. }
  1660. });
  1661. return false;
  1662. });
  1663. /*
  1664. * Proposition de tag sur un élément FIN
  1665. */
  1666. /*
  1667. * Report / signalement d'un commentaire
  1668. */
  1669. $('a.comment_report').jConfirmAction({
  1670. question : string_commentreport_confirm_sentence,
  1671. yesAnswer : string_commentreport_confirm_yes,
  1672. cancelAnswer : string_commentreport_confirm_no,
  1673. onYes: function(link){
  1674. $.getJSON(link.attr('href'), function(response){
  1675. if (response.status == 'mustbeconnected')
  1676. {
  1677. $(location).attr('href', url_index);
  1678. }
  1679. });
  1680. $('div.question').fadeOut();
  1681. return false;
  1682. },
  1683. onOpen: function(link){
  1684. },
  1685. onClose: function(link){
  1686. }
  1687. });
  1688. });