1/* 2 * To change this license header, choose License Headers in Project Properties. 3 * To change this template file, choose Tools | Templates 4 * and open the template in the editor. 5 */ 6 7(function ($, Drupal, window, document) { 8 // To understand behaviors, see https://drupal.org/node/756722#behaviors 9 Drupal.behaviors.ws_communo = { 10 attach: function (context, settings) { 11 12 $(once('bookmarks-init', $('body'))).each(function () { 13 14 let btnBookmark = $('.btn-bookmark'); 15 let bookmarks = JSON.parse(window.localStorage.getItem('eprojet_embrun_bookmarks')) ?? []; 16 17 // état initial du bouton en fonction du contenu de eprojet_embrun_bookmarks 18 let currentNid = drupalSettings.nid; 19 let alreadyThere = bookmarks.filter(val => val.nid == currentNid).length >= 1; 20 if(alreadyThere) { 21 btnBookmark.addClass('bookmark-saved'); 22 } 23 24 $('.menu--accesrapidevilleembrunfr', 'body').append('<ul class="nav navbar-nav bookmarks-nav"></ul>'); 25 updateAccesRapide(); 26 27 btnBookmark.on('click', function (e) { 28 let fav = e.target.dataset; 29 let bookmarks = JSON.parse(window.localStorage.getItem('eprojet_embrun_bookmarks')) ?? []; 30 let found = false; 31 bookmarks.forEach((value, index) => { 32 if(value.nid === fav.nid) { 33 found = index; 34 } 35 }); 36 if(found !== false) { // il se peut que found === 0, d'où la comparaison avec false 37 bookmarks.splice(found, 1); 38 btnBookmark.removeClass('bookmark-saved'); 39 } else { 40 if(bookmarks.length > 4) { 41 bookmarks = bookmarks.slice(1, 5); 42 } 43 bookmarks.push(fav); 44 btnBookmark.addClass('bookmark-saved'); 45 } 46 window.localStorage.setItem('eprojet_embrun_bookmarks', JSON.stringify(bookmarks)); 47 updateAccesRapide(); 48 }); 49 }); 50 51 function updateAccesRapide() { 52 let bookmarks = JSON.parse(window.localStorage.getItem('eprojet_embrun_bookmarks')) ?? []; 53 bookmarks.reverse(); 54 let accesrapide = $('.menu--accesrapidevilleembrunfr > .bookmarks-nav', 'body'); 55 accesrapide.html(''); 56 if(bookmarks.length === 0) { 57 accesrapide.append('<li class="nav-item"><a class="nav-link bookmark-empty">Ajoutez des pages à vos favoris pour les retrouver ici !</a></li>'); 58 } else { 59 bookmarks.forEach((value) => { 60 accesrapide.append(`<li class="nav-item"><a href="${value.url}" class="nav-link link-bookmark">${value.title}</a></li>`); 61 }); 62 } 63 } 64 65 } 66 }; 67})(jQuery, Drupal, this, this.document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.