Browse Source

+ merge 'dev'

react
RubaXa 10 years ago
parent
commit
4cd67d6107
  1. 6
      .jshintrc
  2. 0
      Gruntfile.js
  3. 2
      README.md
  4. 33
      Sortable.js
  5. 4
      Sortable.min.js
  6. 2
      bower.json
  7. 2
      component.json
  8. 2
      index.html
  9. 2
      meteor/package.js
  10. 38
      ng-sortable.js
  11. 12
      package.json
  12. 1
      st/app.css

6
.jshintrc

@ -1,9 +1,9 @@
{ {
"strict": true, "strict": true,
"newcap": false, // "Tolerate uncapitalized constructors" "newcap": false,
"node": true, "node": true,
"expr": true, // - true && call() "Expected an assignment or function call and instead saw an expression." "expr": true,
"supernew": true, // - "Missing '()' invoking a constructor." "supernew": true,
"laxbreak": true, "laxbreak": true,
"white": true, "white": true,
"globals": { "globals": {

0
Gruntfile.js

2
README.md

@ -202,7 +202,7 @@ Sortable.create(list, {
#### `ghostClass` option #### `ghostClass` option
Class name for the drop placeholder. Class name for the drop placeholder.
Demo: http://jsbin.com/boqugumiqi/1/edit?css,js,output Demo: http://jsbin.com/hunifu/1/edit?css,js,output
```css ```css
.ghost { .ghost {

33
Sortable.js

@ -171,6 +171,7 @@
_dragStarted: function () { _dragStarted: function () {
if (rootEl && dragEl) {
// Apply effect // Apply effect
_toggleClass(dragEl, this.options.ghostClass, true); _toggleClass(dragEl, this.options.ghostClass, true);
@ -178,6 +179,7 @@
// Drag start event // Drag start event
_dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex);
}
}, },
@ -276,13 +278,6 @@
} }
} catch (err) { } catch (err) {
} }
if (activeGroup.pull == 'clone') {
cloneEl = dragEl.cloneNode(true);
_css(cloneEl, 'display', 'none');
rootEl.insertBefore(cloneEl, dragEl);
}
} }
}, },
@ -347,6 +342,12 @@
this._offUpEvents(); this._offUpEvents();
if (activeGroup.pull == 'clone') {
cloneEl = dragEl.cloneNode(true);
_css(cloneEl, 'display', 'none');
rootEl.insertBefore(cloneEl, dragEl);
}
if (isTouch) { if (isTouch) {
var rect = dragEl.getBoundingClientRect(), var rect = dragEl.getBoundingClientRect(),
css = _css(dragEl), css = _css(dragEl),
@ -470,7 +471,7 @@
!options.dragoverBubble && evt.stopPropagation(); !options.dragoverBubble && evt.stopPropagation();
} }
if (!_silent && activeGroup && if (!_silent && activeGroup && !options.disabled &&
(isOwner (isOwner
? canSort || (revert = !rootEl.contains(dragEl)) ? canSort || (revert = !rootEl.contains(dragEl))
: activeGroup.pull && groupPut && ( : activeGroup.pull && groupPut && (
@ -627,17 +628,19 @@
// Remove event // Remove event
_dispatchEvent(rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
} }
else if (dragEl.nextSibling !== nextEl) { else {
// (1) Remove clone // Remove clone
cloneEl && cloneEl.parentNode.removeChild(cloneEl); cloneEl && cloneEl.parentNode.removeChild(cloneEl);
// (2) Get the index of the dragged element within its parent if (dragEl.nextSibling !== nextEl) {
// Get the index of the dragged element within its parent
newIndex = _index(dragEl); newIndex = _index(dragEl);
// drag & drop within the same list // drag & drop within the same list
_dispatchEvent(rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
} }
}
// Drag end event // Drag end event
Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
@ -820,7 +823,7 @@
do { do {
if ( if (
(tag === '>*' && el.parentNode === ctx) || ( (tag === '>*' && el.parentNode === ctx) || (
(tag === '' || el.nodeName == tag) && (tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length) (!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
) )
) { ) {
@ -948,9 +951,11 @@
*/ */
function _index(/**HTMLElement*/el) { function _index(/**HTMLElement*/el) {
var index = 0; var index = 0;
while (el && (el = el.previousElementSibling) && (el.nodeName !== 'TEMPLATE')) { while (el && (el = el.previousElementSibling)) {
if (el.nodeName.toUpperCase() !== 'TEMPLATE') {
index++; index++;
} }
}
return index; return index;
} }
@ -994,7 +999,7 @@
}; };
Sortable.version = '1.0.0'; Sortable.version = '1.0.1';
/** /**

4
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

2
bower.json

@ -1,7 +1,7 @@
{ {
"name": "Sortable", "name": "Sortable",
"main": "Sortable.js", "main": "Sortable.js",
"version": "1.0.0", "version": "1.0.1",
"homepage": "http://rubaxa.github.io/Sortable/", "homepage": "http://rubaxa.github.io/Sortable/",
"authors": [ "authors": [
"RubaXa <ibnRubaXa@gmail.com>" "RubaXa <ibnRubaXa@gmail.com>"

2
component.json

@ -1,7 +1,7 @@
{ {
"name": "Sortable", "name": "Sortable",
"main": "Sortable.js", "main": "Sortable.js",
"version": "1.0.0", "version": "1.0.1",
"homepage": "http://rubaxa.github.io/Sortable/", "homepage": "http://rubaxa.github.io/Sortable/",
"repo": "RubaXa/Sortable", "repo": "RubaXa/Sortable",
"authors": [ "authors": [

2
index.html

@ -128,7 +128,7 @@
</div> </div>
<div style="width: 25%; float: left; margin-top: 15px; margin-left: 10px" class="block__list block__list_words"> <div style="width: 25%; float: left; margin-top: 15px; margin-left: 10px" class="block__list block__list_words">
<div class="block__list-title">only pull (clone), no reordering</div> <div class="block__list-title">only pull (clone) no&nbsp;reordering</div>
<ul id="advanced-2"> <ul id="advanced-2">
<li>Sex</li> <li>Sex</li>
<li>Drugs</li> <li>Drugs</li>

2
meteor/package.js

@ -16,7 +16,7 @@ Package.describe({
Package.onUse(function (api) { Package.onUse(function (api) {
api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']);
api.use('templating', 'client'); api.use('templating', 'client');
api.use('dburles:mongo-collection-instances@0.2.5'); // to watch collections getting created api.use('dburles:mongo-collection-instances@0.2.6'); // to watch collections getting created
api.export('Sortable'); api.export('Sortable');
api.addFiles([ api.addFiles([
'Sortable.js', 'Sortable.js',

38
ng-sortable.js

@ -15,9 +15,10 @@
'use strict'; 'use strict';
angular.module('ng-sortable', []) angular.module('ng-sortable', [])
.constant('$version', '0.3.2') .constant('$version', '0.3.5')
.directive('ngSortable', ['$parse', function ($parse) { .directive('ngSortable', ['$parse', function ($parse) {
var removed; var removed,
nextSibling;
function getSource(el) { function getSource(el) {
var scope = angular.element(el).scope(); var scope = angular.element(el).scope();
@ -27,7 +28,9 @@
(node.nodeValue.indexOf('ngRepeat:') !== -1) (node.nodeValue.indexOf('ngRepeat:') !== -1)
); );
})[0]; })[0];
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([^\s]+)\s+in\s+([^\s|]+)/);
// tests: http://jsbin.com/kosubutilo/1/edit?js,output
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/);
var itemExpr = $parse(ngRepeat[1]); var itemExpr = $parse(ngRepeat[1]);
var itemsExpr = $parse(ngRepeat[2]); var itemsExpr = $parse(ngRepeat[2]);
@ -70,19 +73,21 @@
prevItems = prevSource.items(); prevItems = prevSource.items();
oldIndex = prevItems.indexOf(prevSource.item(evt.item)); oldIndex = prevItems.indexOf(prevSource.item(evt.item));
removed = prevItems.splice(oldIndex, 1)[0]; removed = prevItems[oldIndex];
items.splice(newIndex, 0, removed);
if (evt.clone) { if (evt.clone) {
newIndex = Sortable.utils.index(evt.clone);
prevItems.splice(newIndex, 0, removed);
evt.from.removeChild(evt.clone); evt.from.removeChild(evt.clone);
removed = angular.copy(removed);
}
else {
prevItems.splice(oldIndex, 1);
} }
evt.from.appendChild(evt.item); // revert element items.splice(newIndex, 0, removed);
} else {
evt.from.insertBefore(evt.item, nextSibling); // revert element
}
else {
items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]);
} }
@ -94,17 +99,21 @@
opts[name] = opts[name] || options[name]; opts[name] = opts[name] || options[name];
return opts; return opts;
}, { }, {
onStart: function () { onStart: function (/**Event*/evt) {
nextSibling = evt.item.nextSibling;
options.onStart(source.items()); options.onStart(source.items());
scope.$apply();
}, },
onEnd: function () { onEnd: function () {
options.onEnd(source.items()); options.onEnd(source.items());
scope.$apply();
}, },
onAdd: function (evt) { onAdd: function (/**Event*/evt) {
_sync(evt); _sync(evt);
options.onAdd(source.items(), removed); options.onAdd(source.items(), removed);
scope.$apply();
}, },
onUpdate: function (evt) { onUpdate: function (/**Event*/evt) {
_sync(evt); _sync(evt);
options.onUpdate(source.items(), source.item(evt.item)); options.onUpdate(source.items(), source.item(evt.item));
}, },
@ -119,6 +128,7 @@
$el.on('$destroy', function () { $el.on('$destroy', function () {
sortable.destroy(); sortable.destroy();
sortable = null; sortable = null;
nextSibling = null;
}); });
if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly

12
package.json

@ -1,7 +1,7 @@
{ {
"name": "sortablejs", "name": "sortablejs",
"exportName": "Sortable", "exportName": "Sortable",
"version": "1.0.0", "version": "1.0.1",
"devDependencies": { "devDependencies": {
"grunt": "*", "grunt": "*",
"grunt-version": "*", "grunt-version": "*",
@ -25,9 +25,17 @@
"drag", "drag",
"meteor", "meteor",
"angular", "angular",
"ng-srotable",
"react", "react",
"mixin" "mixin"
], ],
"author": "Konstantin Lebedev <ibnRubaXa@gmail.com>", "author": "Konstantin Lebedev <ibnRubaXa@gmail.com>",
"license": "MIT" "license": "MIT",
"spm": {
"main": "Sortable.js",
"ignore": [
"meteor",
"st"
]
}
} }

1
st/app.css

@ -220,6 +220,7 @@ img {
margin-right: 10px; margin-right: 10px;
font: bold 20px Sans-Serif; font: bold 20px Sans-Serif;
color: #5F9EDF; color: #5F9EDF;
display: inline-block;
cursor: move; cursor: move;
cursor: -webkit-grabbing; /* overrides 'move' */ cursor: -webkit-grabbing; /* overrides 'move' */
} }

Loading…
Cancel
Save