muzich.js 98KB

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