muzich.js 72KB

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