Created
November 29, 2012 09:02
-
-
Save ibrahima/4167712 to your computer and use it in GitHub Desktop.
Bookmarklet for embedding diff views into Github commit log pages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Go to http://jsfiddle.net/zdJ9f/1/embedded/result/ to get a link to this bookmarklet, or stick the following HTML someplace, or make a just bookmark to the href of the link below. | |
| <a href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://raw.github.com/gist/4167712/test.js';})();">Github Inline Diffs</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(){ | |
| // template from http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/ | |
| // the minimum version of jQuery we want | |
| var v = "1.7.0"; | |
| // check prior inclusion and version | |
| if (window.jQuery === undefined || window.jQuery.fn.jquery < v) { | |
| var done = false; | |
| var script = document.createElement("script"); | |
| script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js"; | |
| script.onload = script.onreadystatechange = function(){ | |
| if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { | |
| done = true; | |
| initMyBookmarklet(); | |
| } | |
| }; | |
| document.getElementsByTagName("head")[0].appendChild(script); | |
| } else { | |
| if(window.githubInlineDiff === undefined){ | |
| initMyBookmarklet(); | |
| } | |
| } | |
| function initMyBookmarklet() { | |
| (window.githubInlineDiff = function() { | |
| // your JavaScript code goes here! | |
| $('<button class="inline-diff-toggle gobutton sha" >Diff</a>').insertAfter($('a.gobutton')); | |
| $('button.inline-diff-toggle').on('click', function(event){ | |
| $elem = $(event.target); | |
| $link = $elem.prev('a.gobutton'); | |
| parent=$elem.closest('li.commit'); | |
| existingDiff = parent.children('div.diff-view'); | |
| if (existingDiff.length == 0){ | |
| url=$link.attr('href'); | |
| $.get(url, function(data, textStatus, jqXHR){ | |
| diffView=$(data).find('div.diff-view#files'); | |
| // Not changing ID for now because otherwise the styling is bad. Might be a way to work around it | |
| // diffView.attr('id', 'inline-diff-'+url.substr(url.lastIndexOf('/')+1)); | |
| parent.append(diffView); | |
| } | |
| ); | |
| } else{ | |
| existingDiff.toggle(); | |
| } | |
| } | |
| ); | |
| })(); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment