script.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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. // DON'T USE JSCROLLPANE FOR NORMAL PAGES ANYMORE
  26. // if(!$('body').is('.front') && !$('body').is('.node-type-performance')){
  27. // $('#main').jScrollPane({autoReinitialise:true, hijackInternalLinks:true});
  28. // }
  29. $('#block-menu-block-2 ul.menu').listnav({cookieName:'test', attribute:'nom'});
  30. $('.burger-icon.header').click(function(){
  31. $('body').toggleClass('burger-header-shown');
  32. });
  33. $('.burger-icon.sidebar-first').click(function(){
  34. $('body').toggleClass('burger-sidebar-first-shown');
  35. });
  36. };
  37. Drupal.behaviors.init_timeline = {};
  38. Drupal.behaviors.init_timeline.attach = function (context) {
  39. // $.paScPlayer.defaults.onDomReady = null;
  40. // $.paScPlayer.defaults.loadArtworks = 0;
  41. if($('html').is('.oldie'))
  42. {
  43. $('html').addClass('classic-nav');
  44. }
  45. else if($('body').is('.front') || $('body').is('.node-type-performance'))
  46. {
  47. var _$modalIntro = $('<div class="modal">').appendTo($('<div id="intro-wrapper"><div class="bg"></div></div>').appendTo('body')).verticalcenter(),
  48. _$timeline_loader, _$perfnode, _$filters, _$timeline, _$timeline_container,
  49. _datas = {},
  50. _dates = [], _dates_nids = [],
  51. _timeline,
  52. view_modes = ["dot", "titles", "thumbnails", "images"], current_view_mode,
  53. _filters = {}, _filters_str_tids = [], _filters_key = {}, _filters_correspondances = {}, _selected_filters = [],
  54. filterInputTimer, prevFilterInput = '',
  55. _layouts = {
  56. intro:"layout-intro",
  57. timeline:"layout-timeline",
  58. perfnode:"layout-perfnode"
  59. },
  60. _grid,
  61. _current_nid = false,
  62. _perf_jsp,
  63. _$next_perf, _$prev_perf,
  64. _intro_start,
  65. _$modal,
  66. _drupalBasePath = Drupal.settings.basePath+Drupal.settings.pathPrefix,
  67. _strings = Drupal.settings.perfarttimeline.strings;
  68. function init(){
  69. let isMobile = window.matchMedia("only screen and (max-width: 799px)").matches;
  70. if(isMobile){
  71. initClassic();
  72. }else if(readCookie('advanced-nav') != 'yes' && readCookie('classic-nav') != 'yes'){
  73. $.getJSON(_drupalBasePath+'perfart/ajax/home', function(data){
  74. console.log('data', data);
  75. _$modalIntro.prepend(data.front).verticalcenter();
  76. $('.nodetitle',_$modalIntro).hide();
  77. });
  78. var $btns = $('<div class="btns">').appendTo(_$modalIntro);
  79. $btns.append($('<span>'+_strings.advanced_nav+'</span>').bind('click', function(event) {
  80. createCookie('advanced-nav', 'yes');
  81. $btns.hide();
  82. initAdvancedNav();
  83. }));
  84. $btns.append($('<span>'+_strings.classical_nav+'</span>').bind('click', function(event) {
  85. createCookie('classic-nav', 'yes');
  86. initClassic();
  87. }));
  88. }else{
  89. if(readCookie('advanced-nav') == 'yes'){
  90. initAdvancedNav();
  91. }else{
  92. initClassic();
  93. }
  94. }
  95. };
  96. function initClassic(){
  97. // console.log('initClassic');
  98. removeIntroModal();
  99. $('html').addClass('classic-nav');
  100. };
  101. function initAdvancedNav(){
  102. // build dom layout //
  103. _$timeline_loader = $('<div id="timeline-loader">').appendTo(_$modalIntro).append('<div>'+_strings.loading_timeline+'</div>').append($('<div class="progress">'));
  104. _$perfnode = $('<div id="perfnode"><div class="loader"/><div class="close"/><div class="node-container"><div class="scroller"/></div></div>').appendTo('#center');
  105. _$filters = $('<div id="filters">').appendTo('#center');
  106. _$timeline = $('<div>').attr('id', 'timeline').appendTo('#center').append('<h3 class="title">Chronologie</h3>');
  107. _$timeline_container = $('<div>').attr('id', 'timeline-container').appendTo('#timeline');
  108. _$next_perf = $('<div class="next-perf">').appendTo(_$perfnode);
  109. _$prev_perf = $('<div class="prev-perf">').appendTo(_$perfnode);
  110. _$modal = $('<div class="timeline-modal">').appendTo('body');
  111. $('body').addClass('view-mode-'+view_modes[0]);
  112. // start //
  113. _timeline = new links.Timeline(document.getElementById('timeline-container'));
  114. var timeline_options = {
  115. "width": "100%",
  116. "height": _$timeline_container.height()+"px",//"100%",
  117. "style": "dot",
  118. "editable": false,
  119. "axisOnTop":true,
  120. "min":new Date('1950'),
  121. "max":new Date('2020'),
  122. "start":new Date('1950'),
  123. "end":new Date('2020'),
  124. "showCurrentTime":false,
  125. "animate":true,
  126. "animateZoom":true,
  127. "intervalMin":1000*60*60*24*365, // a year
  128. "showNavigation":true,
  129. // "stackEvents":false,
  130. 'eventMargin': 0, // minimal margin between events
  131. 'eventMarginAxis': 4, // minimal margin beteen events and the axis
  132. // custom options
  133. "mousewheel":"move",
  134. "dblclick":"zoom",
  135. "language":Drupal.settings.perfarttimeline.language,
  136. };
  137. _timeline.draw([], timeline_options);
  138. _$next_perf.bind("click", onClickBtnNavPerf);
  139. _$prev_perf.bind("click", onClickBtnNavPerf);
  140. $('.close', _$perfnode).bind('click', function(event) {
  141. showTimeline();
  142. });
  143. $(".node-container",_$perfnode).height(_$perfnode.height());
  144. switchLayout('intro');
  145. initHistory();
  146. initKeyBoardNav();
  147. // Drupal.settings.perfart.effectuations_pages = 1;
  148. _intro_start = new Date();
  149. loadDates();
  150. };
  151. function loadDates(page){
  152. page = page || 0;
  153. var url = _drupalBasePath + "perfart/ajax/dates/"+page,
  154. regexp;
  155. if(page == 0)
  156. $('.progress', _$timeline_loader).width('5%');
  157. $.getJSON(url, function(data){
  158. var date, start, end;
  159. // console.log('data', data);
  160. $('.progress', _$timeline_loader).width((page+1)*(100/Drupal.settings.perfart.effectuations_pages)+'%');
  161. for(ind in data){
  162. if(data[ind].start === undefined)
  163. continue;
  164. date = data[ind];
  165. // console.log('date thumb',date.thumb);
  166. date.start = new Date(date.start.year, date.start.month, date.start.day);
  167. if(typeof date.end != "undefined")
  168. date.end = new Date(date.end.year, date.end.month, date.end.day);
  169. // filters
  170. for(filterstitle in date.filters){
  171. // console.log('date.filters', date.filters.length);
  172. // var filterstitle, tid;
  173. // for (var i = 0; i < date.filters.length; i++) {
  174. // filterstitle = date.filters[i];
  175. if(_filters[filterstitle] === undefined){
  176. _filters[filterstitle] = [];
  177. _filters_str_tids[filterstitle] = "";
  178. }
  179. // console.log('date.filters = '+filterstitle, date.filters[filterstitle]);
  180. for(tid in date.filters[filterstitle]){
  181. // for (var j = 0; j < date.filters[filterstitle].length; j++) {
  182. // tid = date.filters[filterstitle][j];
  183. if(_filters_key[tid] === undefined)
  184. _filters_key[tid] = filterstitle;
  185. if(date.tids === undefined)
  186. date.tids = [];
  187. date.tids.push(tid);
  188. regexp = new RegExp('tid'+tid+';');
  189. if(_filters_str_tids[filterstitle].search(regexp) != -1)
  190. continue;
  191. _filters_str_tids[filterstitle] += 'tid'+tid+";";
  192. date.filters[filterstitle][tid].visible = true;
  193. _filters[filterstitle].push(date.filters[filterstitle][tid]);
  194. }
  195. }
  196. for (var i = 0; i < date.tids.length; i++) {
  197. if(_filters_correspondances[date.tids[i]]=== undefined)
  198. _filters_correspondances[date.tids[i]] = [];
  199. for (var j = 0; j < date.tids.length; j++) {
  200. if(date.tids[j] != date.tids[i] && array_indexOf(_filters_correspondances[date.tids[i]], date.tids[j]) === -1)
  201. _filters_correspondances[date.tids[i]].push(date.tids[j]);
  202. }
  203. }
  204. _datas[date.nid] = date;
  205. _dates.push(date);
  206. _dates_nids.push(date.nid);
  207. }
  208. if(page+1 == Drupal.settings.perfart.effectuations_pages){
  209. $('.progress', _$timeline_loader).width('100%').addClass('complete');
  210. //console.log('_datas', _datas);
  211. // console.log('_filters', _filters);
  212. // console.log('_dates', _dates);
  213. onDatesLoaded();
  214. }else{
  215. loadDates(page+1);
  216. }
  217. })
  218. .error(function(jqXHR, textStatus, errorThrown) {
  219. console.log("error " + textStatus);
  220. console.log("incoming Text ", jqXHR);
  221. console.log('ERROR on loading dates page '+page);
  222. $('.progress', _$timeline_loader).width((page+1)*(100/Drupal.settings.perfart.effectuations_pages)+'%');
  223. if(page+1 == Drupal.settings.perfart.effectuations_pages){
  224. $('.progress', _$timeline_loader).width('100%').addClass('complete');
  225. onDatesLoaded();
  226. }else{
  227. loadDates(page+1);
  228. }
  229. });
  230. };
  231. function onDatesLoaded(){
  232. initTimeline();
  233. if($('body').is('.front')){ launchTimeline();}
  234. else if( $('body').is('.node-type-performance') ){ launchPerf(); }
  235. setTimeout(removeIntroModal, 400);
  236. };
  237. function removeIntroModal(){
  238. _$modalIntro
  239. .css({'margin-top':'-'+(_$modalIntro.height()+100)+'px'})
  240. .siblings().hide();
  241. setTimeout(function(){
  242. _$modalIntro.parent().hide();
  243. }, 900);
  244. };
  245. function launchTimeline(){
  246. var end_loading = new Date(),
  247. pause = readCookie('timelinelaunched') == 'ok' ? 5000 : 10000,
  248. left_time = pause - (end_loading.getTime() - _intro_start.getTime());
  249. if(left_time < 0){
  250. showTimeline();
  251. }else{
  252. setTimeout(function(){
  253. createCookie('timelinelaunched', 'ok', 1);
  254. showTimeline();
  255. }, left_time);
  256. }
  257. };
  258. function launchPerf(){
  259. var bodyclasses = $('body').attr('class'),
  260. matches = bodyclasses.match(/page-node-([0-9]+)/),
  261. nid = matches[1],
  262. date = _dates[array_indexOf(_dates_nids, nid)];
  263. loadPerformance(_datas[nid].ajax_link);
  264. };
  265. /**
  266. * keyboard navigation
  267. */
  268. function initKeyBoardNav(){
  269. $(window).bind('keydown', function(event){
  270. // console.log('keypressed', event);
  271. switch(event.keyCode){
  272. case 39://droite
  273. nextPerf();
  274. break;
  275. case 37://gauche
  276. prevPerf();
  277. break;
  278. case 38://haut
  279. if(_current_nid)
  280. //showPerformance();
  281. break;
  282. case 40://bas
  283. showTimeline();
  284. break;
  285. }
  286. });
  287. };
  288. /**
  289. * History
  290. */
  291. function initHistory(){
  292. var State = History.getState();
  293. // Log Initial State
  294. //History.log('initial:', State.data, State.title, State.url);
  295. // Bind to State Change
  296. $(window).bind('statechange', function(){
  297. historyOnStateChange(History.getState());
  298. });
  299. };
  300. function historyOnStateChange(state){
  301. // History.log('statechange:', state.data, state.title, state.url);
  302. if (objectIsEmpty(state.data)){
  303. switchLayout('timeline');
  304. _current_nid = false;
  305. updateTranslationLink();
  306. }else if (_current_nid != state.data.json.nid) {
  307. updateTranslationLink(_datas[state.data.json.nid].node_translation);
  308. resetFilters();
  309. switchLayout('perfnode');
  310. showPerformance(state.data.json);
  311. // if(_current_nid){
  312. // showPerformance(state.data.json);
  313. // }else{
  314. // loadPerformance(state.data.ajaxpath);
  315. // }
  316. };
  317. };
  318. /**
  319. * time line
  320. */
  321. function initTimeline(){
  322. setFilters();
  323. setupDatesLinks();
  324. updateTimeline();
  325. $('body').addClass('timeline');
  326. $('h3.title', _$timeline).bind('click', function(event) {
  327. showTimeline();
  328. });
  329. initSearch();
  330. };
  331. function showTimeline(){
  332. switchLayout('timeline');
  333. updateTranslationLink('');
  334. History.pushState({}, _strings.site_name, _drupalBasePath);
  335. };
  336. function setupDatesLinks(){
  337. $('div.date', _$timeline_container)
  338. .bind('click', onClickDate)
  339. .bind('mouseenter', onHoverDate)
  340. .bind('mouseleave', onOutDate);
  341. };
  342. function onClickDate(event){
  343. event.preventDefault();
  344. //console.log('onClickDate');
  345. loadPerformance($(this).attr('href'));
  346. return false;
  347. };
  348. function onHoverDate(event){
  349. var $date = $(event.currentTarget);
  350. _$modal
  351. .stop(true, true)
  352. .css({
  353. 'top':event.clientY - _$modal.height() - 5,
  354. 'left':event.clientX+5
  355. });
  356. // console.log('event',event);
  357. var visible = true;
  358. if($('body').is('.view-mode-dot')){
  359. _$modal.html($date.find('.text-content').html());
  360. }else{
  361. // console.log('thumb = '+$date.attr('thumb'));
  362. if(typeof _datas[$date.attr('nid')].thumb != "undefined"){
  363. _$modal.html(_datas[$date.attr('nid')].thumb);
  364. }else{
  365. _$modal.html("");
  366. visible = false;
  367. }
  368. }
  369. if(visible){
  370. $date.bind('mousemove', onDateMouseMove);
  371. _$modal.fadeIn();
  372. }
  373. };
  374. function onDateMouseMove(event){
  375. _$modal
  376. .css({
  377. 'top':event.clientY - _$modal.height() - 5,
  378. 'left':event.clientX+5
  379. });
  380. };
  381. function onOutDate(event){
  382. $(event.currentRarget).unbind('mousemove', onDateMouseMove);
  383. _$modal.stop(true, true).fadeOut();
  384. };
  385. function onBeforeStackEvents(){
  386. // console.log('onBeforeStackEvents | visibleItems', _timeline.visibleItems.length);
  387. if(_timeline.visibleItemsChanged){
  388. if(_timeline.visibleItems.length < 4){
  389. current_view_mode = 3;
  390. }else if(_timeline.visibleItems.length <= 10){
  391. current_view_mode = 2;
  392. }else if(_timeline.visibleItems.length <= 120){
  393. current_view_mode = 1;
  394. }else{
  395. current_view_mode = 0;
  396. }
  397. //
  398. for (var i=0, max_len = view_modes.length; i < max_len; i++) {
  399. if(i == current_view_mode){
  400. $('body').addClass('view-mode-'+view_modes[i]);
  401. }else{
  402. $('body').removeClass('view-mode-'+view_modes[i]);
  403. }
  404. };
  405. _timeline.itemsSizeChanged = true;
  406. }
  407. };
  408. links.events.addListener(_timeline, 'on-before-stack-events', onBeforeStackEvents);
  409. function filterDates(){
  410. // console.log('filterDates');
  411. var date, tid, filter, active;
  412. _dates = [];
  413. _dates_nids = [];
  414. // console.log('_selected_filters', _selected_filters);
  415. for(nid in _datas){
  416. date = _datas[nid];
  417. active = true;
  418. if(_selected_filters.length){
  419. for (var i = _selected_filters.length - 1; i >= 0; i--){
  420. if(array_indexOf(date.tids, _selected_filters[i]) == -1){
  421. active = false;
  422. break;
  423. }
  424. };
  425. }
  426. if(active){
  427. _dates.push(date);
  428. _dates_nids.push(nid);
  429. }
  430. }
  431. updateTimeline();
  432. };
  433. function updateTimeline(){
  434. //console.log('updateTimeline | _dates');//, _dates);
  435. switchLayout('timeline');
  436. _timeline.draw(_dates);
  437. _timeline.setVisibleChartRangeAuto();
  438. setupDatesLinks();
  439. };
  440. function zoomToDate(nid){
  441. var index = array_indexOf(_dates_nids, nid),
  442. date = _dates[index];
  443. _timeline.setSelection([{row:index}]);
  444. _timeline.setVisibleChartRange(date.start, date.start);
  445. };
  446. /**
  447. * filters
  448. *
  449. */
  450. function setFilters(){
  451. var delta = 0;
  452. for(title in _filters){
  453. var $input = $('<input class="search" type="text" value="'+_strings.search+'" key="'+title+'">'),
  454. $filter = $('<div class="filter">')
  455. .addClass(title).addClass('filter-'+delta)
  456. .appendTo(_$filters)
  457. .append('<div class="list"><ul></ul></div>')
  458. .append('<h3 class="title">'+Drupal.settings.perfart.strings[title]+'</h3>')
  459. // .append('<h3 class="title">'+title+'</h3>')
  460. .append($input)
  461. .wrapInner('<div class="filters-selection">')
  462. .append('<div class="filters-selected">'),
  463. $list = $('.list ul', $filter);
  464. if(title == "peoples"){
  465. _filters[title].sort(sortFiltersByName);
  466. // console.log('_filters[title]',_filters[title]);
  467. }else{
  468. _filters[title].sort(sortFilters);
  469. }
  470. for(filter in _filters[title]){
  471. if(typeof _filters[title][filter]['tid'] !== "undefined"){
  472. $list.append($('<li class="'+_filters[title][filter]['tid']+'"></li>')
  473. .append('<span class="'+_filters[title][filter]['tid']+'">'+_filters[title][filter]['name']+'</span>'));
  474. }
  475. }
  476. $input
  477. .bind('focus', clearInput)
  478. .bind('keydown', onInputKeypressed)
  479. .bind('valuechanged', filterFiltersList);
  480. $('li', $list)
  481. .bind('click', onClickAddFilter);
  482. delta++;
  483. };
  484. $('.list', "#filters").jScrollPane({autoReinitialise:true});
  485. };
  486. function sortFiltersByName(a,b) {
  487. if(typeof a == 'object'){
  488. // var wordsa = a.name.toLowerCase().match(/^[^\s]+\s([^\s]+)/),
  489. // na = wordsa === null ? a.name.toLowerCase() : wordsa[1],
  490. // wordsb = b.name.toLowerCase().match(/^[^\s]+\s([^\s]+)/),
  491. // nb = wordsb === null ? b.name.toLowerCase() : wordsb[1];
  492. var na = a.nom ? a.nom : a.name;
  493. var nb = b.nom ? b.nom : b.name;
  494. // na = na.toLowerCase();
  495. na = na.toLowerCase().latinise();
  496. // nb = nb.toLowerCase();
  497. nb = nb.toLowerCase().latinise();
  498. if (na < nb)
  499. return -1;
  500. if (na > nb)
  501. return 1;
  502. }
  503. return 0;
  504. };
  505. function sortFilters(a,b) {
  506. //console.log('a', a);
  507. if(typeof a == 'object'){
  508. var na = a.name.toLowerCase().latinise(),
  509. nb = b.name.toLowerCase().latinise();
  510. if (na < nb)
  511. return -1;
  512. if (na > nb)
  513. return 1;
  514. }
  515. return 0;
  516. };
  517. function clearInput(event){
  518. var $input = $(this);
  519. if($input.attr('value') == _strings.search)
  520. $(this).attr('value', '');
  521. };
  522. function onInputKeypressed(event) {
  523. // this setTimeout just serve to retreive the juste added letter
  524. // without we always have a one char delay on the keypress event
  525. var $this = $(this);
  526. setTimeout(function(){ $this.trigger('valuechanged'); },1);
  527. };
  528. function filterFiltersList(event){
  529. console.log('filterFiltersList', event);
  530. var $input = $(this),
  531. value = $input.val(),
  532. filtersList = _filters[$input.attr('key')],
  533. $list = $input.siblings('.list'),
  534. regexpValue, filter;
  535. clearTimeout(filterInputTimer);
  536. // prevFilterInput
  537. if(value != ''){
  538. filterInputTimer = setTimeout(function(){
  539. console.log('value = '+value);
  540. regexpValue = new RegExp(value, 'i');
  541. for(key in filtersList){
  542. filter = filtersList[key];
  543. // console.log('filter', filter);
  544. if (filter.name.search(regexpValue) == -1){
  545. if(filter.visible){
  546. filter.visible = false;
  547. $('li.'+filter.tid, $list).height(0);//.slideUp();
  548. }
  549. }else if(!filter.visible){
  550. filter.visible = true;
  551. $('li.'+filter.tid, $list).height('auto');//.slideDown();
  552. }
  553. }
  554. // $list.jScrollPane();
  555. }, 500);
  556. }else{
  557. // $('li', $list).height('auto');
  558. for(key in filtersList){
  559. filter = filtersList[key];
  560. filter.visible = true;
  561. $('li.'+filter.tid, $list).height('auto');//.slideDown();
  562. }
  563. }
  564. };
  565. function onClickAddFilter(event){
  566. var $this = $(this);
  567. if(!$this.is('.selected')){
  568. var $clone = $('span', $this).clone(),
  569. tid = $clone.attr('class');
  570. $this
  571. .addClass('selected')
  572. .parents('.filter').find('.filters-selected')
  573. .append($clone);
  574. $clone.bind('click', onClickRemoveFilter );
  575. var click = jQuery.Event("click");
  576. click.dontfilterdate = true;
  577. $('.close-search','#search-block-form').trigger(click);
  578. _selected_filters.push(tid);
  579. filterOtherFilters();
  580. filterDates();
  581. checkFiltersHeight();
  582. }
  583. };
  584. function onClickRemoveFilter(event){
  585. if(!$('body').is('.layout-timeline'))
  586. return;
  587. console.log('onClickRemoveFilter', event);
  588. var $this = $(this),
  589. tid = $this.attr('class'),
  590. dontfilterdate = event.dontfilterdate || false;
  591. $this.parents('.filter').find('.filters-selection').find('li.'+tid).removeClass('selected');
  592. $this.remove();
  593. setTimeout(function(){
  594. array_remove(_selected_filters,tid);
  595. filterOtherFilters();
  596. checkFiltersHeight();
  597. if(!dontfilterdate)
  598. filterDates();
  599. },5);
  600. };
  601. function filterOtherFilters(){
  602. var active, classe;
  603. $('.filter .filters-selection li:not(.selected)').each(function(){
  604. active = true;
  605. classe = $(this).attr('class');
  606. if(_selected_filters.length){ // && array_indexOf(_selected_filters, classe) === -1
  607. for (var i = _selected_filters.length - 1; i >= 0; i--){
  608. if(array_indexOf(_filters_correspondances[_selected_filters[i]], classe) == -1){
  609. active = false;
  610. break;
  611. }
  612. };
  613. }
  614. if (!active) {
  615. $(this).height(0);
  616. }else{
  617. $(this).height('auto');
  618. }
  619. });
  620. }
  621. function checkFiltersHeight(){
  622. var h = 0;
  623. $('.filters-selected', '#filters').each(function(i, elmt){
  624. h = $(elmt).height() > h ? $(elmt).height() : h;
  625. });
  626. _$filters.css({marginBottom:(h+5)+'px'});
  627. };
  628. function resetFilters(fd){
  629. var click = jQuery.Event("click");
  630. click.dontfilterdate = true;
  631. console.log('resetFilters : click', click);
  632. $('#filters .filters-selected span').trigger(click);
  633. };
  634. /**
  635. * search
  636. */
  637. function initSearch(){
  638. $('#search-block-form').bind('submit', function(event) {
  639. // console.log('search submited', event);
  640. var $this = $(this);
  641. setTimeout(function(){
  642. var searched_keys = $this.find('input[name*="search_block_form"]').val()
  643. searchFormSubmit(searched_keys, $this);
  644. },10);
  645. return false;
  646. });
  647. };
  648. function searchFormSubmit(typed, $form){
  649. // console.log('searchFormSubmit | keys = '+keys);
  650. if(typed !== undefined && typed !== '' && typed.length >= 2){
  651. typed = typed.replace('/', ' ');
  652. $form.addClass('loading');
  653. // $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'perfart/search/',
  654. // {keys:keys},
  655. // function(json){
  656. // $form.removeClass('loading');
  657. // searchFiltreTimeline(json);
  658. // });
  659. $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'perfart/search_api/',
  660. {typed:typed},
  661. function(json){
  662. $form.removeClass('loading');
  663. console.log('json', json);
  664. searchFiltreTimeline(json);
  665. });
  666. }
  667. };
  668. function searchFiltreTimeline(json){
  669. console.log('searchFiltreTimeline | json', json);
  670. var nid;
  671. _dates = [];
  672. _dates_nids = [];
  673. for(var nid in json['results']){
  674. // nid = json['results'][ind];
  675. if(typeof _datas[nid] != 'undefined'){
  676. _dates.push(_datas[nid]);
  677. _dates_nids.push(nid);
  678. }
  679. }
  680. resetFilters(false);
  681. updateTimeline();
  682. if(!$('.container-inline .close-search', '#search-block-form').size()){
  683. $('.container-inline','#search-block-form').append($('<span class="close-search">').bind('click', resetSearch));
  684. }
  685. };
  686. function resetSearch(event){
  687. console.log('resetSearch')
  688. $(event.currentTarget).remove();
  689. var dontfilterdate = event.dontfilterdate || false;
  690. $('#search-block-form').find('input[name*="search_block_form"]').val('');
  691. if(dontfilterdate)
  692. return;
  693. _dates = [];
  694. _dates_nids = [];
  695. // console.log('_selected_filters', _selected_filters);
  696. for(nid in _datas){
  697. _dates.push(_datas[nid]);
  698. _dates_nids.push(nid);
  699. }
  700. updateTimeline();
  701. };
  702. /**
  703. * performance view
  704. */
  705. function loadPerformance(url){
  706. _$perfnode.addClass('loading').children('.node');
  707. $('.node-container .node', _$perfnode).hide();
  708. clearPerfNav();
  709. switchLayout('perfnode');
  710. // if(url.indexOf("/") === 0){
  711. url = url.replace(/^\//, '');
  712. // }
  713. url = _drupalBasePath + url;
  714. $.getJSON(url,
  715. function(json){
  716. // console.log('json', json);
  717. showPerformance(json);
  718. History.pushState({json:json, ajaxpath:url}, _datas[json.nid].perf_title+' | '+_strings.site_name, _drupalBasePath + _datas[json.nid].node_link);
  719. updateTranslationLink(_datas[json.nid].node_translation);
  720. });
  721. };
  722. function updateTranslationLink(p){
  723. if(!updateTranslationLink.homeTranslationLink){
  724. updateTranslationLink.homeTranslationLink = $('.language-switcher-locale-url li:not(.active) a').attr('href');
  725. }
  726. var href = p ? Drupal.settings.basePath + p : updateTranslationLink.homeTranslationLink;
  727. $('.language-switcher-locale-url li:not(.active) a').attr('href', href);
  728. }
  729. function showPerformance(data){
  730. // console.log('showPerformance', data);
  731. zoomToDate(data.nid);
  732. var $node_container = $('.node-container', _$perfnode);
  733. // $('>*', $node_container).remove();
  734. // $node_container.empty();
  735. _$perfnode.removeClass('loading');
  736. $node_container.find('.scroller').html(data.node_view)
  737. .children('.node').children().addClass('grid-block');
  738. _randomizeImageSizes($('.scroller>.node', $node_container));
  739. $('.node .node-title', $node_container).after($('.node figure.grid_large', $node_container));
  740. $('.node .field-type-textauthor', $node_container).children('.field-item').jScrollPane();
  741. _initPaScPlayer($node_container);
  742. $node_container.bind('grid_ready', onGridReady);
  743. _grid = new Grid($node_container, {
  744. cell_w:50,
  745. cell_h:50,
  746. // lines:Math.ceil($node_container.height())/100,
  747. // columns:Math.ceil($node_container.width())/100,
  748. padding:{t:0,r:0,b:0,l:0},
  749. gouttiere: 5,
  750. grille: false,
  751. decalage: false,
  752. latitude: 0,
  753. augmentable:true
  754. });
  755. protectImages($node_container);
  756. setPerfNav(data.nid);
  757. _current_nid = data.nid;
  758. };
  759. function _randomizeImageSizes($container){
  760. array_randomize($container.children('figure')).each(function(index) {
  761. _setImageSize(this, true, index);
  762. });
  763. array_randomize($container.children().find('figure')).each(function(index) {
  764. _setImageSize(this);
  765. });
  766. };
  767. function _setImageSize(figure, c, index){
  768. var children = c || false,
  769. style, $remain_img;
  770. $('img:not([path])', figure).each(function(){
  771. $(this).attr('path', $(this).attr('src'));
  772. });
  773. $('img', figure).attr('src', '');
  774. if(children){
  775. if(index == 0){ style = 'grid_large';
  776. }else if (index < 5){ style = 'grid_medium';
  777. }else{ style = 'grid_small'; }
  778. }else{
  779. style = 'grid_medium';
  780. }
  781. $remain_img = $('img.'+style, figure);
  782. $remain_img.attr('src', $remain_img.attr('path'));
  783. $(figure).css({
  784. 'width':$remain_img.attr('width'),
  785. 'height':$remain_img.attr('height')
  786. })
  787. .addClass(style);
  788. $('img:not(.blank,.'+style+')', figure).remove();
  789. };
  790. function protectImages($container){
  791. $('figure', $container)
  792. // .append('<img class="blank" src="/'+Drupal.settings.perfarttimeline.theme_path+'/images/blank.gif" />')
  793. .bind("contextmenu", function(e){ alert("Cette image est soumise au droit d'auteur."); return false; })
  794. .addClass('protected');
  795. };
  796. function onGridReady(event){
  797. //console.log('onGridReady', event);
  798. // var $node_container = $('.node-container', _$perfnode);
  799. //console.log('grid max width = '+event.grid.maxwidth+' | grid max height = '+event.grid.maxheight);
  800. // _perf_jsp.destroy();
  801. $('.node-container',_$perfnode).find('.scroller').height(event.grid.maxheight);
  802. if(!_perf_jsp){
  803. var pane = $('.node-container',_$perfnode).jScrollPane({
  804. verticalGutter:5,
  805. autoReinitialise:true
  806. });
  807. _perf_jsp = pane.data('jsp');
  808. }
  809. };
  810. function clearPerfNav(){
  811. _$prev_perf.attr('url', '');
  812. _$next_perf.attr('url', '');
  813. };
  814. function setPerfNav(nid){
  815. // console.log('nid = '+nid);
  816. var index = array_indexOf(_dates_nids, nid);
  817. if(typeof _dates_nids[index-1] != 'undefined'){
  818. _$prev_perf.attr('url', _datas[_dates_nids[index-1]].ajax_link).show();
  819. }else{
  820. _$prev_perf.hide();
  821. }
  822. if(typeof _dates_nids[index+1] != 'undefined'){
  823. _$next_perf.attr('url', _datas[_dates_nids[index+1]].ajax_link).show();
  824. }else{
  825. _$next_perf.hide();
  826. }
  827. };
  828. function onClickBtnNavPerf(event){
  829. var url = $(this).attr('url');
  830. if(url != '')
  831. loadPerformance(url);
  832. };
  833. function nextPerf(){
  834. if(_current_nid){
  835. var index = array_indexOf(_dates_nids, _current_nid);
  836. // console.log('index = '+index);
  837. loadPerformance(_datas[_dates_nids[index+1]].ajax_link);
  838. }
  839. };
  840. function prevPerf(){
  841. if(_current_nid){
  842. var index = array_indexOf(_dates_nids,_current_nid);
  843. // console.log('index = '+index);
  844. loadPerformance(_datas[_dates_nids[index-1]].ajax_link);
  845. }
  846. };
  847. /**
  848. * layout
  849. */
  850. function switchLayout(mode){
  851. //console.log('switchLayout | mode '+mode);
  852. // if(mode != 'timeline'){
  853. // // _timeline.deleteAllItems();
  854. // }else{
  855. // // updateTimeline();
  856. // }
  857. for (key in _layouts)
  858. $('body').removeClass(_layouts[key]);
  859. $('body').addClass(_layouts[mode]);
  860. };
  861. /**
  862. * Grid()
  863. */
  864. function Grid($f, settings){
  865. var _defaults = {
  866. padding:{t:20,r:25,b:20,l:25},
  867. gouttiere: 20,
  868. cell_w: 155,
  869. cell_h: 50,
  870. lines: 0,
  871. columns: 0,
  872. grille: false,
  873. decalage: false,
  874. latitude: 50,
  875. augmentable:false
  876. },
  877. $fiche = $f,
  878. _cells = new Array(),
  879. _positions = new Array(),
  880. _thisgrid = this,
  881. _prePlacedBlocks = 0,
  882. _placedBlocks = 0,
  883. _allBlocks = 0,
  884. _grilleInterval;
  885. this.fiche = $fiche;
  886. this.settings = $.extend({}, _defaults, settings);
  887. this.settings.lines = Math.floor(($f.height() - this.settings.padding.t - this.settings.padding.b) / (this.settings.cell_h + this.settings.gouttiere));
  888. this.settings.columns = Math.floor(($f.width() - - this.settings.padding.r - this.settings.padding.l) / (this.settings.cell_w + this.settings.gouttiere));
  889. this.maxheight = this.maxwidth = 0;
  890. // console.log('w = '+$f.width()+' | h = '+$f.height());
  891. // console.log('lines = '+this.settings.lines+' | columns = '+this.settings.columns);
  892. if (this.settings.grille) {
  893. $fiche.append('<div class="grille"><div>');
  894. $('.grille', $fiche).css({
  895. 'width': '100%',
  896. 'height': '100%',
  897. 'position': 'relative'
  898. });
  899. }
  900. for (var l = 0; l < this.settings.lines; l++) {
  901. _cells[l] = new Array();
  902. for (var c = 0; c < this.settings.columns; c++) {
  903. _cells[l][c] = new Cell(this, c, l);
  904. };
  905. };
  906. _allBlocks = $('.grid-block', $fiche).length;
  907. if (this.settings.grille) {
  908. _grilleInterval = setInterval(function(){
  909. if(_prePlacedBlocks < _allBlocks){
  910. _placeBlock($('.grid-block', $fiche).eq(_prePlacedBlocks));
  911. _prePlacedBlocks ++;
  912. }else{
  913. clearInterval(_grilleInterval);
  914. }
  915. },1000);
  916. }else{
  917. $('.grid-block', $fiche).each(function() {
  918. // _allBlocks++;
  919. _placeBlock(this);
  920. });
  921. }
  922. function _block_placed(){
  923. // console.log('_block_placed _allBlocks = '+_allBlocks+' _placedBlocks = '+_placedBlocks)
  924. _placedBlocks++;
  925. if(_placedBlocks == _allBlocks){
  926. var event = jQuery.Event('grid_ready');
  927. event.grid = _thisgrid;
  928. $fiche.trigger(event);
  929. }
  930. }
  931. /**
  932. *
  933. */
  934. function _placeBlock(_this){
  935. //console.log('_placeBlock', _this);
  936. var $this = $(_this),
  937. this_cells_w = 0,
  938. this_cells_h = 0,
  939. free_cells = [];
  940. // if($this.hasClass('image')){
  941. // var sizes = [155, 330, 505],
  942. // i = sizes.length,
  943. // $img = $('img', $this),
  944. // $legende = $('.legende', $this);
  945. //
  946. // while(free_cells.length == 0 && i > 0){
  947. // i--;
  948. // $img.width(sizes[i]);
  949. // $this.width(sizes[i]+$legende.outerWidth()+2);
  950. // this_cells_w = Math.ceil($this.width() / (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere)),
  951. // this_cells_h = Math.ceil($this.height() / (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere));
  952. // free_cells = getFreeCells(this_cells_w, this_cells_h);
  953. // }
  954. // }else{
  955. this_cells_w = Math.ceil($this.width() / (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere)),
  956. this_cells_h = Math.ceil($this.height() / (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere));
  957. free_cells = getFreeCells(this_cells_w, this_cells_h);
  958. // }
  959. if(free_cells.length > 0){
  960. // var cell_num = Math.round(Math.random() * (free_cells.length - 1));
  961. // var cell_num = 0;
  962. var cell_num = Math.floor((free_cells.length-1)*0.5 + (-2+Math.random()*4));
  963. cell_num = cell_num > free_cells.length-1 ? free_cells.length-1 : ( cell_num < 0 ? 0 : cell_num );
  964. var cell = free_cells[cell_num],
  965. line_limit_loop = cell.getPos().l + (this_cells_h),
  966. column_limit_loop = cell.getPos().c + (this_cells_w);
  967. for (var l = cell.getPos().l; l < line_limit_loop; l++) {
  968. for (var c = cell.getPos().c; c < column_limit_loop; c++) {
  969. var temp_cell = _cells[l][c];
  970. temp_cell.setFull();
  971. };
  972. };
  973. var top = cell.getPos().l * (_thisgrid.settings.cell_h + _thisgrid.settings.gouttiere),
  974. left = cell.getPos().c * (_thisgrid.settings.cell_w + _thisgrid.settings.gouttiere),
  975. latitude = _thisgrid.settings.latitude;
  976. top = !_thisgrid.settings.decalage ? top: top + Math.round(Math.random() * latitude - latitude / 2)
  977. left = !_thisgrid.settings.decalage ? left: left + Math.round(Math.random() * latitude - latitude / 2);
  978. $this.css({
  979. 'top': top+_thisgrid.settings.padding.t,
  980. 'left': left+_thisgrid.settings.padding.l
  981. });
  982. _thisgrid.maxheight = Math.max(top+_thisgrid.settings.padding.t+$this.height(), _thisgrid.maxheight);
  983. _thisgrid.maxwidth = Math.max(left+_thisgrid.settings.padding.l+$this.width(), _thisgrid.maxwidth);
  984. _block_placed();
  985. } else {
  986. if(!_thisgrid.settings.augmentable){
  987. $this.css({
  988. 'border': '2px solid red',
  989. 'opacity': 0.2
  990. }).remove();
  991. _block_placed();
  992. }else{
  993. _augmenteGrid();
  994. //console.log('re placeblock');
  995. _placeBlock(_this);
  996. }
  997. }
  998. }
  999. function _augmenteGrid(){
  1000. // for (var l = 0; l < this.settings.lines; l++) {
  1001. var l = _thisgrid.settings.lines ;
  1002. _thisgrid.settings.lines ++;
  1003. _cells[l] = new Array();
  1004. for (var c = 0; c < _thisgrid.settings.columns; c++) {
  1005. _cells[l][c] = new Cell(_thisgrid, c, l);
  1006. };
  1007. // };
  1008. _refreshCells();
  1009. // console.log('lines = '+_thisgrid.settings.lines+' | columns = '+_thisgrid.settings.columns);
  1010. };
  1011. function _refreshCells(){
  1012. for (var l = _thisgrid.settings.lines-1; l >= 0 ; l--) {
  1013. for (var c = _thisgrid.settings.columns-1; c >= 0 ; c--) {
  1014. _cells[l][c].refresh();
  1015. }
  1016. }
  1017. }
  1018. /**
  1019. * getFreeCells()
  1020. */
  1021. function getFreeCells(this_cells_w, this_cells_h){
  1022. var free_cells = new Array();
  1023. for (var l = 0; l < _thisgrid.settings.lines; l++) {
  1024. for (var c = 0; c < _thisgrid.settings.columns; c++) {
  1025. var cell = _cells[l][c];
  1026. if (cell.isFree() && (cell.getAround().right + 1) >= this_cells_w && (cell.getAround().bottom + 1) >= this_cells_h) {
  1027. var good = true;
  1028. for (var i = 1; i < this_cells_w; i++) {
  1029. var temp_cell = _cells[l][c + i];
  1030. if ((temp_cell.getAround().bottom + 1) < this_cells_h) {
  1031. good = false;
  1032. break;
  1033. }
  1034. };
  1035. if (good) free_cells.push(cell);
  1036. }
  1037. };
  1038. };
  1039. return free_cells;
  1040. }
  1041. /**
  1042. * Cell()
  1043. */
  1044. function Cell(g, c, l) {
  1045. var _g = g,
  1046. _column = c,
  1047. _line = l,
  1048. _free = true,
  1049. _free_cell_right = _g.settings.columns - 1 - c,
  1050. _free_cell_bottom = _g.settings.lines - 1 - l;
  1051. if (_g.settings.grille) {
  1052. var _table = '<table>';
  1053. _table += '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  1054. // _table += '<tr><td>&nbsp;</td><td class="state">'+_free+'</td><td class="fr">'+_free_cell_right+'</td></tr>';
  1055. _table += '<tr><td>&nbsp;</td><td>&nbsp;</td><td class="fr">' + _free_cell_right + '</td></tr>';
  1056. _table += '<tr><td>&nbsp;</td><td class="fb">' + _free_cell_bottom + '</td><td>&nbsp;</td></tr>';
  1057. _table += '</table>';
  1058. _g.fiche.find('.grille').append('<div class="cell-' + l + '-' + c + '">' + _table + '<div>');
  1059. var _dom = $('.cell-' + l + '-' + c, _g.fiche.find('.grille'));
  1060. _dom.css({
  1061. 'position': 'absolute',
  1062. 'top': _line * (_g.settings.cell_h + _g.settings.gouttiere) + _g.settings.padding.t,
  1063. 'left': _column * (_g.settings.cell_w + _g.settings.gouttiere) + _g.settings.padding.l,
  1064. 'width': _g.settings.cell_w,
  1065. 'height': _g.settings.cell_h,
  1066. 'backgroundColor': '#00FF00',
  1067. 'opacity': 0.6
  1068. }).find('table').css({
  1069. width:'100%',
  1070. height:'100%'
  1071. }).find('td').css({width:"30%"});
  1072. // $('td', _dom).css({
  1073. // 'fontSize': '8px'
  1074. // });
  1075. }
  1076. this.isFree = function() {
  1077. return _free;
  1078. };
  1079. this.getPos = function() {
  1080. return {
  1081. c: _column,
  1082. l: _line
  1083. };
  1084. };
  1085. this.getAround = function() {
  1086. return {
  1087. right: _free_cell_right,
  1088. bottom: _free_cell_bottom
  1089. };
  1090. };
  1091. this.setFull = function() {
  1092. _free = false;
  1093. _free_cell_bottom = -1;
  1094. _free_cell_right = -1;
  1095. if (_g.settings.grille) {
  1096. _dom.css({
  1097. 'backgroundColor': '#0000FF'
  1098. });
  1099. $('.fb', _dom).html(_free_cell_bottom);
  1100. $('.fr', _dom).html(_free_cell_right);
  1101. }
  1102. _propageFreeCells();
  1103. };
  1104. this.setFreeCellsRight = function(right) {
  1105. if (_free) {
  1106. // console.log('_setFreeCellRigth | _free_cell_right = ' + _free_cell_right + ' | new right = ' + right);
  1107. _free_cell_right = right;
  1108. if (_g.settings.grille) $('.fr', _dom).html(_free_cell_right);
  1109. _propageFreeCellsLeft();
  1110. }
  1111. };
  1112. this.setFreeCellsBottom = function(bottom) {
  1113. if (_free) {
  1114. // console.log('_setFreeCellsBottom | _free_cell_bottom = ' + _free_cell_bottom + ' | new right = ' + bottom);
  1115. _free_cell_bottom = bottom;
  1116. if (_g.settings.grille) $('.fb', _dom).html(_free_cell_bottom);
  1117. _propageFreeCellsTop();
  1118. }
  1119. };
  1120. this.refresh = function(){
  1121. if(_free)
  1122. _propageFreeCellsTop();
  1123. };
  1124. function _propageFreeCells() {
  1125. // console.log('_propageFreeCells');
  1126. _propageFreeCellsLeft();
  1127. _propageFreeCellsTop();
  1128. };
  1129. function _propageFreeCellsLeft() {
  1130. // console.log('_propageFreeCellsLeft | _column = '+_column);
  1131. if (_column > 0) {
  1132. var left_cel = _cells[_line][_column - 1];
  1133. left_cel.setFreeCellsRight(_free_cell_right + 1);
  1134. }
  1135. };
  1136. function _propageFreeCellsTop() {
  1137. // console.log('_propageFreeCellsTop | _line = '+_line);
  1138. if (_line > 0) {
  1139. var top_cel = _cells[_line - 1][_column];
  1140. top_cel.setFreeCellsBottom(_free_cell_bottom + 1);
  1141. }
  1142. };
  1143. if (typeof Cell.initialized == "undefined") {
  1144. Cell.prototype.infos = function() {
  1145. //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);
  1146. };
  1147. Cell.initialized = true;
  1148. }
  1149. }; // cell()
  1150. this.clear = function(){
  1151. $('.grille', $fiche).fadeOut(200, function() {
  1152. $(this).remove();
  1153. });
  1154. }
  1155. }; // GRIB
  1156. /**
  1157. * on resize
  1158. */
  1159. // debulked onresize handler
  1160. function on_resize(c,t){onresize=function(){clearTimeout(t);t=setTimeout(c,100)};return c};
  1161. on_resize(function() { if(typeof _timeline != 'undefined') _timeline.redraw(); });
  1162. /**
  1163. * cookies
  1164. */
  1165. function createCookie(name,value,days) {
  1166. if (days) {
  1167. var date = new Date();
  1168. date.setTime(date.getTime()+(days*24*60*60*1000));
  1169. var expires = "; expires="+date.toGMTString();
  1170. }
  1171. else var expires = "";
  1172. document.cookie = name+"="+value+expires+"; path=/";
  1173. }
  1174. function readCookie(name) {
  1175. var nameEQ = name + "=";
  1176. var ca = document.cookie.split(';');
  1177. for(var i=0;i < ca.length;i++) {
  1178. var c = ca[i];
  1179. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  1180. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  1181. }
  1182. return null;
  1183. }
  1184. function eraseCookie(name) {
  1185. createCookie(name,"",-1);
  1186. }
  1187. /**
  1188. * init
  1189. */
  1190. init();
  1191. }
  1192. function _initPaScPlayer($container, ap){
  1193. var $container = $container || $('body');
  1194. var ap = ap || false;
  1195. // console.log('_initPaScPlayer');
  1196. // $.paScPlayer.stopAll();
  1197. // var $links = $('a[rel="soundcloud"]', $container);
  1198. // // // console.log('$links', $links);
  1199. // if($links.size()){
  1200. // // $links.parents('.field-item').find('span.ext').remove();
  1201. // // $links.paScPlayer({autoplay:ap});
  1202. // /* add players for each link */
  1203. // for ( var i = 0; i < $links.length; i++ ) {
  1204. // $links[i].parentNode.replaceChild(
  1205. // SCPurePlayer.create($links[i]), $links[i]
  1206. // );
  1207. // }
  1208. // }
  1209. }
  1210. _initPaScPlayer();
  1211. };
  1212. $.fn.verticalcenter = function(){
  1213. return this.each(function(index) {
  1214. $(this).css({
  1215. "margin-top": ($(this).parent().height() - $(this).height()) / 2
  1216. });
  1217. });
  1218. };
  1219. $.fn.innerheight = function(){
  1220. var h = 0;
  1221. this.chlidren().each(function(index) {
  1222. h = h + $(this).height() + parseInt($(this).css('margin-top')) + parseInt($(this).css('margin-bottom')) + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom'))
  1223. });
  1224. return h;
  1225. };
  1226. })(jQuery);
  1227. /** HELPERS */
  1228. /**
  1229. * returned value: (Array)
  1230. */
  1231. array_remove= function(ar){
  1232. var what, a= arguments, L= a.length, ax;
  1233. while(L && ar.length){
  1234. what= a[--L];
  1235. while((ax= ar.indexOf(what))!= -1){
  1236. ar.splice(ax, 1);
  1237. }
  1238. }
  1239. return ar;
  1240. };
  1241. array_indexOf = function(ar, what, i){
  1242. i= i || 0;
  1243. var L= ar.length;
  1244. while(i< L){
  1245. if(ar[i]=== what) return i;
  1246. ++i;
  1247. }
  1248. return -1;
  1249. };
  1250. array_randomize = function(arr) {
  1251. for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
  1252. return arr;
  1253. };
  1254. function objectIsEmpty(obj){
  1255. for (var prop in obj) {
  1256. if (obj.hasOwnProperty(prop))
  1257. return false;
  1258. };
  1259. return true;
  1260. }
  1261. 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"};
  1262. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  1263. String.prototype.latinize=String.prototype.latinise;
  1264. String.prototype.isLatin=function(){return this==this.latinise()}