HTML 5 拖放到 Firefox 中的所见即所得编辑器中

发布于 2024-08-19 08:58:03 字数 322 浏览 1 评论 0原文

我有一个所见即所得编辑器,使用 HTML 5 拖放 API 来允许用户将小部件放置在他们正在编辑的页面中。当 OnDrop 事件触发时,我阻止默认事件,并在编辑器中插入一些代表它们插入的小部件的 html。我在 Firefox 中使用 execCommand("inserthtml", false, html) 来实现此目的。

这在 IE 中工作正常,但在 Firefox 中,html 不会放置在放置的位置。它总是被放置在先前选择所在的位置,这使我相信取消 OnDrop 事件以覆盖默认放置也会取消选择更改。

关于如何解决这个问题有什么想法吗?

谢谢!

I have a wysiwyg editor using the HTML 5 drag-drop api to allow the user to place widgets within the page they are editing. When the OnDrop event fires, I prevent the default event, and insert some html within the editor that represents the widget they inserted. I use execCommand("inserthtml", false, html) for this in Firefox.

This works fine in IE, but in Firefox the html is not placed in the location where it was dropped. It always gets placed in the location where the previous selection was, which leads me to believe that cancelling the OnDrop event to override the default drop also cancels the selection change.

Any ideas on how to solve this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妖妓 2024-08-26 08:58:03

我讨厌这些类型的答案,但我不得不说,jQuery UI 的拖放功能。 drop 事件结构非常简单。它将允许您跟踪您正在使用的对象并快速附加您正在谈论的 html。

如果您不熟悉它,我认为对于您正在讨论的系统类型来说,这是一个很好的选择。

I hate these kinds of answers, but I have to say, jQuery UI's drag & drop event structure is pretty straightforward. It would allow you to track the objects you're using and append the html you're talking about quickly.

If you aren't familiar with it, I think it's an excellent option for the type of system you're talking about.

寒尘 2024-08-26 08:58:03

是的,或者雅虎提供了一个很好的解决方案,示例位于 http://developer.yahoo.com /yui/examples/dragdrop/.

Yep, or YAHOO offers a nice solution, with examples at http://developer.yahoo.com/yui/examples/dragdrop/.

吻风 2024-08-26 08:58:03

试试这个

$('.textarea').wysihtml5({
    events: {
        "load": function() {
        var vm=this;
           $($('.wysihtml5-sandbox').contents().find('body')).on("dragleave", function(event) {
              event.preventDefault();  
              event.stopPropagation();
          });

          $($('.wysihtml5-sandbox').contents().find('body')).on("drop", function(event) {
              event.preventDefault();  
              event.stopPropagation();
              debugger;
               var dt = event.originalEvent.dataTransfer;
                        var files = dt.files;

              var reader = new FileReader();
              reader.onload = function (e) {
                  var data = this.result;
                  debugger;
                  vm.composer.commands.exec('insertImage',e.target.result);
              }
              reader.readAsDataURL( files[0] );
          });
                $($('.wysihtml5-sandbox').contents().find('body')).on("dragover", function(event) {
      console.log('graddddd');
                  event.preventDefault();  
                  event.stopPropagation();
                  $(this).addClass('dragging');
              });
        }
    }
});

https://jsfiddle.net/surajmahajan007/2yu456nw/

Try this

$('.textarea').wysihtml5({
    events: {
        "load": function() {
        var vm=this;
           $($('.wysihtml5-sandbox').contents().find('body')).on("dragleave", function(event) {
              event.preventDefault();  
              event.stopPropagation();
          });

          $($('.wysihtml5-sandbox').contents().find('body')).on("drop", function(event) {
              event.preventDefault();  
              event.stopPropagation();
              debugger;
               var dt = event.originalEvent.dataTransfer;
                        var files = dt.files;

              var reader = new FileReader();
              reader.onload = function (e) {
                  var data = this.result;
                  debugger;
                  vm.composer.commands.exec('insertImage',e.target.result);
              }
              reader.readAsDataURL( files[0] );
          });
                $($('.wysihtml5-sandbox').contents().find('body')).on("dragover", function(event) {
      console.log('graddddd');
                  event.preventDefault();  
                  event.stopPropagation();
                  $(this).addClass('dragging');
              });
        }
    }
});

https://jsfiddle.net/surajmahajan007/2yu456nw/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文