Skip to content

Commit

Permalink
Added standard input functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy van Kaathoven committed Dec 30, 2012
1 parent 74886ff commit 7b76194
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Inline Attachment 0.3
Inline Attachment 1.0
=====================

Adds upload functionality to a textarea or CodeMirror instance by either drag-dropping or pasting (only in chrome) an image inside it.
Expand Down
16 changes: 16 additions & 0 deletions demo/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Textarea Inline Attachment Demo</title>
</head>
<body>

<textarea id="code" rows="10" cols="50"></textarea>

<script type="text/javascript" src="../src/inline-attach.js"></script>
<script type="text/javascript">
inlineAttach.attachToInput(document.getElementById("code"));
</script>
</body>
</html>
35 changes: 34 additions & 1 deletion src/inline-attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,40 @@
* @param {Object} options
*/
window.inlineAttach.attachToInput = function(input, options) {
// TODO

options = options || {};

options.onRecievedFile = function(file) {
last_upload = '![Uploadf file...]()';
input.value = (input.value + "\n\n" + last_upload);
};

options.onUploadedFile = function(data) {
if (data.filename) {
var val = input.value.replace(last_upload, "![file](" + data.filename + ")")
input.value = val;
}
};

var inlineattach = new inlineAttach(options),
last_upload;

input.addEventListener('paste', function(e) {
inlineattach.onPaste(e);
}, false);
input.addEventListener('drop', function(e) {
e.stopPropagation();
e.preventDefault();
inlineattach.onDrop(e);
}, false);
input.addEventListener('dragenter', function(e) {
e.stopPropagation();
e.preventDefault();
}, false);
input.addEventListener('dragover', function(e) {
e.stopPropagation();
e.preventDefault();
}, false);
};

})(document, window);

0 comments on commit 7b76194

Please sign in to comment.