show/hide this revision's text 5 deleted 279 characters in body

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" />&nbsp;

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);
    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:

/* */

Note: images from some applications just appear as a white box and no image is actually pasted -- It seems that is chrome's fault though -- things

I've updated the code so that paste successfully into GMail will it'll work here... coming from MSWord any time a ckeditor is present (single image copyincluding new wiki pages)as well as from other browsers seem to paste OK. Snag-It, MSPaint and others aren't working. There is a chrome case open: http://code.google.com/p/chromium/issues/detail?id=86085

show/hide this revision's text 4 added 492 characters in body

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" />&nbsp;

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.0

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);
                pasteImageXhr.open("POST", var uploadUrl;
                if (window.location.href.indexOf("pg=pgEditBug") != -1)
                    uploadUrl = window.location.origin + window.location.pathname + "?fAlaCarte=1&fPictureUpload=1&pre=preBugEventUpload");
                &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);
    }
    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:

/* */

Note: images from some applications just appear as a white box and no image is actually pasted -- It seems that is chrome's fault though -- things that paste successfully into GMail will work here... coming from MSWord (single image copy) as well as from other browsers seem to paste OK. Snag-It, MSPaint and others aren't working. There is a chrome case open: http://code.google.com/p/chromium/issues/detail?id=86085

show/hide this revision's text 3 added 27 characters in body

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 which is working for me (I haven't tested this much at all -- it may be horribly broken.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" />&nbsp;

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
author:        Dio, James
version:       1.0.0.0

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);
                pasteImageXhr.open("POST", window.location.origin + window.location.pathname + "?fAlaCarte=1&fPictureUpload=1&pre=preBugEventUpload");
                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);
    }
    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:

/* */

Note: this images from some applications just appear as a white box and no image is pretty buggy overall actually pasted -- It seems that is chrome's fault though -- things that paste successfully into GMail seem to will work here... coming from MSWord (single image copy) as well as from other browsers seem to paste OK. Snag-It, MSPaint and others aren't working. There is a chrome case open: http://code.google.com/p/chromium/issues/detail?id=86085

show/hide this revision's text 2 added 361 characters in body
show/hide this revision's text 1