muzich.js 87KB

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