From c18c8e0a6bc0d6b433bc41128d4cf12a2ff41880 Mon Sep 17 00:00:00 2001 From: Levi DeHaan Date: Wed, 9 Mar 2011 13:40:44 -0800 Subject: [PATCH 01/10] Made some changes to get it working with new api requirements added some things, modified some things, I am using it in a current project that is running locally and pulling data from github from local:// --- github.js | 285 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 192 insertions(+), 93 deletions(-) diff --git a/github.js b/github.js index 2509ec0..bda05d3 100644 --- a/github.js +++ b/github.js @@ -43,12 +43,37 @@ url += prefix + "callback=" + encodeURIComponent("gh.__jsonp_callbacks[" + id + "]"); if (authUsername && authToken) { - url += "&login=" + authUsername + "&authToken=" + authToken; + url += "&login=" + authUsername + "&token=" + authToken; } script.setAttribute("src", apiRoot + url); document.getElementsByTagName('head')[0].appendChild(script); }, + + jsonp2 = function (url, callback, context) { + apiRoot2 = 'https://gist.github.com/' + var id = +new Date, + script = document.createElement("script"); + + while (gh.__jsonp_callbacks[id] !== undefined) + id += Math.random(); // Avoid slight possibility of id clashes. + + gh.__jsonp_callbacks[id] = function () { + delete gh.__jsonp_callbacks[id]; + callback.apply(context, arguments); + }; + + var prefix = "?"; + if (url.indexOf("?") >= 0) + prefix = "&"; + + url += prefix + "callback=" + encodeURIComponent("gh.__jsonp_callbacks[" + id + "]"); + + script.setAttribute("src", apiRoot2 + url); + console.log('jsonp2'); + console.log(script); + document.getElementsByTagName('head')[0].appendChild(script); + }, // Send an HTTP POST. Unfortunately, it isn't possible to support a callback // with the resulting data. (Please prove me wrong if you can!) @@ -57,36 +82,70 @@ // restrictions on ajax calls. Basically, a form is created that will POST // to the GitHub API URL, stuck inside an iframe so that it won't redirect // this page, and then submitted. + // THIS FUNCTION NOW DEPENDS ON jQuery post = function (url, vals) { - var - form = document.createElement("form"), - iframe = document.createElement("iframe"), - doc = iframe.contentDocument !== undefined ? - iframe.contentDocument : - iframe.contentWindow.document, - key, field; - vals = vals || {}; - - form.setAttribute("method", "post"); - form.setAttribute("action", apiRoot + url); - for (key in vals) { - if (vals.hasOwnProperty(key)) { - field = document.createElement("input"); - field.type = "hidden"; - field.value = encodeURIComponent(vals[key]); - form.appendChild(field); + var key, field; + + var iframe = $('