muzich.js 88KB

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