wysihtml5-0.3.0.min.js 112 KB
/**
 * @license wysihtml5 v0.3.0
 * https://github.com/xing/wysihtml5
 *
 * Author: Christopher Blum (https://github.com/tiff)
 *
 * Copyright (C) 2012 XING AG
 * Licensed under the MIT license (MIT)
 *
 */
var wysihtml5={version:"0.3.0",commands:{},dom:{},quirks:{},toolbar:{},lang:{},selection:{},views:{},INVISIBLE_SPACE:"",EMPTY_FUNCTION:function(){},ELEMENT_NODE:1,TEXT_NODE:3,BACKSPACE_KEY:8,ENTER_KEY:13,ESCAPE_KEY:27,SPACE_KEY:32,DELETE_KEY:46};/**
 * @license Rangy, a cross-browser JavaScript range and selection library
 * http://code.google.com/p/rangy/
 *
 * Copyright 2011, Tim Down
 * Licensed under the MIT license.
 * Version: 1.2.2
 * Build date: 13 November 2011
 */
window.rangy=function(){function e(e,t){var n=typeof e[t];return n==d||!(n!=u||!e[t])||"unknown"==n}function t(e,t){return!(typeof e[t]!=u||!e[t])}function n(e,t){return typeof e[t]!=f}function o(e){return function(t,n){for(var o=n.length;o--;)if(!e(t,n[o]))return!1;return!0}}function r(e){return e&&v(e,p)&&C(e,g)}function i(e){window.alert("Rangy not supported in your browser. Reason: "+e),w.initialized=!0,w.supported=!1}function s(e){var t="Rangy warning: "+e;w.config.alertOnWarn?window.alert(t):typeof window.console!=f&&typeof window.console.log!=f&&window.console.log(t)}function a(){if(!w.initialized){var n,o=!1,s=!1;e(document,"createRange")&&(n=document.createRange(),v(n,m)&&C(n,h)&&(o=!0),n.detach());var a=t(document,"body")?document.body:document.getElementsByTagName("body")[0];a&&e(a,"createTextRange")&&(n=a.createTextRange(),r(n)&&(s=!0)),o||s||i("Neither Range nor TextRange are implemented"),w.initialized=!0,w.features={implementsDomRange:o,implementsTextRange:s};for(var c=E.concat(N),l=0,u=c.length;u>l;++l)try{c[l](w)}catch(d){t(window,"console")&&e(window.console,"log")&&window.console.log("Init listener threw an exception. Continuing.",d)}}}function c(e){e=e||window,a();for(var t=0,n=b.length;n>t;++t)b[t](e)}function l(e){this.name=e,this.initialized=!1,this.supported=!1}var u="object",d="function",f="undefined",h=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer","START_TO_START","START_TO_END","END_TO_START","END_TO_END"],m=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],g=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],p=["collapse","compareEndPoints","duplicate","getBookmark","moveToBookmark","moveToElementText","parentElement","pasteHTML","select","setEndPoint","getBoundingClientRect"],v=o(e),y=o(t),C=o(n),w={version:"1.2.2",initialized:!1,supported:!0,util:{isHostMethod:e,isHostObject:t,isHostProperty:n,areHostMethods:v,areHostObjects:y,areHostProperties:C,isTextRange:r},features:{},modules:{},config:{alertOnWarn:!1,preferTextRange:!1}};w.fail=i,w.warn=s,{}.hasOwnProperty?w.util.extend=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}:i("hasOwnProperty not supported");var N=[],E=[];w.init=a,w.addInitListener=function(e){w.initialized?e(w):N.push(e)};var b=[];w.addCreateMissingNativeApiListener=function(e){b.push(e)},w.createMissingNativeApi=c,l.prototype.fail=function(e){throw this.initialized=!0,this.supported=!1,new Error("Module '"+this.name+"' failed to load: "+e)},l.prototype.warn=function(e){w.warn("Module "+this.name+": "+e)},l.prototype.createError=function(e){return new Error("Error in Rangy "+this.name+" module: "+e)},w.createModule=function(e,t){var n=new l(e);w.modules[e]=n,E.push(function(e){t(e,n),n.initialized=!0,n.supported=!0})},w.requireModules=function(e){for(var t,n,o=0,r=e.length;r>o;++o){if(n=e[o],t=w.modules[n],!(t&&t instanceof l))throw new Error("Module '"+n+"' not found");if(!t.supported)throw new Error("Module '"+n+"' not supported")}};var S=!1,T=function(){S||(S=!0,w.initialized||a())};return typeof window==f?(i("No window found"),void 0):typeof document==f?(i("No document found"),void 0):(e(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",T,!1),e(window,"addEventListener")?window.addEventListener("load",T,!1):e(window,"attachEvent")?window.attachEvent("onload",T):i("Window does not have required addEventListener or attachEvent method"),w)}(),rangy.createModule("DomUtil",function(e,t){function n(e){var t;return typeof e.namespaceURI==T||null===(t=e.namespaceURI)||"http://www.w3.org/1999/xhtml"==t}function o(e){var t=e.parentNode;return 1==t.nodeType?t:null}function r(e){for(var t=0;e=e.previousSibling;)t++;return t}function i(e){var t;return l(e)?e.length:(t=e.childNodes)?t.length:0}function s(e,t){var n,o=[];for(n=e;n;n=n.parentNode)o.push(n);for(n=t;n;n=n.parentNode)if(A(o,n))return n;return null}function a(e,t,n){for(var o=n?t:t.parentNode;o;){if(o===e)return!0;o=o.parentNode}return!1}function c(e,t,n){for(var o,r=n?e:e.parentNode;r;){if(o=r.parentNode,o===t)return r;r=o}return null}function l(e){var t=e.nodeType;return 3==t||4==t||8==t}function u(e,t){var n=t.nextSibling,o=t.parentNode;return n?o.insertBefore(e,n):o.appendChild(e),e}function d(e,t){var n=e.cloneNode(!1);return n.deleteData(0,t),e.deleteData(t,e.length-t),u(n,e),n}function f(e){if(9==e.nodeType)return e;if(typeof e.ownerDocument!=T)return e.ownerDocument;if(typeof e.document!=T)return e.document;if(e.parentNode)return f(e.parentNode);throw new Error("getDocument: no document found for node")}function h(e){var t=f(e);if(typeof t.defaultView!=T)return t.defaultView;if(typeof t.parentWindow!=T)return t.parentWindow;throw new Error("Cannot get a window object for node")}function m(e){if(typeof e.contentDocument!=T)return e.contentDocument;if(typeof e.contentWindow!=T)return e.contentWindow.document;throw new Error("getIframeWindow: No Document object found for iframe element")}function g(e){if(typeof e.contentWindow!=T)return e.contentWindow;if(typeof e.contentDocument!=T)return e.contentDocument.defaultView;throw new Error("getIframeWindow: No Window object found for iframe element")}function p(e){return x.isHostObject(e,"body")?e.body:e.getElementsByTagName("body")[0]}function v(e){for(var t;t=e.parentNode;)e=t;return e}function y(e,t,n,o){var i,a,l,u,d;if(e==n)return t===o?0:o>t?-1:1;if(i=c(n,e,!0))return t<=r(i)?-1:1;if(i=c(e,n,!0))return r(i)<o?-1:1;if(a=s(e,n),l=e===a?a:c(e,a,!0),u=n===a?a:c(n,a,!0),l===u)throw new Error("comparePoints got to case 4 and childA and childB are the same!");for(d=a.firstChild;d;){if(d===l)return-1;if(d===u)return 1;d=d.nextSibling}throw new Error("Should not be here!")}function C(e){for(var t,n=f(e).createDocumentFragment();t=e.firstChild;)n.appendChild(t);return n}function w(e){if(!e)return"[No node]";if(l(e))return'"'+e.data+'"';if(1==e.nodeType){var t=e.id?' id="'+e.id+'"':"";return"<"+e.nodeName+t+">["+e.childNodes.length+"]"}return e.nodeName}function N(e){this.root=e,this._next=e}function E(e){return new N(e)}function b(e,t){this.node=e,this.offset=t}function S(e){this.code=this[e],this.codeName=e,this.message="DOMException: "+this.codeName}var T="undefined",x=e.util;x.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||t.fail("document missing a Node creation method"),x.isHostMethod(document,"getElementsByTagName")||t.fail("document missing getElementsByTagName method");var R=document.createElement("div");x.areHostMethods(R,["insertBefore","appendChild","cloneNode"]||!x.areHostObjects(R,["previousSibling","nextSibling","childNodes","parentNode"]))||t.fail("Incomplete Element implementation"),x.isHostProperty(R,"innerHTML")||t.fail("Element is missing innerHTML property");var _=document.createTextNode("test");x.areHostMethods(_,["splitText","deleteData","insertData","appendData","cloneNode"]||!x.areHostObjects(R,["previousSibling","nextSibling","childNodes","parentNode"])||!x.areHostProperties(_,["data"]))||t.fail("Incomplete Text Node implementation");var A=function(e,t){for(var n=e.length;n--;)if(e[n]===t)return!0;return!1};N.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var e,t,n=this._current=this._next;if(this._current)if(e=n.firstChild)this._next=e;else{for(t=null;n!==this.root&&!(t=n.nextSibling);)n=n.parentNode;this._next=t}return this._current},detach:function(){this._current=this._next=this.root=null}},b.prototype={equals:function(e){return this.node===e.node&this.offset==e.offset},inspect:function(){return"[DomPosition("+w(this.node)+":"+this.offset+")]"}},S.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11},S.prototype.toString=function(){return this.message},e.dom={arrayContains:A,isHtmlNamespace:n,parentElement:o,getNodeIndex:r,getNodeLength:i,getCommonAncestor:s,isAncestorOf:a,getClosestAncestorIn:c,isCharacterDataNode:l,insertAfter:u,splitDataNode:d,getDocument:f,getWindow:h,getIframeWindow:g,getIframeDocument:m,getBody:p,getRootContainer:v,comparePoints:y,inspectNode:w,fragmentFromNodeChildren:C,createIterator:E,DomPosition:b},e.DOMException=S}),rangy.createModule("DomRange",function(e){function t(e,t){return 3!=e.nodeType&&(k.isAncestorOf(e,t.startContainer,!0)||k.isAncestorOf(e,t.endContainer,!0))}function n(e){return k.getDocument(e.startContainer)}function o(e,t,n){var o=e._listeners[t];if(o)for(var r=0,i=o.length;i>r;++r)o[r].call(e,{target:e,args:n})}function r(e){return new H(e.parentNode,k.getNodeIndex(e))}function i(e){return new H(e.parentNode,k.getNodeIndex(e)+1)}function s(e,t,n){var o=11==e.nodeType?e.firstChild:e;return k.isCharacterDataNode(t)?n==t.length?k.insertAfter(e,t):t.parentNode.insertBefore(e,0==n?t:k.splitDataNode(t,n)):n>=t.childNodes.length?t.appendChild(e):t.insertBefore(e,t.childNodes[n]),o}function a(e){for(var t,o,r,i=n(e.range).createDocumentFragment();o=e.next();){if(t=e.isPartiallySelectedSubtree(),o=o.cloneNode(!t),t&&(r=e.getSubtreeIterator(),o.appendChild(a(r)),r.detach(!0)),10==o.nodeType)throw new B("HIERARCHY_REQUEST_ERR");i.appendChild(o)}return i}function c(e,t,n){var o,r;n=n||{stop:!1};for(var i,s;i=e.next();)if(e.isPartiallySelectedSubtree()){if(t(i)===!1)return n.stop=!0,void 0;if(s=e.getSubtreeIterator(),c(s,t,n),s.detach(!0),n.stop)return}else for(o=k.createIterator(i);r=o.next();)if(t(r)===!1)return n.stop=!0,void 0}function l(e){for(var t;e.next();)e.isPartiallySelectedSubtree()?(t=e.getSubtreeIterator(),l(t),t.detach(!0)):e.remove()}function u(e){for(var t,o,r=n(e.range).createDocumentFragment();t=e.next();){if(e.isPartiallySelectedSubtree()?(t=t.cloneNode(!1),o=e.getSubtreeIterator(),t.appendChild(u(o)),o.detach(!0)):e.remove(),10==t.nodeType)throw new B("HIERARCHY_REQUEST_ERR");r.appendChild(t)}return r}function d(e,t,n){var o,r=!(!t||!t.length),i=!!n;r&&(o=new RegExp("^("+t.join("|")+")$"));var s=[];return c(new h(e,!1),function(e){r&&!o.test(e.nodeType)||i&&!n(e)||s.push(e)}),s}function f(e){var t="undefined"==typeof e.getName?"Range":e.getName();return"["+t+"("+k.inspectNode(e.startContainer)+":"+e.startOffset+", "+k.inspectNode(e.endContainer)+":"+e.endOffset+")]"}function h(e,t){if(this.range=e,this.clonePartiallySelectedTextNodes=t,!e.collapsed){this.sc=e.startContainer,this.so=e.startOffset,this.ec=e.endContainer,this.eo=e.endOffset;var n=e.commonAncestorContainer;this.sc===this.ec&&k.isCharacterDataNode(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==n||k.isCharacterDataNode(this.sc)?k.getClosestAncestorIn(this.sc,n,!0):this.sc.childNodes[this.so],this._last=this.ec!==n||k.isCharacterDataNode(this.ec)?k.getClosestAncestorIn(this.ec,n,!0):this.ec.childNodes[this.eo-1])}}function m(e){this.code=this[e],this.codeName=e,this.message="RangeException: "+this.codeName}function g(e,t,n){this.nodes=d(e,t,n),this._next=this.nodes[0],this._position=0}function p(e){return function(t,n){for(var o,r=n?t:t.parentNode;r;){if(o=r.nodeType,k.arrayContains(e,o))return r;r=r.parentNode}return null}}function v(e,t){if(Y(e,t))throw new m("INVALID_NODE_TYPE_ERR")}function y(e){if(!e.startContainer)throw new B("INVALID_STATE_ERR")}function C(e,t){if(!k.arrayContains(t,e.nodeType))throw new m("INVALID_NODE_TYPE_ERR")}function w(e,t){if(0>t||t>(k.isCharacterDataNode(e)?e.length:e.childNodes.length))throw new B("INDEX_SIZE_ERR")}function N(e,t){if(F(e,!0)!==F(t,!0))throw new B("WRONG_DOCUMENT_ERR")}function E(e){if(K(e,!0))throw new B("NO_MODIFICATION_ALLOWED_ERR")}function b(e,t){if(!e)throw new B(t)}function S(e){return!k.arrayContains(W,e.nodeType)&&!F(e,!0)}function T(e,t){return t<=(k.isCharacterDataNode(e)?e.length:e.childNodes.length)}function x(e){if(y(e),S(e.startContainer)||S(e.endContainer)||!T(e.startContainer,e.startOffset)||!T(e.endContainer,e.endOffset))throw new Error("Range error: Range is no longer valid after DOM mutation ("+e.inspect()+")")}function R(){}function _(e){e.START_TO_START=J,e.START_TO_END=et,e.END_TO_END=tt,e.END_TO_START=nt,e.NODE_BEFORE=ot,e.NODE_AFTER=rt,e.NODE_BEFORE_AND_AFTER=it,e.NODE_INSIDE=st}function A(e){_(e),_(e.prototype)}function D(e,t){return function(){x(this);var n,o,r=this.startContainer,s=this.startOffset,a=this.commonAncestorContainer,l=new h(this,!0);r!==a&&(n=k.getClosestAncestorIn(r,a,!0),o=i(n),r=o.node,s=o.offset),c(l,E),l.reset();var u=e(l);return l.detach(),t(this,r,s,r,s),u}}function O(n,o,s){function a(e,t){return function(n){y(this),C(n,V),C(j(n),W);var o=(e?r:i)(n);(t?c:d)(this,o.node,o.offset)}}function c(e,t,n){var r=e.endContainer,i=e.endOffset;(t!==e.startContainer||n!==e.startOffset)&&((j(t)!=j(r)||1==k.comparePoints(t,n,r,i))&&(r=t,i=n),o(e,t,n,r,i))}function d(e,t,n){var r=e.startContainer,i=e.startOffset;(t!==e.endContainer||n!==e.endOffset)&&((j(t)!=j(r)||-1==k.comparePoints(t,n,r,i))&&(r=t,i=n),o(e,r,i,t,n))}function f(e,t,n){(t!==e.startContainer||n!==e.startOffset||t!==e.endContainer||n!==e.endOffset)&&o(e,t,n,t,n)}n.prototype=new R,e.util.extend(n.prototype,{setStart:function(e,t){y(this),v(e,!0),w(e,t),c(this,e,t)},setEnd:function(e,t){y(this),v(e,!0),w(e,t),d(this,e,t)},setStartBefore:a(!0,!0),setStartAfter:a(!1,!0),setEndBefore:a(!0,!1),setEndAfter:a(!1,!1),collapse:function(e){x(this),e?o(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):o(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(e){y(this),v(e,!0),o(this,e,0,e,k.getNodeLength(e))},selectNode:function(e){y(this),v(e,!1),C(e,V);var t=r(e),n=i(e);o(this,t.node,t.offset,n.node,n.offset)},extractContents:D(u,o),deleteContents:D(l,o),canSurroundContents:function(){x(this),E(this.startContainer),E(this.endContainer);var e=new h(this,!0),n=e._first&&t(e._first,this)||e._last&&t(e._last,this);return e.detach(),!n},detach:function(){s(this)},splitBoundaries:function(){x(this);var e=this.startContainer,t=this.startOffset,n=this.endContainer,r=this.endOffset,i=e===n;k.isCharacterDataNode(n)&&r>0&&r<n.length&&k.splitDataNode(n,r),k.isCharacterDataNode(e)&&t>0&&t<e.length&&(e=k.splitDataNode(e,t),i?(r-=t,n=e):n==e.parentNode&&r>=k.getNodeIndex(e)&&r++,t=0),o(this,e,t,n,r)},normalizeBoundaries:function(){x(this);var e=this.startContainer,t=this.startOffset,n=this.endContainer,r=this.endOffset,i=function(e){var t=e.nextSibling;t&&t.nodeType==e.nodeType&&(n=e,r=e.length,e.appendData(t.data),t.parentNode.removeChild(t))},s=function(o){var i=o.previousSibling;if(i&&i.nodeType==o.nodeType){e=o;var s=o.length;if(t=i.length,o.insertData(0,i.data),i.parentNode.removeChild(i),e==n)r+=t,n=e;else if(n==o.parentNode){var a=k.getNodeIndex(o);r==a?(n=o,r=s):r>a&&r--}}},a=!0;if(k.isCharacterDataNode(n))n.length==r&&i(n);else{if(r>0){var c=n.childNodes[r-1];c&&k.isCharacterDataNode(c)&&i(c)}a=!this.collapsed}if(a){if(k.isCharacterDataNode(e))0==t&&s(e);else if(t<e.childNodes.length){var l=e.childNodes[t];l&&k.isCharacterDataNode(l)&&s(l)}}else e=n,t=r;o(this,e,t,n,r)},collapseToPoint:function(e,t){y(this),v(e,!0),w(e,t),f(this,e,t)}}),A(n)}function L(e){e.collapsed=e.startContainer===e.endContainer&&e.startOffset===e.endOffset,e.commonAncestorContainer=e.collapsed?e.startContainer:k.getCommonAncestor(e.startContainer,e.endContainer)}function I(e,t,n,r,i){var s=e.startContainer!==t||e.startOffset!==n,a=e.endContainer!==r||e.endOffset!==i;e.startContainer=t,e.startOffset=n,e.endContainer=r,e.endOffset=i,L(e),o(e,"boundarychange",{startMoved:s,endMoved:a})}function P(e){y(e),e.startContainer=e.startOffset=e.endContainer=e.endOffset=null,e.collapsed=e.commonAncestorContainer=null,o(e,"detach",null),e._listeners=null}function M(e){this.startContainer=e,this.startOffset=0,this.endContainer=e,this.endOffset=0,this._listeners={boundarychange:[],detach:[]},L(this)}e.requireModules(["DomUtil"]);var k=e.dom,H=k.DomPosition,B=e.DOMException;h.prototype={_current:null,_next:null,_first:null,_last:null,isSingleCharacterDataNode:!1,reset:function(){this._current=null,this._next=this._first},hasNext:function(){return!!this._next},next:function(){var e=this._current=this._next;return e&&(this._next=e!==this._last?e.nextSibling:null,k.isCharacterDataNode(e)&&this.clonePartiallySelectedTextNodes&&(e===this.ec&&(e=e.cloneNode(!0)).deleteData(this.eo,e.length-this.eo),this._current===this.sc&&(e=e.cloneNode(!0)).deleteData(0,this.so))),e},remove:function(){var e,t,n=this._current;!k.isCharacterDataNode(n)||n!==this.sc&&n!==this.ec?n.parentNode&&n.parentNode.removeChild(n):(e=n===this.sc?this.so:0,t=n===this.ec?this.eo:n.length,e!=t&&n.deleteData(e,t-e))},isPartiallySelectedSubtree:function(){var e=this._current;return t(e,this.range)},getSubtreeIterator:function(){var e;if(this.isSingleCharacterDataNode)e=this.range.cloneRange(),e.collapse();else{e=new M(n(this.range));var t=this._current,o=t,r=0,i=t,s=k.getNodeLength(t);k.isAncestorOf(t,this.sc,!0)&&(o=this.sc,r=this.so),k.isAncestorOf(t,this.ec,!0)&&(i=this.ec,s=this.eo),I(e,o,r,i,s)}return new h(e,this.clonePartiallySelectedTextNodes)},detach:function(e){e&&this.range.detach(),this.range=this._current=this._next=this._first=this._last=this.sc=this.so=this.ec=this.eo=null}},m.prototype={BAD_BOUNDARYPOINTS_ERR:1,INVALID_NODE_TYPE_ERR:2},m.prototype.toString=function(){return this.message},g.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){return this._current=this._next,this._next=this.nodes[++this._position],this._current},detach:function(){this._current=this._next=this.nodes=null}};var V=[1,3,4,5,7,8,10],W=[2,9,11],z=[5,6,10,12],q=[1,3,4,5,7,8,10,11],U=[1,3,4,5,7,8],j=k.getRootContainer,F=p([9,11]),K=p(z),Y=p([6,10,12]),G=document.createElement("style"),X=!1;try{G.innerHTML="<b>x</b>",X=3==G.firstChild.nodeType}catch(Q){}e.features.htmlParsingConforms=X;var $=X?function(e){var t=this.startContainer,n=k.getDocument(t);if(!t)throw new B("INVALID_STATE_ERR");var o=null;return 1==t.nodeType?o=t:k.isCharacterDataNode(t)&&(o=k.parentElement(t)),o=null===o||"HTML"==o.nodeName&&k.isHtmlNamespace(k.getDocument(o).documentElement)&&k.isHtmlNamespace(o)?n.createElement("body"):o.cloneNode(!1),o.innerHTML=e,k.fragmentFromNodeChildren(o)}:function(e){y(this);var t=n(this),o=t.createElement("body");return o.innerHTML=e,k.fragmentFromNodeChildren(o)},Z=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],J=0,et=1,tt=2,nt=3,ot=0,rt=1,it=2,st=3;R.prototype={attachListener:function(e,t){this._listeners[e].push(t)},compareBoundaryPoints:function(e,t){x(this),N(this.startContainer,t.startContainer);var n,o,r,i,s=e==nt||e==J?"start":"end",a=e==et||e==J?"start":"end";return n=this[s+"Container"],o=this[s+"Offset"],r=t[a+"Container"],i=t[a+"Offset"],k.comparePoints(n,o,r,i)},insertNode:function(e){if(x(this),C(e,q),E(this.startContainer),k.isAncestorOf(e,this.startContainer,!0))throw new B("HIERARCHY_REQUEST_ERR");var t=s(e,this.startContainer,this.startOffset);this.setStartBefore(t)},cloneContents:function(){x(this);var e,t;if(this.collapsed)return n(this).createDocumentFragment();if(this.startContainer===this.endContainer&&k.isCharacterDataNode(this.startContainer))return e=this.startContainer.cloneNode(!0),e.data=e.data.slice(this.startOffset,this.endOffset),t=n(this).createDocumentFragment(),t.appendChild(e),t;var o=new h(this,!0);return e=a(o),o.detach(),e},canSurroundContents:function(){x(this),E(this.startContainer),E(this.endContainer);var e=new h(this,!0),n=e._first&&t(e._first,this)||e._last&&t(e._last,this);return e.detach(),!n},surroundContents:function(e){if(C(e,U),!this.canSurroundContents())throw new m("BAD_BOUNDARYPOINTS_ERR");var t=this.extractContents();if(e.hasChildNodes())for(;e.lastChild;)e.removeChild(e.lastChild);s(e,this.startContainer,this.startOffset),e.appendChild(t),this.selectNode(e)},cloneRange:function(){x(this);for(var e,t=new M(n(this)),o=Z.length;o--;)e=Z[o],t[e]=this[e];return t},toString:function(){x(this);var e=this.startContainer;if(e===this.endContainer&&k.isCharacterDataNode(e))return 3==e.nodeType||4==e.nodeType?e.data.slice(this.startOffset,this.endOffset):"";var t=[],n=new h(this,!0);return c(n,function(e){(3==e.nodeType||4==e.nodeType)&&t.push(e.data)}),n.detach(),t.join("")},compareNode:function(e){x(this);var t=e.parentNode,n=k.getNodeIndex(e);if(!t)throw new B("NOT_FOUND_ERR");var o=this.comparePoint(t,n),r=this.comparePoint(t,n+1);return 0>o?r>0?it:ot:r>0?rt:st},comparePoint:function(e,t){return x(this),b(e,"HIERARCHY_REQUEST_ERR"),N(e,this.startContainer),k.comparePoints(e,t,this.startContainer,this.startOffset)<0?-1:k.comparePoints(e,t,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:$,toHtml:function(){x(this);var e=n(this).createElement("div");return e.appendChild(this.cloneContents()),e.innerHTML},intersectsNode:function(e,t){if(x(this),b(e,"NOT_FOUND_ERR"),k.getDocument(e)!==n(this))return!1;var o=e.parentNode,r=k.getNodeIndex(e);b(o,"NOT_FOUND_ERR");var i=k.comparePoints(o,r,this.endContainer,this.endOffset),s=k.comparePoints(o,r+1,this.startContainer,this.startOffset);return t?0>=i&&s>=0:0>i&&s>0},isPointInRange:function(e,t){return x(this),b(e,"HIERARCHY_REQUEST_ERR"),N(e,this.startContainer),k.comparePoints(e,t,this.startContainer,this.startOffset)>=0&&k.comparePoints(e,t,this.endContainer,this.endOffset)<=0},intersectsRange:function(e,t){if(x(this),n(e)!=n(this))throw new B("WRONG_DOCUMENT_ERR");var o=k.comparePoints(this.startContainer,this.startOffset,e.endContainer,e.endOffset),r=k.comparePoints(this.endContainer,this.endOffset,e.startContainer,e.startOffset);return t?0>=o&&r>=0:0>o&&r>0},intersection:function(e){if(this.intersectsRange(e)){var t=k.comparePoints(this.startContainer,this.startOffset,e.startContainer,e.startOffset),n=k.comparePoints(this.endContainer,this.endOffset,e.endContainer,e.endOffset),o=this.cloneRange();return-1==t&&o.setStart(e.startContainer,e.startOffset),1==n&&o.setEnd(e.endContainer,e.endOffset),o}return null},union:function(e){if(this.intersectsRange(e,!0)){var t=this.cloneRange();return-1==k.comparePoints(e.startContainer,e.startOffset,this.startContainer,this.startOffset)&&t.setStart(e.startContainer,e.startOffset),1==k.comparePoints(e.endContainer,e.endOffset,this.endContainer,this.endOffset)&&t.setEnd(e.endContainer,e.endOffset),t}throw new m("Ranges do not intersect")},containsNode:function(e,t){return t?this.intersectsNode(e,!1):this.compareNode(e)==st},containsNodeContents:function(e){return this.comparePoint(e,0)>=0&&this.comparePoint(e,k.getNodeLength(e))<=0},containsRange:function(e){return this.intersection(e).equals(e)},containsNodeText:function(e){var t=this.cloneRange();t.selectNode(e);var n=t.getNodes([3]);if(n.length>0){t.setStart(n[0],0);var o=n.pop();t.setEnd(o,o.length);var r=this.containsRange(t);return t.detach(),r}return this.containsNodeContents(e)},createNodeIterator:function(e,t){return x(this),new g(this,e,t)},getNodes:function(e,t){return x(this),d(this,e,t)},getDocument:function(){return n(this)},collapseBefore:function(e){y(this),this.setEndBefore(e),this.collapse(!1)},collapseAfter:function(e){y(this),this.setStartAfter(e),this.collapse(!0)},getName:function(){return"DomRange"},equals:function(e){return M.rangesEqual(this,e)},inspect:function(){return f(this)}},O(M,I,P),e.rangePrototype=R.prototype,M.rangeProperties=Z,M.RangeIterator=h,M.copyComparisonConstants=A,M.createPrototypeRange=O,M.inspect=f,M.getRangeDocument=n,M.rangesEqual=function(e,t){return e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset},e.DomRange=M,e.RangeException=m}),rangy.createModule("WrappedRange",function(e){function t(e){var t=e.parentElement(),n=e.duplicate();n.collapse(!0);var o=n.parentElement();n=e.duplicate(),n.collapse(!1);var r=n.parentElement(),i=o==r?o:s.getCommonAncestor(o,r);return i==t?i:s.getCommonAncestor(t,i)}function n(e){return 0==e.compareEndPoints("StartToEnd",e)}function o(e,t,n,o){var r=e.duplicate();r.collapse(n);var i=r.parentElement();if(s.isAncestorOf(t,i,!0)||(i=t),!i.canHaveHTML)return new a(i.parentNode,s.getNodeIndex(i));var c,l,u,d,f,h=s.getDocument(i).createElement("span"),m=n?"StartToStart":"StartToEnd";do i.insertBefore(h,h.previousSibling),r.moveToElementText(h);while((c=r.compareEndPoints(m,e))>0&&h.previousSibling);if(f=h.nextSibling,-1==c&&f&&s.isCharacterDataNode(f)){r.setEndPoint(n?"EndToStart":"EndToEnd",e);var g;if(/[\r\n]/.test(f.data)){var p=r.duplicate(),v=p.text.replace(/\r\n/g,"\r").length;for(g=p.moveStart("character",v);-1==(c=p.compareEndPoints("StartToEnd",p));)g++,p.moveStart("character",1)}else g=r.text.length;d=new a(f,g)}else l=(o||!n)&&h.previousSibling,u=(o||n)&&h.nextSibling,d=u&&s.isCharacterDataNode(u)?new a(u,0):l&&s.isCharacterDataNode(l)?new a(l,l.length):new a(i,s.getNodeIndex(h));return h.parentNode.removeChild(h),d}function r(e,t){var n,o,r,i,a=e.offset,c=s.getDocument(e.node),l=c.body.createTextRange(),u=s.isCharacterDataNode(e.node);return u?(n=e.node,o=n.parentNode):(i=e.node.childNodes,n=a<i.length?i[a]:null,o=e.node),r=c.createElement("span"),r.innerHTML="&#feff;",n?o.insertBefore(r,n):o.appendChild(r),l.moveToElementText(r),l.collapse(!t),o.removeChild(r),u&&l[t?"moveStart":"moveEnd"]("character",a),l}e.requireModules(["DomUtil","DomRange"]);var i,s=e.dom,a=s.DomPosition,c=e.DomRange;if(!e.features.implementsDomRange||e.features.implementsTextRange&&e.config.preferTextRange){if(e.features.implementsTextRange){i=function(e){this.textRange=e,this.refresh()},i.prototype=new c(document),i.prototype.refresh=function(){var e,r,i=t(this.textRange);n(this.textRange)?r=e=o(this.textRange,i,!0,!0):(e=o(this.textRange,i,!0,!1),r=o(this.textRange,i,!1,!1)),this.setStart(e.node,e.offset),this.setEnd(r.node,r.offset)},c.copyComparisonConstants(i);var l=function(){return this}();"undefined"==typeof l.Range&&(l.Range=i),e.createNativeRange=function(e){return e=e||document,e.body.createTextRange()}}}else!function(){function t(e){for(var t,n=u.length;n--;)t=u[n],e[t]=e.nativeRange[t]}function n(e,t,n,o,r){var i=e.startContainer!==t||e.startOffset!=n,s=e.endContainer!==o||e.endOffset!=r;(i||s)&&(e.setEnd(o,r),e.setStart(t,n))}function o(e){e.nativeRange.detach(),e.detached=!0;for(var t,n=u.length;n--;)t=u[n],e[t]=null}var r,a,l,u=c.rangeProperties;i=function(e){if(!e)throw new Error("Range must be specified");this.nativeRange=e,t(this)},c.createPrototypeRange(i,n,o),r=i.prototype,r.selectNode=function(e){this.nativeRange.selectNode(e),t(this)},r.deleteContents=function(){this.nativeRange.deleteContents(),t(this)},r.extractContents=function(){var e=this.nativeRange.extractContents();return t(this),e},r.cloneContents=function(){return this.nativeRange.cloneContents()},r.surroundContents=function(e){this.nativeRange.surroundContents(e),t(this)},r.collapse=function(e){this.nativeRange.collapse(e),t(this)},r.cloneRange=function(){return new i(this.nativeRange.cloneRange())},r.refresh=function(){t(this)},r.toString=function(){return this.nativeRange.toString()};var d=document.createTextNode("test");s.getBody(document).appendChild(d);var f=document.createRange();f.setStart(d,0),f.setEnd(d,0);try{f.setStart(d,1),a=!0,r.setStart=function(e,n){this.nativeRange.setStart(e,n),t(this)},r.setEnd=function(e,n){this.nativeRange.setEnd(e,n),t(this)},l=function(e){return function(n){this.nativeRange[e](n),t(this)}}}catch(h){a=!1,r.setStart=function(e,n){try{this.nativeRange.setStart(e,n)}catch(o){this.nativeRange.setEnd(e,n),this.nativeRange.setStart(e,n)}t(this)},r.setEnd=function(e,n){try{this.nativeRange.setEnd(e,n)}catch(o){this.nativeRange.setStart(e,n),this.nativeRange.setEnd(e,n)}t(this)},l=function(e,n){return function(o){try{this.nativeRange[e](o)}catch(r){this.nativeRange[n](o),this.nativeRange[e](o)}t(this)}}}r.setStartBefore=l("setStartBefore","setEndBefore"),r.setStartAfter=l("setStartAfter","setEndAfter"),r.setEndBefore=l("setEndBefore","setStartBefore"),r.setEndAfter=l("setEndAfter","setStartAfter"),f.selectNodeContents(d),r.selectNodeContents=f.startContainer==d&&f.endContainer==d&&0==f.startOffset&&f.endOffset==d.length?function(e){this.nativeRange.selectNodeContents(e),t(this)}:function(e){this.setStart(e,0),this.setEnd(e,c.getEndOffset(e))},f.selectNodeContents(d),f.setEnd(d,3);var m=document.createRange();m.selectNodeContents(d),m.setEnd(d,4),m.setStart(d,2),r.compareBoundaryPoints=-1==f.compareBoundaryPoints(f.START_TO_END,m)&1==f.compareBoundaryPoints(f.END_TO_START,m)?function(e,t){return t=t.nativeRange||t,e==t.START_TO_END?e=t.END_TO_START:e==t.END_TO_START&&(e=t.START_TO_END),this.nativeRange.compareBoundaryPoints(e,t)}:function(e,t){return this.nativeRange.compareBoundaryPoints(e,t.nativeRange||t)},e.util.isHostMethod(f,"createContextualFragment")&&(r.createContextualFragment=function(e){return this.nativeRange.createContextualFragment(e)}),s.getBody(document).removeChild(d),f.detach(),m.detach()}(),e.createNativeRange=function(e){return e=e||document,e.createRange()};e.features.implementsTextRange&&(i.rangeToTextRange=function(e){if(e.collapsed){var t=r(new a(e.startContainer,e.startOffset),!0);return t}var n=r(new a(e.startContainer,e.startOffset),!0),o=r(new a(e.endContainer,e.endOffset),!1),i=s.getDocument(e.startContainer).body.createTextRange();return i.setEndPoint("StartToStart",n),i.setEndPoint("EndToEnd",o),i}),i.prototype.getName=function(){return"WrappedRange"},e.WrappedRange=i,e.createRange=function(t){return t=t||document,new i(e.createNativeRange(t))},e.createRangyRange=function(e){return e=e||document,new c(e)},e.createIframeRange=function(t){return e.createRange(s.getIframeDocument(t))},e.createIframeRangyRange=function(t){return e.createRangyRange(s.getIframeDocument(t))},e.addCreateMissingNativeApiListener(function(t){var n=t.document;"undefined"==typeof n.createRange&&(n.createRange=function(){return e.createRange(this)}),n=t=null})}),rangy.createModule("WrappedSelection",function(e,t){function n(e){return(e||window).getSelection()}function o(e){return(e||window).document.selection}function r(e,t,n){var o=n?"end":"start",r=n?"start":"end";e.anchorNode=t[o+"Container"],e.anchorOffset=t[o+"Offset"],e.focusNode=t[r+"Container"],e.focusOffset=t[r+"Offset"]}function i(e){var t=e.nativeSelection;e.anchorNode=t.anchorNode,e.anchorOffset=t.anchorOffset,e.focusNode=t.focusNode,e.focusOffset=t.focusOffset}function s(e){e.anchorNode=e.focusNode=null,e.anchorOffset=e.focusOffset=0,e.rangeCount=0,e.isCollapsed=!0,e._ranges.length=0}function a(t){var n;return t instanceof S?(n=t._selectionNativeRange,n||(n=e.createNativeRange(E.getDocument(t.startContainer)),n.setEnd(t.endContainer,t.endOffset),n.setStart(t.startContainer,t.startOffset),t._selectionNativeRange=n,t.attachListener("detach",function(){this._selectionNativeRange=null}))):t instanceof T?n=t.nativeRange:e.features.implementsDomRange&&t instanceof E.getWindow(t.startContainer).Range&&(n=t),n}function c(e){if(!e.length||1!=e[0].nodeType)return!1;for(var t=1,n=e.length;n>t;++t)if(!E.isAncestorOf(e[0],e[t]))return!1;return!0}function l(e){var t=e.getNodes();if(!c(t))throw new Error("getSingleElementFromRange: range "+e.inspect()+" did not consist of a single element");return t[0]}function u(e){return!!e&&"undefined"!=typeof e.text}function d(e,t){var n=new T(t);e._ranges=[n],r(e,n,!1),e.rangeCount=1,e.isCollapsed=n.collapsed}function f(t){if(t._ranges.length=0,"None"==t.docSelection.type)s(t);else{var n=t.docSelection.createRange();if(u(n))d(t,n);else{t.rangeCount=n.length;for(var o,i=E.getDocument(n.item(0)),a=0;a<t.rangeCount;++a)o=e.createRange(i),o.selectNode(n.item(a)),t._ranges.push(o);t.isCollapsed=1==t.rangeCount&&t._ranges[0].collapsed,r(t,t._ranges[t.rangeCount-1],!1)}}}function h(e,t){for(var n=e.docSelection.createRange(),o=l(t),r=E.getDocument(n.item(0)),i=E.getBody(r).createControlRange(),s=0,a=n.length;a>s;++s)i.add(n.item(s));try{i.add(o)}catch(c){throw new Error("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}i.select(),f(e)}function m(e,t,n){this.nativeSelection=e,this.docSelection=t,this._ranges=[],this.win=n,this.refresh()}function g(e,t){for(var n,o=E.getDocument(t[0].startContainer),r=E.getBody(o).createControlRange(),i=0;rangeCount>i;++i){n=l(t[i]);try{r.add(n)}catch(s){throw new Error("setRanges(): Element within the one of the specified Ranges could not be added to control selection (does it have layout?)")
}}r.select(),f(e)}function p(e,t){if(e.anchorNode&&E.getDocument(e.anchorNode)!==E.getDocument(t))throw new x("WRONG_DOCUMENT_ERR")}function v(e){var t=[],n=new R(e.anchorNode,e.anchorOffset),o=new R(e.focusNode,e.focusOffset),r="function"==typeof e.getName?e.getName():"Selection";if("undefined"!=typeof e.rangeCount)for(var i=0,s=e.rangeCount;s>i;++i)t[i]=S.inspect(e.getRangeAt(i));return"["+r+"(Ranges: "+t.join(", ")+")(anchor: "+n.inspect()+", focus: "+o.inspect()+"]"}e.requireModules(["DomUtil","DomRange","WrappedRange"]),e.config.checkSelectionRanges=!0;var y,C,w="boolean",N="_rangySelection",E=e.dom,b=e.util,S=e.DomRange,T=e.WrappedRange,x=e.DOMException,R=E.DomPosition,_="Control",A=e.util.isHostMethod(window,"getSelection"),D=e.util.isHostObject(document,"selection"),O=D&&(!A||e.config.preferTextRange);O?(y=o,e.isSelectionValid=function(e){var t=(e||window).document,n=t.selection;return"None"!=n.type||E.getDocument(n.createRange().parentElement())==t}):A?(y=n,e.isSelectionValid=function(){return!0}):t.fail("Neither document.selection or window.getSelection() detected."),e.getNativeSelection=y;var L=y(),I=e.createNativeRange(document),P=E.getBody(document),M=b.areHostObjects(L,["anchorNode","focusNode"]&&b.areHostProperties(L,["anchorOffset","focusOffset"]));e.features.selectionHasAnchorAndFocus=M;var k=b.isHostMethod(L,"extend");e.features.selectionHasExtend=k;var H="number"==typeof L.rangeCount;e.features.selectionHasRangeCount=H;var B=!1,V=!0;b.areHostMethods(L,["addRange","getRangeAt","removeAllRanges"])&&"number"==typeof L.rangeCount&&e.features.implementsDomRange&&!function(){var e=document.createElement("iframe");P.appendChild(e);var t=E.getIframeDocument(e);t.open(),t.write("<html><head></head><body>12</body></html>"),t.close();var n=E.getIframeWindow(e).getSelection(),o=t.documentElement,r=o.lastChild,i=r.firstChild,s=t.createRange();s.setStart(i,1),s.collapse(!0),n.addRange(s),V=1==n.rangeCount,n.removeAllRanges();var a=s.cloneRange();s.setStart(i,0),a.setEnd(i,2),n.addRange(s),n.addRange(a),B=2==n.rangeCount,s.detach(),a.detach(),P.removeChild(e)}(),e.features.selectionSupportsMultipleRanges=B,e.features.collapsedNonEditableSelectionsSupported=V;var W,z=!1;P&&b.isHostMethod(P,"createControlRange")&&(W=P.createControlRange(),b.areHostProperties(W,["item","add"])&&(z=!0)),e.features.implementsControlRange=z,C=M?function(e){return e.anchorNode===e.focusNode&&e.anchorOffset===e.focusOffset}:function(e){return e.rangeCount?e.getRangeAt(e.rangeCount-1).collapsed:!1};var q;b.isHostMethod(L,"getRangeAt")?q=function(e,t){try{return e.getRangeAt(t)}catch(n){return null}}:M&&(q=function(t){var n=E.getDocument(t.anchorNode),o=e.createRange(n);return o.setStart(t.anchorNode,t.anchorOffset),o.setEnd(t.focusNode,t.focusOffset),o.collapsed!==this.isCollapsed&&(o.setStart(t.focusNode,t.focusOffset),o.setEnd(t.anchorNode,t.anchorOffset)),o}),e.getSelection=function(e){e=e||window;var t=e[N],n=y(e),r=D?o(e):null;return t?(t.nativeSelection=n,t.docSelection=r,t.refresh(e)):(t=new m(n,r,e),e[N]=t),t},e.getIframeSelection=function(t){return e.getSelection(E.getIframeWindow(t))};var U=m.prototype;if(!O&&M&&b.areHostMethods(L,["removeAllRanges","addRange"])){U.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),s(this)};var j=function(t,n){var o=S.getRangeDocument(n),r=e.createRange(o);r.collapseToPoint(n.endContainer,n.endOffset),t.nativeSelection.addRange(a(r)),t.nativeSelection.extend(n.startContainer,n.startOffset),t.refresh()};U.addRange=H?function(t,n){if(z&&D&&this.docSelection.type==_)h(this,t);else if(n&&k)j(this,t);else{var o;if(B?o=this.rangeCount:(this.removeAllRanges(),o=0),this.nativeSelection.addRange(a(t)),this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==o+1){if(e.config.checkSelectionRanges){var i=q(this.nativeSelection,this.rangeCount-1);i&&!S.rangesEqual(i,t)&&(t=new T(i))}this._ranges[this.rangeCount-1]=t,r(this,t,Y(this.nativeSelection)),this.isCollapsed=C(this)}else this.refresh()}}:function(e,t){t&&k?j(this,e):(this.nativeSelection.addRange(a(e)),this.refresh())},U.setRanges=function(e){if(z&&e.length>1)g(this,e);else{this.removeAllRanges();for(var t=0,n=e.length;n>t;++t)this.addRange(e[t])}}}else{if(!(b.isHostMethod(L,"empty")&&b.isHostMethod(I,"select")&&z&&O))return t.fail("No means of selecting a Range or TextRange was found"),!1;U.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var e;if(this.anchorNode)e=E.getDocument(this.anchorNode);else if(this.docSelection.type==_){var t=this.docSelection.createRange();t.length&&(e=E.getDocument(t.item(0)).body.createTextRange())}if(e){var n=e.body.createTextRange();n.select(),this.docSelection.empty()}}}catch(o){}s(this)},U.addRange=function(e){this.docSelection.type==_?h(this,e):(T.rangeToTextRange(e).select(),this._ranges[0]=e,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,r(this,e,!1))},U.setRanges=function(e){this.removeAllRanges();var t=e.length;t>1?g(this,e):t&&this.addRange(e[0])}}U.getRangeAt=function(e){if(0>e||e>=this.rangeCount)throw new x("INDEX_SIZE_ERR");return this._ranges[e]};var F;if(O)F=function(t){var n;e.isSelectionValid(t.win)?n=t.docSelection.createRange():(n=E.getBody(t.win.document).createTextRange(),n.collapse(!0)),t.docSelection.type==_?f(t):u(n)?d(t,n):s(t)};else if(b.isHostMethod(L,"getRangeAt")&&"number"==typeof L.rangeCount)F=function(t){if(z&&D&&t.docSelection.type==_)f(t);else if(t._ranges.length=t.rangeCount=t.nativeSelection.rangeCount,t.rangeCount){for(var n=0,o=t.rangeCount;o>n;++n)t._ranges[n]=new e.WrappedRange(t.nativeSelection.getRangeAt(n));r(t,t._ranges[t.rangeCount-1],Y(t.nativeSelection)),t.isCollapsed=C(t)}else s(t)};else{if(!M||typeof L.isCollapsed!=w||typeof I.collapsed!=w||!e.features.implementsDomRange)return t.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;F=function(e){var t,n=e.nativeSelection;n.anchorNode?(t=q(n,0),e._ranges=[t],e.rangeCount=1,i(e),e.isCollapsed=C(e)):s(e)}}U.refresh=function(e){var t=e?this._ranges.slice(0):null;if(F(this),e){var n=t.length;if(n!=this._ranges.length)return!1;for(;n--;)if(!S.rangesEqual(t[n],this._ranges[n]))return!1;return!0}};var K=function(e,t){var n=e.getAllRanges(),o=!1;e.removeAllRanges();for(var r=0,i=n.length;i>r;++r)o||t!==n[r]?e.addRange(n[r]):o=!0;e.rangeCount||s(e)};U.removeRange=z?function(e){if(this.docSelection.type==_){for(var t,n=this.docSelection.createRange(),o=l(e),r=E.getDocument(n.item(0)),i=E.getBody(r).createControlRange(),s=!1,a=0,c=n.length;c>a;++a)t=n.item(a),t!==o||s?i.add(n.item(a)):s=!0;i.select(),f(this)}else K(this,e)}:function(e){K(this,e)};var Y;!O&&M&&e.features.implementsDomRange?(Y=function(e){var t=!1;return e.anchorNode&&(t=1==E.comparePoints(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)),t},U.isBackwards=function(){return Y(this)}):Y=U.isBackwards=function(){return!1},U.toString=function(){for(var e=[],t=0,n=this.rangeCount;n>t;++t)e[t]=""+this._ranges[t];return e.join("")},U.collapse=function(t,n){p(this,t);var o=e.createRange(E.getDocument(t));o.collapseToPoint(t,n),this.removeAllRanges(),this.addRange(o),this.isCollapsed=!0},U.collapseToStart=function(){if(!this.rangeCount)throw new x("INVALID_STATE_ERR");var e=this._ranges[0];this.collapse(e.startContainer,e.startOffset)},U.collapseToEnd=function(){if(!this.rangeCount)throw new x("INVALID_STATE_ERR");var e=this._ranges[this.rangeCount-1];this.collapse(e.endContainer,e.endOffset)},U.selectAllChildren=function(t){p(this,t);var n=e.createRange(E.getDocument(t));n.selectNodeContents(t),this.removeAllRanges(),this.addRange(n)},U.deleteFromDocument=function(){if(z&&D&&this.docSelection.type==_){for(var e,t=this.docSelection.createRange();t.length;)e=t.item(0),t.remove(e),e.parentNode.removeChild(e);this.refresh()}else if(this.rangeCount){var n=this.getAllRanges();this.removeAllRanges();for(var o=0,r=n.length;r>o;++o)n[o].deleteContents();this.addRange(n[r-1])}},U.getAllRanges=function(){return this._ranges.slice(0)},U.setSingleRange=function(e){this.setRanges([e])},U.containsNode=function(e,t){for(var n=0,o=this._ranges.length;o>n;++n)if(this._ranges[n].containsNode(e,t))return!0;return!1},U.toHtml=function(){var e="";if(this.rangeCount){for(var t=S.getRangeDocument(this._ranges[0]).createElement("div"),n=0,o=this._ranges.length;o>n;++n)t.appendChild(this._ranges[n].cloneContents());e=t.innerHTML}return e},U.getName=function(){return"WrappedSelection"},U.inspect=function(){return v(this)},U.detach=function(){this.win[N]=null,this.win=this.anchorNode=this.focusNode=null},m.inspect=v,e.Selection=m,e.selectionPrototype=U,e.addCreateMissingNativeApiListener(function(t){"undefined"==typeof t.getSelection&&(t.getSelection=function(){return e.getSelection(this)}),t=null})});/*
	Base.js, version 1.1a
	Copyright 2006-2010, Dean Edwards
	License: http://www.opensource.org/licenses/mit-license.php
*/
var Base=function(){};Base.extend=function(e,t){var n=Base.prototype.extend;Base._prototyping=!0;var o=new this;n.call(o,e),o.base=function(){},delete Base._prototyping;var r=o.constructor,i=o.constructor=function(){if(!Base._prototyping)if(this._constructing||this.constructor==i)this._constructing=!0,r.apply(this,arguments),delete this._constructing;else if(null!=arguments[0])return(arguments[0].extend||n).call(arguments[0],o)};return i.ancestor=this,i.extend=this.extend,i.forEach=this.forEach,i.implement=this.implement,i.prototype=o,i.toString=this.toString,i.valueOf=function(e){return"object"==e?i:r.valueOf()},n.call(i,t),"function"==typeof i.init&&i.init(),i},Base.prototype={extend:function(e,t){if(arguments.length>1){var n=this[e];if(n&&"function"==typeof t&&(!n.valueOf||n.valueOf()!=t.valueOf())&&/\bbase\b/.test(t)){var o=t.valueOf();t=function(){var e=this.base||Base.prototype.base;this.base=n;var t=o.apply(this,arguments);return this.base=e,t},t.valueOf=function(e){return"object"==e?t:o},t.toString=Base.toString}this[e]=t}else if(e){var r=Base.prototype.extend;Base._prototyping||"function"==typeof this||(r=this.extend||r);for(var i={toSource:null},s=["constructor","toString","valueOf"],a=Base._prototyping?0:1;c=s[a++];)e[c]!=i[c]&&r.call(this,c,e[c]);for(var c in e)i[c]||r.call(this,c,e[c])}return this}},Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,version:"1.1",forEach:function(e,t,n){for(var o in e)void 0===this.prototype[o]&&t.call(n,e[o],o,e)},implement:function(){for(var e=0;e<arguments.length;e++)"function"==typeof arguments[e]?arguments[e](this.prototype):this.prototype.extend(arguments[e]);return this},toString:function(){return String(this.valueOf())}}),wysihtml5.browser=function(){function e(e){return(/ipad|iphone|ipod/.test(e)&&e.match(/ os (\d+).+? like mac os x/)||[,0])[1]}var t=navigator.userAgent,n=document.createElement("div"),o=-1!==t.indexOf("MSIE")&&-1===t.indexOf("Opera"),r=-1!==t.indexOf("Gecko")&&-1===t.indexOf("KHTML"),i=-1!==t.indexOf("AppleWebKit/"),s=-1!==t.indexOf("Chrome/"),a=-1!==t.indexOf("Opera/");return{USER_AGENT:t,supported:function(){var t=this.USER_AGENT.toLowerCase(),o="contentEditable"in n,r=document.execCommand&&document.queryCommandSupported&&document.queryCommandState,i=document.querySelector&&document.querySelectorAll,s=this.isIos()&&e(t)<5||-1!==t.indexOf("opera mobi")||-1!==t.indexOf("hpwos/");return o&&r&&i&&!s},isTouchDevice:function(){return this.supportsEvent("touchmove")},isIos:function(){var e=this.USER_AGENT.toLowerCase();return-1!==e.indexOf("webkit")&&-1!==e.indexOf("mobile")},supportsSandboxedIframes:function(){return o},throwsMixedContentWarningWhenIframeSrcIsEmpty:function(){return!("querySelector"in document)},displaysCaretInEmptyContentEditableCorrectly:function(){return!r},hasCurrentStyleProperty:function(){return"currentStyle"in n},insertsLineBreaksOnReturn:function(){return r},supportsPlaceholderAttributeOn:function(e){return"placeholder"in e},supportsEvent:function(e){return"on"+e in n||function(){return n.setAttribute("on"+e,"return;"),"function"==typeof n["on"+e]}()},supportsEventsInIframeCorrectly:function(){return!a},firesOnDropOnlyWhenOnDragOverIsCancelled:function(){return i||r},supportsDataTransfer:function(){try{return i&&(window.Clipboard||window.DataTransfer).prototype.getData}catch(e){return!1}},supportsHTML5Tags:function(e){var t=e.createElement("div"),n="<article>foo</article>";return t.innerHTML=n,t.innerHTML.toLowerCase()===n},supportsCommand:function(){var e={formatBlock:o,insertUnorderedList:o||a||i,insertOrderedList:o||a||i},t={insertHTML:r};return function(n,o){var r=e[o];if(!r){try{return n.queryCommandSupported(o)}catch(i){}try{return n.queryCommandEnabled(o)}catch(s){return!!t[o]}}return!1}}(),doesAutoLinkingInContentEditable:function(){return o},canDisableAutoLinking:function(){return this.supportsCommand(document,"AutoUrlDetect")},clearsContentEditableCorrectly:function(){return r||a||i},supportsGetAttributeCorrectly:function(){var e=document.createElement("td");return"1"!=e.getAttribute("rowspan")},canSelectImagesInContentEditable:function(){return r||o||a},clearsListsInContentEditableCorrectly:function(){return r||o||i},autoScrollsToCaret:function(){return!i},autoClosesUnclosedTags:function(){var e,t,o=n.cloneNode(!1);return o.innerHTML="<p><div></div>",t=o.innerHTML.toLowerCase(),e="<p></p><div></div>"===t||"<p><div></div></p>"===t,this.autoClosesUnclosedTags=function(){return e},e},supportsNativeGetElementsByClassName:function(){return-1!==String(document.getElementsByClassName).indexOf("[native code]")},supportsSelectionModify:function(){return"getSelection"in window&&"modify"in window.getSelection()},supportsClassList:function(){return"classList"in n},needsSpaceAfterLineBreak:function(){return a},supportsSpeechApiOn:function(e){var n=t.match(/Chrome\/(\d+)/)||[,0];return n[1]>=11&&("onwebkitspeechchange"in e||"speech"in e)},crashesWhenDefineProperty:function(e){return o&&("XMLHttpRequest"===e||"XDomainRequest"===e)},doesAsyncFocus:function(){return o},hasProblemsSettingCaretAfterImg:function(){return o},hasUndoInContextMenu:function(){return r||s||a}}}(),wysihtml5.lang.array=function(e){return{contains:function(t){if(e.indexOf)return-1!==e.indexOf(t);for(var n=0,o=e.length;o>n;n++)if(e[n]===t)return!0;return!1},without:function(t){t=wysihtml5.lang.array(t);for(var n=[],o=0,r=e.length;r>o;o++)t.contains(e[o])||n.push(e[o]);return n},get:function(){for(var t=0,n=e.length,o=[];n>t;t++)o.push(e[t]);return o}}},wysihtml5.lang.Dispatcher=Base.extend({observe:function(e,t){return this.events=this.events||{},this.events[e]=this.events[e]||[],this.events[e].push(t),this},on:function(){return this.observe.apply(this,wysihtml5.lang.array(arguments).get())},fire:function(e,t){this.events=this.events||{};for(var n=this.events[e]||[],o=0;o<n.length;o++)n[o].call(this,t);return this},stopObserving:function(e,t){this.events=this.events||{};var n,o,r=0;if(e){for(n=this.events[e]||[],o=[];r<n.length;r++)n[r]!==t&&t&&o.push(n[r]);this.events[e]=o}else this.events={};return this}}),wysihtml5.lang.object=function(e){return{merge:function(t){for(var n in t)e[n]=t[n];return this},get:function(){return e},clone:function(){var t,n={};for(t in e)n[t]=e[t];return n},isArray:function(){return"[object Array]"===Object.prototype.toString.call(e)}}},function(){var e=/^\s+/,t=/\s+$/;wysihtml5.lang.string=function(n){return n=String(n),{trim:function(){return n.replace(e,"").replace(t,"")},interpolate:function(e){for(var t in e)n=this.replace("#{"+t+"}").by(e[t]);return n},replace:function(e){return{by:function(t){return n.split(e).join(t)}}}}}}(),function(e){function t(e){return i(e)?e:(e===e.ownerDocument.documentElement&&(e=e.ownerDocument.body),s(e))}function n(e){return e.replace(c,function(e,t){var n=(t.match(l)||[])[1]||"",o=d[n];t=t.replace(l,""),t.split(o).length>t.split(n).length&&(t+=n,n="");var r=t,i=t;return t.length>u&&(i=i.substr(0,u)+"..."),"www."===r.substr(0,4)&&(r="http://"+r),'<a href="'+r+'">'+i+"</a>"+n})}function o(e){var t=e._wysihtml5_tempElement;return t||(t=e._wysihtml5_tempElement=e.createElement("div")),t}function r(e){var t=e.parentNode,r=o(t.ownerDocument);for(r.innerHTML="<span></span>"+n(e.data),r.removeChild(r.firstChild);r.firstChild;)t.insertBefore(r.firstChild,e);t.removeChild(e)}function i(e){for(var t;e.parentNode;){if(e=e.parentNode,t=e.nodeName,a.contains(t))return!0;if("body"===t)return!1}return!1}function s(t){if(!a.contains(t.nodeName)){if(t.nodeType===e.TEXT_NODE&&t.data.match(c))return r(t),void 0;for(var n=e.lang.array(t.childNodes).get(),o=n.length,i=0;o>i;i++)s(n[i]);return t}}var a=e.lang.array(["CODE","PRE","A","SCRIPT","HEAD","TITLE","STYLE"]),c=/((https?:\/\/|www\.)[^\s<]{3,})/gi,l=/([^\w\/\-](,?))$/i,u=100,d={")":"(","]":"[","}":"{"};e.dom.autoLink=t,e.dom.autoLink.URL_REG_EXP=c}(wysihtml5),function(e){var t=e.browser.supportsClassList(),n=e.dom;n.addClass=function(e,o){return t?e.classList.add(o):(n.hasClass(e,o)||(e.className+=" "+o),void 0)},n.removeClass=function(e,n){return t?e.classList.remove(n):(e.className=e.className.replace(new RegExp("(^|\\s+)"+n+"(\\s+|$)")," "),void 0)},n.hasClass=function(e,n){if(t)return e.classList.contains(n);var o=e.className;return o.length>0&&(o==n||new RegExp("(^|\\s)"+n+"(\\s|$)").test(o))}}(wysihtml5),wysihtml5.dom.contains=function(){var e=document.documentElement;return e.contains?function(e,t){return t.nodeType!==wysihtml5.ELEMENT_NODE&&(t=t.parentNode),e!==t&&e.contains(t)}:e.compareDocumentPosition?function(e,t){return!!(16&e.compareDocumentPosition(t))}:void 0}(),wysihtml5.dom.convertToList=function(){function e(e,t){var n=e.createElement("li");return t.appendChild(n),n}function t(e,t){return e.createElement(t)}function n(n,o){if("UL"===n.nodeName||"OL"===n.nodeName||"MENU"===n.nodeName)return n;var r,i,s,a,c,l,u,d,f,h=n.ownerDocument,m=t(h,o),g=n.querySelectorAll("br"),p=g.length;for(f=0;p>f;f++)for(a=g[f];(c=a.parentNode)&&c!==n&&c.lastChild===a;){if("block"===wysihtml5.dom.getStyle("display").from(c)){c.removeChild(a);break}wysihtml5.dom.insert(a).after(a.parentNode)}for(r=wysihtml5.lang.array(n.childNodes).get(),i=r.length,f=0;i>f;f++)d=d||e(h,m),s=r[f],l="block"===wysihtml5.dom.getStyle("display").from(s),u="BR"===s.nodeName,l?(d=d.firstChild?e(h,m):d,d.appendChild(s),d=null):u?d=d.firstChild?null:d:d.appendChild(s);return n.parentNode.replaceChild(m,n),m}return n}(),wysihtml5.dom.copyAttributes=function(e){return{from:function(t){return{to:function(n){for(var o,r=0,i=e.length;i>r;r++)o=e[r],"undefined"!=typeof t[o]&&""!==t[o]&&(n[o]=t[o]);return{andTo:arguments.callee}}}}}},function(e){var t=["-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing"],n=function(t){return o(t)?parseInt(e.getStyle("width").from(t),10)<t.offsetWidth:!1},o=function(n){for(var o=0,r=t.length;r>o;o++)if("border-box"===e.getStyle(t[o]).from(n))return t[o]};e.copyStyles=function(o){return{from:function(r){n(r)&&(o=wysihtml5.lang.array(o).without(t));for(var i,s="",a=o.length,c=0;a>c;c++)i=o[c],s+=i+":"+e.getStyle(i).from(r)+";";return{to:function(t){return e.setStyles(s).on(t),{andTo:arguments.callee}}}}}}}(wysihtml5.dom),function(e){e.dom.delegate=function(t,n,o,r){return e.dom.observe(t,o,function(o){for(var i=o.target,s=e.lang.array(t.querySelectorAll(n));i&&i!==t;){if(s.contains(i)){r.call(i,o);break}i=i.parentNode}})}}(wysihtml5),wysihtml5.dom.getAsDom=function(){var e=function(e,t){var n=t.createElement("div");n.style.display="none",t.body.appendChild(n);try{n.innerHTML=e}catch(o){}return t.body.removeChild(n),n},t=function(e){if(!e._wysihtml5_supportsHTML5Tags){for(var t=0,o=n.length;o>t;t++)e.createElement(n[t]);e._wysihtml5_supportsHTML5Tags=!0}},n=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];return function(n,o){o=o||document;var r;return"object"==typeof n&&n.nodeType?(r=o.createElement("div"),r.appendChild(n)):wysihtml5.browser.supportsHTML5Tags(o)?(r=o.createElement("div"),r.innerHTML=n):(t(o),r=e(n,o)),r}}(),wysihtml5.dom.getParentElement=function(){function e(e,t){return t&&t.length?"string"==typeof t?e===t:wysihtml5.lang.array(t).contains(e):!0}function t(e){return e.nodeType===wysihtml5.ELEMENT_NODE}function n(e,t,n){var o=(e.className||"").match(n)||[];return t?o[o.length-1]===t:!!o.length}function o(t,n,o){for(;o--&&t&&"BODY"!==t.nodeName;){if(e(t.nodeName,n))return t;t=t.parentNode}return null}function r(o,r,i,s,a){for(;a--&&o&&"BODY"!==o.nodeName;){if(t(o)&&e(o.nodeName,r)&&n(o,i,s))return o;o=o.parentNode}return null}return function(e,t,n){return n=n||50,t.className||t.classRegExp?r(e,t.nodeName,t.className,t.classRegExp,n):o(e,t.nodeName,n)}}(),wysihtml5.dom.getStyle=function(){function e(e){return e.replace(n,function(e){return e.charAt(1).toUpperCase()})}var t={"float":"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat"},n=/\-[a-z]/g;return function(n){return{from:function(o){if(o.nodeType===wysihtml5.ELEMENT_NODE){var r=o.ownerDocument,i=t[n]||e(n),s=o.style,a=o.currentStyle,c=s[i];if(c)return c;if(a)try{return a[i]}catch(l){}var u,d,f=r.defaultView||r.parentWindow,h=("height"===n||"width"===n)&&"TEXTAREA"===o.nodeName;return f.getComputedStyle?(h&&(u=s.overflow,s.overflow="hidden"),d=f.getComputedStyle(o,null).getPropertyValue(n),h&&(s.overflow=u||""),d):void 0}}}}}(),wysihtml5.dom.hasElementWithTagName=function(){function e(e){return e._wysihtml5_identifier||(e._wysihtml5_identifier=n++)}var t={},n=1;return function(n,o){var r=e(n)+":"+o,i=t[r];return i||(i=t[r]=n.getElementsByTagName(o)),i.length>0}}(),function(e){function t(e){return e._wysihtml5_identifier||(e._wysihtml5_identifier=o++)}var n={},o=1;e.dom.hasElementWithClassName=function(o,r){if(!e.browser.supportsNativeGetElementsByClassName())return!!o.querySelector("."+r);var i=t(o)+":"+r,s=n[i];return s||(s=n[i]=o.getElementsByClassName(r)),s.length>0}}(wysihtml5),wysihtml5.dom.insert=function(e){return{after:function(t){t.parentNode.insertBefore(e,t.nextSibling)},before:function(t){t.parentNode.insertBefore(e,t)},into:function(t){t.appendChild(e)}}},wysihtml5.dom.insertCSS=function(e){return e=e.join("\n"),{into:function(t){var n=t.head||t.getElementsByTagName("head")[0],o=t.createElement("style");o.type="text/css",o.styleSheet?o.styleSheet.cssText=e:o.appendChild(t.createTextNode(e)),n&&n.appendChild(o)}}},wysihtml5.dom.observe=function(e,t,n){t="string"==typeof t?[t]:t;for(var o,r,i=0,s=t.length;s>i;i++)r=t[i],e.addEventListener?e.addEventListener(r,n,!1):(o=function(t){"target"in t||(t.target=t.srcElement),t.preventDefault=t.preventDefault||function(){this.returnValue=!1},t.stopPropagation=t.stopPropagation||function(){this.cancelBubble=!0},n.call(e,t)},e.attachEvent("on"+r,o));return{stop:function(){for(var r,i=0,s=t.length;s>i;i++)r=t[i],e.removeEventListener?e.removeEventListener(r,n,!1):e.detachEvent("on"+r,o)}}},wysihtml5.dom.parse=function(){function e(e,n,o,r){wysihtml5.lang.object(d).merge(u).merge(n).get(),o=o||e.ownerDocument||document;var i,s,a,c=o.createDocumentFragment(),l="string"==typeof e;for(i=l?wysihtml5.dom.getAsDom(e,o):e;i.firstChild;)a=i.firstChild,i.removeChild(a),s=t(a,r),s&&c.appendChild(s);return i.innerHTML="",i.appendChild(c),l?wysihtml5.quirks.getCorrectInnerHTML(i):i}function t(e,n){var o,r=e.nodeType,i=e.childNodes,s=i.length,l=a[r],u=0;if(o=l&&l(e),!o)return null;for(u=0;s>u;u++)newChild=t(i[u],n),newChild&&o.appendChild(newChild);return n&&o.childNodes.length<=1&&o.nodeName.toLowerCase()===c&&!o.attributes.length?o.firstChild:o}function n(e){var t,n,r=d.tags,i=e.nodeName.toLowerCase(),s=e.scopeName;if(e._wysihtml5)return null;if(e._wysihtml5=1,"wysihtml5-temp"===e.className)return null;if(s&&"HTML"!=s&&(i=s+":"+i),"outerHTML"in e&&(wysihtml5.browser.autoClosesUnclosedTags()||"P"!==e.nodeName||"</p>"===e.outerHTML.slice(-4).toLowerCase()||(i="div")),i in r){if(t=r[i],!t||t.remove)return null;t="string"==typeof t?{rename_tag:t}:t}else{if(!e.firstChild)return null;t={rename_tag:c}}return n=e.ownerDocument.createElement(t.rename_tag||i),o(e,n,t),e=null,n}function o(e,t,n){var o,i,s,a,c,u,f,g={},p=n.set_class,v=n.add_class,y=n.set_attributes,C=n.check_attributes,w=d.classes,N=0,E=[],b=[],S=[],T=[];if(y&&(g=wysihtml5.lang.object(y).clone()),C)for(c in C)f=h[C[c]],f&&(u=f(r(e,c)),"string"==typeof u&&(g[c]=u));if(p&&E.push(p),v)for(c in v)f=m[v[c]],f&&(a=f(r(e,c)),"string"==typeof a&&E.push(a));for(w["_wysihtml5-temp-placeholder"]=1,T=e.getAttribute("class"),T&&(E=E.concat(T.split(l))),o=E.length;o>N;N++)s=E[N],w[s]&&b.push(s);for(i=b.length;i--;)s=b[i],wysihtml5.lang.array(S).contains(s)||S.unshift(s);S.length&&(g["class"]=S.join(" "));for(c in g)try{t.setAttribute(c,g[c])}catch(x){}g.src&&("undefined"!=typeof g.width&&t.setAttribute("width",g.width),"undefined"!=typeof g.height&&t.setAttribute("height",g.height))}function r(e,t){t=t.toLowerCase();var n=e.nodeName;if("IMG"==n&&"src"==t&&i(e)===!0)return e.src;if(f&&"outerHTML"in e){var o=e.outerHTML.toLowerCase(),r=-1!=o.indexOf(" "+t+"=");return r?e.getAttribute(t):null}return e.getAttribute(t)}function i(e){try{return e.complete&&!e.mozMatchesSelector(":-moz-broken")}catch(t){if(e.complete&&"complete"===e.readyState)return!0}}function s(e){return e.ownerDocument.createTextNode(e.data)}var a={1:n,3:s},c="span",l=/\s+/,u={tags:{},classes:{}},d={},f=!wysihtml5.browser.supportsGetAttributeCorrectly(),h={href:function(){var e=/^mailto:.+@.+|https?:\/\/|\/\//i;return function(t){return t&&t.match(e)?t.replace(e,function(e){return e.toLowerCase()}):null}}(),url:function(){var e=/^https?:\/\//i;return function(t){return t&&t.match(e)?t.replace(e,function(e){return e.toLowerCase()}):null}}(),alt:function(){var e=/[^ a-z0-9_\-]/gi;return function(t){return t?t.replace(e,""):""}}(),numbers:function(){var e=/\D/g;return function(t){return t=(t||"").replace(e,""),t||null}}()},m={align_img:function(){var e={left:"wysiwyg-float-left",right:"wysiwyg-float-right"};return function(t){return e[String(t).toLowerCase()]}}(),align_text:function(){var e={left:"wysiwyg-text-align-left",right:"wysiwyg-text-align-right",center:"wysiwyg-text-align-center",justify:"wysiwyg-text-align-justify"};return function(t){return e[String(t).toLowerCase()]}}(),clear_br:function(){var e={left:"wysiwyg-clear-left",right:"wysiwyg-clear-right",both:"wysiwyg-clear-both",all:"wysiwyg-clear-both"};return function(t){return e[String(t).toLowerCase()]}}(),size_font:function(){var e={1:"wysiwyg-font-size-xx-small",2:"wysiwyg-font-size-small",3:"wysiwyg-font-size-medium",4:"wysiwyg-font-size-large",5:"wysiwyg-font-size-x-large",6:"wysiwyg-font-size-xx-large",7:"wysiwyg-font-size-xx-large","-":"wysiwyg-font-size-smaller","+":"wysiwyg-font-size-larger"};return function(t){return e[String(t).charAt(0)]}}()};return e}(),wysihtml5.dom.removeEmptyTextNodes=function(e){for(var t,n=wysihtml5.lang.array(e.childNodes).get(),o=n.length,r=0;o>r;r++)t=n[r],t.nodeType===wysihtml5.TEXT_NODE&&""===t.data&&t.parentNode.removeChild(t)},wysihtml5.dom.renameElement=function(e,t){for(var n,o=e.ownerDocument.createElement(t);n=e.firstChild;)o.appendChild(n);return wysihtml5.dom.copyAttributes(["align","className"]).from(e).to(o),e.parentNode.replaceChild(o,e),o},wysihtml5.dom.replaceWithChildNodes=function(e){if(e.parentNode){if(!e.firstChild)return e.parentNode.removeChild(e),void 0;for(var t=e.ownerDocument.createDocumentFragment();e.firstChild;)t.appendChild(e.firstChild);e.parentNode.replaceChild(t,e),e=t=null}},function(e){function t(t){return"block"===e.getStyle("display").from(t)}function n(e){return"BR"===e.nodeName}function o(e){var t=e.ownerDocument.createElement("br");e.appendChild(t)}function r(e){if("MENU"===e.nodeName||"UL"===e.nodeName||"OL"===e.nodeName){var r,i,s,a,c,l=e.ownerDocument,u=l.createDocumentFragment(),d=e.previousElementSibling||e.previousSibling;for(d&&!t(d)&&o(u);c=e.firstChild;){for(i=c.lastChild;r=c.firstChild;)s=r===i,a=s&&!t(r)&&!n(r),u.appendChild(r),a&&o(u);c.parentNode.removeChild(c)}e.parentNode.replaceChild(u,e)}}e.resolveList=r}(wysihtml5.dom),function(e){var t=document,n=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"],o=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"],r=["referrer","write","open","close"];e.dom.Sandbox=Base.extend({constructor:function(t,n){this.callback=t||e.EMPTY_FUNCTION,this.config=e.lang.object({}).merge(n).get(),this.iframe=this._createIframe()},insertInto:function(e){"string"==typeof e&&(e=t.getElementById(e)),e.appendChild(this.iframe)},getIframe:function(){return this.iframe},getWindow:function(){this._readyError()},getDocument:function(){this._readyError()},destroy:function(){var e=this.getIframe();e.parentNode.removeChild(e)},_readyError:function(){throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")},_createIframe:function(){var n=this,o=t.createElement("iframe");return o.className="wysihtml5-sandbox",e.dom.setAttributes({security:"restricted",allowtransparency:"true",frameborder:0,width:0,height:0,marginwidth:0,marginheight:0}).on(o),e.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()&&(o.src="javascript:'<html></html>'"),o.onload=function(){o.onreadystatechange=o.onload=null,n._onLoadIframe(o)},o.onreadystatechange=function(){/loaded|complete/.test(o.readyState)&&(o.onreadystatechange=o.onload=null,n._onLoadIframe(o))},o},_onLoadIframe:function(i){if(e.dom.contains(t.documentElement,i)){var s=this,a=i.contentWindow,c=i.contentWindow.document,l=t.characterSet||t.charset||"utf-8",u=this._getHtml({charset:l,stylesheets:this.config.stylesheets});if(c.open("text/html","replace"),c.write(u),c.close(),this.getWindow=function(){return i.contentWindow},this.getDocument=function(){return i.contentWindow.document},a.onerror=function(e,t,n){throw new Error("wysihtml5.Sandbox: "+e,t,n)},!e.browser.supportsSandboxedIframes()){var d,f;for(d=0,f=n.length;f>d;d++)this._unset(a,n[d]);for(d=0,f=o.length;f>d;d++)this._unset(a,o[d],e.EMPTY_FUNCTION);for(d=0,f=r.length;f>d;d++)this._unset(c,r[d]);this._unset(c,"cookie","",!0)}this.loaded=!0,setTimeout(function(){s.callback(s)},0)}},_getHtml:function(t){var n,o=t.stylesheets,r="",i=0;if(o="string"==typeof o?[o]:o)for(n=o.length;n>i;i++)r+='<link rel="stylesheet" href="'+o[i]+'">';return t.stylesheets=r,e.lang.string('<!DOCTYPE html><html><head><meta charset="#{charset}">#{stylesheets}</head><body></body></html>').interpolate(t)},_unset:function(t,n,o,r){try{t[n]=o}catch(i){}try{t.__defineGetter__(n,function(){return o})}catch(i){}if(r)try{t.__defineSetter__(n,function(){})}catch(i){}if(!e.browser.crashesWhenDefineProperty(n))try{var s={get:function(){return o}};r&&(s.set=function(){}),Object.defineProperty(t,n,s)}catch(i){}}})}(wysihtml5),function(){var e={className:"class"};wysihtml5.dom.setAttributes=function(t){return{on:function(n){for(var o in t)n.setAttribute(e[o]||o,t[o])}}}}(),wysihtml5.dom.setStyles=function(e){return{on:function(t){var n=t.style;if("string"==typeof e)return n.cssText+=";"+e,void 0;for(var o in e)"float"===o?(n.cssFloat=e[o],n.styleFloat=e[o]):n[o]=e[o]}}},function(e){e.simulatePlaceholder=function(t,n,o){var r="placeholder",i=function(){n.hasPlaceholderSet()&&n.clear(),e.removeClass(n.element,r)},s=function(){n.isEmpty()&&(n.setValue(o),e.addClass(n.element,r))};t.observe("set_placeholder",s).observe("unset_placeholder",i).observe("focus:composer",i).observe("paste:composer",i).observe("blur:composer",s),s()}}(wysihtml5.dom),function(e){var t=document.documentElement;"textContent"in t?(e.setTextContent=function(e,t){e.textContent=t},e.getTextContent=function(e){return e.textContent}):"innerText"in t?(e.setTextContent=function(e,t){e.innerText=t},e.getTextContent=function(e){return e.innerText}):(e.setTextContent=function(e,t){e.nodeValue=t},e.getTextContent=function(e){return e.nodeValue})}(wysihtml5.dom),wysihtml5.quirks.cleanPastedHTML=function(){function e(e,n,o){n=n||t,o=o||e.ownerDocument||document;var r,i,s,a,c,l="string"==typeof e,u=0;r=l?wysihtml5.dom.getAsDom(e,o):e;for(c in n)for(s=r.querySelectorAll(c),i=n[c],a=s.length;a>u;u++)i(s[u]);return s=e=n=null,l?r.innerHTML:r}var t={"a u":wysihtml5.dom.replaceWithChildNodes};return e}(),function(e){var t=e.dom;e.quirks.ensureProperClearing=function(){var e=function(){var e=this;setTimeout(function(){var t=e.innerHTML.toLowerCase();("<p>&nbsp;</p>"==t||"<p>&nbsp;</p><p>&nbsp;</p>"==t)&&(e.innerHTML="")},0)};return function(n){t.observe(n.element,["cut","keydown"],e)}}(),e.quirks.ensureProperClearingOfLists=function(){var n=["OL","UL","MENU"],o=function(o,r){if(r.firstChild&&e.lang.array(n).contains(r.firstChild.nodeName)){var i=t.getParentElement(o,{nodeName:n});if(i){var s=i==r.firstChild;if(s){var a=i.childNodes.length<=1;if(a){var c=i.firstChild?""===i.firstChild.innerHTML:!0;c&&i.parentNode.removeChild(i)}}}}};return function(n){t.observe(n.element,"keydown",function(t){if(t.keyCode===e.BACKSPACE_KEY){var r=n.selection.getSelectedNode();o(r,n.element)}})}}()}(wysihtml5),function(e){var t="%7E";e.quirks.getCorrectInnerHTML=function(n){var o=n.innerHTML;if(-1===o.indexOf(t))return o;var r,i,s,a,c=n.querySelectorAll("[href*='~'], [src*='~']");for(a=0,s=c.length;s>a;a++)r=c[a].href||c[a].src,i=e.lang.string(r).replace("~").by(t),o=e.lang.string(o).replace(i).by(r);return o}}(wysihtml5),function(e){var t=e.dom,n=["LI","P","H1","H2","H3","H4","H5","H6"],o=["UL","OL","MENU"];e.quirks.insertLineBreakOnReturn=function(r){function i(n){var o=t.getParentElement(n,{nodeName:["P","DIV"]},2);if(o){var i=document.createTextNode(e.INVISIBLE_SPACE);t.insert(i).before(o),t.replaceWithChildNodes(o),r.selection.selectNode(i)}}function s(s){var a=s.keyCode;if(!(s.shiftKey||a!==e.ENTER_KEY&&a!==e.BACKSPACE_KEY)){var c=(s.target,r.selection.getSelectedNode()),l=t.getParentElement(c,{nodeName:n},4);return l?("LI"!==l.nodeName||a!==e.ENTER_KEY&&a!==e.BACKSPACE_KEY?l.nodeName.match(/H[1-6]/)&&a===e.ENTER_KEY&&setTimeout(function(){i(r.selection.getSelectedNode())},0):setTimeout(function(){var e,n=r.selection.getSelectedNode();n&&(e=t.getParentElement(n,{nodeName:o},2),e||i(n))},0),void 0):(a!==e.ENTER_KEY||e.browser.insertsLineBreaksOnReturn()||(r.commands.exec("insertLineBreak"),s.preventDefault()),void 0)}}t.observe(r.element.ownerDocument,"keydown",s)}}(wysihtml5),function(e){var t="wysihtml5-quirks-redraw";e.quirks.redraw=function(n){e.dom.addClass(n,t),e.dom.removeClass(n,t);try{var o=n.ownerDocument;o.execCommand("italic",!1,null),o.execCommand("italic",!1,null)}catch(r){}}}(wysihtml5),function(e){function t(e){var t=0;if(e.parentNode)do t+=e.offsetTop||0,e=e.offsetParent;while(e);return t}var n=e.dom;e.Selection=Base.extend({constructor:function(e){window.rangy.init(),this.editor=e,this.composer=e.composer,this.doc=this.composer.doc},getBookmark:function(){var e=this.getRange();return e&&e.cloneRange()},setBookmark:function(e){e&&this.setSelection(e)},setBefore:function(e){var t=rangy.createRange(this.doc);return t.setStartBefore(e),t.setEndBefore(e),this.setSelection(t)},setAfter:function(e){var t=rangy.createRange(this.doc);return t.setStartAfter(e),t.setEndAfter(e),this.setSelection(t)},selectNode:function(t){var o=rangy.createRange(this.doc),r=t.nodeType===e.ELEMENT_NODE,i="canHaveHTML"in t?t.canHaveHTML:"IMG"!==t.nodeName,s=r?t.innerHTML:t.data,a=""===s||s===e.INVISIBLE_SPACE,c=n.getStyle("display").from(t),l="block"===c||"list-item"===c;if(a&&r&&i)try{t.innerHTML=e.INVISIBLE_SPACE}catch(u){}i?o.selectNodeContents(t):o.selectNode(t),i&&a&&r?o.collapse(l):i&&a&&(o.setStartAfter(t),o.setEndAfter(t)),this.setSelection(o)},getSelectedNode:function(e){var t,n;return e&&this.doc.selection&&"Control"===this.doc.selection.type&&(n=this.doc.selection.createRange(),n&&n.length)?n.item(0):(t=this.getSelection(this.doc),t.focusNode===t.anchorNode?t.focusNode:(n=this.getRange(this.doc),n?n.commonAncestorContainer:this.doc.body))},executeAndRestore:function(t,n){var o,r=this.doc.body,i=n&&r.scrollTop,s=n&&r.scrollLeft,a="_wysihtml5-temp-placeholder",c='<span class="'+a+'">'+e.INVISIBLE_SPACE+"</span>",l=this.getRange(this.doc);if(!l)return t(r,r),void 0;var u=l.createContextualFragment(c);l.insertNode(u);try{t(l.startContainer,l.endContainer)}catch(d){setTimeout(function(){throw d},0)}caretPlaceholder=this.doc.querySelector("."+a),caretPlaceholder?(o=rangy.createRange(this.doc),o.selectNode(caretPlaceholder),o.deleteContents(),this.setSelection(o)):r.focus(),n&&(r.scrollTop=i,r.scrollLeft=s);try{caretPlaceholder.parentNode.removeChild(caretPlaceholder)}catch(f){}},executeAndRestoreSimple:function(e){var t,n,o,r,i,s=this.getRange(),a=this.doc.body;if(!s)return e(a,a),void 0;r=s.getNodes([3]),n=r[0]||s.startContainer,o=r[r.length-1]||s.endContainer,i={collapsed:s.collapsed,startContainer:n,startOffset:n===s.startContainer?s.startOffset:0,endContainer:o,endOffset:o===s.endContainer?s.endOffset:o.length};try{e(s.startContainer,s.endContainer)}catch(c){setTimeout(function(){throw c},0)}t=rangy.createRange(this.doc);try{t.setStart(i.startContainer,i.startOffset)}catch(l){}try{t.setEnd(i.endContainer,i.endOffset)}catch(u){}try{this.setSelection(t)}catch(d){}},insertHTML:function(e){var t=rangy.createRange(this.doc),n=t.createContextualFragment(e),o=n.lastChild;this.insertNode(n),o&&this.setAfter(o)},insertNode:function(e){var t=this.getRange();t&&t.insertNode(e)},surround:function(e){var t=this.getRange();if(t)try{t.surroundContents(e),this.selectNode(e)}catch(n){e.appendChild(t.extractContents()),t.insertNode(e)}},scrollIntoView:function(){var n,o=this.doc,r=o.documentElement.scrollHeight>o.documentElement.offsetHeight,i=o._wysihtml5ScrollIntoViewElement=o._wysihtml5ScrollIntoViewElement||function(){var t=o.createElement("span");return t.innerHTML=e.INVISIBLE_SPACE,t}();r&&(this.insertNode(i),n=t(i),i.parentNode.removeChild(i),n>o.body.scrollTop&&(o.body.scrollTop=n))},selectLine:function(){e.browser.supportsSelectionModify()?this._selectLine_W3C():this.doc.selection&&this._selectLine_MSIE()},_selectLine_W3C:function(){var e=this.doc.defaultView,t=e.getSelection();t.modify("extend","left","lineboundary"),t.modify("extend","right","lineboundary")},_selectLine_MSIE:function(){var e,t,n,o,r,i=this.doc.selection.createRange(),s=i.boundingTop,a=(i.boundingHeight,this.doc.body.scrollWidth);if(i.moveToPoint){for(0===s&&(n=this.doc.createElement("span"),this.insertNode(n),s=n.offsetTop,n.parentNode.removeChild(n)),s+=1,o=-10;a>o;o+=2)try{i.moveToPoint(o,s);break}catch(c){}for(e=s,t=this.doc.selection.createRange(),r=a;r>=0;r--)try{t.moveToPoint(r,e);break}catch(l){}i.setEndPoint("EndToEnd",t),i.select()}},getText:function(){var e=this.getSelection();return e?e.toString():""},getNodes:function(e,t){var n=this.getRange();return n?n.getNodes([e],t):[]},getRange:function(){var e=this.getSelection();return e&&e.rangeCount&&e.getRangeAt(0)},getSelection:function(){return rangy.getSelection(this.doc.defaultView||this.doc.parentWindow)},setSelection:function(e){var t=this.doc.defaultView||this.doc.parentWindow,n=rangy.getSelection(t);return n.setSingleRange(e)}})}(wysihtml5),function(e,t){function n(e,t,n){if(!e.className)return!1;var o=e.className.match(n)||[];return o[o.length-1]===t}function o(e,t,n){e.className?(r(e,n),e.className+=" "+t):e.className=t}function r(e,t){e.className&&(e.className=e.className.replace(t,""))}function i(e,t){return e.className.replace(h," ")==t.className.replace(h," ")}function s(e){for(var t=e.parentNode;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}function a(e,t){if(e.attributes.length!=t.attributes.length)return!1;for(var n,o,r,i=0,s=e.attributes.length;s>i;++i)if(n=e.attributes[i],r=n.name,"class"!=r){if(o=t.attributes.getNamedItem(r),n.specified!=o.specified)return!1;if(n.specified&&n.nodeValue!==o.nodeValue)return!1}return!0}function c(e,n){return t.dom.isCharacterDataNode(e)?0==n?!!e.previousSibling:n==e.length?!!e.nextSibling:!0:n>0&&n<e.childNodes.length}function l(e,n,o){var r;if(t.dom.isCharacterDataNode(n)&&(0==o?(o=t.dom.getNodeIndex(n),n=n.parentNode):o==n.length?(o=t.dom.getNodeIndex(n)+1,n=n.parentNode):r=t.dom.splitDataNode(n,o)),!r){r=n.cloneNode(!1),r.id&&r.removeAttribute("id");for(var i;i=n.childNodes[o];)r.appendChild(i);t.dom.insertAfter(r,n)}return n==e?r:l(e,r.parentNode,t.dom.getNodeIndex(r))}function u(t){this.isElementMerge=t.nodeType==e.ELEMENT_NODE,this.firstTextNode=this.isElementMerge?t.lastChild:t,this.textNodes=[this.firstTextNode]}function d(e,t,n,o){this.tagNames=e||[f],this.cssClass=t||"",this.similarClassRegExp=n,this.normalize=o,this.applyToAnyTagName=!1}var f="span",h=/\s+/g;u.prototype={doMerge:function(){for(var e,t,n,o=[],r=0,i=this.textNodes.length;i>r;++r)e=this.textNodes[r],t=e.parentNode,o[r]=e.data,r&&(t.removeChild(e),t.hasChildNodes()||t.parentNode.removeChild(t));return this.firstTextNode.data=n=o.join(""),n},getLength:function(){for(var e=this.textNodes.length,t=0;e--;)t+=this.textNodes[e].length;return t},toString:function(){for(var e=[],t=0,n=this.textNodes.length;n>t;++t)e[t]="'"+this.textNodes[t].data+"'";return"[Merge("+e.join(",")+")]"}},d.prototype={getAncestorWithClass:function(o){for(var r;o;){if(r=this.cssClass?n(o,this.cssClass,this.similarClassRegExp):!0,o.nodeType==e.ELEMENT_NODE&&t.dom.arrayContains(this.tagNames,o.tagName.toLowerCase())&&r)return o;o=o.parentNode}return!1},postApply:function(e,t){for(var n,o,r,i=e[0],s=e[e.length-1],a=[],c=i,l=s,d=0,f=s.length,h=0,m=e.length;m>h;++h)o=e[h],r=this.getAdjacentMergeableTextNode(o.parentNode,!1),r?(n||(n=new u(r),a.push(n)),n.textNodes.push(o),o===i&&(c=n.firstTextNode,d=c.length),o===s&&(l=n.firstTextNode,f=n.getLength())):n=null;
var g=this.getAdjacentMergeableTextNode(s.parentNode,!0);if(g&&(n||(n=new u(s),a.push(n)),n.textNodes.push(g)),a.length){for(h=0,m=a.length;m>h;++h)a[h].doMerge();t.setStart(c,d),t.setEnd(l,f)}},getAdjacentMergeableTextNode:function(t,n){var o,r=t.nodeType==e.TEXT_NODE,i=r?t.parentNode:t,s=n?"nextSibling":"previousSibling";if(r){if(o=t[s],o&&o.nodeType==e.TEXT_NODE)return o}else if(o=i[s],o&&this.areElementsMergeable(t,o))return o[n?"firstChild":"lastChild"];return null},areElementsMergeable:function(e,n){return t.dom.arrayContains(this.tagNames,(e.tagName||"").toLowerCase())&&t.dom.arrayContains(this.tagNames,(n.tagName||"").toLowerCase())&&i(e,n)&&a(e,n)},createContainer:function(e){var t=e.createElement(this.tagNames[0]);return this.cssClass&&(t.className=this.cssClass),t},applyToTextNode:function(e){var n=e.parentNode;if(1==n.childNodes.length&&t.dom.arrayContains(this.tagNames,n.tagName.toLowerCase()))this.cssClass&&o(n,this.cssClass,this.similarClassRegExp);else{var r=this.createContainer(t.dom.getDocument(e));e.parentNode.insertBefore(r,e),r.appendChild(e)}},isRemovable:function(n){return t.dom.arrayContains(this.tagNames,n.tagName.toLowerCase())&&e.lang.string(n.className).trim()==this.cssClass},undoToTextNode:function(e,t,n){if(!t.containsNode(n)){var o=t.cloneRange();o.selectNode(n),o.isPointInRange(t.endContainer,t.endOffset)&&c(t.endContainer,t.endOffset)&&(l(n,t.endContainer,t.endOffset),t.setEndAfter(n)),o.isPointInRange(t.startContainer,t.startOffset)&&c(t.startContainer,t.startOffset)&&(n=l(n,t.startContainer,t.startOffset))}this.similarClassRegExp&&r(n,this.similarClassRegExp),this.isRemovable(n)&&s(n)},applyToRange:function(t){var n=t.getNodes([e.TEXT_NODE]);if(!n.length)try{var o=this.createContainer(t.endContainer.ownerDocument);return t.surroundContents(o),this.selectNode(t,o),void 0}catch(r){}if(t.splitBoundaries(),n=t.getNodes([e.TEXT_NODE]),n.length){for(var i,s=0,a=n.length;a>s;++s)i=n[s],this.getAncestorWithClass(i)||this.applyToTextNode(i);t.setStart(n[0],0),i=n[n.length-1],t.setEnd(i,i.length),this.normalize&&this.postApply(n,t)}},undoToRange:function(t){var n,o,r=t.getNodes([e.TEXT_NODE]);if(r.length)t.splitBoundaries(),r=t.getNodes([e.TEXT_NODE]);else{var i=t.endContainer.ownerDocument,s=i.createTextNode(e.INVISIBLE_SPACE);t.insertNode(s),t.selectNode(s),r=[s]}for(var a=0,c=r.length;c>a;++a)n=r[a],o=this.getAncestorWithClass(n),o&&this.undoToTextNode(n,t,o);1==c?this.selectNode(t,r[0]):(t.setStart(r[0],0),n=r[r.length-1],t.setEnd(n,n.length),this.normalize&&this.postApply(r,t))},selectNode:function(t,n){var o=n.nodeType===e.ELEMENT_NODE,r="canHaveHTML"in n?n.canHaveHTML:!0,i=o?n.innerHTML:n.data,s=""===i||i===e.INVISIBLE_SPACE;if(s&&o&&r)try{n.innerHTML=e.INVISIBLE_SPACE}catch(a){}t.selectNodeContents(n),s&&o?t.collapse(!1):s&&(t.setStartAfter(n),t.setEndAfter(n))},getTextSelectedByRange:function(e,t){var n=t.cloneRange();n.selectNodeContents(e);var o=n.intersection(t),r=o?o.toString():"";return n.detach(),r},isAppliedToRange:function(t){var n,o=[],r=t.getNodes([e.TEXT_NODE]);if(!r.length)return n=this.getAncestorWithClass(t.startContainer),n?[n]:!1;for(var i,s=0,a=r.length;a>s;++s){if(i=this.getTextSelectedByRange(r[s],t),n=this.getAncestorWithClass(r[s]),""!=i&&!n)return!1;o.push(n)}return o},toggleRange:function(e){this.isAppliedToRange(e)?this.undoToRange(e):this.applyToRange(e)}},e.selection.HTMLApplier=d}(wysihtml5,rangy),wysihtml5.Commands=Base.extend({constructor:function(e){this.editor=e,this.composer=e.composer,this.doc=this.composer.doc},support:function(e){return wysihtml5.browser.supportsCommand(this.doc,e)},exec:function(e,t){var n=wysihtml5.commands[e],o=wysihtml5.lang.array(arguments).get(),r=n&&n.exec,i=null;if(this.editor.fire("beforecommand:composer"),r)o.unshift(this.composer),i=r.apply(n,o);else try{i=this.doc.execCommand(e,!1,t)}catch(s){}return this.editor.fire("aftercommand:composer"),i},state:function(e){var t=wysihtml5.commands[e],n=wysihtml5.lang.array(arguments).get(),o=t&&t.state;if(o)return n.unshift(this.composer),o.apply(t,n);try{return this.doc.queryCommandState(e)}catch(r){return!1}},value:function(e){var t=wysihtml5.commands[e],n=t&&t.value;if(n)return n.call(t,this.composer,e);try{return this.doc.queryCommandValue(e)}catch(o){return null}}}),function(e){var t;e.commands.bold={exec:function(t,n){return e.commands.formatInline.exec(t,n,"b")},state:function(t,n){return e.commands.formatInline.state(t,n,"b")},value:function(){return t}}}(wysihtml5),function(e){function t(e,t){for(var n,o,r,s=t.length,a=0;s>a;a++)n=t[a],o=i.getParentElement(n,{nodeName:"code"}),r=i.getTextContent(n),r.match(i.autoLink.URL_REG_EXP)&&!o?o=i.renameElement(n,"code"):i.replaceWithChildNodes(n)}function n(t,n){var s,a,c,l,u,d,f,h,m,g=t.doc,p="_wysihtml5-temp-"+ +new Date,v=/non-matching-class/g,y=0;for(e.commands.formatInline.exec(t,o,r,p,v),a=g.querySelectorAll(r+"."+p),s=a.length;s>y;y++){c=a[y],c.removeAttribute("class");for(m in n)c.setAttribute(m,n[m])}d=c,1===s&&(f=i.getTextContent(c),l=!!c.querySelector("*"),u=""===f||f===e.INVISIBLE_SPACE,!l&&u&&(i.setTextContent(c,n.text||c.href),h=g.createTextNode(" "),t.selection.setAfter(c),t.selection.insertNode(h),d=h)),t.selection.setAfter(d)}var o,r="A",i=e.dom;e.commands.createLink={exec:function(e,o,r){var i=this.state(e,o);i?e.selection.executeAndRestore(function(){t(e,i)}):(r="object"==typeof r?r:{href:r},n(e,r))},state:function(t,n){return e.commands.formatInline.state(t,n,"A")},value:function(){return o}}}(wysihtml5),function(e){var t,n=/wysiwyg-font-size-[a-z\-]+/g;e.commands.fontSize={exec:function(t,o,r){return e.commands.formatInline.exec(t,o,"span","wysiwyg-font-size-"+r,n)},state:function(t,o,r){return e.commands.formatInline.state(t,o,"span","wysiwyg-font-size-"+r,n)},value:function(){return t}}}(wysihtml5),function(e){var t,n=/wysiwyg-color-[a-z]+/g;e.commands.foreColor={exec:function(t,o,r){return e.commands.formatInline.exec(t,o,"span","wysiwyg-color-"+r,n)},state:function(t,o,r){return e.commands.formatInline.state(t,o,"span","wysiwyg-color-"+r,n)},value:function(){return t}}}(wysihtml5),function(e){function t(e,t,o){e.className?(n(e,o),e.className+=" "+t):e.className=t}function n(e,t){e.className=e.className.replace(t,"")}function o(t){return t.nodeType===e.TEXT_NODE&&!e.lang.string(t.data).trim()}function r(e){for(var t=e.previousSibling;t&&o(t);)t=t.previousSibling;return t}function i(e){for(var t=e.nextSibling;t&&o(t);)t=t.nextSibling;return t}function s(e){var t=e.ownerDocument,n=i(e),o=r(e);n&&!u(n)&&e.parentNode.insertBefore(t.createElement("br"),n),o&&!u(o)&&e.parentNode.insertBefore(t.createElement("br"),e)}function a(e){var t=i(e),n=r(e);t&&l(t)&&t.parentNode.removeChild(t),n&&l(n)&&n.parentNode.removeChild(n)}function c(e){var t=e.lastChild;t&&l(t)&&t.parentNode.removeChild(t)}function l(e){return"BR"===e.nodeName}function u(e){return l(e)?!0:"block"===g.getStyle("display").from(e)?!0:!1}function d(t,n,o,r){if(r)var i=g.observe(t,"DOMNodeInserted",function(t){var n,o=t.target;o.nodeType===e.ELEMENT_NODE&&(n=g.getStyle("display").from(o),"inline"!==n.substr(0,6)&&(o.className+=" "+r))});t.execCommand(n,!1,o),i&&i.stop()}function f(e,t){e.selection.selectLine(),e.selection.surround(t),a(t),c(t),e.selection.selectNode(t)}function h(t){return!!e.lang.string(t.className).trim()}var m,g=e.dom,p="DIV",v=["H1","H2","H3","H4","H5","H6","P","BLOCKQUOTE",p];e.commands.formatBlock={exec:function(o,r,i,a,c){var l,u=o.doc,m=this.state(o,r,i,a,c);return i="string"==typeof i?i.toUpperCase():i,m?(o.selection.executeAndRestoreSimple(function(){c&&n(m,c);var e=h(m);e||m.nodeName!==(i||p)?e&&g.renameElement(m,p):(s(m),g.replaceWithChildNodes(m))}),void 0):(null===i||e.lang.array(v).contains(i))&&(l=o.selection.getSelectedNode(),m=g.getParentElement(l,{nodeName:v}))?(o.selection.executeAndRestoreSimple(function(){i&&(m=g.renameElement(m,i)),a&&t(m,a,c)}),void 0):o.commands.support(r)?(d(u,r,i||p,a),void 0):(m=u.createElement(i||p),a&&(m.className=a),f(o,m),void 0)},state:function(e,t,n,o,r){n="string"==typeof n?n.toUpperCase():n;var i=e.selection.getSelectedNode();return g.getParentElement(i,{nodeName:n,className:o,classRegExp:r})},value:function(){return m}}}(wysihtml5),function(e){function t(e){var t=r[e];return t?[e.toLowerCase(),t.toLowerCase()]:[e.toLowerCase()]}function n(n,o,r){var s=n+":"+o;return i[s]||(i[s]=new e.selection.HTMLApplier(t(n),o,r,!0)),i[s]}var o,r={strong:"b",em:"i",b:"strong",i:"em"},i={};e.commands.formatInline={exec:function(e,t,o,r,i){var s=e.selection.getRange();return s?(n(o,r,i).toggleRange(s),e.selection.setSelection(s),void 0):!1},state:function(t,o,i,s,a){var c,l=t.doc,u=r[i]||i;return e.dom.hasElementWithTagName(l,i)||e.dom.hasElementWithTagName(l,u)?s&&!e.dom.hasElementWithClassName(l,s)?!1:(c=t.selection.getRange(),c?n(i,s,a).isAppliedToRange(c):!1):!1},value:function(){return o}}}(wysihtml5),function(e){var t;e.commands.insertHTML={exec:function(e,t,n){e.commands.support(t)?e.doc.execCommand(t,!1,n):e.selection.insertHTML(n)},state:function(){return!1},value:function(){return t}}}(wysihtml5),function(e){var t="IMG";e.commands.insertImage={exec:function(n,o,r){r="object"==typeof r?r:{src:r};var i,s,a,c=n.doc,l=this.state(n);if(l)return n.selection.setBefore(l),a=l.parentNode,a.removeChild(l),e.dom.removeEmptyTextNodes(a),"A"!==a.nodeName||a.firstChild||(n.selection.setAfter(a),a.parentNode.removeChild(a)),e.quirks.redraw(n.element),void 0;l=c.createElement(t);for(s in r)l[s]=r[s];n.selection.insertNode(l),e.browser.hasProblemsSettingCaretAfterImg()?(i=c.createTextNode(e.INVISIBLE_SPACE),n.selection.insertNode(i),n.selection.setAfter(i)):n.selection.setAfter(l)},state:function(n){var o,r,i,s=n.doc;return e.dom.hasElementWithTagName(s,t)?(o=n.selection.getSelectedNode())?o.nodeName===t?o:o.nodeType!==e.ELEMENT_NODE?!1:(r=n.selection.getText(),(r=e.lang.string(r).trim())?!1:(i=n.selection.getNodes(e.ELEMENT_NODE,function(e){return"IMG"===e.nodeName}),1!==i.length?!1:i[0])):!1:!1},value:function(e){var t=this.state(e);return t&&t.src}}}(wysihtml5),function(e){var t,n="<br>"+(e.browser.needsSpaceAfterLineBreak()?" ":"");e.commands.insertLineBreak={exec:function(t,o){t.commands.support(o)?(t.doc.execCommand(o,!1,null),e.browser.autoScrollsToCaret()||t.selection.scrollIntoView()):t.commands.exec("insertHTML",n)},state:function(){return!1},value:function(){return t}}}(wysihtml5),function(e){var t;e.commands.insertOrderedList={exec:function(t,n){var o,r,i=t.doc,s=t.selection.getSelectedNode(),a=e.dom.getParentElement(s,{nodeName:"OL"}),c=e.dom.getParentElement(s,{nodeName:"UL"}),l="_wysihtml5-temp-"+(new Date).getTime();return t.commands.support(n)?(i.execCommand(n,!1,null),void 0):(a?t.selection.executeAndRestoreSimple(function(){e.dom.resolveList(a)}):c?t.selection.executeAndRestoreSimple(function(){e.dom.renameElement(c,"ol")}):(t.commands.exec("formatBlock","div",l),r=i.querySelector("."+l),o=""===r.innerHTML||r.innerHTML===e.INVISIBLE_SPACE,t.selection.executeAndRestoreSimple(function(){a=e.dom.convertToList(r,"ol")}),o&&t.selection.selectNode(a.querySelector("li"))),void 0)},state:function(t){var n=t.selection.getSelectedNode();return e.dom.getParentElement(n,{nodeName:"OL"})},value:function(){return t}}}(wysihtml5),function(e){var t;e.commands.insertUnorderedList={exec:function(t,n){var o,r,i=t.doc,s=t.selection.getSelectedNode(),a=e.dom.getParentElement(s,{nodeName:"UL"}),c=e.dom.getParentElement(s,{nodeName:"OL"}),l="_wysihtml5-temp-"+(new Date).getTime();return t.commands.support(n)?(i.execCommand(n,!1,null),void 0):(a?t.selection.executeAndRestoreSimple(function(){e.dom.resolveList(a)}):c?t.selection.executeAndRestoreSimple(function(){e.dom.renameElement(c,"ul")}):(t.commands.exec("formatBlock","div",l),r=i.querySelector("."+l),o=""===r.innerHTML||r.innerHTML===e.INVISIBLE_SPACE,t.selection.executeAndRestoreSimple(function(){a=e.dom.convertToList(r,"ul")}),o&&t.selection.selectNode(a.querySelector("li"))),void 0)},state:function(t){var n=t.selection.getSelectedNode();return e.dom.getParentElement(n,{nodeName:"UL"})},value:function(){return t}}}(wysihtml5),function(e){var t;e.commands.italic={exec:function(t,n){return e.commands.formatInline.exec(t,n,"i")},state:function(t,n){return e.commands.formatInline.state(t,n,"i")},value:function(){return t}}}(wysihtml5),function(e){var t,n="wysiwyg-text-align-center",o=/wysiwyg-text-align-[a-z]+/g;e.commands.justifyCenter={exec:function(t){return e.commands.formatBlock.exec(t,"formatBlock",null,n,o)},state:function(t){return e.commands.formatBlock.state(t,"formatBlock",null,n,o)},value:function(){return t}}}(wysihtml5),function(e){var t,n="wysiwyg-text-align-left",o=/wysiwyg-text-align-[a-z]+/g;e.commands.justifyLeft={exec:function(t){return e.commands.formatBlock.exec(t,"formatBlock",null,n,o)},state:function(t){return e.commands.formatBlock.state(t,"formatBlock",null,n,o)},value:function(){return t}}}(wysihtml5),function(e){var t,n="wysiwyg-text-align-right",o=/wysiwyg-text-align-[a-z]+/g;e.commands.justifyRight={exec:function(t){return e.commands.formatBlock.exec(t,"formatBlock",null,n,o)},state:function(t){return e.commands.formatBlock.state(t,"formatBlock",null,n,o)},value:function(){return t}}}(wysihtml5),function(e){var t;e.commands.underline={exec:function(t,n){return e.commands.formatInline.exec(t,n,"u")},state:function(t,n){return e.commands.formatInline.state(t,n,"u")},value:function(){return t}}}(wysihtml5),function(e){function t(e){for(var t;t=e.querySelector("._wysihtml5-temp");)t.parentNode.removeChild(t)}var n=90,o=89,r=8,i=46,s=40,a='<span id="_wysihtml5-undo" class="_wysihtml5-temp">'+e.INVISIBLE_SPACE+"</span>",c='<span id="_wysihtml5-redo" class="_wysihtml5-temp">'+e.INVISIBLE_SPACE+"</span>",l=e.dom;e.UndoManager=e.lang.Dispatcher.extend({constructor:function(e){this.editor=e,this.composer=e.composer,this.element=this.composer.element,this.history=[this.composer.getValue()],this.position=1,this.composer.commands.support("insertHTML")&&this._observe()},_observe:function(){var s,u=this,d=this.composer.sandbox.getDocument();if(l.observe(this.element,"keydown",function(e){if(!e.altKey&&(e.ctrlKey||e.metaKey)){var t=e.keyCode,r=t===n&&!e.shiftKey,i=t===n&&e.shiftKey||t===o;r?(u.undo(),e.preventDefault()):i&&(u.redo(),e.preventDefault())}}),l.observe(this.element,"keydown",function(e){var t=e.keyCode;t!==s&&(s=t,(t===r||t===i)&&u.transact())}),e.browser.hasUndoInContextMenu()){var f,h,m=function(){t(d),clearInterval(f)};l.observe(this.element,"contextmenu",function(){m(),u.composer.selection.executeAndRestoreSimple(function(){u.element.lastChild&&u.composer.selection.setAfter(u.element.lastChild),d.execCommand("insertHTML",!1,a),d.execCommand("insertHTML",!1,c),d.execCommand("undo",!1,null)}),f=setInterval(function(){d.getElementById("_wysihtml5-redo")?(m(),u.redo()):d.getElementById("_wysihtml5-undo")||(m(),u.undo())},400),h||(h=!0,l.observe(document,"mousedown",m),l.observe(d,["mousedown","paste","cut","copy"],m))})}this.editor.observe("newword:composer",function(){u.transact()}).observe("beforecommand:composer",function(){u.transact()})},transact:function(){var e=this.history[this.position-1],t=this.composer.getValue();if(t!=e){var n=this.history.length=this.position;n>s&&(this.history.shift(),this.position--),this.position++,this.history.push(t)}},undo:function(){this.transact(),this.position<=1||(this.set(this.history[--this.position-1]),this.editor.fire("undo:composer"))},redo:function(){this.position>=this.history.length||(this.set(this.history[++this.position-1]),this.editor.fire("redo:composer"))},set:function(e){this.composer.setValue(e),this.editor.focus(!0)}})}(wysihtml5),wysihtml5.views.View=Base.extend({constructor:function(e,t,n){this.parent=e,this.element=t,this.config=n,this._observeViewChange()},_observeViewChange:function(){var e=this;this.parent.observe("beforeload",function(){e.parent.observe("change_view",function(t){t===e.name?(e.parent.currentView=e,e.show(),setTimeout(function(){e.focus()},0)):e.hide()})})},focus:function(){if(this.element.ownerDocument.querySelector(":focus")!==this.element)try{this.element.focus()}catch(e){}},hide:function(){this.element.style.display="none"},show:function(){this.element.style.display=""},disable:function(){this.element.setAttribute("disabled","disabled")},enable:function(){this.element.removeAttribute("disabled")}}),function(e){var t=e.dom,n=e.browser;e.views.Composer=e.views.View.extend({name:"composer",CARET_HACK:"<br>",constructor:function(e,t,n){this.base(e,t,n),this.textarea=this.parent.textarea,this._initSandbox()},clear:function(){this.element.innerHTML=n.displaysCaretInEmptyContentEditableCorrectly()?"":this.CARET_HACK},getValue:function(t){var n=this.isEmpty()?"":e.quirks.getCorrectInnerHTML(this.element);return t&&(n=this.parent.parse(n)),n=e.lang.string(n).replace(e.INVISIBLE_SPACE).by("")},setValue:function(e,t){t&&(e=this.parent.parse(e)),this.element.innerHTML=e},show:function(){this.iframe.style.display=this._displayStyle||"",this.disable(),this.enable()},hide:function(){this._displayStyle=t.getStyle("display").from(this.iframe),"none"===this._displayStyle&&(this._displayStyle=null),this.iframe.style.display="none"},disable:function(){this.element.removeAttribute("contentEditable"),this.base()},enable:function(){this.element.setAttribute("contentEditable","true"),this.base()},focus:function(t){e.browser.doesAsyncFocus()&&this.hasPlaceholderSet()&&this.clear(),this.base();var n=this.element.lastChild;t&&n&&("BR"===n.nodeName?this.selection.setBefore(this.element.lastChild):this.selection.setAfter(this.element.lastChild))},getTextContent:function(){return t.getTextContent(this.element)},hasPlaceholderSet:function(){return this.getTextContent()==this.textarea.element.getAttribute("placeholder")},isEmpty:function(){var e=this.element.innerHTML,t="blockquote, ul, ol, img, embed, object, table, iframe, svg, video, audio, button, input, select, textarea";return""===e||e===this.CARET_HACK||this.hasPlaceholderSet()||""===this.getTextContent()&&!this.element.querySelector(t)},_initSandbox:function(){var e=this;this.sandbox=new t.Sandbox(function(){e._create()},{stylesheets:this.config.stylesheets}),this.iframe=this.sandbox.getIframe();var n=document.createElement("input");n.type="hidden",n.name="_wysihtml5_mode",n.value=1;var o=this.textarea.element;t.insert(this.iframe).after(o),t.insert(n).after(o)},_create:function(){var o=this;this.doc=this.sandbox.getDocument(),this.element=this.doc.body,this.textarea=this.parent.textarea,this.element.innerHTML=this.textarea.getValue(!0),this.enable(),this.selection=new e.Selection(this.parent),this.commands=new e.Commands(this.parent),t.copyAttributes(["className","spellcheck","title","lang","dir","accessKey"]).from(this.textarea.element).to(this.element),t.addClass(this.element,this.config.composerClassName),this.config.style&&this.style(),this.observe();var r=this.config.name;r&&(t.addClass(this.element,r),t.addClass(this.iframe,r));var i="string"==typeof this.config.placeholder?this.config.placeholder:this.textarea.element.getAttribute("placeholder");i&&t.simulatePlaceholder(this.parent,this,i),this.commands.exec("styleWithCSS",!1),this._initAutoLinking(),this._initObjectResizing(),this._initUndoManager(),(this.textarea.element.hasAttribute("autofocus")||document.querySelector(":focus")==this.textarea.element)&&setTimeout(function(){o.focus()},100),e.quirks.insertLineBreakOnReturn(this),n.clearsContentEditableCorrectly()||e.quirks.ensureProperClearing(this),n.clearsListsInContentEditableCorrectly()||e.quirks.ensureProperClearingOfLists(this),this.initSync&&this.config.sync&&this.initSync(),this.textarea.hide(),this.parent.fire("beforeload").fire("load")},_initAutoLinking:function(){var o=this,r=n.canDisableAutoLinking(),i=n.doesAutoLinkingInContentEditable();if(r&&this.commands.exec("autoUrlDetect",!1),this.config.autoLink){(!i||i&&r)&&this.parent.observe("newword:composer",function(){o.selection.executeAndRestore(function(e,n){t.autoLink(n.parentNode)})});var s=this.sandbox.getDocument().getElementsByTagName("a"),a=t.autoLink.URL_REG_EXP,c=function(n){var o=e.lang.string(t.getTextContent(n)).trim();return"www."===o.substr(0,4)&&(o="http://"+o),o};t.observe(this.element,"keydown",function(e){if(s.length){var n,r=o.selection.getSelectedNode(e.target.ownerDocument),i=t.getParentElement(r,{nodeName:"A"},4);i&&(n=c(i),setTimeout(function(){var e=c(i);e!==n&&e.match(a)&&i.setAttribute("href",e)},0))}})}},_initObjectResizing:function(){var o=["width","height"],r=o.length,i=this.element;this.commands.exec("enableObjectResizing",this.config.allowObjectResizing),this.config.allowObjectResizing?n.supportsEvent("resizeend")&&t.observe(i,"resizeend",function(t){for(var n,s=t.target||t.srcElement,a=s.style,c=0;r>c;c++)n=o[c],a[n]&&(s.setAttribute(n,parseInt(a[n],10)),a[n]="");e.quirks.redraw(i)}):n.supportsEvent("resizestart")&&t.observe(i,"resizestart",function(e){e.preventDefault()})},_initUndoManager:function(){new e.UndoManager(this.parent)}})}(wysihtml5),function(e){var t=e.dom,n=document,o=window,r=n.createElement("div"),i=["background-color","color","cursor","font-family","font-size","font-style","font-variant","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-rendering","word-break","word-wrap","word-spacing"],s=["background-color","border-collapse","border-bottom-color","border-bottom-style","border-bottom-width","border-left-color","border-left-style","border-left-width","border-right-color","border-right-style","border-right-width","border-top-color","border-top-style","border-top-width","clear","display","float","margin-bottom","margin-left","margin-right","margin-top","outline-color","outline-offset","outline-width","outline-style","padding-left","padding-right","padding-top","padding-bottom","position","top","left","right","bottom","z-index","vertical-align","text-align","-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing","-webkit-box-shadow","-moz-box-shadow","-ms-box-shadow","box-shadow","-webkit-border-top-right-radius","-moz-border-radius-topright","border-top-right-radius","-webkit-border-bottom-right-radius","-moz-border-radius-bottomright","border-bottom-right-radius","-webkit-border-bottom-left-radius","-moz-border-radius-bottomleft","border-bottom-left-radius","-webkit-border-top-left-radius","-moz-border-radius-topleft","border-top-left-radius","width","height"],a=["width","height","top","left","right","bottom"],c=["html             { height: 100%; }","body             { min-height: 100%; padding: 0; margin: 0; margin-top: -1px; padding-top: 1px; }","._wysihtml5-temp { display: none; }",e.browser.isGecko?"body.placeholder { color: graytext !important; }":"body.placeholder { color: #a9a9a9 !important; }","body[disabled]   { background-color: #eee !important; color: #999 !important; cursor: default !important; }","img:-moz-broken  { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],l=function(e){if(e.setActive)try{e.setActive()}catch(r){}else{var i=e.style,s=n.documentElement.scrollTop||n.body.scrollTop,a=n.documentElement.scrollLeft||n.body.scrollLeft,c={position:i.position,top:i.top,left:i.left,WebkitUserSelect:i.WebkitUserSelect};t.setStyles({position:"absolute",top:"-99999px",left:"-99999px",WebkitUserSelect:"none"}).on(e),e.focus(),t.setStyles(c).on(e),o.scrollTo&&o.scrollTo(a,s)}};e.views.Composer.prototype.style=function(){var u=this,d=n.querySelector(":focus"),f=this.textarea.element,h=f.hasAttribute("placeholder"),m=h&&f.getAttribute("placeholder");this.focusStylesHost=this.focusStylesHost||r.cloneNode(!1),this.blurStylesHost=this.blurStylesHost||r.cloneNode(!1),h&&f.removeAttribute("placeholder"),f===d&&f.blur(),t.copyStyles(s).from(f).to(this.iframe).andTo(this.blurStylesHost),t.copyStyles(i).from(f).to(this.element).andTo(this.blurStylesHost),t.insertCSS(c).into(this.element.ownerDocument),l(f),t.copyStyles(s).from(f).to(this.focusStylesHost),t.copyStyles(i).from(f).to(this.focusStylesHost);var g=e.lang.array(s).without(["display"]);if(d?d.focus():f.blur(),h&&f.setAttribute("placeholder",m),!e.browser.hasCurrentStyleProperty())var p=t.observe(o,"resize",function(){if(!t.contains(document.documentElement,u.iframe))return p.stop(),void 0;var e=t.getStyle("display").from(f),n=t.getStyle("display").from(u.iframe);f.style.display="",u.iframe.style.display="none",t.copyStyles(a).from(f).to(u.iframe).andTo(u.focusStylesHost).andTo(u.blurStylesHost),u.iframe.style.display=n,f.style.display=e});return this.parent.observe("focus:composer",function(){t.copyStyles(g).from(u.focusStylesHost).to(u.iframe),t.copyStyles(i).from(u.focusStylesHost).to(u.element)}),this.parent.observe("blur:composer",function(){t.copyStyles(g).from(u.blurStylesHost).to(u.iframe),t.copyStyles(i).from(u.blurStylesHost).to(u.element)}),this}}(wysihtml5),function(e){var t=e.dom,n=e.browser,o={66:"bold",73:"italic",85:"underline"};e.views.Composer.prototype.observe=function(){var r=this,i=this.getValue(),s=this.sandbox.getIframe(),a=this.element,c=n.supportsEventsInIframeCorrectly()?a:this.sandbox.getWindow(),l=n.supportsEvent("drop")?["drop","paste"]:["dragdrop","paste"];t.observe(s,"DOMNodeRemoved",function(){clearInterval(u),r.parent.fire("destroy:composer")});var u=setInterval(function(){t.contains(document.documentElement,s)||(clearInterval(u),r.parent.fire("destroy:composer"))},250);t.observe(c,"focus",function(){r.parent.fire("focus").fire("focus:composer"),setTimeout(function(){i=r.getValue()},0)}),t.observe(c,"blur",function(){i!==r.getValue()&&r.parent.fire("change").fire("change:composer"),r.parent.fire("blur").fire("blur:composer")}),e.browser.isIos()&&t.observe(a,"blur",function(){var e=a.ownerDocument.createElement("input"),t=document.documentElement.scrollTop||document.body.scrollTop,n=document.documentElement.scrollLeft||document.body.scrollLeft;try{r.selection.insertNode(e)}catch(o){a.appendChild(e)}e.focus(),e.parentNode.removeChild(e),window.scrollTo(n,t)}),t.observe(a,"dragenter",function(){r.parent.fire("unset_placeholder")}),n.firesOnDropOnlyWhenOnDragOverIsCancelled()&&t.observe(a,["dragover","dragenter"],function(e){e.preventDefault()}),t.observe(a,l,function(e){var t,o=e.dataTransfer;console.log("PASTED",e),o&&n.supportsDataTransfer()&&(t=o.getData("text/html")||o.getData("text/plain")),t?(a.focus(),r.commands.exec("insertHTML",t),r.parent.fire("paste").fire("paste:composer"),e.stopPropagation(),e.preventDefault()):setTimeout(function(){r.parent.fire("paste").fire("paste:composer")},0)}),t.observe(a,"keyup",function(t){var n=t.keyCode;(n===e.SPACE_KEY||n===e.ENTER_KEY)&&r.parent.fire("newword:composer")}),this.parent.observe("paste:composer",function(){setTimeout(function(){r.parent.fire("newword:composer")},0)}),n.canSelectImagesInContentEditable()||t.observe(a,"mousedown",function(e){var t=e.target;"IMG"===t.nodeName&&(r.selection.selectNode(t),e.preventDefault())}),t.observe(a,"keydown",function(e){var t=e.keyCode,n=o[t];(e.ctrlKey||e.metaKey)&&!e.altKey&&n&&(r.commands.exec(n),e.preventDefault())}),t.observe(a,"keydown",function(t){var n,o=r.selection.getSelectedNode(!0),i=t.keyCode;!o||"IMG"!==o.nodeName||i!==e.BACKSPACE_KEY&&i!==e.DELETE_KEY||(n=o.parentNode,n.removeChild(o),"A"!==n.nodeName||n.firstChild||n.parentNode.removeChild(n),setTimeout(function(){e.quirks.redraw(a)},0),t.preventDefault())});var d={IMG:"Image: ",A:"Link: "};t.observe(a,"mouseover",function(e){var t,n=e.target,o=n.nodeName;if("A"===o||"IMG"===o){var r=n.hasAttribute("title");r||(t=d[o]+(n.getAttribute("href")||n.getAttribute("src")),n.setAttribute("title",t))}})}}(wysihtml5),function(e){var t=400;e.views.Synchronizer=Base.extend({constructor:function(e,t,n){this.editor=e,this.textarea=t,this.composer=n,this._observe()},fromComposerToTextarea:function(t){this.textarea.setValue(e.lang.string(this.composer.getValue()).trim(),t)},fromTextareaToComposer:function(e){var t=this.textarea.getValue();t?this.composer.setValue(t,e):(this.composer.clear(),this.editor.fire("set_placeholder"))},sync:function(e){"textarea"===this.editor.currentView.name?this.fromTextareaToComposer(e):this.fromComposerToTextarea(e)},_observe:function(){var n,o=this,r=this.textarea.element.form,i=function(){n=setInterval(function(){o.fromComposerToTextarea()},t)},s=function(){clearInterval(n),n=null};i(),r&&(e.dom.observe(r,"submit",function(){o.sync(!0)}),e.dom.observe(r,"reset",function(){setTimeout(function(){o.fromTextareaToComposer()},0)})),this.editor.observe("change_view",function(e){"composer"!==e||n?"textarea"===e&&(o.fromComposerToTextarea(!0),s()):(o.fromTextareaToComposer(!0),i())}),this.editor.observe("destroy:composer",s)}})}(wysihtml5),wysihtml5.views.Textarea=wysihtml5.views.View.extend({name:"textarea",constructor:function(e,t,n){this.base(e,t,n),this._observe()},clear:function(){this.element.value=""},getValue:function(e){var t=this.isEmpty()?"":this.element.value;return e&&(t=this.parent.parse(t)),t},setValue:function(e,t){t&&(e=this.parent.parse(e)),this.element.value=e},hasPlaceholderSet:function(){var e=wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),t=this.element.getAttribute("placeholder")||null,n=this.element.value,o=!n;return e&&o||n===t},isEmpty:function(){return!wysihtml5.lang.string(this.element.value).trim()||this.hasPlaceholderSet()},_observe:function(){var e=this.element,t=this.parent,n={focusin:"focus",focusout:"blur"},o=wysihtml5.browser.supportsEvent("focusin")?["focusin","focusout","change"]:["focus","blur","change"];t.observe("beforeload",function(){wysihtml5.dom.observe(e,o,function(e){var o=n[e.type]||e.type;t.fire(o).fire(o+":textarea")}),wysihtml5.dom.observe(e,["paste","drop"],function(){setTimeout(function(){t.fire("paste").fire("paste:textarea")},0)})})}}),function(e){var t=e.dom,n="wysihtml5-command-dialog-opened",o="input, select, textarea",r="[data-wysihtml5-dialog-field]",i="data-wysihtml5-dialog-field";e.toolbar.Dialog=e.lang.Dispatcher.extend({constructor:function(e,t){this.link=e,this.container=t},_observe:function(){if(!this._observed){var r=this,i=function(e){var t=r._serialize();t==r.elementToChange?r.fire("edit",t):r.fire("save",t),r.hide(),e.preventDefault(),e.stopPropagation()};t.observe(r.link,"click",function(){t.hasClass(r.link,n)&&setTimeout(function(){r.hide()},0)}),t.observe(this.container,"keydown",function(t){var n=t.keyCode;n===e.ENTER_KEY&&i(t),n===e.ESCAPE_KEY&&r.hide()}),t.delegate(this.container,"[data-wysihtml5-dialog-action=save]","click",i),t.delegate(this.container,"[data-wysihtml5-dialog-action=cancel]","click",function(e){r.fire("cancel"),r.hide(),e.preventDefault(),e.stopPropagation()});for(var s=this.container.querySelectorAll(o),a=0,c=s.length,l=function(){clearInterval(r.interval)};c>a;a++)t.observe(s[a],"change",l);this._observed=!0}},_serialize:function(){for(var e=this.elementToChange||{},t=this.container.querySelectorAll(r),n=t.length,o=0;n>o;o++)e[t[o].getAttribute(i)]=t[o].value;return e},_interpolate:function(e){for(var t,n,o,s=document.querySelector(":focus"),a=this.container.querySelectorAll(r),c=a.length,l=0;c>l;l++)t=a[l],t!==s&&(e&&"hidden"===t.type||(n=t.getAttribute(i),o=this.elementToChange?this.elementToChange[n]||"":t.defaultValue,t.value=o))},show:function(e){var r=this,i=this.container.querySelector(o);if(this.elementToChange=e,this._observe(),this._interpolate(),e&&(this.interval=setInterval(function(){r._interpolate(!0)},500)),t.addClass(this.link,n),this.container.style.display="",this.fire("show"),i&&!e)try{i.focus()}catch(s){}},hide:function(){clearInterval(this.interval),this.elementToChange=null,t.removeClass(this.link,n),this.container.style.display="none",this.fire("hide")}})}(wysihtml5),function(e){var t=e.dom,n={position:"relative"},o={left:0,margin:0,opacity:0,overflow:"hidden",padding:0,position:"absolute",top:0,zIndex:1},r={cursor:"inherit",fontSize:"50px",height:"50px",marginTop:"-25px",outline:0,padding:0,position:"absolute",right:"-4px",top:"50%"},i={"x-webkit-speech":"",speech:""};e.toolbar.Speech=function(s,a){var c=document.createElement("input");if(!e.browser.supportsSpeechApiOn(c))return a.style.display="none",void 0;var l=document.createElement("div");e.lang.object(o).merge({width:a.offsetWidth+"px",height:a.offsetHeight+"px"}),t.insert(c).into(l),t.insert(l).into(a),t.setStyles(r).on(c),t.setAttributes(i).on(c),t.setStyles(o).on(l),t.setStyles(n).on(a);var u="onwebkitspeechchange"in c?"webkitspeechchange":"speechchange";t.observe(c,u,function(){s.execCommand("insertText",c.value),c.value=""}),t.observe(c,"click",function(e){t.hasClass(a,"wysihtml5-command-disabled")&&e.preventDefault(),e.stopPropagation()})}}(wysihtml5),function(e){var t="wysihtml5-command-disabled",n="wysihtml5-commands-disabled",o="wysihtml5-command-active",r="wysihtml5-action-active",i=e.dom;
e.toolbar.Toolbar=Base.extend({constructor:function(t,n){this.editor=t,this.container="string"==typeof n?document.getElementById(n):n,this.composer=t.composer,this._getLinks("command"),this._getLinks("action"),this._observe(),this.show();for(var o=this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),r=o.length,i=0;r>i;i++)new e.toolbar.Speech(this,o[i])},_getLinks:function(t){for(var n,o,r,i,s,a=this[t+"Links"]=e.lang.array(this.container.querySelectorAll("[data-wysihtml5-"+t+"]")).get(),c=a.length,l=0,u=this[t+"Mapping"]={};c>l;l++)n=a[l],r=n.getAttribute("data-wysihtml5-"+t),i=n.getAttribute("data-wysihtml5-"+t+"-value"),o=this.container.querySelector("[data-wysihtml5-"+t+"-group='"+r+"']"),s=this._getDialog(n,r),u[r+":"+i]={link:n,group:o,name:r,value:i,dialog:s,state:!1}},_getDialog:function(t,n){var o,r,i=this,s=this.container.querySelector("[data-wysihtml5-dialog='"+n+"']");return s&&(o=new e.toolbar.Dialog(t,s),o.observe("show",function(){r=i.composer.selection.getBookmark(),i.editor.fire("show:dialog",{command:n,dialogContainer:s,commandLink:t})}),o.observe("save",function(e){r&&i.composer.selection.setBookmark(r),i._execCommand(n,e),i.editor.fire("save:dialog",{command:n,dialogContainer:s,commandLink:t})}),o.observe("cancel",function(){i.editor.focus(!1),i.editor.fire("cancel:dialog",{command:n,dialogContainer:s,commandLink:t})})),o},execCommand:function(e,t){if(!this.commandsDisabled){var n=this.commandMapping[e+":"+t];n&&n.dialog&&!n.state?n.dialog.show():this._execCommand(e,t)}},_execCommand:function(e,t){this.editor.focus(!1),this.composer.commands.exec(e,t),this._updateLinkStates()},execAction:function(e){var t=this.editor;switch(e){case"change_view":t.currentView===t.textarea?t.fire("change_view","composer"):t.fire("change_view","textarea")}},_observe:function(){for(var e=this,t=this.editor,o=this.container,r=this.commandLinks.concat(this.actionLinks),s=r.length,a=0;s>a;a++)i.setAttributes({href:"javascript:;",unselectable:"on"}).on(r[a]);i.delegate(o,"[data-wysihtml5-command]","mousedown",function(e){e.preventDefault()}),i.delegate(o,"[data-wysihtml5-command]","click",function(t){var n=this,o=n.getAttribute("data-wysihtml5-command"),r=n.getAttribute("data-wysihtml5-command-value");e.execCommand(o,r),t.preventDefault()}),i.delegate(o,"[data-wysihtml5-action]","click",function(t){var n=this.getAttribute("data-wysihtml5-action");e.execAction(n),t.preventDefault()}),t.observe("focus:composer",function(){e.bookmark=null,clearInterval(e.interval),e.interval=setInterval(function(){e._updateLinkStates()},500)}),t.observe("blur:composer",function(){clearInterval(e.interval)}),t.observe("destroy:composer",function(){clearInterval(e.interval)}),t.observe("change_view",function(t){setTimeout(function(){e.commandsDisabled="composer"!==t,e._updateLinkStates(),e.commandsDisabled?i.addClass(o,n):i.removeClass(o,n)},0)})},_updateLinkStates:function(){var n,s,a,c,l=(this.composer.element,this.commandMapping),u=this.actionMapping;for(n in l)c=l[n],this.commandsDisabled?(s=!1,i.removeClass(c.link,o),c.group&&i.removeClass(c.group,o),c.dialog&&c.dialog.hide()):(s=this.composer.commands.state(c.name,c.value),e.lang.object(s).isArray()&&(s=1===s.length?s[0]:!0),i.removeClass(c.link,t),c.group&&i.removeClass(c.group,t)),c.state!==s&&(c.state=s,s?(i.addClass(c.link,o),c.group&&i.addClass(c.group,o),c.dialog&&("object"==typeof s?c.dialog.show(s):c.dialog.hide())):(i.removeClass(c.link,o),c.group&&i.removeClass(c.group,o),c.dialog&&c.dialog.hide()));for(n in u)a=u[n],"change_view"===a.name&&(a.state=this.editor.currentView===this.editor.textarea,a.state?i.addClass(a.link,r):i.removeClass(a.link,r))},show:function(){this.container.style.display=""},hide:function(){this.container.style.display="none"}})}(wysihtml5),function(e){var t,n={name:t,style:!0,toolbar:t,autoLink:!0,parserRules:{tags:{br:{},span:{},div:{},p:{}},classes:{}},parser:e.dom.parse,composerClassName:"wysihtml5-editor",bodyClassName:"wysihtml5-supported",stylesheets:[],placeholderText:t,allowObjectResizing:!0,supportTouchDevices:!0};e.Editor=e.lang.Dispatcher.extend({constructor:function(t,o){if(this.textareaElement="string"==typeof t?document.getElementById(t):t,this.config=e.lang.object({}).merge(n).merge(o).get(),this.textarea=new e.views.Textarea(this,this.textareaElement,this.config),this.currentView=this.textarea,this._isCompatible=e.browser.supported(),!this._isCompatible||!this.config.supportTouchDevices&&e.browser.isTouchDevice()){var r=this;return setTimeout(function(){r.fire("beforeload").fire("load")},0),void 0}e.dom.addClass(document.body,this.config.bodyClassName),this.composer=new e.views.Composer(this,this.textareaElement,this.config),this.currentView=this.composer,"function"==typeof this.config.parser&&this._initParser(),this.observe("beforeload",function(){this.synchronizer=new e.views.Synchronizer(this,this.textarea,this.composer),this.config.toolbar&&(this.toolbar=new e.toolbar.Toolbar(this,this.config.toolbar))});try{console.log("Heya! This page is using wysihtml5 for rich text editing. Check out https://github.com/xing/wysihtml5")}catch(i){}},isCompatible:function(){return this._isCompatible},clear:function(){return this.currentView.clear(),this},getValue:function(e){return this.currentView.getValue(e)},setValue:function(e,t){return e?(this.currentView.setValue(e,t),this):this.clear()},focus:function(e){return this.currentView.focus(e),this},disable:function(){return this.currentView.disable(),this},enable:function(){return this.currentView.enable(),this},isEmpty:function(){return this.currentView.isEmpty()},hasPlaceholderSet:function(){return this.currentView.hasPlaceholderSet()},parse:function(t){var n=this.config.parser(t,this.config.parserRules,this.composer.sandbox.getDocument(),!0);return"object"==typeof t&&e.quirks.redraw(t),n},_initParser:function(){this.observe("paste:composer",function(){var t=!0,n=this;n.composer.selection.executeAndRestore(function(){e.quirks.cleanPastedHTML(n.composer.element),n.parse(n.composer.element)},t)}),this.observe("paste:textarea",function(){var e,t=this.textarea.getValue();e=this.parse(t),this.textarea.setValue(e)})}})}(wysihtml5);