1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

First separation commit.

Added LICENSE, README.md, CONTRIBUTORS.md
This commit is contained in:
Erwin de Haan 2019-01-09 12:36:54 +01:00
parent 09513af31b
commit 4678528d00
657 changed files with 422 additions and 0 deletions

View file

@ -0,0 +1,139 @@
<link rel="import" href="../polymer/polymer.html">
<script src="./Sortable.js"></script>
<dom-module id="sortable-js">
<template>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: "sortable-js",
properties: {
group : { type: String, value: () => Math.random(), observer: "groupChanged" },
sort : { type: Boolean, value: true, observer: "sortChanged" },
disabled : { type: Boolean, value: false, observer: "disabledChanged" },
store : { type: Object, value: null, observer: "storeChanged" },
handle : { type: String, value: null, observer: "handleChanged" },
scrollSensitivity : { type: Number, value: 30, observer: "scrollSensitivityChanged" },
scrollSpeed : { type: Number, value: 10, observer: "scrollSpeedChanged" },
ghostClass : { type: String, value: "sortable-ghost", observer: "ghostClassChanged" },
chosenClass : { type: String, value: "sortable-chosen", observer: "chosenClassChanged" },
ignore : { type: String, value: "a, img", observer: "ignoreChanged" },
filter : { type: Object, value: null, observer: "filterChanged" },
animation : { type: Number, value: 0, observer: "animationChanged" },
dropBubble : { type: Boolean, value: false, observer: "dropBubbleChanged" },
dragoverBubble : { type: Boolean, value: false, observer: "dragoverBubbleChanged" },
dataIdAttr : { type: String, value: "data-id", observer: "dataIdAttrChanged" },
delay : { type: Number, value: 0, observer: "delayChanged" },
forceFallback : { type: Boolean, value: false, observer: "forceFallbackChanged" },
fallbackClass : { type: String, value: "sortable-fallback", observer: "fallbackClassChanged" },
fallbackOnBody : { type: Boolean, value: false, observer: "fallbackOnBodyChanged" },
draggable : {},
scroll : {}
},
created() {
// override default DOM property behavior
Object.defineProperties(this, {
draggable: { get() { return this._draggable || this.getAttribute("draggable") || ">*"}, set(value) { this._draggable = value; this.draggableChanged(value)} },
scroll: { get() { return this._scroll || JSON.parse(this.getAttribute("scroll") || "true") }, set(value) { this._scroll = value; this.scrollChanged(value)} }
})
},
attached: function() {
// Given
// <sortable-js>
// <template is="dom-repeat" items={{data}}>
// <div>
// <template is="dom-if" if="true">
// <span>hello</span></template></div>
// After render, it becomes
// <sortable-js>
// <div>
// <span>hello</span>
// <template is="dom-if">
// <tempalte is="dom-repeat">
var templates = this.querySelectorAll("template[is='dom-repeat']")
var template = templates[templates.length-1]
var options = {}
Object.keys(this.properties).forEach(key => {
options[key] = this[key]
})
this.sortable = Sortable.create(this, Object.assign(options, {
onUpdate: e => {
if (template) {
template.splice("items", e.newIndex, 0, template.splice("items", e.oldIndex, 1)[0])
}
this.fire("update", e)
},
onAdd: e => {
if (template) {
var froms = e.from.querySelectorAll("template[is='dom-repeat']")
var from = froms[froms.length-1]
var item = from.items[e.oldIndex]
template.splice("items", e.newIndex, 0, item)
}
this.fire("add", e)
},
onRemove: e => {
if (template) {
template.splice("items", e.oldIndex, 1)[0]
}
this.fire("remove", e)
},
onStart: e => {
this.fire("start", e)
},
onEnd: e => {
this.fire("end", e)
},
onSort: e => {
this.fire("sort", e)
},
onFilter: e => {
this.fire("filter", e)
},
onMove: e => {
this.fire("move", e)
}
}))
},
detached: function() {
this.sortable.destroy()
},
groupChanged : function(value) { this.sortable && this.sortable.option("group", value) },
sortChanged : function(value) { this.sortable && this.sortable.option("sort", value) },
disabledChanged : function(value) { this.sortable && this.sortable.option("disabled", value) },
storeChanged : function(value) { this.sortable && this.sortable.option("store", value) },
handleChanged : function(value) { this.sortable && this.sortable.option("handle", value) },
scrollChanged : function(value) { this.sortable && this.sortable.option("scroll", value) },
scrollSensitivityChanged : function(value) { this.sortable && this.sortable.option("scrollSensitivity", value) },
scrollSpeedChanged : function(value) { this.sortable && this.sortable.option("scrollSpeed", value) },
draggableChanged : function(value) { this.sortable && this.sortable.option("draggable", value) },
ghostClassChanged : function(value) { this.sortable && this.sortable.option("ghostClass", value) },
chosenClassChanged : function(value) { this.sortable && this.sortable.option("chosenClass", value) },
ignoreChanged : function(value) { this.sortable && this.sortable.option("ignore", value) },
filterChanged : function(value) { this.sortable && this.sortable.option("filter", value) },
animationChanged : function(value) { this.sortable && this.sortable.option("animation", value) },
dropBubbleChanged : function(value) { this.sortable && this.sortable.option("dropBubble", value) },
dragoverBubbleChanged : function(value) { this.sortable && this.sortable.option("dragoverBubble", value) },
dataIdAttrChanged : function(value) { this.sortable && this.sortable.option("dataIdAttr", value) },
delayChanged : function(value) { this.sortable && this.sortable.option("delay", value) },
forceFallbackChanged : function(value) { this.sortable && this.sortable.option("forceFallback", value) },
fallbackClassChanged : function(value) { this.sortable && this.sortable.option("fallbackClass", value) },
fallbackOnBodyChanged : function(value) { this.sortable && this.sortable.option("fallbackOnBody", value) }
})
</script>

