Chrome 12+ has made it possible to paste images into the browser. I've written a bugmonkey script to insert images into fogbugz cases by pasting them (I haven't tested this much -- it may be ridden with bugs.) I'll include that below for those interested... (note: the data in the clipboard has to be an image.. so if you copy a bunch of text from a word document AND an image, it doesn't work, the data in the clipboard doesn't contain an image.)
What I don't have working is pasting images into wiki pages. With the code below, the image gets inserted and uploaded to the same place they do for cases (which is NOT the same as where the images go when you upload in the wiki page.) When I save the page, the image HTML gets replaced with
<img border="0" />
Is FogBugz stripping images that don't have URLs like the ones inserted by the wiki insert image function? If so -- I'll work on having the script upload them to the same place the wiki insert image is posting them to, but the URL includes an action token...
name: CaseImagePaste
description: Allows Chrome 12+ to paste an image into a html case edit and wiki page
author: Dio, James
version: 1.0.0.1
js:
var pasteImageXhr;
function getCurrentCK() {
if (typeof (CKEDITOR) != "undefined") {
if (typeof (CKEDITOR.instances.sEventEdit) != "undefined") return CKEDITOR.instances.sEventEdit;
else if (typeof (CKEDITOR.instances.sBody) != "undefined") return CKEDITOR.instances.sBody;
}
return null;
}
function imagePasteOnPaste(evt) {
var imagesFound = false;
var event = evt.originalEvent;
if (getCurrentCK() != null) {
var items = event.clipboardData.items;
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image/") != -1) {
imagesFound = true;
var blob = items[i].getAsFile();
var fdata = new FormData();
fdata.append("File1", blob);
var uploadUrl;
if (window.location.href.indexOf("pg=pgEditBug") != -1)
uploadUrl = window.location.origin + window.location.pathname + "?fAlaCarte=1&fPictureUpload=1&pre=preBugEventUpload";
else if (typeof(g_ixWikiPage) != "undefined")
uploadUrl = window.location.origin + window.location.pathname + "?fAlaCarte=1&fPictureUpload=1&pre=preWikiUpload&sActionToken=" + g_ActionTokens.getToken("preWikiUpload") + "&ixWiki=" + g_ixWiki + "&ixWikiPage=" + g_ixWikiPage;
pasteImageXhr.open("POST", uploadUrl);
pasteImageXhr.send(fdata);
}
}
}
if (imagesFound) return false;
}
$(document).ready(function () {
pasteImageXhr = new XMLHttpRequest();
function enableImagePaste() {
return (parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./)[1]) >= 12)
&& (window.location.href.indexOf("pg=pgEditBug") != -1 ||
window.location.href.indexOf("command=edit") != -1 ||
getCurrentCK() != null);
}
if (enableImagePaste()) {
function pastedImageCallback() {
if (pasteImageXhr.readyState != 4 || pasteImageXhr.status != 200) {
return;
}
var xmlRes = pasteImageXhr.responseXML;
getCurrentCK().insertHtml(xmlRes.getElementsByTagName("sHTML")[0].firstChild.nodeValue);
}
pasteImageXhr.onreadystatechange = pastedImageCallback;
function bindPasteInCK() {
$("iframe").contents().find("body").bind('paste', imagePasteOnPaste);
}
if (getCurrentCK() != null) {
bindPasteInCK();
getCurrentCK().on("instanceReady", bindPasteInCK);
}
CKEDITOR.on('instanceCreated', function (e) {
e.editor.on("instanceReady", bindPasteInCK);
});
}
});
css:
/* */
I've updated the code so that it'll work any time a ckeditor is present (including new wiki pages)