diff --git a/README.md b/README.md index 1a9dcb0..057cfca 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,59 @@ Reference 'github.commits.widget.js' and containter div and place such script. ``` -where, user is your github account, repo is name of repository and branch is the name of branch you want to track. +This sample shows a short *last modification* message related to the site (e.g., `Last modification just now`): + +```yaml +... +baseurl: "/my-repo" +branch: "gh-pages" +... +author: + name: itsme +... +``` + +```html +Last modification unknown +``` + +```html +$(function() { + $('#last-site-mod').githubInfoWidget( + { user: '{{ site.author.name }}', repo: '{{ site.baseurl }}', branch: '{{ site.branch }}', nouser: true, nomsg: true, abstime: false, simple: 2, last: 1, limitMessageTo: 500 }); +}); + +``` + +This sample shows a short *last modification* message related to a specific page (e.g., `Last modification: 2016-10-03, about 2 hours ago`): + +```html +Last modification: unknown +``` + +```html + +``` Configuration ------------- + +* user is your github account +* repo is name of repository; can be with or without initial `/` +* branch is the name of branch you want to track +* nouser (true/false/unset): if set to true, does not show user +* noavatar (true/false/unset): if set to true, does not show avatar +* nomsg (true/false/unset): if set to true, does not show message +* abstime (true/false/unset): if set to true, shows absolute time +* noreltime (true/false/unset): if set to true, does not show relative time +* simple (unset, 1, 2): if set to 1, shows a simple message without list; if set to 2, also show the number of commits in the tooltip + + You might limit number commits shown in widget by providing with 'last' parameter: ```html diff --git a/js/github.commits.widget.js b/js/github.commits.widget.js index c043fd1..993a08a 100644 --- a/js/github.commits.widget.js +++ b/js/github.commits.widget.js @@ -1,5 +1,13 @@ /* +Modified by ircama, 2016; added the following options: +- nouser (true/false/unset): if set to true, does not show user +- noavatar (true/false/unset): if set to true, does not show avatar +- nomsg (true/false/unset): if set to true, does not show message +- abstime (true/false/unset): if set to true, shows absolute time +- noreltime (true/false/unset): if set to true, does not show relative time +- simple (unset, 1, 2): if set to 1, shows a simple message without list; if set to 2, also show the number of commits in the tooltip + https://github.com/alexanderbeletsky/github-commits-widget # Legal Info (MIT License) @@ -35,11 +43,18 @@ THE SOFTWARE. widget.prototype = (function() { - function getCommits(user, repo, branch, callback) { + function getCommits(user, repo, branch, path, simple, element, callback) { $.ajax({ - url: "https://api.github.com/repos/" + user + "/" + repo + "/commits?sha=" + branch, + url: "https://api.github.com/repos/" + user + repo + "/commits?sha=" + branch + (path === undefined ? '' : "&path=" + path), dataType: 'jsonp', - success: callback + success: callback, + error: function(){ + if (simple) + { + element.empty(); + element.append((simple < 2 ? ' ' : ': ') + ' '); + } + } }); } @@ -51,43 +66,84 @@ THE SOFTWARE. var callback = widget.callback; var element = widget.element; var user = widget.options.user; + var nouser = widget.options.nouser === undefined ? 0 : nouser = widget.options.nouser; + var noavatar = widget.options.noavatar === undefined ? 0 : noavatar = widget.options.noavatar; + var nomsg = widget.options.nomsg === undefined ? 0 : widget.options.nomsg; + var abstime = widget.options.abstime === undefined ? 0 : widget.options.abstime; + var noreltime = widget.options.noreltime === undefined ? 0 : widget.options.noreltime; var repo = widget.options.repo; + if ((repo.length<1) || (repo.substring(0, 1) != '/')) + repo = '/' + repo; var branch = widget.options.branch; + var path = widget.options.path; var avatarSize = widget.options.avatarSize || 20; + var simple = widget.options.simple === undefined ? 0 : widget.options.simple; var last = widget.options.last === undefined ? 0 : widget.options.last; var limitMessage = widget.options.limitMessageTo === undefined ? 0 : widget.options.limitMessageTo; - getCommits(user, repo, branch, function (data) { + getCommits(user, repo, branch, path, simple, element, function (data) { var commits = data.data; var totalCommits = (last < commits.length ? last : commits.length); element.empty(); - var list = $('