View file

@ -0,0 +1,393 @@
/*! Sortable 1.4.2 - MIT | git://github.com/rubaxa/Sortable.git */ ! function(a) {
"use strict";
"function" == typeof define && define.amd ? define(a) : "undefined" != typeof module && "undefined" != typeof module.exports ? module.exports = a() : "undefined" != typeof Package ? Sortable = a() : window.Sortable = a()
}(function() {
"use strict";
function a(a, b) {
if (!a || !a.nodeType || 1 !== a.nodeType) throw "Sortable: `el` must be HTMLElement, and not " + {}.toString.call(a);
this.el = a, this.options = b = r({}, b), a[L] = this;
var c = {
group: Math.random(),
sort: !0,
disabled: !1,
store: null,
handle: null,
scroll: !0,
scrollSensitivity: 30,
scrollSpeed: 10,
draggable: /[uo]l/i.test(a.nodeName) ? "li" : ">*",
ghostClass: "sortable-ghost",
chosenClass: "sortable-chosen",
ignore: "a, img",
filter: null,
animation: 0,
setData: function(a, b) {
a.setData("Text", b.textContent)
},
dropBubble: !1,
dragoverBubble: !1,
dataIdAttr: "data-id",
delay: 0,
forceFallback: !1,
fallbackClass: "sortable-fallback",
fallbackOnBody: !1
};
for (var d in c) !(d in b) && (b[d] = c[d]);
V(b);
for (var f in this) "_" === f.charAt(0) && (this[f] = this[f].bind(this));
this.nativeDraggable = b.forceFallback ? !1 : P, e(a, "mousedown", this._onTapStart), e(a, "touchstart", this._onTapStart), this.nativeDraggable && (e(a, "dragover", this), e(a, "dragenter", this)), T.push(this._onDragOver), b.store && this.sort(b.store.get(this))
}
function b(a) {
v && v.state !== a && (h(v, "display", a ? "none" : ""), !a && v.state && w.insertBefore(v, s), v.state = a)
}
function c(a, b, c) {
if (a) {
c = c || N, b = b.split(".");
var d = b.shift().toUpperCase(),
e = new RegExp("\\s(" + b.join("|") + ")(?=\\s)", "g");
do
if (">*" === d && a.parentNode === c || ("" === d || a.nodeName.toUpperCase() == d) && (!b.length || ((" " + a.className + " ").match(e) || []).length == b.length)) return a; while (a !== c && (a = a.parentNode))
}
return null
}
function d(a) {
a.dataTransfer && (a.dataTransfer.dropEffect = "move"), a.preventDefault()
}
function e(a, b, c) {
a.addEventListener(b, c, !1)
}
function f(a, b, c) {
a.removeEventListener(b, c, !1)
}
function g(a, b, c) {
if (a)
if (a.classList) a.classList[c ? "add" : "remove"](b);
else {
var d = (" " + a.className + " ").replace(K, " ").replace(" " + b + " ", " ");
a.className = (d + (c ? " " + b : "")).replace(K, " ")
}
}
function h(a, b, c) {
var d = a && a.style;
if (d) {
if (void 0 === c) return N.defaultView && N.defaultView.getComputedStyle ? c = N.defaultView.getComputedStyle(a, "") : a.currentStyle && (c = a.currentStyle), void 0 === b ? c : c[b];
b in d || (b = "-webkit-" + b), d[b] = c + ("string" == typeof c ? "" : "px")
}
}
function i(a, b, c) {
if (a) {
var d = a.getElementsByTagName(b),
e = 0,
f = d.length;
if (c)
for (; f > e; e++) c(d[e], e);
return d
}
return []
}
function j(a, b, c, d, e, f, g) {
var h = N.createEvent("Event"),
i = (a || b[L]).options,
j = "on" + c.charAt(0).toUpperCase() + c.substr(1);
h.initEvent(c, !0, !0), h.to = b, h.from = e || b, h.item = d || b, h.clone = v, h.oldIndex = f, h.newIndex = g, b.dispatchEvent(h), i[j] && i[j].call(a, h)
}
function k(a, b, c, d, e, f) {
var g, h, i = a[L],
j = i.options.onMove;
return g = N.createEvent("Event"), g.initEvent("move", !0, !0), g.to = b, g.from = a, g.dragged = c, g.draggedRect = d, g.related = e || b, g.relatedRect = f || b.getBoundingClientRect(), a.dispatchEvent(g), j && (h = j.call(i, g)), h
}
function l(a) {
a.draggable = !1
}
function m() {
R = !1
}
function n(a, b) {
var c = a.lastElementChild,
d = c.getBoundingClientRect();
return (b.clientY - (d.top + d.height) > 5 || b.clientX - (d.right + d.width) > 5) && c
}
function o(a) {
for (var b = a.tagName + a.className + a.src + a.href + a.textContent, c = b.length, d = 0; c--;) d += b.charCodeAt(c);
return d.toString(36)
}
function p(a) {
var b = 0;
if (!a || !a.parentNode) return -1;
for (; a && (a = a.previousElementSibling);) "TEMPLATE" !== a.nodeName.toUpperCase() && b++;
return b
}
function q(a, b) {
var c, d;
return function() {
void 0 === c && (c = arguments, d = this, setTimeout(function() {
1 === c.length ? a.call(d, c[0]) : a.apply(d, c), c = void 0
}, b))
}
}
function r(a, b) {
if (a && b)
for (var c in b) b.hasOwnProperty(c) && (a[c] = b[c]);
return a
}
var s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J = {},
K = /\s+/g,
L = "Sortable" + (new Date).getTime(),
M = window,
N = M.document,
O = M.parseInt,
P = !!("draggable" in N.createElement("div")),
Q = function(a) {
return a = N.createElement("x"), a.style.cssText = "pointer-events:auto", "auto" === a.style.pointerEvents
}(),
R = !1,
S = Math.abs,
T = ([].slice, []),
U = q(function(a, b, c) {
if (c && b.scroll) {
var d, e, f, g, h = b.scrollSensitivity,
i = b.scrollSpeed,
j = a.clientX,
k = a.clientY,
l = window.innerWidth,
m = window.innerHeight;
if (z !== c && (y = b.scroll, z = c, y === !0)) {
y = c;
do
if (y.offsetWidth < y.scrollWidth || y.offsetHeight < y.scrollHeight) break; while (y = y.parentNode)
}
y && (d = y, e = y.getBoundingClientRect(), f = (S(e.right - j) <= h) - (S(e.left - j) <= h), g = (S(e.bottom - k) <= h) - (S(e.top - k) <= h)), f || g || (f = (h >= l - j) - (h >= j), g = (h >= m - k) - (h >= k), (f || g) && (d = M)), (J.vx !== f || J.vy !== g || J.el !== d) && (J.el = d, J.vx = f, J.vy = g, clearInterval(J.pid), d && (J.pid = setInterval(function() {
d === M ? M.scrollTo(M.pageXOffset + f * i, M.pageYOffset + g * i) : (g && (d.scrollTop += g * i), f && (d.scrollLeft += f * i))
}, 24)))
}
}, 30),
V = function(a) {
var b = a.group;
b && "object" == typeof b || (b = a.group = {
name: b
}), ["pull", "put"].forEach(function(a) {
a in b || (b[a] = !0)
}), a.groups = " " + b.name + (b.put.join ? " " + b.put.join(" ") : "") + " "
};
return a.prototype = {
constructor: a,
_onTapStart: function(a) {
var b = this,
d = this.el,
e = this.options,
f = a.type,
g = a.touches && a.touches[0],
h = (g || a).target,
i = h,
k = e.filter;
if (!("mousedown" === f && 0 !== a.button || e.disabled) && (h = c(h, e.draggable, d))) {
if (D = p(h), "function" == typeof k) {
if (k.call(this, a, h, this)) return j(b, i, "filter", h, d, D), void a.preventDefault()
} else if (k && (k = k.split(",").some(function(a) {
return a = c(i, a.trim(), d), a ? (j(b, a, "filter", h, d, D), !0) : void 0
}))) return void a.preventDefault();
(!e.handle || c(i, e.handle, d)) && this._prepareDragStart(a, g, h)
}
},
_prepareDragStart: function(a, b, c) {
var d, f = this,
h = f.el,
j = f.options,
k = h.ownerDocument;
c && !s && c.parentNode === h && (G = a, w = h, s = c, t = s.parentNode, x = s.nextSibling, F = j.group, d = function() {
f._disableDelayedDrag(), s.draggable = !0, g(s, f.options.chosenClass, !0), f._triggerDragStart(b)
}, j.ignore.split(",").forEach(function(a) {
i(s, a.trim(), l)
}), e(k, "mouseup", f._onDrop), e(k, "touchend", f._onDrop), e(k, "touchcancel", f._onDrop), j.delay ? (e(k, "mouseup", f._disableDelayedDrag), e(k, "touchend", f._disableDelayedDrag), e(k, "touchcancel", f._disableDelayedDrag), e(k, "mousemove", f._disableDelayedDrag), e(k, "touchmove", f._disableDelayedDrag), f._dragStartTimer = setTimeout(d, j.delay)) : d())
},
_disableDelayedDrag: function() {
var a = this.el.ownerDocument;
clearTimeout(this._dragStartTimer), f(a, "mouseup", this._disableDelayedDrag), f(a, "touchend", this._disableDelayedDrag), f(a, "touchcancel", this._disableDelayedDrag), f(a, "mousemove", this._disableDelayedDrag), f(a, "touchmove", this._disableDelayedDrag)
},
_triggerDragStart: function(a) {
a ? (G = {
target: s,
clientX: a.clientX,
clientY: a.clientY
}, this._onDragStart(G, "touch")) : this.nativeDraggable ? (e(s, "dragend", this), e(w, "dragstart", this._onDragStart)) : this._onDragStart(G, !0);
try {
N.selection ? N.selection.empty() : window.getSelection().removeAllRanges()
} catch (b) {}
},
_dragStarted: function() {
w && s && (g(s, this.options.ghostClass, !0), a.active = this, j(this, w, "start", s, w, D))
},
_emulateDragOver: function() {
if (H) {
if (this._lastX === H.clientX && this._lastY === H.clientY) return;
this._lastX = H.clientX, this._lastY = H.clientY, Q || h(u, "display", "none");
var a = N.elementFromPoint(H.clientX, H.clientY),
b = a,
c = " " + this.options.group.name,
d = T.length;
if (b)
do {
if (b[L] && b[L].options.groups.indexOf(c) > -1) {
for (; d--;) T[d]({
clientX: H.clientX,
clientY: H.clientY,
target: a,
rootEl: b
});
break
}
a = b
} while (b = b.parentNode);
Q || h(u, "display", "")
}
},
_onTouchMove: function(b) {
if (G) {
a.active || this._dragStarted(), this._appendGhost();
var c = b.touches ? b.touches[0] : b,
d = c.clientX - G.clientX,
e = c.clientY - G.clientY,
f = b.touches ? "translate3d(" + d + "px," + e + "px,0)" : "translate(" + d + "px," + e + "px)";
I = !0, H = c, h(u, "webkitTransform", f), h(u, "mozTransform", f), h(u, "msTransform", f), h(u, "transform", f), b.preventDefault()
}
},
_appendGhost: function() {
if (!u) {
var a, b = s.getBoundingClientRect(),
c = h(s),
d = this.options;
u = s.cloneNode(!0), g(u, d.ghostClass, !1), g(u, d.fallbackClass, !0), h(u, "top", b.top - O(c.marginTop, 10)), h(u, "left", b.left - O(c.marginLeft, 10)), h(u, "width", b.width), h(u, "height", b.height), h(u, "opacity", "0.8"), h(u, "position", "fixed"), h(u, "zIndex", "100000"), h(u, "pointerEvents", "none"), d.fallbackOnBody && N.body.appendChild(u) || w.appendChild(u), a = u.getBoundingClientRect(), h(u, "width", 2 * b.width - a.width), h(u, "height", 2 * b.height - a.height)
}
},
_onDragStart: function(a, b) {
var c = a.dataTransfer,
d = this.options;
this._offUpEvents(), "clone" == F.pull && (v = s.cloneNode(!0), h(v, "display", "none"), w.insertBefore(v, s)), b ? ("touch" === b ? (e(N, "touchmove", this._onTouchMove), e(N, "touchend", this._onDrop), e(N, "touchcancel", this._onDrop)) : (e(N, "mousemove", this._onTouchMove), e(N, "mouseup", this._onDrop)), this._loopId = setInterval(this._emulateDragOver, 50)) : (c && (c.effectAllowed = "move", d.setData && d.setData.call(this, c, s)), e(N, "drop", this), setTimeout(this._dragStarted, 0))
},
_onDragOver: function(a) {
var d, e, f, g = this.el,
i = this.options,
j = i.group,
l = j.put,
o = F === j,
p = i.sort;
if (void 0 !== a.preventDefault && (a.preventDefault(), !i.dragoverBubble && a.stopPropagation()), I = !0, F && !i.disabled && (o ? p || (f = !w.contains(s)) : F.pull && l && (F.name === j.name || l.indexOf && ~l.indexOf(F.name))) && (void 0 === a.rootEl || a.rootEl === this.el)) {
if (U(a, i, this.el), R) return;
if (d = c(a.target, i.draggable, g), e = s.getBoundingClientRect(), f) return b(!0), void(v || x ? w.insertBefore(s, v || x) : p || w.appendChild(s));
if (0 === g.children.length || g.children[0] === u || g === a.target && (d = n(g, a))) {
if (d) {
if (d.animated) return;
r = d.getBoundingClientRect()
}
b(o), k(w, g, s, e, d, r) !== !1 && (s.contains(g) || (g.appendChild(s), t = g), this._animate(e, s), d && this._animate(r, d))
} else if (d && !d.animated && d !== s && void 0 !== d.parentNode[L]) {
A !== d && (A = d, B = h(d), C = h(d.parentNode));
var q, r = d.getBoundingClientRect(),
y = r.right - r.left,
z = r.bottom - r.top,
D = /left|right|inline/.test(B.cssFloat + B.display) || "flex" == C.display && 0 === C["flex-direction"].indexOf("row"),
E = d.offsetWidth > s.offsetWidth,
G = d.offsetHeight > s.offsetHeight,
H = (D ? (a.clientX - r.left) / y : (a.clientY - r.top) / z) > .5,
J = d.nextElementSibling,
K = k(w, g, s, e, d, r);
if (K !== !1) {
if (R = !0, setTimeout(m, 30), b(o), 1 === K || -1 === K) q = 1 === K;
else if (D) {
var M = s.offsetTop,
N = d.offsetTop;
q = M === N ? d.previousElementSibling === s && !E || H && E : N > M
} else q = J !== s && !G || H && G;
s.contains(g) || (q && !J ? g.appendChild(s) : d.parentNode.insertBefore(s, q ? J : d)), t = s.parentNode, this._animate(e, s), this._animate(r, d)
}
}
}
},
_animate: function(a, b) {
var c = this.options.animation;
if (c) {
var d = b.getBoundingClientRect();
h(b, "transition", "none"), h(b, "transform", "translate3d(" + (a.left - d.left) + "px," + (a.top - d.top) + "px,0)"), b.offsetWidth, h(b, "transition", "all " + c + "ms"), h(b, "transform", "translate3d(0,0,0)"), clearTimeout(b.animated), b.animated = setTimeout(function() {
h(b, "transition", ""), h(b, "transform", ""), b.animated = !1
}, c)
}
},
_offUpEvents: function() {
var a = this.el.ownerDocument;
f(N, "touchmove", this._onTouchMove), f(a, "mouseup", this._onDrop), f(a, "touchend", this._onDrop), f(a, "touchcancel", this._onDrop)
},
_onDrop: function(b) {
var c = this.el,
d = this.options;
clearInterval(this._loopId), clearInterval(J.pid), clearTimeout(this._dragStartTimer), f(N, "mousemove", this._onTouchMove), this.nativeDraggable && (f(N, "drop", this), f(c, "dragstart", this._onDragStart)), this._offUpEvents(), b && (I && (b.preventDefault(), !d.dropBubble && b.stopPropagation()), u && u.parentNode.removeChild(u), s && (this.nativeDraggable && f(s, "dragend", this), l(s), g(s, this.options.ghostClass, !1), g(s, this.options.chosenClass, !1), w !== t ? (E = p(s), E >= 0 && (j(null, t, "sort", s, w, D, E), j(this, w, "sort", s, w, D, E), j(null, t, "add", s, w, D, E), j(this, w, "remove", s, w, D, E))) : (v && v.parentNode.removeChild(v), s.nextSibling !== x && (E = p(s), E >= 0 && (j(this, w, "update", s, w, D, E), j(this, w, "sort", s, w, D, E)))), a.active && ((null === E || -1 === E) && (E = D), j(this, w, "end", s, w, D, E), this.save())), w = s = t = u = x = v = y = z = G = H = I = E = A = B = F = a.active = null)
},
handleEvent: function(a) {
var b = a.type;
"dragover" === b || "dragenter" === b ? s && (this._onDragOver(a), d(a)) : ("drop" === b || "dragend" === b) && this._onDrop(a)
},
toArray: function() {
for (var a, b = [], d = this.el.children, e = 0, f = d.length, g = this.options; f > e; e++) a = d[e], c(a, g.draggable, this.el) && b.push(a.getAttribute(g.dataIdAttr) || o(a));
return b
},
sort: function(a) {
var b = {},
d = this.el;
this.toArray().forEach(function(a, e) {
var f = d.children[e];
c(f, this.options.draggable, d) && (b[a] = f)
}, this), a.forEach(function(a) {
b[a] && (d.removeChild(b[a]), d.appendChild(b[a]))
})
},
save: function() {
var a = this.options.store;
a && a.set(this)
},
closest: function(a, b) {
return c(a, b || this.options.draggable, this.el)
},
option: function(a, b) {
var c = this.options;
return void 0 === b ? c[a] : (c[a] = b, void("group" === a && V(c)))
},
destroy: function() {
var a = this.el;
a[L] = null, f(a, "mousedown", this._onTapStart), f(a, "touchstart", this._onTapStart), this.nativeDraggable && (f(a, "dragover", this), f(a, "dragenter", this)), Array.prototype.forEach.call(a.querySelectorAll("[draggable]"), function(a) {
a.removeAttribute("draggable")
}), T.splice(T.indexOf(this._onDragOver), 1), this._onDrop(), this.el = a = null
}
}, a.utils = {
on: e,
off: f,
css: h,
find: i,
is: function(a, b) {
return !!c(a, b, a)
},
extend: r,
throttle: q,
closest: c,
toggleClass: g,
index: p
}, a.create = function(b, c) {
return new a(b, c)
}, a.version = "1.4.2", a
});

