js/knockout.sortable.js

(完整代码) 5KB

// knockout-sortable 0.9.3 | (c) 2014 Ryan Niemeyer |  http://www.opensource.org/licenses/mit-license
!function (a) { if ("function" == typeof define && define.amd) define(["knockout", "jquery", "jquery.ui.sortable"], a); else if ("function" == typeof require && "object" == typeof exports && "object" == typeof module) { var b = require("knockout"), c = require("jquery"); require("jquery.ui.sortable"), a(b, c) } else a(window.ko, window.jQuery) }(function (a, b) { var c = "ko_sortItem", d = "ko_sourceIndex", e = "ko_sortList", f = "ko_parentList", g = "ko_dragItem", h = a.utils.unwrapObservable, i = a.utils.domData.get, j = a.utils.domData.set, k = b.ui && b.ui.version, l = k && k.indexOf("1.6.") && k.indexOf("1.7.") && (k.indexOf("1.8.") || "1.8.24" === k), m = function (b, d) { a.utils.arrayForEach(b, function (a) { 1 === a.nodeType && (j(a, c, d), j(a, f, i(a.parentNode, e))) }) }, n = function (b, c) { var d, e = {}, f = h(b()) || {}; return f.data ? (e[c] = f.data, e.name = f.template) : e[c] = b(), a.utils.arrayForEach(["afterAdd", "afterRender", "as", "beforeRemove", "includeDestroyed", "templateEngine", "templateOptions"], function (b) { e[b] = f[b] || a.bindingHandlers.sortable[b] }), "foreach" === c && (e.afterRender ? (d = e.afterRender, e.afterRender = function (a, b) { m.call(b, a, b), d.call(b, a, b) }) : e.afterRender = m), e }, o = function (a, b) { var c = h(b); if (c) for (var d = 0; a > d; d++) c[d] && h(c[d]._destroy) && a++; return a }, p = function (c, d) { var e, f; d ? (f = document.getElementById(d), f && (e = new a.templateSources.domElement(f), e.text(b.trim(e.text())))) : b(c).contents().each(function () { this && 1 !== this.nodeType && c.removeChild(this) }) }; a.bindingHandlers.sortable = { init: function (k, m, q, r, s) { var t, u, v = b(k), w = h(m()) || {}, x = n(m, "foreach"), y = {}; p(k, x.name), b.extend(!0, y, a.bindingHandlers.sortable), w.options && y.options && (a.utils.extend(y.options, w.options), delete w.options), a.utils.extend(y, w), y.connectClass && (a.isObservable(y.allowDrop) || "function" == typeof y.allowDrop) ? a.computed({ read: function () { var b = h(y.allowDrop), c = "function" == typeof b ? b.call(this, x.foreach) : b; a.utils.toggleDomNodeCssClass(k, y.connectClass, c) }, disposeWhenNodeIsRemoved: k }, this) : a.utils.toggleDomNodeCssClass(k, y.connectClass, y.allowDrop), a.bindingHandlers.template.init(k, function () { return x }, q, r, s), t = y.options.start, u = y.options.update; var z = setTimeout(function () { var m; v.sortable(a.utils.extend(y.options, { start: function (b, c) { var e = c.item[0]; j(e, d, a.utils.arrayIndexOf(c.item.parent().children(), e)), c.item.find("input:focus").change(), t && t.apply(this, arguments) }, receive: function (a, b) { m = i(b.item[0], g), m && (m.clone && (m = m.clone()), y.dragged && (m = y.dragged.call(this, m, a, b) || m)) }, update: function (g, h) { var k, n, p, q, r, s = h.item[0], t = h.item.parent()[0], v = i(s, c) || m; if (m = null, v && this === t || !l && b.contains(this, t)) { if (k = i(s, f), p = i(s, d), n = i(s.parentNode, e), q = a.utils.arrayIndexOf(h.item.parent().children(), s), x.includeDestroyed || (p = o(p, k), q = o(q, n)), (y.beforeMove || y.afterMove) && (r = { item: v, sourceParent: k, sourceParentNode: k && h.sender || s.parentNode, sourceIndex: p, targetParent: n, targetIndex: q, cancelDrop: !1 }, y.beforeMove && y.beforeMove.call(this, r, g, h)), k ? b(k === n ? this : h.sender || this).sortable("cancel") : b(s).remove(), r && r.cancelDrop) return; q >= 0 && (k && (k.splice(p, 1), a.processAllDeferredBindingUpdates && a.processAllDeferredBindingUpdates()), n.splice(q, 0, v)), j(s, c, null), a.processAllDeferredBindingUpdates && a.processAllDeferredBindingUpdates(), y.afterMove && y.afterMove.call(this, r, g, h) } u && u.apply(this, arguments) }, connectWith: y.connectClass ? "." + y.connectClass : !1 })), void 0 !== y.isEnabled && a.computed({ read: function () { v.sortable(h(y.isEnabled) ? "enable" : "disable") }, disposeWhenNodeIsRemoved: k }) }, 0); return a.utils.domNodeDisposal.addDisposeCallback(k, function () { (v.data("ui-sortable") || v.data("sortable")) && v.sortable("destroy"), clearTimeout(z) }), { controlsDescendantBindings: !0 } }, update: function (b, c, d, f, g) { var h = n(c, "foreach"); j(b, e, h.foreach), a.bindingHandlers.template.update(b, function () { return h }, d, f, g) }, connectClass: "ko_container", allowDrop: !0, afterMove: null, beforeMove: null, options: {} }, a.bindingHandlers.draggable = { init: function (c, d, e, f, i) { var k = h(d()) || {}, l = k.options || {}, m = a.utils.extend({}, a.bindingHandlers.draggable.options), o = n(d, "data"), p = k.connectClass || a.bindingHandlers.draggable.connectClass, q = void 0 !== k.isEnabled ? k.isEnabled : a.bindingHandlers.draggable.isEnabled; return k = "data" in k ? k.data : k, j(c, g, k), a.utils.extend(m, l), m.connectToSortable = p ? "." + p : !1, b(c).draggable(m), void 0 !== q && a.computed({ read: function () { b(c).draggable(h(q) ? "enable" : "disable") }, disposeWhenNodeIsRemoved: c }), a.bindingHandlers.template.init(c, function () { return o }, e, f, i) }, update: function (b, c, d, e, f) { var g = n(c, "data"); return a.bindingHandlers.template.update(b, function () { return g }, d, e, f) }, connectClass: a.bindingHandlers.sortable.connectClass, options: { helper: "clone" } } });

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。