From e908ec7963a7b06ee0fe08f8167ae5c4aed8ba90 Mon Sep 17 00:00:00 2001 From: jordanmccullough Date: Thu, 2 Oct 2014 22:15:02 -0600 Subject: [PATCH 1/4] Add proper documentation descriptions --- _javascript/curriculum.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_javascript/curriculum.js b/_javascript/curriculum.js index 0492a9638..54fcabec0 100644 --- a/_javascript/curriculum.js +++ b/_javascript/curriculum.js @@ -1,6 +1,7 @@ $(function(){ var timeLeftInterval = 0; + // Bind checkbox/label click for slide toggle $("#slide-only-toggle").change(function(){ var checkState = $("#slide-only-toggle").attr("checked"); $(".materials > *").toggleClass("hidden"); @@ -8,7 +9,7 @@ $(function(){ }); - // WARNING This only anticipates one querystring value + // Parse username from querystring var urlSearch = window.location.search, queryString = urlSearch.substring(1,urlSearch.length), username = queryString.substring((queryString.indexOf("="))+1, queryString.length); From 78585f1b5b6a682c0328ec70c6d198cf481d1304 Mon Sep 17 00:00:00 2001 From: jordanmccullough Date: Thu, 2 Oct 2014 22:15:45 -0600 Subject: [PATCH 2/4] Refactor query string parsing with regex Discard fragile substring only extraction with regex to acquire the `teacher` query string value. --- _javascript/curriculum.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_javascript/curriculum.js b/_javascript/curriculum.js index 54fcabec0..23b9e1536 100644 --- a/_javascript/curriculum.js +++ b/_javascript/curriculum.js @@ -11,8 +11,9 @@ $(function(){ // Parse username from querystring var urlSearch = window.location.search, - queryString = urlSearch.substring(1,urlSearch.length), - username = queryString.substring((queryString.indexOf("="))+1, queryString.length); + teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/)[0], + username = teacherQuery.substring(8, teacherQuery.length); + if(username){ $.ajax( { From 6268fde01489fe6fde7d96999c8f11038cf8ee11 Mon Sep 17 00:00:00 2001 From: jordanmccullough Date: Thu, 2 Oct 2014 22:28:48 -0600 Subject: [PATCH 3/4] Add conditionals around "teacher" info injection --- _javascript/curriculum.js | 44 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/_javascript/curriculum.js b/_javascript/curriculum.js index 23b9e1536..e121e42f6 100644 --- a/_javascript/curriculum.js +++ b/_javascript/curriculum.js @@ -19,6 +19,7 @@ $(function(){ { url: "https://api.github.com/users/"+username, success: function(data, textStatus, jqXHR){ + $("", { class: "teacher-name", @@ -30,20 +31,39 @@ $(function(){ text: data.login }).appendTo("#teacher-username"); - $("", - { - text: data.email - }).appendTo("#teacher-email"); + // Profile email + if(data.email){ + $("", + { + text: data.email + }).appendTo("#teacher-email"); + } + else{ + $("#teacher-email").toggleClass("hidden"); + } - $("", - { - text: data.company - }).appendTo("#teacher-organization"); + // Profile company + if(data.company){ + $("", + { + text: data.company + }).appendTo("#teacher-organization"); + } + else{ + $("#teacher-organization").toggleClass("hidden"); + } - $("", - { - text: data.location - }).appendTo("#teacher-location"); + + // Profile location + if(data.location){ + $("", + { + text: data.location + }).appendTo("#teacher-location"); + } + else{ + $("#teacher-location").toggleClass("hidden"); + } $("", { From b8008acb45eb3c56358d0ba096860d376a9da5b1 Mon Sep 17 00:00:00 2001 From: jordanmccullough Date: Thu, 2 Oct 2014 22:38:54 -0600 Subject: [PATCH 4/4] Correct bad array logic test for teacher query string parse --- _javascript/curriculum.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/_javascript/curriculum.js b/_javascript/curriculum.js index e121e42f6..579675638 100644 --- a/_javascript/curriculum.js +++ b/_javascript/curriculum.js @@ -11,10 +11,14 @@ $(function(){ // Parse username from querystring var urlSearch = window.location.search, - teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/)[0], - username = teacherQuery.substring(8, teacherQuery.length); + teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/), + username; + + if(teacherQuery && teacherQuery.length == 1){ + username = teacherQuery[0].substring(8, teacherQuery[0].length); + + console.log(username); - if(username){ $.ajax( { url: "https://api.github.com/users/"+username,