Browse Source

Merge branch 'dev' into gh-pages

gh-pages
RubaXa 10 years ago
parent
commit
8d75bd78b3
  1. 11
      Sortable.js
  2. 201
      index.html
  3. 4
      ng-sortable.js
  4. 6
      st/app.css
  5. 186
      st/app.js

11
Sortable.js

@ -106,7 +106,9 @@
animation: 0, animation: 0,
setData: function (dataTransfer, dragEl) { setData: function (dataTransfer, dragEl) {
dataTransfer.setData('Text', dragEl.textContent); dataTransfer.setData('Text', dragEl.textContent);
} },
dropBubble: false,
dragoverBubble: false
}; };
@ -465,7 +467,7 @@
if (evt.preventDefault !== void 0) { if (evt.preventDefault !== void 0) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); !options.dragoverBubble && evt.stopPropagation();
} }
if (!_silent && activeGroup && if (!_silent && activeGroup &&
@ -586,7 +588,8 @@
}, },
_onDrop: function (/**Event*/evt) { _onDrop: function (/**Event*/evt) {
var el = this.el; var el = this.el,
options = this.options;
clearInterval(this._loopId); clearInterval(this._loopId);
clearInterval(autoScroll.pid); clearInterval(autoScroll.pid);
@ -601,7 +604,7 @@
if (evt) { if (evt) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); !options.dropBubble && evt.stopPropagation();
ghostEl && ghostEl.parentNode.removeChild(ghostEl); ghostEl && ghostEl.parentNode.removeChild(ghostEl);

201
index.html

@ -28,6 +28,7 @@
</div> </div>
<!-- Connected lists -->
<div class="container" style="height: 520px"> <div class="container" style="height: 520px">
<div data-force="30" class="layer block" style="left: 14.5%; top: 0; width: 37%"> <div data-force="30" class="layer block" style="left: 14.5%; top: 0; width: 37%">
<div class="layer title">List A</div> <div class="layer title">List A</div>
@ -55,6 +56,7 @@
</div> </div>
<!-- Multi connected lists -->
<a name="m"></a> <a name="m"></a>
<div class="container"> <div class="container">
<div id="multi" style="margin-left: 30px"> <div id="multi" style="margin-left: 30px">
@ -91,6 +93,7 @@
</div> </div>
<!-- Editable list -->
<a name="e"></a> <a name="e"></a>
<div class="container" style="margin-top: 100px"> <div class="container" style="margin-top: 100px">
<div id="filter" style="margin-left: 30px"> <div id="filter" style="margin-left: 30px">
@ -109,6 +112,7 @@
</div> </div>
<!-- Advanced connected lists -->
<a name="ag"></a> <a name="ag"></a>
<div class="container" style="margin-top: 100px;"> <div class="container" style="margin-top: 100px;">
<div id="advanced" style="margin-left: 30px;"> <div id="advanced" style="margin-left: 30px;">
@ -146,6 +150,7 @@
</div> </div>
<!-- 'handle' option -->
<a name="h"></a> <a name="h"></a>
<div class="container" style="margin-top: 100px;"> <div class="container" style="margin-top: 100px;">
<div id="handle" style="margin-left: 30px;"> <div id="handle" style="margin-left: 30px;">
@ -164,6 +169,7 @@
</div> </div>
<!-- Angular -->
<a name="ng"></a> <a name="ng"></a>
<div id="todos" ng-app="todoApp" class="container" style="margin-top: 100px"> <div id="todos" ng-app="todoApp" class="container" style="margin-top: 100px">
<div style="margin-left: 30px"> <div style="margin-left: 30px">
@ -204,27 +210,27 @@
</div> </div>
<!-- Code example -->
<a name="c"></a> <a name="c"></a>
<div class="container" style="margin-top: 100px"> <div class="container" style="margin-top: 100px">
<div style="margin-left: 30px"> <div style="margin-left: 30px">
<div><div class="layer title title_xl">Code example</div></div> <div><div class="layer title title_xl">Code example</div></div>
<pre data-force="100" class="layer javascript" style="margin-top: -8px; margin-left: 10px; width: 90%"><code>// Simple list <pre data-force="100" class="layer javascript" style="margin-top: -8px; margin-left: 10px; width: 90%"><code>// Simple list
var list = document.getElementById("my-ui-list"); var list = document.getElementById("my-ui-list");
new Sortable(list); // That's all. Sortable.create(list); // That's all.
// Grouping // Grouping
var foo = document.getElementById("foo"); var foo = document.getElementById("foo");
new Sortable(foo, { group: "omega" }); Sortable.create(foo, { group: "omega" });
var bar = document.getElementById("bar"); var bar = document.getElementById("bar");
new Sortable(bar, { group: "omega" }); Sortable.create(bar, { group: "omega" });
// Or // Or
var container = document.getElementById("multi"); var container = document.getElementById("multi");
var sort = new Sortable(container, { var sort = Sortable.create(container, {
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
handle: ".tile__title", // Restricts sort start click/touch to the specified element handle: ".tile__title", // Restricts sort start click/touch to the specified element
draggable: ".tile", // Specifies which items inside the element should be sortable draggable: ".tile", // Specifies which items inside the element should be sortable
@ -238,7 +244,7 @@ sort.destroy();
// Editable list // Editable list
var editableList = new Sortable(editable, { var editableList = Sortable.create(editable, {
filter: '.js-remove', filter: '.js-remove',
onFilter: function (evt) { onFilter: function (evt) {
var el = editableList.closest(evt.item); // get dragged item var el = editableList.closest(evt.item); // get dragged item
@ -265,188 +271,7 @@ var editableList = new Sortable(editable, {
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="ng-sortable.js"></script> <script src="ng-sortable.js"></script>
<script> <script src="st/app.js"></script>
(function (){
var console = window.console;
if( !console.log ){
console.log = function (){
alert([].join.apply(arguments, ' '));
};
}
Sortable.create(foo, {
group: "words",
animation: 150,
store: {
get: function (sortable) {
var order = localStorage.getItem(sortable.options.group);
return order ? order.split('|') : [];
},
set: function (sortable) {
var order = sortable.toArray();
localStorage.setItem(sortable.options.group, order.join('|'));
}
},
onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); },
onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); },
onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); },
onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);}
});
Sortable.create(bar, {
group: "words",
animation: 150,
onAdd: function (evt){ console.log('onAdd.bar:', evt.item); },
onUpdate: function (evt){ console.log('onUpdate.bar:', evt.item); },
onRemove: function (evt){ console.log('onRemove.bar:', evt.item); },
onStart:function(evt){ console.log('onStart.foo:', evt.item);},
onEnd: function(evt){ console.log('onEnd.foo:', evt.item);}
});
Sortable.create(multi, {
animation: 150,
draggable: '.tile',
handle: '.tile__name'
});
var editableList = Sortable.create(editable, {
animation: 150,
filter: '.js-remove',
onFilter: function (evt) {
evt.item.parentNode.removeChild(evt.item);
}
});
addUser.onclick = function () {
Ply.dialog('prompt', {
title: 'Add',
form: { name: 'name' }
}).done(function (ui) {
var el = document.createElement('li');
el.innerHTML = ui.data.name + '<i class="js-remove">âś–</i>';
editableList.el.appendChild(el);
});
};
[].forEach.call(multi.getElementsByClassName('tile__list'), function (el){
Sortable.create(el, {
group: 'photo',
animation: 150
});
});
[{
name: 'advanced',
pull: true,
put: true
},
{
name: 'advanced',
pull: 'clone',
put: false
}, {
name: 'advanced',
pull: false,
put: true
}].forEach(function (groupOpts, i) {
Sortable.create(document.getElementById('advanced-' + (i + 1)), {
sort: (i != 1),
group: groupOpts,
animation: 150
});
});
Sortable.create(document.getElementById('handle-1'), {
handle: '.drag-handle',
animation: 150
});
angular.module('todoApp', ['ng-sortable'])
.controller('TodoController', ['$scope', function ($scope) {
$scope.todos = [
{text: 'learn angular', done: true},
{text: 'build an angular app', done: false}
];
$scope.addTodo = function () {
$scope.todos.push({text: $scope.todoText, done: false});
$scope.todoText = '';
};
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.archive = function () {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function (todo) {
if (!todo.done) $scope.todos.push(todo);
});
};
}])
.controller('TodoControllerNext', ['$scope', function ($scope) {
$scope.todos = [
{text: 'learn Sortable', done: true},
{text: 'use ng-sortable', done: false},
{text: 'Enjoy', done: false}
];
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.sortableConfig = { group: 'todo', animation: 150 };
'Start End Add Update Remove Sort'.split(' ').forEach(function (name) {
$scope.sortableConfig['on' + name] = console.log.bind(console, name);
});
}]);
})();
// Background
document.addEventListener( "DOMContentLoaded", function (){
function setNoiseBackground(el, width, height, opacity){
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
canvas.width = width;
canvas.height = height;
for( var i = 0; i < width; i++ ){
for( var j = 0; j < height; j++ ){
var val = Math.floor(Math.random() * 255);
context.fillStyle = "rgba(" + val + "," + val + "," + val + "," + opacity + ")";
context.fillRect(i, j, 1, 1);
}
}
el.style.background = "url(" + canvas.toDataURL("image/png") + ")";
}
setNoiseBackground(document.getElementsByTagName('body')[0], 50, 50, 0.02);
}, false );
</script>

4
ng-sortable.js

@ -15,7 +15,7 @@
'use strict'; 'use strict';
angular.module('ng-sortable', []) angular.module('ng-sortable', [])
.constant('$version', '0.3.2') .constant('$version', '0.3.3')
.directive('ngSortable', ['$parse', function ($parse) { .directive('ngSortable', ['$parse', function ($parse) {
var removed; var removed;
@ -76,7 +76,7 @@
if (evt.clone) { if (evt.clone) {
newIndex = Sortable.utils.index(evt.clone); newIndex = Sortable.utils.index(evt.clone);
prevItems.splice(newIndex, 0, removed); prevItems.splice(oldIndex, 0, removed);
evt.from.removeChild(evt.clone); evt.from.removeChild(evt.clone);
} }

6
st/app.css

@ -231,3 +231,9 @@ img {
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
font-weight: 300; font-weight: 300;
} }
#nested ul li {
background-color: rgba(0,0,0,.05);
}

186
st/app.js

@ -0,0 +1,186 @@
(function () {
var byId = function (id) { return document.getElementById(id); },
console = window.console;
if (!console.log) {
console.log = function () {
alert([].join.apply(arguments, ' '));
};
}
Sortable.create(byId('foo'), {
group: "words",
animation: 150,
store: {
get: function (sortable) {
var order = localStorage.getItem(sortable.options.group);
return order ? order.split('|') : [];
},
set: function (sortable) {
var order = sortable.toArray();
localStorage.setItem(sortable.options.group, order.join('|'));
}
},
onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); },
onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); },
onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); },
onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);}
});
Sortable.create(byId('bar'), {
group: "words",
animation: 150,
onAdd: function (evt){ console.log('onAdd.bar:', evt.item); },
onUpdate: function (evt){ console.log('onUpdate.bar:', evt.item); },
onRemove: function (evt){ console.log('onRemove.bar:', evt.item); },
onStart:function(evt){ console.log('onStart.foo:', evt.item);},
onEnd: function(evt){ console.log('onEnd.foo:', evt.item);}
});
// Multi groups
Sortable.create(byId('multi'), {
animation: 150,
draggable: '.tile',
handle: '.tile__name'
});
[].forEach.call(byId('multi').getElementsByClassName('tile__list'), function (el){
Sortable.create(el, {
group: 'photo',
animation: 150
});
});
// Editable list
var editableList = Sortable.create(byId('editable'), {
animation: 150,
filter: '.js-remove',
onFilter: function (evt) {
evt.item.parentNode.removeChild(evt.item);
}
});
byId('addUser').onclick = function () {
Ply.dialog('prompt', {
title: 'Add',
form: { name: 'name' }
}).done(function (ui) {
var el = document.createElement('li');
el.innerHTML = ui.data.name + '<i class="js-remove">âś–</i>';
editableList.el.appendChild(el);
});
};
// Advanced groups
[{
name: 'advanced',
pull: true,
put: true
},
{
name: 'advanced',
pull: 'clone',
put: false
}, {
name: 'advanced',
pull: false,
put: true
}].forEach(function (groupOpts, i) {
Sortable.create(byId('advanced-' + (i + 1)), {
sort: (i != 1),
group: groupOpts,
animation: 150
});
});
// 'handle' option
Sortable.create(byId('handle-1'), {
handle: '.drag-handle',
animation: 150
});
// Angular example
angular.module('todoApp', ['ng-sortable'])
.controller('TodoController', ['$scope', function ($scope) {
$scope.todos = [
{text: 'learn angular', done: true},
{text: 'build an angular app', done: false}
];
$scope.addTodo = function () {
$scope.todos.push({text: $scope.todoText, done: false});
$scope.todoText = '';
};
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.archive = function () {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function (todo) {
if (!todo.done) $scope.todos.push(todo);
});
};
}])
.controller('TodoControllerNext', ['$scope', function ($scope) {
$scope.todos = [
{text: 'learn Sortable', done: true},
{text: 'use ng-sortable', done: false},
{text: 'Enjoy', done: false}
];
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
};
$scope.sortableConfig = { group: 'todo', animation: 150 };
'Start End Add Update Remove Sort'.split(' ').forEach(function (name) {
$scope.sortableConfig['on' + name] = console.log.bind(console, name);
});
}]);
})();
// Background
document.addEventListener("DOMContentLoaded", function () {
function setNoiseBackground(el, width, height, opacity) {
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
canvas.width = width;
canvas.height = height;
for (var i = 0; i < width; i++) {
for (var j = 0; j < height; j++) {
var val = Math.floor(Math.random() * 255);
context.fillStyle = "rgba(" + val + "," + val + "," + val + "," + opacity + ")";
context.fillRect(i, j, 1, 1);
}
}
el.style.background = "url(" + canvas.toDataURL("image/png") + ")";
}
setNoiseBackground(document.getElementsByTagName('body')[0], 50, 50, 0.02);
}, false);
Loading…
Cancel
Save