PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/DAF/Applications/DAF.App.DynamicForm/DAF.App.DynamicForm/Scripts/plugins/knockout.mapping.js

#
JavaScript | 59 lines | 55 code | 1 blank | 3 comment | 118 complexity | 5fe58cdc91b9f5815b11d1cacad04d96 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. // Knockout Mapping plugin v2.1.0
  2. // (c) 2011 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/
  3. // License: MIT (http://www.opensource.org/licenses/mit-license.php)
  4. (function (d) { "function" === typeof require && "object" === typeof exports && "object" === typeof module ? d(require("knockout"), exports) : "function" === typeof define && define.amd ? define(["knockout", "exports"], d) : d(ko, ko.mapping = {}) })(function (d, f) {
  5. function C(a, c) { for (var b in c) c.hasOwnProperty(b) && c[b] && (b && a[b] && !(a[b] instanceof Array) ? C(a[b], c[b]) : a[b] = c[b]) } function D(a, c) { var b = {}; C(b, a); C(b, c); return b } function E(a, c) {
  6. a = a || {}; if (a.create instanceof Function || a.update instanceof Function || a.key instanceof Function ||
  7. a.arrayChanged instanceof Function) a = { "": a }; c && (a.ignore = i(c.ignore, a.ignore), a.include = i(c.include, a.include), a.copy = i(c.copy, a.copy)); a.ignore = i(a.ignore, g.ignore); a.include = i(a.include, g.include); a.copy = i(a.copy, g.copy); a.mappedProperties = a.mappedProperties || {}; return a
  8. } function i(a, c) { a instanceof Array || (a = "undefined" === f.getType(a) ? [] : [a]); c instanceof Array || (c = "undefined" === f.getType(c) ? [] : [c]); return a.concat(c) } function M(a, c) {
  9. var b = d.dependentObservable; d.dependentObservable = function (b,
  10. c, e) { var e = e || {}, f = e.deferEvaluation; b && "object" == typeof b && (e = b); var l = !1, k = function (b) { var c = o({ read: function () { l || (d.utils.arrayRemoveItem(a, b), l = !0); return b.apply(b, arguments) }, write: function (a) { return b(a) }, deferEvaluation: !0 }); c.__ko_proto__ = o; return c }; e.deferEvaluation = !0; b = new o(b, c, e); b.__ko_proto__ = o; f || (a.push(b), b = k(b)); return b }; d.computed = d.dependentObservable; var e = c(); d.dependentObservable = b; d.computed = d.dependentObservable; return e
  11. } function z(a, c, b, e, v, g) {
  12. var y = d.utils.unwrapObservable(c) instanceof
  13. Array, g = g || ""; if (f.isMapped(a)) var j = d.utils.unwrapObservable(a)[n], b = D(j, b); var l = function () { return b[e] && b[e].create instanceof Function }, k = function (a) { return M(F, function () { return b[e].create({ data: a || c, parent: v }) }) }, s = function () { return b[e] && b[e].update instanceof Function }, q = function (a, f) { var h = { data: f || c, parent: v, target: d.utils.unwrapObservable(a) }; d.isWriteableObservable(a) && (h.observable = a); return b[e].update(h) }; if (j = A.get(c)) return j; e = e || ""; if (y) {
  14. var y = [], m = !1, h = function (a) { return a }; b[e] &&
  15. b[e].key && (h = b[e].key, m = !0); d.isObservable(a) || (a = d.observableArray([]), a.mappedRemove = function (b) { var c = "function" == typeof b ? b : function (a) { return a === h(b) }; return a.remove(function (a) { return c(h(a)) }) }, a.mappedRemoveAll = function (b) { var c = w(b, h); return a.remove(function (a) { return -1 != d.utils.arrayIndexOf(c, h(a)) }) }, a.mappedDestroy = function (b) { var c = "function" == typeof b ? b : function (a) { return a === h(b) }; return a.destroy(function (a) { return c(h(a)) }) }, a.mappedDestroyAll = function (b) {
  16. var c = w(b, h); return a.destroy(function (a) {
  17. return -1 !=
  18. d.utils.arrayIndexOf(c, h(a))
  19. })
  20. }, a.mappedIndexOf = function (b) { var c = w(a(), h), b = h(b); return d.utils.arrayIndexOf(c, b) }, a.mappedCreate = function (b) { if (-1 !== a.mappedIndexOf(b)) throw Error("There already is an object with the key that you specified."); var c = l() ? k(b) : b; s() && (b = q(c, b), d.isWriteableObservable(c) ? c(b) : c = b); a.push(c); return c }); var j = w(d.utils.unwrapObservable(a), h).sort(), i = w(c, h); m && i.sort(); for (var m = d.utils.compareArrays(j, i), j = {}, i = [], o = 0, u = m.length; o < u; o++) {
  21. var t = m[o], p, r = g + "[" + o + "]"; switch (t.status) {
  22. case "added": var x =
  23. B(d.utils.unwrapObservable(c), t.value, h); p = z(void 0, x, b, e, a, r); l() || (p = d.utils.unwrapObservable(p)); r = I(d.utils.unwrapObservable(c), x, j); i[r] = p; j[r] = !0; break; case "retained": x = B(d.utils.unwrapObservable(c), t.value, h); p = B(a, t.value, h); z(p, x, b, e, a, r); r = I(d.utils.unwrapObservable(c), x, j); i[r] = p; j[r] = !0; break; case "deleted": p = B(a, t.value, h)
  24. } y.push({ event: t.status, item: p })
  25. } a(i); b[e] && b[e].arrayChanged && d.utils.arrayForEach(y, function (a) { b[e].arrayChanged(a.event, a.item) })
  26. } else if (G(c)) {
  27. a = d.utils.unwrapObservable(a);
  28. if (!a) { if (l()) return m = k(), s() && (m = q(m)), m; if (s()) return q(m); a = {} } s() && (a = q(a)); A.save(c, a); J(c, function (e) { var f = g.length ? g + "." + e : e; if (-1 == d.utils.arrayIndexOf(b.ignore, f)) if (-1 != d.utils.arrayIndexOf(b.copy, f)) a[e] = c[e]; else { var v = A.get(c[e]) || z(a[e], c[e], b, e, a, f); if (d.isWriteableObservable(a[e])) a[e](d.utils.unwrapObservable(v)); else a[e] = v; b.mappedProperties[f] = !0 } })
  29. } else switch (f.getType(c)) {
  30. case "function": s() ? d.isWriteableObservable(c) ? (c(q(c)), a = c) : a = q(c) : a = c; break; default: d.isWriteableObservable(a) ?
  31. s() ? a(q(a)) : a(d.utils.unwrapObservable(c)) : (a = l() ? k() : d.observable(d.utils.unwrapObservable(c)), s() && a(q(a)))
  32. } return a
  33. } function I(a, c, b) { for (var e = 0, d = a.length; e < d; e++) if (!0 !== b[e] && a[e] === c) return e; return null } function K(a, c) { var b; c && (b = c(a)); "undefined" === f.getType(b) && (b = a); return d.utils.unwrapObservable(b) } function B(a, c, b) {
  34. a = d.utils.arrayFilter(d.utils.unwrapObservable(a), function (a) { return K(a, b) === c }); if (0 == a.length) throw Error("When calling ko.update*, the key '" + c + "' was not found!");
  35. if (1 < a.length && G(a[0])) throw Error("When calling ko.update*, the key '" + c + "' was not unique!"); return a[0]
  36. } function w(a, c) { return d.utils.arrayMap(d.utils.unwrapObservable(a), function (a) { return c ? K(a, c) : a }) } function J(a, c) { if (a instanceof Array) for (var b = 0; b < a.length; b++) c(b); else for (b in a) c(b) } function G(a) { var c = f.getType(a); return "object" === c && null !== a && "undefined" !== c } function L() {
  37. var a = [], c = []; this.save = function (b, e) { var f = d.utils.arrayIndexOf(a, b); 0 <= f ? c[f] = e : (a.push(b), c.push(e)) }; this.get =
  38. function (b) { b = d.utils.arrayIndexOf(a, b); return 0 <= b ? c[b] : void 0 }
  39. } var n = "__ko_mapping__", o = d.dependentObservable, H = 0, F, A, u = { include: ["_destroy"], ignore: [], copy: [] }, g = u; f.isMapped = function (a) { return (a = d.utils.unwrapObservable(a)) && a[n] }; f.fromJS = function (a) {
  40. if (0 == arguments.length) throw Error("When calling ko.fromJS, pass the object you want to convert."); window.setTimeout(function () { H = 0 }, 0); H++ || (F = [], A = new L); var c, b; 2 == arguments.length && (arguments[1][n] ? b = arguments[1] : c = arguments[1]); 3 == arguments.length &&
  41. (c = arguments[1], b = arguments[2]); b && (c = D(c, b[n])); c = E(c); var e = z(b, a, c); b && (e = b); --H || window.setTimeout(function () { d.utils.arrayForEach(F, function (a) { a && a() }) }, 0); e[n] = D(e[n], c); return e
  42. }; f.fromJSON = function (a) { var c = d.utils.parseJson(a); arguments[0] = c; return f.fromJS.apply(this, arguments) }; f.updateFromJS = function () { throw Error("ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!"); }; f.updateFromJSON = function () {
  43. throw Error("ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!");
  44. }; f.toJS = function (a, c) {
  45. g || f.resetDefaultOptions(); if (0 == arguments.length) throw Error("When calling ko.mapping.toJS, pass the object you want to convert."); if (!(g.ignore instanceof Array)) throw Error("ko.mapping.defaultOptions().ignore should be an array."); if (!(g.include instanceof Array)) throw Error("ko.mapping.defaultOptions().include should be an array."); if (!(g.copy instanceof Array)) throw Error("ko.mapping.defaultOptions().copy should be an array."); c = E(c, a[n]); return f.visitModel(a, function (a) { return d.utils.unwrapObservable(a) },
  46. c)
  47. }; f.toJSON = function (a, c) { var b = f.toJS(a, c); return d.utils.stringifyJson(b) }; f.defaultOptions = function () { if (0 < arguments.length) g = arguments[0]; else return g }; f.resetDefaultOptions = function () { g = { include: u.include.slice(0), ignore: u.ignore.slice(0), copy: u.copy.slice(0)} }; f.getType = function (a) { return a && "object" === typeof a && a.constructor == (new Date).constructor ? "date" : typeof a }; f.visitModel = function (a, c, b) {
  48. b = b || {}; b.visitedObjects = b.visitedObjects || new L; b.parentName || (b = E(b)); var e, g = d.utils.unwrapObservable(a);
  49. if (G(g)) c(a, b.parentName), e = g instanceof Array ? [] : {}; else return c(a, b.parentName); b.visitedObjects.save(a, e); var i = b.parentName; J(g, function (a) {
  50. if (!(b.ignore && -1 != d.utils.arrayIndexOf(b.ignore, a))) {
  51. var j = g[a], l = b, k = i || ""; g instanceof Array ? i && (k += "[" + a + "]") : (i && (k += "."), k += a); l.parentName = k; if (!(-1 === d.utils.arrayIndexOf(b.copy, a) && -1 === d.utils.arrayIndexOf(b.include, a) && g[n] && g[n].mappedProperties && !g[n].mappedProperties[a] && !(g instanceof Array))) switch (f.getType(d.utils.unwrapObservable(j))) {
  52. case "object": case "undefined": l =
  53. b.visitedObjects.get(j); e[a] = "undefined" !== f.getType(l) ? l : f.visitModel(j, c, b); break; default: e[a] = c(j, b.parentName)
  54. }
  55. }
  56. }); return e
  57. }
  58. });