Update 3
The following solution is pretty stable in Chrome Firefox and Safari:
var $editor = $("#input").cleditor()[0];
var focused = false;
var isFirefox = typeof InstallTrigger !== 'undefined';
var text = '';
$('.draggable').draggable({
appendTo:'body',
helper:'clone',
iframeFix: true,
revert:'invalid',
cursorAt:{top:0,left:0}
});
$("#w-edit").droppable({
drop: function (event, ui) {
text = ui.draggable.text();
if(!focused && !isFirefox)
$editor.focus();
else
$editor.focused();
}
});
$editor.focused(function(){
if(text != ''){
$editor.execCommand('inserthtml',text, false);
text = '';
}
focused = true;
});
$editor.blurred(function(){
focused = false;
});
$editor.change(function(){
if(!$('#w-edit').hasClass('ui-droppable')){
focused = false;
$("#w-edit").droppable({
drop: function (event, ui) {
text = ui.draggable.text();
if(!focused && !isFirefox)
$editor.focus();
else
$editor.focused();
}
});
}
});
http://jsfiddle.net/C3cFk/
, , - , , , . , , , , . ( - IE)
IE
IE ( IE 10), , , . execCommand('inserthtml' IE, . , pasteHTMl, IE , , , , . , , , , . , IE8, , IE8, .
, IE10:
$(document).ready(function(){
var $editor = $("#input").cleditor()[0];
var focused = false;
var text ='';
var temp;
$('.draggable').draggable({
appendTo:'body',
helper:'clone',
iframeFix: true,
revert:'invalid',
cursorAt:{top:0,left:0}
});
$("#w-edit").droppable({
drop: function (event, ui) {
temp = $(this).contents().find("html body")[0];
text = ui.draggable.text();
if(!focused)
$editor.focus();
else
$editor.focused();
}
});
$editor.focused(function(){
if(text != ''){
var doc = document.getElementById("w-edit").contentWindow.document;
if (doc.selection && doc.selection.createRange) {
var range = doc.selection.createRange();
if (range.pasteHTML) {
range.pasteHTML(text);
}
}
$editor.updateTextArea();
text = '';
}
focused = true;
});
$editor.blurred(function(){
focused = false;
});
$editor.change(function(){
if(!$('#w-edit').hasClass('ui-droppable')){
$("#w-edit").droppable({
drop: function (event, ui) {
temp = $(this).contents().find("html body")[0];
text = ui.draggable.text();
if(!focused)
$editor.focus();
else
$editor.focused();
}
});
}
});
});
, . - -, .
:
(, , , IE8, , ) IE8, (, doc - IE8):
$(document).ready(function(){
var $editor = $("#input").cleditor()[0];
$('.draggable').draggable({
appendTo:'body',
helper:'clone',
iframeFix: true,
revert:'invalid',
cursorAt:{top:0,left:0}
});
$("#w-edit").droppable({
drop: function (event, ui) {
console.log('drop');
$(this).contents().find("html body").append(ui.draggable.text()+' ');
$editor.updateTextArea();
}
});
$editor.change(function(){
if(!$('#w-edit').hasClass('ui-droppable')){
$("#w-edit").droppable({
drop: function (event, ui) {
$(this).contents().find("html body").append(ui.draggable.text()+' ');
$editor.updateTextArea();
}
});
}
});
});