script.js 53 KB

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