单击拖动项目时触发的事件(Firefox)

时间:2012-10-01 16:47:45

标签: javascript jquery backbone.js twitter-bootstrap jquery-ui-sortable

当我点击某个项目时,我可以通过bootstrap-editable编辑该字段 当我拖放项目时,我可以通过jquery.ui.sortable更改项目的位置。

使用Google Chrome一切正常 使用Firefox 15.0.1我有以下问题。

移动项目后,会出现编辑该字段的弹出窗口 我想这个事件是由于事件的传播造成的 我试图解决它但没有成功......

这是我的代码:

    onSortReceive: function (e, ui) {
        this.$(ui.item[0]).trigger('drop', this.options.taskType);
        // TODO just on firefox there is a issue related to bootstrap-editable
        // it shows the popup even if there is e.stopPropagation() here
        // the only way to fix this issue is to re-render the view
        e.stopPropagation(); // it makes no difference 
        this.render(); // it fix the problem 
                       // but I want to avoid to re-render the view
    },

对于完整的代码,您可以继续:
https://github.com/antonioJs/CoCoTask/pull/21/files

对于工作版本,你可以继续:
http://computerone.altervista.org/CoCoTask/(问题仅在于firefox)

知道如何解决这个问题吗?

由于

2 个答案:

答案 0 :(得分:1)

好的,这是我发现的一种工作方式。在taskItem.js使用以下代码替换onRender

    onRender: function () {
        var sortInAction = false;
        this.$el.find('label').mouseup(function(e) {
          sortInAction = 'absolute' === $(e.target).closest('li').css('position');
        }).click(function(e) {
            if (sortInAction)
              e.stopImmediatePropagation();
        }).editable({
            type: 'textarea',
            name: 'task-name',
            validate: this.editTaskName,
            template: '<textarea rows="3"></textarea>'
        });
    },

希望它有所帮助。

答案 1 :(得分:0)

你应该e.preventDefault()mouseup事件,而不是sortreceive jquery.ui事件。也许这样的事情会起作用(未经测试):

'mouseup li': 'liMouseUp'

/* ... */

liMouseUp: function(e) {
    if ($(e.target).is('.ui-draggable-dragging')) {
        e.preventDefault();
    }
}
相关问题