muzich.js 92KB

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