Skip to content

Commit 186fed5

Browse files
committed
Merge branch 'master' of https://github.com/RubaXa/Sortable
2 parents a3a8c0c + 6963281 commit 186fed5

File tree

5 files changed

+149
-79
lines changed

5 files changed

+149
-79
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### Issue
44

55
1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved;
6-
2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer;
6+
2. [Use the search](https://github.com/RubaXa/Sortable/search?type=Issues&q=problem), maybe already have an answer;
77
3. If not found, create example on [jsbin.com (draft)](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem.
88

99
---

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ Other attributes are:
476476
### Support Polymer
477477
```html
478478

479-
<link rel="import" href="bower_components/Sortable/Sortable-js.html">
479+
<link rel="import" href="bower_components/Sortable/Sortable.html">
480480

481481
<sortable-js handle=".handle">
482482
<template is="dom-repeat" items={{names}}>

Sortable.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
}
2424
})(function () {
2525
"use strict";
26+
27+
if (typeof window == "undefined" || typeof window.document == "undefined") {
28+
return function() {
29+
throw new Error( "Sortable.js requires a window with a document" );
30+
}
31+
}
2632

2733
var dragEl,
2834
parentEl,
@@ -273,7 +279,7 @@
273279
}
274280

275281
// get the index of the dragged element within its parent
276-
oldIndex = _index(target);
282+
oldIndex = _index(target, options.draggable);
277283

278284
// Check filter
279285
if (typeof filter === 'function') {
@@ -769,7 +775,7 @@
769775
_toggleClass(dragEl, this.options.chosenClass, false);
770776

771777
if (rootEl !== parentEl) {
772-
newIndex = _index(dragEl);
778+
newIndex = _index(dragEl, options.draggable);
773779

774780
if (newIndex >= 0) {
775781
// drag from one list and drop into another
@@ -789,7 +795,7 @@
789795

790796
if (dragEl.nextSibling !== nextEl) {
791797
// Get the index of the dragged element within its parent
792-
newIndex = _index(dragEl);
798+
newIndex = _index(dragEl, options.draggable);
793799

794800
if (newIndex >= 0) {
795801
// drag & drop within the same list
@@ -811,31 +817,34 @@
811817
}
812818
}
813819

814-
// Nulling
815-
rootEl =
816-
dragEl =
817-
parentEl =
818-
ghostEl =
819-
nextEl =
820-
cloneEl =
820+
}
821+
this._nulling();
822+
},
821823

822-
scrollEl =
823-
scrollParentEl =
824+
_nulling: function() {
825+
// Nulling
826+
rootEl =
827+
dragEl =
828+
parentEl =
829+
ghostEl =
830+
nextEl =
831+
cloneEl =
824832

825-
tapEvt =
826-
touchEvt =
833+
scrollEl =
834+
scrollParentEl =
827835

828-
moved =
829-
newIndex =
836+
tapEvt =
837+
touchEvt =
830838

831-
lastEl =
832-
lastCSS =
839+
moved =
840+
newIndex =
833841

834-
activeGroup =
835-
Sortable.active = null;
836-
}
837-
},
842+
lastEl =
843+
lastCSS =
838844

845+
activeGroup =
846+
Sortable.active = null;
847+
},
839848

840849
handleEvent: function (/**Event*/evt) {
841850
var type = evt.type;
@@ -982,17 +991,11 @@
982991
function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) {
983992
if (el) {
984993
ctx = ctx || document;
985-
selector = selector.split('.');
986-
987-
var tag = selector.shift().toUpperCase(),
988-
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
989994

990995
do {
991996
if (
992-
(tag === '>*' && el.parentNode === ctx) || (
993-
(tag === '' || el.nodeName.toUpperCase() == tag) &&
994-
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
995-
)
997+
(selector === '>*' && el.parentNode === ctx)
998+
|| _matches(el, selector)
996999
) {
9971000
return el;
9981001
}
@@ -1165,26 +1168,45 @@
11651168
}
11661169

11671170
/**
1168-
* Returns the index of an element within its parent
1171+
* Returns the index of an element within its parent for a selected set of
1172+
* elements
11691173
* @param {HTMLElement} el
1174+
* @param {selector} selector
11701175
* @return {number}
11711176
*/
1172-
function _index(el) {
1177+
function _index(el, selector) {
11731178
var index = 0;
11741179

11751180
if (!el || !el.parentNode) {
11761181
return -1;
11771182
}
11781183

11791184
while (el && (el = el.previousElementSibling)) {
1180-
if (el.nodeName.toUpperCase() !== 'TEMPLATE') {
1185+
if (el.nodeName.toUpperCase() !== 'TEMPLATE'
1186+
&& _matches(el, selector)) {
11811187
index++;
11821188
}
11831189
}
11841190

11851191
return index;
11861192
}
11871193

1194+
function _matches(/**HTMLElement*/el, /**String*/selector) {
1195+
if (el) {
1196+
selector = selector.split('.');
1197+
1198+
var tag = selector.shift().toUpperCase(),
1199+
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
1200+
1201+
return (
1202+
(tag === '' || el.nodeName.toUpperCase() == tag) &&
1203+
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
1204+
);
1205+
}
1206+
1207+
return false;
1208+
}
1209+
11881210
function _throttle(callback, ms) {
11891211
var args, _this;
11901212

0 commit comments

Comments
 (0)