Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 2da9df6a3781e26757e4d946b678b40d19a2ab39 0 parents
@potomak authored
Showing with 129 additions and 0 deletions.
  1. +54 −0 README.md
  2. +75 −0 jquery.github.js
54 README.md
@@ -0,0 +1,54 @@
+# GitHub jQuery plugin
+
+A jQuery plugin to access GitHub API.
+
+## Usage
+
+Import the script
+
+```html
+<script src="jquery.github.js"></script>
+```
+
+Insert an empty `div` in the code
+
+```html
+<div class="members"></div>
+```
+
+Run the plugin
+
+```javascript
+$(function() {
+ $(".members").github({organization: 'hackatron'});
+});
+```
+
+## Options
+
+### organization
+
+Show a list of `organization`'s members.
+See also http://developer.github.com/v3/orgs/members/
+
+Type: `String`
+
+Default: `null`
+
+### onLoad
+
+Called just before making a request to GitHub API.
+
+Type: `Function`
+
+Default: `null`
+
+### onComplete
+
+Called after a response from GitHub API.
+
+Type: `Function`
+
+Arguments: `response`
+
+Default: `null`
75 jquery.github.js
@@ -0,0 +1,75 @@
+(function($){
+ $.fn.github = function(options) {
+ var that = this,
+ apiEndpoint = "https://api.github.com",
+ settings = {
+ organization: null
+ , onLoad: null
+ , onComplete: function(response) {
+ var length = typeof response.data != 'undefined' ? response.data.length : 0;
+
+ if(length > 0) {
+ for(var i = 0; i < length; i++) {
+ that.append(createMemberElement(response.data[i]));
+ }
+ }
+ else {
+ that.append(createEmptyElement());
+ }
+ }
+ };
+
+ options && $.extend(settings, options);
+
+ function createMemberElement(member) {
+ return $('<div>')
+ .addClass('github-member')
+ .attr('id', member.id)
+ .append(
+ $('<a>')
+ .attr('href', member.url)
+ .append(
+ $('<img>')
+ .addClass('github-member-avatar')
+ .attr('src', member.avatar_url)
+ )
+ );
+ }
+
+ function createEmptyElement() {
+ return $('<div>')
+ .addClass('github-member')
+ .attr('id', 'empty')
+ .html('No members for this organization');
+ }
+
+ function composeRequestURL() {
+ var url = apiEndpoint,
+ params = {};
+
+ if(settings.organization != null) {
+ url += "/orgs/" + settings.organization + "/members";
+ }
+
+ url += "?" + $.param(params)
+
+ return url;
+ }
+
+ function runIfNotNull(f, o, args) {
+ f != null && typeof f == 'function' && f.apply(o, args);
+ }
+
+ runIfNotNull(settings.onLoad, this, []);
+
+ $.ajax({
+ type: "GET",
+ dataType: "jsonp",
+ cache: false,
+ url: composeRequestURL(),
+ success: settings.onComplete
+ });
+
+ return this;
+ };
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.