muzich.js 84KB

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