Permalink
Browse files

moving to separate file, updating readme, cleanup

  • Loading branch information...
1 parent 6fc816a commit b680e51ab65d97637ea25f56ca8041186e2d435f @addyosmani committed Oct 30, 2011
Showing with 131 additions and 129 deletions.
  1. +15 −1 README.md
  2. +1 −128 buttons.html
  3. +115 −0 github-watchers.js
View
@@ -1 +1,15 @@
-A holding page for a new project.
+##GitHub Watchers - a bookmarklet for showing the number of people watching a repository on GitHub
+
+
+<ul>
+###changes made:
+<ul>
+<li>Added watchers capability from API</li>
+<li>Stripped non-cross browser offline storage implem</li>
+<li>Cleaned up some of the code</li>
+<li>Added cross-browser styling</li>
+<li>Added window/doc to IIFE</li>
+<li>Moving towards jsHint compatability</li>
+</ul>
+</ul>
+
View
@@ -8,134 +8,7 @@
<body>
-<script type="text/javascript">
-/*
- gitwatchers.js - styles and populates a link with a GitHub repo's watchers count
- by Addy Osmani
- Based on gitfollow by Guillermo Rauch
- Released under an MIT-license
-*/
-
-
-(function (window, document) {
-
-
-/*
- changes made:
- Added watchers capability from API
- Stripped non-cross browser offline storage implem
- Cleaned up some of the code
- Added cross-browser styling
- Added window/doc to IIFE
- Moving towards jsHint compatability
- */
-
- window.gitwatch = {
-
- text: '% watchers',
-
- styles: [
- '.gitwatch { background: #fafafa; background-color: #fbfbfb; background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fbfbfb), to(#cccccc)); background-image: -webkit-linear-gradient(#fbfbfb, #cccccc); background-image: -moz-linear-gradient(#fbfbfb, #cccccc); background-image: -ms-linear-gradient(#fbfbfb, #cccccc); background-image: -o-linear-gradient(#fbfbfb, #cccccc); background-image: linear-gradient(#fbfbfb, #cccccc); font: 11px "Lucida Grande", Verdana, sans-serif; outline: 0; -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); font-weight: bold; line-height: 1; cursor: pointer; position: relative; text-decoration: none; width: auto; border-bottom-color: rgba(0, 0, 0, 0.3); -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius:15px; padding: 4px 14px 6px; color: #4183C4; text-shadow: 0 1px 0 #fff; }',
- '.gitwatch:active { top: 1px; }',
- '.gitwatch:hover { background: #eee; text-decoration: none; }',
- '.gitwatch img { vertical-align: middle; padding-right: 5px; border: 0; }',
- '.gitwatch.large { padding: 10px 30px 8px; font-size:30px; letter-spacing:-2px; bottom:5px; }',
- '.gitwatch.small { padding: 2px 14px 4px; }'
- ],
-
- logo: 'data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%20%00%00%00%0F%08%06%00%00%00%85%80%CD%17%00%00%00%04sBIT%08%08%08%08%7C%08d%88%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%D2%DD~%FC%00%00%00%1CtEXtSoftware%00Adobe%20Fireworks%20CS4%06%B2%D3%A0%00%00%00%15tEXtCreation%20Time%0012%2F8%2F09%5E%88%A8%A3%00%00%048IDAT8%8D%BD%94%5DH%DBW%18%C6%7F%E7%FCc%3E%5C%14%17%B3%D8%A4Z%8Bq%A0%0E%D7X%E9%CA%3E%B2*tq%A3%DB%C5F%95%0E%0B%B6%17%A3%B0R%98%D0%0D3%D8%CD%3A%84%89%D8%CB%C9.%DC%06k%A1s%A30%9C%A3%A8utS%CAZ%91d%E9%8ARi%3B%1Bp%A1%BAL%B3%A6%89%F9%E7%DDEc)%B2%8E%5E%F5%B9%3B%BF%F7y%DF%F3%C0y9%F0p9%81%F3%C0%9B%FFQ%DB%02%9C%03%C2%FF%D3%BFY_%02_%3C%B2%BB%A2%A2%E2%00%20%5E%AF%F7%B7%CD%B5c%C7%8E5%01%D2%D4%D4%14%7D%D4y%1E%8Fg%B5%A2%A2bu3%D7%0Fk%18%1B%1B3zzz8y%F2%A4Y%40%1F%00%1D%00%E5%E5%E5Jk%8D%CB%E5*%7B%D4%00%0E%87%C3%EEt%3A%ED%9B%B9%E5%81%20%AF%01V%E0W%C0%D5%DF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C5R%5EH%AF%26\'\'%B5%D5je~~%BE%14%E8%9C%9A%9Az%CAb%B1%20%22%06%40%3E%9F%B7%00%14%17%17%A7%FD~%7F%F6%DA%B5k%0E%E0%FD%C1%C1%C1%B7%00%B4%D6%D8%EDv%B9q%E3%86%15%F8htt%B4%1F%A0%B7%B7%17%AD%94%BA%9DL%26%E3%00%A7N%9D%1A%A9%AB%AB%7B%5B)%B5%E8%F3%F9%ACZkr%B9%5CQKKK%B6%B3%B33%97H%24%1C%C0%D7Z%EB%1DN%A7%13%A5%94%06%B8%7B%F7%AE%5D)%C5%CA%CA%0A%3D%3D%3D%97%5D.%17%40_%3A%9D~%CE0%0C2%99%8C6%0C%C3%B4%D9l%00%1F%A7R%A9%9D%DD%DD%DD%84%C3%E1%0F%01%5E%F0%FB%FD%D7%BD%5E%AF%B8%5C%AEdaK%CF%C6b%B1%1D%91H%C4%8C%C5b%9F%03%88%C8g%D3%D3%D32%3B%3B%2B%F1x%FC%40%24%12%F9%3B%16%8B%8D%02%C4b%B1%AE%99%99%99%FC%CC%CC%CC%7B%22%12%88%C7%E3%7F%CD%CE%CE%CA%EA%EA%EAr4%1A5%A3%D1%E8%91H%24%F2%F3%CD%9B7%EF%2C..%CA%95%2BWDD%066%DEF%00%B9z%F5jBD%AE%1F%3E%7CX%00ill%AC%13%91gE%C4w%DF(%F2%BC%88%04D%C4!%22%CF%88Hu%81%97%89%C8N%11%F1%14%CE%5B%0A%3E%A7%884%8A%88KD%FC%22R%25%22%95%22%D2p%7F3%C2%E1%B0%94%95%95%89%DDn%FF%1D%F8%DE%E1pdB%A1%90%2C%2C%2C%3C%CD%E3%90%88%F4%9E%3E%7D%3A%B5%F1I%04%83%C1%F5%A5%A5%A5%F3%22R%F4X%02%14B%B4%8B%88)%F74)%22O%3E%AE%BB%FF%05%F5a%F7%07%0C%EA%3Aj%00%00%00%00IEND%AEB%60%82',
-
- className: 'gitwatch',
-
- injectScript: function (src) {
- var script = document.createElement('script');
- script.src = src;
- document.body.appendChild(script);
- },
-
- applyCss: function (css) {
- var style = document.createElement('style');
- style.type = 'text/css';
-
- try {
- style.appendChild(document.createTextNode(css));
- } catch (e) {
- if (style.styleSheet) {
- style.styleSheet.cssText = css;
- }
- }
-
- document.body.appendChild(style);
- },
-
-
- getByClass: function () {
- if (document.getElementsByClassName) {
- return document.getElementsByClassName('gitwatch');
- } else {
- var links = document.getElementsByTagName('a'),
- found = [];
- for (var i = 0, l = links.length; i < l; i++) {
- if ((' ' + this + ' ').indexOf(' ' + links[i].className + ' ') > -1) {
- found.push(links[i]);
- }
- }
- return found;
- }
- },
-
- run: function () {
- this.elements = this.getByClass(this.className);
- if (this.elements && this.elements.length === 0) {
- //if (window.console) console.log('No elements found to use with gitwatch.');
- return false;
- }
- var match = this.elements[0].href.match(/com\/([^\s\/]+)\/([^\s\/]+)/);
- if (!match || !match[1]) {
- //if (window.console) console.log('Bad GitHub URL ' + this.elements[0].href);
- return false;
- }
-
- this.username = match[1];
- this.reponame = match[2];
-
- this.injectScript('http://github.com/api/v2/json/repos/show/' + encodeURIComponent(this.username) + '/' + encodeURIComponent(this.reponame) + '?callback=' + encodeURIComponent('gitwatch.callback'));
- },
-
- callback: function (object) {
- if (object && object.repository) {
- this.apply(object.repository.watchers);
- }
- },
-
- apply: function (count) {
- this.applyCss(this.styles.join(''));
- var img = '<img src="' + this.logo + '" /> ',
- text = "";
- for (var i = 0, l = this.elements.length; i < l; i++) {
- if (this.elements[i].className.indexOf('small') > 0) {
- text = img + count;
- } else {
- text = img + this.text.replace(/%/, count);
- }
- this.elements[i].innerHTML = text;
- }
- }
-
- };
-
- run = function () {
- window.gitwatch.run();
- };
-
- if (document.addEventListener) {
- document.addEventListener('DOMContentLoaded', run , false);
- } else if (window.attachEvent) {
- window.attachEvent('onload', run);
- }
-
-})(window, document);
-</script>
+<script type="text/javascript" src="github-watchers.js"></script>
<p><a href="http://github.com/addyosmani/todomvc" target="_blank" class="gitwatch large">followers</a></p>
<p><a href="http://github.com/addyosmani/todomvc" target="_blank" class="gitwatch">followers</a></p>
View
@@ -0,0 +1,115 @@
+/*
+ gitwatchers.js - styles and populates a link with a GitHub repo's watchers count
+ by Addy Osmani
+ Based on gitfollow by Guillermo Rauch
+ Released under an MIT-license
+*/
+
+
+;(function (window, document) {
+
+ window.gitwatch = {
+
+ text: '% watchers',
+
+ styles: [
+ '.gitwatch { background: #fafafa; background-color: #fbfbfb; background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fbfbfb), to(#cccccc)); background-image: -webkit-linear-gradient(#fbfbfb, #cccccc); background-image: -moz-linear-gradient(#fbfbfb, #cccccc); background-image: -ms-linear-gradient(#fbfbfb, #cccccc); background-image: -o-linear-gradient(#fbfbfb, #cccccc); background-image: linear-gradient(#fbfbfb, #cccccc); font: 11px "Lucida Grande", Verdana, sans-serif; outline: 0; -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); font-weight: bold; line-height: 1; cursor: pointer; position: relative; text-decoration: none; width: auto; border-bottom-color: rgba(0, 0, 0, 0.3); -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius:15px; padding: 4px 14px 6px; color: #4183C4; text-shadow: 0 1px 0 #fff; }',
+ '.gitwatch:active { top: 1px; }',
+ '.gitwatch:hover { background: #eee; text-decoration: none; }',
+ '.gitwatch img { vertical-align: middle; padding-right: 5px; border: 0; }',
+ '.gitwatch.large { padding: 10px 30px 8px; font-size:30px; letter-spacing:-2px; bottom:5px; }',
+ '.gitwatch.small { padding: 2px 14px 4px; }'
+ ],
+
+ logo: 'data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%20%00%00%00%0F%08%06%00%00%00%85%80%CD%17%00%00%00%04sBIT%08%08%08%08%7C%08d%88%00%00%00%09pHYs%00%00%0B%12%00%00%0B%12%01%D2%DD~%FC%00%00%00%1CtEXtSoftware%00Adobe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%CF%C6b%B1%1D%91H%C4%8C%C5b%9F%03%88%C8g%D3%D3%D32%3B%3B%2B%F1x%FC%40%24%12%F9%3B%16%8B%8D%02%C4b%B1%AE%99%99%99%FC%CC%CC%CC%7B%22%12%88%C7%E3%7F%CD%CE%CE%CA%EA%EA%EAr4%1A5%A3%D1%E8%91H%24%F2%F3%CD%9B7%EF%2C..%CA%95%2BWDD%066%DEF%00%B9z%F5jBD%AE%1F%3E%7CX%00ill%AC%13%91gE%C4w%DF(%F2%BC%88%04D%C4!%22%CF%88Hu%81%97%89%C8N%11%F1%14%CE%5B%0A%3E%A7%884%8A%88KD%FC%22R%25%22%95%22%D2p%7F3%C2%E1%B0%94%95%95%89%DDn%FF%1D%F8%DE%E1pdB%A1%90%2C%2C%2C%3C%CD%E3%90%88%F4%9E%3E%7D%3A%B5%F1I%04%83%C1%F5%A5%A5%A5%F3%22R%F4X%02%14B%B4%8B%88)%F74)%22O%3E%AE%BB%FF%05%F5a%F7%07%0C%EA%3Aj%00%00%00%00IEND%AEB%60%82',
+
+ className: 'gitwatch',
+
+ injectScript: function (src) {
+ var script = document.createElement('script');
+ script.src = src;
+ document.body.appendChild(script);
+ },
+
+ applyCss: function (css) {
+ var style = document.createElement('style');
+ style.type = 'text/css';
+
+ try {
+ style.appendChild(document.createTextNode(css));
+ } catch (e) {
+ if (style.styleSheet) {
+ style.styleSheet.cssText = css;
+ }
+ }
+
+ document.body.appendChild(style);
+ },
+
+
+ getByClass: function () {
+ if (document.getElementsByClassName) {
+ return document.getElementsByClassName('gitwatch');
+ } else {
+ var links = document.getElementsByTagName('a'),
+ found = [];
+ for (var i = 0, l = links.length; i < l; i++) {
+ if ((' ' + this + ' ').indexOf(' ' + links[i].className + ' ') > -1) {
+ found.push(links[i]);
+ }
+ }
+ return found;
+ }
+ },
+
+ run: function () {
+ this.elements = this.getByClass(this.className);
+ if (this.elements && this.elements.length === 0) {
+ //if (window.console) console.log('No elements found to use with gitwatch.');
+ return false;
+ }
+ var match = this.elements[0].href.match(/com\/([^\s\/]+)\/([^\s\/]+)/);
+ if (!match || !match[1]) {
+ //if (window.console) console.log('Bad GitHub URL ' + this.elements[0].href);
+ return false;
+ }
+
+ this.username = match[1];
+ this.reponame = match[2];
+
+ this.injectScript('http://github.com/api/v2/json/repos/show/' + encodeURIComponent(this.username) + '/' + encodeURIComponent(this.reponame) + '?callback=' + encodeURIComponent('gitwatch.callback'));
+ },
+
+ callback: function (object) {
+ if (object && object.repository) {
+ this.apply(object.repository.watchers);
+ }
+ },
+
+ apply: function (count) {
+ this.applyCss(this.styles.join(''));
+ var img = '<img src="' + this.logo + '" /> ',
+ text = "";
+ for (var i = 0, l = this.elements.length; i < l; i++) {
+ if (this.elements[i].className.indexOf('small') > 0) {
+ text = img + count;
+ } else {
+ text = img + this.text.replace(/%/, count);
+ }
+ this.elements[i].innerHTML = text;
+ }
+ }
+
+ };
+
+ run = function () {
+ window.gitwatch.run();
+ };
+
+ if (document.addEventListener) {
+ document.addEventListener('DOMContentLoaded', run , false);
+ } else if (window.attachEvent) {
+ window.attachEvent('onload', run);
+ }
+
+})( window, document );

0 comments on commit b680e51

Please sign in to comment.