Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/RubaXa/Sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Jan 20, 2016
2 parents a3a8c0c + 6963281 commit 186fed5
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Issue

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

---
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ Other attributes are:
### Support Polymer
```html

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

<sortable-js handle=".handle">
<template is="dom-repeat" items={{names}}>
Expand Down
88 changes: 55 additions & 33 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
}
})(function () {
"use strict";

if (typeof window == "undefined" || typeof window.document == "undefined") {
return function() {
throw new Error( "Sortable.js requires a window with a document" );
}
}

var dragEl,
parentEl,
Expand Down Expand Up @@ -273,7 +279,7 @@
}

// get the index of the dragged element within its parent
oldIndex = _index(target);
oldIndex = _index(target, options.draggable);

// Check filter
if (typeof filter === 'function') {
Expand Down Expand Up @@ -769,7 +775,7 @@
_toggleClass(dragEl, this.options.chosenClass, false);

if (rootEl !== parentEl) {
newIndex = _index(dragEl);
newIndex = _index(dragEl, options.draggable);

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

if (dragEl.nextSibling !== nextEl) {
// Get the index of the dragged element within its parent
newIndex = _index(dragEl);
newIndex = _index(dragEl, options.draggable);

if (newIndex >= 0) {
// drag & drop within the same list
Expand All @@ -811,31 +817,34 @@
}
}

// Nulling
rootEl =
dragEl =
parentEl =
ghostEl =
nextEl =
cloneEl =
}
this._nulling();
},

scrollEl =
scrollParentEl =
_nulling: function() {
// Nulling
rootEl =
dragEl =
parentEl =
ghostEl =
nextEl =
cloneEl =

tapEvt =
touchEvt =
scrollEl =
scrollParentEl =

moved =
newIndex =
tapEvt =
touchEvt =

lastEl =
lastCSS =
moved =
newIndex =

activeGroup =
Sortable.active = null;
}
},
lastEl =
lastCSS =

activeGroup =
Sortable.active = null;
},

handleEvent: function (/**Event*/evt) {
var type = evt.type;
Expand Down Expand Up @@ -982,17 +991,11 @@
function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) {
if (el) {
ctx = ctx || document;
selector = selector.split('.');

var tag = selector.shift().toUpperCase(),
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');

do {
if (
(tag === '>*' && el.parentNode === ctx) || (
(tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
)
(selector === '>*' && el.parentNode === ctx)
|| _matches(el, selector)
) {
return el;
}
Expand Down Expand Up @@ -1165,26 +1168,45 @@
}

/**
* Returns the index of an element within its parent
* Returns the index of an element within its parent for a selected set of
* elements
* @param {HTMLElement} el
* @param {selector} selector
* @return {number}
*/
function _index(el) {
function _index(el, selector) {
var index = 0;

if (!el || !el.parentNode) {
return -1;
}

while (el && (el = el.previousElementSibling)) {
if (el.nodeName.toUpperCase() !== 'TEMPLATE') {
if (el.nodeName.toUpperCase() !== 'TEMPLATE'
&& _matches(el, selector)) {
index++;
}
}

return index;
}

function _matches(/**HTMLElement*/el, /**String*/selector) {
if (el) {
selector = selector.split('.');

var tag = selector.shift().toUpperCase(),
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');

return (
(tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
);
}

return false;
}

function _throttle(callback, ms) {
var args, _this;

Expand Down
Loading

0 comments on commit 186fed5

Please sign in to comment.