Comparing version 0.1.1 to 1.0.0
@@ -1,193 +0,13 @@ | ||
/*! ghembedder - v0.1.0 - 2012-08-28 | ||
* https://github.com/kirbysayshi/ghembedder | ||
* Copyright (c) 2012 Andrew Petersen; Licensed MIT */ | ||
/* | ||
* Copyright (c) 2010 Nick Galbreath | ||
* http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
/** | ||
* Modules in this bundle | ||
* | ||
* ghembedder: | ||
* license: MIT | ||
* author: Andrew Petersen <senofpeter@gmail.com> | ||
* | ||
*/ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ghembedder=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/* base64 encode/decode compatible with window.btoa/atob | ||
* | ||
* window.atob/btoa is a Firefox extension to convert binary data (the "b") | ||
* to base64 (ascii, the "a"). | ||
* | ||
* It is also found in Safari and Chrome. It is not available in IE. | ||
* | ||
* if (!window.btoa) window.btoa = base64.encode | ||
* if (!window.atob) window.atob = base64.decode | ||
* | ||
* The original spec's for atob/btoa are a bit lacking | ||
* https://developer.mozilla.org/en/DOM/window.atob | ||
* https://developer.mozilla.org/en/DOM/window.btoa | ||
* | ||
* window.btoa and base64.encode takes a string where charCodeAt is [0,255] | ||
* If any character is not [0,255], then an DOMException(5) is thrown. | ||
* | ||
* window.atob and base64.decode take a base64-encoded string | ||
* If the input length is not a multiple of 4, or contains invalid characters | ||
* then an DOMException(5) is thrown. | ||
*/ | ||
;(function(window) { | ||
var base64 = window.base64 = {}; | ||
base64.PADCHAR = '='; | ||
base64.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
base64.makeDOMException = function() { | ||
// sadly in FF,Safari,Chrome you can't make a DOMException | ||
// not available, just passback a duck-typed equiv | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error/prototype | ||
var ex = new Error("DOM Exception 5"); | ||
// ex.number and ex.description is IE-specific. | ||
ex.code = ex.number = 5; | ||
ex.name = ex.description = "INVALID_CHARACTER_ERR"; | ||
// Safari/Chrome output format | ||
ex.toString = function() { return 'Error: ' + ex.name + ': ' + ex.message; }; | ||
return ex; | ||
}; | ||
base64.getbyte64 = function(s,i) { | ||
// This is oddly fast, except on Chrome/V8. | ||
// Minimal or no improvement in performance by using a | ||
// object with properties mapping chars to value (eg. 'A': 0) | ||
var idx = base64.ALPHA.indexOf(s.charAt(i)); | ||
if (idx === -1) { | ||
throw base64.makeDOMException(); | ||
} | ||
return idx; | ||
}; | ||
base64.decode = function(s) { | ||
// convert to string | ||
s = '' + s; | ||
var getbyte64 = base64.getbyte64; | ||
var pads, i, b10; | ||
var imax = s.length; | ||
if (imax === 0) { | ||
return s; | ||
} | ||
if (imax % 4 !== 0) { | ||
throw base64.makeDOMException(); | ||
} | ||
pads = 0; | ||
if (s.charAt(imax - 1) === base64.PADCHAR) { | ||
pads = 1; | ||
if (s.charAt(imax - 2) === base64.PADCHAR) { | ||
pads = 2; | ||
} | ||
// either way, we want to ignore this last block | ||
imax -= 4; | ||
} | ||
var x = []; | ||
for (i = 0; i < imax; i += 4) { | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | | ||
(getbyte64(s,i+2) << 6) | getbyte64(s,i+3); | ||
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff)); | ||
} | ||
switch (pads) { | ||
case 1: | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | (getbyte64(s,i+2) << 6); | ||
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff)); | ||
break; | ||
case 2: | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12); | ||
x.push(String.fromCharCode(b10 >> 16)); | ||
break; | ||
} | ||
return x.join(''); | ||
}; | ||
base64.getbyte = function(s,i) { | ||
var x = s.charCodeAt(i); | ||
if (x > 255) { | ||
throw base64.makeDOMException(); | ||
} | ||
return x; | ||
}; | ||
base64.encode = function(s) { | ||
if (arguments.length !== 1) { | ||
throw new SyntaxError("Not enough arguments"); | ||
} | ||
var padchar = base64.PADCHAR; | ||
var alpha = base64.ALPHA; | ||
var getbyte = base64.getbyte; | ||
var i, b10; | ||
var x = []; | ||
// convert to string | ||
s = '' + s; | ||
var imax = s.length - s.length % 3; | ||
if (s.length === 0) { | ||
return s; | ||
} | ||
for (i = 0; i < imax; i += 3) { | ||
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8) | getbyte(s,i+2); | ||
x.push(alpha.charAt(b10 >> 18)); | ||
x.push(alpha.charAt((b10 >> 12) & 0x3F)); | ||
x.push(alpha.charAt((b10 >> 6) & 0x3f)); | ||
x.push(alpha.charAt(b10 & 0x3f)); | ||
} | ||
switch (s.length - imax) { | ||
case 1: | ||
b10 = getbyte(s,i) << 16; | ||
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) + | ||
padchar + padchar); | ||
break; | ||
case 2: | ||
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8); | ||
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) + | ||
alpha.charAt((b10 >> 6) & 0x3f) + padchar); | ||
break; | ||
} | ||
return x.join(''); | ||
}; | ||
}(window)); | ||
if (!window.btoa) { window.btoa = window.base64.encode; } | ||
if (!window.atob) { window.atob = window.base64.decode; } | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Begin the actual ghembedder code... | ||
/////////////////////////////////////////////////////////////////////////////// | ||
;(function(exports) { | ||
var ghe = exports.ghe = { | ||
var ghe = module.exports = { | ||
_apiBase: 'https://api.github.com' | ||
,_callbacks: {} | ||
,_library: {} | ||
@@ -205,7 +25,7 @@ ,_rLeadSlash: /^\/+|\/+$/g | ||
ghe._keygen = function(){ | ||
return 'ghe_' + ~~(Math.random() * 100000); | ||
return 'ghembedder_key_' + ~~(Math.random() * 100000); | ||
}; | ||
ghe._jsonpCallback = function(key){ | ||
return ghe._callbacks[key] = function(resp){ | ||
return window[key] = function(resp){ | ||
var lib = ghe._library[key] | ||
@@ -224,7 +44,14 @@ ,linenos = false | ||
decoded = ghe._decodeContent( resp.data.content ); | ||
//check if the file is htm(l) | ||
if (lib.fileName.match(/.*\.htm[l]*$/)){ | ||
//replace the tags so that they will be interpreted as text, and not source | ||
decoded = decoded.replace(/</g,"<").replace(/>/g,">"); | ||
} | ||
//replace the tags so that they will be interpreted as text, and not source | ||
decoded = decoded.replace(/[&<>"'`]/g, (function() { | ||
var chars = { | ||
"&": "&" | ||
,"<": "<" | ||
,">": ">" | ||
,'"': """ | ||
,"'": "'" | ||
,"`": "`" | ||
} | ||
return function(match) { return chars[match]; } | ||
}())); | ||
lines = decoded.split('\n'); | ||
@@ -264,2 +91,8 @@ | ||
: ''); | ||
// Remove the reference to this function. | ||
delete window[key]; | ||
if (lib.onload) { | ||
lib.onload(null, lib); | ||
} | ||
} | ||
@@ -287,3 +120,3 @@ }; | ||
var script = document.createElement('script'); | ||
script.async = true; | ||
script.type = 'text/javascript'; | ||
script.src = fileUrl | ||
@@ -334,3 +167,3 @@ + (fileUrl.indexOf('?') > -1 ? '&' : '?') | ||
/////////////////////////////////////////////////////////////////////////////// | ||
ghe.load = function(cfg){ | ||
ghe.load = function(cfg, opt_cb){ | ||
@@ -342,3 +175,7 @@ var key = ghe._keygen(); | ||
} | ||
if (opt_cb) { | ||
cfg.onload = opt_cb; | ||
} | ||
ghe._jsonpCallback(key); | ||
@@ -353,3 +190,3 @@ ghe._library[key] = cfg; | ||
+ '?ref=' + cfg.ref | ||
,'ghe._callbacks.' + key | ||
, key | ||
); | ||
@@ -376,2 +213,3 @@ }; | ||
}(typeof window === 'object' && window || this)); | ||
},{}]},{},[1])(1) | ||
}); |
@@ -1,4 +0,9 @@ | ||
/*! ghembedder - v0.1.0 - 2012-08-28 | ||
* https://github.com/kirbysayshi/ghembedder | ||
* Copyright (c) 2012 Andrew Petersen; Licensed MIT */ | ||
(function(a){var b=a.base64={};b.PADCHAR="=",b.ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b.makeDOMException=function(){var a=new Error("DOM Exception 5");return a.code=a.number=5,a.name=a.description="INVALID_CHARACTER_ERR",a.toString=function(){return"Error: "+a.name+": "+a.message},a},b.getbyte64=function(a,c){var d=b.ALPHA.indexOf(a.charAt(c));if(d===-1)throw b.makeDOMException();return d},b.decode=function(a){a=""+a;var c=b.getbyte64,d,e,f,g=a.length;if(g===0)return a;if(g%4!==0)throw b.makeDOMException();d=0,a.charAt(g-1)===b.PADCHAR&&(d=1,a.charAt(g-2)===b.PADCHAR&&(d=2),g-=4);var h=[];for(e=0;e<g;e+=4)f=c(a,e)<<18|c(a,e+1)<<12|c(a,e+2)<<6|c(a,e+3),h.push(String.fromCharCode(f>>16,f>>8&255,f&255));switch(d){case 1:f=c(a,e)<<18|c(a,e+1)<<12|c(a,e+2)<<6,h.push(String.fromCharCode(f>>16,f>>8&255));break;case 2:f=c(a,e)<<18|c(a,e+1)<<12,h.push(String.fromCharCode(f>>16))}return h.join("")},b.getbyte=function(a,c){var d=a.charCodeAt(c);if(d>255)throw b.makeDOMException();return d},b.encode=function(a){if(arguments.length!==1)throw new SyntaxError("Not enough arguments");var c=b.PADCHAR,d=b.ALPHA,e=b.getbyte,f,g,h=[];a=""+a;var i=a.length-a.length%3;if(a.length===0)return a;for(f=0;f<i;f+=3)g=e(a,f)<<16|e(a,f+1)<<8|e(a,f+2),h.push(d.charAt(g>>18)),h.push(d.charAt(g>>12&63)),h.push(d.charAt(g>>6&63)),h.push(d.charAt(g&63));switch(a.length-i){case 1:g=e(a,f)<<16,h.push(d.charAt(g>>18)+d.charAt(g>>12&63)+c+c);break;case 2:g=e(a,f)<<16|e(a,f+1)<<8,h.push(d.charAt(g>>18)+d.charAt(g>>12&63)+d.charAt(g>>6&63)+c)}return h.join("")}})(window),window.btoa||(window.btoa=window.base64.encode),window.atob||(window.atob=window.base64.decode),function(a){var b=a.ghe={_apiBase:"https://api.github.com",_callbacks:{},_library:{},_rLeadSlash:/^\/+|\/+$/g,_rWhiteSpace:/\s/g};b._decodeContent=function(a){var c=window.atob(a.replace(b._rWhiteSpace,""));return c},b._keygen=function(){return"ghe_"+~~(Math.random()*1e5)},b._jsonpCallback=function(c){return b._callbacks[c]=function(d){var e=b._library[c],f=!1,g=e.lineBegin>-1&&e.lineEnd>-1,h,i,j,k=(new Array(e.tabSize+1)).join(" ");d.data&&d.data.content&&(e.data=d.data,h=b._decodeContent(d.data.content),e.fileName.match(/.*\.htm[l]*$/)&&(h=h.replace(/</g,"<").replace(/>/g,">")),i=h.split("\n"),g&&(i=i.splice(e.lineBegin-1,e.lineEnd-e.lineBegin+1)),e.linenos&&(f=g?e.lineBegin:e.linenos),i=i.map(function(a,b){return'<a class="nocode" id="'+e.fileName+"-L"+(b+e.lineBegin)+'">'+(a?"":" ")+"</a>"+a.replace(/\t/gi,k)}),h=i.join("\n"),a.prettyPrintOne&&(h=a.prettyPrintOne(h,e.lang,f)),e.el.className+=" ghe",e.el.innerHTML='<pre class="prettyprint"><code>'+h+"</code></pre>"+(e.annotate?b._annotation(c):""))}},b._annotation=function(a){var c=b._library[a],d=c.lineBegin>-1&&c.lineEnd>-1;return'<div class="ghe-annotation">'+c.fileName+(d?", lines "+c.lineBegin+"-"+c.lineEnd:"")+(c.data?'. <a href="'+c.data._links.html+'" target="_blank">Source</a>':"")+"</div>"},b._jsonp=function(a,b){var c=document.createElement("script");c.async=!0,c.src=a+(a.indexOf("?")>-1?"&":"?")+"callback="+b,document.getElementsByTagName("head")[0].appendChild(c)},b._parseNode=function(a){var b=a.getAttribute("data-ghlines"),c=a.getAttribute("data-ghpath"),d,e;return b&&b.indexOf("-")>-1?(b=b.split("-"),d=parseInt(b[0],10),e=parseInt(b[1],10)):b?d=e=parseInt(b,10):d=e=-1,{path:c,userrepo:a.getAttribute("data-ghuserrepo"),ref:a.getAttribute("data-ghref")||"master",lineBegin:d,lineEnd:e,el:a,fileName:c.split("/").pop(),lang:a.getAttribute("data-ghlang"),linenos:a.getAttribute("data-ghlinenos"),annotate:a.getAttribute("data-ghannotate"),tabSize:parseInt(a.getAttribute("data-ghtabsize"),10)||4}},b.load=function(a){var c=b._keygen();a.nodeName&&(a=b._parseNode(a)),b._jsonpCallback(c),b._library[c]=a,b._jsonp(b._apiBase+"/repos/"+a.userrepo.replace(b._rLeadSlash,"")+"/contents/"+a.path.replace(b._rLeadSlash,"")+"?ref="+a.ref,"ghe._callbacks."+c)},b.autoload=function(){var a;window.jQuery?a=window.jQuery("[data-ghpath]"):a=document.querySelectorAll("[data-ghpath]");for(var c=0;c<a.length;c++)b.load(a[c])}}(typeof window=="object"&&window||this); | ||
/** | ||
* Modules in this bundle | ||
* | ||
* ghembedder: | ||
* license: MIT | ||
* author: Andrew Petersen <senofpeter@gmail.com> | ||
* | ||
*/ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ghembedder=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var ghe=module.exports={_apiBase:"https://api.github.com",_library:{},_rLeadSlash:/^\/+|\/+$/g,_rWhiteSpace:/\s/g};ghe._decodeContent=function(content){var decoded=window.atob(content.replace(ghe._rWhiteSpace,""));return decoded};ghe._keygen=function(){return"ghembedder_key_"+~~(Math.random()*1e5)};ghe._jsonpCallback=function(key){return window[key]=function(resp){var lib=ghe._library[key],linenos=false,hasLineRange=lib.lineBegin>-1&&lib.lineEnd>-1,decoded,lines,nums,tabSpace=new Array(lib.tabSize+1).join(" ");if(resp.data&&resp.data.content){lib.data=resp.data;decoded=ghe._decodeContent(resp.data.content);decoded=decoded.replace(/[&<>"'`]/g,function(){var chars={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};return function(match){return chars[match]}}());lines=decoded.split("\n");if(hasLineRange){lines=lines.splice(lib.lineBegin-1,lib.lineEnd-lib.lineBegin+1)}if(lib.linenos){linenos=hasLineRange?lib.lineBegin:lib.linenos}lines=lines.map(function(l,i){return'<a class="nocode" id="'+lib.fileName+"-L"+(i+lib.lineBegin)+'">'+(l?"":" ")+"</a>"+l.replace(/\t/gi,tabSpace)});decoded=lines.join("\n");if(exports.prettyPrintOne){decoded=exports.prettyPrintOne(decoded,lib.lang,linenos)}lib.el.className+=" ghe";lib.el.innerHTML='<pre class="prettyprint"><code>'+decoded+"</code></pre>"+(lib.annotate?ghe._annotation(key):"");delete window[key];if(lib.onload){lib.onload(null,lib)}}}};ghe._annotation=function(key){var lib=ghe._library[key],hasLineRange=lib.lineBegin>-1&&lib.lineEnd>-1;return'<div class="ghe-annotation">'+lib.fileName+(hasLineRange?", lines "+lib.lineBegin+"-"+lib.lineEnd:"")+(lib.data?'. <a href="'+lib.data._links.html+'" target="_blank">Source</a>':"")+"</div>"};ghe._jsonp=function(fileUrl,cbName){var script=document.createElement("script");script.type="text/javascript";script.src=fileUrl+(fileUrl.indexOf("?")>-1?"&":"?")+"callback="+cbName;document.getElementsByTagName("head")[0].appendChild(script)};ghe._parseNode=function(el){var lines=el.getAttribute("data-ghlines"),path=el.getAttribute("data-ghpath"),start,end;if(lines&&lines.indexOf("-")>-1){lines=lines.split("-");start=parseInt(lines[0],10);end=parseInt(lines[1],10)}else if(lines){start=end=parseInt(lines,10)}else{start=end=-1}return{path:path,userrepo:el.getAttribute("data-ghuserrepo"),ref:el.getAttribute("data-ghref")||"master",lineBegin:start,lineEnd:end,el:el,fileName:path.split("/").pop(),lang:el.getAttribute("data-ghlang"),linenos:el.getAttribute("data-ghlinenos"),annotate:el.getAttribute("data-ghannotate"),tabSize:parseInt(el.getAttribute("data-ghtabsize"),10)||4}};ghe.load=function(cfg,opt_cb){var key=ghe._keygen();if(cfg.nodeName){cfg=ghe._parseNode(cfg)}if(opt_cb){cfg.onload=opt_cb}ghe._jsonpCallback(key);ghe._library[key]=cfg;ghe._jsonp(ghe._apiBase+"/repos/"+cfg.userrepo.replace(ghe._rLeadSlash,"")+"/contents/"+cfg.path.replace(ghe._rLeadSlash,"")+"?ref="+cfg.ref,key)};ghe.autoload=function(){var nodes;if(window.jQuery){nodes=window.jQuery("[data-ghpath]")}else{nodes=document.querySelectorAll("[data-ghpath]")}for(var i=0;i<nodes.length;i++){ghe.load(nodes[i])}}},{}]},{},[1])(1)}); |
{ | ||
"name": "ghembedder", | ||
"description": "Embed any source file (or specific lines) from any public github repo in your page, with no server-side dependencies.", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/kirbysayshi/ghembedder", | ||
"author": { | ||
"name": "Andrew Petersen", | ||
"email": "senofpeter@gmail.com", | ||
"url": "http://kirbysayshi.github.com" | ||
}, | ||
"author": "Andrew Petersen <senofpeter@gmail.com>", | ||
"repository": { | ||
@@ -18,9 +14,18 @@ "type": "git", | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/kirbysayshi/ghembedder/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"keywords": [] | ||
"scripts": { | ||
"bundle": "browserify --standalone ghembedder -p licensify src/ghembedder.js > dist/ghembedder.js", | ||
"dist": "npm run bundle && uglifyjs dist/ghembedder.js --comments '/Modules/' > dist/ghembedder.min.js", | ||
"test": "zuul --phantom --ui tape -- test.js", | ||
"test-debug": "zuul --local --open --ui tape -- test.js" | ||
}, | ||
"license": "MIT", | ||
"keywords": [], | ||
"devDependencies": { | ||
"browserify": "^8.0.3", | ||
"licensify": "^0.2.0", | ||
"phantomjs": "^1.9.13", | ||
"tape": "^3.0.3", | ||
"uglify-js": "^2.4.16", | ||
"zuul": "^1.16.3" | ||
} | ||
} |
@@ -71,3 +71,4 @@ # ghembedder | ||
Load lines 743-768 from `src/core.js` of the jQuery repo @ 714b8ffd2b28af446fea8f25e369597d7c509cb4 | ||
Load lines 743-768 from `src/core.js` of the jQuery repo `@ 714b8ffd2b28af446fea8f25e369597d7c509cb4` | ||
<div | ||
@@ -111,14 +112,21 @@ data-ghuserrepo="jquery/jquery" | ||
## Contributing | ||
Please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory! | ||
Please don't edit files in the "dist" subdirectory as they are generated. You'll find source code in the "src" subdirectory! | ||
Install grunt: | ||
- `npm install` | ||
`npm install grunt -g` | ||
To run tests via zuul / phantomjs: | ||
And then run it to update the `dist` folder: | ||
- `npm test` | ||
`grunt` | ||
To run tests in an actual browser: | ||
- `npm run test-debug` | ||
To build: | ||
- `npm run dist` | ||
## Release History | ||
- 1.0.0: Remove btoa/atob shim. Always html escape content. | ||
- 0.1.1: Basic html escaping if extension matches `.htm|.html` | ||
@@ -128,11 +136,7 @@ - 0.1.0: initial release | ||
## License | ||
Copyright (c) 2012 Andrew Petersen | ||
Licensed under the MIT license. | ||
[base64][] is Copyright (c) 2010 Nick Galbreath | ||
MIT | ||
## Thanks | ||
Ben Alman, for [Grunt](https://github.com/cowboy/grunt/). | ||
[google-code-prettify]: https://code.google.com/p/google-code-prettify/ | ||
@@ -139,0 +143,0 @@ [min]: https://raw.github.com/kirbysayshi/ghembedder/master/dist/ghembedder.min.js |
@@ -1,199 +0,4 @@ | ||
/* | ||
* ghembedder | ||
* https://github.com/kirbysayshi/ghembedder | ||
* | ||
* Copyright (c) 2012 Andrew Petersen | ||
* Licensed under the MIT license. | ||
* | ||
* Examples and docs at: https://github.com/kirbysayshi/ghembedder | ||
*/ | ||
/* | ||
* Copyright (c) 2010 Nick Galbreath | ||
* http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
/* base64 encode/decode compatible with window.btoa/atob | ||
* | ||
* window.atob/btoa is a Firefox extension to convert binary data (the "b") | ||
* to base64 (ascii, the "a"). | ||
* | ||
* It is also found in Safari and Chrome. It is not available in IE. | ||
* | ||
* if (!window.btoa) window.btoa = base64.encode | ||
* if (!window.atob) window.atob = base64.decode | ||
* | ||
* The original spec's for atob/btoa are a bit lacking | ||
* https://developer.mozilla.org/en/DOM/window.atob | ||
* https://developer.mozilla.org/en/DOM/window.btoa | ||
* | ||
* window.btoa and base64.encode takes a string where charCodeAt is [0,255] | ||
* If any character is not [0,255], then an DOMException(5) is thrown. | ||
* | ||
* window.atob and base64.decode take a base64-encoded string | ||
* If the input length is not a multiple of 4, or contains invalid characters | ||
* then an DOMException(5) is thrown. | ||
*/ | ||
;(function(window) { | ||
var base64 = window.base64 = {}; | ||
base64.PADCHAR = '='; | ||
base64.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
base64.makeDOMException = function() { | ||
// sadly in FF,Safari,Chrome you can't make a DOMException | ||
// not available, just passback a duck-typed equiv | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error | ||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error/prototype | ||
var ex = new Error("DOM Exception 5"); | ||
// ex.number and ex.description is IE-specific. | ||
ex.code = ex.number = 5; | ||
ex.name = ex.description = "INVALID_CHARACTER_ERR"; | ||
// Safari/Chrome output format | ||
ex.toString = function() { return 'Error: ' + ex.name + ': ' + ex.message; }; | ||
return ex; | ||
}; | ||
base64.getbyte64 = function(s,i) { | ||
// This is oddly fast, except on Chrome/V8. | ||
// Minimal or no improvement in performance by using a | ||
// object with properties mapping chars to value (eg. 'A': 0) | ||
var idx = base64.ALPHA.indexOf(s.charAt(i)); | ||
if (idx === -1) { | ||
throw base64.makeDOMException(); | ||
} | ||
return idx; | ||
}; | ||
base64.decode = function(s) { | ||
// convert to string | ||
s = '' + s; | ||
var getbyte64 = base64.getbyte64; | ||
var pads, i, b10; | ||
var imax = s.length; | ||
if (imax === 0) { | ||
return s; | ||
} | ||
if (imax % 4 !== 0) { | ||
throw base64.makeDOMException(); | ||
} | ||
pads = 0; | ||
if (s.charAt(imax - 1) === base64.PADCHAR) { | ||
pads = 1; | ||
if (s.charAt(imax - 2) === base64.PADCHAR) { | ||
pads = 2; | ||
} | ||
// either way, we want to ignore this last block | ||
imax -= 4; | ||
} | ||
var x = []; | ||
for (i = 0; i < imax; i += 4) { | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | | ||
(getbyte64(s,i+2) << 6) | getbyte64(s,i+3); | ||
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff)); | ||
} | ||
switch (pads) { | ||
case 1: | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12) | (getbyte64(s,i+2) << 6); | ||
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff)); | ||
break; | ||
case 2: | ||
b10 = (getbyte64(s,i) << 18) | (getbyte64(s,i+1) << 12); | ||
x.push(String.fromCharCode(b10 >> 16)); | ||
break; | ||
} | ||
return x.join(''); | ||
}; | ||
base64.getbyte = function(s,i) { | ||
var x = s.charCodeAt(i); | ||
if (x > 255) { | ||
throw base64.makeDOMException(); | ||
} | ||
return x; | ||
}; | ||
base64.encode = function(s) { | ||
if (arguments.length !== 1) { | ||
throw new SyntaxError("Not enough arguments"); | ||
} | ||
var padchar = base64.PADCHAR; | ||
var alpha = base64.ALPHA; | ||
var getbyte = base64.getbyte; | ||
var i, b10; | ||
var x = []; | ||
// convert to string | ||
s = '' + s; | ||
var imax = s.length - s.length % 3; | ||
if (s.length === 0) { | ||
return s; | ||
} | ||
for (i = 0; i < imax; i += 3) { | ||
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8) | getbyte(s,i+2); | ||
x.push(alpha.charAt(b10 >> 18)); | ||
x.push(alpha.charAt((b10 >> 12) & 0x3F)); | ||
x.push(alpha.charAt((b10 >> 6) & 0x3f)); | ||
x.push(alpha.charAt(b10 & 0x3f)); | ||
} | ||
switch (s.length - imax) { | ||
case 1: | ||
b10 = getbyte(s,i) << 16; | ||
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) + | ||
padchar + padchar); | ||
break; | ||
case 2: | ||
b10 = (getbyte(s,i) << 16) | (getbyte(s,i+1) << 8); | ||
x.push(alpha.charAt(b10 >> 18) + alpha.charAt((b10 >> 12) & 0x3F) + | ||
alpha.charAt((b10 >> 6) & 0x3f) + padchar); | ||
break; | ||
} | ||
return x.join(''); | ||
}; | ||
}(window)); | ||
if (!window.btoa) { window.btoa = window.base64.encode; } | ||
if (!window.atob) { window.atob = window.base64.decode; } | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Begin the actual ghembedder code... | ||
/////////////////////////////////////////////////////////////////////////////// | ||
;(function(exports) { | ||
var ghe = exports.ghe = { | ||
var ghe = module.exports = { | ||
_apiBase: 'https://api.github.com' | ||
,_callbacks: {} | ||
,_library: {} | ||
@@ -211,7 +16,7 @@ ,_rLeadSlash: /^\/+|\/+$/g | ||
ghe._keygen = function(){ | ||
return 'ghe_' + ~~(Math.random() * 100000); | ||
return 'ghembedder_key_' + ~~(Math.random() * 100000); | ||
}; | ||
ghe._jsonpCallback = function(key){ | ||
return ghe._callbacks[key] = function(resp){ | ||
return window[key] = function(resp){ | ||
var lib = ghe._library[key] | ||
@@ -230,7 +35,14 @@ ,linenos = false | ||
decoded = ghe._decodeContent( resp.data.content ); | ||
//check if the file is htm(l) | ||
if (lib.fileName.match(/.*\.htm[l]*$/)){ | ||
//replace the tags so that they will be interpreted as text, and not source | ||
decoded = decoded.replace(/</g,"<").replace(/>/g,">"); | ||
} | ||
//replace the tags so that they will be interpreted as text, and not source | ||
decoded = decoded.replace(/[&<>"'`]/g, (function() { | ||
var chars = { | ||
"&": "&" | ||
,"<": "<" | ||
,">": ">" | ||
,'"': """ | ||
,"'": "'" | ||
,"`": "`" | ||
} | ||
return function(match) { return chars[match]; } | ||
}())); | ||
lines = decoded.split('\n'); | ||
@@ -270,2 +82,8 @@ | ||
: ''); | ||
// Remove the reference to this function. | ||
delete window[key]; | ||
if (lib.onload) { | ||
lib.onload(null, lib); | ||
} | ||
} | ||
@@ -293,3 +111,3 @@ }; | ||
var script = document.createElement('script'); | ||
script.async = true; | ||
script.type = 'text/javascript'; | ||
script.src = fileUrl | ||
@@ -340,3 +158,3 @@ + (fileUrl.indexOf('?') > -1 ? '&' : '?') | ||
/////////////////////////////////////////////////////////////////////////////// | ||
ghe.load = function(cfg){ | ||
ghe.load = function(cfg, opt_cb){ | ||
@@ -348,3 +166,7 @@ var key = ghe._keygen(); | ||
} | ||
if (opt_cb) { | ||
cfg.onload = opt_cb; | ||
} | ||
ghe._jsonpCallback(key); | ||
@@ -359,3 +181,3 @@ ghe._library[key] = cfg; | ||
+ '?ref=' + cfg.ref | ||
,'ghe._callbacks.' + key | ||
, key | ||
); | ||
@@ -381,3 +203,1 @@ }; | ||
}; | ||
}(typeof window === 'object' && window || this)); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
143
0
22662
6
8
380
4
2