Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

687 lines
25KB

  1. /**
  2. Copyright La boîte à pain (2018)
  3. contact@laboiteapain.net
  4. Ce logiciel est un programme informatique servant à aider les producteurs
  5. à distribuer leur production en circuits courts.
  6. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  7. respectant les principes de diffusion des logiciels libres. Vous pouvez
  8. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  9. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  10. sur le site "http://www.cecill.info".
  11. En contrepartie de l'accessibilité au code source et des droits de copie,
  12. de modification et de redistribution accordés par cette licence, il n'est
  13. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  14. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  15. titulaire des droits patrimoniaux et les concédants successifs.
  16. A cet égard l'attention de l'utilisateur est attirée sur les risques
  17. associés au chargement, à l'utilisation, à la modification et/ou au
  18. développement et à la reproduction du logiciel par l'utilisateur étant
  19. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  20. manipuler et qui le réserve donc à des développeurs et des professionnels
  21. avertis possédant des connaissances informatiques approfondies. Les
  22. utilisateurs sont donc invités à charger et tester l'adéquation du
  23. logiciel à leurs besoins dans des conditions permettant d'assurer la
  24. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  25. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  26. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  27. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  28. termes.
  29. */
  30. /* French initialisation for the jQuery UI date picker plugin. */
  31. /* Written by Keith Wood (kbwood{at}iinet.com.au),
  32. Stéphane Nahmani (sholby@sholby.net),
  33. Stéphane Raimbault <stephane.raimbault@gmail.com> */
  34. (function( factory ) {
  35. if ( typeof define === "function" && define.amd ) {
  36. // AMD. Register as an anonymous module.
  37. define([ "../jquery.ui.datepicker" ], factory );
  38. } else {
  39. // Browser globals
  40. factory( jQuery.datepicker );
  41. }
  42. }(function( datepicker ) {
  43. datepicker.regional['fr'] = {
  44. closeText: 'Fermer',
  45. prevText: 'Précédent',
  46. nextText: 'Suivant',
  47. currentText: 'Aujourd\'hui',
  48. monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
  49. 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
  50. monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
  51. 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
  52. dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  53. dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
  54. dayNamesMin: ['D','L','M','M','J','V','S'],
  55. weekHeader: 'Sem.',
  56. dateFormat: 'dd/mm/yy',
  57. firstDay: 1,
  58. isRTL: false,
  59. showMonthAfterYear: false,
  60. yearSuffix: ''};
  61. datepicker.setDefaults(datepicker.regional['fr']);
  62. return datepicker.regional['fr'];
  63. }));
  64. $(document).ready(function() {
  65. $('[data-toggle="tooltip"]').tooltip() ;
  66. chat_systeme_commande() ;
  67. chat_profil_user() ;
  68. $('.dropdown-toggle').dropdown() ;
  69. chat_datepicker() ;
  70. }) ;
  71. function chat_datepicker() {
  72. $('input.datepicker').datepicker({dateFormat:'dd/mm/yy'}) ;
  73. }
  74. function chat_profil_user() {
  75. if($('#profil-user').size()) {
  76. if($('#user-no_mail').is(':checked')) {
  77. $('#mails-jours-prod').hide() ;
  78. }
  79. $('#user-no_mail').change(function() {
  80. if($('#user-no_mail').is(':checked')) {
  81. $('#mails-jours-prod').hide() ;
  82. }
  83. else {
  84. $('#mails-jours-prod').fadeIn() ;
  85. }
  86. }) ;
  87. }
  88. }
  89. function chat_event_click_point_vente(id, force) {
  90. if($('.point-sale-'+id).data('code') == 1) {
  91. $('#modal-code #id-point-sale').val(id) ;
  92. $('#modal-code').modal('show') ;
  93. }
  94. else {
  95. $('#order-id_point_sale').val(id) ;
  96. $('#points-sale .point-sale').removeClass('selected') ;
  97. $('.point-sale-'+id).addClass('selected') ;
  98. $('.point-sale-'+id).hide().fadeIn('fast') ;
  99. var pain = parseInt($('.point-sale-'+id).data('pain')) ;
  100. var vrac = parseInt($('.point-sale-'+id).data('vrac')) ;
  101. if(pain) {
  102. $('#pain .table').show() ;
  103. $('#pain .indisponible').hide() ;
  104. }
  105. else {
  106. $('#pain .table').hide() ;
  107. $('#pain .indisponible').show() ;
  108. }
  109. if(vrac) {
  110. $('#vrac .table').show() ;
  111. $('#vrac .indisponible').hide() ;
  112. }
  113. else {
  114. $('#vrac .table').hide() ;
  115. $('#vrac .indisponible').show() ;
  116. }
  117. $('#products, #step-infos-point-sale, .confirm-order, .btn-comment, #bar-fixed').fadeIn() ;
  118. // credit pain
  119. chat_systeme_commande_credit_pain_event(chat_systeme_commande_maj_table_prix()) ;
  120. // scroll
  121. if(!force) {
  122. boulange_scroll('step-infos-point-sale') ;
  123. }
  124. // infos point de vente
  125. $('.infos-point-sale').hide() ;
  126. $('.infos-point-sale-'+id).fadeIn() ;
  127. }
  128. }
  129. function chat_init_horaire_point_vente(date) {
  130. $('.infos-point-sale .jour').hide() ;
  131. var selector_jour = '.infos-point-sale .jour-'+date.getDay() ;
  132. $(selector_jour).show() ;
  133. $('.select-previous-day').unbind('click').click(function() {
  134. $('.ui-datepicker-current-day').prev().find('a').click() ;
  135. }) ;
  136. }
  137. function chat_base_url(with_slug) {
  138. var base_url = $('meta[name=base-url]').attr('content')+'/' ;
  139. if(with_slug) {
  140. base_url += $('meta[name=slug-producer]').attr('content')+'/' ;
  141. }
  142. return base_url ;
  143. }
  144. function chat_systeme_commande() {
  145. if($('.order-form').size()) {
  146. // scroll initial
  147. if($('.producer.selected').size())
  148. {
  149. boulange_scroll('step-date') ;
  150. }
  151. // affichage des différentes parties du formulaire
  152. if(!$('#order-id_distribution').val()) {
  153. $('#block-points-sale, #step-infos-point-sale, #points-sale, #products, .confirm-order, .btn-comment, #bar-fixed').hide() ;
  154. }
  155. else if(!$('#commande-id_point_vente').val()) {
  156. $('#products, .confirm-order, .btn-comment, #bar-fixed, #has-order-in-progress').hide() ;
  157. }
  158. // points de vente
  159. if($('#order-id_point_sale').val()) {
  160. chat_event_click_point_vente($('#order-id_point_sale').val(), true) ;
  161. }
  162. $('#modal-code form').submit(function() {
  163. var id_pv = $('#modal-code #id-point-sale').val() ;
  164. var code = $('#modal-code #code').val() ;
  165. $.get(chat_base_url(true)+'order/validate-code-point-sale',{
  166. idPointSale: id_pv,
  167. code: code
  168. }, function(ok) {
  169. if(ok) {
  170. $('.point-sale-'+id_pv).data('code',0) ;
  171. $('.point-sale-'+id_pv+' .glyphicon').remove() ;
  172. $('input[name="code_point_sale_'+id_pv+'"]').val(code) ;
  173. $('#modal-code').modal('hide') ;
  174. chat_event_click_point_vente($('#modal-code #id-point-sale').val()) ;
  175. }
  176. else {
  177. $('#modal-code .field-code').addClass('has-error') ;
  178. $('#modal-code .help-block-error').hide().fadeIn() ;
  179. }
  180. }) ;
  181. return false ;
  182. }) ;
  183. $('#points-sale .point-sale').click(function() {
  184. var id = parseInt($(this).find('.id').html()) ;
  185. chat_event_click_point_vente(id) ;
  186. }) ;
  187. // datepicker
  188. var dates_production = [] ;
  189. $('#dates div').each(function() {
  190. dates_production.push($(this).find('.date').html()) ;
  191. }) ;
  192. //var var_datepicker = $.datepicker ;
  193. $('#datepicker-distribution').datepicker({
  194. beforeShowDay: function(date){
  195. var string = $.datepicker.formatDate('dd/mm/yy', date);
  196. for(var i=0; i<dates_production.length; i++) {
  197. //alert(dates_production[i]+' '+string) ;
  198. if(dates_production[i] == string)
  199. return [1] ;
  200. }
  201. return [0] ;
  202. // désactivé car internet explorer plante
  203. //return [ dates_production.indexOf(string) != -1 ] ;
  204. },
  205. onSelect: function(selectedDate) {
  206. $('.infos-points-sale').hide() ;
  207. // on remet tout les prix à zéro
  208. chat_systeme_commande_reset_table_prix() ;
  209. $('#has-order-in-progress').hide() ;
  210. var tab_date = selectedDate.split('/') ;
  211. var date = new Date(tab_date[2],tab_date[1]-1,tab_date[0]) ;
  212. // set id production
  213. var id_production = 0 ;
  214. $('#dates div .date').each(function() {
  215. if($(this).html() == selectedDate) {
  216. id_production = $(this).parent().find('.id_distribution').html() ;
  217. }
  218. });
  219. $('#order-id_distribution').val(id_production) ;
  220. // verif si le gars a une commande en cours pour cette production
  221. var has_commande_en_cours = false ;
  222. $('#orders-in-progress .order').each(function() {
  223. if($(this).data('iddistribution') == id_production) {
  224. //alert('bada') ;
  225. $('#has-order-in-progress a').attr('href',$(this).data('href')) ;
  226. $('#has-order-in-progress').show() ;
  227. has_commande_en_cours = true ;
  228. $('#block-points-sale, #step-infos-point-sale, #points-sale, #products, #bar-fixed').hide() ;
  229. }
  230. }) ;
  231. if(!has_commande_en_cours) {
  232. chat_systeme_commande_produits_dispos(tab_date[2]+'-'+tab_date[1]+'-'+tab_date[0], date) ;
  233. $('#products, .confirm-order, .btn-comment, #bar-fixed').hide() ;
  234. // déselection points de vente
  235. $('#points-sale .point-sale').removeClass('selected') ;
  236. $('#order-id_point_sale').val('') ;
  237. // affichage points de vente
  238. $('#block-points-sale, #points-sale, #order-infos').fadeIn() ;
  239. // scroll
  240. boulange_scroll('step-point-sale') ;
  241. }
  242. }
  243. }) ;
  244. if($('#order-id_distribution').val()) {
  245. $("#dates .id_distribution").each(function() {
  246. if($(this).html() == $('#order-id_distribution').val()) {
  247. var tab_date = $(this).parent().find('.date').html().split('/') ;
  248. var date = new Date(tab_date[2],tab_date[1]-1,tab_date[0]);
  249. $('#datepicker-distribution').datepicker('setDate',date) ;
  250. chat_systeme_commande_produits_dispos(tab_date[2]+'-'+tab_date[1]+'-'+tab_date[0], date) ;
  251. chat_init_horaire_point_vente(date) ;
  252. }
  253. }) ;
  254. }
  255. // tableau produits
  256. $('.order-form .move-quantity').click(function() {
  257. var vrac = ($(this).parent().parent().parent().parent().parent().parent().parent().attr('id') == 'vrac') ;
  258. if(vrac) {
  259. var quantite = parseInt($(this).parent().parent().find('input.quantity').val()) ;
  260. if($(this).hasClass('minus') && quantite != 0)
  261. quantite -= 500 ;
  262. if($(this).hasClass('plus'))
  263. quantite += 500 ;
  264. $(this).parent().parent().find('input.quantity').val(quantite) ;
  265. chat_systeme_commande_maj_table_prix();
  266. }
  267. else {
  268. var quantite_totale = 0 ;
  269. $('.quantity').each(function() {
  270. quantite_totale += parseInt($(this).val()) ;
  271. }) ;
  272. var quantite = parseInt($(this).parent().parent().find('input.quantity').val()) ;
  273. var quantite_restante = parseInt($(this).parent().parent().parent().find('.quantity-remaining .nb').html()) ;
  274. var quantite_max = $(this).parent().parent().parent().parent().data('quantity-max') ;
  275. var no_limit = $(this).parent().parent().parent().parent().data('no-limit') ;
  276. if($(this).hasClass('minus') && quantite != 0) {
  277. quantite -- ;
  278. quantite_restante ++ ;
  279. }
  280. if($(this).hasClass('plus') ){
  281. if(quantite_restante > 0 || no_limit) {
  282. quantite ++ ;
  283. quantite_restante -- ;
  284. }
  285. }
  286. $(this).parent().parent().parent().find('.quantity-remaining .nb').html(quantite_restante) ;
  287. if(quantite_restante <= 5 && quantite_restante > 0) {
  288. $(this).parent().parent().parent().find('.quantity-remaining').fadeIn() ;
  289. }
  290. else {
  291. $(this).parent().parent().parent().find('.quantity-remaining').hide() ;
  292. }
  293. if(quantite_restante == 0 && !no_limit) {
  294. $(this).parent().parent().parent().find('.unavailable').fadeIn() ;
  295. }
  296. else {
  297. $(this).parent().parent().parent().find('.unavailable').hide() ;
  298. }
  299. $(this).parent().parent().find('input.quantity').val(quantite) ;
  300. chat_systeme_commande_maj_table_prix();
  301. }
  302. }) ;
  303. chat_systeme_commande_maj_table_prix() ;
  304. chat_systeme_commande_credit_pain();
  305. }
  306. // commentaire commande
  307. $('.order-form .btn-comment').click(function() {
  308. if($('.field-order-comment').css('display') == 'none') {
  309. $('.field-order-comment').slideDown() ;
  310. }
  311. else {
  312. $('.field-order-comment').slideUp() ;
  313. }
  314. return false ;
  315. }) ;
  316. // bar fixed
  317. if($('#bar-fixed').size()) {
  318. $(window).scroll(function (event) {
  319. var scroll = $(window).scrollTop() + $(window).height();
  320. var pos_bottom_produits = $('#table-products').offset().top + $('#table-products').height() + 100 ;
  321. if($(window).height() < 700) {
  322. if(!$('#bar-fixed').hasClass('not-fixed')) {
  323. $('#bar-fixed').addClass('not-fixed') ;
  324. }
  325. }
  326. else {
  327. if(scroll > pos_bottom_produits) {
  328. if(!$('#bar-fixed').hasClass('not-fixed')) {
  329. $('#bar-fixed').addClass('not-fixed') ;
  330. }
  331. }
  332. else {
  333. $('#bar-fixed').removeClass('not-fixed') ;
  334. }
  335. }
  336. });
  337. }
  338. }
  339. function chat_systeme_commande_produits_dispos(str_date, date) {
  340. // produits dispos à la vente à cette date
  341. $.get(chat_base_url(true)+'order/infos-distribution',{
  342. idDistribution: $('#order-id_distribution').val()
  343. }, function(data) {
  344. if(data.products) {
  345. $.each(data.products, function( id_produit, produit ) {
  346. if(produit.active) $('.product-'+id_produit).show() ;
  347. else $('.product-'+id_produit).hide() ;
  348. var quantite_restante = produit.quantity_max - produit.quantity_order ;
  349. var no_limit = 0 ;
  350. if(!produit.quantity_max)
  351. no_limit = 1 ;
  352. $('.product-'+id_produit).attr('data-no-limit',no_limit) ;
  353. $('.product-'+id_produit).attr('data-quantity-max',produit.quantity_max) ;
  354. $('.product-'+id_produit+' .quantity-remaining .nb').html(quantite_restante) ;
  355. if(produit.quantity_max && (!quantite_restante || quantite_restante < 0 || produit.unavailable)) {
  356. $('.product-'+id_produit+' .unavailable').show() ;
  357. if(!$('#id-order').val() && $('.product-'+id_produit+' .quantity').val() == 0)
  358. {
  359. $('.product-'+id_produit+' .quantity-remaining').hide() ;
  360. $('.product-'+id_produit+' .input-group').hide() ;
  361. }
  362. }
  363. else {
  364. $('.product-'+id_produit+' .unavailable').hide() ;
  365. $('.product-'+id_produit+' .input-group').show() ;
  366. $('.product-'+id_produit+' .quantity-remaining .nb').html(quantite_restante) ;
  367. }
  368. if($('.product-'+id_produit+' .quantity-remaining').size()) {
  369. if(parseInt($('.product-'+id_produit+' .quantity-remaining .nb').html()) > 5 ||
  370. parseInt($('.product-'+id_produit+' .quantity-remaining .nb').html()) <= 0) {
  371. $('.product-'+id_produit+' .quantity-remaining').hide() ;
  372. }
  373. else {
  374. $('.product-'+id_produit+' .quantity-remaining').show() ;
  375. }
  376. }
  377. });
  378. }
  379. $('#points-sale .point-sale').hide() ;
  380. // init affichage points de vente
  381. $.each(data.points_sale, function(key, livraison) {
  382. if(livraison) {
  383. $('.point-sale-'+key).fadeIn() ;
  384. }
  385. else {
  386. $('.point-sale-'+key).hide() ;
  387. }
  388. }) ;
  389. chat_init_horaire_point_vente(date) ;
  390. }, 'json') ;
  391. }
  392. function chat_systeme_commande_reset_table_prix() {
  393. $('#table-products tr .column-quantity .quantity').each(function() {
  394. $(this).val(0) ;
  395. }) ;
  396. chat_systeme_commande_maj_table_prix() ;
  397. }
  398. function chat_systeme_commande_maj_table_prix() {
  399. // produits pain
  400. var prix = 0 ;
  401. $('.order-form #table-products tbody tr').each(function() {
  402. var quantite = parseInt($(this).find('.quantity').val()) ;
  403. var prix_produit = parseFloat($(this).find('.price').html()) ;
  404. var prix_total_produit = quantite * prix_produit ;
  405. if(prix_total_produit)
  406. $(this).find('.total').html(formate_prix(prix_total_produit)+' €') ;
  407. else
  408. $(this).find('.total').html('--') ;
  409. if(quantite > 0)
  410. prix += prix_total_produit ;
  411. }) ;
  412. $('#total-order strong').html(formate_prix(prix)+' €') ;
  413. var prix_global = prix ;
  414. // produits vrac
  415. var prix = 0 ;
  416. $('.order-form #table-products-vrac tbody tr').each(function() {
  417. var quantite = parseInt($(this).find('.quantity').val()) ;
  418. var prix_produit = parseFloat($(this).find('.price').html()) ;
  419. var prix_total_produit = quantite/1000 * prix_produit ;
  420. if(prix_total_produit)
  421. $(this).find('.total').html(formate_prix(prix_total_produit)+' €') ;
  422. else
  423. $(this).find('.total').html('--') ;
  424. if(quantite > 0)
  425. prix += prix_total_produit ;
  426. }) ;
  427. $('#total-order-vrac strong').html(formate_prix(prix)+' €') ;
  428. prix_global += prix ;
  429. $('#total-order-bottom span').html(formate_prix(prix_global)) ;
  430. if(prix_global)
  431. $('#total-order-bottom').fadeIn() ;
  432. else
  433. $('#total-order-bottom').hide() ;
  434. // maj credit pain
  435. chat_systeme_commande_credit_pain_event(prix_global) ;
  436. return prix_global ;
  437. }
  438. function chat_systeme_commande_credit_pain() {
  439. $('input[name=credit]').change(function() {
  440. var prix_global = chat_systeme_commande_maj_table_prix() ;
  441. chat_systeme_commande_credit_pain_event(prix_global) ;
  442. }) ;
  443. }
  444. function chat_systeme_commande_credit_pain_event(prix_global) {
  445. var html = '' ;
  446. var use_credit_pain = $('input[name=credit]').prop('checked') ;
  447. var credit_pain = parseFloat($('#montant-credit').val()) ;
  448. var credit_pain_dispo = credit_pain ;
  449. var montant_paye = 0
  450. if($('#amount-paid').size() && $('#amount-paid').val())
  451. montant_paye = parseFloat($('#amount-paid').val()) ;
  452. if($('#id-order').size() && $('#id-order').val()) {
  453. credit_pain_dispo = credit_pain + montant_paye ;
  454. }
  455. var credit_pain_active = $('.point-sale.selected').data('credit') ;
  456. if(credit_pain_active || montant_paye) {
  457. $('#checkbox-credit #info-credit-empty').show() ;
  458. $('#checkbox-credit label').show() ;
  459. $('#checkbox-credit #credit-disabled').hide() ;
  460. if(prix_global > credit_pain_dispo) {
  461. var reste_payer = prix_global - credit_pain_dispo ;
  462. if(use_credit_pain) {
  463. if(montant_paye) {
  464. html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ;
  465. }
  466. html += '<strong>'+credit_pain.toFixed(2)+' €</strong> seront débités<br />' ;
  467. html += 'Restera <strong>'+reste_payer+' €</strong> à payer à la boulangerie' ;
  468. $('#checkbox-credit .info').html(html) ;
  469. }
  470. else {
  471. $('#checkbox-credit .info').html('') ;
  472. }
  473. }
  474. else {
  475. $('#checkbox-credit').removeClass('payment-impossible') ;
  476. $('input[name=credit]').removeAttr('disabled') ;
  477. if(use_credit_pain) {
  478. var html = '' ;
  479. // à payer
  480. if(prix_global > montant_paye)
  481. {
  482. montant = prix_global - montant_paye ;
  483. if(montant_paye) {
  484. html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ;
  485. }
  486. html += '<strong>'+montant.toFixed(2)+' €</strong> seront débités' ;
  487. $('#checkbox-credit .info').html(html) ;
  488. }
  489. // remboursé
  490. else if(prix_global < montant_paye) {
  491. montant = montant_paye - prix_global ;
  492. if(montant_paye) {
  493. html += '<span class="amount-paid">'+montant_paye+' € déjà payé</span><br />' ;
  494. }
  495. html += '<strong>'+montant+' €</strong> seront remboursés' ;
  496. $('#checkbox-credit .info').html(html) ;
  497. }
  498. else {
  499. if(montant_paye > 0)
  500. $('#checkbox-credit .info').html('<span class="amount-paid">'+montant_paye+' € déjà payé</span>') ;
  501. else
  502. $('#checkbox-credit .info').html('') ;
  503. }
  504. }
  505. else {
  506. $('#checkbox-credit .info').html('')
  507. }
  508. }
  509. }
  510. else {
  511. $('#checkbox-credit #info-credit-empty').hide() ;
  512. $('#checkbox-credit label').hide() ;
  513. $('#checkbox-credit #credit-disabled').show() ;
  514. }
  515. }
  516. function formate_prix(prix) {
  517. return prix.toFixed(2).replace( ".", "," ) ;
  518. }
  519. function chat_slideshow() {
  520. if($('body').hasClass('home')) {
  521. var base_url = $('#base_url').val() ;
  522. $.vegas('slideshow', {
  523. backgrounds:[
  524. //{ src:'./img/background/back2.jpg' },
  525. { src:base_url+'/img/background/four.jpg' },
  526. { src:base_url+'/img/background/gueulard.jpg' }
  527. ],
  528. walk: function() {
  529. $('.vegas-loading').css('display','none') ;
  530. $('.vegas-background').css('position','absolute') ;
  531. }
  532. })('overlay');
  533. }
  534. }
  535. function chat_scroll() {
  536. if($('body').hasClass('home')) {
  537. $('#header nav ul a[href^="#"]').click(function(){
  538. var the_id = $(this).attr("href");
  539. $('html, body').animate({
  540. scrollTop: $(the_id).offset().top - 100
  541. }, 'normal');
  542. return false;
  543. });
  544. $(window).scroll(function() {
  545. chat_event_scroll() ;
  546. }) ;
  547. chat_event_scroll() ;
  548. }
  549. }
  550. function chat_event_scroll() {
  551. var scroll_top = $(window).scrollTop() ;
  552. //console.log(scroll_top + ' '+ ($('#horaires').offset().top-100)) ;
  553. $('#header nav ul a').each(function() {
  554. var top = $($(this).attr('href')).offset().top ;
  555. var test = top + $($(this).attr('href')).height() - 150 ;
  556. //console.log($(this).attr('href')+' : '+scroll_top+ ' | '+ test) ;
  557. if(scroll_top <= top + $($(this).attr('href')).height() - 150) {
  558. $('#header a').removeClass('selec') ;
  559. $(this).addClass('selec') ;
  560. }
  561. }) ;
  562. }