3 lines
37 KiB
JavaScript
3 lines
37 KiB
JavaScript
|
!function(a){"use strict";var b=navigator.appVersion.indexOf("Mac")>-1,c=navigator.userAgent.indexOf("MSIE")>-1,d=function(){var a=function(a){return function(b){return a===b}},b=function(a,b){return a===b},c=function(){return!1},d=function(a){return function(){return!a.apply(a,arguments)}},e=function(a){return a};return{eq:a,eq2:b,fail:c,not:d,self:e}}(),e=function(){var a=function(a){return a[0]},b=function(a){return a[a.length-1]},c=function(a){return a.slice(0,a.length-1)},e=function(a){return a.slice(1)},f=function(a,b){return b=b||d.self,a.reduce(function(a,c){return a+b(c)},0)},g=function(a){for(var b=[],c=-1,d=a.length;++c<d;)b[c]=a[c];return b},h=function(c,d){if(0===c.length)return[];var f=e(c);return f.reduce(function(a,c){var e=b(a);return d(b(e),c)?e[e.length]=c:a[a.length]=[c],a},[[a(c)]])},i=function(a){for(var b=[],c=0,d=a.length;d>c;c++)a[c]&&b.push(a[c]);return b};return{head:a,last:b,initial:c,tail:e,sum:f,from:g,compact:i,clusterBy:h}}(),f=function(){var b=function(a){return function(b){return b&&b.nodeName===a}},c=function(a){return a&&/^P|^LI|^H[1-7]/.test(a.nodeName)},f=function(a){return a&&/^UL|^OL/.test(a.nodeName)},g=function(b){return b&&a(b).hasClass("note-editable")},h=function(b){return b&&a(b).hasClass("note-control-sizing")},i=function(a,b){for(;a;){if(b(a))return a;a=a.parentNode}return null},j=function(a,b){b=b||d.fail;var c=[];return i(a,function(a){return c.push(a),b(a)}),c},k=function(b,c){for(var d=j(b),e=c;e;e=e.parentNode)if(a.inArray(e,d)>-1)return e;return null},l=function(a,b){var c=[],d=!1,e=!1,f=function(g){if(g){if(g===a&&(d=!0),d&&!e&&c.push(g),g===b)return e=!0,void 0;for(var h=0,i=g.childNodes.length;i>h;h++)f(g.childNodes[h])}};return f(k(a,b)),c},m=function(a,b){b=b||d.fail;for(var c=[];a&&(c.push(a),!b(a));)a=a.previousSibling;return c},n=function(a,b){b=b||d.fail;for(var c=[];a&&(c.push(a),!b(a));)a=a.nextSibling;return c},o=function(a,b){var c=b.nextSibling,d=b.parentNode;return c?d.insertBefore(a,c):d.appendChild(a),a},p=function(b,c){return a.each(c,function(a,c){b.appendChild(c)}),b},q=b("#text"),r=function(a){return q(a)?a.nodeValue.length:a.childNodes.length},s=function(a){for(var b=0;a=a.previousSibling;)b+=1;return b},t=function(b,c){var f=e.initial(j(c,d.eq(b)));return a.map(f,s).reverse()},u=function(a,b){for(var c=a,d=0,e=b.length;e>d;d++)c=c.childNodes[b[d]];return c},v=function(a,b){if(0===b)return a;if(b>=r(a))return a.nextSibling;if(q(a))return a.splitText(b);var c=a.childNodes[b];return a=o(a.cloneNode(!1),a),p(a,n(c))},w=function(a,b,c){var e=j(b,d.eq(a));return 1===e.length?v(b,c):e.reduce(function(a,d){var e=d.cloneNode(!1);return o(e,d),a===b&&(a=v(a,c)),p(e,n(a)),e})},x=function(a,b){if(a&&a.parentNode){if(a.removeNode)return a.removeNode(b);var c=a.parentNode;if(!b){for(var d=[],e=0,f=a.childNodes.length;f>e;e++)d.push(a.childNodes[e]);for(var e=0,f=d.length;f>e;e++)c.insertBefore(d[e],a)}c.removeChild(a)}};return{isText:q,isPara:c,isList:f,isEditable:g,isControlSizing:h,isAnchor:b("A"),isDiv:b("DIV"),isSpan:b("SPAN"),isB:b("B"),isU:b("U"),isS:b("S"),isI:b("I"),isImg:b("IMG"),isTextarea:b("TEXTAREA"),ancestor:i,listAncestor:j,listNext:n,listPrev:m,commonAncestor:k,listBetween:l,insertAfter:o,position:s,makeOffsetPath:t,fromOffsetPath:u,split:w,remove:x}}(),g=function(){var b=!!document.createRange,c=function(a,b){var c,d,g=a.parentElement(),h=document.body.createTextRange(),i=e.from(g.childNodes);for(c=0;c<i.length;c++)if(!f.isText(i[c])){if(h.moveToElementText(i[c]),h.compareEndPoints("StartToStart",a)>=0)break;d=i[c]}if(0!=c&&f.isText(i[c-1])){var j=document.body.createTextRange(),k=null;j.moveToElementText(d||g),j.collapse(!d),k=d?d.nextSibling:g.firstChild;var l=a.duplicate();l.setEndPoint("StartToStart",j);for(var m=l.text.replace(/[\r\n]/g,"").length;m>k.nodeValue.length&&k.nextSibling;)m-=k.nodeValue.length,k=k.nextSibling;k.nodeValue,b&&k.nextSibling&&f.isText(k.nextSibling)&&m==k.nodeValue.length&&(m-=k.nodeValue.length,k=k.nextSibling),g=k,c=m}return{cont:g,offset:c}},g=function(a){var b=function(a,c){var g,h;if(f.isText(a)){var i=f.li
|
||
|
f&&e.attr("title",function(a,b){return b+" ("+f+")"})}).tooltip({container:"body",placement:d||"top"})},o=[["#000000","#424242","#636363","#9C9C94","#CEC6CE","#EFEFEF","#EFF7F7","#FFFFFF"],["#FF0000","#FF9C00","#FFFF00","#00FF00","#00FFFF","#0000FF","#9C00FF","#FF00FF"],["#F7C6CE","#FFE7CE","#FFEFC6","#D6EFD6","#CEDEE7","#CEE7F7","#D6D6E7","#E7D6DE"],["#E79C9C","#FFC69C","#FFE79C","#B5D6A5","#A5C6CE","#9CC6EF","#B5A5D6","#D6A5BD"],["#E76363","#F7AD6B","#FFD663","#94BD7B","#73A5AD","#6BADDE","#8C7BC6","#C67BA5"],["#CE0000","#E79439","#EFC631","#6BA54A","#4A7B8C","#3984C6","#634AA5","#A54A7B"],["#9C0000","#B56308","#BD9400","#397B21","#104A5A","#085294","#311873","#731842"],["#630000","#7B3900","#846300","#295218","#083139","#003163","#21104A","#4A1031"]],p=function(b){b.find(".note-color-palette").each(function(){for(var b=a(this),c=b.attr("data-target-event"),d="",e=0,f=o.length;f>e;e++){for(var g=o[e],h="<div>",i=0,j=g.length;j>i;i++){var k=g[i],l=['<button type="button" class="note-color-btn" style="background-color:',k,';" data-event="',c,'" data-value="',k,'" title="',k,'" data-toggle="button" tabindex="-1"></button>'].join("");h+=l}h+="</div>",d+=h}b.html(d)})};this.createLayout=function(b,g,h,j){if(!b.next().hasClass("note-editor")){var k=a('<div class="note-editor"></div>');g>0&&a('<div class="note-statusbar"><div class="note-resizebar"><div class="note-icon-bar"></div><div class="note-icon-bar"></div><div class="note-icon-bar"></div></div></div>').prependTo(k);var l=a('<div class="note-editable" contentEditable="true"></div>').prependTo(k);g&&l.height(g),h&&l.data("tabsize",h);var o=b.html(),q=function(b){return a("<div/>").html(b).text()};f.isTextarea(b[0])&&(o=q(o)),l.html(o),l.data("NoteHistory",new i);for(var r="",s=0,t=j.length;t>s;s++){var u=j[s];r+='<div class="note-'+u[0]+' btn-group">';for(var v=0,w=u[1].length;w>v;v++)r+=c[u[1][v]];r+="</div>"}r='<div class="note-toolbar btn-toolbar">'+r+"</div>";var x=a(r).prependTo(k);p(x),n(x,"bottom");var y=a(d).prependTo(k);n(y),a(e).prependTo(k),a(m).prependTo(k),k.insertAfter(b),b.hide()}};var q=this.layoutInfoFromHolder=function(a){var b=a.next();if(b.hasClass("note-editor"))return{editor:b,toolbar:b.find(".note-toolbar"),editable:b.find(".note-editable"),statusbar:b.find(".note-statusbar"),popover:b.find(".note-popover"),handle:b.find(".note-handle"),dialog:b.find(".note-dialog")}};this.removeLayout=function(a){var b=q(a);b&&(a.html(b.editable.html()),b.editor.remove(),a.show())}},q=new p,r=new o;a.fn.extend({summernote:function(b){if(b=a.extend({toolbar:[["style",["style"]],["font",["bold","italic","underline","clear"]],["fontsize",["fontsize"]],["color",["color"]],["para",["ul","ol","paragraph"]],["height",["height"]],["table",["table"]],["insert",["link","picture"]],["fullscreen",["fullscreen"]],["help",["help"]]]},b),this.each(function(c,d){var e=a(d);q.createLayout(e,b.height,b.tabsize,b.toolbar);var f=q.layoutInfoFromHolder(e);r.attach(f,b)}),this.first()&&b.focus){var c=q.layoutInfoFromHolder(this.first());c.editable.focus()}this.length>0&&b.oninit&&b.oninit()},code:function(b){if(void 0===b){var c=this.first();if(0==c.length)return;var d=q.layoutInfoFromHolder(c),e=!(!d||!d.editable);return e?d.editable.html():c.html()}this.each(function(c,d){var e=q.layoutInfoFromHolder(a(d));e&&e.editable&&e.editable.html(b)})},destroy:function(){this.each(function(b,c){var d=a(c),e=q.layoutInfoFromHolder(d);e&&e.editable&&(r.dettach(e),q.removeLayout(d))})},summernoteInner:function(){return{dom:f,list:e,func:d,range:g}}})}(window.jQuery),"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){"use strict";var c,d,e=this.length>>>0,f=!1;for(1<arguments.length&&(d=b,f=!0),c=0;e>c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d});
|