1(function (Drupal) { 2 3 Drupal.theme.icon = function (name) { 4 return '<svg class="icon icon-' + name + '" role="img" aria-hidden="true"><use xlink:href="#' + name + '-icon"></use></svg>'; 5 }; 6 7 Toolbar.template = '\ 8 <div class="toolbar_alpha">\ 9 <a href="" target="_blank" data-share="twitter" class="toolbar_btn bg-twitter color-white" title="Partager sur Twitter">' + 10 Drupal.theme.icon('ic_twitter') + 11 '</a>\ 12 <a href="" target="_blank" data-share="facebook" class="toolbar_btn bg-facebook color-white" title="Partager sur Facebook">' + 13 Drupal.theme.icon('ic_facebook') + 14 '</a>\ 15 <a href="" target="_blank" data-share="linkedin" class="toolbar_btn bg-linkedin color-white" title="Partager sur LinkedIn">' + 16 Drupal.theme.icon('ic_linkedin') + 17 '</a>\ 18 </div>\ 19 <div class="toolbar_beta">\ 20 </div>\ 21 <div class="toolbar_gamma">\ 22 <button class="toolbar_btn toolbar_btn-bookmark">' + 23 Drupal.theme.icon('ic_etoile') + 24 '</button>\ 25 <a href="javascript:print();" class="toolbar_btn toolbar_btn--print bg-black color-white" title="Imprimer">' + 26 Drupal.theme.icon('ic_imprimante') + 27 '</a>\ 28 <a href="" data-share="email" class="toolbar_btn toolbar_btn--email bg-grey color-white" title="Partager par email">' + 29 Drupal.theme.icon('ic_mail') + 30 '</a>\ 31 </div>'; 32 33 function Toolbar () { 34 this.toolbar; 35 this.init(); 36 document.body.className += ' toolbar-active' 37 } 38 39 Toolbar.prototype.init = function () { 40 // Insert toolbar 41 if (!document.getElementById('toolbar')) { 42 this.toolbar = document.createElement('div'); 43 this.toolbar.id = 'toolbar'; 44 this.toolbar.className = 'toolbar'; 45 this.toolbar.setAttribute('role', 'complementary'); 46 this.toolbar.innerHTML = Toolbar.template; 47 document.body.appendChild(this.toolbar); 48 } 49 50 this.updateSharers(); 51 var bookmarkButton = this.toolbar.querySelector('.toolbar_btn-bookmark'); 52 bookmarkButton.setAttribute('data-bookmark-id', drupalSettings.bookmark.id); 53 this.bookmark = new Bookmark(bookmarkButton); 54 }; 55 56 Toolbar.prototype.updateSharers = function (title, url) { 57 title = title || (document.querySelector('h1') ? document.querySelector('h1').textContent : null) || document.title; 58 url = url || window.location.href; 59 60 var sharers = this.toolbar.querySelectorAll('[data-share]'); 61 sharers.forEach(function (sharer) { 62 var provider = sharer.getAttribute('data-share'); 63 if (typeof Toolbar.providers[provider] === 'function') { 64 sharer.href = Toolbar.providers[provider](title, url); 65 } 66 }); 67 68 }; 69 70 Toolbar.prototype.getReadingTime = function(elements){ 71 var wordsPerMinute = 250; // cf https://fr.wikipedia.org/wiki/Mot_par_minute 72 var words = 0; 73 var current_toolbar = this; 74 elements.forEach(function(element){ 75 words += current_toolbar.countWords(element.textContent); 76 }); 77 return Math.ceil(words / wordsPerMinute); 78 }; 79 80 Toolbar.prototype.countWords = function(str) { 81 var matches = str.match(/\S+/g); 82 return matches ? matches.length : 0; 83 }; 84 85 Toolbar.prototype.calculateArticleReadingTime = function(selector, context) { 86 context = context || document; 87 selector = selector || '.chapo, .wysiwyg'; 88 var readingElements = context.querySelectorAll(selector); 89 return this.getReadingTime(readingElements); 90 }; 91 92 Toolbar.prototype.updateArticleToolbar = function(selector, context) { 93 readingTime = this.calculateArticleReadingTime(selector, context); 94 this.updateContent('Temps de lecture estimé à ' + readingTime + ' minute' + (readingTime > 1 ? 's' : '') + '.'); 95 }; 96 97 Toolbar.providers = {}; 98 99 Toolbar.providers.twitter = function (title, url) { 100 return 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(url) + '&via=CB_News'; 101 }; 102 103 Toolbar.providers.facebook = function (title, url) { 104 return 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url); 105 }; 106 107 Toolbar.providers.linkedin = function (title, url) { 108 return 'http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(url); 109 }; 110 111 Toolbar.providers.googleplus = function (title, url) { 112 return 'https://plus.google.com/share?url=' + encodeURIComponent(url); 113 }; 114 115 Toolbar.providers.email = function (title, url) { 116 var subject = 'CB News - ' + title; 117 var body = "Bonjour,%0D%0A%0D%0AJ'ai pensé que cet article de CB News pourrait t'intéresser :%0D%0A" + title + "%0D%0A" + url + "%0D%0A%0D%0Aà bientôt !"; 118 return 'mailto:?subject=' + subject + '&body=' + body; 119 }; 120 121 Toolbar.prototype.changeProvider = function(provider, prov_func){ 122 if (typeof Toolbar.providers[provider] === 'function' && typeof prov_func === 'function') { 123 Toolbar.providers[provider] = prov_func; 124 } 125 this.updateSharers(); 126 }; 127 128 Toolbar.prototype.updateContent = function (content) { 129 this.toolbar.querySelector('.toolbar_beta').innerHTML = content; 130 }; 131 132 window.Toolbar = Toolbar; 133 134})(Drupal);
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.