Permalink
Browse files

Base plugin structure, proof of consept code

  • Loading branch information...
1 parent ac91da6 commit 7d0d83735fc4c9660b3c5a590ead23f887163379 @mikaelbr committed Jul 29, 2011
Showing with 153 additions and 0 deletions.
  1. +22 −0 index.html
  2. +113 −0 jquery.metabrag.js
  3. +18 −0 jquery.min.js
View
@@ -0,0 +1,22 @@
+<!doctype html>
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+
+ <script type="text/javascript" src="jquery.min.js"></script>
+ <script type="text/javascript" src="jquery.metabrag.js"></script>
+
+ <script type="text/javascript">
+ $(function() {
+ $(".testing").metabrag();
+ });
+ </script>
+ </head>
+ <body>
+
+ <strong class="testing" data-metabrag-username="mikaelbr"></strong>
+ <strong class="testing" data-metabrag-username="schacon"></strong>
+
+ </body>
+</html>
View
@@ -0,0 +1,113 @@
+/*!
+ * jQuery JavaScript Library Plugin: metabrag
+ *
+ * Copyright 2011, John Resig
+ * Licensed under the GPL Version 2 licens.
+ * http://jquery.org/license
+ *
+ *
+ * Date: Thu Jul 29 21:48:21 2011 +0100
+ */
+(function( $ ){
+
+ var metabragMethods = {
+ init : function( options ) {
+ // get settings..
+ var $this = metabragMethods;
+ var $element = this;
+ $this._settings = $.extend({}, $.fn.metabrag.defaults, options);
+
+ $element.each(function () {
+ var username = $this._settings.username != "" ? $this._settings.username : $(this).attr("data-metabrag-username");
+
+ if(typeof username == "undefined" || username == "") {
+ $.error( 'No username is defined for the jquery.metabrag plugin.' );
+ }
+
+ console.log()
+
+ if(!!$this._settings.showGithubUserInfo) {
+ $this._getGithubUserInfo(username);
+ }
+
+ if(!!$this._settings.showGithubRepoInfo) {
+ $this._getGithubRepoInfo(username);
+ }
+
+ if(!!$this._settings.showCoderwallBadges) {
+ $this._getCoderwallBadges(username);
+ }
+
+
+ });
+
+ },
+
+ refresh: function () {
+
+ },
+
+ _getGithubUserInfo: function (username) {
+ $.getJSON(this._githubApiURL + username, this._insertGuthubUserInfo);
+ },
+
+ _insertGuthubUserInfo: function (jsonObj) {
+ console.log("------ Github UserInfo -------");
+ console.log(jsonObj);
+ console.log("---- // Github UserInfo -----");
+ },
+
+ _getGithubRepoInfo: function (username) {
+ $.getJSON(this._githubApiURL + username + "/repos", this._insertGuthubUserInfo);
+ },
+
+ _insertGuthubRepoInfo: function (jsonObj) {
+ console.log("------ Github Repos Info -------");
+ console.log(jsonObj);
+ console.log("---- // Github Repos Info -----");
+ },
+
+ _getCoderwallBadges: function (username) {
+ $.getJSON(this._coderwallApiURL + username + ".json", this._insertGuthubUserInfo);
+ },
+
+ _insertCoderwallBadges: function (jsonObj) {
+ console.log("------ Coderwall UserInfo -------");
+ console.log(jsonObj);
+ console.log("---- // Coderwall UserInfo -----");
+ },
+
+
+ _githubApiURL: "https://api.github.com/users/",
+ _coderwallApiURL: "http://coderwall.com/"
+ };
+
+
+ // Define metabrag as a part of the jQuery namespace.
+ $.fn.metabrag = function( method ) {
+
+ // Allow method calls (but not prefixed by _
+ if ( metabragMethods[method] && method.substr(0,1) != "_") {
+ return metabragMethods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
+ }
+ // If argument is object or not set, init plugin.
+ else if ( typeof method === 'object' || ! method ) {
+ return metabragMethods.init.apply( this, arguments );
+ }
+ // No method found by argument input. Could be a private method.
+ else {
+ $.error( 'Method ' + method + ' does not exist on jQuery.metabrag' );
+ return this;
+ }
+
+ };
+
+ $.fn.metabrag.defaults = {
+ useDataAttr: true,
+ username: '',
+ showGithubUserInfo: true,
+ showGithubRepoInfo: true,
+ showCoderwallBadges: true
+ };
+
+})( jQuery );
Oops, something went wrong.

0 comments on commit 7d0d837

Please sign in to comment.