Permalink
Browse files

Merge branch 'gh-pages' of https://github.com/williame/Kivabeta

  • Loading branch information...
2 parents 66f3494 + 979eaec commit 5f54f02c8263c0ddd51e7ef240641d61290943e7 @mscoutermarsh committed May 7, 2012
Showing with 411 additions and 1 deletion.
  1. +99 −0 achievements.html
  2. +8 −0 css/kivabeta.css
  3. +1 −1 index.html
  4. +157 −0 js/achievements.js
  5. +146 −0 mobile.html
View
@@ -0,0 +1,99 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>KivaBeta</title>
+<link type="text/css" href="./js/jquery-ui-1.8.2.custom.css" rel="stylesheet">
+<link type="text/css" href="./css/bootstrap.css" rel="stylesheet">
+<link type="text/css" href="./css/kivabeta.css" rel="stylesheet">
+<link type="text/css" href="http://www.kiva.org/StyleSheets/kiva.supercat.css" rel="stylesheet">
+<script type="text/javascript" src="./js/JSLINQ.js"></script>
+<script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>
+<script type="text/javascript" src="./js/jquery-ui-1.8.2.custom.min.js"></script>
+<script type="text/javascript" src="./js/jquery.layout.min-1.2.0.js"></script>
+<script type="text/javascript" src="./js/bootstrap.js"></script>
+<script type="text/javascript" src="./js/achievements.js"></script>
+<script type="text/javascript">
+
+jQuery(window).load( function() {
+});
+
+
+var achievementMap = { "hasMadeALoan" : ACH.HasMadeALoan ,
+ "hasMadeFiveLoans" : ACH.HasMadeFiveLoans,
+ "hasMadeFiftyLoans" : ACH.HasMadeFiftyLoans,
+ "globetrotter" : ACH.Globetrotter
+ };
+
+function ActivateAchievement(achievement)
+{
+ jQuery("#" + achievement).text("Yes");
+ jQuery("#" + achievement).removeClass("achievement-notactive");
+ jQuery("#" + achievement).addClass("achievement-active");
+}
+
+function DeactivateAchievement(achievement)
+{
+ jQuery("#" + achievement).text("No");
+ jQuery("#" + achievement).removeClass("achievement-active");
+ jQuery("#" + achievement).addClass("achievement-notactive");
+}
+
+function UpdateAchievements()
+{
+ for (var achievement in achievementMap)
+ {
+ if (achievementMap[achievement]())
+ {
+ ActivateAchievement(achievement);
+ }
+ else
+ {
+ DeactivateAchievement(achievement);
+ }
+ }
+}
+
+var usrName = "";
+
+function GetUserData()
+{
+ var curUsrName = jQuery('#userNameBox').val();
+ if (curUsrName !== usrName)
+ {
+ usrName = curUsrName;
+ ACH.LoadData(curUsrName, UpdateAchievements, 1, true);
+ }
+}
+
+
+</script>
+</head>
+<body >
+<div class="container">
+ <div class="row">
+ <h1 class="pageHeader">KivaBeta</h1>
+ </div>
+ <div class="row">
+ <div class="b rC bS">
+ <h3 class="pT pB">Achievements</h3>
+ <div>
+ Kiva account name: <input type="text" id="userNameBox" onkeyup="GetUserData();" style="width:125px;">
+ </div>
+ <p class="">
+ <span id="results" tabindex="0">
+ <div>Has made a loan: <span id="hasMadeALoan" class="achievement-notactive">No</span></div>
+ <div>Has made 5 loans: <span id="hasMadeFiveLoans" class="achievement-notactive">No</span></div>
+ <div>Has made 50 loans: <span id="hasMadeFiftyLoans" class="achievement-notactive">No</span></div>
+ <div>Has made a loan in 10 different countries: <span id="globetrotter" class="achievement-notactive">No</span></div>
+ </span>
+ <span id="log"></span>
+ </p>
+ </div>
+ </div>
+ <div class="row" >
+ <div class="span3"><p>(C) 2012 Kiva</p></div>
+ </div>
+</div>
+</body>
+</html>
View
@@ -5,3 +5,11 @@
.loan-display li:nth-child(2n+1) {
background-color:#F7F7F2;
}
+
+.achievement-active {
+ color : green;
+}
+
+.achievement-notactive {
+ color : red;
+}
View
@@ -272,7 +272,7 @@ <h3 class=""><span class=""></span><a href="/#">Saved Filters</a></h3>
</div>
</div>
<div class="pB">
- <h3 class=""><span class=""></span><a href="/#">Achievements</a></h3>
+ <h3 class=""><span class=""></span><a href="./achievements.html">Achievements</a></h3>
<div class="" >
<p>Would be great to have a feature achievement</p>
<ul>
View
@@ -0,0 +1,157 @@
+//-----------------------------------------------------------------------
+// Fill this in with a header
+// Dependent upon jquery
+//-----------------------------------------------------------------------
+
+var ACH = {};
+
+(function ()
+{
+ ACH.usrData = null;
+ ACH.usrDataLoaded = false;
+ ACH.curUser = "";
+ ACH.loadingUser = "";
+ reqID = 0;
+ errTimeout = null;
+
+
+ BatchLoad = function (user, startPage, endPage, ID, callback)
+ {
+ var returnedPages = 0;
+ for (var pageNum = startPage; pageNum <= endPage; ++pageNum)
+ {
+ jQuery.ajax(
+ {
+ type : "GET",
+ url : "http://api.kivaws.org/v1/lenders/" + user + "/loans.json",
+ data : "page=" + pageNum,
+ contentType: "application/json; charset=utf-8",
+ dataType : "jsonp",
+ jsonp : "jsonp",
+ id : ID,
+ success : function (data)
+ {
+ if (reqID === this.id)
+ {
+ returnedPages++;
+ console.log("received page " + data.paging.page + " for user " + user + " on reqID " + reqID);
+ ACH.usrData.loans = ACH.usrData.loans.concat(data.loans);
+ if (returnedPages === endPage - startPage + 1)
+ {
+ ACH.usrDataLoaded = true;
+ callback();
+ }
+ }
+ },
+ error : function (msg, url, line)
+ {
+ console.log("error connecting to Kiva");
+ }
+ })
+ }
+ }
+
+ ACH.LoadData = function (user, callback, page, initial)
+ {
+ clearTimeout(errTimeout);
+ reqID++;
+ console.log("LoadData called for user " + user + " on reqID " + reqID);
+ ACH.loadingUser = user;
+ ACH.usrDataLoaded = false;
+ ACH.usrData = null;
+
+
+ page = page || 1;
+ if (typeof initial === "undefined")
+ {
+ initial = true;
+ }
+ var timeout = 2000;
+ errTimeout = setTimeout(function()
+ {
+ console.log("timed out");
+ callback();
+ }, timeout);
+ jQuery.ajax(
+ {
+ type : "GET",
+ url : "http://api.kivaws.org/v1/lenders/" + user + "/loans.json",
+ data : "page=" + page,
+ contentType: "application/json; charset=utf-8",
+ dataType : "jsonp",
+ jsonp : "jsonp",
+ id : reqID,
+ success : function (data)
+ {
+ clearTimeout(errTimeout);
+ if (reqID === this.id)
+ {
+ ACH.usrData = data;
+ if (data.paging.pages - data.paging.page > 0)
+ {
+ BatchLoad(user, data.paging.page + 1, data.paging.pages, this.id, callback);
+ }
+ else
+ {
+ ACH.usrDataLoaded = true;
+ callback();
+ }
+ }
+ },
+ error : function (msg, url, line)
+ {
+ console.log("error connecting to Kiva");
+ }
+ })
+ }
+
+ ACH.HasMadeALoan = function()
+ {
+ if (ACH.usrData && ACH.usrData.loans)
+ {
+ return (ACH.usrData.loans.length > 0);
+ }
+ return false;
+ }
+
+ ACH.HasMadeFiveLoans = function()
+ {
+ if (ACH.usrData && ACH.usrData.loans)
+ {
+ return (ACH.usrData.loans.length >= 5);
+ }
+ return false;
+ }
+
+ ACH.HasMadeFiftyLoans = function()
+ {
+ if (ACH.usrData && ACH.usrData.loans)
+ {
+ return (ACH.usrData.loans.length >= 50);
+ }
+ return false;
+ }
+
+ ACH.Globetrotter = function()
+ {
+ if (ACH.usrData && ACH.usrData.loans)
+ {
+ var countryCodes = [];
+ for (var i = 0; i < ACH.usrData.loans.length; ++i)
+ {
+ var loan = ACH.usrData.loans[i];
+ //console.log(loan.location.country_code);
+ if (jQuery.inArray(loan.location.country_code, countryCodes) == -1)
+ {
+ countryCodes.push(loan.location.country_code);
+ if (countryCodes.length >= 10)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ //console.log(countryCodes)
+ return false;
+ }
+})();
Oops, something went wrong.

0 comments on commit 5f54f02

Please sign in to comment.