script.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. (function($) {
  2. Drupal.behaviors.init_theme = {};
  3. Drupal.behaviors.init_theme.attach = function (context) {
  4. // Growl-style system messages
  5. $('#messages-and-help > div.messages:not(.processed)')
  6. .addClass('processed')
  7. .each(function() {
  8. // If a message meets these criteria, we don't autoclose
  9. // - contains a link
  10. // - is an error or warning
  11. // - contains a lenghthy amount of text
  12. if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
  13. $(this).prepend("<span class='close'>X</span>");
  14. $('span.close', this).click(function() {
  15. $(this).parent().slideUp('fast');
  16. });
  17. }
  18. else {
  19. // This essentially adds a 3 second pause before hiding the message.
  20. $(this).animate({opacity:1}, 5000, 'linear', function() {
  21. $(this).slideUp('fast');
  22. });
  23. }
  24. });
  25. if(!$('body').is('.front') && !$('body').is('.node-type-performance')){
  26. $('#main').jScrollPane({autoReinitialise:true, hijackInternalLinks:true});
  27. }
  28. $('#block-menu-block-2 ul.menu').listnav({cookieName:'test', attribute:'nom'});
  29. };
  30. Drupal.behaviors.init_timeline = {};
  31. Drupal.behaviors.init_timeline.attach = function (context) {
  32. $.paScPlayer.defaults.onDomReady = null;
  33. $.paScPlayer.defaults.loadArtworks = 0;
  34. if($('html').is('.oldie'))
  35. {
  36. $('html').addClass('classic-nav');
  37. }
  38. else if($('body').is('.front') || $('body').is('.node-type-performance'))
  39. {
  40. var _$modalIntro = $('<div class="modal">').appendTo($('<div id="intro-wrapper"><div class="bg"></div></div>').appendTo('body')).verticalcenter(),
  41. _$timeline_loader, _$perfnode, _$filters, _$timeline, _$timeline_container,
  42. _datas = {},
  43. _dates = [], _dates_nids = [],
  44. _timeline,
  45. view_modes = ["dot", "titles", "thumbnails", "images"], current_view_mode,
  46. _filters = {}, _filters_str_tids = [], _filters_key = {}, _filters_correspondances = {}, _selected_filters = [],
  47. filterInputTimer, prevFilterInput = '',
  48. _layouts = {
  49. intro:"layout-intro",
  50. timeline:"layout-timeline",
  51. perfnode:"layout-perfnode"
  52. },
  53. _grid,
  54. _current_nid = false,
  55. _perf_jsp,
  56. _$next_perf, _$prev_perf,
  57. _intro_start,
  58. _$modal,
  59. _drupalBasePath = Drupal.settings.basePath+Drupal.settings.pathPrefix,
  60. _strings = Drupal.settings.perfarttimeline.strings;
  61. function init(){
  62. if(readCookie('advanced-nav') != 'yes' && readCookie('classic-nav') != 'yes'){
  63. $.getJSON(_drupalBasePath+'perfart/ajax/home', function(data){
  64. console.log('data', data);
  65. _$modalIntro.prepend(data.front).verticalcenter();
  66. $('.nodetitle',_$modalIntro).hide();
  67. });
  68. var $btns = $('<div class="btns">').appendTo(_$modalIntro);
  69. $btns.append($('<span>'+_strings.advanced_nav+'</span>').bind('click', function(event) {
  70. createCookie('advanced-nav', 'yes');
  71. $btns.hide();
  72. initAdvancedNav();
  73. }));
  74. $btns.append($('<span>'+_strings.classical_nav+'</span>').bind('click', function(event) {
  75. createCookie('classic-nav', 'yes');
  76. initClassic();
  77. }));
  78. }else{
  79. if(readCookie('advanced-nav') == 'yes'){
  80. initAdvancedNav();
  81. }else{
  82. initClassic();
  83. }
  84. }
  85. };
  86. function initClassic(){
  87. // console.log('initClassic');
  88. removeIntroModal();
  89. $('html').addClass('classic-nav');
  90. };
  91. function initAdvancedNav(){
  92. // build dom layout //
  93. _$timeline_loader = $('<div id="timeline-loader">').appendTo(_$modalIntro).append('<div>'+_strings.loading_timeline+'</div>').append($('<div class="progress">'));
  94. _$perfnode = $('<div id="perfnode"><div class="loader"/><div class="close"/><div class="node-container"><div class="scroller"/></div></div>').appendTo('#center');
  95. _$filters = $('<div id="filters">').appendTo('#center');
  96. _$timeline = $('<div>').attr('id', 'timeline').appendTo('#center').append('<h3 class="title">Chronologie</h3>');
  97. _$timeline_container = $('<div>').attr('id', 'timeline-container').appendTo('#timeline');
  98. _$next_perf = $('<div class="next-perf">').appendTo(_$perfnode);
  99. _$prev_perf = $('<div class="prev-perf">').appendTo(_$perfnode);
  100. _$modal = $('<div class="timeline-modal">').appendTo('body');
  101. $('body').addClass('view-mode-'+view_modes[0]);
  102. // start //
  103. _timeline = new links.Timeline(document.getElementById('timeline-container'));
  104. var timeline_options = {
  105. "width": "100%",
  106. "height": _$timeline_container.height()+"px",//"100%",
  107. "style": "dot",
  108. "editable": false,
  109. "axisOnTop":true,
  110. "min":new Date('1950'),
  111. "max":new Date('2020'),
  112. "start":new Date('1950'),
  113. "end":new Date('2020'),
  114. "showCurrentTime":false,
  115. "animate":true,
  116. "animateZoom":true,
  117. "intervalMin":1000*60*60*24*365, // a year
  118. "showNavigation":true,
  119. // "stackEvents":false,
  120. 'eventMargin': 0, // minimal margin between events
  121. 'eventMarginAxis': 4, // minimal margin beteen events and the axis
  122. // custom options
  123. "mousewheel":"move",
  124. "dblclick":"zoom",
  125. "language":Drupal.settings.perfarttimeline.language,
  126. };
  127. _timeline.draw([], timeline_options);
  128. _$next_perf.bind("click", onClickBtnNavPerf);
  129. _$prev_perf.bind("click", onClickBtnNavPerf);
  130. $('.close', _$perfnode).bind('click', function(event) {
  131. showTimeline();
  132. });
  133. $(".node-container",_$perfnode).height(_$perfnode.height());
  134. switchLayout('intro');
  135. initHistory();
  136. initKeyBoardNav();
  137. // Drupal.settings.perfart.effectuations_pages = 1;
  138. _intro_start = new Date();
  139. loadDates();
  140. };
  141. function loadDates(page){
  142. page = page || 0;
  143. var url = _drupalBasePath + "perfart/ajax/dates/"+page,
  144. regexp;
  145. if(page == 0)
  146. $('.progress', _$timeline_loader).width('5%');
  147. $.getJSON(url, function(data){
  148. var date, start, end;
  149. // console.log('data', data);
  150. $('.progress', _$timeline_loader).width((page+1)*(100/Drupal.settings.perfart.effectuations_pages)+'%');
  151. for(ind in data){
  152. if(data[ind].start === undefined)
  153. continue;
  154. date = data[ind];
  155. // console.log('date thumb',date.thumb);
  156. date.start = new Date(date.start.year, date.start.month, date.start.day);
  157. if(typeof date.end != "undefined")
  158. date.end = new Date(date.end.year, date.end.month, date.end.day);
  159. // filters
  160. for(filterstitle in date.filters){
  161. // console.log('date.filters', date.filters.length);
  162. // var filterstitle, tid;
  163. // for (var i = 0; i < date.filters.length; i++) {
  164. // filterstitle = date.filters[i];
  165. if(_filters[filterstitle] === undefined){
  166. _filters[filterstitle] = [];
  167. _filters_str_tids[filterstitle] = "";
  168. }
  169. // console.log('date.filters = '+filterstitle, date.filters[filterstitle]);
  170. for(tid in date.filters[filterstitle]){
  171. // for (var j = 0; j < date.filters[filterstitle].length; j++) {
  172. // tid = date.filters[filterstitle][j];
  173. if(_filters_key[tid] === undefined)
  174. _filters_key[tid] = filterstitle;
  175. if(date.tids === undefined)
  176. date.tids = [];
  177. date.tids.push(tid);
  178. regexp = new RegExp('tid'+tid+';');
  179. if(_filters_str_tids[filterstitle].search(regexp) != -1)
  180. continue;
  181. _filters_str_tids[filterstitle] += 'tid'+tid+";";
  182. date.filters[filterstitle][tid].visible = true;
  183. _filters[filterstitle].push(date.filters[filterstitle][tid]);
  184. }
  185. }
  186. for (var i = 0; i < date.tids.length; i++) {
  187. if(_filters_correspondances[date.tids[i]]=== undefined)
  188. _filters_correspondances[date.tids[i]] = [];
  189. for (var j = 0; j < date.tids.length; j++) {
  190. if(date.tids[j] != date.tids[i] && array_indexOf(_filters_correspondances[date.tids[i]], date.tids[j]) === -1)
  191. _filters_correspondances[date.tids[i]].push(date.tids[j]);
  192. }
  193. }
  194. _datas[date.nid] = date;
  195. _dates.push(date);
  196. _dates_nids.push(date.nid);
  197. }
  198. if(page+1 == Drupal.settings.perfart.effectuations_pages){
  199. $('.progress', _$timeline_loader).width('100%').addClass('complete');
  200. //console.log('_datas', _datas);
  201. // console.log('_filters', _filters);
  202. // console.log('_dates', _dates);
  203. onDatesLoaded();
  204. }else{
  205. loadDates(page+1);
  206. }
  207. })
  208. .error(function(jqXHR, textStatus, errorThrown) {
  209. console.log("error " + textStatus);
  210. console.log("incoming Text ", jqXHR);
  211. console.log('ERROR on loading dates page '+page);
  212. $('.progress', _$timeline_loader).width((page+1)*(100/Drupal.settings.perfart.effectuations_pages)+'%');
  213. if(page+1 == Drupal.settings.perfart.effectuations_pages){
  214. $('.progress', _$timeline_loader).width('100%').addClass('complete');
  215. onDatesLoaded();
  216. }else{
  217. loadDates(page+1);
  218. }
  219. });
  220. };
  221. function onDatesLoaded(){
  222. initTimeline();
  223. if($('body').is('.front')){ launchTimeline();}
  224. else if( $('body').is('.node-type-performance') ){ launchPerf(); }
  225. setTimeout(removeIntroModal, 400);
  226. };
  227. function removeIntroModal(){
  228. _$modalIntro
  229. .css({'margin-top':'-'+(_$modalIntro.height()+100)+'px'})
  230. .siblings().hide();
  231. setTimeout(function(){
  232. _$modalIntro.parent().hide();
  233. }, 900);
  234. };
  235. function launchTimeline(){
  236. var end_loading = new Date(),
  237. pause = readCookie('timelinelaunched') == 'ok' ? 5000 : 10000,
  238. left_time = pause - (end_loading.getTime() - _intro_start.getTime());
  239. if(left_time < 0){
  240. showTimeline();
  241. }else{
  242. setTimeout(function(){
  243. createCookie('timelinelaunched', 'ok', 1);
  244. showTimeline();
  245. }, left_time);
  246. }
  247. };
  248. function launchPerf(){
  249. var bodyclasses = $('body').attr('class'),
  250. matches = bodyclasses.match(/page-node-([0-9]+)/),
  251. nid = matches[1],
  252. date = _dates[array_indexOf(_dates_nids, nid)];
  253. loadPerformance(_datas[nid].ajax_link);
  254. };
  255. /**
  256. * keyboard navigation
  257. */
  258. function initKeyBoardNav(){
  259. $(window).bind('keydown', function(event){
  260. // console.log('keypressed', event);
  261. switch(event.keyCode){
  262. case 39://droite
  263. nextPerf();
  264. break;
  265. case 37://gauche
  266. prevPerf();
  267. break;
  268. case 38://haut
  269. if(_current_nid)
  270. //showPerformance();
  271. break;
  272. case 40://bas
  273. showTimeline();
  274. break;
  275. }
  276. });
  277. };
  278. /**
  279. * History
  280. */
  281. function initHistory(){
  282. var State = History.getState();
  283. // Log Initial State
  284. //History.log('initial:', State.data, State.title, State.url);
  285. // Bind to State Change
  286. $(window).bind('statechange', function(){
  287. historyOnStateChange(History.getState());
  288. });
  289. };
  290. function historyOnStateChange(state){
  291. // History.log('statechange:', state.data, state.title, state.url);
  292. if (objectIsEmpty(state.data)){
  293. switchLayout('timeline');
  294. _current_nid = false;
  295. updateTranslationLink();
  296. }else if (_current_nid != state.data.json.nid) {
  297. updateTranslationLink(_datas[state.data.json.nid].node_translation);
  298. resetFilters();
  299. switchLayout('perfnode');
  300. showPerformance(state.data.json);
  301. // if(_current_nid){
  302. // showPerformance(state.data.json);
  303. // }else{
  304. // loadPerformance(state.data.ajaxpath);
  305. // }
  306. };
  307. };
  308. /**
  309. * time line
  310. */
  311. function initTimeline(){
  312. setFilters();
  313. setupDatesLinks();
  314. updateTimeline();
  315. $('body').addClass('timeline');
  316. $('h3.title', _$timeline).bind('click', function(event) {
  317. showTimeline();
  318. });
  319. initSearch();
  320. };
  321. function showTimeline(){
  322. switchLayout('timeline');
  323. updateTranslationLink('');
  324. History.pushState({}, _strings.site_name, _drupalBasePath);
  325. };
  326. function setupDatesLinks(){
  327. $('div.date', _$timeline_container)
  328. .bind('click', onClickDate)
  329. .bind('mouseenter', onHoverDate)
  330. .bind('mouseleave', onOutDate);
  331. };
  332. function onClickDate(event){
  333. event.preventDefault();
  334. //console.log('onClickDate');
  335. loadPerformance($(this).attr('href'));
  336. return false;
  337. };
  338. function onHoverDate(event){
  339. var $date = $(event.currentTarget);
  340. _$modal
  341. .stop(true, true)
  342. .css({
  343. 'top':event.clientY - _$modal.height() - 5,
  344. 'left':event.clientX+5
  345. });
  346. // console.log('event',event);
  347. var visible = true;
  348. if($('body').is('.view-mode-dot')){
  349. _$modal.html($date.find('.text-content').html());
  350. }else{
  351. // console.log('thumb = '+$date.attr('thumb'));
  352. if(typeof _datas[$date.attr('nid')].thumb != "undefined"){
  353. _$modal.html(_datas[$date.attr('nid')].thumb);
  354. }else{
  355. _$modal.html("");
  356. visible = false;
  357. }
  358. }
  359. if(visible){
  360. $date.bind('mousemove', onDateMouseMove);
  361. _$modal.fadeIn();
  362. }
  363. };
  364. function onDateMouseMove(event){
  365. _$modal
  366. .css({
  367. 'top':event.clientY - _$modal.height() - 5,
  368. 'left':event.clientX+5
  369. });
  370. };
  371. function onOutDate(event){
  372. $(event.currentRarget).unbind('mousemove', onDateMouseMove);
  373. _$modal.stop(true, true).fadeOut();
  374. };
  375. function onBeforeStackEvents(){
  376. // console.log('onBeforeStackEvents | visibleItems', _timeline.visibleItems.length);
  377. if(_timeline.visibleItemsChanged){
  378. if(_timeline.visibleItems.length < 4){
  379. current_view_mode = 3;
  380. }else if(_timeline.visibleItems.length <= 10){
  381. current_view_mode = 2;
  382. }else if(_timeline.visibleItems.length <= 120){
  383. current_view_mode = 1;
  384. }else{
  385. current_view_mode = 0;
  386. }
  387. //
  388. for (var i=0, max_len = view_modes.length; i < max_len; i++) {
  389. if(i == current_view_mode){
  390. $('body').addClass('view-mode-'+view_modes[i]);
  391. }else{
  392. $('body').removeClass('view-mode-'+view_modes[i]);
  393. }
  394. };
  395. _timeline.itemsSizeChanged = true;
  396. }
  397. };
  398. links.events.addListener(_timeline, 'on-before-stack-events', onBeforeStackEvents);
  399. function filterDates(){
  400. // console.log('filterDates');
  401. var date, tid, filter, active;
  402. _dates = [];
  403. _dates_nids = [];
  404. // console.log('_selected_filters', _selected_filters);
  405. for(nid in _datas){
  406. date = _datas[nid];
  407. active = true;
  408. if(_selected_filters.length){
  409. for (var i = _selected_filters.length - 1; i >= 0; i--){
  410. if(array_indexOf(date.tids, _selected_filters[i]) == -1){
  411. active = false;
  412. break;
  413. }
  414. };
  415. }
  416. if(active){
  417. _dates.push(date);
  418. _dates_nids.push(nid);
  419. }
  420. }
  421. updateTimeline();
  422. };
  423. function updateTimeline(){
  424. //console.log('updateTimeline | _dates');//, _dates);
  425. switchLayout('timeline');
  426. _timeline.draw(_dates);
  427. _timeline.setVisibleChartRangeAuto();
  428. setupDatesLinks();
  429. };
  430. function zoomToDate(nid){
  431. var index = array_indexOf(_dates_nids, nid),
  432. date = _dates[index];
  433. _timeline.setSelection([{row:index}]);
  434. _timeline.setVisibleChartRange(date.start, date.start);
  435. };
  436. /**
  437. * filters
  438. *
  439. */
  440. function setFilters(){
  441. var delta = 0;
  442. for(title in _filters){
  443. var $input = $('<input class="search" type="text" value="'+_strings.search+'" key="'+title+'">'),
  444. $filter = $('<div class="filter">')
  445. .addClass(title).addClass('filter-'+delta)
  446. .appendTo(_$filters)
  447. .append('<div class="list"><ul></ul></div>')
  448. .append('<h3 class="title">'+Drupal.settings.perfart.strings[title]+'</h3>')
  449. // .append('<h3 class="title">'+title+'</h3>')
  450. .append($input)
  451. .wrapInner('<div class="filters-selection">')
  452. .append('<div class="filters-selected">'),
  453. $list = $('.list ul', $filter);
  454. if(title == "peoples"){
  455. _filters[title].sort(sortFiltersByName);
  456. // console.log('_filters[title]',_filters[title]);
  457. }else{
  458. _filters[title].sort(sortFilters);
  459. }
  460. for(filter in _filters[title]){
  461. if(typeof _filters[title][filter]['tid'] !== "undefined"){
  462. $list.append($('<li class="'+_filters[title][filter]['tid']+'"></li>')
  463. .append('<span class="'+_filters[title][filter]['tid']+'">'+_filters[title][filter]['name']+'</span>'));
  464. }
  465. }
  466. $input
  467. .bind('focus', clearInput)
  468. .bind('keydown', onInputKeypressed)
  469. .bind('valuechanged', filterFiltersList);
  470. $('li', $list)
  471. .bind('click', onClickAddFilter);
  472. delta++;
  473. };
  474. $('.list', "#filters").jScrollPane({autoReinitialise:true});
  475. };
  476. function sortFiltersByName(a,b) {
  477. if(typeof a == 'object'){
  478. // var wordsa = a.name.toLowerCase().match(/^[^\s]+\s([^\s]+)/),
  479. // na = wordsa === null ? a.name.toLowerCase() : wordsa[1],
  480. // wordsb = b.name.toLowerCase().match(/^[^\s]+\s([^\s]+)/),
  481. // nb = wordsb === null ? b.name.toLowerCase() : wordsb[1];
  482. var na = a.nom ? a.nom : a.name;
  483. var nb = b.nom ? b.nom : b.name;
  484. // na = na.toLowerCase();
  485. na = na.toLowerCase().latinise();
  486. // nb = nb.toLowerCase();
  487. nb = nb.toLowerCase().latinise();
  488. if (na < nb)
  489. return -1;
  490. if (na > nb)
  491. return 1;
  492. }
  493. return 0;
  494. };
  495. function sortFilters(a,b) {
  496. //console.log('a', a);
  497. if(typeof a == 'object'){
  498. var na = a.name.toLowerCase().latinise(),
  499. nb = b.name.toLowerCase().latinise();
  500. if (na < nb)
  501. return -1;
  502. if (na > nb)
  503. return 1;
  504. }
  505. return 0;
  506. };
  507. function clearInput(event){
  508. var $input = $(this);
  509. if($input.attr('value') == _strings.search)
  510. $(this).attr('value', '');
  511. };
  512. function onInputKeypressed(event) {
  513. // this setTimeout just serve to retreive the juste added letter
  514. // without we always have a one char delay on the keypress event
  515. var $this = $(this);
  516. setTimeout(function(){ $this.trigger('valuechanged'); },1);
  517. };
  518. function filterFiltersList(event){
  519. console.log('filterFiltersList', event);
  520. var $input = $(this),
  521. value = $input.val(),
  522. filtersList = _filters[$input.attr('key')],
  523. $list = $input.siblings('.list'),
  524. regexpValue, filter;
  525. clearTimeout(filterInputTimer);
  526. // prevFilterInput
  527. if(value != ''){
  528. filterInputTimer = setTimeout(function(){
  529. console.log('value = '+value);
  530. regexpValue = new RegExp(value, 'i');
  531. for(key in filtersList){
  532. filter = filtersList[key];
  533. // console.log('filter', filter);
  534. if (filter.name.search(regexpValue) == -1){
  535. if(filter.visible){
  536. filter.visible = false;
  537. $('li.'+filter.tid, $list).height(0);//.slideUp();
  538. }
  539. }else if(!filter.visible){
  540. filter.visible = true;
  541. $('li.'+filter.tid, $list).height('auto');//.slideDown();
  542. }
  543. }
  544. // $list.jScrollPane();
  545. }, 500);
  546. }else{
  547. // $('li', $list).height('auto');
  548. for(key in filtersList){
  549. filter = filtersList[key];
  550. filter.visible = true;
  551. $('li.'+filter.tid, $list).height('auto');//.slideDown();
  552. }
  553. }
  554. };
  555. function onClickAddFilter(event){
  556. var $this = $(this);
  557. if(!$this.is('.selected')){
  558. var $clone = $('span', $this).clone(),
  559. tid = $clone.attr('class');
  560. $this
  561. .addClass('selected')
  562. .parents('.filter').find('.filters-selected')
  563. .append($clone);
  564. $clone.bind('click', onClickRemoveFilter );
  565. var click = jQuery.Event("click");
  566. click.dontfilterdate = true;
  567. $('.close-search','#search-block-form').trigger(click);
  568. _selected_filters.push(tid);
  569. filterOtherFilters();
  570. filterDates();
  571. checkFiltersHeight();
  572. }
  573. };
  574. function onClickRemoveFilter(event){
  575. if(!$('body').is('.layout-timeline'))
  576. return;
  577. console.log('onClickRemoveFilter', event);
  578. var $this = $(this),
  579. tid = $this.attr('class'),
  580. dontfilterdate = event.dontfilterdate || false;
  581. $this.parents('.filter').find('.filters-selection').find('li.'+tid).removeClass('selected');
  582. $this.remove();
  583. setTimeout(function(){
  584. array_remove(_selected_filters,tid);
  585. filterOtherFilters();
  586. checkFiltersHeight();
  587. if(!dontfilterdate)
  588. filterDates();
  589. },5);
  590. };
  591. function filterOtherFilters(){
  592. var active, classe;
  593. $('.filter .filters-selection li:not(.selected)').each(function(){
  594. active = true;
  595. classe = $(this).attr('class');
  596. if(_selected_filters.length){ // && array_indexOf(_selected_filters, classe) === -1
  597. for (var i = _selected_filters.length - 1; i >= 0; i--){
  598. if(array_indexOf(_filters_correspondances[_selected_filters[i]], classe) == -1){
  599. active = false;
  600. break;
  601. }
  602. };
  603. }
  604. if (!active) {
  605. $(this).height(0);
  606. }else{
  607. $(this).height('auto');
  608. }
  609. });
  610. }
  611. function checkFiltersHeight(){
  612. var h = 0;
  613. $('.filters-selected', '#filters').each(function(i, elmt){
  614. h = $(elmt).height() > h ? $(elmt).height() : h;
  615. });
  616. _$filters.css({marginBottom:(h+5)+'px'});
  617. };
  618. function resetFilters(fd){
  619. var click = jQuery.Event("click");
  620. click.dontfilterdate = true;
  621. console.log('resetFilters : click', click);
  622. $('#filters .filters-selected span').trigger(click);
  623. };
  624. /**
  625. * search
  626. */
  627. function initSearch(){
  628. $('#search-block-form').bind('submit', function(event) {
  629. // console.log('search submited', event);
  630. var $this = $(this);
  631. setTimeout(function(){
  632. var searched_keys = $this.find('input[name*="search_block_form"]').val()
  633. searchFormSubmit(searched_keys, $this);
  634. },10);
  635. return false;
  636. });
  637. };
  638. function searchFormSubmit(typed, $form){
  639. // console.log('searchFormSubmit | keys = '+keys);
  640. if(typed !== undefined && typed !== '' && typed.length >= 2){
  641. typed = typed.replace('/', ' ');
  642. $form.addClass('loading');
  643. // $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'perfart/search/',
  644. // {keys:keys},
  645. // function(json){
  646. // $form.removeClass('loading');
  647. // searchFiltreTimeline(json);
  648. // });
  649. $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'perfart/search_api/',
  650. {typed:typed},
  651. function(json){
  652. $form.removeClass('loading');
  653. console.log('json', json);
  654. searchFiltreTimeline(json);
  655. });
  656. }
  657. };
  658. function searchFiltreTimeline(json){
  659. console.log('searchFiltreTimeline | json', json);
  660. var nid;
  661. _dates = [];
  662. _dates_nids = [];
  663. for(var nid in json['results']){
  664. // nid = json['results'][ind];
  665. if(typeof _datas[nid] != 'undefined'){
  666. _dates.push(_datas[nid]);
  667. _dates_nids.push(nid);
  668. }
  669. }
  670. resetFilters(false);
  671. updateTimeline();
  672. if(!$('.container-inline .close-search', '#search-block-form').size()){
  673. $('.container-inline','#search-block-form').append($('<span class="close-search">').bind('click', resetSearch));
  674. }
  675. };
  676. function resetSearch(event){
  677. console.log('resetSearch')
  678. $(event.currentTarget).remove();
  679. var dontfilterdate = event.dontfilterdate || false;
  680. $('#search-block-form').find('input[name*="search_block_form"]').val('');
  681. if(dontfilterdate)
  682. return;
  683. _dates = [];
  684. _dates_nids = [];
  685. // console.log('_selected_filters', _selected_filters);
  686. for(nid in _datas){
  687. _dates.push(_datas[nid]);
  688. _dates_nids.push(nid);
  689. }
  690. updateTimeline();
  691. };
  692. /**
  693. * performance view
  694. */
  695. function loadPerformance(url){
  696. _$perfnode.addClass('loading').children('.node');
  697. $('.node-container .node', _$perfnode).hide();
  698. clearPerfNav();
  699. switchLayout('perfnode');
  700. // if(url.indexOf("/") === 0){
  701. url = url.replace(/^\//, '');
  702. // }
  703. url = _drupalBasePath + url;
  704. $.getJSON(url,
  705. function(json){
  706. // console.log('json', json);
  707. showPerformance(json);
  708. History.pushState({json:json, ajaxpath:url}, _datas[json.nid].perf_title+' | '+_strings.site_name, _drupalBasePath + _datas[json.nid].node_link);
  709. updateTranslationLink(_datas[json.nid].node_translation);
  710. });
  711. };
  712. function updateTranslationLink(p){
  713. if(!updateTranslationLink.homeTranslationLink){
  714. updateTranslationLink.homeTranslationLink = $('.language-switcher-locale-url li:not(.active) a').attr('href');
  715. }
  716. var href = p ? Drupal.settings.basePath + p : updateTranslationLink.homeTranslationLink;
  717. $('.language-switcher-locale-url li:not(.active) a').attr('href', href);
  718. }
  719. function showPerformance(data){
  720. // console.log('showPerformance', data);
  721. zoomToDate(data.nid);
  722. var $node_container = $('.node-container', _$perfnode);
  723. // $('>*', $node_container).remove();
  724. // $node_container.empty();
  725. _$perfnode.removeClass('loading');
  726. $node_container.find('.scroller').html(data.node_view)
  727. .children('.node').children().addClass('grid-block');
  728. _randomizeImageSizes($('.scroller>.node', $node_container));
  729. $('.node .node-title', $node_container).after($('.node figure.grid_large', $node_container));
  730. $('.node .field-type-textauthor', $node_container).children('.field-item').jScrollPane();
  731. _initPaScPlayer($node_container);
  732. $node_container.bind('grid_ready', onGridReady);
  733. _grid = new Grid($node_container, {
  734. cell_w:50,
  735. cell_h:50,
  736. // lines:Math.ceil($node_container.height())/100,
  737. // columns:Math.ceil($node_container.width())/100,
  738. padding:{t:0,r:0,b:0,l:0},
  739. gouttiere: 5,
  740. grille: false,
  741. decalage: false,
  742. latitude: 0,
  743. augmentable:true
  744. });
  745. protectImages($node_container);
  746. setPerfNav(data.nid);
  747. _current_nid = data.nid;
  748. };
  749. function _randomizeImageSizes($container){
  750. array_randomize($container.children('figure')).each(function(index) {
  751. _setImageSize(this, true, index);
  752. });
  753. array_randomize($container.children().find('figure')).each(function(index) {
  754. _setImageSize(this);
  755. });
  756. };
  757. function _setImageSize(figure, c, index){
  758. var children = c || false,
  759. style, $remain_img;
  760. $('img:not([path])', figure).each(function(){
  761. $(this).attr('path', $(this).attr('src'));
  762. });
  763. $('img', figure).attr('src', '');
  764. if(children){
  765. if(index == 0){ style = 'grid_large';
  766. }else if (index < 5){ style = 'grid_medium';
  767. }else{ style = 'grid_small'; }
  768. }else{
  769. style = 'grid_medium';
  770. }
  771. $remain_img = $('img.'+style, figure);
  772. $remain_img.attr('src', $remain_img.attr('path'));
  773. $(figure).css({
  774. 'width':$remain_img.attr('width'),
  775. 'height':$remain_img.attr('height')
  776. })
  777. .addClass(style);
  778. $('img:not(.blank,.'+style+')', figure).remove();
  779. };
  780. function protectImages($container){
  781. $('figure', $container)
  782. // .append('<img class="blank" src="/'+Drupal.settings.perfarttimeline.theme_path+'/images/blank.gif" />')
  783. .bind("contextmenu", function(e){ alert("Cette image est soumise au droit d'auteur."); return false; })
  784. .addClass('protected');
  785. };
  786. function onGridReady(event){
  787. //console.log('onGridReady', event);
  788. // var $node_container = $('.node-container', _$perfnode);
  789. //console.log('grid max width = '+event.grid.maxwidth+' | grid max height = '+event.grid.maxheight);
  790. // _perf_jsp.destroy();
  791. $('.node-container',_$perfnode).find('.scroller').height(event.grid.maxheight);
  792. if(!_perf_jsp){
  793. var pane = $('.node-container',_$perfnode).jScrollPane({
  794. verticalGutter:5,
  795. autoReinitialise:true
  796. });
  797. _perf_jsp = pane.data('jsp');
  798. }
  799. };
  800. function clearPerfNav(){
  801. _$prev_perf.attr('url', '');
  802. _$next_perf.attr('url', '');
  803. };
  804. function setPerfNav(nid){
  805. // console.log('nid = '+nid);
  806. var index = array_indexOf(_dates_nids, nid);
  807. if(typeof _dates_nids[index-1] != 'undefined'){
  808. _$prev_perf.attr('url', _datas[_dates_nids[index-1]].ajax_link).show();
  809. }else{
  810. _$prev_perf.hide();
  811. }
  812. if(typeof _dates_nids[index+1] != 'undefined'){
  813. _$next_perf.attr('url', _datas[_dates_nids[index+1]].ajax_link).show();
  814. }else{
  815. _$next_perf.hide();
  816. }
  817. };
  818. function onClickBtnNavPerf(event){
  819. var url = $(this).attr('url');
  820. if(url != '')
  821. loadPerformance(url);
  822. };
  823. function nextPerf(){
  824. if(_current_nid){
  825. var index = array_indexOf(_dates_nids, _current_nid);
  826. // console.log('index = '+index);
  827. loadPerformance(_datas[_dates_nids[index+1]].ajax_link);
  828. }
  829. };
  830. function prevPerf(){
  831. if(_current_nid){
  832. var index = array_indexOf(_dates_nids,_current_nid);
  833. // console.log('index = '+index);
  834. loadPerformance(_datas[_dates_nids[index-1]].ajax_link);
  835. }
  836. };
  837. /**
  838. * layout
  839. */
  840. function switchLayout(mode){
  841. //console.log('switchLayout | mode '+mode);
  842. // if(mode != 'timeline'){
  843. // // _timeline.deleteAllItems();
  844. // }else{
  845. // // updateTimeline();
  846. // }
  847. for (key in _layouts)
  848. $('body').removeClass(_layouts[key]);
  849. $('body').addClass(_layouts[mode]);
  850. };
  851. /**
  852. * Grid()
  853. */
  854. function Grid($f, settings){
  855. var _defaults = {
  856. padding:{t:20,r:25,b:20,l:25},
  857. gouttiere: 20,
  858. cell_w: 155,
  859. cell_h: 50,
  860. lines: 0,
  861. columns: 0,
  862. grille: false,
  863. decalage: false,
  864. latitude: 50,
  865. augmentable:false
  866. },
  867. $fiche = $f,
  868. _cells = new Array(),
  869. _positions = new Array(),
  870. _thisgrid = this,
  871. _prePlacedBlocks = 0,
  872. _placedBlocks = 0,
  873. _allBlocks = 0,
  874. _grilleInterval;
  875. this.fiche = $fiche;
  876. this.settings = $.extend({}, _defaults, settings);
  877. this.settings.lines = Math.floor(($f.height() - this.settings.padding.t - this.settings.padding.b) / (this.settings.cell_h + this.settings.gouttiere));
  878. this.settings.columns = Math.floor(($f.width() - - this.settings.padding.r - this.settings.padding.l) / (this.settings.cell_w + this.settings.gouttiere));
  879. this.maxheight = this.maxwidth = 0;
  880. // console.log('w = '+$f.width()+' | h = '+$f.height());
  881. // console.log('lines = '+this.settings.lines+' | columns = '+this.settings.columns);
  882. if (this.settings.grille) {
  883. $fiche.append('<div class="grille"><div>');
  884. $('.grille', $fiche).css({
  885. 'width': '100%',
  886. 'height': '100%',
  887. 'position': 'relative'
  888. });
  889. }
  890. for (var l = 0; l < this.settings.lines; l++) {
  891. _cells[l] = new Array();
  892. for (var c = 0; c < this.settings.columns; c++) {
  893. _cells[l][c] = new Cell(this, c, l);
  894. };
  895. };
  896. _allBlocks = $('.grid-block', $fiche).length;
  897. if (this.settings.grille) {
  898. _grilleInterval = setInterval(function(){
  899. if(_prePlacedBlocks < _allBlocks){
  900. _placeBlock($('.grid-block', $fiche).eq(_prePlacedBlocks));
  901. _prePlacedBlocks ++;
  902. }else{
  903. clearInterval(_grilleInterval);
  904. }
  905. },1000);
  906. }else{
  907. $('.grid-block', $fiche).each(function() {
  908. // _allBlocks++;
  909. _placeBlock(this);
  910. });
  911. }
  912. function _block_placed(){
  913. // console.log('_block_placed _allBlocks = '+_allBlocks+' _placedBlocks = '+_placedBlocks)
  914. _placedBlocks++;
  915. if(_placedBlocks == _allBlocks){
  916. var event = jQuery.Event('grid_ready');
  917. event.grid = _thisgrid;
  918. $fiche.trigger(event);
  919. }
  920. }
  921. /**
  922. *
  923. */
  924. function _placeBlock(_this){
  925. //console.log('_placeBlock', _this);
  926. var $this = $(_this),
  927. this_cells_w = 0,
  928. this_cells_h = 0,
  929. free_cells = [];
  930. // if($this.hasClass('image')){
  931. // var sizes = [155, 330, 505],
  932. // i = sizes.length,
  933. // $img = $('img', $this),
  934. // $legende = $('.legende', $this);
  935. //
  936. // while(free_cells.length == 0 && i > 0){
  937. // i--;
  938. // $img.width(sizes[i]);
  939. // $this.width(sizes[i]+$legende.outerWidth()+2);
  940. // this_cells_w = Math.ceil($this.width() / (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere)),
  941. // this_cells_h = Math.ceil($this.height() / (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere));
  942. // free_cells = getFreeCells(this_cells_w, this_cells_h);
  943. // }
  944. // }else{
  945. this_cells_w = Math.ceil($this.width() / (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere)),
  946. this_cells_h = Math.ceil($this.height() / (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere));
  947. free_cells = getFreeCells(this_cells_w, this_cells_h);
  948. // }
  949. if(free_cells.length > 0){
  950. // var cell_num = Math.round(Math.random() * (free_cells.length - 1));
  951. // var cell_num = 0;
  952. var cell_num = Math.floor((free_cells.length-1)*0.5 + (-2+Math.random()*4));
  953. cell_num = cell_num > free_cells.length-1 ? free_cells.length-1 : ( cell_num < 0 ? 0 : cell_num );
  954. var cell = free_cells[cell_num],
  955. line_limit_loop = cell.getPos().l + (this_cells_h),
  956. column_limit_loop = cell.getPos().c + (this_cells_w);
  957. for (var l = cell.getPos().l; l < line_limit_loop; l++) {
  958. for (var c = cell.getPos().c; c < column_limit_loop; c++) {
  959. var temp_cell = _cells[l][c];
  960. temp_cell.setFull();
  961. };
  962. };
  963. var top = cell.getPos().l * (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere),
  964. left = cell.getPos().c * (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere),
  965. latitude = _thisgrid.settings.latitude;
  966. top = !_thisgrid.settings.decalage ? top: top + Math.round(Math.random() * latitude - latitude / 2)
  967. left = !_thisgrid.settings.decalage ? left: left + Math.round(Math.random() * latitude - latitude / 2);
  968. $this.css({
  969. 'top': top+_thisgrid.settings.padding.t,
  970. 'left': left+_thisgrid.settings.padding.l
  971. });
  972. _thisgrid.maxheight = Math.max(top+_thisgrid.settings.padding.t+$this.height(), _thisgrid.maxheight);
  973. _thisgrid.maxwidth = Math.max(left+_thisgrid.settings.padding.l+$this.width(), _thisgrid.maxwidth);
  974. _block_placed();
  975. } else {
  976. if(!_thisgrid.settings.augmentable){
  977. $this.css({
  978. 'border': '2px solid red',
  979. 'opacity': 0.2
  980. }).remove();
  981. _block_placed();
  982. }else{
  983. _augmenteGrid();
  984. //console.log('re placeblock');
  985. _placeBlock(_this);
  986. }
  987. }
  988. }
  989. function _augmenteGrid(){
  990. // for (var l = 0; l < this.settings.lines; l++) {
  991. var l = _thisgrid.settings.lines ;
  992. _thisgrid.settings.lines ++;
  993. _cells[l] = new Array();
  994. for (var c = 0; c < _thisgrid.settings.columns; c++) {
  995. _cells[l][c] = new Cell(_thisgrid, c, l);
  996. };
  997. // };
  998. _refreshCells();
  999. // console.log('lines = '+_thisgrid.settings.lines+' | columns = '+_thisgrid.settings.columns);
  1000. };
  1001. function _refreshCells(){
  1002. for (var l = _thisgrid.settings.lines-1; l >= 0 ; l--) {
  1003. for (var c = _thisgrid.settings.columns-1; c >= 0 ; c--) {
  1004. _cells[l][c].refresh();
  1005. }
  1006. }
  1007. }
  1008. /**
  1009. * getFreeCells()
  1010. */
  1011. function getFreeCells(this_cells_w, this_cells_h){
  1012. var free_cells = new Array();
  1013. for (var l = 0; l < _thisgrid.settings.lines; l++) {
  1014. for (var c = 0; c < _thisgrid.settings.columns; c++) {
  1015. var cell = _cells[l][c];
  1016. if (cell.isFree() && (cell.getAround().right + 1) >= this_cells_w && (cell.getAround().bottom + 1) >= this_cells_h) {
  1017. var good = true;
  1018. for (var i = 1; i < this_cells_w; i++) {
  1019. var temp_cell = _cells[l][c + i];
  1020. if ((temp_cell.getAround().bottom + 1) < this_cells_h) {
  1021. good = false;
  1022. break;
  1023. }
  1024. };
  1025. if (good) free_cells.push(cell);
  1026. }
  1027. };
  1028. };
  1029. return free_cells;
  1030. }
  1031. /**
  1032. * Cell()
  1033. */
  1034. function Cell(g, c, l) {
  1035. var _g = g,
  1036. _column = c,
  1037. _line = l,
  1038. _free = true,
  1039. _free_cell_right = _g.settings.columns - 1 - c,
  1040. _free_cell_bottom = _g.settings.lines - 1 - l;
  1041. if (_g.settings.grille) {
  1042. var _table = '<table>';
  1043. _table += '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  1044. // _table += '<tr><td>&nbsp;</td><td class="state">'+_free+'</td><td class="fr">'+_free_cell_right+'</td></tr>';
  1045. _table += '<tr><td>&nbsp;</td><td>&nbsp;</td><td class="fr">' + _free_cell_right + '</td></tr>';
  1046. _table += '<tr><td>&nbsp;</td><td class="fb">' + _free_cell_bottom + '</td><td>&nbsp;</td></tr>';
  1047. _table += '</table>';
  1048. _g.fiche.find('.grille').append('<div class="cell-' + l + '-' + c + '">' + _table + '<div>');
  1049. var _dom = $('.cell-' + l + '-' + c, _g.fiche.find('.grille'));
  1050. _dom.css({
  1051. 'position': 'absolute',
  1052. 'top': _line * (_g.settings.cell_h + _g.settings.gouttiere) + _g.settings.padding.t,
  1053. 'left': _column * (_g.settings.cell_w + _g.settings.gouttiere) + _g.settings.padding.l,
  1054. 'width': _g.settings.cell_w,
  1055. 'height': _g.settings.cell_h,
  1056. 'backgroundColor': '#00FF00',
  1057. 'opacity': 0.6
  1058. }).find('table').css({
  1059. width:'100%',
  1060. height:'100%'
  1061. }).find('td').css({width:"30%"});
  1062. // $('td', _dom).css({
  1063. // 'fontSize': '8px'
  1064. // });
  1065. }
  1066. this.isFree = function() {
  1067. return _free;
  1068. };
  1069. this.getPos = function() {
  1070. return {
  1071. c: _column,
  1072. l: _line
  1073. };
  1074. };
  1075. this.getAround = function() {
  1076. return {
  1077. right: _free_cell_right,
  1078. bottom: _free_cell_bottom
  1079. };
  1080. };
  1081. this.setFull = function() {
  1082. _free = false;
  1083. _free_cell_bottom = -1;
  1084. _free_cell_right = -1;
  1085. if (_g.settings.grille) {
  1086. _dom.css({
  1087. 'backgroundColor': '#0000FF'
  1088. });
  1089. $('.fb', _dom).html(_free_cell_bottom);
  1090. $('.fr', _dom).html(_free_cell_right);
  1091. }
  1092. _propageFreeCells();
  1093. };
  1094. this.setFreeCellsRight = function(right) {
  1095. if (_free) {
  1096. // console.log('_setFreeCellRigth | _free_cell_right = ' + _free_cell_right + ' | new right = ' + right);
  1097. _free_cell_right = right;
  1098. if (_g.settings.grille) $('.fr', _dom).html(_free_cell_right);
  1099. _propageFreeCellsLeft();
  1100. }
  1101. };
  1102. this.setFreeCellsBottom = function(bottom) {
  1103. if (_free) {
  1104. // console.log('_setFreeCellsBottom | _free_cell_bottom = ' + _free_cell_bottom + ' | new right = ' + bottom);
  1105. _free_cell_bottom = bottom;
  1106. if (_g.settings.grille) $('.fb', _dom).html(_free_cell_bottom);
  1107. _propageFreeCellsTop();
  1108. }
  1109. };
  1110. this.refresh = function(){
  1111. if(_free)
  1112. _propageFreeCellsTop();
  1113. };
  1114. function _propageFreeCells() {
  1115. // console.log('_propageFreeCells');
  1116. _propageFreeCellsLeft();
  1117. _propageFreeCellsTop();
  1118. };
  1119. function _propageFreeCellsLeft() {
  1120. // console.log('_propageFreeCellsLeft | _column = '+_column);
  1121. if (_column > 0) {
  1122. var left_cel = _cells[_line][_column - 1];
  1123. left_cel.setFreeCellsRight(_free_cell_right + 1);
  1124. }
  1125. };
  1126. function _propageFreeCellsTop() {
  1127. // console.log('_propageFreeCellsTop | _line = '+_line);
  1128. if (_line > 0) {
  1129. var top_cel = _cells[_line - 1][_column];
  1130. top_cel.setFreeCellsBottom(_free_cell_bottom + 1);
  1131. }
  1132. };
  1133. if (typeof Cell.initialized == "undefined") {
  1134. Cell.prototype.infos = function() {
  1135. //console.log('cell | column = ' + this.getPos().c + ', line = ' + this.getPos().l + ', free = ' + this.isFree() + ', free cell right = ' + this.getAround().right + ', free cell bottom = ' + this.getAround().bottom);
  1136. };
  1137. Cell.initialized = true;
  1138. }
  1139. }; // cell()
  1140. this.clear = function(){
  1141. $('.grille', $fiche).fadeOut(200, function() {
  1142. $(this).remove();
  1143. });
  1144. }
  1145. }; // GRIB
  1146. /**
  1147. * on resize
  1148. */
  1149. // debulked onresize handler
  1150. function on_resize(c,t){onresize=function(){clearTimeout(t);t=setTimeout(c,100)};return c};
  1151. on_resize(function() { if(typeof _timeline != 'undefined') _timeline.redraw(); });
  1152. /**
  1153. * cookies
  1154. */
  1155. function createCookie(name,value,days) {
  1156. if (days) {
  1157. var date = new Date();
  1158. date.setTime(date.getTime()+(days*24*60*60*1000));
  1159. var expires = "; expires="+date.toGMTString();
  1160. }
  1161. else var expires = "";
  1162. document.cookie = name+"="+value+expires+"; path=/";
  1163. }
  1164. function readCookie(name) {
  1165. var nameEQ = name + "=";
  1166. var ca = document.cookie.split(';');
  1167. for(var i=0;i < ca.length;i++) {
  1168. var c = ca[i];
  1169. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  1170. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  1171. }
  1172. return null;
  1173. }
  1174. function eraseCookie(name) {
  1175. createCookie(name,"",-1);
  1176. }
  1177. /**
  1178. * init
  1179. */
  1180. init();
  1181. }
  1182. function _initPaScPlayer($container, ap){
  1183. var $container = $container || $('body');
  1184. var ap = ap || false;
  1185. // console.log('_initPaScPlayer');
  1186. $.paScPlayer.stopAll();
  1187. var $links = $('a[rel="soundcloud"]', $container);
  1188. // console.log('$links', $links);
  1189. if($links.size()){
  1190. $links.parents('.field-item').find('span.ext').remove();
  1191. $links.paScPlayer({autoplay:ap});
  1192. }
  1193. }
  1194. _initPaScPlayer();
  1195. };
  1196. $.fn.verticalcenter = function(){
  1197. return this.each(function(index) {
  1198. $(this).css({
  1199. "margin-top": ($(this).parent().height() - $(this).height()) / 2
  1200. });
  1201. });
  1202. };
  1203. $.fn.innerheight = function(){
  1204. var h = 0;
  1205. this.chlidren().each(function(index) {
  1206. h = h + $(this).height() + parseInt($(this).css('margin-top')) + parseInt($(this).css('margin-bottom')) + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom'))
  1207. });
  1208. return h;
  1209. };
  1210. })(jQuery);
  1211. /** HELPERS */
  1212. /**
  1213. * returned value: (Array)
  1214. */
  1215. array_remove= function(ar){
  1216. var what, a= arguments, L= a.length, ax;
  1217. while(L && ar.length){
  1218. what= a[--L];
  1219. while((ax= ar.indexOf(what))!= -1){
  1220. ar.splice(ax, 1);
  1221. }
  1222. }
  1223. return ar;
  1224. };
  1225. array_indexOf = function(ar, what, i){
  1226. i= i || 0;
  1227. var L= ar.length;
  1228. while(i< L){
  1229. if(ar[i]=== what) return i;
  1230. ++i;
  1231. }
  1232. return -1;
  1233. };
  1234. array_randomize = function(arr) {
  1235. for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
  1236. return arr;
  1237. };
  1238. function objectIsEmpty(obj){
  1239. for (var prop in obj) {
  1240. if (obj.hasOwnProperty(prop))
  1241. return false;
  1242. };
  1243. return true;
  1244. }
  1245. var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","Ṕ":"P","Ṗ":"P","Ꝓ":"P","Ƥ":"P","Ꝕ":"P","Ᵽ":"P","Ꝑ":"P","Ꝙ":"Q","Ꝗ":"Q","Ŕ":"R","Ř":"R","Ŗ":"R","Ṙ":"R","Ṛ":"R","Ṝ":"R","Ȑ":"R","Ȓ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꜿ":"C","Ǝ":"E","Ś":"S","Ṥ":"S","Š":"S","Ṧ":"S","Ş":"S","Ŝ":"S","Ș":"S","Ṡ":"S","Ṣ":"S","Ṩ":"S","Ť":"T","Ţ":"T","Ṱ":"T","Ț":"T","Ⱦ":"T","Ṫ":"T","Ṭ":"T","Ƭ":"T","Ṯ":"T","Ʈ":"T","Ŧ":"T","Ɐ":"A","Ꞁ":"L","Ɯ":"M","Ʌ":"V","Ꜩ":"TZ","Ú":"U","Ŭ":"U","Ǔ":"U","Û":"U","Ṷ":"U","Ü":"U","Ǘ":"U","Ǚ":"U","Ǜ":"U","Ǖ":"U","Ṳ":"U","Ụ":"U","Ű":"U","Ȕ":"U","Ù":"U","Ủ":"U","Ư":"U","Ứ":"U","Ự":"U","Ừ":"U","Ử":"U","Ữ":"U","Ȗ":"U","Ū":"U","Ṻ":"U","Ų":"U","Ů":"U","Ũ":"U","Ṹ":"U","Ṵ":"U","Ꝟ":"V","Ṿ":"V","Ʋ":"V","Ṽ":"V","Ꝡ":"VY","Ẃ":"W","Ŵ":"W","Ẅ":"W","Ẇ":"W","Ẉ":"W","Ẁ":"W","Ⱳ":"W","Ẍ":"X","Ẋ":"X","Ý":"Y","Ŷ":"Y","Ÿ":"Y","Ẏ":"Y","Ỵ":"Y","Ỳ":"Y","Ƴ":"Y","Ỷ":"Y","Ỿ":"Y","Ȳ":"Y","Ɏ":"Y","Ỹ":"Y","Ź":"Z","Ž":"Z","Ẑ":"Z","Ⱬ":"Z","Ż":"Z","Ẓ":"Z","Ȥ":"Z","Ẕ":"Z","Ƶ":"Z","IJ":"IJ","Œ":"OE","ᴀ":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
  1246. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  1247. String.prototype.latinize=String.prototype.latinise;
  1248. String.prototype.isLatin=function(){return this==this.latinise()}