344
src/bower_components/Sortable/index.html vendored Normal file
View file

@ -0,0 +1,344 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta property="og:image" content="/st/og-image.png"/>
<title>Sortable. No jQuery.</title>
<meta name="keywords" content="sortable, reorder, list, javascript, html5, drag and drop, dnd, animation, groups, angular, ng-sortable, react, mixin, effects, rubaxa"/>
<meta name="description" content="Sortable - is a minimalist JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery. Supports Meteor, AngularJS, React and any CSS library, e.g. Bootstrap."/>
<meta name="viewport" content="width=device-width, initial-scale=0.5"/>
<link href="//rubaxa.github.io/Ply/ply.css" rel="stylesheet" type="text/css"/>
<link href="//fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet" type="text/css"/>
<link href="st/app.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<a href="https://github.com/RubaXa/Sortable"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 10000;" src="//s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div class="container">
<div style="padding: 80px 150px 0; height: 160px;">
<a class="logo" href="https://github.com/RubaXa/Sortable"><img src="st/logo.png"/></a>
<h1 data-force="40" data-force-y="2.5">The JavaScript library for modern browsers and touch devices. No&nbsp;jQuery.</h1>
</div>
</div>
<!-- Connected lists -->
<div class="container" style="height: 520px">
<div data-force="30" class="layer block" style="left: 14.5%; top: 0; width: 37%">
<div class="layer title">List A</div>
<ul id="foo" class="block__list block__list_words">
<li>бегемот</li>
<li>корм</li>
<li>антон</li>
<li>сало</li>
<li>железосталь</li>
<li>валик</li>
<li>кровать</li>
<li>краб</li>
</ul>
</div>
<div data-force="18" class="layer block" style="left: 58%; top: 143px; width: 40%;">
<div class="layer title">List B</div>
<ul id="bar" class="block__list block__list_tags">
<li>казнить</li>
<li>,</li>
<li>нельзя</li>
<li>помиловать</li>
</ul>
</div>
</div>
<!-- Multi connected lists -->
<a name="m"></a>
<div class="container">
<div id="multi" style="margin-left: 30px">
<div><div data-force="5" class="layer title title_xl">Multi</div></div>
<div class="layer tile" data-force="30">
<div class="tile__name">Group A</div>
<div class="tile__list">
<img src="st/face-01.jpg"/><!--
--><img src="st/face-02.jpg"/><!--
--><img src="st/face-03.jpg"/><!--
--><img src="st/face-04.jpg"/>
</div>
</div>
<div class="layer tile" data-force="25">
<div class="tile__name">Group B</div>
<div class="tile__list">
<img src="st/face-05.jpg"/><!--
--><img src="st/face-06.jpg"/><!--
--><img src="st/face-07.jpg"/>
</div>
</div>
<div class="layer tile" data-force="20">
<div class="tile__name">Group C</div>
<div class="tile__list">
<img src="st/face-08.jpg"/><!--
--><img src="st/face-09.jpg"/>
</div>
</div>
</div>
</div>
<!-- Editable list -->
<a name="e"></a>
<div class="container" style="margin-top: 100px">
<div id="filter" style="margin-left: 30px">
<div><div data-force="5" class="layer title title_xl">Editable list</div></div>
<div style="margin-top: -8px; margin-left: 10px" class="block__list block__list_words">
<ul id="editable">
<li>Оля<i class="js-remove"></i></li>
<li>Владимир<i class="js-remove"></i></li>
<li>Алина<i class="js-remove"></i></li>
</ul>
<button id="addUser">Add</button>
</div>
</div>
</div>
<!-- Advanced connected lists -->
<a name="ag"></a>
<div class="container" style="margin-top: 100px;">
<div id="advanced" style="margin-left: 30px;">
<div><div data-force="5" class="layer title title_xl">Advanced groups</div></div>
<div style="width: 25%; float: left; margin-top: 15px; margin-left: 10px" class="block__list block__list_words">
<div class="block__list-title">pull & put</div>
<ul id="advanced-1">
<li>Meat</li>
<li>Potato</li>
<li>Tea</li>
</ul>
</div>
<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&nbsp;reordering</div>
<ul id="advanced-2">
<li>Sex</li>
<li>Drugs</li>
<li>Rock'n'roll</li>
</ul>
</div>
<div style="width: 25%; float: left; margin-top: 15px; margin-left: 10px" class="block__list block__list_words">
<div class="block__list-title">only put</div>
<ul id="advanced-3">
<li>Money</li>
<li>Force</li>
<li>Agility</li>
</ul>
</div>
<div style="clear: both"></div>
</div>
</div>
<!-- 'handle' option -->
<a name="h"></a>
<div class="container" style="margin-top: 100px;">
<div id="handle" style="margin-left: 30px;">
<div><div data-force="5" class="layer title title_xl">Drag handle and selectable text</div></div>
<div style="width: 30%; margin-left: 10px" class="block__list_words">
<ul id="handle-1">
<li><span class="drag-handle">&#9776;</span>Select text freely</li>
<li><span class="drag-handle">&#9776;</span>Drag my handle</li>
<li><span class="drag-handle">&#9776;</span>Best of both worlds</li>
</ul>
</div>
<div style="clear: both"></div>
</div>
</div>
<!-- Angular -->
<a name="ng"></a>
<div id="todos" ng-app="todoApp" class="container" style="margin-top: 100px">
<div style="margin-left: 30px">
<div><div data-force="5" class="layer title title_xl">AngularJS / ng-sortable</div></div>
<div style="width: 30%; margin-top: -8px; margin-left: 10px; float: left;" class="block__list block__list_words">
<div ng-controller="TodoController">
<span style="padding-left: 20px">{{remaining()}} of {{todos.length}} remaining</span>
[ <a href="" ng-click="archive()">archive</a> ]
<ul ng-sortable="{ group: 'todo', animation: 150 }" class="unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="addTodo()" style="padding-left: 20px">
<input type="text" ng-model="todoText" size="30"
placeholder="add new todo here">
</form>
</div>
</div>
<div style="width: 30%; margin-top: -8px; margin-left: 10px; float: left;" class="block__list block__list_words">
<div ng-controller="TodoControllerNext">
<span style="padding-left: 20px">{{remaining()}} of {{todos.length}} remaining</span>
<ul ng-sortable="sortableConfig" class="unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
</div>
</div>
<div style="clear: both"></div>
</div>
</div>
<!-- Code example -->
<a name="c"></a>
<div class="container" style="margin-top: 100px">
<div style="margin-left: 30px">
<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
var list = document.getElementById("my-ui-list");
Sortable.create(list); // That's all.
// Grouping
var foo = document.getElementById("foo");
Sortable.create(foo, { group: "omega" });
var bar = document.getElementById("bar");
Sortable.create(bar, { group: "omega" });
// Or
var container = document.getElementById("multi");
var sort = Sortable.create(container, {
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
handle: ".tile__title", // Restricts sort start click/touch to the specified element
draggable: ".tile", // Specifies which items inside the element should be sortable
onUpdate: function (evt/**Event*/){
var item = evt.item; // the current dragged HTMLElement
}
});
// ..
sort.destroy();
// Editable list
var editableList = Sortable.create(editable, {
filter: '.js-remove',
onFilter: function (evt) {
var el = editableList.closest(evt.item); // get dragged item
el && el.parentNode.removeChild(el);
}
});
</code></pre>
</div>
<div class="container" style="margin: 100px 0;">
<div style="margin-left: 30px">
<div><div class="layer title title_xl">See also</div></div>
<div id="rubaxa-repos" data-force="100" class="layer" style="margin-top: -8px; margin-left: 10px; width: 90%; background-color: #fff;">Loading&hellip;</div>
<script src="//rubaxa.github.io/repos.js"></script>
</div>
</div>
</div>
<script src="Sortable.js"></script>
<script src="//rubaxa.github.io/Ply/Ply.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="st/app.js"></script>
<!-- highlight.js -->
<style>
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}
.tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #c82829;
}
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant {
color: #f5871f;
}
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #eab700;
}
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #718c00;
}
.tomorrow-aqua, pre .css .hexcolor {
color: #3e999f;
}
.tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #4271ae;
}
.tomorrow-purple, pre .keyword, pre .javascript .function {
color: #8959a8;
}
pre {
border: 0;
background-color: #fff;
}
pre code {
display: block;
color: #4d4d4c;
font-size: 15px;
font-family: Menlo, Monaco, Consolas, monospace;
line-height: 1.5;
padding: 30px;
}
</style>
<script src="//yandex.st/highlightjs/7.5/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-16483888-3', 'rubaxa.github.io');
ga('send', 'pageview');
</script>
</body>
</html>

