muzich.js 72KB

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