One upload dialog - Two targets?
Using CKeditor 3, I've created image handling functions:
An upload reciever (filebrowserUploadUrl) and an image browser dialog (filebrowserBrowseUrl) - Both work perfectlyBUT of course my users want more... We have two image-databases: Common and Private
- The image-browser lets the user pick images from either.My upload-reciever (php) can easily put the new image in either of these containers.
- but how do I let the user pick which one ?Three ideas - all involving modifying the upload-dialog-tab ( type=file + upload-button)
Adding a target selector by:Using two different upload-buttons: (Upload to Common) and (Upload to Private) both pointing to the same filebrowserUploadUrl but adding a parameter: &target=C or &target=P
or
A couple of "radio switches": Common or Private - essentially doing the same: Adding &target=(P or C) with one of them selected by default, so the user can't break it by negligence...
or
Just a single checkbox: Private (or not) ~ adding &target=P (or not)
I've really tried (my fingers are bleeding, and I've vomited with rage, twice!) but as a non-jQuery javascript developer, I just can't make sense of it all. When I add a text-开发者_Go百科field, it shows up just fine : )
- but not on the actual upload-form (in an iframe) that one still only contains the type=file field ?!?So I'd appreciate an example of how to modify the upload-dialog-tab to accomplish it ?
I have my launch platform ready (I think):
CKEDITOR.on( 'dialogDefinition', function( ev ) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if ( dialogName == 'image' ) { var infoTab = dialogDefinition.getContents( 'Upload' ); infoTab.add({ what ?
Solved it myself, but did have to go a bit rouge on it : )
I think there's may be an error in CKeditor here (or maybe it's by design..)
Adding new fields (whether in image.js or through CKEDITOR.on( 'dialogDefinition'..) they just don't translate into new fields on the actual upload-form in the iframe. (Bug or feature?)
SO, I added one checkbox (Private?not) to /plugins/image/dialogs/image.js
in the (id : 'Upload',) section between the file-field and the button, with an onClick-event that does the business, the hard way:
{
type : 'checkbox',
id : 'PrivateFlag',
label: 'Private',
checked : false,
onClick: function()
{
var theFrame = document.getElementById("125_fileInput");
var theDoc = theFrame.contentDocument || theFrame.contentWindow.document;
var theForm = theDoc.forms[0];
var action = theForm.getAttribute("action"); // alert("pre:"+theForm.getAttribute("action"));
if (action.indexOf("&target=P") == -1)
action += "&target=P";
else
action = action.replace("&target=P","");
theForm.setAttribute("action",action); // alert("post: "+theForm.getAttribute("action"));
}
},
It works (at least as long as the iframe's id is "125_fileInput")
IE-modification (of course):
if (navigator.appName == 'Microsoft Internet Explorer') // aka BrokenTurd
{
var theFrame = document.frames[1]; // may be inaccurate in your case..
var theDoc = theFrame.document;
}
else
{
var theFrame = document.getElementById("125_fileInput");
var theDoc = theFrame.contentDocument || theFrame.contentWindow.document;
}
精彩评论