View file

@ -0,0 +1,17 @@
! function(factory) {
"use strict";
"function" == typeof define && define.amd ? define(["jquery"], factory) : factory(jQuery)
}(function($) {
"use strict";
$.fn.sortable = function(options) {
var retVal, args = arguments;
return this.each(function() {
var $el = $(this),
sortable = $el.data("sortable");
if (sortable || !(options instanceof Object) && options || (sortable = new Sortable(this, options), $el.data("sortable", sortable)), sortable) {
if ("widget" === options) return sortable;
"destroy" === options ? (sortable.destroy(), $el.removeData("sortable")) : "function" == typeof sortable[options] ? retVal = sortable[options].apply(sortable, [].slice.call(args, 1)) : options in sortable.options && (retVal = sortable.option.apply(sortable, args))
}
}), void 0 === retVal ? this : retVal
}
});

View file

@ -0,0 +1,97 @@
! function(factory) {
"use strict";
if ("function" == typeof define && define.amd) define(["knockout"], factory);
else if ("function" == typeof require && "object" == typeof exports && "object" == typeof module) {
var ko = require("knockout");
factory(ko)
} else factory(window.ko)
}(function(ko) {
"use strict";
var init = function(element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) {
var options = buildOptions(valueAccessor, sortableOptions);
["onStart", "onEnd", "onRemove", "onAdd", "onUpdate", "onSort", "onFilter"].forEach(function(e) {
(options[e] || eventHandlers[e]) && (options[e] = function(eventType, parentVM, parentBindings, handler, e) {
var itemVM = ko.dataFor(e.item),
bindings = ko.utils.peekObservable(parentBindings()),
bindingHandlerBinding = bindings.sortable || bindings.draggable,
collection = bindingHandlerBinding.collection || bindingHandlerBinding.foreach;
handler && handler(e, itemVM, parentVM, collection, bindings), eventHandlers[eventType] && eventHandlers[eventType](e, itemVM, parentVM, collection, bindings)
}.bind(void 0, e, viewModel, allBindings, options[e]))
});
var sortableElement = Sortable.create(element, options);
return ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
sortableElement.destroy()
}), ko.bindingHandlers.template.init(element, valueAccessor)
},
update = function(element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) {
return ko.bindingHandlers.template.update(element, valueAccessor, allBindings, viewModel, bindingContext)
},
eventHandlers = function(handlers) {
var moveOperations = [],
tryMoveOperation = function(e, itemVM, parentVM, collection, parentBindings) {
var currentOperation = {
event: e,
itemVM: itemVM,
parentVM: parentVM,
collection: collection,
parentBindings: parentBindings
},
existingOperation = moveOperations.filter(function(op) {
return op.itemVM === currentOperation.itemVM
})[0];
if (existingOperation) {
moveOperations.splice(moveOperations.indexOf(existingOperation), 1);
var removeOperation = "remove" === currentOperation.event.type ? currentOperation : existingOperation,
addOperation = "add" === currentOperation.event.type ? currentOperation : existingOperation;
moveItem(itemVM, removeOperation.collection, addOperation.collection, addOperation.event.clone, addOperation.event)
} else moveOperations.push(currentOperation)
},
moveItem = function(itemVM, from, to, clone, e) {
var fromArray = from(),
originalIndex = fromArray.indexOf(itemVM),
newIndex = e.newIndex;
e.item.previousElementSibling && (newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling)), originalIndex > newIndex && (newIndex += 1)), e.item.parentNode.removeChild(e.item), fromArray.splice(originalIndex, 1), from.valueHasMutated(), clone && from !== to && (fromArray.splice(originalIndex, 0, itemVM), from.valueHasMutated()), to().splice(newIndex, 0, itemVM), to.valueHasMutated()
};
return handlers.onRemove = tryMoveOperation, handlers.onAdd = tryMoveOperation, handlers.onUpdate = function(e, itemVM, parentVM, collection, parentBindings) {
moveItem(itemVM, collection, collection, !1, e)
}, handlers
}({}),
buildOptions = function(bindingOptions, options) {
var merge = function(into, from) {
for (var prop in from) "[object Object]" === Object.prototype.toString.call(from[prop]) ? ("[object Object]" !== Object.prototype.toString.call(into[prop]) && (into[prop] = {}), into[prop] = merge(into[prop], from[prop])) : into[prop] = from[prop];
return into
},
unwrappedOptions = ko.utils.peekObservable(bindingOptions()).options || {};
return options = merge({}, options), unwrappedOptions.group && "[object Object]" !== Object.prototype.toString.call(unwrappedOptions.group) && (unwrappedOptions.group = {
name: unwrappedOptions.group
}), merge(options, unwrappedOptions)
};
ko.bindingHandlers.draggable = {
sortableOptions: {
group: {
pull: "clone",
put: !1
},
sort: !1
},
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
return init(element, valueAccessor, allBindings, viewModel, 0, ko.bindingHandlers.draggable.sortableOptions)
},
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
return update(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.draggable.sortableOptions)
}
}, ko.bindingHandlers.sortable = {
sortableOptions: {
group: {
pull: !0,
put: !0
}
},
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
return init(element, valueAccessor, allBindings, viewModel, 0, ko.bindingHandlers.sortable.sortableOptions)
},
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
return update(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.sortable.sortableOptions)
}
}
});

