Browse Source

Improvide github user resolution code. Don't cycle backer messages after the page has been loaded.

Riccardo Balbo 5 years ago
parent
commit
2fa44314e9
2 changed files with 24 additions and 14 deletions
  1. 10 9
      layouts/shortcodes/ghuser.html
  2. 14 5
      static/js/Main.js

+ 10 - 9
layouts/shortcodes/ghuser.html

@@ -1,13 +1,14 @@
 <figure class="githubUser {{ .Get "mode" }} " github-user="{{ .Get "user" }}">
 <figure class="githubUser {{ .Get "mode" }} " github-user="{{ .Get "user" }}">
-    <img src="https://avatars.githubusercontent.com/{{ lower ( .Get "user" ) }}">
+    <img class="excludeSummary" src="https://avatars.githubusercontent.com/{{ lower ( .Get "user" )  }}">
     <figcaption>  
     <figcaption>  
-        <h2>
-            <span class="ghname">{{ .Get "user" }}</span>
+        <h2 ghresolve-bio="title" alt="{{ .Get "user" }}" class="ghname" ghresolve-name="innerText">
+            {{ .Get "user" }}
         </h2>
         </h2>
-        <span class="ghbio"></span>
-        <br />
-        <a href="https://github.com/{{ lower ( .Get "user" )  }}"><i class="fab fa-github"></i></a>
-        <a class="ghtwitter_link" href="" style="display:none"><i class="fab fa-twitter"></i></a>
-        <a class="ghblog" href="" style="display:none"><i class="fas fa-globe"></i></a>
+            <span ghresolve-bio="innerText" class="ghbio excludeSummary"></span>
+        <div>
+            <a alt="github link" title="Github"  href="https://github.com/{{ lower ( .Get "user" )  }}" class="excludeSummary"><i class="fab fa-github"></i></a>
+            <a  alt="twitter link"  title="Twitter" ghresolve-twitter_link="href" class="ghtwitter_link excludeSummary" href="" style="display:none"><i class="fab fa-twitter"></i></a>
+            <a  alt="website link"  title="Website" ghresolve-blog="href"  class="ghblog excludeSummary" href="" style="display:none"><i class="fas fa-globe"></i></a>
+        </div>
     </figcaption>
     </figcaption>
-</figure> 
+</figure> 

+ 14 - 5
static/js/Main.js

@@ -17,7 +17,6 @@ class OpenCollectiveService{
 		this.cycleMessage();
 		this.cycleMessage();
 		setInterval(() =>{
 		setInterval(() =>{
 			this.cycleBackers();
 			this.cycleBackers();
-			this.cycleMessage();
 		}, 5000);
 		}, 5000);
 	}
 	}
 
 
@@ -77,7 +76,7 @@ class GithubService{
 			console.log("Found user needing resolution",el,user)
 			console.log("Found user needing resolution",el,user)
 
 
 			GithubUtils.resolveUser(user).then(user=>{
 			GithubUtils.resolveUser(user).then(user=>{
-				console.log(user,"resolved!");
+				// console.log(user,"read for resolution!");
 				const properties={};
 				const properties={};
 				properties.name=user.name;
 				properties.name=user.name;
 				if(!properties.name)properties.name=user.login;
 				if(!properties.name)properties.name=user.login;
@@ -93,9 +92,19 @@ class GithubService{
 				for(let k in properties){
 				for(let k in properties){
 					const v=properties[k];
 					const v=properties[k];
 					if(!v)continue;
 					if(!v)continue;
-					el.querySelectorAll(".gh"+k).forEach(eel=>eel.style.display="inline-block");
-					el.querySelectorAll("a.gh"+k).forEach(eel=>eel.setAttribute("href",v));
-					el.querySelectorAll("span.gh"+k).forEach(eel=>eel.innerText=v);					
+					const attr="ghresolve-"+k;
+					el.querySelectorAll("["+attr+"]").forEach(eel=>{
+						const realattr=eel.getAttribute(attr);
+						eel.style.display="inline-block";
+						if(realattr==="innerText"){
+							eel.innerText=v;
+						}else{
+							eel.setAttribute(realattr,v);
+						}
+					})
+					// el.querySelectorAll(".gh"+k).forEach(eel=>eel.style.display="inline-block");
+					// el.querySelectorAll("a.gh"+k).forEach(eel=>eel.setAttribute("href",v));
+					// el.querySelectorAll("span.gh"+k).forEach(eel=>eel.innerText=v);					
 				}
 				}
 			});
 			});
 		});
 		});