muzich.js 69KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  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. $('.message').hide();
  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 array_key_exists (key, search) {
  40. // http://kevin.vanzonneveld.net
  41. // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  42. // + improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
  43. // * example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
  44. // * returns 1: true
  45. // input sanitation
  46. if (!search || (search.constructor !== Array && search.constructor !== Object)) {
  47. return false;
  48. }
  49. return key in search;
  50. }
  51. function json_to_array(json_string)
  52. {
  53. if (json_string.length)
  54. {
  55. return eval("(" + json_string + ")");
  56. }
  57. return new Array();
  58. }
  59. function strpos (haystack, needle, offset) {
  60. // Finds position of first occurrence of a string within another
  61. //
  62. // version: 1109.2015
  63. // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  64. // + improved by: Onno Marsman
  65. // + bugfixed by: Daniel Esteban
  66. // + improved by: Brett Zamir (http://brett-zamir.me)
  67. // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
  68. var i = (haystack + '').indexOf(needle, (offset || 0));
  69. return i === -1 ? false : i;
  70. }
  71. /**
  72. * Converts the given data structure to a JSON string.
  73. * Argument: arr - The data structure that must be converted to JSON
  74. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  75. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  76. * http://www.openjs.com/scripts/data/json_encode.php
  77. */
  78. function array2json(arr) {
  79. var parts = [];
  80. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  81. for(var key in arr) {
  82. var value = arr[key];
  83. if(typeof value == "object") { //Custom handling for arrays
  84. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  85. else parts[key] = array2json(value); /* :RECURSION: */
  86. } else {
  87. var str = "";
  88. if(!is_list) str = '"' + key + '":';
  89. //Custom handling for multiple data types
  90. if(typeof value == "number") str += value; //Numbers
  91. else if(value === false) str += 'false'; //The booleans
  92. else if(value === true) str += 'true';
  93. else str += '"' + value + '"'; //All other things
  94. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  95. parts.push(str);
  96. }
  97. }
  98. var json = parts.join(",");
  99. if(is_list) return '[' + json + ']';//Return numerical JSON
  100. return '{' + json + '}';//Return associative JSON
  101. }
  102. function isInteger(s) {
  103. return (s.toString().search(/^-?[0-9]+$/) == 0);
  104. }
  105. function inArray(array, p_val) {
  106. var l = array.length;
  107. for(var i = 0; i < l; i++) {
  108. if(array[i] == p_val) {
  109. return true;
  110. }
  111. }
  112. return false;
  113. }
  114. if(typeof(String.prototype.trim) === "undefined")
  115. {
  116. String.prototype.trim = function()
  117. {
  118. return String(this).replace(/^\s+|\s+$/g, '');
  119. };
  120. }
  121. function str_replace (search, replace, subject, count) {
  122. // Replaces all occurrences of search in haystack with replace
  123. //
  124. // version: 1109.2015
  125. // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  126. // + improved by: Gabriel Paderni
  127. // + improved by: Philip Peterson
  128. // + improved by: Simon Willison (http://simonwillison.net)
  129. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
  130. // + input by: Onno Marsman
  131. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  132. // + tweaked by: Onno Marsman
  133. // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  134. // + input by: Oleg Eremeev
  135. // + improved by: Brett Zamir (http://brett-zamir.me)
  136. // + bugfixed by: Oleg Eremeev
  137. // % 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
  138. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  139. // * returns 1: 'Kevin.van.Zonneveld'
  140. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  141. // * returns 2: 'hemmo, mars' var i = 0,
  142. j = 0,
  143. temp = '',
  144. repl = '',
  145. sl = 0, fl = 0,
  146. f = [].concat(search),
  147. r = [].concat(replace),
  148. s = subject,
  149. ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
  150. s = [].concat(s);
  151. if (count) {
  152. this.window[count] = 0;
  153. }
  154. for (i = 0, sl = s.length; i < sl; i++) {
  155. if (s[i] === '') {
  156. continue;
  157. }for (j = 0, fl = f.length; j < fl; j++) {
  158. temp = s[i] + '';
  159. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  160. s[i] = (temp).split(f[j]).join(repl);
  161. if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
  162. }
  163. }
  164. }
  165. return sa ? s : s[0];
  166. }
  167. function explode (delimiter, string, limit) {
  168. // 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.
  169. //
  170. // version: 1109.2015
  171. // discuss at: http://phpjs.org/functions/explode // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  172. // + improved by: kenneth
  173. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  174. // + improved by: d3x
  175. // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: explode(' ', 'Kevin van Zonneveld');
  176. // * returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
  177. // * example 2: explode('=', 'a=bc=d', 2);
  178. // * returns 2: ['a', 'bc=d']
  179. var emptyArray = {0: ''
  180. };
  181. // third argument is not required
  182. if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {return null;
  183. }
  184. if (delimiter === '' || delimiter === false || delimiter === null) {
  185. return false;}
  186. if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
  187. return emptyArray;
  188. }
  189. if (delimiter === true) {
  190. delimiter = '1';
  191. }
  192. if (!limit) {
  193. return string.toString().split(delimiter.toString());
  194. }
  195. // support for limit argument
  196. var splitted = string.toString().split(delimiter.toString());var partA = splitted.splice(0, limit - 1);
  197. var partB = splitted.join(delimiter.toString());
  198. partA.push(partB);
  199. return partA;
  200. }
  201. // fonction de nettoyage des tags
  202. function remove_tags(form_name)
  203. {
  204. //tagsAddeds[form_name] = new Array();
  205. //$('form[name="'+form_name+'"] ul.tagbox li.tag').remove();
  206. //$('form[name="'+form_name+'"] input.tagBox_tags_ids').val('');
  207. }
  208. function JQueryJson(url, data, callback_success)
  209. {
  210. $.ajax({
  211. type: 'POST',
  212. url: url,
  213. dataType: 'json',
  214. data: data,
  215. success: function(response)
  216. {
  217. if (response.status == 'mustbeconnected')
  218. {
  219. $(location).attr('href', url_index);
  220. }
  221. callback_success(response);
  222. }
  223. });
  224. }
  225. $(document).ready(function(){
  226. // Controle du focus sur la page
  227. function onBlur() {
  228. document.body.className = 'blurred';
  229. }
  230. function onFocus(){
  231. document.body.className = 'focused';
  232. do_action_body_focused();
  233. }
  234. if (/*@cc_on!@*/false) { // check for Internet Explorer
  235. document.onfocusin = onFocus;
  236. document.onfocusout = onBlur;
  237. } else {
  238. window.onfocus = onFocus;
  239. window.onblur = onBlur;
  240. }
  241. // Bouton de personalisation du filtre
  242. // Aucun tags
  243. $('#tabs_tag_search_no_tags, a.filter_clear_url').live("click", function(){
  244. $('img.elements_more_loader').show();
  245. $('ul.elements').html('');
  246. // On initialise la liste de tags déjà ajouté
  247. window.search_tag_prompt_connector.initializeTags([]);
  248. $('div.no_elements').hide();
  249. //tagsAddeds['search'] = new Array;
  250. var form = $('form[name="search"]');
  251. //remove_tags(form.attr('name'));
  252. form.submit();
  253. });
  254. // tags préférés
  255. $('#tabs_tag_search_with_tags').live("click", function(){
  256. $('img.elements_more_loader').show();
  257. $('ul.elements').html('');
  258. var form = $('form[name="search"]');
  259. $.getJSON(url_get_favorites_tags, function(response) {
  260. if (response.status == 'mustbeconnected')
  261. {
  262. $(location).attr('href', url_index);
  263. }
  264. var tags = [];
  265. for (i in response.tags)
  266. {
  267. var tag = new Tag(i, response.tags[i]);
  268. tags.push(tag);
  269. }
  270. window.search_tag_prompt_connector.initializeTags(tags);
  271. form.submit();
  272. });
  273. });
  274. // Tag cliqué dans la liste d'éléments
  275. $('ul.element_tags li a.element_tag').live('click', function(){
  276. // Si il y a une liste de tags (comme sur la page favoris, profil)
  277. var id;
  278. if ($('ul#favorite_tags').length)
  279. {
  280. id = str_replace('element_tag_', '', $(this).attr('id'));
  281. var link = $('a#filtering_tag_'+id);
  282. list_tag_clicked(link, true);
  283. }
  284. if ($('form[name="search"]').length)
  285. {
  286. $('img.elements_more_loader').show();
  287. $('ul.elements').html('');
  288. var form = $('form[name="search"]');
  289. id = str_replace('element_tag_', '', $(this).attr('id'));
  290. var tag = new Tag(id, $(this).text());
  291. window.search_tag_prompt_connector.initializeTags([tag]);
  292. form.submit();
  293. }
  294. });
  295. function element_last_opened(li)
  296. {
  297. $('li.element').removeClass('shadows');
  298. li.addClass('shadows');
  299. }
  300. // Affichage un/des embed
  301. // 1328283150_media-playback-start.png
  302. // 1328283201_emblem-symbolic-link.png
  303. $('a.element_embed_open_link').live("click", function(){
  304. var li = $(this).parents('li.element');
  305. element_last_opened(li);
  306. li.find('a.element_embed_close_link').show();
  307. li.find('a.element_embed_open_link_text').hide();
  308. li.find('div.element_embed').show();
  309. return false;
  310. });
  311. $('a.element_name_embed_open_link').live("click", function(){
  312. var li = $(this).parents('li.element');
  313. element_last_opened(li);
  314. li.find('a.element_embed_close_link').show();
  315. li.find('a.element_embed_open_link_text').hide();
  316. li.find('div.element_embed').show();
  317. return false;
  318. });
  319. // Fermeture du embed si demandé
  320. $('a.element_embed_close_link').live("click", function(){
  321. var li = $(this).parents('li.element');
  322. li.removeClass('shadows');
  323. li.find('div.element_embed').hide();
  324. li.find('a.element_embed_open_link_text').show();
  325. $(this).hide();
  326. return false;
  327. });
  328. // Affichage du "play" ou du "open" (image png)
  329. $('li.element a.a_thumbnail, li.element img.open, li.element img.play').live({
  330. mouseenter:
  331. function()
  332. {
  333. var td = $(this).parent('td');
  334. var a = td.find('a.a_thumbnail');
  335. if (a.hasClass('embed'))
  336. {
  337. td.find('img.play').show();
  338. }
  339. else
  340. {
  341. td.find('img.open').show();
  342. }
  343. },
  344. mouseleave:
  345. function()
  346. {
  347. var td = $(this).parent('td');
  348. var a = td.find('a.a_thumbnail');
  349. if (a.hasClass('embed'))
  350. {
  351. td.find('img.play').hide();
  352. }
  353. else
  354. {
  355. td.find('img.open').hide();
  356. }
  357. }
  358. }
  359. );
  360. // Mise en favoris
  361. $('a.favorite_link').live("click", function(){
  362. var link = $(this);
  363. // Pour ne pas attendre la fin du chargement ajax:
  364. var img = link.find('img');
  365. if (!link.hasClass('loading'))
  366. {
  367. if (img.attr('src') == '/img/icon_star_2.png')
  368. {
  369. img.attr('src', '/img/icon_star_2_red.png');
  370. }
  371. else
  372. {
  373. img.attr('src', '/img/icon_star_2.png');
  374. }
  375. }
  376. link.addClass('loading');
  377. $.getJSON($(this).attr('href'), function(response) {
  378. if (response.status == 'mustbeconnected')
  379. {
  380. $(location).attr('href', url_index);
  381. }
  382. var img = link.find('img');
  383. link.attr('href', response.link_new_url);
  384. img.attr('src', response.img_new_src);
  385. img.attr('title', response.img_new_title);
  386. link.removeClass('loading');
  387. });
  388. return false;
  389. });
  390. // // Affichage du bouton Modifier et Supprimer
  391. // $('ul.elements li.element').live({
  392. // mouseenter:
  393. // function()
  394. // {
  395. // $(this).find('a.element_edit_link').show();
  396. // $(this).find('a.element_remove_link').show();
  397. // },
  398. // mouseleave:
  399. // function()
  400. // {
  401. // if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
  402. // {
  403. // $(this).find('a.element_edit_link').hide();
  404. // }
  405. // if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
  406. // {
  407. // $(this).find('a.element_remove_link').hide();
  408. // }
  409. // }
  410. // }
  411. // );
  412. // Plus d'éléments
  413. var last_id = null;
  414. $('a.elements_more').click(function(){
  415. var link = $(this);
  416. var last_element = $('ul.elements li.element:last-child');
  417. var id_last = str_replace('element_', '', last_element.attr('id'));
  418. var invertcolor = 0;
  419. if (last_element.hasClass('even'))
  420. {
  421. invertcolor = 1;
  422. }
  423. $('img.elements_more_loader').show();
  424. var url = link.attr('href')+'/'+id_last+'/'+invertcolor;
  425. // Cas exeptionel si on se trouve sur la global_search
  426. if ($('div#results_search_form').length)
  427. {
  428. url = link.attr('href')+id_last+'/'+$('div#results_search_form form input[type="text"]').val();
  429. }
  430. var old_form_action = $('form[name="search"]').attr('action');
  431. $('form[name="search"]').attr('action', url);
  432. $.ajax({
  433. type: 'POST',
  434. url: url,
  435. data: $('form[name="search"]').serialize(),
  436. success: function(response) {
  437. if (response.status == 'mustbeconnected')
  438. {
  439. $(location).attr('href', url_index);
  440. }
  441. if (response.count)
  442. {
  443. $('ul.elements').append(response.html);
  444. $('img.elements_more_loader').hide();
  445. recolorize_element_list();
  446. }
  447. if (response.end || response.count < 1)
  448. {
  449. $('img.elements_more_loader').hide();
  450. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  451. response.message+'</p></div>');
  452. link.hide();
  453. }
  454. },
  455. dataType: "json"
  456. });
  457. $('form[name="search"]').attr('action', old_form_action);
  458. // $.getJSON(url, function(response) {
  459. // if (response.status == 'mustbeconnected')
  460. // {
  461. // $(location).attr('href', url_index);
  462. // }
  463. //
  464. // if (response.count)
  465. // {
  466. // $('ul.elements').append(response.html);
  467. // $('img.elements_more_loader').hide();
  468. // recolorize_element_list();
  469. // }
  470. //
  471. // if (response.end || response.count < 1)
  472. // {
  473. // $('img.elements_more_loader').hide();
  474. // $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  475. // response.message+'</p></div>');
  476. // link.hide();
  477. // }
  478. // });
  479. return false;
  480. });
  481. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  482. // Filtre et affichage éléments ajax
  483. $('form[name="search"] input[type="submit"]').click(function(){
  484. $('ul.elements').html('');
  485. $('div.no_elements').hide();
  486. $('img.elements_more_loader').show();
  487. });
  488. $('form[name="search"]').ajaxForm(function(response) {
  489. if (response.status == 'mustbeconnected')
  490. {
  491. $(location).attr('href', url_index);
  492. }
  493. $('ul.elements').html(response.html);
  494. if (response.count)
  495. {
  496. $('img.elements_more_loader').hide();
  497. $('span.elements_more').show();
  498. $('a.elements_more').show();
  499. }
  500. if (response.count < 1)
  501. {
  502. $('img.elements_more_loader').hide();
  503. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  504. response.message+'</p></div>');
  505. $('a.elements_more').hide()
  506. ;
  507. }
  508. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  509. });
  510. // Suppression d'un element
  511. $('a.element_remove_link').jConfirmAction({
  512. question : string_element_delete_confirm_sentence,
  513. yesAnswer : string_element_delete_confirm_yes,
  514. cancelAnswer : string_element_delete_confirm_no,
  515. onYes: function(link){
  516. var li = link.parents('li.element');
  517. li.find('img.element_loader').show();
  518. $.getJSON(link.attr('href'), function(response){
  519. if (response.status == 'mustbeconnected')
  520. {
  521. $(location).attr('href', url_index);
  522. }
  523. if (response.status == 'success')
  524. {
  525. li.remove();
  526. }
  527. else
  528. {
  529. li.find('img.element_loader').hide();
  530. }
  531. });
  532. return false;
  533. },
  534. onOpen: function(link){
  535. var li = link.parents('li.element');
  536. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  537. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  538. },
  539. onClose: function(link){
  540. var li = link.parents('li.element');
  541. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  542. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  543. li.find('a.element_edit_link').hide();
  544. li.find('a.element_remove_link').hide();
  545. }
  546. });
  547. var elements_edited = new Array();
  548. // Ouverture du formulaire de modification
  549. $('a.element_edit_link').live('click', function(){
  550. var link = $(this);
  551. var li = link.parents('li.element');
  552. // On garde en mémoire l'élément édité en cas d'annulation
  553. elements_edited[li.attr('id')] = li.html();
  554. var div_loader = li.find('div.loader');
  555. li.html(div_loader);
  556. li.find('img.element_loader').show();
  557. $.getJSON($(this).attr('href'), function(response) {
  558. if (response.status == 'mustbeconnected')
  559. {
  560. $(location).attr('href', url_index);
  561. }
  562. // On prépare le tagBox
  563. li.html(response.html);
  564. // Pour le click sur l'input de saisie de tag
  565. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  566. var options = new Array();
  567. options.form_name = response.form_name;
  568. options.tag_init = response.tags;
  569. ajax_query_timestamp = null;
  570. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  571. // On rend ce formulaire ajaxFormable
  572. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  573. var li = $(this).parents('li.element');
  574. li.prepend(div_loader);
  575. li.find('img.element_loader').show();
  576. });
  577. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  578. if (response.status == 'mustbeconnected')
  579. {
  580. $(location).attr('href', url_index);
  581. }
  582. var li = $('li#'+response.dom_id);
  583. if (response.status == 'success')
  584. {
  585. li.html(response.html);
  586. delete(elements_edited[li.attr('id')]);
  587. }
  588. else if (response.status == 'error')
  589. {
  590. li.find('img.element_loader').hide();
  591. li.find('ul.error_list').remove();
  592. var ul_errors = $('<ul>').addClass('error_list');
  593. for (i in response.errors)
  594. {
  595. ul_errors.append($('<li>').append(response.errors[i]));
  596. }
  597. li.prepend(ul_errors);
  598. }
  599. });
  600. });
  601. return false;
  602. });
  603. // Annulation d'un formulaire de modification d'élément
  604. $('form.edit_element input.cancel_edit').live('click', function(){
  605. var li = $(this).parents('li.element');
  606. li.html(elements_edited[li.attr('id')]);
  607. delete(elements_edited[li.attr('id')]);
  608. });
  609. ////////////////// TAG PROMPT ///////////////
  610. //
  611. //var ajax_query_timestamp = null;
  612. //
  613. //// Les deux clicks ci-dessous permettent de faire disparaitre
  614. //// la div de tags lorsque l'on clique ailleurs
  615. //$('html').click(function() {
  616. // if ($("div.search_tag_list").is(':visible'))
  617. // {
  618. // $("div.search_tag_list").hide();
  619. // }
  620. //});
  621. //
  622. //$("div.search_tag_list, div.search_tag_list a.more").live('click', function(event){
  623. // event.stopPropagation();
  624. // $("div.search_tag_list").show();
  625. //});
  626. //
  627. //function autocomplete_tag(input, form_name)
  628. //{
  629. // // Il doit y avoir au moin un caractère
  630. // if (input.val().length > 0)
  631. // {
  632. //
  633. // // on met en variable l'input
  634. // var inputTag = input;
  635. //
  636. // // On récupére la div de tags
  637. // var divtags = $("#search_tag_"+form_name);
  638. //
  639. // // Si la fenêtre de tags est caché
  640. // if (!divtags.is(':visible'))
  641. // {
  642. // // On la replace
  643. // var position = input.position();
  644. // divtags.css('left', Math.round(position.left) + 5);
  645. // divtags.css('top', Math.round(position.top) + 28);
  646. // // Et on l'affiche
  647. // divtags.show();
  648. // }
  649. // // On affiche le loader
  650. // $('#tag_loader_'+form_name).show();
  651. // // On cache la liste de tags
  652. // var search_tag_list = divtags.find('ul.search_tag_list');
  653. // // On supprime les anciens li
  654. // search_tag_list.find('li').remove();
  655. // search_tag_list.hide();
  656. // // Et on affiche une info
  657. // var span_info = divtags.find('span.info');
  658. // span_info.show();
  659. // // TODO: multilingue !
  660. // span_info.text(str_replace('%string_search%', input.val(), string_search_tag_title));
  661. //
  662. // // C'est en fonction du nb de resultats qu'il sera affiché
  663. // divtags.find('a.more').hide();
  664. //
  665. // // On récupère le timestamp pour reconnaitre la dernière requête effectué
  666. // ajax_query_timestamp = new Date().getTime();
  667. //
  668. // // Récupération des tags correspondants
  669. // $.ajax({
  670. // type: 'POST',
  671. // url: url_search_tag+'/'+ajax_query_timestamp,
  672. // dataType: 'json',
  673. // data: {'string_search':input.val()},
  674. // success: function(data) {
  675. // if (data.status == 'mustbeconnected')
  676. // {
  677. // $(location).attr('href', url_index);
  678. // }
  679. //
  680. // // Ce contrôle permet de ne pas continuer si une requete
  681. // // ajax a été faite depuis.
  682. // if (data.timestamp == ajax_query_timestamp)
  683. // {
  684. // var status = data.status;
  685. // var tags = data.data;
  686. //
  687. // // Si on spécifie une erreur
  688. // if (status == 'error')
  689. // {
  690. // // On l'affiche a l'utilisateur
  691. // span_info.text(data.error);
  692. // }
  693. // // Si c'est un succés
  694. // else if (status == 'success')
  695. // {
  696. // if (tags.length > 0)
  697. // {
  698. // var more = false;
  699. // // Pour chaque tags retournés
  700. // for (i in tags)
  701. // {
  702. // var tag_name = tags[i]['name'];
  703. // var tag_id = tags[i]['id'];
  704. // var t_string = tag_name
  705. // // On construit un li
  706. //
  707. // var r_string = $.trim(input.val());
  708. // var re = new RegExp(r_string, "i");
  709. // t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
  710. //
  711. //
  712. // var li_tag =
  713. // $('<li>').append(
  714. // $('<a>').attr('id','searched_tag_'+tag_id)
  715. // .attr('href', '#')
  716. // // qui réagit quand on clique dessus
  717. // .click(function(e){
  718. //
  719. // var id = str_replace('searched_tag_', '', $(this).attr('id'));
  720. // var name = $('span#tag_prompt_tag_'+id+'_name').html();
  721. //
  722. // $('input#tags_selected_tag_'+form_name).val(id);
  723. // inputTag.val(name);
  724. // // Et on execute l'évènement selectTag de l'input
  725. // inputTag.trigger("selectTag");
  726. // // On cache la liste puisque le choix vient d'être fait
  727. // divtags.hide();
  728. // // On vide le champs de saisie du tag
  729. // $('input.form-default-value-processed').val('');
  730. // return false;
  731. // })
  732. // .append(t_string)
  733. // ).append($('<span style="display: none;" id="tag_prompt_tag_'+tag_id+'_name">'+tag_name+'</span>'));
  734. //
  735. // // Si on depasse les 30 tags
  736. // if (i > 30)
  737. // {
  738. // more = true;
  739. // // On le cache
  740. // li_tag.hide();
  741. // }
  742. //
  743. // // On ajout ce li a la liste
  744. // search_tag_list.append(li_tag);
  745. // }
  746. //
  747. // if (more)
  748. // {
  749. // divtags.find('a.more').show();
  750. // }
  751. //
  752. // span_info.show();
  753. // span_info.text(data.message);
  754. // // Et on affiche la liste
  755. // search_tag_list.show();
  756. // }
  757. // else
  758. // {
  759. // span_info.show();
  760. // span_info.text(data.message);
  761. // search_tag_list.show();
  762. //
  763. // // Dans ce cas ou aucun tag n'a été trouvé, la proposition
  764. // // d'ajout s'affichecf en dessous
  765. //
  766. // //span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  767. // }
  768. //
  769. // // Si le tag ne semble pas connu en base
  770. // if (!data.same_found)
  771. // {
  772. // li_tag =
  773. // $('<li>').addClass('new').append(
  774. // $('<a>').attr('href','#new#'+$.trim(input.val()))
  775. // // qui réagit quand on clique dessus
  776. // .click({
  777. // inputTag: inputTag,
  778. // form_name: form_name,
  779. // divtags: divtags
  780. // }, event_click_new_tag_proposition)
  781. // .append($.trim(input.val()))
  782. // );
  783. // search_tag_list.append(li_tag);
  784. // }
  785. //
  786. // }
  787. //
  788. // // On cache le loader
  789. // $('#tag_loader_'+form_name).hide();
  790. // }
  791. // }
  792. // });
  793. //
  794. //
  795. // //$.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, );
  796. //
  797. // }
  798. //}
  799. //
  800. //function event_click_new_tag_proposition(event)
  801. //{
  802. // form_add_open_dialog_for_new_tag($(event.target), event.data.inputTag, event.data.form_name, event.data.divtags);
  803. //}
  804. //
  805. //function form_add_open_dialog_for_new_tag(link_add_tag, inputTag, form_name, divtags)
  806. //{
  807. //
  808. //
  809. // // Effet fade-in du fond opaque
  810. // $('body').append($('<div>').attr('id', 'fade'));
  811. // //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  812. // $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  813. //
  814. // // En premier lieux on fait apparaître la fenêtre de confirmation
  815. // var popup = $('<div>')
  816. // .attr('id', 'add_tag')
  817. // .addClass('popin_block')
  818. // .css('width', '400px')
  819. // //.append($('<h2>').append(string_tag_add_title))
  820. // .append($('<form>')
  821. // .attr('action', url_add_tag)
  822. // .attr('method', 'post')
  823. // .attr('name', 'add_tag')
  824. // .ajaxForm(function(response) {
  825. // /*
  826. // *
  827. // */
  828. //
  829. // if (response.status == 'mustbeconnected')
  830. // {
  831. // $(location).attr('href', url_index);
  832. // }
  833. //
  834. // if (response.status == 'success')
  835. // {
  836. // var tag_id = response.tag_id;
  837. // var tag_name = response.tag_name;
  838. //
  839. // $('input#tags_selected_tag_'+form_name).val(tag_id);
  840. // inputTag.val(tag_name);
  841. // // Et on execute l'évènement selectTag de l'input
  842. // inputTag.trigger("selectTag");
  843. // // On cache la liste puisque le choix vient d'être fait
  844. // divtags.hide();
  845. //
  846. // link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
  847. //
  848. // $('#fade').fadeOut(400, function(){$('#fade').remove();});
  849. // $('#add_tag').remove();
  850. // }
  851. //
  852. // if (response.status == 'error')
  853. // {
  854. // $('form[name="add_tag"]').find('ul.error_list').remove();
  855. // var ul_errors = $('<ul>').addClass('error_list');
  856. //
  857. // for (i in response.errors)
  858. // {
  859. // ul_errors.append($('<li>').append(response.errors[i]));
  860. // }
  861. //
  862. // $('form[name="add_tag"]').prepend(ul_errors);
  863. // }
  864. //
  865. // return false;
  866. // })
  867. //
  868. // .append($('<div>').addClass('tag')
  869. // .append($('<ul>')
  870. // .append($('<li>').addClass('button')
  871. // .append(link_add_tag.text()))))
  872. // .append($('<p>').append(string_tag_add_text))
  873. // .append($('<p>').append(string_tag_add_argument))
  874. // .append($('<textarea>').attr('name', 'argument'))
  875. // .append($('<div>').addClass('inputs')
  876. // .append($('<input>')
  877. // .attr('type', 'button')
  878. // .attr('value', string_tag_add_inputs_cancel)
  879. // .addClass('button')
  880. // .click(function(){
  881. // $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  882. // $('#add_tag').remove();
  883. //
  884. // return false;
  885. // })
  886. // )
  887. // .append($('<input>')
  888. // .attr('type', 'submit')
  889. // .attr('value', string_tag_add_inputs_submit)
  890. // .addClass('button')
  891. // .click(function(){
  892. //
  893. // link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
  894. //
  895. // })
  896. // )
  897. // .append($('<input>').attr('type', 'hidden').attr('name', 'tag_name').val(link_add_tag.text()))
  898. // ))
  899. // ;
  900. //
  901. // // Il faut ajouter le popup au dom avant de le positionner en css
  902. // // Sinon la valeur height n'est pas encore calculable
  903. // $('body').prepend(popup);
  904. //
  905. // //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
  906. // var popMargTop = (popup.height() + 50) / 2;
  907. // var popMargLeft = (popup.width() + 50) / 2;
  908. //
  909. // //On affecte le margin
  910. // $(popup).css({
  911. // 'margin-top' : -popMargTop,
  912. // 'margin-left' : -popMargLeft
  913. // });
  914. //
  915. // return false;
  916. //}
  917. //
  918. //var last_keypress = 0;
  919. //
  920. //function check_timelaps_and_search(input, form_name, time_id, timed, info)
  921. //{
  922. // if (!timed)
  923. // {
  924. // // C'est une nouvelle touche (pas redirigé) on lui donne un id
  925. // // et on met a jour l'id de la dernière pressé
  926. // last_keypress = new Date().getTime();
  927. // var this_time_id = last_keypress;
  928. // }
  929. // else
  930. // {
  931. // // Si elle a été redirigé, on met son id dans cette variable
  932. // var this_time_id = time_id;
  933. // }
  934. //
  935. // // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  936. // if (time_id != last_keypress && timed)
  937. // {
  938. // // elle disparait
  939. // }
  940. // else
  941. // {
  942. // //
  943. // if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  944. // {
  945. // // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  946. // // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  947. // // elle doit attendre au cas ou soit pressé.
  948. // setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  949. // }
  950. // else
  951. // {
  952. // // il n'y a plus a attendre, on envoie la demande de tag.
  953. // autocomplete_tag(input, form_name);
  954. // }
  955. // }
  956. //}
  957. //
  958. //// Autocompletion de tags
  959. //$("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  960. //
  961. // var form_name = $(this).parents('form').attr('name');
  962. // var code = (e.keyCode ? e.keyCode : e.which);
  963. //
  964. // if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  965. // {
  966. // check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  967. // }
  968. //
  969. //});
  970. //
  971. //// Un click sur ce lien affiche tout les tags cachés de la liste
  972. //$('div.search_tag_list a.more').live('click', function(){
  973. // jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  974. // $(this).show();
  975. // });
  976. // $(this).hide();
  977. // return false;
  978. //});
  979. //
  980. //$('ul.tagbox li.input input[type="text"]').formDefaults();
  981. //
  982. ////////////////// FIN TAG PROMPT ///////////////
  983. // Suppression d'un element
  984. $('a.group_remove_link').jConfirmAction({
  985. question : "Supprimer ce groupe ?",
  986. yesAnswer : "Oui",
  987. cancelAnswer : "Non",
  988. onYes: function(link){
  989. window.location = link.attr('href');
  990. return false;
  991. },
  992. onOpen: function(){},
  993. onClose: function(){}
  994. });
  995. // Selection Réseau global / Mon réseau
  996. $('div.select_network a').live('click', function(){
  997. var divSelect = $(this).parent('div');
  998. if ($(this).hasClass('all_network'))
  999. {
  1000. divSelect.find('a.all_network').addClass('active');
  1001. divSelect.find('a.my_network').removeClass('active');
  1002. divSelect.find('select').val('network_public');
  1003. }
  1004. else
  1005. {
  1006. divSelect.find('a.my_network').addClass('active');
  1007. divSelect.find('a.all_network').removeClass('active');
  1008. divSelect.find('select').val('network_personal');
  1009. }
  1010. });
  1011. function element_add_proceed_json_response(response)
  1012. {
  1013. if (response.status == 'success')
  1014. {
  1015. $('form[name="add"]').find('ul.error_list').remove();
  1016. $('ul.elements').prepend(response.html);
  1017. $('form[name="add"] input[type="text"]').val('');
  1018. if ($('form[name="search"]').length)
  1019. {
  1020. $('form[name="search"]').slideDown();
  1021. }
  1022. remove_tags('add');
  1023. recolorize_element_list();
  1024. $('div#element_add_box').slideUp();
  1025. if (response.groups.length)
  1026. {
  1027. // Des groupes sont proposés pour diffuser cet élément
  1028. $('div#added_element_to_group').slideDown();
  1029. for (i in response.groups)
  1030. {
  1031. var group = response.groups[i];
  1032. $('ul#groups_to_add_element').html('');
  1033. $('ul#groups_to_add_element')
  1034. .append($('<li>')
  1035. .append($('<a>')
  1036. .addClass('added_element_add_to_group')
  1037. .attr('href', group.url)
  1038. .append(group.name)
  1039. )
  1040. )
  1041. ;
  1042. }
  1043. }
  1044. else
  1045. {
  1046. $('a#element_add_link').show();
  1047. }
  1048. form_add_hide_errors();
  1049. return true;
  1050. }
  1051. else if (response.status == 'error')
  1052. {
  1053. form_add_display_errors(response.errors);
  1054. $('#form_add_loader').hide();
  1055. return false;
  1056. }
  1057. return false;
  1058. }
  1059. function form_add_hide_errors()
  1060. {
  1061. $('form[name="add"]').find('ul.error_list').remove();
  1062. }
  1063. // Affichage des erreurs lors de laprocédure d'ajout d'un élément
  1064. function form_add_display_errors(errors)
  1065. {
  1066. $('form[name="add"]').find('ul.error_list').remove();
  1067. var ul_errors = $('<ul>').addClass('error_list');
  1068. for (i in errors)
  1069. {
  1070. ul_errors.append($('<li>').append(errors[i]));
  1071. }
  1072. $('form[name="add"]').prepend(ul_errors);
  1073. }
  1074. // Ajout d'un element #ajouter (première partie)
  1075. // // Click sur "ajouter" (l'url)
  1076. // $('a#form_add_check_url').click(function(){
  1077. //
  1078. // // On fait tourner notre gif loader
  1079. // $('img#form_add_loader').show();
  1080. //
  1081. // $.ajax({
  1082. // type: 'POST',
  1083. // url: url_datas_api,
  1084. // data: {'url':$('input#element_add_url').val()},
  1085. // success: function(response){
  1086. //
  1087. // if (response.status == 'mustbeconnected')
  1088. // {
  1089. // $(location).attr('href', url_index);
  1090. // }
  1091. //
  1092. // if (response.status == 'success')
  1093. // {
  1094. // // On cache notre gif loader.
  1095. // $('img#form_add_loader').hide();
  1096. //
  1097. // // On commence par renseigner les champs si on a du concret
  1098. // // name
  1099. // if (response.name)
  1100. // {
  1101. // $('input#element_add_name').val(response.name);
  1102. // }
  1103. //
  1104. // // thumb
  1105. // $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
  1106. // if (response.thumb)
  1107. // {
  1108. // $('div#form_add_thumb img').attr('src', response.thumb);
  1109. // }
  1110. //
  1111. // // Proposition de tags
  1112. // if (response.tags)
  1113. // {
  1114. // $('ul#form_add_prop_tags li').remove();
  1115. // $('ul#form_add_prop_tags').show();
  1116. // $('ul#form_add_prop_tags_text').show();
  1117. //
  1118. // for (tags_index = 0; tags_index < response.tags.length; tags_index++)
  1119. // {
  1120. // var tag = response.tags[tags_index];
  1121. // var tag_id = '';
  1122. // var tag_name = tag.original_name;
  1123. // // Si il y a des équivalent en base.
  1124. // if (tag.like_found)
  1125. // {
  1126. // tag_id = tag.like.id;
  1127. // tag_name = tag.like.name;
  1128. // }
  1129. //
  1130. // // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
  1131. // $('ul#form_add_prop_tags').append(
  1132. // '<li>'+
  1133. // '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
  1134. // tag_name+
  1135. // '</a>'+
  1136. // '</li>'
  1137. // );
  1138. // }
  1139. // }
  1140. //
  1141. // // On a plus qu'a afficher les champs
  1142. // $('div#form_add_second_part').slideDown();
  1143. // $('div#form_add_first_part').slideUp();
  1144. // form_add_hide_errors();
  1145. // }
  1146. // else if (response.status == 'error')
  1147. // {
  1148. // form_add_display_errors(response.errors);
  1149. // $('#form_add_loader').hide();
  1150. // return false;
  1151. // }
  1152. // },
  1153. // dataType: 'json'
  1154. // });
  1155. //
  1156. // });
  1157. function element_add_proceed_data_apis(response)
  1158. {
  1159. if (response.status == 'mustbeconnected')
  1160. {
  1161. $(location).attr('href', url_index);
  1162. }
  1163. if (response.status == 'success')
  1164. {
  1165. // On cache notre gif loader.
  1166. $('img#form_add_loader').hide();
  1167. // On commence par renseigner les champs si on a du concret
  1168. // name
  1169. if (response.name)
  1170. {
  1171. $('input#element_add_name').val(response.name);
  1172. }
  1173. // thumb
  1174. $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
  1175. if (response.thumb)
  1176. {
  1177. $('div#form_add_thumb img').attr('src', response.thumb);
  1178. }
  1179. // Proposition de tags
  1180. if (response.tags)
  1181. {
  1182. $('ul#form_add_prop_tags li').remove();
  1183. $('ul#form_add_prop_tags_api').show();
  1184. $('p#form_add_prop_tags_text').hide();
  1185. if (response.tags.length)
  1186. {
  1187. $('p#form_add_prop_tags_text').show();
  1188. }
  1189. $('ul#form_add_prop_tags_api li').remove();
  1190. for (tags_index = 0; tags_index < response.tags.length; tags_index++)
  1191. {
  1192. var tag = response.tags[tags_index];
  1193. var tag_id = '';
  1194. var tag_name = tag.original_name;
  1195. // Si il y a des équivalent en base.
  1196. if (tag.like_found)
  1197. {
  1198. tag_id = tag.like.id;
  1199. tag_name = tag.like.name;
  1200. }
  1201. // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
  1202. $('ul#form_add_prop_tags_api').append(
  1203. '<li>'+
  1204. '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
  1205. tag_name+
  1206. '</a>'+
  1207. '</li>'
  1208. );
  1209. }
  1210. }
  1211. return true;
  1212. }
  1213. else if (response.status == 'error')
  1214. {
  1215. return false;
  1216. }
  1217. return true;
  1218. }
  1219. /*
  1220. * Formulaire d'ajout: click sur proposition de tags du a une api
  1221. */
  1222. $('a.form_add_prop_tag').live('click', function(){
  1223. var form_name = "add";
  1224. var tag_id = str_replace('#', '', $(this).attr('href'));
  1225. // Si on connait le tag id (pas un nouveau tag donc)
  1226. if (tag_id)
  1227. {
  1228. var tag = new Tag(tag_id, $(this).text());
  1229. window.add_tag_prompt_connector.addTagToTagPrompt(tag);
  1230. }
  1231. else
  1232. {
  1233. // Cette var sert a rien ici, mais c'est la refactorisation qui
  1234. // pose problmeme (corrigeable cela dit)
  1235. var divtags = $("#search_tag_"+form_name);
  1236. form_add_open_dialog_for_new_tag($(this), input_tag, form_name, divtags);
  1237. }
  1238. // On nettoie le champs de saisie des tags
  1239. $('input.form-default-value-processed').val('');
  1240. });
  1241. // #ajouter ajouter un élément (envoi du formulaire)
  1242. $('form[name="add"] input[type="submit"]').live('click', function(){
  1243. $('form[name="add"]').find('img.tag_loader').show();
  1244. });
  1245. $('form[name="add"]').ajaxForm(function(response) {
  1246. if (response.status == 'mustbeconnected')
  1247. {
  1248. $(location).attr('href', url_index);
  1249. }
  1250. $('form[name="add"] img.tag_loader').hide();
  1251. // Si on en est a la promière étape la réponse sera des données récupérés auprès
  1252. // des apis
  1253. if ($('input#form_add_step').val() == '1')
  1254. {
  1255. if (element_add_proceed_data_apis(response))
  1256. {
  1257. // On a plus qu'a afficher les champs
  1258. $('div#form_add_second_part').slideDown();
  1259. $('div#form_add_first_part').slideUp();
  1260. form_add_hide_errors();
  1261. $('#form_add_loader').hide();
  1262. $('input#form_add_step').val('2');
  1263. // On doit avoir le slug du groupe si on ajoute a un groupe
  1264. if (!$('input#add_element_group_page').length)
  1265. {
  1266. $('form[name="add"]').attr('action', url_element_add);
  1267. }
  1268. else
  1269. {
  1270. $('form[name="add"]').attr('action', url_element_add+'/'+$('input#add_element_group_page').val());
  1271. }
  1272. $('span#add_url_title_url').html($('input#element_add_url').val());
  1273. }
  1274. else
  1275. {
  1276. form_add_display_errors(response.errors);
  1277. $('#form_add_loader').hide();
  1278. }
  1279. }
  1280. else if ($('input#form_add_step').val() == '2')
  1281. {
  1282. if (element_add_proceed_json_response(response))
  1283. {
  1284. form_add_reinit();
  1285. }
  1286. }
  1287. return false;
  1288. });
  1289. function form_add_reinit()
  1290. {
  1291. $('div#element_add_box').slideUp();
  1292. $('div#form_add_first_part').show();
  1293. $('div#form_add_second_part').hide();
  1294. $('ul#form_add_prop_tags_api').hide();
  1295. $('ul#form_add_prop_tags_text').hide();
  1296. $('input#element_add_url').val('');
  1297. $('input#element_add_name').val('');
  1298. $('input#form_add_step').val(1);
  1299. $('form[name="add"]').attr('action', url_datas_api);
  1300. }
  1301. /////////////////////
  1302. var tags_ids_for_filter = new Array();
  1303. // Filtre par tags (show, favorite)
  1304. function refresh_elements_with_tags_selected(link)
  1305. {
  1306. // Puis on fait notre rekékéte ajax.
  1307. $('ul.elements').html('');
  1308. $('div.no_elements').hide();
  1309. $('img.elements_more_loader').show();
  1310. $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
  1311. if (response.status == 'mustbeconnected')
  1312. {
  1313. $(location).attr('href', url_index);
  1314. }
  1315. $('ul.elements').html(response.html);
  1316. if (response.count)
  1317. {
  1318. $('img.elements_more_loader').hide();
  1319. $('span.elements_more').show();
  1320. $('a.elements_more').show();
  1321. }
  1322. });
  1323. return false;
  1324. }
  1325. function list_tag_clicked(link, erease)
  1326. {
  1327. if (erease)
  1328. {
  1329. $('ul#favorite_tags a.tag').removeClass('active');
  1330. }
  1331. // Ensuite on l'active ou le désactive
  1332. if (link.hasClass('active'))
  1333. {
  1334. link.removeClass('active');
  1335. }
  1336. else
  1337. {
  1338. link.addClass('active');
  1339. }
  1340. // On construit notre liste de tags
  1341. tags_ids_for_filter = new Array();
  1342. $('ul#favorite_tags a.tag.active').each(function(index){
  1343. var id = str_replace('filtering_tag_', '', $(this).attr('id'));
  1344. tags_ids_for_filter[id] = id;
  1345. });
  1346. // On adapte le lien afficher plus de résultats
  1347. var a_more = $('a.elements_more');
  1348. a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
  1349. // On adapte aussi le lien de l'autoplay
  1350. $('a#autoplay_launch').attr('href', $('input#autoplay_url').val()+'/'+array2json(tags_ids_for_filter));
  1351. return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
  1352. }
  1353. $('ul#favorite_tags a.tag').click(function(){
  1354. list_tag_clicked($(this));
  1355. });
  1356. last_keypress = 0;
  1357. function check_timelaps_and_find_with_tags(link, time_id, timed)
  1358. {
  1359. if (!timed)
  1360. {
  1361. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  1362. // et on met a jour l'id de la dernière pressé
  1363. last_keypress = new Date().getTime();
  1364. var this_time_id = last_keypress;
  1365. }
  1366. else
  1367. {
  1368. // Si elle a été redirigé, on met son id dans cette variable
  1369. var this_time_id = time_id;
  1370. }
  1371. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  1372. if (time_id != last_keypress && timed)
  1373. {
  1374. // elle disparait
  1375. }
  1376. else
  1377. {
  1378. //
  1379. if ((new Date().getTime() - last_keypress) < 800 || timed == false)
  1380. {
  1381. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  1382. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  1383. // elle doit attendre au cas ou soit pressé.
  1384. setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
  1385. }
  1386. else
  1387. {
  1388. // il n'y a plus a attendre, on envoie la demande de tag.
  1389. return refresh_elements_with_tags_selected(link);
  1390. }
  1391. }
  1392. return null;
  1393. }
  1394. ////////////////////////////////////////
  1395. /// Gestion de nouveaux éléments
  1396. var do_check_new_elements = false;
  1397. function check_new_elements()
  1398. {
  1399. if ($('ul.elements li').length)
  1400. {
  1401. // Si l'utilisateur a quitté la page on reporte le check
  1402. if ($('body.blurred').length)
  1403. {
  1404. // on passe la variable a vrai de façon a ce que lorsque la page
  1405. // et ré affiché on lance le check
  1406. do_check_new_elements = true;
  1407. }
  1408. else
  1409. {
  1410. var url = url_element_new_count
  1411. +'/'
  1412. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1413. ;
  1414. $.ajax({
  1415. type: 'POST',
  1416. url: url,
  1417. data: $('form[name="search"]').serialize(),
  1418. success: function(response){
  1419. if (response.status == 'mustbeconnected')
  1420. {
  1421. $(location).attr('href', url_index);
  1422. }
  1423. if (response.status == 'success' && response.count)
  1424. {
  1425. $('div.display_more_elements').show();
  1426. $('div.display_more_elements span').html(response.message);
  1427. }
  1428. setTimeout(check_new_elements, 150000);
  1429. },
  1430. dataType: "json"
  1431. });
  1432. // $.getJSON(url, function(response){
  1433. //
  1434. // if (response.status == 'mustbeconnected')
  1435. // {
  1436. // $(location).attr('href', url_index);
  1437. // }
  1438. //
  1439. // if (response.status == 'success' && response.count)
  1440. // {
  1441. // $('div.display_more_elements').show();
  1442. // $('div.display_more_elements span').html(response.message);
  1443. // }
  1444. //
  1445. // setTimeout(check_new_elements, 150000);
  1446. // });
  1447. do_check_new_elements = false;
  1448. }
  1449. }
  1450. }
  1451. if ($('div.display_more_elements').length)
  1452. {
  1453. setTimeout(check_new_elements, 150000);
  1454. }
  1455. $('a.show_new_elements').live('click', function(){
  1456. var url = url_element_new_get
  1457. +'/'
  1458. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1459. ;
  1460. $('img.elements_new_loader').show();
  1461. $.ajax({
  1462. type: 'POST',
  1463. url: url,
  1464. data: $('form[name="search"]').serialize(),
  1465. success: function(response){
  1466. if (response.status == 'mustbeconnected')
  1467. {
  1468. $(location).attr('href', url_index);
  1469. }
  1470. if (response.status == 'success')
  1471. {
  1472. if (response.count)
  1473. {
  1474. $('div.display_more_elements').show();
  1475. $('div.display_more_elements span').html(response.message);
  1476. }
  1477. else
  1478. {
  1479. $('div.display_more_elements').hide();
  1480. }
  1481. $('ul.elements').prepend(response.html);
  1482. recolorize_element_list();
  1483. }
  1484. $('img.elements_new_loader').hide();
  1485. },
  1486. dataType: "json"
  1487. });
  1488. // $.getJSON(url, function(response){
  1489. //
  1490. // if (response.status == 'mustbeconnected')
  1491. // {
  1492. // $(location).attr('href', url_index);
  1493. // }
  1494. //
  1495. // if (response.status == 'success')
  1496. // {
  1497. // if (response.count)
  1498. // {
  1499. // $('div.display_more_elements').show();
  1500. // $('div.display_more_elements span').html(response.message);
  1501. // }
  1502. // else
  1503. // {
  1504. // $('div.display_more_elements').hide();
  1505. // }
  1506. //
  1507. // $('ul.elements').prepend(response.html);
  1508. // recolorize_element_list();
  1509. // }
  1510. //
  1511. // $('img.elements_new_loader').hide();
  1512. // });
  1513. });
  1514. function recolorize_element_list()
  1515. {
  1516. $('ul.elements li.element').each(function(index){
  1517. if ((index & 1) == 1)
  1518. {
  1519. $(this).removeClass('even');
  1520. $(this).removeClass('odd');
  1521. $(this).addClass('odd');
  1522. }
  1523. else
  1524. {
  1525. $(this).removeClass('odd');
  1526. $(this).removeClass('even');
  1527. $(this).addClass('even');
  1528. }
  1529. });
  1530. }
  1531. /*
  1532. * Action a effectuer lorsque l'utilisateur met le focus sur la page
  1533. */
  1534. function do_action_body_focused()
  1535. {
  1536. if (do_check_new_elements)
  1537. {
  1538. check_new_elements();
  1539. }
  1540. }
  1541. /*
  1542. * Commentaires d'élément
  1543. */
  1544. // Afficher les commentaires
  1545. $('td.element_content a.display_comments').live('click', function(){
  1546. display_comments($(this).parents('li.element'));
  1547. });
  1548. $('td.element_content a.hide_comments').live('click', function(){
  1549. hide_comments($(this).parents('li.element'));
  1550. });
  1551. function display_comments(li_element)
  1552. {
  1553. li_element.find('div.comments').slideDown();
  1554. li_element.find('a.display_comments').hide();
  1555. li_element.find('a.hide_comments').show();
  1556. }
  1557. function hide_comments(li_element)
  1558. {
  1559. li_element.find('div.comments').slideUp();
  1560. li_element.find('a.display_comments').show();
  1561. li_element.find('a.hide_comments').hide();
  1562. }
  1563. // Ajouter un commentaire
  1564. $('li.element a.add_comment').live('click', function(){
  1565. display_add_comment($(this).parents('li.element'));
  1566. });
  1567. $('form.add_comment input[type="submit"]').live('click', function(){
  1568. $(this).parents('div.comments').find('img.comments_loader').show();
  1569. });
  1570. function display_add_comment(li_element)
  1571. {
  1572. display_comments(li_element);
  1573. li_element.find('a.add_comment').hide();
  1574. li_element.find('form.add_comment').show();
  1575. li_element.find('form.add_comment').ajaxForm(function(response) {
  1576. if (response.status == 'mustbeconnected')
  1577. {
  1578. $(location).attr('href', url_index);
  1579. }
  1580. li_element.find('img.comments_loader').hide();
  1581. if (response.status == 'success')
  1582. {
  1583. li_element.find('form.add_comment').find('ul.error_list').remove();
  1584. li_element.find('div.comments ul.comments').append(response.html);
  1585. hide_add_comment(li_element);
  1586. }
  1587. else if (response.status == 'error')
  1588. {
  1589. li_element.find('form.add_comment').find('ul.error_list').remove();
  1590. var ul_errors = $('<ul>').addClass('error_list');
  1591. for (i in response.errors)
  1592. {
  1593. ul_errors.append($('<li>').append(response.errors[i]));
  1594. }
  1595. li_element.find('form.add_comment').prepend(ul_errors);
  1596. }
  1597. return false;
  1598. });
  1599. }
  1600. $('form.add_comment input.cancel').live('click', function(){
  1601. var li_element = $(this).parents('li.element');
  1602. hide_add_comment(li_element);
  1603. });
  1604. function hide_add_comment(li_element)
  1605. {
  1606. li_element.find('a.add_comment').show();
  1607. li_element.find('form.add_comment').hide();
  1608. li_element.find('form.add_comment textarea').val('');
  1609. }
  1610. // Modifier et supprimer
  1611. // Affichage du bouton Modifier et Supprimer
  1612. $('ul.comments li.comment').live({
  1613. mouseenter:
  1614. function()
  1615. {
  1616. $(this).find('a.comment_edit_link').show();
  1617. $(this).find('a.comment_remove_link').show();
  1618. },
  1619. mouseleave:
  1620. function()
  1621. {
  1622. if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
  1623. {
  1624. $(this).find('a.comment_edit_link').hide();
  1625. }
  1626. if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
  1627. {
  1628. $(this).find('a.comment_remove_link').hide();
  1629. }
  1630. }
  1631. }
  1632. );
  1633. // Supprimer
  1634. $('a.comment_remove_link').jConfirmAction({
  1635. question : string_comment_delete_confirm_sentence,
  1636. yesAnswer : string_comment_delete_confirm_yes,
  1637. cancelAnswer : string_comment_delete_confirm_no,
  1638. onYes: function(link){
  1639. var li = link.parents('li.comment');
  1640. li.find('img.comment_loader').show();
  1641. $.getJSON(link.attr('href'), function(response){
  1642. li.find('img.comment_loader').hide();
  1643. if (response.status == 'mustbeconnected')
  1644. {
  1645. $(location).attr('href', url_index);
  1646. }
  1647. if (response.status == 'success')
  1648. {
  1649. li.remove();
  1650. }
  1651. });
  1652. return false;
  1653. },
  1654. onOpen: function(link){
  1655. var li = link.parents('li.comment');
  1656. li.find('a.comment_edit_link').addClass('mustBeDisplayed');
  1657. li.find('a.comment_remove_link').addClass('mustBeDisplayed');
  1658. },
  1659. onClose: function(link){
  1660. var li = link.parents('li.comment');
  1661. li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
  1662. li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
  1663. li.find('a.comment_edit_link').hide();
  1664. li.find('a.comment_remove_link').hide();
  1665. }
  1666. });
  1667. var comments_edited = new Array();
  1668. // Modification
  1669. // Ouverture du formulaire de modification
  1670. $('a.comment_edit_link').live('click', function(){
  1671. var link = $(this);
  1672. var li = link.parents('li.comment');
  1673. // On garde en mémoire l'élément édité en cas d'annulation
  1674. comments_edited[li.attr('id')] = li.html();
  1675. var loader = li.find('img.comment_loader');
  1676. li.html(loader);
  1677. li.find('img.comment_loader').show();
  1678. $.getJSON($(this).attr('href'), function(response) {
  1679. if (response.status == 'mustbeconnected')
  1680. {
  1681. $(location).attr('href', url_index);
  1682. }
  1683. li.html(response.html);
  1684. // On rend ce formulaire ajaxFormable
  1685. $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
  1686. var li_current = $(this).parents('li.comment');
  1687. li_current.prepend(loader);
  1688. li_current.find('img.comment_loader').show();
  1689. });
  1690. li.find('form.edit_comment').ajaxForm(function(response){
  1691. li = $('li#'+response.dom_id);
  1692. li.find('img.comment_loader').hide();
  1693. if (response.status == 'mustbeconnected')
  1694. {
  1695. $(location).attr('href', url_index);
  1696. }
  1697. if (response.status == 'success')
  1698. {
  1699. li.html(response.html);
  1700. delete(comments_edited[li.attr('id')]);
  1701. }
  1702. else if (response.status == 'error')
  1703. {
  1704. li.find('ul.error_list').remove();
  1705. var ul_errors = $('<ul>').addClass('error_list');
  1706. for (i in response.errors)
  1707. {
  1708. ul_errors.append($('<li>').append(response.errors[i]));
  1709. }
  1710. li.prepend(ul_errors);
  1711. }
  1712. });
  1713. });
  1714. return false;
  1715. });
  1716. // Annulation d'un formulaire de modification d'un comment
  1717. $('form.edit_comment input.cancel').live('click', function(){
  1718. var li = $(this).parents('li.comment');
  1719. li.html(comments_edited[li.attr('id')]);
  1720. delete(comments_edited[li.attr('id')]);
  1721. });
  1722. /*
  1723. * Ajout d'un tag en favoris a partir d'un élément
  1724. */
  1725. $('li.element_tag').live({
  1726. mouseenter:
  1727. function()
  1728. {
  1729. $(this).find('a.tag_to_favorites').show();
  1730. $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
  1731. },
  1732. mouseleave:
  1733. function()
  1734. {
  1735. if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
  1736. {
  1737. $(this).find('a.tag_to_favorites').hide();
  1738. $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
  1739. }
  1740. }
  1741. }
  1742. );
  1743. $('a.tag_to_favorites').jConfirmAction({
  1744. question : string_tag_addtofav_confirm_sentence,
  1745. yesAnswer : string_tag_addtofav_confirm_yes,
  1746. cancelAnswer : string_tag_addtofav_confirm_no,
  1747. onYes: function(link){
  1748. $.getJSON(link.attr('href'), function(response){
  1749. if (response.status == 'mustbeconnected')
  1750. {
  1751. $(location).attr('href', url_index);
  1752. }
  1753. });
  1754. $('div.question').fadeOut();
  1755. return false;
  1756. },
  1757. onOpen: function(link){
  1758. var li = link.parents('li.element_tag');
  1759. li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
  1760. },
  1761. onClose: function(link){
  1762. var li = link.parents('li.element_tag');
  1763. li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
  1764. li.find('a.element_tag').removeClass('element_tag_large_for_fav');
  1765. li.find('a.tag_to_favorites').hide();
  1766. }
  1767. });
  1768. /*
  1769. * Ajout dans un groupe de l'élément envoyé
  1770. */
  1771. $('a.added_element_add_to_group').live('click', function(){
  1772. var loader = $('div#added_element_to_group').find('img.loader');
  1773. loader.show();
  1774. $.getJSON($(this).attr('href'), function(response) {
  1775. loader.hide();
  1776. if (response.status == 'mustbeconnected')
  1777. {
  1778. $(location).attr('href', url_index);
  1779. }
  1780. if (response.status == 'success')
  1781. {
  1782. $('li#'+response.dom_id).html(response.html);
  1783. }
  1784. $('div#added_element_to_group').slideUp();
  1785. $('a#element_add_link').show();
  1786. });
  1787. return false;
  1788. });
  1789. $('div#added_element_to_group a.cancel').live('click', function(){
  1790. $('div#added_element_to_group').slideUp();
  1791. $('a#element_add_link').show();
  1792. return false;
  1793. });
  1794. /*
  1795. * Report / signalement d'un élément
  1796. */
  1797. $('a.element_report').jConfirmAction({
  1798. question : string_elementreport_confirm_sentence,
  1799. yesAnswer : string_elementreport_confirm_yes,
  1800. cancelAnswer : string_elementreport_confirm_no,
  1801. onYes: function(link){
  1802. $.getJSON(link.attr('href'), function(response){
  1803. if (response.status == 'mustbeconnected')
  1804. {
  1805. $(location).attr('href', url_index);
  1806. }
  1807. });
  1808. $('div.question').fadeOut();
  1809. return false;
  1810. },
  1811. onOpen: function(link){
  1812. },
  1813. onClose: function(link){
  1814. }
  1815. });
  1816. /*
  1817. * Vote sur element
  1818. */
  1819. $('li.element a.vote').live('click', function(){
  1820. var img = $(this).find('img');
  1821. var link = $(this);
  1822. img.attr('src', url_img_ajax_loader);
  1823. $.getJSON(link.attr('href'), function(response){
  1824. if (response.status == 'mustbeconnected')
  1825. {
  1826. $(location).attr('href', url_index);
  1827. }
  1828. if (response.status == 'success')
  1829. {
  1830. link.attr('href', response.data.a.href);
  1831. img.attr('src', response.data.img.src);
  1832. link.parents('td.right').find('li.score span.score').html(response.data.element.points);
  1833. }
  1834. });
  1835. return false;
  1836. });
  1837. // Enlever les ids du ElementSearch
  1838. $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
  1839. $('img.elements_more_loader').show();
  1840. $('ul.elements').html('');
  1841. var link = $(this);
  1842. $.getJSON(link.attr('href'), function(response){
  1843. if (response.status == 'mustbeconnected')
  1844. {
  1845. $(location).attr('href', url_index);
  1846. }
  1847. if (response.status == 'success')
  1848. {
  1849. $('form[name="search"]').submit();
  1850. $('div.more_filters a.new_comments').hide();
  1851. $('div.more_filters a.new_favorites').hide();
  1852. $('div.more_filters a.new_tags').hide();
  1853. }
  1854. });
  1855. return false;
  1856. });
  1857. /*
  1858. *
  1859. * Proposition de tags sur un élément
  1860. *
  1861. */
  1862. // Ouverture du formulaire de modification
  1863. $('a.element_propose_tags').live('click', function(){
  1864. var link = $(this);
  1865. var li = link.parents('li.element');
  1866. li.find('img.element_loader').show();
  1867. $.getJSON($(this).attr('href'), function(response) {
  1868. if (response.status == 'mustbeconnected')
  1869. {
  1870. $(location).attr('href', url_index);
  1871. }
  1872. li.find('img.element_loader').hide();
  1873. if (response.status == 'success')
  1874. {
  1875. // On prépare le tagBox
  1876. var table = li.find('table:first');
  1877. li.find('div.tag_proposition').remove();
  1878. table.after(response.html);
  1879. // Pour le click sur l'input de saisie de tag
  1880. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  1881. var options = new Array();
  1882. options.form_name = response.form_name;
  1883. options.tag_init = response.tags;
  1884. ajax_query_timestamp = null;
  1885. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  1886. // On rend ce formulaire ajaxFormable
  1887. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  1888. li = $(this).parents('li.element');
  1889. li.find('img.element_loader').show();
  1890. });
  1891. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  1892. if (response.status == 'mustbeconnected')
  1893. {
  1894. $(location).attr('href', url_index);
  1895. }
  1896. if (response.status == 'success')
  1897. {
  1898. li = $('li#'+response.dom_id);
  1899. li.find('img.element_loader').hide();
  1900. li.find('form')
  1901. li.find('div.tag_proposition').remove();
  1902. }
  1903. else if (response.status == 'error')
  1904. {
  1905. li.find('img.element_loader').hide();
  1906. li.find('ul.error_list').remove();
  1907. var ul_errors = $('<ul>').addClass('error_list');
  1908. for (i in response.errors)
  1909. {
  1910. ul_errors.append($('<li>').append(response.errors[i]));
  1911. }
  1912. li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
  1913. }
  1914. });
  1915. }
  1916. });
  1917. return false;
  1918. });
  1919. // Annulation d'un formulaire de modification d'élément
  1920. $('div.tag_proposition input.cancel').live('click', function(){
  1921. $(this).parents('div.tag_proposition').slideUp();
  1922. });
  1923. // Ouvrir les propositions de tags de l'élément
  1924. $('a.element_view_propositions_link').live('click', function(){
  1925. var link = $(this);
  1926. li = link.parents('li.element');
  1927. li.find('img.element_loader').show();
  1928. $.getJSON($(this).attr('href'), function(response) {
  1929. if (response.status == 'mustbeconnected')
  1930. {
  1931. $(location).attr('href', url_index);
  1932. }
  1933. li.find('img.element_loader').hide();
  1934. if (response.status == 'success')
  1935. {
  1936. var table = li.find('table:first');
  1937. li.find('div.tags_proposition_view').remove();
  1938. table.after(response.html);
  1939. }
  1940. });
  1941. return false;
  1942. });
  1943. $('a.accept_tag_propotision').live('click', function(){
  1944. var link = $(this);
  1945. var li = link.parents('li.element');
  1946. li.find('img.element_loader').show();
  1947. $.getJSON($(this).attr('href'), function(response) {
  1948. if (response.status == 'mustbeconnected')
  1949. {
  1950. $(location).attr('href', url_index);
  1951. }
  1952. li.find('img.element_loader').hide();
  1953. if (response.status == 'success')
  1954. {
  1955. li.html(response.html);
  1956. }
  1957. });
  1958. return false;
  1959. });
  1960. //
  1961. $('a.refuse_tag_propositions').live('click', function(){
  1962. var link = $(this);
  1963. var li = link.parents('li.element');
  1964. li.find('img.element_loader').show();
  1965. $.getJSON($(this).attr('href'), function(response) {
  1966. if (response.status == 'mustbeconnected')
  1967. {
  1968. $(location).attr('href', url_index);
  1969. }
  1970. li.find('img.element_loader').hide();
  1971. if (response.status == 'success')
  1972. {
  1973. li.find('div.tags_proposition_view').remove();
  1974. }
  1975. });
  1976. return false;
  1977. });
  1978. /*
  1979. * Proposition de tag sur un élément FIN
  1980. */
  1981. /*
  1982. * Report / signalement d'un commentaire
  1983. */
  1984. $('a.comment_report').jConfirmAction({
  1985. question : string_commentreport_confirm_sentence,
  1986. yesAnswer : string_commentreport_confirm_yes,
  1987. cancelAnswer : string_commentreport_confirm_no,
  1988. onYes: function(link){
  1989. $.getJSON(link.attr('href'), function(response){
  1990. if (response.status == 'mustbeconnected')
  1991. {
  1992. $(location).attr('href', url_index);
  1993. }
  1994. });
  1995. $('div.question').fadeOut();
  1996. return false;
  1997. },
  1998. onOpen: function(link){
  1999. },
  2000. onClose: function(link){
  2001. }
  2002. });
  2003. /*
  2004. * reshare repartage
  2005. */
  2006. $('a.element_reshare').jConfirmAction({
  2007. question : string_elementreshare_confirm_sentence,
  2008. yesAnswer : string_elementreshare_confirm_yes,
  2009. cancelAnswer : string_elementreshare_confirm_no,
  2010. onYes: function(link){
  2011. $('div.question').fadeOut();
  2012. $.getJSON(link.attr('href'), function(response){
  2013. if (response.status == 'mustbeconnected')
  2014. {
  2015. $(location).attr('href', url_index);
  2016. }
  2017. // On affiche l'élément que si on voit que le formulaire est sur la page
  2018. // Sinon c'est qu'on est sur une page ou on a pas normalement la possibilité
  2019. // d'ajouetr un élément.
  2020. if ($('form[name="add"]').length)
  2021. {
  2022. element_add_proceed_json_response(response);
  2023. }
  2024. return false;
  2025. });
  2026. return false;
  2027. },
  2028. onOpen: function(link){
  2029. },
  2030. onClose: function(link){
  2031. }
  2032. });
  2033. /*
  2034. * Cloud tags
  2035. */
  2036. $('a#display_all_cloud_tag').click(function(){
  2037. $('ul#favorite_tags li').show();
  2038. $(this).hide();
  2039. });
  2040. $('input#cloud_tags_filter').keyup(function(){
  2041. var search_string = $(this).val();
  2042. $('ul#favorite_tags li a').removeClass('highlight');
  2043. if (search_string.length > 1)
  2044. {
  2045. $('ul#favorite_tags li a').each(function(){
  2046. if ($(this).text().toUpperCase().search(search_string.toUpperCase()) != -1)
  2047. {
  2048. $(this).addClass('highlight')
  2049. }
  2050. });
  2051. }
  2052. });
  2053. });
  2054. /*
  2055. * Ouverture d'une boite avec effet fade et centré
  2056. * code origine: form_add_open_dialog_for_new_tag
  2057. */
  2058. function open_popin_dialog(object_id)
  2059. {
  2060. // Effet fade-in du fond opaque
  2061. $('body').append($('<div>').attr('id', 'fade'));
  2062. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  2063. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  2064. $('#'+object_id).css({
  2065. position: 'absolute',
  2066. left: ($(window).width()
  2067. - $('#'+object_id).width())/2,
  2068. // top: ($(window).height()
  2069. // - $('#'+object_id).height())/2
  2070. top: '10%'
  2071. });
  2072. $('#'+object_id).show();
  2073. }