View file

@ -0,0 +1,87 @@
! function(factory) {
"use strict";
"function" == typeof define && define.amd ? define(["angular", "./Sortable"], factory) : "function" == typeof require && "object" == typeof exports && "object" == typeof module ? (require("angular"), factory(angular, require("./Sortable")), module.exports = "ng-sortable") : window.angular && window.Sortable && factory(angular, Sortable)
}(function(angular, Sortable) {
"use strict";
var expando = "Sortable:ng-sortable";
angular.module("ng-sortable", []).constant("ngSortableVersion", "0.4.0").constant("ngSortableConfig", {}).directive("ngSortable", ["$parse", "ngSortableConfig", function($parse, ngSortableConfig) {
var removed, nextSibling, getSourceFactory = function(el, scope) {
var ngRepeat = [].filter.call(el.childNodes, function(node) {
return 8 === node.nodeType && -1 !== node.nodeValue.indexOf("ngRepeat:")
})[0];
if (!ngRepeat) return function() {
return null
};
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/);
var itemsExpr = $parse(ngRepeat[2]);
return function() {
return itemsExpr(scope.$parent) || []
}
};
return {
restrict: "AC",
scope: {
ngSortable: "=?"
},
link: function(scope, $el) {
function _emitEvent(evt, item) {
var name = "on" + evt.type.charAt(0).toUpperCase() + evt.type.substr(1),
source = getSource();
options[name] && options[name]({
model: item || source[evt.newIndex],
models: source,
oldIndex: evt.oldIndex,
newIndex: evt.newIndex
})
}
function _sync(evt) {
var items = getSource();
if (items) {
var oldIndex = evt.oldIndex,
newIndex = evt.newIndex;
if (el !== evt.from) {
var prevItems = evt.from[expando]();
removed = prevItems[oldIndex], evt.clone ? (removed = angular.copy(removed), prevItems.splice(Sortable.utils.index(evt.clone), 0, prevItems.splice(oldIndex, 1)[0]), evt.from.removeChild(evt.clone)) : prevItems.splice(oldIndex, 1), items.splice(newIndex, 0, removed), evt.from.insertBefore(evt.item, nextSibling)
} else items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]);
scope.$apply()
}
}
var sortable, el = $el[0],
options = angular.extend(scope.ngSortable || {}, ngSortableConfig),
watchers = [],
getSource = getSourceFactory(el, scope);
el[expando] = getSource, sortable = Sortable.create(el, Object.keys(options).reduce(function(opts, name) {
return opts[name] = opts[name] || options[name], opts
}, {
onStart: function(evt) {
nextSibling = evt.item.nextSibling, _emitEvent(evt), scope.$apply()
},
onEnd: function(evt) {
_emitEvent(evt, removed), scope.$apply()
},
onAdd: function(evt) {
_sync(evt), _emitEvent(evt, removed), scope.$apply()
},
onUpdate: function(evt) {
_sync(evt), _emitEvent(evt)
},
onRemove: function(evt) {
_emitEvent(evt, removed)
},
onSort: function(evt) {
_emitEvent(evt)
}
})), $el.on("$destroy", function() {
angular.forEach(watchers, function(unwatch) {
unwatch()
}), sortable.destroy(), el[expando] = null, el = null, watchers = null, sortable = null, nextSibling = null
}), angular.forEach(["sort", "disabled", "draggable", "handle", "animation", "group", "ghostClass", "filter", "onStart", "onEnd", "onAdd", "onUpdate", "onRemove", "onSort"], function(name) {
watchers.push(scope.$watch("ngSortable." + name, function(value) {
void 0 !== value && (options[name] = value, /^on[A-Z]/.test(name) || sortable.option(name, value))
}))
})
}
}
}])
});

