!
function(t) {
"function" == typeof define && define.amd ? define(["jquery", "codemirror"], t) : t(window.jQuery, window.CodeMirror)
}(function(t, e) {
"function" != typeof Array.prototype.reduce && (Array.prototype.reduce = function(t, e) {
var n, a, o = this.length >>> 0,
i = !1;
for (1 < arguments.length && (a = e, i = !0), n = 0; o > n; ++n) this.hasOwnProperty(n) && (i ? a = t(a, this[n], n, this) : (a = this[n], i = !0));
if (!i) throw new TypeError("Reduce of empty array with no initial value");
return a
});
var n = {
bMac: navigator.appVersion.indexOf("Mac") > -1,
bMSIE: navigator.userAgent.indexOf("MSIE") > -1,
bFF: navigator.userAgent.indexOf("Firefox") > -1,
bCodeMirror: !! e
},
a = function() {
var t = function(t) {
return function(e) {
return t === e
}
},
e = function(t, e) {
return t === e
},
n = function() {
return !1
},
a = function(t) {
return function() {
return !t.apply(t, arguments)
}
},
o = function(t) {
return t
};
return {
eq: t,
eq2: e,
fail: n,
not: a,
self: o
}
}(),
o = function() {
var t = function(t) {
return t[0]
},
e = function(t) {
return t[t.length - 1]
},
n = function(t) {
return t.slice(0, t.length - 1)
},
o = function(t) {
return t.slice(1)
},
i = function(t, e) {
return e = e || a.self, t.reduce(function(t, n) {
return t + e(n)
}, 0)
},
r = function(t) {
for (var e = [], n = -1, a = t.length; ++n < a;) e[n] = t[n];
return e
},
l = function(n, a) {
if (0 === n.length) return [];
var i = o(n);
return i.reduce(function(t, n) {
var o = e(t);
return a(e(o), n) ? o[o.length] = n : t[t.length] = [n], t
}, [
[t(n)]
])
},
s = function(t) {
for (var e = [], n = 0, a = t.length; a > n; n++) t[n] && e.push(t[n]);
return e
};
return {
head: t,
last: e,
initial: n,
tail: o,
sum: i,
from: r,
compact: s,
clusterBy: l
}
}(),
i = function() {
var e = function(t) {
return function(e) {
return e && e.nodeName === t
}
},
n = function(t) {
return t && /^DIV|^P|^LI|^H[1-7]/.test(t.nodeName)
},
r = "
",
l = function(t) {
return t && /^UL|^OL/.test(t.nodeName)
},
s = function(e) {
return e && t(e).hasClass("note-editable")
},
d = function(e) {
return e && t(e).hasClass("note-control-sizing")
},
c = function(t, e) {
for (; t;) {
if (e(t)) return t;
t = t.parentNode
}
return null
},
u = function(t, e) {
e = e || a.fail;
var n = [];
return c(t, function(t) {
return n.push(t), e(t)
}), n
},
f = function(e, n) {
for (var a = u(e), o = n; o; o = o.parentNode) if (t.inArray(o, a) > -1) return o;
return null
},
h = function(t, e) {
var n = [],
a = !1,
o = !1,
i = function(r) {
if (r) {
if (r === t && (a = !0), a && !o && n.push(r), r === e) return void(o = !0);
for (var l = 0, s = r.childNodes.length; s > l; l++) i(r.childNodes[l])
}
};
return i(f(t, e)), n
},
b = function(t, e) {
e = e || a.fail;
for (var n = []; t && (n.push(t), !e(t));) t = t.previousSibling;
return n
},
v = function(t, e) {
e = e || a.fail;
for (var n = []; t && (n.push(t), !e(t));) t = t.nextSibling;
return n
},
m = function(t, e) {
var n = e.nextSibling,
a = e.parentNode;
return n ? a.insertBefore(t, n) : a.appendChild(t), t
},
g = function(e, n) {
return t.each(n, function(t, n) {
e.appendChild(n)
}), e
},
p = e("#text"),
y = function(t) {
return p(t) ? t.nodeValue.length : t.childNodes.length
},
k = function(t) {
for (var e = 0; t = t.previousSibling;) e += 1;
return e
},
w = function(e, n) {
var i = o.initial(u(n, a.eq(e)));
return t.map(i, k).reverse()
},
C = function(t, e) {
for (var n = t, a = 0, o = e.length; o > a; a++) n = n.childNodes[e[a]];
return n
},
x = function(t, e) {
if (0 === e) return t;
if (e >= y(t)) return t.nextSibling;
if (p(t)) return t.splitText(e);
var n = t.childNodes[e];
return t = m(t.cloneNode(!1), t), g(t, v(n))
},
F = function(t, e, n) {
var o = u(e, a.eq(t));
return 1 === o.length ? x(e, n) : o.reduce(function(t, a) {
var o = a.cloneNode(!1);
return m(o, a), t === e && (t = x(t, n)), g(o, v(t)), o
})
},
S = function(t, e) {
if (t && t.parentNode) {
if (t.removeNode) return t.removeNode(e);
var n = t.parentNode;
if (!e) {
var a, o, i = [];
for (a = 0, o = t.childNodes.length; o > a; a++) i.push(t.childNodes[a]);
for (a = 0, o = i.length; o > a; a++) n.insertBefore(i[a], t)
}
n.removeChild(t)
}
},
A = function(t) {
return i.isTextarea(t[0]) ? t.val() : t.html()
};
return {
emptyPara: r,
isText: p,
isPara: n,
isList: l,
isEditable: s,
isControlSizing: d,
isAnchor: e("A"),
isDiv: e("DIV"),
isSpan: e("SPAN"),
isB: e("B"),
isU: e("U"),
isS: e("S"),
isI: e("I"),
isImg: e("IMG"),
isTextarea: e("TEXTAREA"),
ancestor: c,
listAncestor: u,
listNext: v,
listPrev: b,
commonAncestor: f,
listBetween: h,
insertAfter: m,
position: k,
makeOffsetPath: w,
fromOffsetPath: C,
split: F,
remove: S,
html: A
}
}(),
r = function() {
var e = !! document.createRange,
n = function(t, e) {
var n, a, r = t.parentElement(),
l = document.body.createTextRange(),
s = o.from(r.childNodes);
for (n = 0; n < s.length; n++) if (!i.isText(s[n])) {
if (l.moveToElementText(s[n]), l.compareEndPoints("StartToStart", t) >= 0) break;
a = s[n]
}
if (0 !== n && i.isText(s[n - 1])) {
var d = document.body.createTextRange(),
c = null;
d.moveToElementText(a || r), d.collapse(!a), c = a ? a.nextSibling : r.firstChild;
var u = t.duplicate();
u.setEndPoint("StartToStart", d);
for (var f = u.text.replace(/[\r\n]/g, "").length; f > c.nodeValue.length && c.nextSibling;) f -= c.nodeValue.length, c = c.nextSibling; {
c.nodeValue
}
e && c.nextSibling && i.isText(c.nextSibling) && f === c.nodeValue.length && (f -= c.nodeValue.length, c = c.nextSibling), r = c, n = f
}
return {
cont: r,
offset: n
}
},
r = function(t) {
var e = function(t, n) {
var r, l;
if (i.isText(t)) {
var s = i.listPrev(t, a.not(i.isText)),
d = o.last(s).previousSibling;
r = d || t.parentNode, n += o.sum(o.tail(s), i.length), l = !d
} else {
if (r = t.childNodes[n] || t, i.isText(r)) return e(r, n);
n = 0, l = !1
}
return {
cont: r,
collapseToStart: l,
offset: n
}
},
n = document.body.createTextRange(),
r = e(t.cont, t.offset);
return n.moveToElementText(r.cont), n.collapse(r.collapseToStart), n.moveStart("character", r.offset), n
},
l = function(n, l, s, d) {
this.sc = n, this.so = l, this.ec = s, this.eo = d;
var c = function() {
if (e) {
var t = document.createRange();
return t.setStart(n, l), t.setEnd(s, d), t
}
var a = r({
cont: n,
offset: l
});
return a.setEndPoint("EndToEnd", r({
cont: s,
offset: d
})), a
};
this.select = function() {
var t = c();
if (e) {
var n = document.getSelection();
n.rangeCount > 0 && n.removeAllRanges(), n.addRange(t)
} else t.select()
}, this.listPara = function() {
var e = i.listBetween(n, s),
r = o.compact(t.map(e, function(t) {
return i.ancestor(t, i.isPara)
}));
return t.map(o.clusterBy(r, a.eq2), o.head)
};
var u = function(t) {
return function() {
var e = i.ancestor(n, t);
return e && e === i.ancestor(s, t)
}
};
this.isOnEditable = u(i.isEditable), this.isOnList = u(i.isList), this.isOnAnchor = u(i.isAnchor), this.isCollapsed = function() {
return n === s && l === d
}, this.insertNode = function(t) {
var n = c();
e ? n.insertNode(t) : n.pasteHTML(t.outerHTML)
}, this.toString = function() {
var t = c();
return e ? t.toString() : t.text
}, this.bookmark = function(t) {
return {
s: {
path: i.makeOffsetPath(t, n),
offset: l
},
e: {
path: i.makeOffsetPath(t, s),
offset: d
}
}
}
};
return {
create: function(t, a, o, i) {
if (0 === arguments.length) if (e) {
var r = document.getSelection();
if (0 === r.rangeCount) return null;
var s = r.getRangeAt(0);
t = s.startContainer, a = s.startOffset, o = s.endContainer, i = s.endOffset
} else {
var d = document.selection.createRange(),
c = d.duplicate();
c.collapse(!1);
var u = d;
u.collapse(!0);
var f = n(u, !0),
h = n(c, !1);
t = f.cont, a = f.offset, o = h.cont, i = h.offset
} else 2 === arguments.length && (o = t, i = a);
return new l(t, a, o, i)
},
createFromBookmark: function(t, e) {
var n = i.fromOffsetPath(t, e.s.path),
a = e.s.offset,
o = i.fromOffsetPath(t, e.e.path),
r = e.e.offset;
return new l(n, a, o, r)
}
}
}(),
l = function() {
var e = function(e) {
return t.Deferred(function(t) {
var n = new FileReader;
n.onload = function(e) {
t.resolve(e.target.result)
}, n.onerror = function() {
t.reject(this)
}, n.readAsDataURL(e)
}).promise()
},
n = function(e) {
return t.Deferred(function(t) {
function n() {
o(), t.resolve(i)
}
function a() {
o(), t.reject(i)
}
function o() {
i.onload = null, i.onerror = null, i.onabort = null
}
var i = new Image;
i.onload = n, i.onerror = a, i.onabort = a, i.src = e
}).promise()
};
return {
readFile: e,
loadImage: n
}
}(),
s = function() {
this.stylePara = function(e, n) {
var a = e.listPara();
t.each(a, function(e, a) {
t.each(n, function(t, e) {
a.style[t] = e
})
})
}, this.current = function(e, n) {
var a = t(i.isText(e.sc) ? e.sc.parentNode : e.sc),
o = a.css(["font-size", "text-align", "list-style-type", "line-height"]) || {};
if (o["font-size"] = parseInt(o["font-size"]), o["font-bold"] = document.queryCommandState("bold") ? "bold" : "normal", o["font-italic"] = document.queryCommandState("italic") ? "italic" : "normal", o["font-underline"] = document.queryCommandState("underline") ? "underline" : "normal", e.isOnList()) {
var r = ["circle", "disc", "disc-leading-zero", "square"],
l = t.inArray(o["list-style-type"], r) > -1;
o["list-style"] = l ? "unordered" : "ordered"
} else o["list-style"] = "none";
var s = i.ancestor(e.sc, i.isPara);
if (s && s.style["line-height"]) o["line-height"] = s.style.lineHeight;
else {
var d = parseInt(o["line-height"]) / parseInt(o["font-size"]);
o["line-height"] = d.toFixed(1)
}
return o.image = i.isImg(n) && n, o.anchor = e.isOnAnchor() && i.ancestor(e.sc, i.isAnchor), o.aAncestor = i.listAncestor(e.sc, i.isEditable), o
}
},
d = function() {
var t = [],
e = [],
n = function(t) {
var e = t[0],
n = r.create();
return {
contents: t.html(),
bookmark: n.bookmark(e),
scrollTop: t.scrollTop()
}
},
a = function(t, e) {
t.html(e.contents).scrollTop(e.scrollTop), r.createFromBookmark(t[0], e.bookmark).select()
};
this.undo = function(o) {
var i = n(o);
0 !== t.length && (a(o, t.pop()), e.push(i))
}, this.redo = function(o) {
var i = n(o);
0 !== e.length && (a(o, e.pop()), t.push(i))
}, this.recordUndo = function(a) {
e = [], t.push(n(a))
}
},
c = function() {
this.saveRange = function(t) {
t.data("range", r.create())
}, this.restoreRange = function(t) {
var e = t.data("range");
e && e.select()
};
var e = new s;
this.currentStyle = function(t) {
var n = r.create();
return n.isOnEditable() && e.current(n, t)
}, this.tab = function(e) {
a(e);
var n = r.create(),
o = new Array(e.data("tabsize") + 1).join(" ");
n.insertNode(t('' + o + "")[0]);
var l = t("#noteTab").removeAttr("id");
n = r.create(l[0], 1), n.select(), i.remove(l[0])
}, this.undo = function(t) {
t.data("NoteHistory").undo(t)
}, this.redo = function(t) {
t.data("NoteHistory").redo(t)
};
for (var a = this.recordUndo = function(t) {
t.data("NoteHistory").recordUndo(t)
}, o = ["bold", "italic", "underline", "strikethrough", "justifyLeft", "justifyCenter", "justifyRight", "justifyFull", "insertOrderedList", "insertUnorderedList", "indent", "outdent", "formatBlock", "removeFormat", "backColor", "foreColor", "insertHorizontalRule"], d = 0, c = o.length; c > d; d++) this[o[d]] = function(t) {
return function(e, n) {
a(e), document.execCommand(t, !1, n)
}
}(o[d]);
this.insertImage = function(e, n) {
l.loadImage(n).done(function(o) {
a(e);
var i = t("
").attr("src", n);
i.css("width", Math.min(e.width(), o.width)), r.create().insertNode(i[0])
}).fail(function() {
var t = e.data("callbacks");
t.onImageUploadError && t.onImageUploadError()
})
}, this.insertVideo = function(e, n) {
var a, o = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,
i = n.match(o),
l = /\/\/instagram.com\/p\/(.[a-zA-Z0-9]*)/,
s = n.match(l),
d = /\/\/vine.co\/v\/(.[a-zA-Z0-9]*)/,
c = n.match(d),
u = /\/\/(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/,
f = n.match(u),
h = /.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/,
b = n.match(h);
if (i && 11 === i[2].length) {
var v = i[2];
a = t("