【发布时间】:2016-07-28 21:18:59
【问题描述】:
我正在尝试将拖放功能添加到 Ace Editor。我正在使用 jQuery Droppable 函数来实现这一点。我有拖动功能,并且 Ace 编辑器区域也出现了。 Drop 功能目前不工作。我对 drop 功能的预期用途是将文本从可拖动的 div 复制到 Ace 编辑器区域。当我不使用 Ace Editor 时,drop 功能起作用,就像当我将 DIV 拖动到可放置的 DIV 时,它会很好地复制可拖动的内容。因此,由于编辑器没有填充可拖动内容,因此使用 Ace 实现了一些问题。这是我的代码。我现在将所有内容都放在一个文件中,一旦我对 Ace 有了更好的了解,我打算将它们分开。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Code Block Project</title>
<style type="text/css" media="screen">
#draggable {
width: 202;
height: 30px;
padding: 0.5em;
float: left;
margin: 10px 10px 10px 0;
border-style: solid;
border-width: 2px;
}
#droppable {
left: 0;
width: 600px;
height: 300px;
padding: 0.5em;
float: left;
margin: 10px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script src="https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js">
</script>
<script>
</script>
<script>
$(function() {
$("#draggable").draggable({
revert: true
});
$("#droppable").droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function(event, ui) {
$(this).find(".ui-widget-header").remove();
$("<p>").append(ui.draggable.contents().clone()).appendTo(this);
}
});
var editor = ace.edit("droppable");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/python");
});
</script>
</head>
<body>
<div id="droppable" class="ui-widget-header">
<p> #Dragcodeblock </p>
</div>
<div id="draggable" class="ui-widget-content">
<p> Hello World </p>
</div>
</body>
</html>
【问题讨论】:
标签: jquery html ace-editor droppable