diff --git a/jquery.sortable.js b/jquery.sortable.js index 350d172..fb53c41 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -28,11 +28,12 @@ $.fn.sortable = function(options) { }).mouseup(function() { isHandle = false; }); - $(this).data('items', options.items) + $(this).data('items', options.items); placeholders = placeholders.add(placeholder); if (options.connectWith) { $(options.connectWith).add(this).data('connectWith', options.connectWith); } + items.attr('draggable', 'true').on('dragstart.h5s', function(e) { if (options.handle && !isHandle) { return false; @@ -43,26 +44,27 @@ $.fn.sortable = function(options) { dt.setData('Text', 'dummy'); index = (dragging = $(this)).addClass('sortable-dragging').index(); }).on('dragend.h5s', function() { - if (!dragging) { - return; - } dragging.removeClass('sortable-dragging').show(); placeholders.detach(); if (index != dragging.index()) { - dragging.parent().trigger('sortupdate', {item: dragging}); + items.parent().trigger('sortupdate', {item: dragging}); } dragging = null; - }).not('a[href], img').on('selectstart.h5s', function() { + }) + .not('a[href], img, [contenteditable]').on('selectstart.h5s', function(e) { + console.log(this); + e.stopImmediatePropagation(); + e.cancelBubble = true; this.dragDrop && this.dragDrop(); return false; - }).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) { + }) + .end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) { if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) { return true; } if (e.type == 'drop') { e.stopPropagation(); placeholders.filter(':visible').after(dragging); - dragging.trigger('dragend.h5s'); return false; } e.preventDefault(); @@ -80,6 +82,23 @@ $.fn.sortable = function(options) { } return false; }); + + items.find("[contenteditable]").on("selectstart.h5s dragstart.h5s", function(e) { + e.stopPropagation(); + e.cancelBubble = true; + }).on("click.h5s focus.h5s", function() { + var $this = $(this), + $p = $(this).parents("[draggable]"); + + $this.data("$p_state", $p.attr("draggable")); + $p.removeAttr("draggable"); + }).on("blur.h5s", function() { + var $this = $(this); + + $this + .parents(".media_block") + .attr("draggable", $this.data("$p_state")); + }); }); }; })(jQuery);