script.js 54 KB

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