made with requirebin
Last active
August 29, 2015 14:08
-
-
Save TooTallNate/789b7e9cefb8be3f8254 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains 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
var domPaste = require('dom-paste'); | |
console.log(domPaste); | |
var input = document.createElement('div'); | |
input.contentEditable = 'true'; | |
input.style.width='300px'; | |
input.style.height='100px'; | |
input.style.border='solid 1px black'; | |
document.body.appendChild(input); | |
input.onpaste = function (e) { | |
domPaste(e, function (data) { | |
console.log('data:', data); | |
while (data.firstChild) | |
document.body.appendChild(data.firstChild); | |
}); | |
console.log(e); | |
}; |
This file contains 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
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}({"dom-paste":[function(require,module,exports){function domPaste(e,callback){var selection=window.getSelection();var originalRange=selection.rangeCount>0?selection.getRangeAt(0):null;var container=document.createElement("div");container.contentEditable="true";var br=document.createElement("br");container.appendChild(br);document.body.appendChild(container);var observer=new MutationObserver(function(){if(br.parentNode){br.parentNode.removeChild(br)}e.target.focus();if(originalRange){selection.removeAllRanges();selection.addRange(originalRange)}observer.disconnect();try{callback(container)}finally{document.body.removeChild(container)}});observer.observe(container,{childList:true,attributes:true,characterData:true,subtree:true});container.focus();var range=document.createRange();range.selectNodeContents(container);selection.removeAllRanges();selection.addRange(range)}module.exports=domPaste},{}]},{},[]);var domPaste=require("dom-paste");console.log(domPaste);var input=document.createElement("div");input.contentEditable="true";input.style.width="300px";input.style.height="100px";input.style.border="solid 1px black";document.body.appendChild(input);input.onpaste=function(e){domPaste(e,function(data){console.log("data:",data);while(data.firstChild)document.body.appendChild(data.firstChild)});console.log(e)}; |
This file contains 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
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"dom-paste": "2.0.0" | |
} | |
} |
This file contains 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
<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