muzich.js 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  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 = $(this).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. li_tag =
  731. $('<li>').addClass('new').append(
  732. $('<a>').attr('href','#new#'+$.trim(input.val()))
  733. // qui réagit quand on clique dessus
  734. .click({
  735. inputTag: inputTag,
  736. form_name: form_name,
  737. divtags: divtags
  738. }, event_click_new_tag_proposition)
  739. .append($.trim(input.val()))
  740. );
  741. search_tag_list.append(li_tag);
  742. }
  743. }
  744. // On cache le loader
  745. $('#tag_loader_'+form_name).hide();
  746. }
  747. }
  748. });
  749. //$.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, );
  750. }
  751. }
  752. function event_click_new_tag_proposition(event)
  753. {
  754. form_add_open_dialog_for_new_tag($(event.target), event.data.inputTag, event.data.form_name, event.data.divtags);
  755. }
  756. function form_add_open_dialog_for_new_tag(link_add_tag, inputTag, form_name, divtags)
  757. {
  758. // Effet fade-in du fond opaque
  759. $('body').append($('<div>').attr('id', 'fade'));
  760. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  761. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  762. // En premier lieux on fait apparaître la fenêtre de confirmation
  763. var popup = $('<div>')
  764. .attr('id', 'add_tag')
  765. .addClass('popin_block')
  766. .css('width', '400px')
  767. //.append($('<h2>').append(string_tag_add_title))
  768. .append($('<form>')
  769. .attr('action', url_add_tag)
  770. .attr('method', 'post')
  771. .attr('name', 'add_tag')
  772. .ajaxForm(function(response) {
  773. /*
  774. *
  775. */
  776. if (response.status == 'mustbeconnected')
  777. {
  778. $(location).attr('href', url_index);
  779. }
  780. if (response.status == 'success')
  781. {
  782. var tag_id = response.tag_id;
  783. var tag_name = response.tag_name;
  784. $('input#tags_selected_tag_'+form_name).val(tag_id);
  785. inputTag.val(tag_name);
  786. // Et on execute l'évènement selectTag de l'input
  787. inputTag.trigger("selectTag");
  788. // On cache la liste puisque le choix vient d'être fait
  789. divtags.hide();
  790. inputTag.val(tag_text_help);
  791. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
  792. $('#fade').fadeOut(400, function(){$('#fade').remove();});
  793. $('#add_tag').remove();
  794. }
  795. if (response.status == 'error')
  796. {
  797. $('form[name="add_tag"]').find('ul.error_list').remove();
  798. var ul_errors = $('<ul>').addClass('error_list');
  799. for (i in response.errors)
  800. {
  801. ul_errors.append($('<li>').append(response.errors[i]));
  802. }
  803. $('form[name="add_tag"]').prepend(ul_errors);
  804. }
  805. return false;
  806. })
  807. .append($('<div>').addClass('tag')
  808. .append($('<ul>')
  809. .append($('<li>').addClass('button')
  810. .append(link_add_tag.text()))))
  811. .append($('<p>').append(string_tag_add_text))
  812. .append($('<p>').append(string_tag_add_argument))
  813. .append($('<textarea>').attr('name', 'argument'))
  814. .append($('<div>').addClass('inputs')
  815. .append($('<input>')
  816. .attr('type', 'button')
  817. .attr('value', string_tag_add_inputs_cancel)
  818. .addClass('button')
  819. .click(function(){
  820. $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  821. $('#add_tag').remove();
  822. return false;
  823. })
  824. )
  825. .append($('<input>')
  826. .attr('type', 'submit')
  827. .attr('value', string_tag_add_inputs_submit)
  828. .addClass('button')
  829. .click(function(){
  830. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
  831. })
  832. )
  833. .append($('<input>').attr('type', 'hidden').attr('name', 'tag_name').val(link_add_tag.text()))
  834. ))
  835. ;
  836. // Il faut ajouter le popup au dom avant de le positionner en css
  837. // Sinon la valeur height n'est pas encore calculable
  838. $('body').prepend(popup);
  839. //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
  840. var popMargTop = (popup.height() + 50) / 2;
  841. var popMargLeft = (popup.width() + 50) / 2;
  842. //On affecte le margin
  843. $(popup).css({
  844. 'margin-top' : -popMargTop,
  845. 'margin-left' : -popMargLeft
  846. });
  847. return false;
  848. }
  849. var last_keypress = 0;
  850. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  851. {
  852. if (!timed)
  853. {
  854. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  855. // et on met a jour l'id de la dernière pressé
  856. last_keypress = new Date().getTime();
  857. var this_time_id = last_keypress;
  858. }
  859. else
  860. {
  861. // Si elle a été redirigé, on met son id dans cette variable
  862. var this_time_id = time_id;
  863. }
  864. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  865. if (time_id != last_keypress && timed)
  866. {
  867. // elle disparait
  868. }
  869. else
  870. {
  871. //
  872. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  873. {
  874. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  875. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  876. // elle doit attendre au cas ou soit pressé.
  877. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  878. }
  879. else
  880. {
  881. // il n'y a plus a attendre, on envoie la demande de tag.
  882. autocomplete_tag(input, form_name);
  883. }
  884. }
  885. }
  886. // Autocompletion de tags
  887. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  888. var form_name = $(this).parents('form').attr('name');
  889. var code = (e.keyCode ? e.keyCode : e.which);
  890. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  891. {
  892. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  893. }
  894. });
  895. // Un click sur ce lien affiche tout les tags cachés de la liste
  896. $('div.search_tag_list a.more').live('click', function(){
  897. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  898. $(this).show();
  899. });
  900. $(this).hide();
  901. return false;
  902. });
  903. $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
  904. $('ul.tagbox li.input input[type="text"]').formDefaults();
  905. ////////////////// FIN TAG PROMPT ///////////////
  906. // Suppression d'un element
  907. $('a.group_remove_link').jConfirmAction({
  908. question : "Supprimer ce groupe ?",
  909. yesAnswer : "Oui",
  910. cancelAnswer : "Non",
  911. onYes: function(link){
  912. window.location = link.attr('href');
  913. return false;
  914. },
  915. onOpen: function(){},
  916. onClose: function(){}
  917. });
  918. // Selection Réseau global / Mon réseau
  919. $('div.select_network a').live('click', function(){
  920. var divSelect = $(this).parent('div');
  921. if ($(this).hasClass('all_network'))
  922. {
  923. divSelect.find('a.all_network').addClass('active');
  924. divSelect.find('a.my_network').removeClass('active');
  925. divSelect.find('select').val('network_public');
  926. }
  927. else
  928. {
  929. divSelect.find('a.my_network').addClass('active');
  930. divSelect.find('a.all_network').removeClass('active');
  931. divSelect.find('select').val('network_personal');
  932. }
  933. });
  934. function element_add_proceed_json_response(response)
  935. {
  936. if (response.status == 'success')
  937. {
  938. $('form[name="add"]').find('ul.error_list').remove();
  939. $('ul.elements').prepend(response.html);
  940. $('form[name="add"] input[type="text"]').val('');
  941. if ($('form[name="search"]').length)
  942. {
  943. $('form[name="search"]').slideDown();
  944. }
  945. remove_tags('add');
  946. recolorize_element_list();
  947. $('div#element_add_box').slideUp();
  948. if (response.groups.length)
  949. {
  950. // Des groupes sont proposés pour diffuser cet élément
  951. $('div#added_element_to_group').slideDown();
  952. for (i in response.groups)
  953. {
  954. var group = response.groups[i];
  955. $('ul#groups_to_add_element').html('');
  956. $('ul#groups_to_add_element')
  957. .append($('<li>')
  958. .append($('<a>')
  959. .addClass('added_element_add_to_group')
  960. .attr('href', group.url)
  961. .append(group.name)
  962. )
  963. )
  964. ;
  965. }
  966. }
  967. else
  968. {
  969. $('a#element_add_link').show();
  970. }
  971. }
  972. else if (response.status == 'error')
  973. {
  974. $('form[name="add"]').find('ul.error_list').remove();
  975. var ul_errors = $('<ul>').addClass('error_list');
  976. for (i in response.errors)
  977. {
  978. ul_errors.append($('<li>').append(response.errors[i]));
  979. }
  980. $('form[name="add"]').prepend(ul_errors);
  981. }
  982. }
  983. // Ajout d'un element #ajouter (première partie)
  984. // Click sur "ajouter" (l'url)
  985. $('a#form_add_check_url').click(function(){
  986. // On fait tourner notre gif loader
  987. $('img#form_add_loader').show();
  988. $.ajax({
  989. type: 'POST',
  990. url: url_datas_api,
  991. data: {'url':$('input#element_add_url').val()},
  992. success: function(response){
  993. if (response.status == 'mustbeconnected')
  994. {
  995. $(location).attr('href', url_index);
  996. }
  997. if (response.status == 'success')
  998. {
  999. // On cache notre gif loader.
  1000. $('img#form_add_loader').hide();
  1001. // On commence par renseigner les champs si on a du concret
  1002. // name
  1003. if (response.name)
  1004. {
  1005. $('input#element_add_name').val(response.name);
  1006. }
  1007. // thumb
  1008. $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
  1009. if (response.thumb)
  1010. {
  1011. $('div#form_add_thumb img').attr('src', response.thumb);
  1012. }
  1013. // Proposition de tags
  1014. if (response.tags)
  1015. {
  1016. $('ul#form_add_prop_tags li').remove();
  1017. $('ul#form_add_prop_tags').show();
  1018. $('ul#form_add_prop_tags_text').show();
  1019. for (tags_index = 0; tags_index < response.tags.length; tags_index++)
  1020. {
  1021. var tag = response.tags[tags_index];
  1022. var tag_id = '';
  1023. var tag_name = tag.original_name;
  1024. // Si il y a des équivalent en base.
  1025. if (tag.like_found)
  1026. {
  1027. tag_id = tag.like.id;
  1028. tag_name = tag.like.name;
  1029. }
  1030. // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
  1031. $('ul#form_add_prop_tags').append(
  1032. '<li>'+
  1033. '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
  1034. tag_name+
  1035. '</a>'+
  1036. '</li>'
  1037. );
  1038. }
  1039. }
  1040. // On a plus qu'a afficher les champs
  1041. $('div#form_add_second_part').slideDown();
  1042. $('div#form_add_first_part').slideUp();
  1043. }
  1044. },
  1045. dataType: 'json'
  1046. });
  1047. });
  1048. /*
  1049. * Formulaire d'ajout: click sur proposition de tags du a une api
  1050. */
  1051. $('a.form_add_prop_tag').live('click', function(){
  1052. var form_name = "add";
  1053. var tag_id = str_replace('#', '', $(this).attr('href'));
  1054. var input_tag = $("div.tags_prompt ul.tagbox li.input input");
  1055. // Si on connait le tag id (pas un nouveau tag donc)
  1056. if (tag_id)
  1057. {
  1058. $('input#tags_selected_tag_'+form_name).val(tag_id);
  1059. input_tag.val($(this).text());
  1060. // Et on execute l'évènement selectTag de l'input
  1061. input_tag.trigger("selectTag");
  1062. input_tag.val(tag_text_help);
  1063. }
  1064. else
  1065. {
  1066. // Cette var sert a rien ici, mais c'est la refactorisation qui
  1067. // pose problmeme (corrigeable cela dit)
  1068. var divtags = $("#search_tag_"+form_name);
  1069. form_add_open_dialog_for_new_tag($(this), input_tag, form_name, divtags);
  1070. }
  1071. });
  1072. // #ajouter ajouter un élément (envoi du formulaire)
  1073. $('form[name="add"] input[type="submit"]').live('click', function(){
  1074. $('form[name="add"]').find('img.tag_loader').show();
  1075. });
  1076. $('form[name="add"]').ajaxForm(function(response) {
  1077. if (response.status == 'mustbeconnected')
  1078. {
  1079. $(location).attr('href', url_index);
  1080. }
  1081. $('form[name="add"] img.tag_loader').hide();
  1082. element_add_proceed_json_response(response);
  1083. $('div#element_add_box').slideUp();
  1084. $('div#form_add_first_part').show();
  1085. $('div#form_add_second_part').hide();
  1086. $('ul#form_add_prop_tags').hide();
  1087. $('ul#form_add_prop_tags_text').hide();
  1088. return false;
  1089. });
  1090. /////////////////////
  1091. var tags_ids_for_filter = new Array();
  1092. // Filtre par tags (show, favorite)
  1093. function refresh_elements_with_tags_selected(link)
  1094. {
  1095. // Puis on fait notre rekékéte ajax.
  1096. $('ul.elements').html('');
  1097. $('div.no_elements').hide();
  1098. $('img.elements_more_loader').show();
  1099. $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
  1100. if (response.status == 'mustbeconnected')
  1101. {
  1102. $(location).attr('href', url_index);
  1103. }
  1104. $('ul.elements').html(response.html);
  1105. if (response.count)
  1106. {
  1107. $('img.elements_more_loader').hide();
  1108. $('span.elements_more').show();
  1109. $('a.elements_more').show();
  1110. }
  1111. });
  1112. return false;
  1113. }
  1114. function list_tag_clicked(link, erease)
  1115. {
  1116. if (erease)
  1117. {
  1118. $('ul#favorite_tags a.tag').removeClass('active');
  1119. }
  1120. // Ensuite on l'active ou le désactive
  1121. if (link.hasClass('active'))
  1122. {
  1123. link.removeClass('active');
  1124. }
  1125. else
  1126. {
  1127. link.addClass('active');
  1128. }
  1129. // On construit notre liste de tags
  1130. tags_ids_for_filter = new Array();
  1131. $('ul#favorite_tags a.tag.active').each(function(index){
  1132. var id = str_replace('filtering_tag_', '', $(this).attr('id'));
  1133. tags_ids_for_filter[id] = id;
  1134. });
  1135. // On adapte le lien afficher plus de résultats
  1136. var a_more = $('a.elements_more');
  1137. a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
  1138. return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
  1139. }
  1140. $('ul#favorite_tags a.tag').click(function(){
  1141. list_tag_clicked($(this));
  1142. });
  1143. last_keypress = 0;
  1144. function check_timelaps_and_find_with_tags(link, time_id, timed)
  1145. {
  1146. if (!timed)
  1147. {
  1148. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  1149. // et on met a jour l'id de la dernière pressé
  1150. last_keypress = new Date().getTime();
  1151. var this_time_id = last_keypress;
  1152. }
  1153. else
  1154. {
  1155. // Si elle a été redirigé, on met son id dans cette variable
  1156. var this_time_id = time_id;
  1157. }
  1158. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  1159. if (time_id != last_keypress && timed)
  1160. {
  1161. // elle disparait
  1162. }
  1163. else
  1164. {
  1165. //
  1166. if ((new Date().getTime() - last_keypress) < 800 || timed == false)
  1167. {
  1168. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  1169. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  1170. // elle doit attendre au cas ou soit pressé.
  1171. setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
  1172. }
  1173. else
  1174. {
  1175. // il n'y a plus a attendre, on envoie la demande de tag.
  1176. return refresh_elements_with_tags_selected(link);
  1177. }
  1178. }
  1179. return null;
  1180. }
  1181. ////////////////////////////////////////
  1182. /// Gestion de nouveaux éléments
  1183. var do_check_new_elements = false;
  1184. function check_new_elements()
  1185. {
  1186. if ($('ul.elements li').length)
  1187. {
  1188. // Si l'utilisateur a quitté la page on reporte le check
  1189. if ($('body.blurred').length)
  1190. {
  1191. // on passe la variable a vrai de façon a ce que lorsque la page
  1192. // et ré affiché on lance le check
  1193. do_check_new_elements = true;
  1194. }
  1195. else
  1196. {
  1197. var url = url_element_new_count
  1198. +'/'
  1199. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1200. ;
  1201. $.ajax({
  1202. type: 'POST',
  1203. url: url,
  1204. data: $('form[name="search"]').serialize(),
  1205. success: function(response){
  1206. if (response.status == 'mustbeconnected')
  1207. {
  1208. $(location).attr('href', url_index);
  1209. }
  1210. if (response.status == 'success' && response.count)
  1211. {
  1212. $('div.display_more_elements').show();
  1213. $('div.display_more_elements span').html(response.message);
  1214. }
  1215. setTimeout(check_new_elements, 150000);
  1216. },
  1217. dataType: "json"
  1218. });
  1219. // $.getJSON(url, function(response){
  1220. //
  1221. // if (response.status == 'mustbeconnected')
  1222. // {
  1223. // $(location).attr('href', url_index);
  1224. // }
  1225. //
  1226. // if (response.status == 'success' && response.count)
  1227. // {
  1228. // $('div.display_more_elements').show();
  1229. // $('div.display_more_elements span').html(response.message);
  1230. // }
  1231. //
  1232. // setTimeout(check_new_elements, 150000);
  1233. // });
  1234. do_check_new_elements = false;
  1235. }
  1236. }
  1237. }
  1238. if ($('div.display_more_elements').length)
  1239. {
  1240. setTimeout(check_new_elements, 150000);
  1241. }
  1242. $('a.show_new_elements').live('click', function(){
  1243. var url = url_element_new_get
  1244. +'/'
  1245. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1246. ;
  1247. $('img.elements_new_loader').show();
  1248. $.ajax({
  1249. type: 'POST',
  1250. url: url,
  1251. data: $('form[name="search"]').serialize(),
  1252. success: function(response){
  1253. if (response.status == 'mustbeconnected')
  1254. {
  1255. $(location).attr('href', url_index);
  1256. }
  1257. if (response.status == 'success')
  1258. {
  1259. if (response.count)
  1260. {
  1261. $('div.display_more_elements').show();
  1262. $('div.display_more_elements span').html(response.message);
  1263. }
  1264. else
  1265. {
  1266. $('div.display_more_elements').hide();
  1267. }
  1268. $('ul.elements').prepend(response.html);
  1269. recolorize_element_list();
  1270. }
  1271. $('img.elements_new_loader').hide();
  1272. },
  1273. dataType: "json"
  1274. });
  1275. // $.getJSON(url, function(response){
  1276. //
  1277. // if (response.status == 'mustbeconnected')
  1278. // {
  1279. // $(location).attr('href', url_index);
  1280. // }
  1281. //
  1282. // if (response.status == 'success')
  1283. // {
  1284. // if (response.count)
  1285. // {
  1286. // $('div.display_more_elements').show();
  1287. // $('div.display_more_elements span').html(response.message);
  1288. // }
  1289. // else
  1290. // {
  1291. // $('div.display_more_elements').hide();
  1292. // }
  1293. //
  1294. // $('ul.elements').prepend(response.html);
  1295. // recolorize_element_list();
  1296. // }
  1297. //
  1298. // $('img.elements_new_loader').hide();
  1299. // });
  1300. });
  1301. function recolorize_element_list()
  1302. {
  1303. $('ul.elements li.element').each(function(index){
  1304. if ((index & 1) == 1)
  1305. {
  1306. $(this).removeClass('even');
  1307. $(this).removeClass('odd');
  1308. $(this).addClass('odd');
  1309. }
  1310. else
  1311. {
  1312. $(this).removeClass('odd');
  1313. $(this).removeClass('even');
  1314. $(this).addClass('even');
  1315. }
  1316. });
  1317. }
  1318. /*
  1319. * Action a effectuer lorsque l'utilisateur met le focus sur la page
  1320. */
  1321. function do_action_body_focused()
  1322. {
  1323. if (do_check_new_elements)
  1324. {
  1325. check_new_elements();
  1326. }
  1327. }
  1328. /*
  1329. * Commentaires d'élément
  1330. */
  1331. // Afficher les commentaires
  1332. $('td.element_content a.display_comments').live('click', function(){
  1333. display_comments($(this).parents('li.element'));
  1334. });
  1335. $('td.element_content a.hide_comments').live('click', function(){
  1336. hide_comments($(this).parents('li.element'));
  1337. });
  1338. function display_comments(li_element)
  1339. {
  1340. li_element.find('div.comments').slideDown();
  1341. li_element.find('a.display_comments').hide();
  1342. li_element.find('a.hide_comments').show();
  1343. }
  1344. function hide_comments(li_element)
  1345. {
  1346. li_element.find('div.comments').slideUp();
  1347. li_element.find('a.display_comments').show();
  1348. li_element.find('a.hide_comments').hide();
  1349. }
  1350. // Ajouter un commentaire
  1351. $('li.element a.add_comment').live('click', function(){
  1352. display_add_comment($(this).parents('li.element'));
  1353. });
  1354. $('form.add_comment input[type="submit"]').live('click', function(){
  1355. $(this).parents('div.comments').find('img.comments_loader').show();
  1356. });
  1357. function display_add_comment(li_element)
  1358. {
  1359. display_comments(li_element);
  1360. li_element.find('a.add_comment').hide();
  1361. li_element.find('form.add_comment').show();
  1362. li_element.find('form.add_comment').ajaxForm(function(response) {
  1363. if (response.status == 'mustbeconnected')
  1364. {
  1365. $(location).attr('href', url_index);
  1366. }
  1367. li_element.find('img.comments_loader').hide();
  1368. if (response.status == 'success')
  1369. {
  1370. li_element.find('form.add_comment').find('ul.error_list').remove();
  1371. li_element.find('div.comments ul.comments').append(response.html);
  1372. hide_add_comment(li_element);
  1373. }
  1374. else if (response.status == 'error')
  1375. {
  1376. li_element.find('form.add_comment').find('ul.error_list').remove();
  1377. var ul_errors = $('<ul>').addClass('error_list');
  1378. for (i in response.errors)
  1379. {
  1380. ul_errors.append($('<li>').append(response.errors[i]));
  1381. }
  1382. li_element.find('form.add_comment').prepend(ul_errors);
  1383. }
  1384. return false;
  1385. });
  1386. }
  1387. $('form.add_comment input.cancel').live('click', function(){
  1388. var li_element = $(this).parents('li.element');
  1389. hide_add_comment(li_element);
  1390. });
  1391. function hide_add_comment(li_element)
  1392. {
  1393. li_element.find('a.add_comment').show();
  1394. li_element.find('form.add_comment').hide();
  1395. li_element.find('form.add_comment textarea').val('');
  1396. }
  1397. // Modifier et supprimer
  1398. // Affichage du bouton Modifier et Supprimer
  1399. $('ul.comments li.comment').live({
  1400. mouseenter:
  1401. function()
  1402. {
  1403. $(this).find('a.comment_edit_link').show();
  1404. $(this).find('a.comment_remove_link').show();
  1405. },
  1406. mouseleave:
  1407. function()
  1408. {
  1409. if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
  1410. {
  1411. $(this).find('a.comment_edit_link').hide();
  1412. }
  1413. if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
  1414. {
  1415. $(this).find('a.comment_remove_link').hide();
  1416. }
  1417. }
  1418. }
  1419. );
  1420. // Supprimer
  1421. $('a.comment_remove_link').jConfirmAction({
  1422. question : string_comment_delete_confirm_sentence,
  1423. yesAnswer : string_comment_delete_confirm_yes,
  1424. cancelAnswer : string_comment_delete_confirm_no,
  1425. onYes: function(link){
  1426. var li = link.parents('li.comment');
  1427. li.find('img.comment_loader').show();
  1428. $.getJSON(link.attr('href'), function(response){
  1429. li.find('img.comment_loader').hide();
  1430. if (response.status == 'mustbeconnected')
  1431. {
  1432. $(location).attr('href', url_index);
  1433. }
  1434. if (response.status == 'success')
  1435. {
  1436. li.remove();
  1437. }
  1438. });
  1439. return false;
  1440. },
  1441. onOpen: function(link){
  1442. var li = link.parents('li.comment');
  1443. li.find('a.comment_edit_link').addClass('mustBeDisplayed');
  1444. li.find('a.comment_remove_link').addClass('mustBeDisplayed');
  1445. },
  1446. onClose: function(link){
  1447. var li = link.parents('li.comment');
  1448. li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
  1449. li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
  1450. li.find('a.comment_edit_link').hide();
  1451. li.find('a.comment_remove_link').hide();
  1452. }
  1453. });
  1454. var comments_edited = new Array();
  1455. // Modification
  1456. // Ouverture du formulaire de modification
  1457. $('a.comment_edit_link').live('click', function(){
  1458. var link = $(this);
  1459. var li = link.parents('li.comment');
  1460. // On garde en mémoire l'élément édité en cas d'annulation
  1461. comments_edited[li.attr('id')] = li.html();
  1462. var loader = li.find('img.comment_loader');
  1463. li.html(loader);
  1464. li.find('img.comment_loader').show();
  1465. $.getJSON($(this).attr('href'), function(response) {
  1466. if (response.status == 'mustbeconnected')
  1467. {
  1468. $(location).attr('href', url_index);
  1469. }
  1470. li.html(response.html);
  1471. // On rend ce formulaire ajaxFormable
  1472. $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
  1473. var li_current = $(this).parents('li.comment');
  1474. li_current.prepend(loader);
  1475. li_current.find('img.comment_loader').show();
  1476. });
  1477. li.find('form.edit_comment').ajaxForm(function(response){
  1478. li = $('li#'+response.dom_id);
  1479. li.find('img.comment_loader').hide();
  1480. if (response.status == 'mustbeconnected')
  1481. {
  1482. $(location).attr('href', url_index);
  1483. }
  1484. if (response.status == 'success')
  1485. {
  1486. li.html(response.html);
  1487. delete(comments_edited[li.attr('id')]);
  1488. }
  1489. else if (response.status == 'error')
  1490. {
  1491. li.find('ul.error_list').remove();
  1492. var ul_errors = $('<ul>').addClass('error_list');
  1493. for (i in response.errors)
  1494. {
  1495. ul_errors.append($('<li>').append(response.errors[i]));
  1496. }
  1497. li.prepend(ul_errors);
  1498. }
  1499. });
  1500. });
  1501. return false;
  1502. });
  1503. // Annulation d'un formulaire de modification d'un comment
  1504. $('form.edit_comment input.cancel').live('click', function(){
  1505. var li = $(this).parents('li.comment');
  1506. li.html(comments_edited[li.attr('id')]);
  1507. delete(comments_edited[li.attr('id')]);
  1508. });
  1509. /*
  1510. * Ajout d'un tag en favoris a partir d'un élément
  1511. */
  1512. $('li.element_tag').live({
  1513. mouseenter:
  1514. function()
  1515. {
  1516. $(this).find('a.tag_to_favorites').show();
  1517. $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
  1518. },
  1519. mouseleave:
  1520. function()
  1521. {
  1522. if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
  1523. {
  1524. $(this).find('a.tag_to_favorites').hide();
  1525. $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
  1526. }
  1527. }
  1528. }
  1529. );
  1530. $('a.tag_to_favorites').jConfirmAction({
  1531. question : string_tag_addtofav_confirm_sentence,
  1532. yesAnswer : string_tag_addtofav_confirm_yes,
  1533. cancelAnswer : string_tag_addtofav_confirm_no,
  1534. onYes: function(link){
  1535. $.getJSON(link.attr('href'), function(response){
  1536. if (response.status == 'mustbeconnected')
  1537. {
  1538. $(location).attr('href', url_index);
  1539. }
  1540. });
  1541. $('div.question').fadeOut();
  1542. return false;
  1543. },
  1544. onOpen: function(link){
  1545. var li = link.parents('li.element_tag');
  1546. li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
  1547. },
  1548. onClose: function(link){
  1549. var li = link.parents('li.element_tag');
  1550. li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
  1551. li.find('a.element_tag').removeClass('element_tag_large_for_fav');
  1552. li.find('a.tag_to_favorites').hide();
  1553. }
  1554. });
  1555. /*
  1556. * Ajout dans un groupe de l'élément envoyé
  1557. */
  1558. $('a.added_element_add_to_group').live('click', function(){
  1559. var loader = $('div#added_element_to_group').find('img.loader');
  1560. loader.show();
  1561. $.getJSON($(this).attr('href'), function(response) {
  1562. loader.hide();
  1563. if (response.status == 'mustbeconnected')
  1564. {
  1565. $(location).attr('href', url_index);
  1566. }
  1567. if (response.status == 'success')
  1568. {
  1569. $('li#'+response.dom_id).html(response.html);
  1570. }
  1571. $('div#added_element_to_group').slideUp();
  1572. $('a#element_add_link').show();
  1573. });
  1574. return false;
  1575. });
  1576. $('div#added_element_to_group a.cancel').live('click', function(){
  1577. $('div#added_element_to_group').slideUp();
  1578. $('a#element_add_link').show();
  1579. return false;
  1580. });
  1581. /*
  1582. * Report / signalement d'un élément
  1583. */
  1584. $('a.element_report').jConfirmAction({
  1585. question : string_elementreport_confirm_sentence,
  1586. yesAnswer : string_elementreport_confirm_yes,
  1587. cancelAnswer : string_elementreport_confirm_no,
  1588. onYes: function(link){
  1589. $.getJSON(link.attr('href'), function(response){
  1590. if (response.status == 'mustbeconnected')
  1591. {
  1592. $(location).attr('href', url_index);
  1593. }
  1594. });
  1595. $('div.question').fadeOut();
  1596. return false;
  1597. },
  1598. onOpen: function(link){
  1599. },
  1600. onClose: function(link){
  1601. }
  1602. });
  1603. /*
  1604. * Vote sur element
  1605. */
  1606. $('li.element a.vote').live('click', function(){
  1607. var img = $(this).find('img');
  1608. var link = $(this);
  1609. img.attr('src', url_img_ajax_loader);
  1610. $.getJSON(link.attr('href'), function(response){
  1611. if (response.status == 'mustbeconnected')
  1612. {
  1613. $(location).attr('href', url_index);
  1614. }
  1615. if (response.status == 'success')
  1616. {
  1617. link.attr('href', response.data.a.href);
  1618. img.attr('src', response.data.img.src);
  1619. link.parents('td.right').find('li.score span.score').html(response.data.element.points);
  1620. }
  1621. });
  1622. return false;
  1623. });
  1624. // Enlever les ids du ElementSearch
  1625. $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
  1626. $('img.elements_more_loader').show();
  1627. $('ul.elements').html('');
  1628. var link = $(this);
  1629. $.getJSON(link.attr('href'), function(response){
  1630. if (response.status == 'mustbeconnected')
  1631. {
  1632. $(location).attr('href', url_index);
  1633. }
  1634. if (response.status == 'success')
  1635. {
  1636. $('form[name="search"]').submit();
  1637. $('div.more_filters a.new_comments').hide();
  1638. $('div.more_filters a.new_favorites').hide();
  1639. $('div.more_filters a.new_tags').hide();
  1640. }
  1641. });
  1642. return false;
  1643. });
  1644. /*
  1645. *
  1646. * Proposition de tags sur un élément
  1647. *
  1648. */
  1649. // Ouverture du formulaire de modification
  1650. $('a.element_propose_tags').live('click', function(){
  1651. var link = $(this);
  1652. var li = link.parents('li.element');
  1653. li.find('img.element_loader').show();
  1654. $.getJSON($(this).attr('href'), function(response) {
  1655. if (response.status == 'mustbeconnected')
  1656. {
  1657. $(location).attr('href', url_index);
  1658. }
  1659. li.find('img.element_loader').hide();
  1660. if (response.status == 'success')
  1661. {
  1662. // On prépare le tagBox
  1663. var table = li.find('table:first');
  1664. li.find('div.tag_proposition').remove();
  1665. table.after(response.html);
  1666. // Pour le click sur l'input de saisie de tag
  1667. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  1668. var options = new Array();
  1669. options.form_name = response.form_name;
  1670. options.tag_init = response.tags;
  1671. ajax_query_timestamp = null;
  1672. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  1673. // On rend ce formulaire ajaxFormable
  1674. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  1675. li = $(this).parents('li.element');
  1676. li.find('img.element_loader').show();
  1677. });
  1678. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  1679. if (response.status == 'mustbeconnected')
  1680. {
  1681. $(location).attr('href', url_index);
  1682. }
  1683. if (response.status == 'success')
  1684. {
  1685. li = $('li#'+response.dom_id);
  1686. li.find('img.element_loader').hide();
  1687. li.find('form')
  1688. li.find('div.tag_proposition').remove();
  1689. }
  1690. else if (response.status == 'error')
  1691. {
  1692. li.find('img.element_loader').hide();
  1693. li.find('ul.error_list').remove();
  1694. var ul_errors = $('<ul>').addClass('error_list');
  1695. for (i in response.errors)
  1696. {
  1697. ul_errors.append($('<li>').append(response.errors[i]));
  1698. }
  1699. li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
  1700. }
  1701. });
  1702. }
  1703. });
  1704. return false;
  1705. });
  1706. // Annulation d'un formulaire de modification d'élément
  1707. $('div.tag_proposition input.cancel').live('click', function(){
  1708. $(this).parents('div.tag_proposition').slideUp();
  1709. });
  1710. // Ouvrir les propositions de tags de l'élément
  1711. $('a.element_view_propositions_link').live('click', function(){
  1712. var link = $(this);
  1713. li = link.parents('li.element');
  1714. li.find('img.element_loader').show();
  1715. $.getJSON($(this).attr('href'), function(response) {
  1716. if (response.status == 'mustbeconnected')
  1717. {
  1718. $(location).attr('href', url_index);
  1719. }
  1720. li.find('img.element_loader').hide();
  1721. if (response.status == 'success')
  1722. {
  1723. var table = li.find('table:first');
  1724. li.find('div.tags_proposition_view').remove();
  1725. table.after(response.html);
  1726. }
  1727. });
  1728. return false;
  1729. });
  1730. $('a.accept_tag_propotision').live('click', function(){
  1731. var link = $(this);
  1732. var li = link.parents('li.element');
  1733. li.find('img.element_loader').show();
  1734. $.getJSON($(this).attr('href'), function(response) {
  1735. if (response.status == 'mustbeconnected')
  1736. {
  1737. $(location).attr('href', url_index);
  1738. }
  1739. li.find('img.element_loader').hide();
  1740. if (response.status == 'success')
  1741. {
  1742. li.html(response.html);
  1743. }
  1744. });
  1745. return false;
  1746. });
  1747. //
  1748. $('a.refuse_tag_propositions').live('click', function(){
  1749. var link = $(this);
  1750. var li = link.parents('li.element');
  1751. li.find('img.element_loader').show();
  1752. $.getJSON($(this).attr('href'), function(response) {
  1753. if (response.status == 'mustbeconnected')
  1754. {
  1755. $(location).attr('href', url_index);
  1756. }
  1757. li.find('img.element_loader').hide();
  1758. if (response.status == 'success')
  1759. {
  1760. li.find('div.tags_proposition_view').remove();
  1761. }
  1762. });
  1763. return false;
  1764. });
  1765. /*
  1766. * Proposition de tag sur un élément FIN
  1767. */
  1768. /*
  1769. * Report / signalement d'un commentaire
  1770. */
  1771. $('a.comment_report').jConfirmAction({
  1772. question : string_commentreport_confirm_sentence,
  1773. yesAnswer : string_commentreport_confirm_yes,
  1774. cancelAnswer : string_commentreport_confirm_no,
  1775. onYes: function(link){
  1776. $.getJSON(link.attr('href'), function(response){
  1777. if (response.status == 'mustbeconnected')
  1778. {
  1779. $(location).attr('href', url_index);
  1780. }
  1781. });
  1782. $('div.question').fadeOut();
  1783. return false;
  1784. },
  1785. onOpen: function(link){
  1786. },
  1787. onClose: function(link){
  1788. }
  1789. });
  1790. /*
  1791. * reshare repartage
  1792. */
  1793. $('a.element_reshare').jConfirmAction({
  1794. question : string_elementreshare_confirm_sentence,
  1795. yesAnswer : string_elementreshare_confirm_yes,
  1796. cancelAnswer : string_elementreshare_confirm_no,
  1797. onYes: function(link){
  1798. $('div.question').fadeOut();
  1799. $.getJSON(link.attr('href'), function(response){
  1800. if (response.status == 'mustbeconnected')
  1801. {
  1802. $(location).attr('href', url_index);
  1803. }
  1804. // On affiche l'élément que si on voit que le formulaire est sur la page
  1805. // Sinon c'est qu'on est sur une page ou on a pas normalement la possibilité
  1806. // d'ajouetr un élément.
  1807. if ($('form[name="add"]').length)
  1808. {
  1809. element_add_proceed_json_response(response);
  1810. }
  1811. return false;
  1812. });
  1813. return false;
  1814. },
  1815. onOpen: function(link){
  1816. },
  1817. onClose: function(link){
  1818. }
  1819. });
  1820. });