hugosoucycc

[ARCHIVED] Another old source code of <hugo.soucy.cc>.
Log | Files | Refs | Submodules

commit 4d5e62cdb300f136433bd57e41210180b229491e
parent aa0683cb0dabe4d0bd6eaf29fe81f7d9fbfeaf52
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Mon, 26 Jun 2017 15:46:52 -0400

Add a searching mecanism for h-entry>p-category.

Diffstat:
Mstatic/dev/js/custom/init.js | 38++++++++++++++++++++++++++++++++++----
Mstatic/prod/js/script.js | 38++++++++++++++++++++++++++++++++++----
Mstatic/prod/js/script.min.js | 6++++--
Mtemplates/mustache/note-index.mustache | 1+
Mtemplates/mustache/note.mustache | 3++-
Atemplates/mustache/partials/search.mustache | 14++++++++++++++
6 files changed, 89 insertions(+), 11 deletions(-)

diff --git a/static/dev/js/custom/init.js b/static/dev/js/custom/init.js @@ -4,28 +4,58 @@ function setNavigation() { var $nav_button; var $nav_panel; var $nav_close; - + if ($nav) { $nav_button = document.querySelector('.nav-button'); $nav_panel = $nav.querySelector('.nav__panel'); $nav_close = $nav_panel.querySelector('.nav__close'); - + du.setClass($nav_panel, 'state--hidden'); du.setEvent($nav_button, 'click', function(thatEvt) { thatEvt.preventDefault(); - + du.toggleClass($nav_panel, 'state--hidden'); du.toggleClass($nav_panel, 'state--visible'); }); du.setEvent($nav_close, 'click', function(thatEvt) { thatEvt.preventDefault(); - + du.toggleClass($nav_panel, 'state--hidden'); du.toggleClass($nav_panel, 'state--visible'); }); } } +function setHashtagSearch() { + var hashTags = du.queryAll('a.p-category'); + + hashTags.forEach(function(tag) { + du.setEvent(tag, 'click', function(thatEvt) { + thatEvt.preventDefault(); + + console.log(tag.innerHTML); + + document.forms['search'].elements['q'].value = tag.innerHTML; + document.forms['search'].submit(); + }); + }); +} + +function setClickableHashtags(fn) { + var hEntries = du.queryAll('.hentry'); + + hEntries.map(function(hEntry) { + var hEntryHashTagged = hEntry.innerHTML.replace( + /(^|\s)(#[a-zA-ZÀ-ú\d-]+)/ig, '$1<a class="p-category" href="$2" title="Chercher sur DuckDuckGo d\'autres entrées avec le tag $2">$2</a>' + ); + + hEntry.innerHTML = hEntryHashTagged; + }); + + fn(); +} + setNavigation(); +setClickableHashtags(setHashtagSearch); diff --git a/static/prod/js/script.js b/static/prod/js/script.js @@ -394,28 +394,58 @@ function setNavigation() { var $nav_button; var $nav_panel; var $nav_close; - + if ($nav) { $nav_button = document.querySelector('.nav-button'); $nav_panel = $nav.querySelector('.nav__panel'); $nav_close = $nav_panel.querySelector('.nav__close'); - + du.setClass($nav_panel, 'state--hidden'); du.setEvent($nav_button, 'click', function(thatEvt) { thatEvt.preventDefault(); - + du.toggleClass($nav_panel, 'state--hidden'); du.toggleClass($nav_panel, 'state--visible'); }); du.setEvent($nav_close, 'click', function(thatEvt) { thatEvt.preventDefault(); - + du.toggleClass($nav_panel, 'state--hidden'); du.toggleClass($nav_panel, 'state--visible'); }); } } +function setHashtagSearch() { + var hashTags = du.queryAll('a.p-category'); + + hashTags.forEach(function(tag) { + du.setEvent(tag, 'click', function(thatEvt) { + thatEvt.preventDefault(); + + console.log(tag.innerHTML); + + document.forms['search'].elements['q'].value = tag.innerHTML; + document.forms['search'].submit(); + }); + }); +} + +function setClickableHashtags(fn) { + var hEntries = du.queryAll('.hentry'); + + hEntries.map(function(hEntry) { + var hEntryHashTagged = hEntry.innerHTML.replace( + /(^|\s)(#[a-zA-ZÀ-ú\d-]+)/ig, '$1<a class="p-category" href="$2" title="Chercher sur DuckDuckGo d\'autres entrées avec le tag $2">$2</a>' + ); + + hEntry.innerHTML = hEntryHashTagged; + }); + + fn(); +} + setNavigation(); +setClickableHashtags(setHashtagSearch); diff --git a/static/prod/js/script.min.js b/static/prod/js/script.min.js @@ -29,4 +29,6 @@ function triggerCustomEvent(el,eventType,eventData){var customEvent;if(window.Cu el.dispatchEvent(customEvent);} function isElementInViewport(el){var elRect=el.getBoundingClientRect();return(elRect.top>=0&&elRect.left>=0&&elRect.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&elRect.right<=(window.innerWidth||document.documentElement.clientWidth));} return{doExtend:doExtend,queryAll:queryAll,setAttrs:setAttrs,setEvent:setEvent,setEventList:setEventList,getIndex:getIndex,getClosest:getClosest,getHeight:getHeight,setClass:setClass,unsetClass:unsetClass,hasClass:hasClass,toggleClass:toggleClass,setDebounce:setDebounce,setThrottle:setThrottle,isElement:isElement,isObject:isObject,triggerEvent:triggerEvent,triggerCustomEvent:triggerCustomEvent,isElementInViewport:isElementInViewport};})(window);function setNavigation(){'use strict';var $nav=document.querySelector('.nav');var $nav_button;var $nav_panel;var $nav_close;if($nav){$nav_button=document.querySelector('.nav-button');$nav_panel=$nav.querySelector('.nav__panel');$nav_close=$nav_panel.querySelector('.nav__close');du.setClass($nav_panel,'state--hidden');du.setEvent($nav_button,'click',function(thatEvt){thatEvt.preventDefault();du.toggleClass($nav_panel,'state--hidden');du.toggleClass($nav_panel,'state--visible');});du.setEvent($nav_close,'click',function(thatEvt){thatEvt.preventDefault();du.toggleClass($nav_panel,'state--hidden');du.toggleClass($nav_panel,'state--visible');});}} -setNavigation();- \ No newline at end of file +function setHashtagSearch(){var hashTags=du.queryAll('a.p-category');hashTags.forEach(function(tag){du.setEvent(tag,'click',function(thatEvt){thatEvt.preventDefault();console.log(tag.innerHTML);document.forms['search'].elements['q'].value=tag.innerHTML;document.forms['search'].submit();});});} +function setClickableHashtags(fn){var hEntries=du.queryAll('.hentry');hEntries.map(function(hEntry){var hEntryHashTagged=hEntry.innerHTML.replace(/(^|\s)(#[a-zA-ZÀ-ú\d-]+)/ig,'$1<a class="p-category" href="$2" title="Chercher sur DuckDuckGo d\'autres entrées avec le tag $2">$2</a>');hEntry.innerHTML=hEntryHashTagged;});fn();} +setNavigation();setClickableHashtags(setHashtagSearch);+ \ No newline at end of file diff --git a/templates/mustache/note-index.mustache b/templates/mustache/note-index.mustache @@ -13,6 +13,7 @@ </div> </main> + {{> partials/search.mustache }} {{> partials/nav.mustache }} {{> partials/bottom-script.mustache }} </body> diff --git a/templates/mustache/note.mustache b/templates/mustache/note.mustache @@ -76,7 +76,8 @@ {{/ bridgy }} </article> </main> - + + {{> partials/search.mustache }} {{> partials/bottom-script.mustache }} </body> </html> diff --git a/templates/mustache/partials/search.mustache b/templates/mustache/partials/search.mustache @@ -0,0 +1,14 @@ +<form action="http://duckduckgo.com/" + class="visuallyhidden" + id="search" + method="get"> + <input name="sites" + type="hidden" + value="hugo.soucy.cc"/> + <input name="kt" + type="hidden" + value="h"/> + <input maxlength="255" + name="q" + type="text"/> +</form>