muzich.js 81KB

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