View file

@ -0,0 +1,71 @@
! function(factory) {
"use strict";
"undefined" != typeof module && void 0 !== module.exports ? module.exports = factory(require("./Sortable")) : "function" == typeof define && define.amd ? define(["./Sortable"], factory) : window.SortableMixin = factory(Sortable)
}(function(Sortable) {
"use strict";
function _getModelName(component) {
return component.sortableOptions && component.sortableOptions.model || _defaultOptions.model
}
function _getModelItems(component) {
var name = _getModelName(component);
return (component.state && component.state[name] || component.props[name]).slice()
}
function _extend(dst, src) {
for (var key in src) src.hasOwnProperty(key) && (dst[key] = src[key]);
return dst
}
var _nextSibling, _activeComponent, _defaultOptions = {
ref: "list",
model: "items",
animation: 100,
onStart: "handleStart",
onEnd: "handleEnd",
onAdd: "handleAdd",
onUpdate: "handleUpdate",
onRemove: "handleRemove",
onSort: "handleSort",
onFilter: "handleFilter",
onMove: "handleMove"
};
return {
sortableMixinVersion: "0.1.1",
_sortableInstance: null,
componentDidMount: function() {
var DOMNode, options = _extend(_extend({}, _defaultOptions), this.sortableOptions || {}),
copyOptions = _extend({}, options),
emitEvent = function(type, evt) {
var method = this[options[type]];
method && method.call(this, evt, this._sortableInstance)
}.bind(this);
"onStart onEnd onAdd onSort onUpdate onRemove onFilter onMove".split(" ").forEach(function(name) {
copyOptions[name] = function(evt) {
if ("onStart" === name) _nextSibling = evt.item.nextElementSibling, _activeComponent = this;
else if ("onAdd" === name || "onUpdate" === name) {
evt.from.insertBefore(evt.item, _nextSibling);
var remoteItems, item, newState = {},
remoteState = {},
oldIndex = evt.oldIndex,
newIndex = evt.newIndex,
items = _getModelItems(this);
"onAdd" === name ? (remoteItems = _getModelItems(_activeComponent), item = remoteItems.splice(oldIndex, 1)[0], items.splice(newIndex, 0, item), remoteState[_getModelName(_activeComponent)] = remoteItems) : items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]), newState[_getModelName(this)] = items, copyOptions.stateHandler ? this[copyOptions.stateHandler](newState) : this.setState(newState), this !== _activeComponent && _activeComponent.setState(remoteState)
}
setTimeout(function() {
emitEvent(name, evt)
}, 0)
}.bind(this)
}, this), DOMNode = this.getDOMNode() ? (this.refs[options.ref] || this).getDOMNode() : this.refs[options.ref] || this, this._sortableInstance = Sortable.create(DOMNode, copyOptions)
},
componentWillReceiveProps: function(nextProps) {
var newState = {},
modelName = _getModelName(this),
items = nextProps[modelName];
items && (newState[modelName] = items, this.setState(newState))
},
componentWillUnmount: function() {
this._sortableInstance.destroy(), this._sortableInstance = null
}
}
});