muzich.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. // Controle du focus sur la page
  8. function onBlur() {
  9. document.body.className = 'blurred';
  10. }
  11. function onFocus(){
  12. document.body.className = 'focused';
  13. }
  14. if (/*@cc_on!@*/false) { // check for Internet Explorer
  15. document.onfocusin = onFocus;
  16. document.onfocusout = onBlur;
  17. } else {
  18. window.onfocus = onFocus;
  19. window.onblur = onBlur;
  20. }
  21. // Messages flashs
  22. var myMessages = ['info','warning','error','success']; // define the messages types
  23. function hideAllMessages()
  24. {
  25. var messagesHeights = new Array(); // this array will store height for each
  26. for (i=0; i<myMessages.length; i++)
  27. {
  28. messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
  29. $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
  30. }
  31. }
  32. $(document).ready(function(){
  33. // Initially, hide them all
  34. hideAllMessages();
  35. $('.message').animate({top:"0"}, 500);
  36. // When message is clicked, hide it
  37. $('.message a.message-close').click(function(){
  38. $(this).parent('.message').animate({top: -$(this).outerHeight()-50}, 700);
  39. return false;
  40. });
  41. });
  42. function findKeyWithValue(arrayt, value)
  43. {
  44. for(i in arrayt)
  45. {
  46. if (arrayt[i] == value)
  47. {
  48. return i;
  49. }
  50. }
  51. return "";
  52. }
  53. function json_to_array(json_string)
  54. {
  55. if (json_string.length)
  56. {
  57. return eval("(" + json_string + ")");
  58. }
  59. return new Array();
  60. }
  61. function strpos (haystack, needle, offset) {
  62. // Finds position of first occurrence of a string within another
  63. //
  64. // version: 1109.2015
  65. // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  66. // + improved by: Onno Marsman
  67. // + bugfixed by: Daniel Esteban
  68. // + improved by: Brett Zamir (http://brett-zamir.me)
  69. // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
  70. var i = (haystack + '').indexOf(needle, (offset || 0));
  71. return i === -1 ? false : i;
  72. }
  73. /**
  74. * Converts the given data structure to a JSON string.
  75. * Argument: arr - The data structure that must be converted to JSON
  76. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  77. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  78. * http://www.openjs.com/scripts/data/json_encode.php
  79. */
  80. function array2json(arr) {
  81. var parts = [];
  82. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  83. for(var key in arr) {
  84. var value = arr[key];
  85. if(typeof value == "object") { //Custom handling for arrays
  86. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  87. else parts[key] = array2json(value); /* :RECURSION: */
  88. } else {
  89. var str = "";
  90. if(!is_list) str = '"' + key + '":';
  91. //Custom handling for multiple data types
  92. if(typeof value == "number") str += value; //Numbers
  93. else if(value === false) str += 'false'; //The booleans
  94. else if(value === true) str += 'true';
  95. else str += '"' + value + '"'; //All other things
  96. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  97. parts.push(str);
  98. }
  99. }
  100. var json = parts.join(",");
  101. if(is_list) return '[' + json + ']';//Return numerical JSON
  102. return '{' + json + '}';//Return associative JSON
  103. }
  104. function isInteger(s) {
  105. return (s.toString().search(/^-?[0-9]+$/) == 0);
  106. }
  107. function inArray(array, p_val) {
  108. var l = array.length;
  109. for(var i = 0; i < l; i++) {
  110. if(array[i] == p_val) {
  111. return true;
  112. }
  113. }
  114. return false;
  115. }
  116. if(typeof(String.prototype.trim) === "undefined")
  117. {
  118. String.prototype.trim = function()
  119. {
  120. return String(this).replace(/^\s+|\s+$/g, '');
  121. };
  122. }
  123. function str_replace (search, replace, subject, count) {
  124. // Replaces all occurrences of search in haystack with replace
  125. //
  126. // version: 1109.2015
  127. // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  128. // + improved by: Gabriel Paderni
  129. // + improved by: Philip Peterson
  130. // + improved by: Simon Willison (http://simonwillison.net)
  131. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
  132. // + input by: Onno Marsman
  133. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  134. // + tweaked by: Onno Marsman
  135. // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  136. // + input by: Oleg Eremeev
  137. // + improved by: Brett Zamir (http://brett-zamir.me)
  138. // + bugfixed by: Oleg Eremeev
  139. // % 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
  140. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  141. // * returns 1: 'Kevin.van.Zonneveld'
  142. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  143. // * returns 2: 'hemmo, mars' var i = 0,
  144. j = 0,
  145. temp = '',
  146. repl = '',
  147. sl = 0, fl = 0,
  148. f = [].concat(search),
  149. r = [].concat(replace),
  150. s = subject,
  151. ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
  152. s = [].concat(s);
  153. if (count) {
  154. this.window[count] = 0;
  155. }
  156. for (i = 0, sl = s.length; i < sl; i++) {
  157. if (s[i] === '') {
  158. continue;
  159. }for (j = 0, fl = f.length; j < fl; j++) {
  160. temp = s[i] + '';
  161. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  162. s[i] = (temp).split(f[j]).join(repl);
  163. if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
  164. }
  165. }
  166. }
  167. return sa ? s : s[0];
  168. }
  169. function explode (delimiter, string, limit) {
  170. // 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.
  171. //
  172. // version: 1109.2015
  173. // discuss at: http://phpjs.org/functions/explode // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  174. // + improved by: kenneth
  175. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  176. // + improved by: d3x
  177. // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: explode(' ', 'Kevin van Zonneveld');
  178. // * returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
  179. // * example 2: explode('=', 'a=bc=d', 2);
  180. // * returns 2: ['a', 'bc=d']
  181. var emptyArray = { 0: ''
  182. };
  183. // third argument is not required
  184. if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') { return null;
  185. }
  186. if (delimiter === '' || delimiter === false || delimiter === null) {
  187. return false; }
  188. if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
  189. return emptyArray;
  190. }
  191. if (delimiter === true) {
  192. delimiter = '1';
  193. }
  194. if (!limit) {
  195. return string.toString().split(delimiter.toString());
  196. }
  197. // support for limit argument
  198. var splitted = string.toString().split(delimiter.toString()); var partA = splitted.splice(0, limit - 1);
  199. var partB = splitted.join(delimiter.toString());
  200. partA.push(partB);
  201. return partA;
  202. }
  203. $(document).ready(function(){
  204. // Bouton de personalisation du filtre
  205. // pour le moment ce ne sotn que des redirection vers des actions
  206. $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
  207. $(location).attr('href', $('input.filter_clear_url').val());
  208. });
  209. $('.tags_prompt input.mytags').live("click", function(){
  210. $(location).attr('href', $('input.filter_mytags_url').val());
  211. });
  212. // Affichage un/des embed
  213. // 1328283150_media-playback-start.png
  214. // 1328283201_emblem-symbolic-link.png
  215. $('a.element_embed_open_link').live("click", function(){
  216. li = $(this).parent('td').parent('tr').parent().parent().parent('li.element');
  217. li.find('a.element_embed_close_link').show();
  218. li.find('a.element_embed_open_link_text').hide();
  219. li.find('div.element_embed').show();
  220. return false;
  221. });
  222. $('a.element_name_embed_open_link').live("click", function(){
  223. li = $(this).parent('span').parent('td').parent('tr').parent().parent().parent('li.element');
  224. li.find('a.element_embed_close_link').show();
  225. li.find('a.element_embed_open_link_text').hide();
  226. li.find('div.element_embed').show();
  227. return false;
  228. });
  229. // Fermeture du embed si demandé
  230. $('a.element_embed_close_link').live("click", function(){
  231. li = $(this).parent('td').parent('tr').parent().parent().parent('li.element');
  232. li.find('div.element_embed').hide();
  233. li.find('a.element_embed_open_link_text').show();
  234. $(this).hide();
  235. return false;
  236. });
  237. // Affichage du "play" ou du "open" (image png)
  238. $('li.element a.a_thumbnail, li.element img.open, li.element img.play').live({
  239. mouseenter:
  240. function()
  241. {
  242. td = $(this).parent('td');
  243. a = td.find('a.a_thumbnail');
  244. if (a.hasClass('embed'))
  245. {
  246. td.find('img.play').show();
  247. }
  248. else
  249. {
  250. td.find('img.open').show();
  251. }
  252. },
  253. mouseleave:
  254. function()
  255. {
  256. td = $(this).parent('td');
  257. a = td.find('a.a_thumbnail');
  258. if (a.hasClass('embed'))
  259. {
  260. td.find('img.play').hide();
  261. }
  262. else
  263. {
  264. td.find('img.open').hide();
  265. }
  266. }
  267. }
  268. );
  269. // Mise en favoris
  270. $('a.favorite_link').live("click", function(){
  271. link = $(this);
  272. $.getJSON($(this).attr('href'), function(response) {
  273. img = link.find('img');
  274. link.attr('href', response.link_new_url);
  275. img.attr('src', response.img_new_src);
  276. img.attr('title', response.img_new_title);
  277. });
  278. return false;
  279. });
  280. // Affichage du bouton Modifier et Supprimer
  281. $('ul.elements li.element').live({
  282. mouseenter:
  283. function()
  284. {
  285. $(this).find('a.element_edit_link').show();
  286. $(this).find('a.element_remove_link').show();
  287. },
  288. mouseleave:
  289. function()
  290. {
  291. if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
  292. {
  293. $(this).find('a.element_edit_link').hide();
  294. }
  295. if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
  296. {
  297. $(this).find('a.element_remove_link').hide();
  298. }
  299. }
  300. }
  301. );
  302. // Plus d'éléments
  303. last_id = null;
  304. $('a.elements_more').click(function(){
  305. link = $(this);
  306. last_element = $('ul.elements li.element:last-child');
  307. id_last = str_replace('element_', '', last_element.attr('id'));
  308. invertcolor = 0;
  309. if (last_element.hasClass('even'))
  310. {
  311. invertcolor = 1;
  312. }
  313. $('img.elements_more_loader').show();
  314. $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
  315. if (response.count)
  316. {
  317. $('ul.elements').append(response.html);
  318. $('img.elements_more_loader').hide();
  319. }
  320. if (response.end || response.count < 1)
  321. {
  322. $('img.elements_more_loader').hide();
  323. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  324. response.message+'</p></div>');
  325. link.hide();
  326. }
  327. });
  328. return false;
  329. });
  330. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  331. // Filtre et affichage éléments ajax
  332. $('form[name="search"] input[type="submit"]').click(function(){
  333. $('ul.elements').html('');
  334. $('div.no_elements').hide();
  335. $('img.elements_more_loader').show();
  336. });
  337. $('form[name="search"]').ajaxForm(function(response) {
  338. $('ul.elements').html(response.html);
  339. if (response.count)
  340. {
  341. $('img.elements_more_loader').hide();
  342. $('span.elements_more').show();
  343. $('a.elements_more').show();
  344. }
  345. if (response.count < 1)
  346. {
  347. $('img.elements_more_loader').hide();
  348. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  349. response.message+'</p></div>');
  350. $('a.elements_more').hide()
  351. ;
  352. }
  353. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  354. });
  355. // Suppression d'un element
  356. $('a.element_remove_link').jConfirmAction({
  357. question : "Vraiment supprimer ?",
  358. yesAnswer : "Oui",
  359. cancelAnswer : "Non",
  360. onYes: function(link){
  361. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  362. li.find('img.element_loader').show();
  363. $.getJSON(link.attr('href'), function(response){
  364. if (response.status == 'success')
  365. {
  366. li.remove();
  367. }
  368. else
  369. {
  370. li.find('img.element_loader').hide();
  371. }
  372. });
  373. return false;
  374. },
  375. onOpen: function(link){
  376. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  377. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  378. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  379. },
  380. onClose: function(link){
  381. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  382. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  383. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  384. li.find('a.element_edit_link').hide();
  385. li.find('a.element_remove_link').hide();
  386. }
  387. });
  388. elements_edited = new Array();
  389. // Ouverture du formulaire de modification
  390. $('a.element_edit_link').live('click', function(){
  391. link = $(this);
  392. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  393. // On garde en mémoire l'élément édité en cas d'annulation
  394. elements_edited[li.attr('id')] = li.html();
  395. div_loader = li.find('div.loader');
  396. li.html(div_loader);
  397. li.find('img.element_loader').show();
  398. $.getJSON($(this).attr('href'), function(response) {
  399. // On prépare le tagBox
  400. li.html(response.html);
  401. var options = new Array();
  402. options.form_name = response.form_name;
  403. options.tag_init = response.tags;
  404. ajax_query_timestamp = null;
  405. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  406. // On rend ce formulaire ajaxFormable
  407. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  408. li.prepend(div_loader);
  409. li.find('img.element_loader').show();
  410. });
  411. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  412. if (response.status == 'success')
  413. {
  414. li.html(response.html);
  415. delete(elements_edited[li.attr('id')]);
  416. }
  417. else if (response.status == 'error')
  418. {
  419. li.find('img.element_loader').hide();
  420. li.find('ul.error_list').remove();
  421. ul_errors = $('<ul>').addClass('error_list');
  422. for (i in response.errors)
  423. {
  424. ul_errors.append($('<li>').append(response.errors[i]));
  425. }
  426. li.prepend(ul_errors);
  427. }
  428. });
  429. });
  430. return false;
  431. });
  432. // Annulation d'un formulaire de modification d'élément
  433. $('form.edit_element input.cancel_edit').live('click', function(){
  434. var li = $(this).parent('form').parent('li');
  435. li.html(elements_edited[li.attr('id')]);
  436. delete(elements_edited[li.attr('id')]);
  437. });
  438. ////////////////// TAG PROMPT ///////////////
  439. ajax_query_timestamp = null;
  440. tag_text_help = $('input.tag_text_help').val();
  441. // Les deux clicks ci-dessous permettent de faire disparaitre
  442. // la div de tags lorsque l'on clique ailleurs
  443. $('html').click(function() {
  444. if ($("div.search_tag_list").is(':visible'))
  445. {
  446. $("div.search_tag_list").hide();
  447. }
  448. });
  449. $("div.search_tag_list").live('click', function(event){
  450. event.stopPropagation();
  451. });
  452. function autocomplete_tag(input, form_name)
  453. {
  454. // Il doit y avoir au moin un caractère
  455. if (input.val().length > 0)
  456. {
  457. // on met en variable l'input
  458. inputTag = input;
  459. // On récupére la div de tags
  460. divtags = $("#search_tag_"+form_name);
  461. // Si la fenêtre de tags est caché
  462. if (!divtags.is(':visible'))
  463. {
  464. // On la replace
  465. position = input.position();
  466. divtags.css('left', Math.round(position.left) + 5);
  467. divtags.css('top', Math.round(position.top) + 28);
  468. // Et on l'affiche
  469. divtags.show();
  470. }
  471. // On affiche le loader
  472. $('#tag_loader_'+form_name).show();
  473. // On cache la liste de tags
  474. search_tag_list = divtags.find('ul.search_tag_list');
  475. // On supprime les anciens li
  476. search_tag_list.find('li').remove();
  477. search_tag_list.hide();
  478. // Et on affiche une info
  479. span_info = divtags.find('span.info');
  480. span_info.show();
  481. span_info.text("Recherche des tags correspondants à \""+input.val()+"\" ...");
  482. // C'est en fonction du nb de resultats qu'il sera affiché
  483. divtags.find('a.more').hide();
  484. // On récupère le timestamp pour reconnaitre la dernière requête effectué
  485. ajax_query_timestamp = new Date().getTime();
  486. // Récupération des tags correspondants
  487. $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
  488. // Ce contrôle permet de ne pas continuer si une requete
  489. // ajax a été faite depuis.
  490. if (data.timestamp == ajax_query_timestamp)
  491. {
  492. status = data.status;
  493. tags = data.data;
  494. // Si on spécifie une erreur
  495. if (status == 'error')
  496. {
  497. // On l'affiche a l'utilisateur
  498. span_info.text(data.error);
  499. }
  500. // Si c'est un succés
  501. else if (status == 'success')
  502. {
  503. if (tags.length > 0)
  504. {
  505. more = false;
  506. // Pour chaque tags retournés
  507. for (i in tags)
  508. {
  509. var tag_name = tags[i]['name'];
  510. var tag_id = tags[i]['id'];
  511. var t_string = tag_name
  512. // On construit un li
  513. string_exploded = explode(' ', $.trim(input.val()));
  514. for (n in string_exploded)
  515. {
  516. r_string = string_exploded[n];
  517. var re = new RegExp(r_string, "i");
  518. t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
  519. }
  520. li_tag =
  521. $('<li>').append(
  522. $('<a>').attr('href','#'+tag_id+'#'+tag_name)
  523. // qui réagit quand on clique dessus
  524. .click(function(e){
  525. // On récupère le nom du tag
  526. name = $(this).attr('href').substr(1,$(this).attr('href').length);
  527. name = name.substr(strpos(name, '#')+1, name.length);
  528. id = $(this).attr('href').substr(1,$(this).attr('href').length);
  529. id = str_replace(name, '', id);
  530. id = str_replace('#', '', id);
  531. $('input#tags_selected_tag_'+form_name).val(id);
  532. inputTag.val(name);
  533. // Et on execute l'évènement selectTag de l'input
  534. inputTag.trigger("selectTag");
  535. // On cache la liste puisque le choix vient d'être fait
  536. divtags.hide();
  537. inputTag.val(tag_text_help);
  538. return false;
  539. })
  540. .append(t_string)
  541. );
  542. // Si on depasse les 30 tags
  543. if (i > 30)
  544. {
  545. more = true;
  546. // On le cache
  547. li_tag.hide();
  548. }
  549. // On ajout ce li a la liste
  550. search_tag_list.append(li_tag);
  551. }
  552. if (more)
  553. {
  554. divtags.find('a.more').show();
  555. }
  556. // On cache l'info
  557. span_info.hide();
  558. // Et on affiche la liste
  559. search_tag_list.show();
  560. }
  561. else
  562. {
  563. span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  564. }
  565. }
  566. // On cache le loader
  567. $('#tag_loader_'+form_name).hide();
  568. }
  569. });
  570. }
  571. }
  572. last_keypress = 0;
  573. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  574. {
  575. if (!timed)
  576. {
  577. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  578. // et on met a jour l'id de la dernière pressé
  579. last_keypress = new Date().getTime();
  580. var this_time_id = last_keypress;
  581. }
  582. else
  583. {
  584. // Si elle a été redirigé, on met son id dans cette variable
  585. var this_time_id = time_id;
  586. }
  587. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  588. if (time_id != last_keypress && timed)
  589. {
  590. // elle disparait
  591. }
  592. else
  593. {
  594. //
  595. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  596. {
  597. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  598. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  599. // elle doit attendre au cas ou soit pressé.
  600. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  601. }
  602. else
  603. {
  604. // il n'y a plus a attendre, on envoie la demande de tag.
  605. autocomplete_tag(input, form_name);
  606. }
  607. }
  608. }
  609. // Autocompletion de tags
  610. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  611. var form_name = $(this).parent('li').parent('ul.tagbox')
  612. .parent('div.tags_prompt').parent('form').attr('name')
  613. ;
  614. var code = (e.keyCode ? e.keyCode : e.which);
  615. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  616. {
  617. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  618. }
  619. });
  620. // Un click sur ce lien affiche tout les tags cachés de la liste
  621. $('div.search_tag_list a.more').live('click', function(){
  622. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  623. $(this).show();
  624. });
  625. return false;
  626. });
  627. $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
  628. $('ul.tagbox li.input input[type="text"]').formDefaults();
  629. ////////////////// FIN TAG PROMPT ///////////////
  630. // Suppression d'un element
  631. $('a.group_remove_link').jConfirmAction({
  632. question : "Supprimer ce groupe ?",
  633. yesAnswer : "Oui",
  634. cancelAnswer : "Non",
  635. onYes: function(link){
  636. window.location = link.attr('href');
  637. return false;
  638. },
  639. onOpen: function(){},
  640. onClose: function(){}
  641. });
  642. // Selection Réseau global / Mon réseau
  643. $('div.select_network a').live('click', function(){
  644. divSelect = $(this).parent('div');
  645. if ($(this).hasClass('all_network'))
  646. {
  647. divSelect.find('a.all_network').addClass('active');
  648. divSelect.find('a.my_network').removeClass('active');
  649. divSelect.find('select').val('network_public');
  650. }
  651. else
  652. {
  653. divSelect.find('a.my_network').addClass('active');
  654. divSelect.find('a.all_network').removeClass('active');
  655. divSelect.find('select').val('network_personal');
  656. }
  657. });
  658. // Ajout d'un element
  659. $('form[name="add"] input[type="submit"]').live('click', function(){
  660. $('form[name="add"]').find('img.tag_loader').show();
  661. });
  662. $('form[name="add"]').ajaxForm(function(response) {
  663. $('form[name="add"] img.tag_loader').hide();
  664. if (response.status == 'success')
  665. {
  666. $('form[name="add"]').find('ul.error_list').remove();
  667. $('ul.elements').prepend(response.html);
  668. $('form[name="add"] input[type="text"]').val('');
  669. $('div#element_add_box').slideUp();
  670. $('a#element_add_link').show();
  671. if ($('form[name="search"]').length)
  672. {
  673. $('form[name="search"]').slideDown();
  674. }
  675. }
  676. else if (response.status == 'error')
  677. {
  678. $('form[name="add"]').find('ul.error_list').remove();
  679. ul_errors = $('<ul>').addClass('error_list');
  680. for (i in response.errors)
  681. {
  682. ul_errors.append($('<li>').append(response.errors[i]));
  683. }
  684. $('form[name="add"]').prepend(ul_errors);
  685. }
  686. return false;
  687. });
  688. // Check périodique
  689. // TODO.
  690. });