diff --git a/README.md b/README.md index a3d888f..b27b814 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +DEPRECATION NOTICE +------------------ +This project is not mantained anymore. I recommend using [RubaXa's Sortable](https://github.com/RubaXa/Sortable) or [voidberg's fork](https://github.com/voidberg/html5sortable) instead. + HTML5 Sortable jQuery Plugin ============================ diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..39fc86c --- /dev/null +++ b/bower.json @@ -0,0 +1,26 @@ +{ + "name": "html5sortable", + "version": "0.0.1", + "homepage": "http://farhadi.ir/projects/html5sortable/", + "authors": [ + "Ali Farhadi " + ], + "description": "Lightweight jQuery plugin to create sortable lists and grids using native HTML5 drag and drop API.", + "main": "./jquery.sortable.js", + "keywords": [ + "html5", + "sortable", + "jquery" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "jquery": ">= 1.9.1" + } +} diff --git a/jquery.sortable.js b/jquery.sortable.js index 350d172..2ebca6f 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -1,7 +1,7 @@ /* * HTML5 Sortable jQuery Plugin * http://farhadi.ir/projects/html5sortable - * + * * Copyright 2012, Ali Farhadi * Released under the MIT license. */ @@ -13,7 +13,7 @@ $.fn.sortable = function(options) { connectWith: false }, options); return this.each(function() { - if (/^enable|disable|destroy$/.test(method)) { + if (/^(enable|disable|destroy)$/.test(method)) { var items = $(this).children($(this).data('items')).attr('draggable', method == 'enable'); if (method == 'destroy') { items.add(this).removeData('connectWith items') @@ -22,7 +22,7 @@ $.fn.sortable = function(options) { return; } var isHandle, index, items = $(this).children(options.items); - var placeholder = $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder">'); + var placeholder = $('<' + (/^(ul|ol)$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder">'); items.find(options.handle).mousedown(function() { isHandle = true; }).mouseup(function() { diff --git a/jquery.sortable.min.js b/jquery.sortable.min.js new file mode 100644 index 0000000..7e90810 --- /dev/null +++ b/jquery.sortable.min.js @@ -0,0 +1,8 @@ +/* + * HTML5 Sortable jQuery Plugin + * http://farhadi.ir/projects/html5sortable + * + * Copyright 2012, Ali Farhadi + * Released under the MIT license. + */ +(function(e){var t,n=e();e.fn.sortable=function(r){var i=String(r);r=e.extend({connectWith:false},r);return this.each(function(){if(/^enable|disable|destroy$/.test(i)){var s=e(this).children(e(this).data("items")).attr("draggable",i=="enable");if(i=="destroy"){s.add(this).removeData("connectWith items").off("dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s")}return}var o,u,s=e(this).children(r.items);var a=e("<"+(/^ul|ol$/i.test(this.tagName)?"li":"div")+' class="sortable-placeholder">');s.find(r.handle).mousedown(function(){o=true}).mouseup(function(){o=false});e(this).data("items",r.items);n=n.add(a);if(r.connectWith){e(r.connectWith).add(this).data("connectWith",r.connectWith)}s.attr("draggable","true").on("dragstart.h5s",function(n){if(r.handle&&!o){return false}o=false;var i=n.originalEvent.dataTransfer;i.effectAllowed="move";i.setData("Text","dummy");u=(t=e(this)).addClass("sortable-dragging").index()}).on("dragend.h5s",function(){if(!t){return}t.removeClass("sortable-dragging").show();n.detach();if(u!=t.index()){t.parent().trigger("sortupdate",{item:t})}t=null}).not("a[href], img").on("selectstart.h5s",function(){this.dragDrop&&this.dragDrop();return false}).end().add([this,a]).on("dragover.h5s dragenter.h5s drop.h5s",function(i){if(!s.is(t)&&r.connectWith!==e(t).parent().data("connectWith")){return true}if(i.type=="drop"){i.stopPropagation();n.filter(":visible").after(t);t.trigger("dragend.h5s");return false}i.preventDefault();i.originalEvent.dataTransfer.dropEffect="move";if(s.is(this)){if(r.forcePlaceholderSize){a.height(t.outerHeight())}t.hide();e(this)[a.index()