Skip to content

Instantly share code, notes, and snippets.

@hemanth
Created January 20, 2015 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemanth/5f5e72e071f99857a85d to your computer and use it in GitHub Desktop.
Save hemanth/5f5e72e071f99857a85d to your computer and use it in GitHub Desktop.
requirebin sketch
var center = require('center')
var el = document.createElement('img');
el.src=''
document.body.appendChild(center(el))
require=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 process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],center:[function(require,module,exports){(function(process){var exports=module.exports=function(el){center(el);function onResize(){center(el)}window.onresize=onResize;process.nextTick(onResize);return el};exports.center=center;function center(el,o){o=o||window;var w=o.innerWidth==null?o.clientWidth:o.innerWidth;var h=o.innerHeight==null?o.clientHeight:o.innerHeight;var cw=el.clientWidth;var ch=el.clientHeight;var l=w/2-cw/2;var t=h/2-ch/2;el.style.setProperty("position","absolute");el.style.setProperty("left",l+"px");el.style.setProperty("top",t+"px");return el}}).call(this,require("_process"))},{_process:1}]},{},[]);var center=require("center");var el=document.createElement("img");el.src="";document.body.appendChild(center(el));
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"center": "0.0.0"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment