ansWebpackJsonpFunction(["qtext2"],{"./qtext2/base.js":function(t,e,n){var i,o=n("./shared/rangy.js"),r=n("./shared/browser.js"),s=n("./qtext2/constants.js").CONTENT_TYPES,a=n("./qtext2/util.js").Util,d=n("./qtext2/diff.js"),c=n("./shared/util.js"),h=c.extend,l=n("./qtext2/container.js").Container,u=n("./qtext2/position.js").Position,f=n("./qtext2/span.js").Span,p=n("./qtext2/quirks.js").Quirks,g=n("./shared/email.js").isValidEmail,m=n("./qtext2/undo.js").UndoManager,v=n("./qtext2/keys.js"),C=n("./qtext2/shortcuts.js").SHORTCUTS,S=n("./qtext2/section.js"),x=S.Section,b=n("./qtext2/sections/plain.js").PlainSection,E=n("./qtext2/sections/video.js").VideoSection,_=n("./qtext2/sections/lists.js").UnorderedListSection,T=n("./qtext2/sections/lists.js").OrderedListSection,N=n("./qtext2/sections/code.js").CodeSection,y=n("./qtext2/sections/image.js").ImageSection,w=n("./qtext2/sections/horizontal_rule.js").HorizontalRuleSection,R=n("./qtext2/formatting_state.js").FormattingState,O=n("./qtext2/caret.js").Caret,D=n("./qtext2/sections/embed.js").EmbedSection,I=n("./shared/client.js"),A=n("./qtext2/modifiers.js").canSetModifier,q=n("./settings.js"),j=n("./shared/eventemitter.js"),M=n("./gating.js"),P=l.create("doc",{init:function(t){o.rangy.init(),this.disabledCommands=[],this.fromJSON(t),this._originalJson=this.toJSON(),this._hasBeenModified=!1,this._emitter=new j.EventEmitter,this._allEmitter=new j.EventEmitter,this.enable(),this._attachEventListeners(),this._commands={},this._attachCommands(),this._extensions=[],this._initExtensions();var e=n("./qtext2/mutations.js").MutationFixer;this.mutationFixer=new e(this);var i=this.firstChild().firstChild();this.caret=new O(i.first(),i.first(),this),this.formattingState=new R(this.caret),this.undoManager=new m(this._originalJson),this.linkSelector=null,this.imageUploader=null,this.photoSearch=null,this._contentType=null,this._backspaceCount=0,this._updatePlaceholder(),this.on("meaningfulChange",this._updatePlaceholder.bind(this)),this.linkInputFocus=!0},setLinkInputFocus:function(t){this.linkInputFocus=t},destroy:function(){this._destroyed=!0,a.safeRemoveChild(this.node,this.node.parentElement),this._extensions.forEach(function(t){t.destroy()})},contains:function(t){return this.node.contains(t)},isEmpty:function(){return 1==this.children.length&&this.children[0].isEmpty()},isInModal:function(){return c.hasAncestor(this.node,".Modal")},isOnlyWhiteSpace:function(){return this.children.every(function(t){return t.isOnlyWhiteSpace()})},getLength:function(){var t=0;return this.children.forEach(function(e){t+=e.getLength()}),t},disableCommands:function(t){this.disabledCommands=t||[]},isDisabledCommand:function(t){return t.startsWith("video")?this.disabledCommands.includes("video"):this.disabledCommands.includes(t)},allowsMultipleSections:function(){return!this.isDisabledCommand("return")},disable:function(){this.node.removeAttribute("contenteditable"),this.disabled=!0},enable:function(){this.node.setAttribute("contenteditable","true"),this.disabled=!1},focus:function(){if(this.node){var t=window.scrollX,e=window.scrollY;if(this.node.focus(),window.scrollTo(t,e),this.moveCaret(this.caret.start,this.caret.end,!0),I.isIOSApp()){var n=this;setTimeout(function(){n.caret.scrollIntoViewIfNeeded()},500)}}},clear:function(){this.fromJSON({})},forceDomReflow:function(){for(var t=this.caret.toJSON(),e=this.children.slice(),n=0;n<e.length;n++){var i=e[n];if(!(i instanceof E||i instanceof y||i instanceof D)){var o=x.fromJSON(i.toJSON(!0));this.insertAfter(o,i),this.removeChild(i)}}this._caretFromJSON(t)},toJSON:function(t){var e={sections:[],caret:this.caret&&this.caret.toJSON()};return this.children.forEach(function(n){e.sections.push(n.toJSON(t))}),a.removeNullValues(e)},fromJSON:function(t){for(var e=t.sections||[],n=this.toJSON().sections,i=this.children.slice(),o=d.lineDiff(n,e,c.jsonEqual),r=0;r<o.length;r++){var s=o[r];"insert"==s.type?this.insertBefore(x.fromJSON(e[s.index]),this.children[s.index]):"remove"==s.type&&this.removeChild(i[s.index])}e.length||this.appendChild(new b),this._caretFromJSON(t.caret)},_caretFromJSON:function(t){if(!t)return void(this.caret=new O(this.lastChild().last(),this.lastChild().last(),this));var e=t.start,n=t.end;if(-1==e.sectionIdx||-1==e.spanIdx||-1==n.sectionIdx||-1==n.spanIdx)return void(this.caret=new O(this.lastChild().last(),this.lastChild().last(),this));this.moveCaret(new u(this.children[e.sectionIdx].children[e.spanIdx],e.offset),new u(this.children[n.sectionIdx].children[n.spanIdx],n.offset))},getVideos:function(){var t=[];return this.children.forEach(function(e){if(e instanceof E){var n=e.getVideo();n.jwplayer_id||t.push(n.uuid)}}),t},hasBeenModified:function(){return this._hasBeenModified||(this._hasBeenModified=this.hasChanged(this._originalJson)),this._hasBeenModified},hasChanged:function(t){var e=this.toJSON();return!c.jsonEqual(e.sections,t.sections)},on:function(t,e){this._emitter.on(t,e)},onAll:function(t){this._allEmitter.on("all",t)},trigger:function(t){for(var e=new Array(arguments.length-1),n=1;n<arguments.length;++n)e[n-1]=arguments[n];return this._allEmitter.trigger("all",[t].concat(e)),!this._emitter.trigger(t,e).some(function(t){return!1===t})&&null},_getToolbarFormattingState:function(t){var e=this.caret.start.span,n=e.parent,i=this.caret.isCollapsed()&&this.caret.hasCharBefore(),o=this.formattingState.is("bold"),r=this.formattingState.is("italic"),s=this.formattingState.is("link"),d=this.formattingState.is("math"),h=this.formattingState.is("code")||n instanceof N,l=n instanceof T,u=n instanceof _,f=l||u,p=e.isEditable(),g=h||d||!p,m=g,v=!(this.undoManager.canUndo()||!c.jsonEqual(this.toJSON(),this.undoManager.state())),C=!this.undoManager.canRedo(),S={span:e,section:n,isMidWord:i,isBold:o,isItalic:r,isLink:s,isMath:d,isCode:h,isOrderedList:l,isUnorderedList:u,isList:f,isEditable:p,disableFormatting:g,disableStyle:m,disableUndo:v,disableRedo:C};return a.assert(t in S,"state name not found: "+t),S[t]},_getToolbarItem:function(t){var e=this,n=e._getToolbarFormattingState("section"),i=e._getToolbarFormattingState("isMidWord"),o=e._getToolbarFormattingState("isBold"),r=e._getToolbarFormattingState("isItalic"),s=e._getToolbarFormattingState("isLink"),d=e._getToolbarFormattingState("isMath"),c=e._getToolbarFormattingState("isCode"),h=e._getToolbarFormattingState("isOrderedList"),l=e._getToolbarFormattingState("isUnorderedList"),u=e._getToolbarFormattingState("isEditable"),f=e._getToolbarFormattingState("disableStyle"),p=e._getToolbarFormattingState("disableUndo"),g=e._getToolbarFormattingState("disableRedo");I.isAndroid()&&(f=i||f);var m={bold:{name:"bold",pressed:o,disabled:f},italic:{name:"italic",pressed:r,disabled:f},orderedList:{name:"ordered_list",pressed:h,disabled:!u},unorderedList:{name:"unordered_list",pressed:l,disabled:!u},indent:{name:"indent"},deindent:{name:"deindent"},mention:{name:"mention",disabled:s||c||d||!u},quote:{name:"quote",pressed:n.isQuoted()},code:{name:"code",pressed:c,disabled:!u},math:{name:"math",pressed:d,disabled:!u},undo:{name:"undo",disabled:p},redo:{name:"redo",disabled:g}};return a.assert(t in m,"item name not found: "+t),m[t]},_getToolbarLinkItems:function(){var t=[];return I.isNativeApp()||t.push({name:"link_input_icon"}),t.concat([{name:"link_input",focused:this.linkInputFocus},{name:"space"},{name:"cite"},{name:"link_save"}])},_isVideoEnabled:function(){var t=this;return!(!t._isImageEnabled()||!t._isVideoEnabledForUser()||t.isDisabledCommand("video"))},_isVideoEnabledForUser:function(){return q.qtextData.videoEnabled&&(q.qtextData.videoEditorSupported||q.debug)},_isImageEnabled:function(){this._getToolbarFormattingState("isList");return!0},_getToolbarContentItems:function(){var t=this,e=t._getToolbarFormattingState("disableFormatting"),n=t._getToolbarFormattingState("isLink"),i=[],o=this._isImageEnabled(),r=this._isVideoEnabled();return q.tabbedEditorToolbar?(!t.isDisabledCommand("video")&&t._isVideoEnabledForUser()&&i.push({name:"video-tab",disabled:!r}),t.isDisabledCommand("image")||i.push({name:"photos-tab",disabled:!o})):(r&&i.push({name:"video"}),o&&i.push({name:"image"})),i.push({name:"link",pressed:n,disabled:e}),i},_getToolbarIndentItems:function(){var t=this._getToolbarFormattingState("isList"),e=[];return t&&(e=e.concat([this._getToolbarItem("indent"),this._getToolbarItem("deindent")])),e},_getToolbarTabbedItems:function(){var t=[this._getToolbarItem("italic"),this._getToolbarItem("bold"),this._getToolbarItem("mention"),this._getToolbarItem("undo"),this._getToolbarItem("orderedList"),this._getToolbarItem("unorderedList"),this._getToolbarItem("quote"),this._getToolbarItem("code"),this._getToolbarItem("math")];return t=t.concat(this._getToolbarIndentItems()),t=t.concat(this._getToolbarContentItems())},getToolbarState:function(t){var e,n=this;return 0===t?e=n._getToolbarLinkItems():q.tabbedEditorToolbar?e=n._getToolbarTabbedItems():1===t?(e=[n._getToolbarItem("bold"),n._getToolbarItem("italic"),n._getToolbarItem("orderedList"),n._getToolbarItem("unorderedList")],e=e.concat(n._getToolbarIndentItems()),e.push({name:"space"}),e=e.concat(n._getToolbarContentItems()),e.push({name:"overflow_show",grayBackground:!0})):2===t&&(e=[n._getToolbarItem("mention"),n._getToolbarItem("quote"),n._getToolbarItem("code"),n._getToolbarItem("math"),{name:"space"},n._getToolbarItem("undo"),n._getToolbarItem("redo"),{name:"overflow_hide"}]),e.forEach(function(t){n.isDisabledCommand(t.name)&&(t.pressed=!1,t.disabled=!0)}),e},updateSpellingSuggestions:function(){I.isIOSApp()&&setTimeout(function(){i.send("selectionChanged")},0)},flushTextInput:function(){I.isIOSApp()&&q.buildNumber>=860&&i.send("flushTextInput")},handleCommand:function(t){if(this.isDisabledCommand(t))return!1;for(var e=t,n=new Array(arguments.length-1),i=1;i<arguments.length;++i)n[i]=arguments[i];return r.ios&&this._backspaceCount>20&&"backspace"==e&&(e="delete-previous-word"),n[0]="command-"+e,this.trigger.apply(this,n)},progressivelyExitSection:function(t,e){if(t.getIndent()>0)t.setIndent(t.getIndent()-1);else if(t instanceof b||e)t.isQuoted()&&t.setQuoted(!1);else{t=t.changeType(b);for(var n=t.previousSibling();n&&n.isEditable()&&(n.isEmpty()||""===n.node.textContent.trim());){var i=n;n=n.previousSibling(),this.removeChild(i)}}return t},toggleModifier:function(t){var e,n;return this.formattingState.toggleModifier(this.caret,t),!this.caret.isCollapsed()&&(e=this._getSelectedSpans(!1),n=e.every(function(e){return e.hasModifier(t)||!A(e,t)}),e.forEach(function(e){e.isEditable()&&(n?e.removeModifier(t):e.setModifier(t,!0))}),!1)},toggleSectionType:function(t){var e=this._getSelectedSections(),n=e[0]instanceof t,i=this.caret.start.clone(),o=this.caret.end.clone();return e.forEach(function(e){e.isEditable()&&(n?e.changeType(b):e.changeType(t))}),this.moveCaret(i,o),n||this.forceDomReflow(),!1},cloneSelection:function(){var t,e,n=this,i=this._getSelectedSpans(!1),o=[];return i.forEach(function(i){t!=i.parent&&(t=i.parent,e=i.parent.toJSON(),e.spans=[],n.caret.containsEntireSection(t)||(e.type="plain"),o.push(e)),e.spans.push(i.toJSON())}),o.map(function(t){return x.fromJSON(t)})},sanitizeContent:function(t){var e=this,n=t.filter(function(t){return!(t instanceof y&&e.isDisabledCommand("image"))&&(!(t instanceof D&&e.isDisabledCommand("embed"))&&!(t instanceof w&&e.isDisabledCommand("horizontal-rule")))});return!e.allowsMultipleSections()&&t.length>0&&(n=[n.reduce(function(t,e){return t.merge(e),t})]),n=n.map(function(t){var n=t instanceof N&&e.isDisabledCommand("code");return n=n||t instanceof _&&e.isDisabledCommand("unordered_list"),n=n||t instanceof T&&e.isDisabledCommand("ordered_list"),n&&(t=t.changeType(b)),t.setQuoted(t.isQuoted()&&!e.isDisabledCommand("quote")),t.children.forEach(function(t){for(var n in t.modifiers)e.isDisabledCommand(n)&&t.removeModifier(n)}),t})},saveState:function(){this.undoManager.add(this.toJSON()),this.trigger("meaningfulChange")},setImageUploader:function(t){this.imageUploader=t},setLinkSelector:function(t){var e=this;e.linkSelector=t,t.onSubmit(function(n){var i=n.target||{type:"url",url:n.url};!i.url&&n.url&&(i.url=n.url);var o=e._insertOrModifyLink(n.text,i);t.hide(),e.focus(),e.moveCaret(o.nextSibling().last()),setTimeout(function(){e.focus(),e.caret.scrollIntoViewIfNeeded(),e._focusAfterHidingLinkSelectorOnIOS()},0),e.saveState()}),t.onCancel(function(n){if(t.hide(),e.focus(),n){var i=e.caret.start.span.modifiers,o=new f(n,i);e.insertSpan(e.caret.start,o),e.moveCaret(o.last())}})},_focusAfterHidingLinkSelectorOnIOS:function(){if(I.isIOSApp()){var t=this,e=300;setTimeout(function(){t.node&&t.node.blur(),setTimeout(function(){t.focus(),t.caret.scrollIntoViewIfNeeded()},e)},e)}},setPhotoSearch:function(t){var e=this;e.photoSearch=t,t.onInsert(function(n){e.insertAndUploadImageUrl(n,"photosearch"),t.hide(),e.focus()}),t.onCancel(function(){t.hide(),e.focus()})},setContentType:function(t){this._contentType=t},getContentType:function(){return this._contentType||"unknown"},getCurrentDirection:function(){return this.caret.start.span.parent.getDirection()},_parseAndLinkifySections:function(t){var e=[];return t.forEach(function(t){t.children.forEach(function(n){if(A(n,"link")&&!n.hasModifier("link")){var i=a.linkify(n.getText());if(0!==i.length&&(1!=i.length||i[0].href)){var o=n.modifiers;i.forEach(function(i){var r=i.text,s=i.href,a=new f(r,o);s&&(a.setModifier("link",{type:"url",url:s},!0),e.push(a)),t.insertBefore(a,n)}),t.removeChild(n)}}})}),e},linkifySections:function(t){this.fetchLinkPreviews(this._parseAndLinkifySections(t))},insertAndUploadImageUrl:function(t,e,n){if(this.imageUploader){var i=this;this.imageUploader.showUploading(),this.imageUploader.uploadImageUrl(t,function(t){n&&(n.previousSibling()?i.moveCaret(n.previousSibling().last()):n.nextSibling()?i.moveCaret(n.nextSibling().first()):(n.parent.insertBefore(new f(" "),n),i.moveCaret(n.previousSibling().first())),n.parent.removeChild(n)),i.insertImages([t],{source:e}),i.imageUploader.hideDropZone()})}},insertSpan:function(t,e){var n;return n=t.atSpanStart()?t.span:t.atSpanEnd()?t.span.nextSibling():t.span.split(t.offset),t.span.parent.insertBefore(e,n),""===t.span.getText()&&t.span.parent.removeChild(t.span),e.last()},insertImages:function(t,e){this.handleCommand("image",t,e)},moveCaret:function(t,e,n){var i=this.caret.move(t,e,n);return this.trigger("caretMoved"),i},moveCaretEnd:function(t){var e=this.caret.moveEnd(t);return this.trigger("caretMoved"),e},moveCaretStart:function(t){var e=this.caret.moveStart(t);return this.trigger("caretMoved"),e},_updatePlaceholder:function(){this.isEmpty()&&this.children[0]instanceof b&&!this.children[0].isQuoted()?this.node.classList.add("empty"):this.node.classList.remove("empty")},_handleEmptySpan:function(t){var e,n,i;return t.parent.firstChild()==t&&1==t.parent.children.length?(t.setText(""),t.removeAllModifiers(),t.first()):(n=t.previousSibling(),i=t.nextSibling(),t.parent.removeChild(t),n?(t=n,e=n.getLength()):(t=i,e=0),new u(t,e))},updateCaret:function(){var t=this.caret.update();return t&&(this.trigger("caretMoved"),this.trigger("meaningfulChange")),this._updateActiveSpans(),t},_updateCaretAndFormattingState:function(){this.updateCaret()&&this._updateFormattingState()},_updateActiveSpans:function(){var t,e,n=this.node.querySelectorAll(".active"),i=this.caret.start.span,o=this.caret.end.span;for(t=0;t<n.length;t++)n[t].classList.remove("active");for(e=i;e!=o;e=e.next())e.node.classList.add("active");e.node.classList.add("active")},_debugEvent:function(t,e){},_attachEventListeners:function(){var t,e=this,n=this._debugEvent.bind(this),i=new v.Hub(this.node);c.iterItems(C,function(t,n){var o={source:"keyboard",shortcut:t};i.on(t,function(t){return e.handleCommand(n,t,o)})}),["Left","Up","Home"].forEach(function(t){i.on(t,function(){return!(e.caret.isCollapsed()&&e.caret.start.atDocStart())})}),["Right","Down","End"].forEach(function(t){i.on(t,function(){return!(e.caret.isCollapsed()&&e.caret.start.atDocEnd())})}),a.on("input",this.node,function(t){if(n("input",t),I.isAndroid()&&"@"==t.data)return e.handleCommand("mention","@",{source:"keyboard"})}),a.on("keydown",this.node,function(o){n("keydown",o);var s;return v.isNavigation(o)&&!e.caret.isCollapsed()||e.updateCaret(),v.isOnlyShiftKey(o)||e.caret.scrollIntoViewIfNeeded(),r.ios&&(8===o.which?e._backspaceCount+=1:e._backspaceCount=0,t<+new Date-500&&(e._backspaceCount=0)),s=i.trigger(o),e.trigger("keydown"),setTimeout(e.trigger.bind(e,"meaningfulChange"),0),s}),a.on("keypress",this.node,function(t){if(n("keypress",t),e.updateCaret(),!t||0===t.which||t.ctrlKey||t.metaKey||t.altKey||e._beforeTextInput(t),"@"==String.fromCharCode(t.which))return e.handleCommand("mention","@",{source:"keyboard"});var i=String.fromCharCode(t.which);return i==t.key?e.trigger("keypress",i):void 0}),a.on("keyup",this.node,function(i){return n("keyup",i),!e.caret.isCollapsed()&&v.isNavigation(i)&&i.shiftKey&&!v.isOnlyShiftKey(i)||e.updateCaret(),r.ios&&(t=+new Date),v.isNavigation(i)||!e.caret.isCollapsed()?e._updateFormattingState():e._afterTextInput(),!1}),a.on("compositionstart",this.node,function(t){n("compositionstart",t)}),a.on(["textInput","compositionupdate"],this.node,function(t,i){if(n(i,t),I.isAndroid()||e.updateCaret(),e._beforeTextInput(t),"textInput"==i&&p.usesCompositionEvents())return!0;if("compositionupdate"==i&&!p.usesCompositionEvents())return!0;if(!e.caret.isCollapsed())return!0;var o=t.data;if(" "==o&&!1===e.handleCommand("space")||o&&!1===e.trigger("keypress",o))return!1;setTimeout(function(){e.updateCaret(),e.caret.scrollIntoViewIfNeeded(),e._afterTextInput()},0)}),a.on("compositionend",this.node,function(t){n("compositionend",t)}),a.on("focus",this.node,function(){e.linkSelector&&e.linkSelector.hide(),e.photoSearch&&e.photoSearch.hide(),e.trigger("focus")}),a.on("blur",this.node,function(){e.trigger("blur")}),(r.mobile||r.ipad)&&e._runForever(function(){e.updateCaret()}),this._attachMouseAndTouchEvents(),this._attachClipboardEvents(),this._attachDragAndDropListeners()},_attachClipboardEvents:function(){a.on("copy",this.node,this.handleCommand.bind(this,"copy")),a.on("cut",this.node,this.handleCommand.bind(this,"cut")),a.on("paste",this.node,this.handleCommand.bind(this,"paste"))},_attachMouseAndTouchEvents:function(){var t=this,e=null,n=this.trigger.bind(this,"longpress"),i=this._debugEvent.bind(this);a.on(["mousedown","touchstart"],this.node,function(o,r){e||(e=setTimeout(function(){n(o)},500)),i(r,o),setTimeout(t._updateCaretAndFormattingState.bind(t),0),t.trigger(r,o)}),a.on(["mouseup","touchend"],this.node,function(n,o){e&&(clearTimeout(e),e=null),i(o,n),setTimeout(t._updateCaretAndFormattingState.bind(t),0),t.trigger(o,n)}),a.on(["mousemove","touchmove"],this.node,function(e,n){setTimeout(t._updateCaretAndFormattingState.bind(t),0),t.trigger(n,e)})},_attachDragAndDropListeners:function(){if(!r.mobile){var t=this,e=!1,i=this._debugEvent.bind(this);a.on(["dragstart","dragend"],this.node,function(n,o){i(o,n),e="dragstart"==o;var r,s=t.caret.start.span.parent;t.caret.isCollapsed()&&(s.isEditable()?"IMG"==n.target.nodeName&&(r=f.get(n.target.parentElement.parentElement),s=r.parent,t.moveCaret(s.first(),s.last())):t.moveCaret(s.first(),s.last()))}),a.on("drop",this.node,function(r){i("drop",r);var a,d,c,h,l,u=[s.PUBLIC_HTML,s.HTML];if(e)e=!1,c=t.cloneSelection();else{for(h=0;h<u.length;h++)if(l=r.dataTransfer.getData(u[h])){c=n("./qtext2/parser.js").parse(l,u[h]),c=t.sanitizeContent(c);break}c=c||[]}try{a=o.rangeFromPoint(r.clientX,r.clientY),d=t.caret._fromNode(a.startContainer,a.startOffset),t.saveState(),t._deleteSelection(),t.moveCaret(d),t.insertSections(c),r.preventDefault()}catch(t){console.error(t)}})}},_attachCommands:function(){var t,e,i,o,r=n("./qtext2/commands.js").COMMANDS,s=Object.keys(r);for(o=0;o<s.length;o++)i=s[o],this.isDisabledCommand(i)||(t=r[i],e=new t(this),this._commands[i]=e,this._emitter.on("command-"+i,e.run.bind(e,i)))},_initExtensions:function(){var t,e,i,o=n("./qtext2/extensions.js").EXTENSIONS;for(i=0;i<o.length;i++)t=o[i],e=new t(this),e.install(),this._extensions.push(e)},_runForever:function(t){var e=this,n=function(){if(!e._destroyed)try{t()}catch(t){}finally{window.requestAnimationFrame(n)}};window.requestAnimationFrame(n)},_beforeTextInput:function(t){var e=this.caret.start.span.parent;if(this.caret.isCollapsed()||(this.saveState(),this._deleteSelection(),e=this.caret.start.span.parent),!e.isEditable()){var n=new b;this.caret.start.atSectionStart()?this.insertBefore(n,e):this.insertAfter(n,e),this.moveCaret(n.first()),this.caret.updateAndroidCaretPosition(1)}this.formattingState.updatePosition(this.caret)},_afterTextInput:function(){this.formattingState.hasChanged(this.caret)&&this._applyFormattingChange()},_updateFormattingState:function(){this.formattingState.update(this.caret)},_applyFormattingChange:function(){var t=this.caret.start.span,e=this.formattingState.position.offset,n=this.caret.start.offset;t===this.formattingState.position.span?n>e?(n<t.getLength()&&t.split(n,!0),e>0&&(t=t.split(e,!0)),this.formattingState.apply(t),this.moveCaret(t.last()),this._updateFormattingState()):n<e&&this._updateFormattingState():this._updateFormattingState()},_deleteSelection:function(){var t,e,n=this.caret.start,i=this.caret.end,o=n.span.parent,r=i.span.parent;if(o.isEditable()&&(n.atSpanStart()?n.atSectionStart()||(e=n.alternatePosition()):e=n),o==r)if(o.isEditable())o.deleteText(n,i);else{var s=n.span.next(),a=n.span.previous();s?e=s.first():a?e=a.last():(t=new b,this.insertAfter(t,o),e=t.first()),this.removeChild(o)}else{for(o.isEditable()?o.deleteText(n,o.last()):(t=new b,this.insertBefore(t,o),this.removeChild(o),o=t);o.nextSibling()!=r;)this.removeChild(o.nextSibling());r.isEditable()?r.deleteText(r.first(),i):(t=new b,this.insertBefore(t,r),this.removeChild(r),r=t),e=o.merge(r)}e||(e=o.first()),this.moveCaret(e,e,!0)},_getSelectedSpans:function(t){this.updateCaret();var e=[],n=this.caret.start,i=this.caret.end;if(this.caret.isCollapsed())return[];if(n.span==i.span)i.offset<i.span.getLength()&&i.span.split(i.offset,t),n.offset>0&&(i.span=n.span=n.span.split(n.offset,t)),e=[n.span];else{n.offset>0&&(n.offset==n.span.getLength()?n.span=n.span.next():n.span=n.span.split(n.offset,t)),i.offset<i.span.getLength()&&(0===i.offset?i.span=i.span.previous():i.span.split(i.offset,t));for(var o=n.span;o!=i.span;o=o.next())e.push(o);e.push(i.span)}return this.moveCaret(n.span.first(),i.span.last()),e},_toggleMathOrCodeModifier:function(t){if(!this.caret.isCollapsed()){var e=this._getSelectedSpans(!0);e[0].getModifier(t)?e.forEach(function(e){e.removeModifier(t)}):(e=this._mergeSpansBySection(e),e.forEach(function(e){e.setModifier(t,!0,!0)}),this.moveCaret(e[0].first(),e[e.length-1].last())),this._updateFormattingState()}},_getSelectedSections:function(){this.updateCaret();var t,e=[],n=this.caret.start,i=this.caret.end;if(this.caret.isCollapsed())e.push(n.span.parent);else{for(t=n.span.parent;t!=i.span.parent;t=t.nextSibling())e.push(t);e.push(i.span.parent)}return e},insertSections:function(t){var e,n,i,o,r,s,a,d=this;if(0!==t.length){if(d.caret.isCollapsed()||d._deleteSelection(!0),this.handleCommand("embed",t),e=d.caret.start,i=e.span.parent,!i.isEditable()){var c=new b;d.caret.start.atSectionStart()?d.insertBefore(c,i):d.insertAfter(c,i),d.moveCaret(c.first()),i=c,e=c.first()}a=h({},e.span.modifiers),i.split(e),o=i.nextSibling(),t.forEach(function(t){t.children.forEach(function(e){t.isEditable()&&e.updateModifiers(a,!0)}),d.insertBefore(t,o),i instanceof N&&t.isEditable()&&t.changeType(N),t.setIndent(t.getIndent())});var l=this._parseAndLinkifySections(t);r=i.nextSibling(),r.constructor==i.constructor||r instanceof b?i.merge(r):i.isEmpty()&&this.removeChild(i),s=o.previousSibling(),s.isEditable()&&(s.constructor==o.constructor||o instanceof b)?(n=s.last(),s.merge(o)):n=o.first(),this.moveCaret(n),this.fetchLinkPreviews(l),s instanceof y&&o instanceof T&&this.forceDomReflow()}},_shouldAllowLinks:function(t){t=t||this.caret.start.span;var e=t.parent;return!!this.caret.isCollapsed()&&(!t.hasModifier("link")&&(!(e instanceof N||t.hasModifier("code"))&&!t.hasModifier("math")))},_insertOrModifyLink:function(t,e,n,i){var o=this.caret.start,r=!i&&o.span.hasAnyModifier(["link","citation"]),s=r?o.span:new f(t),a=new f(" ");return r||s.updateModifiers(o.span.modifiers),s.removeModifier("link"),s.removeModifier("citation"),a.updateModifiers(s.modifiers),r||(o=this.insertSpan(o,s)),n?(s.setModifier("citation",{target:e}),s.setText(" ")):(s.setModifier("link",e),s.setText(t)),o=s.last(),this.caret.move(o)," "!==this.caret.charAfter()&&(o=this.insertSpan(o,a),this.caret.move(o)),s},_previewLink:function(t,e){var n,i,o,r=this;e=e||this.saveState.bind(this),t.hasModifier("link")?o=t.getModifier("link").url:t.hasModifier("citation")?(n=t.getModifier("citation"),i="target"in n?n.target:n,o=i.url):o=t.getText(),o.startsWith("mailto:")&&g(o.slice(7))||(o=a.ensureProtocol(o),this.linkSelector.getLinkPreview(o,function(n){if(!r.disabled)if(e(),t.hasModifier("citation"))t.setModifier("citation",h({title:n.title},t.getModifier("citation")));else if("image"==n.type)r.insertAndUploadImageUrl(o,"link",t);else{if(t.setText(n.title),M.qtext_hyperlink_embed){var i=document.createElement("iframe");i.setAttribute("src",n.embed_url),document.body.appendChild(i)}r.caret.start.span==t&&(r.moveCaret(t.last()),r._updateFormattingState())}},function(){}))},fetchLinkPreviews:function(t){var e=this,n=c.once(function(){e.saveState()});t.forEach(function(t){e._previewLink(t,n)})},_mergeSpansBySection:function(t){var e,n=null,i=null,o=[];return t.forEach(function(t){t.parent!=i?(n=t,i=t.parent,o.push(t)):(e=a.objectIntersection(n.modifiers,t.modifiers),n.removeAllModifiers(),n.updateModifiers(e),n.setText(n.getText()+t.getText()),t.parent.removeChild(t))}),o}});e.Doc=P},"./qtext2/caret.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=n("./shared/jquery.js"),r=n("./shared/errors.js"),s=n("./qtext2/util.js").Util,a=n("./shared/util.js"),d=n("./shared/rangy.js").rangy,c=(n("./settings.js"),n("./qtext2/span.js").Span),h=n("./qtext2/section.js").Section,l=n("./qtext2/base.js"),u=n("./qtext2/position.js").Position,f=n("./qtext2/selection.js").Selection,p=n("./shared/client.js"),g=n("./shared/browser.js"),m=function(t,e,n){var i="Failed to set range safe="+n+": ";i+="("+(s.isTextNode(t)?t.textContent:t.outerHTML)+") "+e,r.logJsError("IndexSizeError",i)},v=function(t,e,n){try{try{t.setStart(e,n)}catch(i){0==e.textContent.length&&t.setStart(e,0),m(e,n,!1)}}catch(t){m(e,n,!0)}},C=function(t,e,n){try{try{t.setEnd(e,n)}catch(i){0==e.textContent.length&&t.setEnd(e,0),m(e,n,!1)}}catch(t){m(e,n,!0)}};e.Caret=i.extend({__init__:function(t,e,n){this.selection=new f(t,e,n),this.doc=n;var i=this;Object.defineProperty(i,"start",{get:function(){return i.selection.start},set:function(t){i.selection=new f(t,i.end)}}),Object.defineProperty(i,"end",{get:function(){return i.selection.end},set:function(t){i.selection=new f(i.start,t)}})},toJSON:function(){return this.selection.toJSON()},getStartNode:function(){return this.selection.getStartNode()},getEndNode:function(){return this.selection.getEndNode()},moveStart:function(t){return this.selection.moveStart(t)},moveEnd:function(t){return this.selection.moveEnd(t)},move:function(t,e,n){e=e||t;var i=!0;return this.start.equals(t)&&this.end.equals(e)&&(i=!1),this.start.span=t.span,this.start.offset=t.offset,this.end.span=e.span,this.end.offset=e.offset,this._apply(n),i},isCollapsed:function(){return this.selection.isCollapsed()},charBefore:function(){return this.selection.charBefore()},hasCharBefore:function(){return this.selection.hasCharBefore()},previousTextUntil:function(t){return this.selection.previousTextUntil(t)},charAfter:function(){return this.selection.charAfter()},charPosition:function(){return this.selection.charPosition()},hasCharAfter:function(){return this.selection.hasCharAfter()},updateAndroidCaretPosition:function(t){t=t||0},update:function(t){var e,n,i,o=d.getSelection();return!!o.anchorNode&&(o.isCollapsed?e=n=this._fromNode(o.anchorNode,o.anchorOffset):(i=o.getRangeAt(0),e=this._fromNode(i.startContainer,i.startOffset),n=this._fromNode(i.endContainer,i.endOffset)),!(!e||!n)&&this.move(e,n,t))},_fromNode:function(t,e){var n,i,o,r;if(!this.doc.contains(t)){return null}if(l.Doc.is(t))r=l.Doc.get(t),0===e?(i=r.firstChild().firstChild(),o=0):(i=r.lastChild().lastChild(),o=i.getLength());else if(h.is(t))n=h.get(t),0===e?(i=n.firstChild(),o=0):(i=n.lastChild(),o=i.getLength());else if(!c.is(t.parentNode)||1!==e&&0!==e){for(;t&&!c.is(t);)t=t.parentNode;if(!t)return null;i=c.get(t),o=e}else i=c.get(t.parentNode),o=0===e?0:i.getLength();return new u(i,o)},_apply:function(t){var e,n,i,o,r=d.getSelection(),s=this.getStartNode();if(this.isCollapsed()){if(!t&&r.isCollapsed&&s==r.anchorNode&&this.start.offset==r.anchorOffset)return;o=d.createRange(),v(o,s,this.start.offset),C(o,s,this.start.offset),o.collapse(!0),r.removeAllRanges(),r.addRange(o)}else{if(e=this.end.span.getFocusNode(),r.isCollapsed)o=d.createRange();else if(o=r.getRangeAt(0),n=this._fromNode(o.startContainer,o.startOffset),i=this._fromNode(o.endContainer,o.endOffset),!t&&n&&i&&this.start.equals(n)&&this.end.equals(i))return;v(o,s,this.start.offset),C(o,e,this.end.offset),r.removeAllRanges(),r.addRange(o)}},getAbsolutePosition:function(t){var e=window.getSelection(),n=s.firstScrollingParent(this.doc.node),i=document.body.parentElement,r=e.rangeCount>0&&e.getRangeAt(0),a=r?r.getClientRects():[];if(a.length>0){var c={top:a[0].top,left:a[0].left};return t||(c.top+=n.scrollTop||i.scrollTop,c.left+=n.scrollLeft||i.scrollLeft),c}var h=d.getSelection().anchorNode;return s.isTextNode(h)&&(h=this.start.span.parent.node),o(h).children().first().is("img")?o(h).children().first().offset():s.getContainerOffset(h,n)},scrollIntoViewIfNeeded:function(){if(this.isCollapsed()&&d.getSelection().anchorNode){var t=window.innerHeight;if(g.ios&&!p.isUIWebView()&&(t=Math.max(document.documentElement.clientHeight,t)),p.isIOSMobileWeb()){var e=window.innerHeight>window.innerWidth;window.navigator.userAgent.indexOf("iPad")>=0?t-=e?325:410:t-=e?265:200}var n,i,o=this.getAbsolutePosition(),r=s.firstScrollingParent(this.doc.node),a=document.body.parentElement,c=r.scrollTop||a.scrollTop,h=c+t;h-=50,o&&(n=o.top,i=n+30,setTimeout(function(){n<c?(r.scrollTop+=n-c,a.scrollTop+=n-c):i>h&&(r.scrollTop+=i-h,a.scrollTop+=i-h)},0))}},containsEntireSection:function(t){return this.selection.containsEntireSection(t)},mergeAdjacentSpans:function(){if(this.isCollapsed()){var t=this.start.span,e=t.nextSibling(),n=t.previousSibling(),i=this.start.offset;e&&a.jsonEqual(t.modifiers,e.modifiers)&&(t.setText(t.getText()+e.getText()),e.parent.removeChild(e),this.move(new u(t,i))),n&&a.jsonEqual(t.modifiers,n.modifiers)&&(i+=n.getLength(),t.setText(n.getText()+t.getText()),n.parent.removeChild(n),this.move(new u(t,i)))}},getCoveringSpans:function(){return this.selection.getCoveringSpans()}})},"./qtext2/command/backspace.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/position.js").Position,r=n("./qtext2/util.js").Util,s=n("./qtext2/sections/plain.js").PlainSection,a=n("./shared/client.js");e.Backspace=i.extend({exec:function(){var t=this._actualBackspace();return t||this.doc.updateSpellingSuggestions(),this.doc.caret.scrollIntoViewIfNeeded(),t},_actualBackspace:function(){var t,e,n,i,d;if(!this.doc.caret.isCollapsed())return this.doc.saveState(),this.doc._deleteSelection(),!1;if(i=this.doc.caret.start.clone(),t=i.span.parent,e=t.previousSibling(),d=i.span.getText(),(i.atSectionStart()&&!i.atDocStart()||!t.isEditable()&&!i.atSectionStart()||"\n"==i.charBefore()||"."==i.charBefore()||","==i.charBefore())&&this.doc.saveState(),!t.isEditable())return this.doc.caret.start.atSectionStart()?e&&e.isEmpty()&&this.doc.removeChild(e):(e||(e=new s,this.doc.insertBefore(e,t)),this.doc.removeChild(t),this.doc.moveCaret(e.last()),this.doc.caret.updateAndroidCaretPosition()),!1;if(i.atDocStart())return n=this.doc.progressivelyExitSection(t),n!=t&&this.doc.saveState(),this.doc.moveCaret(n.first(),n.first(),!0),!1;if(i.atSectionStart())return t.getIndent()>0?(t.setIndent(t.getIndent()-1),this.doc.caret.updateAndroidCaretPosition()):e.isEditable()||t.isEmpty()?(this.doc.moveCaret(e.merge(t)),this.doc.caret.mergeAdjacentSpans()):this.doc.moveCaret(e.last()),!1;var c=!1;i.atSpanStart()&&(i.span=i.span.previous(),i.offset=i.span.getLength(),d=i.span.getText(),c=!0);for(var h=d.slice(0,i.offset),l=d.slice(i.offset),u=0,f=h.length;f>0&&"\n"==h[f-1];f--)u+=1;return 1==u&&l.startsWith("\n")&&(l=l.slice(1),c=!0),r.isAstralSymbol(h.slice(h.length-2))?(h=h.slice(0,-2),c=!0):h=h.slice(0,-1),i.atSectionEnd()&&h.endsWith("\n")&&(0===u?h+="\n":h=h.slice(0,-1),c=!0),h+l===""&&(c=!0),!(c&&!a.isIOS())||(this.doc.flushTextInput(),i.span.setText(h+l),i.span.isEmpty()?(i=this.doc._handleEmptySpan(i.span),this.doc.moveCaret(i,i,!0)):this.doc.moveCaret(new o(i.span,h.length)),!1)}})},"./qtext2/command/base.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=n("./qtext2/span.js").Span,r=n("./qtext2/modifiers.js").canForceModifier,s=e.Command=i.extend({__init__:function(t){this.doc=t},exec:function(t){throw new Error("Sub-classes should implement this method.")},shouldExec:function(t){return!0},run:function(t){return!this.shouldExec(t)||this.exec.apply(this,arguments)}});e.spanModifierToggle=function(t){return s.extend({exec:function(){return this.doc.saveState(),this.doc.toggleModifier(t)},shouldExec:function(){var e;return e=this.doc.caret.isCollapsed()?[new o(this.doc.caret.end.span.getText(),this.doc.formattingState._modifiers)]:this.doc.caret.getCoveringSpans(),e.some(function(e){return e.hasModifier(t)||r(e,t)})}})},e.sectionTypeToggle=function(t){return s.extend({exec:function(){return this.doc.saveState(),this.doc.toggleSectionType(t)}})}},"./qtext2/command/code.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/code.js").CodeSection,r=n("./qtext2/modifiers.js").canForceModifier;e.Code=i.extend({exec:function(){return this.doc.saveState(),this.doc.caret.isCollapsed()?(this.doc.formattingState.is("code")||!this.doc.allowsMultipleSections()?this.doc.toggleModifier("code"):this.doc.toggleSectionType(o),!1):(!this.doc._getSelectedSections().some(function(t){return!t.isEditable()})&&this.doc.caret.start.atSectionStart()&&this.doc.caret.end.atSectionEnd()?this.doc.toggleSectionType(o):this.doc._toggleMathOrCodeModifier("code"),!1)},shouldExec:function(){return this.doc.caret.isCollapsed()?this.doc.caret.start.span.parent.isEditable():!(this.doc._getSelectedSections().some(function(t){return!t.isEditable()})||!this.doc.caret.start.atSectionStart()||!this.doc.caret.end.atSectionEnd())||this.doc.caret.getCoveringSpans().some(function(t){return r(t,"code")})}})},"./qtext2/command/copy.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/section.js").Section,r=n("./qtext2/constants.js").CONTENT_TYPES,s=(n("./shared/client.js"),n("./shared/browser.js"));n("./settings.js");e.Copy=i.extend({exec:function(t,e){if(!s.msedge){var n=this._selectedSectionsJSON(),i=n.map(o.fromJSON),a=this.getContentForType(i,r.TEXT),d=this.getContentForType(i,r.HTML);e.clipboardData.setData(r.TEXT,a),e.clipboardData.setData(r.HTML,d),e.preventDefault(),e.stopPropagation(),"cut"==t&&this.doc._deleteSelection()}},getContentForType:function(t,e){return t.map(function(n){return n.toContent(e,t)}).join("")},_selectedSectionsJSON:function(){if(this.doc.caret.isCollapsed())return[];var t,e,n=[],i=this.doc.caret.start.clone(),o=this.doc.caret.end.clone(),r=i.span;for(r=i.span;r&&r.previous()!=o.span;r=r.next())if(!(i.span===r&&i.atSpanEnd()||o.span===r&&o.atSpanStart())){t!=r.parent&&(t=r.parent,e=t.toJSON(),e.spans=[],n.push(e));var s=i.span===r?i.offset:undefined,a=o.span===r?o.offset:undefined,d=!1;e.spans.push(r.toJSON(d,s,a))}return n}})},"./qtext2/command/delete.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/util.js").Util,r=n("./qtext2/sections/plain.js").PlainSection;e.Delete=i.extend({exec:function(t){if(this.doc.saveState(),this.doc.caret.isCollapsed()){if("delete"==t)return this._deleteSingle();"delete-forward"==t?this.doc.moveCaretEnd(this.doc.caret.start.span.parent.last()):"delete-backward"==t?this.doc.moveCaretStart(this.doc.caret.start.span.parent.first()):"delete-next-word"==t?this.doc.moveCaretEnd(this.doc.caret.start.nextWordBoundary()):"delete-previous-word"==t&&this.doc.moveCaretStart(this.doc.caret.start.previousWordBoundary())}return this._deleteSelection()},_deleteSelection:function(){if(!this.doc.caret.isCollapsed())return this.doc._deleteSelection(),!1},_deleteSingle:function(){var t,e,n;if(n=this.doc.caret.start.clone(),t=n.span.parent,e=t.nextSibling(),this.doc.caret.isCollapsed()){if(!t.isEditable())return this.doc.caret.start.atSectionEnd()?e&&e.isEmpty()&&this.doc.removeChild(e):(e||(e=new r,this.doc.insertBefore(e,t)),this.doc.removeChild(t),this.doc.moveCaret(e.first()),this.doc.caret.updateAndroidCaretPosition()),!1;if(n.atDocEnd())return!1;if(n.atSectionEnd())return t=n.span.parent,this.doc.moveCaret(t.merge(t.nextSibling())),!1;n.atSpanEnd()&&(n.span=n.span.next(),n.offset=0);var i=n.span.getText();return o.isAstralSymbol(i.slice(n.offset,n.offset+2))?n.span.deleteText(n.offset,n.offset+2):n.span.deleteText(n.offset,n.offset+1),n.span.isEmpty()?this.doc.moveCaret(this.doc._handleEmptySpan(n.span)):this.doc.moveCaret(n),!1}}})},"./qtext2/command/embed.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/embed.js").EmbedSection;e.Embed=i.extend({exec:function(t,e){e.forEach(function(t,n){var i=o.fromOtherSection(t);null!==i&&(e[n]=i)})}})},"./qtext2/command/image.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/image.js").ImageSection;e.Image=i.extend({exec:function(t,e){if(0!==e.length){var n=e.map(function(t){return o.fromURL(t)});this.doc.saveState(),this.doc.insertSections(n),this.doc.saveState()}}})},"./qtext2/command/indent.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/code.js").CodeSection,r=n("./qtext2/position.js").Position;e.Indent=i.extend({exec:function(t){return"indent"==t?this._indent():this._deindent()},_maybeInsertTab:function(){var t=this.doc.caret.isCollapsed(),e=this.doc.caret.start.clone(),n=e.span,i=n.parent,s=n.getText(),a=e.offset;return!!(t&&i instanceof o)&&(n.setText(s.slice(0,a)+"\t"+s.slice(a)),this.doc.moveCaret(new r(n,a+1)),!0)},_afterIndent:function(t){t&&this.doc.forceDomReflow(),this.doc.updateCaret()},_indent:function(){if(this._maybeInsertTab())return!1;var t=this.doc._getSelectedSections(),e=!1;return t.forEach(function(t){t.setIndent(t.getIndent()+1)&&(e=!0)}),this._afterIndent(e),!e},_deindent:function(){var t=this.doc._getSelectedSections(),e=!1;return t.forEach(function(t){t.setIndent(t.getIndent()-1)&&(e=!0)}),this._afterIndent(e),!e}})},"./qtext2/command/link.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/span.js").Span,r=n("./qtext2/util.js").Util,s=n("./qtext2/position.js").Position,a=n("./qtext2/modifiers.js").canForceModifier;e.Link=i.extend({exec:function(){var t,e,n,i=this.doc.caret.start.span;return!!i.isEditable()&&(i.hasModifier("link")?(this.doc.caret.isCollapsed()||this.doc.saveState(),this.doc.formattingState.toggleModifier(this.doc.caret,"link"),this.doc._getSelectedSpans(!0).forEach(function(t){t.removeModifier("link")}),!1):(i.hasModifier("citation")&&(t=i.getModifier("citation").target,n=!0),t&&(e=t.url),this.doc.linkSelector.getExternalURL(this.onLinkInput.bind(this),e,n),!1))},shouldExec:function(){return a(this.doc.caret.start.span,"link")},onLinkInput:function(t){var e,n,i,a=this.doc.caret.isCollapsed(),d=this.doc.caret.start.clone(),c=this.doc._getSelectedSpans(!0),h=t.url,l=t.isCitation,u=this.doc.caret.start.span,f=l&&u.hasModifier("citation")||!l&&u.hasModifier("link"),p=f?u.getText():h;this.doc.saveState(),h&&(h=r.ensureProtocol(h),e={type:"url",url:h},l||(c=this.doc._mergeSpansBySection(c)),a?(n=this.doc._insertOrModifyLink(p,e,l,!0),d=new s(n.nextSibling(),1)):l?(n=new o(" ",{citation:{target:e}}),i=c[c.length-1],i.parent.insertAfter(n,i)):c.forEach(function(t){t.setModifier("link",e)}),!n||u.hasModifier("link")&&f||this.doc.fetchLinkPreviews([n])),this.doc.node.focus(),a?this.doc.moveCaret(d):this.doc.moveCaret(c[0].first(),c[c.length-1].last()),this.doc.caret.scrollIntoViewIfNeeded()}})},"./qtext2/command/math.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/modifiers.js").canForceModifier;e.Math=i.extend({exec:function(){return this.doc.saveState(),this.doc.caret.isCollapsed()?this.doc.formattingState.toggleModifier(this.doc.caret,"math"):this.doc._toggleMathOrCodeModifier("math"),!1},shouldExec:function(){return this.doc.caret.getCoveringSpans().some(function(t){return o(t,"math")})}})},"./qtext2/command/mention.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/constants.js"),r=n("./third_party/unicode/UnicodeBidiDirection.js");e.Mention=i.extend({exec:function(t,e){if(this.doc._shouldAllowLinks()&&!this.doc.linkSelector.isActive()){if("@"==e){var n=this.doc.caret.charBefore();if(n&&!o.WORD_START_REGEX.test(n))return}var i=this.doc.getCurrentDirection(),s=i==r.RTL;this.doc.focus();var a=this.doc.caret.getAbsolutePosition(this.doc.isInModal())||{};return this.doc.linkSelector.show(e,a.left,a.top,s),!1}}})},"./qtext2/command/paste.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/parser.js"),r=n("./qtext2/constants.js").CONTENT_TYPES,s=[r.PUBLIC_HTML,r.HTML,r.TEXT,r.TEXT_URI],a=/href=(['"])([^'">]*)\1[^>]*>\2/im;e.Paste=i.extend({exec:function(t,e){if(!e.clipboardData||!e.clipboardData.types||!e.clipboardData.getData)return!1;var n,i=this;return s.some(function(t){for(var o=0;o<e.clipboardData.types.length;o++)if(e.clipboardData.types[o]==t&&(n=e.clipboardData.getData(t))&&i.allowClipboardData(t,n))return e.stopImmediatePropagation(),i.doc.saveState(),i._paste(n,t),!0}),!1},allowClipboardData:function(t,e){return t!=r.HTML||!a.test(e)},_paste:function(t,e){var n=o.parse(t,e);n=this.doc.sanitizeContent(n),this.doc.insertSections(n)}})},"./qtext2/command/quote.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/lists.js").isListSection;e.Quote=i.extend({exec:function(){var t,e,n=this.doc._getSelectedSections(),i=n[0],r=i.isQuoted(),s=[];for(this.doc.saveState();o(i)&&(t=i.previousSibling())&&t.getType()==i.getType();)s.push(t),i=t;for(i=n[n.length-1];o(i)&&(e=i.nextSibling())&&e.getType()==i.getType();)s.push(e),i=e;return n=n.concat(s),n.forEach(function(t){t.setQuoted(!r)}),!1}})},"./qtext2/command/return.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/plain.js").PlainSection,r=n("./qtext2/sections/code.js").CodeSection;e.Return=i.extend({exec:function(){this.doc.saveState();var t=this._actualReturn();return this.doc.updateSpellingSuggestions(),this.doc.caret.scrollIntoViewIfNeeded(),this.doc.caret.updateAndroidCaretPosition(),t},_actualReturn:function(){var t,e,n,i,s;return this.doc.caret.isCollapsed()||this.doc._deleteSelection(),t=this.doc.caret.start.span.parent,e=t.previousSibling(),n=e&&e.isEmpty(),s=this.doc.caret.start.clone(),t.isEditable()?(t.isEmpty()||""===t.node.textContent.trim()?t instanceof r&&e instanceof r&&!n?s=t.split(s):t instanceof o&&!t.isQuoted()&&0===t.getIndent()?s=t.split(s):(t=this.doc.progressivelyExitSection(t),s=t.first()):s=t.split(s),this.doc.moveCaret(s),!1):(i=new o,this.doc.caret.start.atSectionStart()?this.doc.insertBefore(i,t):(this.doc.insertBefore(i,t.nextSibling()),this.doc.moveCaret(i.first())),!1)}})},"./qtext2/command/soft_return.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./qtext2/sections/code.js").CodeSection,r=n("./qtext2/position.js").Position;e.SoftReturn=i.extend({exec:function(){var t=this.doc.caret.start,e=t.span,n=t.offset,i=e.parent,s=e.getText(),a="\n"==this.doc.caret.charBefore();if(!i.isEditable())return this.doc.handleCommand("return");if(this.doc.saveState(),i instanceof o){var d=i.split(t);return this.doc.moveCaret(d),!1}if(!i.allowsMultipleSoftReturns()&&a){for(;s.endsWith("\n");)s=s.slice(0,-1);return e.setText(s),this.doc.handleCommand("return")}return t.atSectionEnd()?(e.setText(s+"\n\n"),this.doc.moveCaret(e.last())):(e.setText(s.slice(0,n)+"\n"+s.slice(n)),this.doc.moveCaret(new r(e,n+1))),this.doc.moveCaret(new r(e,n+1)),!1}})},"./qtext2/command/undoredo.js":function(t,e,n){var i=n("./qtext2/command/base.js").Command,o=n("./shared/util.js");e.UndoRedo=i.extend({exec:function(t){return"undo"==t?this._undo():this._redo()},_undo:function(){return this.doc.undoManager.canRedo()||o.jsonEqual(this.doc.toJSON(!0),this.doc.undoManager.state())||this.doc.saveState(),this.doc.undoManager.undo(),this.doc.fromJSON(this.doc.undoManager.state()),!1},_redo:function(){return this.doc.undoManager.redo(),this.doc.fromJSON(this.doc.undoManager.state()),!1}})},"./qtext2/command/video.js":function(t,e,n){var i,o=n("./shared/client.js"),r=n("./qtext2/command/base.js").Command,s=n("./shared/errors.js"),a=n("./qtext2/sections/video.js").VideoSection,d=n("./shared/client.js"),c=n("./shared/upload.js"),h=n("./shared/util.js"),l=n("./settings.js"),u=n("./qtext2/util.js").Util,f=u.h,p=2e3;e.Video=r.extend({exec:function(t,e){l.qtextData.videoEnabled&&("video"==t?(e=e||{},this.showVideoUi(e.uuid,e.version)):"video:update"==t?this.updateOrInsertVideo(e):"video:upload-progress"===t?this.updateVideoProgress(e):"video:resume-upload"===t?c.resumeVideoUpload(e.uuid):"video:pause-upload"===t?c.pauseVideoUpload(e.uuid):"video:retry-upload"===t&&c.retryFailedVideoUpload(e.uuid)),"video:remove"==t&&this.removeVideo(e)},_findVideoSection:function(t){for(var e=0;e<this.doc.children.length;e++){var n=this.doc.children[e];if(n instanceof a&&n.getId()==t)return n}return null},updateVideoProgress:function(t){var e=this._findVideoSection(t.uuid);e&&e.updateVideoUploadProgress(t.progress,t.videoSize)},removeVideo:function(t){var e=this._findVideoSection(t);e&&(this.doc.saveState(),this.doc.moveCaret(e.first(),e.last(),!0),this.doc._deleteSelection(),this.doc.trigger("meaningfulChange"))},updateOrInsertVideo:function(t){this.doc.saveState(),t.onDevice=!t.libraryVideo,t.videoContentChanged=!0;var e=this._findVideoSection(t.uuid);e?e.updateVideo(t):this.doc.insertSections([a.fromVideo(t)]),this.doc.trigger("meaningfulChange")},showVideoUi:function(t,e){if(d.isNativeApp()){var n={uuid:t};e&&(n.version=e),i.send("showVideoEditor",n)}else this._showFileBrowser(t)},_showFileBrowser:function(t){var e=this,n=f("input",{type:"file",style:"display: none;",accept:".mp4, .webm, .avi, .mov|video/*"});document.body.appendChild(n),n.click(),n.addEventListener("change",function(){e._handleVideoUpload(n.files[0],t),n.value=null,n.parentElement.removeChild(n)})},_handleVideoUpload:function(t,e){var n=window.URL.createObjectURL(t),i=f("video",{src:n,style:"display: none;"}),r=this,a=function(){var n=r._thumbnailFromVideoEl(i);i.parentElement.removeChild(i),c.uploadData({kind:"qtext"},[n],function(n){r._enqueueAndUploadVideo(t,i,n.qimg_urls[0],e)},function(n){s.logJsError("qtext",["Uploading thumbnail failed: ",JSON.stringify(arguments),n].join("")),r._enqueueAndUploadVideo(t,i,null,e)})};o.isIOS()?i.onsuspend=a:i.oncanplay=a,document.body.appendChild(i)},_handleVideoProgress:function(t,e,n){if(e.shouldReportProgress===undefined)return e.shouldReportProgress=!1,void setTimeout(function(){e.shouldReportProgress=!0},p);e.shouldReportProgress&&this.doc.handleCommand("video:upload-progress",{uuid:n,progress:t,videoSize:e.size})},_enqueueAndUploadVideo:function(t,e,n,i){var o=this,r=i||h.uuid4(),a=1;this.doc.handleCommand("video:update",{uuid:r,version:a,length:e.duration,thumb:n,libraryVideo:!0,is_web_upload:!0,videoWidth:e.videoWidth,videoHeight:e.videoHeight,isUploading:!0}),c.enqueueResumableVideo(r,t,function(i,d){var h={vid:r,resumable_id:i,version:a,thumb:n,clips:[{id:r+"-1",num_chunks:d,start:0,end:1e3*e.duration}]};o._uploadVideoMetadata(h,function(e){c.onVideoUploadEvent(r,"success",function(){o._uploadVideoMetadata(h)}),c.onVideoUploadEvent(r,"failure",function(t){var e=o._findVideoSection(r);e&&e.renderVideoRetry(),s.logJsError("qtext","Qtext video file upload error: "+t.message)}),c.onVideoUploadEvent(r,"progress",function(e){o._handleVideoProgress(e.progress,t,r)}),c.uploadResumableVideo(r)})})},_uploadVideoMetadata:function(t,e){c.uploadVideoMetadata(t,e,function(t){s.logJsError("qtext","Qtext video metadata upload error: "+t)})},_thumbnailFromVideoEl:function(t){var e=document.createElement("canvas");e.width=t.videoWidth,e.height=t.videoHeight,e.getContext("2d").drawImage(t,0,0);for(var n=e.toDataURL("img/jpeg"),i=n.split(",")[1],o=n.split(";")[0].slice(5),r=window.atob(i),s=new window.ArrayBuffer(r.length),a=new window.Uint8Array(s),d=0;d<r.length;d++)a[d]=r.charCodeAt(d);return new window.Blob([a],{type:o})}})},"./qtext2/commands.js":function(t,e,n){var i=n("./qtext2/command/base.js"),o=n("./qtext2/command/backspace.js").Backspace,r=n("./qtext2/command/code.js").Code,s=n("./qtext2/command/copy.js").Copy,a=n("./qtext2/command/delete.js").Delete,d=n("./qtext2/command/indent.js").Indent,c=n("./qtext2/command/image.js").Image,h=n("./qtext2/command/link.js").Link,l=n("./qtext2/command/math.js").Math,u=n("./qtext2/command/mention.js").Mention,f=n("./qtext2/command/paste.js").Paste,p=n("./qtext2/command/quote.js").Quote,g=n("./qtext2/command/return.js").Return,m=n("./qtext2/command/soft_return.js").SoftReturn,v=n("./qtext2/command/undoredo.js").UndoRedo,C=n("./qtext2/command/embed.js").Embed,S=n("./qtext2/command/video.js").Video,x=n("./qtext2/sections/lists.js").OrderedListSection,b=n("./qtext2/sections/lists.js").UnorderedListSection;e.COMMANDS={backspace:o,cite:h,code:r,copy:s,cut:s,deindent:d,"delete":a,"delete-backward":a,"delete-forward":a,"delete-next-word":a,"delete-previous-word":a,indent:d,image:c,link:h,math:l,mention:u,paste:f,quote:p,redo:v,"return":g,"soft-return":m,undo:v,embed:C,video:S,"video:update":S,"video:remove":S,"video:upload-progress":S,"video:resume-upload":S,"video:pause-upload":S,"video:retry-upload":S,bold:i.spanModifierToggle("bold"),italic:i.spanModifierToggle("italic"),ordered_list:i.sectionTypeToggle(x),unordered_list:i.sectionTypeToggle(b)}},"./qtext2/diff.js":function(t,e){e.lineDiff=function(t,e,n){for(var i=t.length,o=e.length,r=[],s=0;s<=i;s++)r[s]=[];n=n||function(t,e){return t==e};for(var a=0,d=[[i,o]];a<d.length;){var c=d[a++],h=c[0],l=c[1],u=null,f=null,p=null;r[h][l]||(h>=i&&l>=o?r[h][l]=[]:(h<i&&l<o&&n(t[h],e[l])?u=r[h+1][l+1]:(h<i&&(p={type:"remove",index:h},u=[p].concat(r[h+1][l])),l<o&&(p={type:"insert",index:l},f=[p].concat(r[h][l+1]),(!u||f.length<u.length)&&(u=f))),r[h][l]=u),h>0&&!r[h-1][l]&&d.push([h-1,l]),l>0&&!r[h][l-1]&&d.push([h,l-1]),h>0&&l>0&&!r[h-1][l-1]&&d.push([h-1,l-1]))}return r[0][0]}},"./qtext2/extension/action_tracker.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./shared/debounce.js").throttle,r=n("./shared/log_sender.js"),s=["command-delete","command-backspace","command-return","command-space","command-embed"];e.ActionTracker=i.extend({install:function(){this.bufferedActions=[],this.doc.onAll(this.handleAllEvents.bind(this))},shouldTrackEvent:function(t){return-1==s.indexOf(t)&&(!!t.startsWith("command-")||!!t.startsWith("track-"))},maybeLogActions:o(function(){this.bufferedActions.forEach(function(t){r.log("qtext_actions",t)}),this.bufferedActions=[]},5e3),handleAllEvents:function(t){if(this.shouldTrackEvent(t)){var e=arguments[arguments.length-1];this.bufferedActions.push({name:t,sourceInfo:e,contentType:this.doc.getContentType()}),this.maybeLogActions()}}})},"./qtext2/extension/arrows.js":function(t,e,n){var i=n("./qtext2/extension/typing_change_base.js").TypingExtension,o=n("./qtext2/selection.js").Selection,r=n("./qtext2/constants.js");e.Arrows=i.extend({install:function(){this.doc.on("keypress",this.onKeypress.bind(this))},onKeypress:function(t){if(this.isActive()){var e,n=this.doc.caret.start.span,i=n.parent,s=this.doc.caret.start.prevPositionInSection();if(s)if(">"!=t){if("-"==t){var a=s.prevPositionInSection();if(!a)return;if(e=new o(a,this.doc.caret.start),!this.isActive(e))return;var d=e.getText();if(d=="<"+r.EM_DASH||"<-"==d)return i.replaceText(e.start,e.end,r.LEFT_ARROW),this.doc.moveCaret(a.nextPositionInSection()),this.doc.caret.updateAndroidCaretPosition(),!1}}else{if(e=new o(s,this.doc.caret.start),!this.isActive(e))return;if(e.getText()==r.EM_DASH)return i.replaceText(s,this.doc.caret.start,r.RIGHT_ARROW),this.doc.moveCaret(s.nextPositionInSection()),this.doc.caret.updateAndroidCaretPosition(),!1}}}})},"./qtext2/extension/autolink.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/span.js").Span,r=n("./qtext2/util.js").Util,s=n("./qtext2/position.js").Position;e.Autolink=i.extend({install:function(){this.doc.on("command-space",this.onSpace.bind(this)),this.doc.on("command-return",this.onReturn.bind(this))},onSpace:function(){return this.detectLinksBeforeCaret()},onReturn:function(){return this.detectLinksBeforeCaret(!0)},detectLinksBeforeCaret:function(t){var e=this.doc.caret.start,n=e.span;if(t&&e.atSectionStart()){if(!(n=n.previous()))return!1;e=n.last()}return!this._detectLinks(n,e,!t)},_detectLinks:function(t,e,n){if(!this.doc._shouldAllowLinks(t))return!1;var i,a=t.parent,d=e||t.last(),c=d.offset,h=d.previousWordBoundary(/\s/),l=t.getText(),u=l.slice(h.offset,c),f=r.linkify(u);if(f.forEach(function(t){var e=t.text,n=t.href;n&&e==u?i=new o(u,{link:{type:"url",url:n}}):u=u.slice(e.length)}),!i)return!1;n&&(t.setText(l.slice(0,c)+" "+l.slice(c)),this.doc.moveCaret(new s(t,c+1))),this.doc.saveState(),h=new s(d.span,c-u.length);var p,g,m=t;return h.equals(t.first())&&d.equals(t.last())?n?(m.setText(" "),g=new s(m,1)):m=null:(h.equals(t.first())||(p=new o(t.getText().slice(0,h.offset),t.modifiers)),n?(m.setText(" "+m.getText().slice(d.offset)),g=new s(m,1)):d.equals(t.last())?m=null:m.setText(m.getText().slice(d.offset))),p&&a.insertBefore(p,t),a.insertBefore(i,t),m||a.removeChild(t),g&&n&&this.doc.moveCaret(g),this.doc.fetchLinkPreviews([i]),!0}})},"./qtext2/extension/autolist.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/position.js").Position,r=n("./qtext2/sections/plain.js").PlainSection,s=n("./qtext2/sections/lists.js").UnorderedListSection,a=n("./qtext2/sections/lists.js").OrderedListSection,d=n("./qtext2/constants.js");e.Autolist=i.extend({install:function(){this.doc.on("command-space",this.onSpace.bind(this))},onSpace:function(){if(this.shouldAutoList()){var t=this.doc.caret.start.clone(),e=t.span,n=e.parent,i=t.offset,r=e.getText(),c=r.slice(0,i),h=new RegExp("^([-*+]|--|"+d.EM_DASH+")$"),l=/^1[.)]$/;if(n.firstChild()==e&&(h.test(c)||l.test(c))){var u=h.exec(c)||l.exec(c);return u=u[0],e.setText(r.slice(0,u.length)+" "+r.slice(u.length)),this.doc.moveCaret(new o(e,u.length+1)),this.doc.saveState(),e.setText(r.slice(u.length)),this.doc.moveCaret(e.first(),null,!0),h.test(c)?this.doc.toggleSectionType(s):this.doc.toggleSectionType(a),!1}}},shouldAutoList:function(){if(this.doc.isDisabledCommand("ordered_list")||this.doc.isDisabledCommand("unordered_list"))return!1;var t=this.doc.caret.isCollapsed(),e=this.doc.caret.start.span,n=e.parent;return!!t&&(!(e.hasModifier("link")||e.hasModifier("math")||e.hasModifier("code"))&&n instanceof r)}})},"./qtext2/extension/base.js":function(t,e,n){var i=n("./shared/Class.js").Class;e.Extension=i.extend({__init__:function(t){this.doc=t},install:function(){throw new Error("Sub-classes should implement this method.")},destroy:function(){}})},"./qtext2/extension/dashes.js":function(t,e,n){var i=n("./qtext2/extension/typing_change_base.js").TypingExtension,o=n("./qtext2/selection.js").Selection,r=n("./qtext2/constants.js");e.Dashes=i.extend({install:function(){this.doc.on("keypress",this.onKeypress.bind(this))},onKeypress:function(t){var e=this.doc.caret.start,n=e.span,i=n.parent;if(e.atSpanStart()){if(!(n=n.previousSibling()))return;e=n.last()}var s=e.prevPositionInSection();if(s){var a=Object.keys(r.FRACTIONS).join(""),d=new RegExp("(\\d|["+a+"])[-"+r.EM_DASH+"]");if(/\d/.test(t)){var c=s.prevPositionInSection();if(!c)return;var h=new o(c,this.doc.caret.start);if(!this.isActive(h))return;return void(d.test(h.getText())&&(i.replaceText(s,this.doc.caret.start,r.EN_DASH),this.doc.moveCaret(s.nextPositionInSection())))}if("-"!=t);else{if(!this.isActive(new o(s,this.doc.caret.start)))return;if("-"==this.doc.caret.charBefore())return i.replaceText(s,this.doc.caret.start,r.EM_DASH),this.doc.moveCaret(s.nextPositionInSection()),this.doc.caret.updateAndroidCaretPosition(),!1}}}})},"./qtext2/extension/double_space.js":function(t,e,n){var i=n("./qtext2/extension/typing_change_base.js").TypingExtension,o=n("./qtext2/selection.js").Selection,r=n("./qtext2/quirks.js").Quirks;e.DoubleSpace=i.extend({install:function(){this.doc.on("command-space",this.onSpace.bind(this)),this.MAX_SPACES=2,this.spacesExp=new RegExp("\\s{"+this.MAX_SPACES+"}")},onSpace:function(){if(this.isActive()){var t=this.doc.caret,e=t.start.prevPositionInSection(this.MAX_SPACES)||t.start.span.parent.first(),n=new o(e,t.start),i=t.start.nextPositionInSection(this.MAX_SPACES)||t.start.span.parent.last(),s=new o(t.start,i),a=t.start.nextPositionInSection(),d=n.getText(),c=s.getText(),h=t.charAfter();return/\s/.test(h)&&"\n"!=h&&a&&!a.span.hasModifier("citation")&&this.spacesExp.test(d+c)&&!r.insertsPeriodWithDoubleSpace()?(this.doc.moveCaret(a),this.doc.caret.updateAndroidCaretPosition(),!1):this.spacesExp.test(d)?(this.doc.caret.updateAndroidCaretPosition(),!1):void 0}}})},"./qtext2/extension/ellipses.js":function(t,e,n){var i=n("./qtext2/extension/typing_change_base.js").TypingExtension,o=n("./qtext2/selection.js").Selection,r=n("./qtext2/constants.js").ELLIPSIS;e.Ellipses=i.extend({install:function(){this.doc.on("keypress",this.onKeypress.bind(this))},onKeypress:function(t){if("."==t&&this.isActive()){var e=this.doc.caret.start.prevPositionInSection(2);if(e){var n=new o(e,this.doc.caret.start);if(this.isActive(n)&&".."==n.getText()){return n.start.span.parent.deleteText(n.start,n.end),n.start.span.insertText(r,n.start.offset),this.doc.moveCaret(n.start.nextPositionInSection()),this.doc.updateSpellingSuggestions(),this.doc.caret.updateAndroidCaretPosition(),this.doc.saveState(),!1}}}}})},"./qtext2/extension/external_image_upload.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/sections/image.js").ImageSection;e.ExternalImageUpload=i.extend({install:function(){this.doc.on("meaningfulChange",this.uploadExternalImages.bind(this))},uploadExternalImages:function(){var t=this;t.doc.children.forEach(function(e){if(e instanceof o){var n=e.firstChild();if(n.hasModifier("external_source")&&!n.hasModifier("uploading")){n.setModifier("uploading",!0);var i=n.getModifier("image"),r=n.getModifier("external_source");t.doc.insertAndUploadImageUrl(i,r,e)}}})}})},"./qtext2/extension/hr.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/sections/plain.js").PlainSection,r=n("./qtext2/sections/horizontal_rule.js").HorizontalRuleSection,s=n("./qtext2/constants.js");e.HR=i.extend({install:function(){this.doc.on("command-return",this.onReturn.bind(this))},onReturn:function(){if(this.isActive()){var t=new RegExp("^([-*+_=]{3,}|["+s.EM_DASH+"-]{2,})$"),e=this.doc.caret.start.clone(),n=e.span,i=n.parent,a=i.previousSibling();a&&a instanceof o&&t.test(a.getText().trim())&&!a.isQuoted()&&(this.doc.insertBefore(new r,a),this.doc.removeChild(a))}},isActive:function(){return!this.doc.isDisabledCommand("horizontal-rule")}})},"./qtext2/extension/image_loading.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./shared/jquery.js");e.ImageLoading=i.extend({install:function(){this.doc.on("meaningfulChange",this.onMeaningfulChange.bind(this))},onMeaningfulChange:function(){var t=this.doc;o(t.node).find("img").each(function(){null===this.onload&&(this.onload=function(){t.trigger("caretMoved")})})}})},"./qtext2/extension/mention.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension;e.Mention=i.extend({install:function(){this.doc.on("keypress",this.onKeypress.bind(this))},onKeypress:function(t){"@"==t&&this.doc.handleCommand("mention",t,{source:"keyboard"})}})},"./qtext2/extension/non_editable_cursors.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/section.js").Section;e.NonEditableCursors=i.extend({install:function(){this.doc.on("mousedown",this.onMousedown.bind(this)),this.doc.on("longpress",this.onLongpress.bind(this))},onLongpress:function(t){var e=this._sectionFromNode(t.target);e&&(e.isEditable()||(this.doc.moveCaret(e.first(),e.last()),this.doc.updateCaret()))},onMousedown:function(t){var e=this._sectionFromNode(t.target);if(e&&!e.isEditable()){var n=t.target.getBoundingClientRect(),i=n.left+document.body.scrollLeft,o=t.pageX-i;t.target.width/2>o?this.doc.moveCaret(e.first()):this.doc.moveCaret(e.last()),this.doc.updateCaret()}},_sectionFromNode:function(t){for(var e=t;e;){if(o.is(e))return o.get(e);e=e.parentElement}return null}})},"./qtext2/extension/smart_quotes.js":function(t,e,n){var i=n("./qtext2/extension/typing_change_base.js").TypingExtension,o=n("./qtext2/position.js").Position,r=n("./qtext2/selection.js").Selection,s=n("./shared/browser.js"),a=n("./qtext2/constants.js"),d=n("./settings.js");e.SmartQuotes=i.extend({install:function(){!s.ios&&d.networkOptions.enableSmartQuotes&&(this.initializeConstants(),this.doc.on("keypress",this.onKeypress.bind(this)),this.doc.on("command-space",this.onSpace.bind(this)))},onSpace:function(){if(this.isActive()){var t=this.doc.caret.start.previousWordBoundary(/\s/),e=t.charAfter(),n=this.doc.caret.start;if(null!==e&&t.atSpanEnd()&&(t=t.span.nextSibling().first()),e===a.OPEN_SINGLE_QUOTE){var i=this.doc.caret.previousTextUntil(t).slice(1);if(this.frontApostropheRegex.test(i)){var o=t.span.getText();t.span.setText(o.slice(0,t.offset)+a.CLOSE_SINGLE_QUOTE+o.slice(t.offset+1)),this.doc.moveCaret(n)}}}},onKeypress:function(t){if(this.isActive()){if("'"==t)return this.handleSingleQuote(),!1;if('"'==t)return this.handleDoubleQuote(),!1;if("S"==t.toUpperCase()&&this.doc.caret.start.charBefore()==a.SINGLE_PRIME){var e=this.doc.caret.start.prevPositionInSection();return this.doc.caret.start.span.parent.deleteText(e,this.doc.caret.start),e.span.insertText(a.CLOSE_SINGLE_QUOTE,e.offset),this.doc.moveCaret(e.nextPositionInSection()),void this.doc.updateSpellingSuggestions()}}},handleSingleQuote:function(){var t=this.doc.caret.charBefore(),e=a.CLOSE_SINGLE_QUOTE,n=this.doc.caret,i=n.start.span.parent,o=new r(i.first(),n.start);null===t||a.WORD_START_REGEX.test(t)?e=a.OPEN_SINGLE_QUOTE:this.primeRegex.test(t)&&(this.unclosedSingleQuoteRegex.test(o.getText())||(e=a.SINGLE_PRIME)),this.insertChar(e)},handleDoubleQuote:function(){var t=this.doc.caret.charBefore(),e=a.CLOSE_DOUBLE_QUOTE,n=this.doc.caret,i=n.start.span.parent,o=new r(i.first(),n.start);null===t||/\s|[({[]/.test(t)?e=a.OPEN_DOUBLE_QUOTE:this.primeRegex.test(t)&&(this.unclosedDoubleQuoteRegex.test(o.getText())||(e=a.DOUBLE_PRIME)),this.insertChar(e)},insertChar:function(t){var e=this.doc.caret.start,n=e.span,i=n.getText(),r=e.offset;n.setText(i.slice(0,r)+t+i.slice(r)),this.doc.moveCaret(new o(n,r+1))},initializeConstants:function(){var t=Object.keys(a.FRACTIONS).join("");this.primeRegex=new RegExp("\\d|["+t+"]");for(var e=["bout","cause","course","d","e_ll","em","er","ere","e_s","fraid","fro","kay","lo","m","n","n_","pon","round","sblood","scuse","sfar","sfoot","sup","t","taint","tain_t","til","tis","tisn_t","tshall","twas","twasn_t","tween","twere","tweren_t","twill","twixt","twon_t","twou_d","twou_dn_t","twould","twouldn_t","um","ve"],n="['‘’′]",i="",o=0;o<e.length;++o)i+="|"+e[o].replace(/_/g,n);this.frontApostropheRegex=new RegExp("^(\\d\\ds?"+i+")$","i"),this.unclosedSingleQuoteRegex=new RegExp(a.OPEN_SINGLE_QUOTE+"[^"+a.CLOSE_SINGLE_QUOTE+"]*$"),this.unclosedDoubleQuoteRegex=new RegExp(a.OPEN_DOUBLE_QUOTE+"[^"+a.CLOSE_DOUBLE_QUOTE+"]*$")}})},"./qtext2/extension/tooltips.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/util.js").Util,r=n("./qtext2/tooltip.js");e.Tooltips=i.extend({install:function(){this._activeLinkSpan=null,this.doc.on("caretMoved",this.onCaretMoved.bind(this)),this.doc.on("blur",this.onDocBlur.bind(this))},destroy:function(){this._hideTooltip()},onDocBlur:function(){this._hideTooltip()},onCaretMoved:function(){this._maybeShowTooltip()},_maybeShowTooltip:function(){this._shouldShowTooltip()?this._showTooltip():this._hideTooltip()},_shouldShowTooltip:function(){var t=this.doc.caret.start.span;return t.hasModifier("link")||t.hasModifier("citation")},_showTooltip:function(){var t,e,n=this.doc.caret.start.span;if(n.hasModifier("link")?e=n.getModifier("link"):n.hasModifier("citation")&&(t=n.getModifier("citation"),e=t.target),e&&e.url){this._activeLinkSpan=n;var i=o.create("a");i.target="_blank",i.rel="noreferrer nofollow",i.href=e.url,i.textContent=e.url,r.show(n.node,i,n.parent.node)}},_hideTooltip:function(){this._activeLinkSpan=null,r.hide()}})},"./qtext2/extension/typing_change_base.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension,o=n("./qtext2/sections/code.js").CodeSection;e.TypingExtension=i.extend({install:function(){},isActive:function(t){return t||(t=this.doc.caret.selection),!(t.start.span.parent instanceof o||t.getCoveringSpans().some(function(t){return t.hasModifier("code")||t.hasModifier("math")})||this.doc.formattingState.is("code")||this.doc.formattingState.is("math"))}})},"./qtext2/extension/undo_state.js":function(t,e,n){var i=n("./qtext2/extension/base.js").Extension;e.UndoState=i.extend({install:function(){this.doc.on("keypress",this.onKeypress.bind(this))},onKeypress:function(t){"."!=t&&","!=t||this.doc.saveState()}})},"./qtext2/extension/video_status.js":function(t,e,n){var i,o=n("./qtext2/extension/base.js").Extension,r=n("./settings.js"),s=n("./shared/client.js"),a=n("./qtext2/sections/video.js").VideoSection;e.VideoStatus=o.extend({install:function(){r.qtextData.videoEnabled&&(s.isNativeApp()?i.send("getExistingVideos",{},this.onExistingVideos.bind(this)):this.onExistingVideos({}))},onExistingVideos:function(t){var e={};(t.videos||[]).forEach(function(t){t.onDevice=!t.libraryVideo,delete t.libraryVideo,e[t.uuid]=t}),this.doc.children.forEach(function(t){if(t instanceof a){var n=e[t.getId()];n&&t.updateVideo(n)}})}})},"./qtext2/extensions.js":function(t,e,n){var i=n("./qtext2/extension/tooltips.js").Tooltips,o=n("./qtext2/extension/autolist.js").Autolist,r=n("./qtext2/extension/autolink.js").Autolink,s=n("./qtext2/extension/ellipses.js").Ellipses,a=n("./qtext2/extension/hr.js").HR,d=n("./qtext2/extension/undo_state.js").UndoState,c=n("./qtext2/extension/mention.js").Mention,h=n("./qtext2/extension/video_status.js").VideoStatus,l=n("./qtext2/extension/non_editable_cursors.js").NonEditableCursors,u=n("./qtext2/extension/smart_quotes.js").SmartQuotes,f=n("./qtext2/extension/double_space.js").DoubleSpace,p=n("./qtext2/extension/dashes.js").Dashes,g=n("./qtext2/extension/action_tracker.js").ActionTracker,m=n("./qtext2/extension/arrows.js").Arrows,v=n("./qtext2/extension/image_loading.js").ImageLoading,C=n("./qtext2/extension/external_image_upload.js").ExternalImageUpload;e.EXTENSIONS=[a,i,r,o,s,d,c,l,u,f,p,m,h,g,v,C]},"./qtext2/formatting_state.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=n("./qtext2/modifiers.js").canForceModifier,r=n("./shared/util.js");e.FormattingState=i.extend({__init__:function(t){this._modifiers={},this.update(t)},is:function(t){return t in this._modifiers},update:function(t){this.updatePosition(t);var e=t.getCoveringSpans(),n=Object.keys(t.start.span.getModifiers()).filter(function(t){return e.every(function(e){return e.hasModifier(t)||!o(e,t)})});this._modifiers={};var i=this;n.forEach(function(e){i._modifiers[e]=t.start.span.getModifier(e)}),this._isLinked()||(delete this._modifiers.link,delete this._modifiers.citation)},updatePosition:function(t){this.caret=t,this.position=t.start.clone(),this.spanText=t.start.span.getText()},_isLinked:function(){var t=this.caret.start.span;return!(!t.hasModifier("link")&&!t.hasModifier("citation"))&&(this.caret.isCollapsed()?!this.caret.start.atSpanStart()&&!this.caret.start.atSpanEnd():t==this.caret.end.span)},toggleModifier:function(t,e){e in this._modifiers?delete this._modifiers[e]:"link"!=e&&"citation"!=e&&(this._modifiers[e]=!0),this.position=t.start.clone()},hasChanged:function(t){return!r.jsonEqual(this._modifiers,t.start.span.getModifiers())&&this.spanText!=t.start.span.getText()},apply:function(t){var e=!r.jsonEqual(t.modifiers,this._modifiers);return t.removeAllModifiers(),t.updateModifiers(this._modifiers),e}})},"./qtext2/mutations.js":function(t,e,n){var i=n("./qtext2/base.js"),o=i.Doc,r=n("./qtext2/section.js"),s=r.Section,a=n("./qtext2/sections/plain.js").PlainSection,d=n("./qtext2/span.js").Span,c=n("./qtext2/position.js").Position,h=n("./qtext2/util.js").Util,l=n("./shared/util.js").extend,u=n("./shared/Class.js").Class,f=n("./shared/client.js"),p=function(){};e.MutationFixer=u.extend({__init__:function(t){this.doc=t;try{var e=n("./third_party/mutation-summary.js");this.mutationSummary=new e.MutationSummary({rootNode:t.node,observeOwnChanges:!1,queries:[{all:!0}],callback:this.handleMutationSummaries.bind(this)})}catch(t){p("Mutation summary initialization failed.")}},pause:function(){this.mutationSummary.disconnect()},resume:function(){this.mutationSummary.reconnect()},handleMutationSummaries:function(t){var e=t[0];p("Mutation summary",e),this.handleNodesAdded(e),this.handleNodesRemoved(e),this.handleNodeAttributeChanges(e),this.doc.hasBeenModified()&&this.doc.trigger("meaningfulChange")},handleNodesAdded:function(t){var e=t.added;if(e&&0!==e.length){var n=this;e.forEach(function(t){try{n._handleNodeAdded(t)}catch(t){p("Error while handling added node",t,t.stack)}})}},_handleNodeAdded:function(t){if(3==t.nodeType&&this.isQText2SpanContent(t.parentElement)&&!f.isIOSApp()&&(t.parentElement.normalize(),p("normalizing span content")),this.isValidQText2Node(t))return void p("Valid qtext2 node added",t);if(!t.parentElement)return void p("Node detached from a previous operation",t);if(!this.isValidQText2Node(t.parentElement))return p("Skipping invalid node added",t),void p("Processing node.parentElement instead",t.parentElement);p("Fixing invalid node added:",t,t.parentElement);var e;this.isQText2SpanContent(t.parentElement)?e=this._handleNodeAddedToSpanContent(t):this.isQText2Span(t.parentElement)?e=this._handleNodeAddedToSpan(t,this.getQText2Span(t.parentElement)):this.isQText2Container(t.parentElement)?e=this._handleNodeAddedToContainer(t,this.getQText2Container(t.parentElement)):p("Unhandled node.",t,t.parentElement),e&&this.doc.moveCaret(e)},_handleNodeAddedToSpanContent:function(t){var e,n,i,o,r,s=this.getQText2Span(t.parentElement.parentElement),a=this._getModifiersFromNode(t);if(this.nodeShouldBeSingleChild(t))return e=s.parent,n=s.previous(),i=n?n.last():s.next().first(),e.removeChild(s),i;for(e=s.parent,o=t.parentElement.childNodes[0],r=!0;o;)o==t?r=!1:e.insertBefore(new d(o.textContent,s.modifiers),r?s:s.nextSibling()),o=o.nextSibling;return s.setText(t.textContent),this._applyModifier(s,a),this.safeRemoveNodeFromDom(t),s.last()},_handleNodeAddedToSpan:function(t,e,n){n=l(this._getModifiersFromNode(t),n||{});for(var i=e.node.textContent,o=t,r=t.textContent.length;o.previousSibling;)o=o.previousSibling,r+=o.textContent.length;for(var s=Array.prototype.slice.call(e.node.childNodes),a=0;a<s.length;a++)s[a]!=e._content&&this.safeRemoveNodeFromDom(s[a]);return e._content||(e._content=e.createContentNode()),e.node!=e._content.parentElement&&e.node.appendChild(e._content),e.setText(i),this._applyModifier(e,n),new c(e,r)},_handleNodeAddedToContainer:function(t,e,n){n=l(this._getModifiersFromNode(t),n||{});var i,o,r,s,c=this.doc;if(e.hasChild(this.getQText2Container(t)))return void this._applyModifiersToContainer(this.getQText2Container(t),n);e.children.forEach(function(t){c.contains(t.node)||e.removeChild(t)}),h.isTextNode(t)?("section"==e.kind?o=i=new d(t.textContent,n):"doc"==e.kind&&(i=new d(t.textContent,n),o=new a([i])),this._replaceNodeWithContainer(t,o,e),s=o.last()):"BR"==t.nodeName&&("section"==e.kind?s=this._splitSectionAtNode(t,e):"doc"==e.kind&&(o=new a,this._replaceNodeWithContainer(t,o,e),s=o.first())),r=this._emptyNodeContents(t);for(var u=0;u<r.length;u++)s=this._handleNodeAddedToContainer(r[u],e,n);return s},_emptyNodeContents:function(t){for(var e=Array.prototype.slice.call(t.childNodes),n=0;n<e.length;n++)t.parentElement.insertBefore(e[n],t);return this.safeRemoveNodeFromDom(t),e},_splitSectionAtNode:function(t,e){var n,i;return n=this.getQText2Span(t.nextSibling),n&&(i=n.first()),n=this.getQText2Span(t.previousSibling),n&&(i=n.last()),this.safeRemoveNodeFromDom(t),i=i||e.last(),e.split(i)},_replaceNodeWithContainer:function(t,e,n){var i;return(i=this.getQText2Container(t.nextSibling,e.Class))?(n.insertBefore(e,i),void this.safeRemoveNodeFromDom(t)):(i=this.getQText2Container(t.previousSibling,e.Class))?(n.insertAfter(e,i),void this.safeRemoveNodeFromDom(t)):(n.appendChild(e),n.node.insertBefore(e.node,n.node.firstElementChild),void this.safeRemoveNodeFromDom(t))},safeRemoveNodeFromDom:function(t){t.parentElement&&h.safeRemoveChild(t,t.parentElement)},_getQText2ContainerType:function(t,e){return e.is(t)&&e.get(t)},isQText2SpanContent:function(t){return!!t.qtextSpanContent},getQText2Span:function(t){return this._getQText2ContainerType(t,d)},isQText2Span:function(t){return!!this.getQText2Span(t)},getQText2Section:function(t){return this._getQText2ContainerType(t,s)},isQText2Section:function(t){return!!this.getQText2Section(t)},getQText2Doc:function(t){return this._getQText2ContainerType(t,o)},isQText2Doc:function(t){return!!this.getQText2Doc(t)},isValidQText2Node:function(t){if(!t)return!1;if(this.isQText2Container(t))return!0;if(this.isQText2SpanContent(t))return!0;if(!t.parentElement)return!1;if(this.isQText2SpanContent(t.parentElement)){if(h.isTextNode(t))return!0;if(this.nodeShouldBeSingleChild(t)){var e=this.getQText2Span(t.parentElement.parentElement);return e&&1==e.parent.children.length}}return!1},nodeShouldBeSingleChild:function(t){return t&&("IMG"==t.nodeName||"BR"==t.nodeName||"IFRAME"==t.nodeName)},nodeCanBeStyled:function(t){return t&&"tweet-content"==t.className},getQText2Container:function(t){for(var e,n=[d,s,o],i=0;i<n.length&&!(e=this._getQText2ContainerType(t,n[i]));i++);return e},isQText2Container:function(t){return!!this.getQText2Container(t)},handleNodesRemoved:function(t){var e=t.removed;if(e&&0!==e.length){var n=this;e.forEach(function(e){try{n._handleNodeRemoved(e,t.getOldParentNode(e))}catch(t){p("Error while handling removed node",t,t.stack)}})}},_handleNodeRemoved:function(t,e){var n,i;if(d.is(e))n=d.get(e),i=n.parent,(this.doc.contains(e)||this.doc.hasChild(i)&&i.hasChild(n))&&(i.removeChild(n),0===i.children.length&&this.doc.removeChild(i));else if(s.is(e)){if(!(i=s.get(e)))return;d.is(t)&&(n=d.get(t),i.hasChild(n)&&i.removeChild(n)),0===i.children.length&&this.doc.removeChild(i)}else o.is(e)&&s.is(t)&&(i=s.get(t),this.doc.hasChild(i)&&this.doc.removeChild(i));this.doc.node.firstElementChild||(this.doc.clear(),this.doc.focus())},handleNodeAttributeChanges:function(t){var e=t.attributeChanged;e.style&&e.style.length&&e.style.forEach(this._handleNodeStyleAttributeChanged.bind(this))},_handleNodeStyleAttributeChanged:function(t){if(p("Fixing external node style changes:",t),this.nodeCanBeStyled(t))return void p("Skipping whitelisted node");var e=this._getModifiersFromNode(t);t.style.cssText="";var n=[];if(d.is(t))n.push(d.get(t));else if(d.is(t.parentElement))n.push(d.get(t.parentElement));else if(s.is(t))for(var i=s.get(t),o=i.firstChild();o;)n.push(o),o=o.nextSibling();this._applyModifiers(n,e)},_getModifiersFromNode:function(t){var e={};if(t.style){var n=t.style.cssText;n=n.replace(/\s|;/g,""),"font-weight:bold"==n?e.bold=!0:"font-weight:normal"==n?e.bold=!1:"text-decoration:none"==n?e.underline=!1:"text-decoration:underline"==n&&(e.underline=!1)}var i={B:"bold",STRONG:"bold",I:"italic",EM:"italic"}[t.nodeName];return i&&(e[i]=!0),e},_applyModifiers:function(t,e){var n=this;t.forEach(function(t){n._applyModifier(t,e)})},_applyModifiersToContainer:function(t,e){var n=[];"span"==t.kind?n=[t]:"section"==t.kind?n=t.children:"doc"==t.kind&&t.children.forEach(function(t){n.push.apply(n,t.children)}),this._applyModifiers(n,e)},_applyModifier:function(t,e){for(var n=Object.keys(e),i=0;i<n.length;i++){var o=n[i];e[o]?t.setModifier(o,!0):t.removeModifier(o)}}})},"./qtext2/parser.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=n("./qtext2/util.js").Util,r=n("./shared/util.js"),s=n("./qtext2/position.js").Position,a=n("./shared/parse_html.js").htmlToNode,d=n("./qtext2/span.js").Span,c=n("./qtext2/base.js"),h=c.Doc,l=n("./qtext2/constants.js").CONTENT_TYPES,u=n("./qtext2/sections/plain.js").PlainSection,f=n("./qtext2/sections/code.js").CodeSection,p=n("./qtext2/sections/lists.js").UnorderedListSection,g=n("./qtext2/sections/lists.js").OrderedListSection,m=n("./qtext2/sections/image.js").ImageSection,v=n("./qtext2/sections/horizontal_rule.js").HorizontalRuleSection,C=function(t){return-1!=["B","I","U","A","EM","STRONG","MATH","CODE"].indexOf(t)},S=function(t){return-1!=["OL","UL"].indexOf(t)},x=function(t){return-1!=["H1","H2","H3","H4","H5"].indexOf(t)},b=function(t){return"BLOCKQUOTE"==t},E=function(t){var e=["STYLE","LINK","SCRIPT","TITLE"];return t.nodeType==t.COMMENT_NODE||-1!=e.indexOf(t.nodeName)},_=i.extend({__init__:function(t,e){this.spans=e||[],this.modifiers=r.extend(t,{}),this.indent=0,this.content=""},visit:function(t){this._enter(t),this._exit(t)},_visitChildren:function(t){for(var e=t.firstChild;null!==e;e=e.nextSibling)this.visit(e)},_enter:function(t){if(o.isTextNode(t)){var e=t.textContent;return e=e.replace(/\n/g," "),e=e.replace(/ {2,}/g," "),void(this.content+=e)}if("BR"==t.nodeName.toUpperCase())return void(this.content+="\n");T(t)&&(this.modifiers[T(t)]=N(t)),this._visitChildren(t)},_exit:function(t){if(o.isTextNode(t)||"BR"==t.nodeName.toUpperCase())return void this._createSpan();T(t)&&delete this.modifiers[T(t)]},_createSpan:function(){var t=this.content;if(t.length){if(t=t.replace(/(\u00a0)+/gm," "),this.spans.length>0){var e=this.spans[this.spans.length-1];if(r.jsonEqual(e.modifiers,this.modifiers)){var n=e.getText();return e.setText(n+t),void(this.content="")}}this.spans.push(new d(t,this.modifiers)),this.content=""}}}),T=function(t){return{B:"bold",STRONG:"bold",I:"italic",EM:"italic",U:"italic",A:"link",CODE:"code",MATH:"math"}[t.nodeName.toUpperCase()]},N=function(t){return{B:!0,I:!0,EM:!0,U:!0,A:{type:"url",url:t.href},CODE:!0,MATH:!0}[t.nodeName.toUpperCase()]},y=function(t,e,n){var i=new _(e,n);return i.visit(t),i.spans},w=function(t,e,n){var i,r,s="OL"==t.nodeName.toUpperCase()?g:p,a=[];n=n||0,e=e||{},o.assert(S(t.nodeName),"Unknown list type",t);for(var d=t.firstElementChild;d;d=d.nextElementSibling)i=d.nodeName.toUpperCase(),"LI"==i?(r=new s(y(d,e)),r.setIndent(n),a.push(r)):S(i)&&(a=a.concat(w(d,e,n+1)));return a},R=function(t){var e,n,i=[],o=new f;for(i.push(o),n=t.firstChild;n;n=n.nextSibling)"BR"==n.nodeName.toUpperCase()?(o=new f,i.push(o)):(e=o.firstChild(),e.setText(e.getText()+n.textContent));return i},O=function(t,e,n,i){var a,d,c=new h({});e=e||{},n=n||[],i=!!i;for(var l=function(){if(n.length){var t=new u(n);if(/\S/.test(t.getText())){c.appendChild(t);for(var e=t.firstChild();e;){var i=e.getText(),o=i.indexOf("\n\n");-1!=o?(e.setText(i.replace("\n\n","")),e.parent.split(new s(e,o)),e=c.lastChild().firstChild()):e=e.nextSibling()}}n.length=[]}},f=t.firstChild;f;f=f.nextSibling)if("SPAN"==(a=f.nodeName.toUpperCase())&&0!==f.textContent.length||o.isTextNode(f)||"BR"==a)y(f,e,n);else if(C(a)){var p={};p[T(f)]=N(f),p=r.extend(p,e),c.appendChildren(O(f,p,n))}else l(),E(f)||(S(a)?c.appendChildren(w(f,e)):x(a)?c.appendChildren(O(f,r.extend({bold:!0},e),n,!0)):b(a)?(d=O(f,e,n,!0),d.forEach(function(t){t.setQuoted(!0)}),c.appendChildren(d)):"HR"==a?c.appendChild(new v):"PRE"==a?c.appendChildren(R(f)):"IMG"==a?o.isValidUrl(f.src)&&f.src.startsWith("http")&&c.appendChild(m.fromURL(f.src,"html_paste")):c.appendChildren(O(f,e,n,!0)));return i&&l(),c.destroy(),c.children.slice(1,c.children.length)},D=function(t){var e=a(t);return O(e,{},[],!0)},I=function(t){var e=[];return 0===t.length?[]:(o.splitLines(t).forEach(function(t){e.push(new u([new d(t)]))}),e)},A=function(t,e){return e==l.HTML||e==l.PUBLIC_HTML?D(t):e==l.TEXT||e==l.TEXT_URI?I(t):[]};e.parseHTML=D,e.parseText=I,e.parse=A},"./qtext2/selection.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=e.Selection=i.extend({__init__:function(t,e,n){this.start=t,this.end=e,this.doc=n},toJSON:function(){return{start:this.start.toJSON(),end:this.end.toJSON()}},equals:function(t){return this.start.equals(t.start)&&this.end.equals(t.end)},getStartNode:function(){return this.start.span.getFocusNode()},getEndNode:function(){return this.end.span.getFocusNode()},moveStart:function(t){this.start.span=t.span,this.start.offset=t.offset},moveEnd:function(t){this.end.span=t.span,this.end.offset=t.offset},isCollapsed:function(){return this.start.equals(this.end)},charBefore:function(){return this.start.charBefore()},hasCharBefore:function(){return this.start.hasCharBefore()},previousTextUntil:function(t){for(var e=this.start.span,n=this.start.offset,i="";e&&e!=t.span;)i=e.getText().substring(0,n)+i,(e=e.previousSibling())&&(n=e.getLength());return e&&(i=e.getText().substring(t.offset,n)+i),i},hasCharAfter:function(){return this.start.hasCharAfter()},charAfter:function(){return this.end.charAfter()},charPosition:function(){for(var t=this.start.offset,e=this.start.span.previousSibling();e;)t+=e.getLength(),e=e.previousSibling();for(var n=this.start.span.parent.previousSibling();n;)t+=n.getLength()+1,n=n.previousSibling();return t},containsEntireSection:function(t){var e,n=this.start,i=this.end;for(e=n.span.parent;e&&e.previousSibling()!=i.span.parent;){if(t==e&&(n.span.parent!=t||n.atSectionStart())&&(i.span.parent!=t||i.atSectionEnd()))return!0;e=e.nextSibling()}return!1},getCoveringSpans:function(){for(var t=this.start.span,e=[];t&&t!=this.end.span;)e.push(t),t=t.next();return e.push(t),e},getText:function(){var t="";if(this.start.span.parent!=this.end.span.parent){var e=this.start.span.parent,n=this.end.span.parent,i=new o(this.start,e.last()),r=new o(n.first(),this.end);t+=i.getText();for(var s=e.nextSibling();s&&s!=n;s=s.nextSibling())t+=s.getText();return t+=r.getText()}for(var a=this.start.span,d=this.start.offset;a&&a!=this.end.span;)t+=a.getText().substring(d,a.getLength()),d=0,a=a.nextSibling();return a&&(t+=a.getText().substring(d,this.end.offset)),t}})},"./qtext2/undo.js":function(t,e,n){var i=n("./shared/Class.js").Class,o=i.extend({__init__:function(t){this.current={state:t,next:null,prev:null}},state:function(){return this.current.state},add:function(t){this.current.next&&(this.current.next.prev=null),this.current.next={state:t,prev:this.current,next:null},this.current=this.current.next},undo:function(){this.current.prev&&(this.current=this.current.prev)},redo:function(){this.current.next&&(this.current=this.current.next)},canUndo:function(){return!!this.current.prev},canRedo:function(){return!!this.current.next}});e.UndoManager=o},"./shared/parse_html.js":function(t,e,n){var i=n("./shared/browser.js");e.htmlToNode=function(t){var e;if(i.msie&&i.version<9||!document.implementation||!document.implementation.createHTMLDocument)e=document.createElement("DIV");else{e=document.implementation.createHTMLDocument("title for old FF versions").createElement("DIV")}return e.innerHTML=t,e}},"./shared/rangy.js":function(t,e,n){var i,o=n("./gating.js");o.use_native_selection?i={getSelection:function(){return window.getSelection()},createRange:function(){return document.createRange()},init:function(){}}:(n("./third_party/rangy-core.js"),i=window.rangy),e.rangy=i,e.rangeFromPoint=function(t,e){var n,o,r,s,a;return document.caretPositionFromPoint?(n=document.caretPositionFromPoint(t,e),r=n.offsetNode,s=n.offset):document.caretRangeFromPoint?(o=document.caretRangeFromPoint(t,e),r=o.startContainer,s=o.startOffset):document.elementFromPoint&&(r=document.elementFromPoint(t,e),s=0),r&&s!==undefined?(a=i.createRange(),a.setStart(r,s),a.setEnd(r,s),a.collapse(!0),a):null}},"./third_party/mutation-summary.js":function(t,e){function n(t){return'"'+t.replace(/"/,'\\"')+'"'}function i(t){if("string"!=typeof t)throw Error("Invalid request opion. attribute must be a non-zero length string.");if(!(t=t.trim()))throw Error("Invalid request opion. attribute must be a non-zero length string.");if(!t.match(S))throw Error("Invalid request option. invalid attribute name: "+t);return t}function o(t){if(!t.trim().length)throw Error("Invalid request option: elementAttributes must contain at least one attribute.");for(var e={},n={},o=t.split(/\s+/),r=0;r<o.length;r++){var s=o[r];if(s){var s=i(s),a=s.toLowerCase();if(e[a])throw Error("Invalid request option: observing multiple case variations of the same attribute is not supported.");n[s]=!0,e[a]=!0}}return Object.keys(n)}function r(t){var e={};return t.forEach(function(t){t.qualifiers.forEach(function(t){e[t.attrName]=!0})}),Object.keys(e)}var s,a=this.__extends||function(t,e){function n(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);n.prototype=e.prototype,t.prototype=new n};if((s="undefined"!=typeof WebKitMutationObserver?WebKitMutationObserver:MutationObserver)===undefined)throw console.error("DOM Mutation Observers are required."),console.error("https://developer.mozilla.org/en-US/docs/DOM/MutationObserver"),Error("DOM Mutation Observers are required");var d,c=function(){function t(){this.nodes=[],this.values=[]}return t.prototype.isIndex=function(t){return+t==t>>>0},t.prototype.nodeId=function(e){var n=e[t.ID_PROP];return n||(n=e[t.ID_PROP]=t.nextId_++),n},t.prototype.set=function(t,e){var n=this.nodeId(t);this.nodes[n]=t,this.values[n]=e},t.prototype.get=function(t){var e=this.nodeId(t);return this.values[e]},t.prototype.has=function(t){return this.nodeId(t)in this.nodes},t.prototype["delete"]=function(t){var e=this.nodeId(t);delete this.nodes[e],this.values[e]=undefined},t.prototype.keys=function(){var t=[];for(var e in this.nodes)this.isIndex(e)&&t.push(this.nodes[e]);return t},t.ID_PROP="__mutation_summary_node_map_id__",t.nextId_=1,t}();!function(t){t[t.STAYED_OUT=0]="STAYED_OUT",t[t.ENTERED=1]="ENTERED",t[t.STAYED_IN=2]="STAYED_IN",t[t.REPARENTED=3]="REPARENTED",t[t.REORDERED=4]="REORDERED",t[t.EXITED=5]="EXITED"}(d||(d={}));var h=function(){function t(t,e,n,i,o,r,s,a){void 0===e&&(e=!1),void 0===n&&(n=!1),void 0===i&&(i=!1),void 0===o&&(o=null),void 0===r&&(r=!1),void 0===s&&(s=null),void 0===a&&(a=null),this.node=t,this.childList=e,this.attributes=n,this.characterData=i,this.oldParentNode=o,this.added=r,this.attributeOldValues=s,this.characterDataOldValue=a,this.isCaseInsensitive=this.node.nodeType===window.Node.ELEMENT_NODE&&this.node instanceof window.HTMLElement&&this.node.ownerDocument instanceof window.HTMLDocument}return t.prototype.getAttributeOldValue=function(t){return this.attributeOldValues?(this.isCaseInsensitive&&(t=t.toLowerCase()),this.attributeOldValues[t]):undefined},t.prototype.getAttributeNamesMutated=function(){var t=[];if(!this.attributeOldValues)return t;for(var e in this.attributeOldValues)t.push(e);return t},t.prototype.attributeMutated=function(t,e){this.attributes=!0,this.attributeOldValues=this.attributeOldValues||{},t in this.attributeOldValues||(this.attributeOldValues[t]=e)},t.prototype.characterDataMutated=function(t){this.characterData||(this.characterData=!0,this.characterDataOldValue=t)},t.prototype.removedFromParent=function(t){this.childList=!0,this.added||this.oldParentNode?this.added=!1:this.oldParentNode=t},t.prototype.insertedIntoParent=function(){this.childList=!0,this.added=!0},t.prototype.getOldParent=function(){if(this.childList){if(this.oldParentNode)return this.oldParentNode;if(this.added)return null}return this.node.parentNode},t}(),l=function(){function t(){this.added=new c,this.removed=new c,this.maybeMoved=new c,this.oldPrevious=new c,this.moved=undefined}return t}(),u=function(t){function e(e,n){t.call(this),this.rootNode=e,this.reachableCache=undefined,this.wasReachableCache=undefined,this.anyParentsChanged=!1,this.anyAttributesChanged=!1,this.anyCharacterDataChanged=!1;for(var i=0;i<n.length;i++){var o=n[i];switch(o.type){case"childList":this.anyParentsChanged=!0;for(var r=0;r<o.removedNodes.length;r++){var s=o.removedNodes[r];this.getChange(s).removedFromParent(o.target)}for(var r=0;r<o.addedNodes.length;r++){var s=o.addedNodes[r];this.getChange(s).insertedIntoParent()}break;case"attributes":this.anyAttributesChanged=!0;var a=this.getChange(o.target);a.attributeMutated(o.attributeName,o.oldValue);break;case"characterData":this.anyCharacterDataChanged=!0;var a=this.getChange(o.target);a.characterDataMutated(o.oldValue)}}}return a(e,t),e.prototype.getChange=function(t){var e=this.get(t);return e||(e=new h(t),this.set(t,e)),e},e.prototype.getOldParent=function(t){var e=this.get(t);return e?e.getOldParent():t.parentNode},e.prototype.getIsReachable=function(t){if(t===this.rootNode)return!0;if(!t)return!1;this.reachableCache=this.reachableCache||new c;var e=this.reachableCache.get(t);return e===undefined&&(e=this.getIsReachable(t.parentNode),this.reachableCache.set(t,e)),e},e.prototype.getWasReachable=function(t){if(t===this.rootNode)return!0;if(!t)return!1;this.wasReachableCache=this.wasReachableCache||new c;var e=this.wasReachableCache.get(t);return e===undefined&&(e=this.getWasReachable(this.getOldParent(t)),this.wasReachableCache.set(t,e)),e},e.prototype.reachabilityChange=function(t){return this.getIsReachable(t)?this.getWasReachable(t)?d.STAYED_IN:d.ENTERED:this.getWasReachable(t)?d.EXITED:d.STAYED_OUT},e}(c),f=function(){function t(t,e,n,i,o){this.rootNode=t,this.mutations=e,this.selectors=n,this.calcReordered=i,this.calcOldPreviousSibling=o,this.treeChanges=new u(t,e),this.entered=[],this.exited=[],this.stayedIn=new c,this.visited=new c,this.childListChangeMap=undefined,this.characterDataOnly=undefined,this.matchCache=undefined,this.processMutations()}return t.prototype.processMutations=function(){if(this.treeChanges.anyParentsChanged||this.treeChanges.anyAttributesChanged)for(var t=this.treeChanges.keys(),e=0;e<t.length;e++)this.visitNode(t[e],undefined)},t.prototype.visitNode=function(t,e){if(!this.visited.has(t)){this.visited.set(t,!0);var n=this.treeChanges.get(t),i=e;if((n&&n.childList||i==undefined)&&(i=this.treeChanges.reachabilityChange(t)),i!==d.STAYED_OUT){if(this.matchabilityChange(t),i===d.ENTERED)this.entered.push(t);else if(i===d.EXITED)this.exited.push(t),this.ensureHasOldPreviousSiblingIfNeeded(t);else if(i===d.STAYED_IN){var o=d.STAYED_IN;n&&n.childList&&(n.oldParentNode!==t.parentNode?(o=d.REPARENTED,this.ensureHasOldPreviousSiblingIfNeeded(t)):this.calcReordered&&this.wasReordered(t)&&(o=d.REORDERED)),this.stayedIn.set(t,o)}if(i!==d.STAYED_IN)for(var r=t.firstChild;r;r=r.nextSibling)this.visitNode(r,i)}}},t.prototype.ensureHasOldPreviousSiblingIfNeeded=function(t){if(this.calcOldPreviousSibling){this.processChildlistChanges();var e=t.parentNode,n=this.treeChanges.get(t);n&&n.oldParentNode&&(e=n.oldParentNode);var i=this.childListChangeMap.get(e);i||(i=new l,this.childListChangeMap.set(e,i)),i.oldPrevious.has(t)||i.oldPrevious.set(t,t.previousSibling)}},t.prototype.getChanged=function(t,e,n){this.selectors=e,this.characterDataOnly=n;for(var i=0;i<this.entered.length;i++){var o=this.entered[i],r=this.matchabilityChange(o);r!==d.ENTERED&&r!==d.STAYED_IN||t.added.push(o)}for(var s=this.stayedIn.keys(),i=0;i<s.length;i++){var o=s[i],r=this.matchabilityChange(o);if(r===d.ENTERED)t.added.push(o);else if(r===d.EXITED)t.removed.push(o);else if(r===d.STAYED_IN&&(t.reparented||t.reordered)){var a=this.stayedIn.get(o);t.reparented&&a===d.REPARENTED?t.reparented.push(o):t.reordered&&a===d.REORDERED&&t.reordered.push(o)}}for(var i=0;i<this.exited.length;i++){var o=this.exited[i],r=this.matchabilityChange(o);r!==d.EXITED&&r!==d.STAYED_IN||t.removed.push(o)}},t.prototype.getOldParentNode=function(t){var e=this.treeChanges.get(t);if(e&&e.childList)return e.oldParentNode?e.oldParentNode:null;var n=this.treeChanges.reachabilityChange(t);if(n===d.STAYED_OUT||n===d.ENTERED)throw Error("getOldParentNode requested on invalid node.");return t.parentNode},t.prototype.getOldPreviousSibling=function(t){var e=t.parentNode,n=this.treeChanges.get(t);n&&n.oldParentNode&&(e=n.oldParentNode);var i=this.childListChangeMap.get(e);if(!i)throw Error("getOldPreviousSibling requested on invalid node.");return i.oldPrevious.get(t)},t.prototype.getOldAttribute=function(t,e){var n=this.treeChanges.get(t);if(!n||!n.attributes)throw Error("getOldAttribute requested on invalid node.");var i=n.getAttributeOldValue(e);if(i===undefined)throw Error("getOldAttribute requested for unchanged attribute name.");return i},t.prototype.attributeChangedNodes=function(t){if(!this.treeChanges.anyAttributesChanged)return{};var e,n;if(t){e={},n={};for(var i=0;i<t.length;i++){var o=t[i];e[o]=!0,n[o.toLowerCase()]=o}}for(var r={},s=this.treeChanges.keys(),i=0;i<s.length;i++){var a=s[i],c=this.treeChanges.get(a);if(c.attributes&&(d.STAYED_IN===this.treeChanges.reachabilityChange(a)&&d.STAYED_IN===this.matchabilityChange(a)))for(var h=a,l=c.getAttributeNamesMutated(),u=0;u<l.length;u++){var o=l[u];if(!e||e[o]||c.isCaseInsensitive&&n[o]){var f=c.getAttributeOldValue(o);f!==h.getAttribute(o)&&(n&&c.isCaseInsensitive&&(o=n[o]),r[o]=r[o]||[],r[o].push(h))}}}return r},t.prototype.getOldCharacterData=function(t){var e=this.treeChanges.get(t);if(!e||!e.characterData)throw Error("getOldCharacterData requested on invalid node.");return e.characterDataOldValue},t.prototype.getCharacterDataChanged=function(){if(!this.treeChanges.anyCharacterDataChanged)return[];for(var t=this.treeChanges.keys(),e=[],n=0;n<t.length;n++){var i=t[n];if(d.STAYED_IN===this.treeChanges.reachabilityChange(i)){var o=this.treeChanges.get(i);o.characterData&&i.textContent!=o.characterDataOldValue&&e.push(i)}}return e},t.prototype.computeMatchabilityChange=function(t,e){this.matchCache||(this.matchCache=[]),this.matchCache[t.uid]||(this.matchCache[t.uid]=new c);var n=this.matchCache[t.uid],i=n.get(e);return i===undefined&&(i=t.matchabilityChange(e,this.treeChanges.get(e)),n.set(e,i)),i},t.prototype.matchabilityChange=function(t){var e=this;if(this.characterDataOnly)switch(t.nodeType){case Node.COMMENT_NODE:case Node.TEXT_NODE:return d.STAYED_IN;default:return d.STAYED_OUT}if(!this.selectors)return d.STAYED_IN;if(t.nodeType!==Node.ELEMENT_NODE)return d.STAYED_OUT;for(var n=t,i=this.selectors.map(function(t){return e.computeMatchabilityChange(t,n)}),o=d.STAYED_OUT,r=0;o!==d.STAYED_IN&&r<i.length;){switch(i[r]){case d.STAYED_IN:o=d.STAYED_IN;break;case d.ENTERED:o=o===d.EXITED?d.STAYED_IN:d.ENTERED;break;case d.EXITED:o=o===d.ENTERED?d.STAYED_IN:d.EXITED}r++}return o},t.prototype.getChildlistChange=function(t){var e=this.childListChangeMap.get(t);return e||(e=new l,this.childListChangeMap.set(t,e)),e},t.prototype.processChildlistChanges=function(){function t(t,e){!t||i.oldPrevious.has(t)||i.added.has(t)||i.maybeMoved.has(t)||e&&(i.added.has(e)||i.maybeMoved.has(e))||i.oldPrevious.set(t,e)}if(!this.childListChangeMap){this.childListChangeMap=new c;for(var e=0;e<this.mutations.length;e++){var n=this.mutations[e];if("childList"==n.type&&(this.treeChanges.reachabilityChange(n.target)===d.STAYED_IN||this.calcOldPreviousSibling)){for(var i=this.getChildlistChange(n.target),o=n.previousSibling,r=0;r<n.removedNodes.length;r++){var s=n.removedNodes[r];t(s,o),i.added.has(s)?i.added["delete"](s):(i.removed.set(s,!0),i.maybeMoved["delete"](s)),o=s}t(n.nextSibling,o);for(var r=0;r<n.addedNodes.length;r++){var s=n.addedNodes[r];i.removed.has(s)?(i.removed["delete"](s),i.maybeMoved.set(s,!0)):i.added.set(s,!0)}}}}},t.prototype.wasReordered=function(t){function e(t){if(!t)return!1;if(!s.maybeMoved.has(t))return!1;var e=s.moved.get(t);return e!==undefined?e:(a.has(t)?e=!0:(a.set(t,!0),e=i(t)!==n(t)),a.has(t)?(a["delete"](t),s.moved.set(t,e)):e=s.moved.get(t),e)}function n(t){var i=d.get(t);if(i!==undefined)return i;for(i=s.oldPrevious.get(t);i&&(s.removed.has(i)||e(i));)i=n(i);return i===undefined&&(i=t.previousSibling),d.set(t,i),i}function i(t){if(h.has(t))return h.get(t);for(var n=t.previousSibling;n&&(s.added.has(n)||e(n));)n=n.previousSibling;return h.set(t,n),n}if(!this.treeChanges.anyParentsChanged)return!1;this.processChildlistChanges();var o=t.parentNode,r=this.treeChanges.get(t);r&&r.oldParentNode&&(o=r.oldParentNode);var s=this.childListChangeMap.get(o);if(!s)return!1;if(s.moved)return s.moved.get(t);s.moved=new c;var a=new c,d=new c,h=new c;return s.maybeMoved.keys().forEach(e),s.moved.get(t)},t}(),p=function(){function t(t,e){var n=this;if(this.projection=t,this.added=[],this.removed=[],this.reparented=e.all||e.element||e.characterData?[]:undefined,this.reordered=e.all?[]:undefined,t.getChanged(this,e.elementFilter,e.characterData),e.all||e.attribute||e.attributeList){var i=e.attribute?[e.attribute]:e.attributeList,o=t.attributeChangedNodes(i);e.attribute?this.valueChanged=o[e.attribute]||[]:(this.attributeChanged=o,e.attributeList&&e.attributeList.forEach(function(t){n.attributeChanged.hasOwnProperty(t)||(n.attributeChanged[t]=[])}))}if(e.all||e.characterData){var r=t.getCharacterDataChanged();e.characterData?this.valueChanged=r:this.characterDataChanged=r}this.reordered&&(this.getOldPreviousSibling=t.getOldPreviousSibling.bind(t))}return t.prototype.getOldParentNode=function(t){return this.projection.getOldParentNode(t)},t.prototype.getOldAttribute=function(t,e){return this.projection.getOldAttribute(t,e)},t.prototype.getOldCharacterData=function(t){return this.projection.getOldCharacterData(t)},t.prototype.getOldPreviousSibling=function(t){return this.projection.getOldPreviousSibling(t)},t}(),g=/[a-zA-Z_]+/,m=/[a-zA-Z0-9_\-]+/,v=function(){function t(){}return t.prototype.matches=function(t){if(null===t)return!1;if(this.attrValue===undefined)return!0;if(!this.contains)return this.attrValue==t;for(var e=t.split(" "),n=0;n<e.length;n++)if(this.attrValue===e[n])return!0;return!1},t.prototype.toString=function(){return"class"===this.attrName&&this.contains?"."+this.attrValue:"id"!==this.attrName||this.contains?this.contains?"["+this.attrName+"~="+n(this.attrValue)+"]":"attrValue"in this?"["+this.attrName+"="+n(this.attrValue)+"]":"["+this.attrName+"]":"#"+this.attrValue},t}(),C=function(){function t(){this.uid=t.nextUid++,this.qualifiers=[]}return Object.defineProperty(t.prototype,"caseInsensitiveTagName",{get:function(){return this.tagName.toUpperCase()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selectorString",{get:function(){return this.tagName+this.qualifiers.join("")},enumerable:!0,configurable:!0}),t.prototype.isMatching=function(e){return e[t.matchesSelector](this.selectorString)},t.prototype.wasMatching=function(t,e,n){if(!e||!e.attributes)return n;var i=e.isCaseInsensitive?this.caseInsensitiveTagName:this.tagName;if("*"!==i&&i!==t.tagName)return!1;for(var o=[],r=!1,s=0;s<this.qualifiers.length;s++){var a=this.qualifiers[s],d=e.getAttributeOldValue(a.attrName);o.push(d),r=r||d!==undefined}if(!r)return n;for(var s=0;s<this.qualifiers.length;s++){var a=this.qualifiers[s],d=o[s];if(d===undefined&&(d=t.getAttribute(a.attrName)),!a.matches(d))return!1}return!0},t.prototype.matchabilityChange=function(t,e){var n=this.isMatching(t);return n?this.wasMatching(t,e,n)?d.STAYED_IN:d.ENTERED:this.wasMatching(t,e,n)?d.EXITED:d.STAYED_OUT},t.parseSelectors=function(e){function n(){o&&(r&&(o.qualifiers.push(r),r=undefined),a.push(o)),o=new t}function i(){r&&o.qualifiers.push(r),r=new v}for(var o,r,s,a=[],d=/\s/,c="Invalid or unsupported selector syntax.",h=1,l=2,u=3,f=4,p=5,C=6,S=7,x=8,b=9,E=10,_=11,T=12,N=13,y=14,w=h,R=0;R<e.length;){var O=e[R++];switch(w){case h:if(O.match(g)){n(),o.tagName=O,w=l;break}if("*"==O){n(),o.tagName="*",w=u;break}if("."==O){n(),i(),o.tagName="*",r.attrName="class",r.contains=!0,w=f;break}if("#"==O){n(),i(),o.tagName="*",r.attrName="id",w=f;break}if("["==O){n(),i(),o.tagName="*",r.attrName="",w=C;break}if(O.match(d))break;throw Error(c);case l:if(O.match(m)){o.tagName+=O;break}if("."==O){i(),r.attrName="class",r.contains=!0,w=f;break}if("#"==O){i(),r.attrName="id",w=f;break}if("["==O){i(),r.attrName="",w=C;break}if(O.match(d)){w=y;break}if(","==O){w=h;break}throw Error(c);case u:if("."==O){i(),r.attrName="class",r.contains=!0,w=f;break}if("#"==O){i(),r.attrName="id",w=f;break}if("["==O){i(),r.attrName="",w=C;break}if(O.match(d)){w=y;break}if(","==O){w=h;break}throw Error(c);case f:if(O.match(g)){r.attrValue=O,w=p;break}throw Error(c);case p:if(O.match(m)){r.attrValue+=O;break}if("."==O){i(),r.attrName="class",r.contains=!0,w=f;break}if("#"==O){i(),r.attrName="id",w=f;break}if("["==O){i(),w=C;break}if(O.match(d)){w=y;break}if(","==O){w=h;break}throw Error(c);case C:if(O.match(g)){r.attrName=O,w=S;break}if(O.match(d))break;throw Error(c);case S:if(O.match(m)){r.attrName+=O;break}if(O.match(d)){w=x;break}if("~"==O){r.contains=!0,w=b;break}if("="==O){r.attrValue="",w=_;break}if("]"==O){w=u;break}throw Error(c);case x:if("~"==O){r.contains=!0,w=b;break}if("="==O){r.attrValue="",w=_;break}if("]"==O){w=u;break}if(O.match(d))break;throw Error(c);case b:if("="==O){r.attrValue="",w=_;break}throw Error(c);case E:if("]"==O){w=u;break}if(O.match(d))break;throw Error(c);case _:if(O.match(d))break;if('"'==O||"'"==O){s=O,w=N;break}r.attrValue+=O,w=T;break;case T:if(O.match(d)){w=E;break}if("]"==O){w=u;break}if("'"==O||'"'==O)throw Error(c);r.attrValue+=O;break;case N:if(O==s){w=E;break}r.attrValue+=O;break;case y:if(O.match(d))break;if(","==O){w=h;break}throw Error(c)}}switch(w){case h:case l:case u:case p:case y:n();break;default:throw Error(c)}if(!a.length)throw Error(c);return a},t.nextUid=1,t.matchesSelector=function(){var t=document.createElement("div");return"function"==typeof t.webkitMatchesSelector?"webkitMatchesSelector":"function"==typeof t.mozMatchesSelector?"mozMatchesSelector":"function"==typeof t.msMatchesSelector?"msMatchesSelector":"matchesSelector"}(),t}(),S=/^([a-zA-Z:_]+[a-zA-Z0-9_\-:\.]*)$/,x=function(){function t(e){var n=this;this.connected=!1,this.options=t.validateOptions(e),this.observerOptions=t.createObserverOptions(this.options.queries),this.root=this.options.rootNode,this.callback=this.options.callback,this.elementFilter=Array.prototype.concat.apply([],this.options.queries.map(function(t){return t.elementFilter?t.elementFilter:[]})),this.elementFilter.length||(this.elementFilter=undefined),this.calcReordered=this.options.queries.some(function(t){return t.all}),this.queryValidators=[],t.createQueryValidator&&(this.queryValidators=this.options.queries.map(function(e){return t.createQueryValidator(n.root,e)})),this.observer=new s(function(t){n.observerCallback(t)}),this.reconnect()}return t.createObserverOptions=function(t){function e(t){if(!i.attributes||n){if(i.attributes=!0,i.attributeOldValue=!0,!t)return void(n=undefined);n=n||{},t.forEach(function(t){n[t]=!0,n[t.toLowerCase()]=!0})}}var n,i={childList:!0,subtree:!0};return t.forEach(function(t){if(t.characterData)return i.characterData=!0,void(i.characterDataOldValue=!0);if(t.all)return e(),i.characterData=!0,void(i.characterDataOldValue=!0);if(t.attribute)return void e([t.attribute.trim()]);var n=r(t.elementFilter).concat(t.attributeList||[]);n.length&&e(n)}),n&&(i.attributeFilter=Object.keys(n)),i},t.validateOptions=function(e){for(var n in e)if(!(n in t.optionKeys))throw Error("Invalid option: "+n);if("function"!=typeof e.callback)throw Error("Invalid options: callback is required and must be a function");if(!e.queries||!e.queries.length)throw Error("Invalid options: queries must contain at least one query request object.");for(var r={callback:e.callback,rootNode:e.rootNode||document,observeOwnChanges:!!e.observeOwnChanges,oldPreviousSibling:!!e.oldPreviousSibling,queries:[]},s=0;s<e.queries.length;s++){var a=e.queries[s];if(a.all){if(Object.keys(a).length>1)throw Error("Invalid request option. all has no options.");r.queries.push({all:!0})}else if("attribute"in a){var d={attribute:i(a.attribute)};if(d.elementFilter=C.parseSelectors("*["+d.attribute+"]"),Object.keys(a).length>1)throw Error("Invalid request option. attribute has no options.");r.queries.push(d)}else if("element"in a){var c=Object.keys(a).length,d={element:a.element,elementFilter:C.parseSelectors(a.element)};if(a.hasOwnProperty("elementAttributes")&&(d.attributeList=o(a.elementAttributes),c--),c>1)throw Error("Invalid request option. element only allows elementAttributes option.");r.queries.push(d)}else{if(!a.characterData)throw Error("Invalid request option. Unknown query request.");if(Object.keys(a).length>1)throw Error("Invalid request option. characterData has no options.");r.queries.push({characterData:!0})}}return r},t.prototype.createSummaries=function(t){if(!t||!t.length)return[];for(var e=new f(this.root,t,this.elementFilter,this.calcReordered,this.options.oldPreviousSibling),n=[],i=0;i<this.options.queries.length;i++)n.push(new p(e,this.options.queries[i]));return n},t.prototype.checkpointQueryValidators=function(){this.queryValidators.forEach(function(t){t&&t.recordPreviousState()})},t.prototype.runQueryValidators=function(t){this.queryValidators.forEach(function(e,n){e&&e.validate(t[n])})},t.prototype.changesToReport=function(t){return t.some(function(t){if(["added","removed","reordered","reparented","valueChanged","characterDataChanged"].some(function(e){return t[e]&&t[e].length}))return!0;if(t.attributeChanged){if(Object.keys(t.attributeChanged).some(function(e){return!!t.attributeChanged[e].length}))return!0}return!1})},t.prototype.observerCallback=function(t){this.options.observeOwnChanges||this.observer.disconnect();var e=this.createSummaries(t);this.runQueryValidators(e),this.options.observeOwnChanges&&this.checkpointQueryValidators(),this.changesToReport(e)&&this.callback(e),!this.options.observeOwnChanges&&this.connected&&(this.checkpointQueryValidators(),this.observer.observe(this.root,this.observerOptions))},t.prototype.reconnect=function(){if(this.connected)throw Error("Already connected");this.observer.observe(this.root,this.observerOptions),this.connected=!0,this.checkpointQueryValidators()},t.prototype.takeSummaries=function(){if(!this.connected)throw Error("Not connected");var t=this.createSummaries(this.observer.takeRecords());return this.changesToReport(t)?t:undefined},t.prototype.disconnect=function(){var t=this.takeSummaries();return this.observer.disconnect(),this.connected=!1,t},t.NodeMap=c,t.parseElementFilter=C.parseSelectors,t.optionKeys={callback:!0,queries:!0,rootNode:!0,oldPreviousSibling:!0,observeOwnChanges:!0},t}();e.MutationSummary=x},"./third_party/rangy-core.js":function(t,e){/**
 * @license Rangy, a cross-browser JavaScript range and selection library
 * http://code.google.com/p/rangy/
 *
 * Copyright 2012, Tim Down
 * Licensed under the MIT license.
 * Version: 1.2.3
 * Build date: 26 February 2012
 */
window.rangy=function(){function t(t,e){var n=typeof t[e];return n==l||!(n!=h||!t[e])||"unknown"==n}function e(t,e){return!(typeof t[e]!=h||!t[e])}function n(t,e){return typeof t[e]!=u}function i(t){return function(e,n){for(var i=n.length;i--;)if(!t(e,n[i]))return!1;return!0}}function o(t){return t&&v(t,m)&&S(t,g)}function r(t){window.alert("Rangy not supported in your browser. Reason: "+t),x.initialized=!0,x.supported=!1}function s(t){var e="Rangy warning: "+t;x.config.alertOnWarn?window.alert(e):typeof window.console!=u&&typeof window.console.log!=u&&window.console.log(e)}function a(){if(!x.initialized){var n,i=!1,s=!1;t(document,"createRange")&&(n=document.createRange(),v(n,p)&&S(n,f)&&(i=!0),n.detach());var a=e(document,"body")?document.body:document.getElementsByTagName("body")[0];a&&t(a,"createTextRange")&&(n=a.createTextRange(),o(n)&&(s=!0)),i||s||r("Neither Range nor TextRange are implemented"),x.initialized=!0,x.features={implementsDomRange:i,implementsTextRange:s};for(var d=E.concat(b),c=0,h=d.length;c<h;++c)try{d[c](x)}catch(n){e(window,"console")&&t(window.console,"log")&&window.console.log("Init listener threw an exception. Continuing.",n)}}}function d(t){t=t||window,a();for(var e=0,n=_.length;e<n;++e)_[e](t)}function c(t){this.name=t,this.initialized=!1,this.supported=!1}var h="object",l="function",u="undefined",f=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer","START_TO_START","START_TO_END","END_TO_START","END_TO_END"],p=["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"],m=["collapse","compareEndPoints","duplicate","getBookmark","moveToBookmark","moveToElementText","parentElement","pasteHTML","select","setEndPoint","getBoundingClientRect"],v=i(t),C=i(e),S=i(n),x={version:"1.2.3",initialized:!1,supported:!0,util:{isHostMethod:t,isHostObject:e,isHostProperty:n,areHostMethods:v,areHostObjects:C,areHostProperties:S,isTextRange:o},features:{},modules:{},config:{alertOnWarn:!1,preferTextRange:!1}};x.fail=r,x.warn=s,!{}.hasOwnProperty?r("hasOwnProperty not supported"):x.util.extend=function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};var b=[],E=[];x.init=a,x.addInitListener=function(t){x.initialized?t(x):b.push(t)};var _=[];x.addCreateMissingNativeApiListener=function(t){_.push(t)},x.createMissingNativeApi=d,c.prototype.fail=function(t){throw this.initialized=!0,this.supported=!1,new Error("Module '"+this.name+"' failed to load: "+t)},c.prototype.warn=function(t){x.warn("Module "+this.name+": "+t)},c.prototype.createError=function(t){return new Error("Error in Rangy "+this.name+" module: "+t)},x.createModule=function(t,e){var n=new c(t);x.modules[t]=n,E.push(function(t){e(t,n),n.initialized=!0,n.supported=!0})},x.requireModules=function(t){for(var e,n,i=0,o=t.length;i<o;++i){if(n=t[i],!((e=x.modules[n])&&e instanceof c))throw new Error("Module '"+n+"' not found");if(!e.supported)throw new Error("Module '"+n+"' not supported")}};var T=!1,N=function(t){T||(T=!0,x.initialized||a())};return typeof window==u?void r("No window found"):typeof document==u?void r("No document found"):(t(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",N,!1),t(window,"addEventListener")?window.addEventListener("load",N,!1):t(window,"attachEvent")?window.attachEvent("onload",N):r("Window does not have required addEventListener or attachEvent method"),x)}(),rangy.createModule("DomUtil",function(t,e){function n(t){var e;return typeof t.namespaceURI==N||null===(e=t.namespaceURI)||"http://www.w3.org/1999/xhtml"==e}function i(t){var e=t.parentNode;return 1==e.nodeType?e:null}function o(t){for(var e=0;t=t.previousSibling;)e++;return e}function r(t){var e;return c(t)?t.length:(e=t.childNodes)?e.length:0}function s(t,e){var n,i=[];for(n=t;n;n=n.parentNode)i.push(n);for(n=e;n;n=n.parentNode)if(O(i,n))return n;return null}function a(t,e,n){for(var i=n?e:e.parentNode;i;){if(i===t)return!0;i=i.parentNode}return!1}function d(t,e,n){for(var i,o=n?t:t.parentNode;o;){if((i=o.parentNode)===e)return o;o=i}return null}function c(t){var e=t.nodeType;return 3==e||4==e||8==e}function h(t,e){var n=e.nextSibling,i=e.parentNode;return n?i.insertBefore(t,n):i.appendChild(t),t}function l(t,e){var n=t.cloneNode(!1);return n.deleteData(0,e),t.deleteData(e,t.length-e),h(n,t),n}function u(t){if(9==t.nodeType)return t;if(typeof t.ownerDocument!=N)return t.ownerDocument;if(typeof t.document!=N)return t.document;if(t.parentNode)return u(t.parentNode);throw new Error("getDocument: no document found for node")}function f(t){var e=u(t);if(typeof e.defaultView!=N)return e.defaultView;if(typeof e.parentWindow!=N)return e.parentWindow;throw new Error("Cannot get a window object for node")}function p(t){if(typeof t.contentDocument!=N)return t.contentDocument;if(typeof t.contentWindow!=N)return t.contentWindow.document;throw new Error("getIframeWindow: No Document object found for iframe element")}function g(t){if(typeof t.contentWindow!=N)return t.contentWindow;if(typeof t.contentDocument!=N)return t.contentDocument.defaultView;throw new Error("getIframeWindow: No Window object found for iframe element")}function m(t){return y.isHostObject(t,"body")?t.body:t.getElementsByTagName("body")[0]}function v(t){for(var e;e=t.parentNode;)t=e;return t}function C(t,e,n,i){var r,a,c,h,l;if(t==n)return e===i?0:e<i?-1:1;if(r=d(n,t,!0))return e<=o(r)?-1:1;if(r=d(t,n,!0))return o(r)<i?-1:1;if(a=s(t,n),c=t===a?a:d(t,a,!0),h=n===a?a:d(n,a,!0),c===h)throw new Error("comparePoints got to case 4 and childA and childB are the same!");for(l=a.firstChild;l;){if(l===c)return-1;if(l===h)return 1;l=l.nextSibling}throw new Error("Should not be here!")}function S(t){for(var e,n=u(t).createDocumentFragment();e=t.firstChild;)n.appendChild(e);return n}function x(t){if(!t)return"[No node]";if(c(t))return'"'+t.data+'"';if(1==t.nodeType){var e=t.id?' id="'+t.id+'"':"";return"<"+t.nodeName+e+">["+t.childNodes.length+"]"}return t.nodeName}function b(t){this.root=t,this._next=t}function E(t){return new b(t)}function _(t,e){this.node=t,this.offset=e}function T(t){this.code=this[t],this.codeName=t,this.message="DOMException: "+this.codeName}var N="undefined",y=t.util;y.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||e.fail("document missing a Node creation method"),y.isHostMethod(document,"getElementsByTagName")||e.fail("document missing getElementsByTagName method");var w=document.createElement("div");y.areHostMethods(w,["insertBefore","appendChild","cloneNode"]||!y.areHostObjects(w,["previousSibling","nextSibling","childNodes","parentNode"]))||e.fail("Incomplete Element implementation"),y.isHostProperty(w,"innerHTML")||e.fail("Element is missing innerHTML property");var R=document.createTextNode("test");y.areHostMethods(R,["splitText","deleteData","insertData","appendData","cloneNode"]||!y.areHostObjects(w,["previousSibling","nextSibling","childNodes","parentNode"])||!y.areHostProperties(R,["data"]))||e.fail("Incomplete Text Node implementation");var O=function(t,e){for(var n=t.length;n--;)if(t[n]===e)return!0;return!1};b.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var t,e,n=this._current=this._next;if(this._current)if(t=n.firstChild)this._next=t;else{for(e=null;n!==this.root&&!(e=n.nextSibling);)n=n.parentNode;this._next=e}return this._current},detach:function(){this._current=this._next=this.root=null}},_.prototype={equals:function(t){return this.node===t.node&this.offset==t.offset},inspect:function(){return"[DomPosition("+x(this.node)+":"+this.offset+")]"}},T.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},T.prototype.toString=function(){return this.message},t.dom={arrayContains:O,isHtmlNamespace:n,parentElement:i,getNodeIndex:o,getNodeLength:r,getCommonAncestor:s,isAncestorOf:a,getClosestAncestorIn:d,isCharacterDataNode:c,insertAfter:h,splitDataNode:l,getDocument:u,getWindow:f,getIframeWindow:g,getIframeDocument:p,getBody:m,getRootContainer:v,comparePoints:C,inspectNode:x,fragmentFromNodeChildren:S,createIterator:E,DomPosition:_},t.DOMException=T}),rangy.createModule("DomRange",function(t,e){function n(t,e){return 3!=t.nodeType&&(L.isAncestorOf(t,e.startContainer,!0)||L.isAncestorOf(t,e.endContainer,!0))}function i(t){return L.getDocument(t.startContainer)}function o(t,e,n){var i=t._listeners[e];if(i)for(var o=0,r=i.length;o<r;++o)i[o].call(t,{target:t,args:n})}function r(t){return new U(t.parentNode,L.getNodeIndex(t))}function s(t){return new U(t.parentNode,L.getNodeIndex(t)+1)}function a(t,e,n){var i=11==t.nodeType?t.firstChild:t;return L.isCharacterDataNode(e)?n==e.length?L.insertAfter(t,e):e.parentNode.insertBefore(t,0==n?e:L.splitDataNode(e,n)):n>=e.childNodes.length?e.appendChild(t):e.insertBefore(t,e.childNodes[n]),i}function d(t){for(var e,n,o,r=i(t.range).createDocumentFragment();n=t.next();){if(e=t.isPartiallySelectedSubtree(),n=n.cloneNode(!e),e&&(o=t.getSubtreeIterator(),n.appendChild(d(o)),o.detach(!0)),10==n.nodeType)throw new B("HIERARCHY_REQUEST_ERR");r.appendChild(n)}return r}function c(t,e,n){var i,o;n=n||{stop:!1};for(var r,s;r=t.next();)if(t.isPartiallySelectedSubtree()){if(!1===e(r))return void(n.stop=!0);if(s=t.getSubtreeIterator(),c(s,e,n),s.detach(!0),n.stop)return}else for(i=L.createIterator(r);o=i.next();)if(!1===e(o))return void(n.stop=!0)}function h(t){for(var e;t.next();)t.isPartiallySelectedSubtree()?(e=t.getSubtreeIterator(),h(e),e.detach(!0)):t.remove()}function l(t){for(var e,n,o=i(t.range).createDocumentFragment();e=t.next();){if(t.isPartiallySelectedSubtree()?(e=e.cloneNode(!1),n=t.getSubtreeIterator(),e.appendChild(l(n)),n.detach(!0)):t.remove(),10==e.nodeType)throw new B("HIERARCHY_REQUEST_ERR");o.appendChild(e)}return o}function u(t,e,n){var i,o=!(!e||!e.length),r=!!n;o&&(i=new RegExp("^("+e.join("|")+")$"));var s=[];return c(new p(t,!1),function(t){o&&!i.test(t.nodeType)||r&&!n(t)||s.push(t)}),s}function f(t){return"["+("undefined"==typeof t.getName?"Range":t.getName())+"("+L.inspectNode(t.startContainer)+":"+t.startOffset+", "+L.inspectNode(t.endContainer)+":"+t.endOffset+")]"}function p(t,e){if(this.range=t,this.clonePartiallySelectedTextNodes=e,!t.collapsed){this.sc=t.startContainer,this.so=t.startOffset,this.ec=t.endContainer,this.eo=t.endOffset;var n=t.commonAncestorContainer;this.sc===this.ec&&L.isCharacterDataNode(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==n||L.isCharacterDataNode(this.sc)?L.getClosestAncestorIn(this.sc,n,!0):this.sc.childNodes[this.so],this._last=this.ec!==n||L.isCharacterDataNode(this.ec)?L.getClosestAncestorIn(this.ec,n,!0):this.ec.childNodes[this.eo-1])}}function g(t){this.code=this[t],this.codeName=t,this.message="RangeException: "+this.codeName}function m(t,e,n){this.nodes=u(t,e,n),this._next=this.nodes[0],this._position=0}function v(t){return function(e,n){for(var i,o=n?e:e.parentNode;o;){if(i=o.nodeType,L.arrayContains(t,i))return o;o=o.parentNode}return null}}function C(t,e){if(X(t,e))throw new g("INVALID_NODE_TYPE_ERR")}function S(t){if(!t.startContainer)throw new B("INVALID_STATE_ERR")}function x(t,e){if(!L.arrayContains(e,t.nodeType))throw new g("INVALID_NODE_TYPE_ERR")}function b(t,e){if(e<0||e>(L.isCharacterDataNode(t)?t.length:t.childNodes.length))throw new B("INDEX_SIZE_ERR")}function E(t,e){if(J(t,!0)!==J(e,!0))throw new B("WRONG_DOCUMENT_ERR")}function _(t){if(z(t,!0))throw new B("NO_MODIFICATION_ALLOWED_ERR")}function T(t,e){if(!t)throw new B(e)}function N(t){return!L.arrayContains(F,t.nodeType)&&!J(t,!0)}function y(t,e){return e<=(L.isCharacterDataNode(t)?t.length:t.childNodes.length)}function w(t){return!!t.startContainer&&!!t.endContainer&&!N(t.startContainer)&&!N(t.endContainer)&&y(t.startContainer,t.startOffset)&&y(t.endContainer,t.endOffset)}function R(t){if(S(t),!w(t))throw new Error("Range error: Range is no longer valid after DOM mutation ("+t.inspect()+")")}function O(){}function D(t){t.START_TO_START=tt,t.START_TO_END=et,t.END_TO_END=nt,t.END_TO_START=it,t.NODE_BEFORE=ot,t.NODE_AFTER=rt,t.NODE_BEFORE_AND_AFTER=st,t.NODE_INSIDE=at}function I(t){D(t),D(t.prototype)}function A(t,e){return function(){R(this);var n,i,o=this.startContainer,r=this.startOffset,a=this.commonAncestorContainer,d=new p(this,!0);o!==a&&(n=L.getClosestAncestorIn(o,a,!0),i=s(n),o=i.node,r=i.offset),c(d,_),d.reset();var h=t(d);return d.detach(),e(this,o,r,o,r),h}}function q(e,i,o){function a(t,e){return function(n){S(this),x(n,V),x(Y(n),F);var i=(t?r:s)(n);(e?d:c)(this,i.node,i.offset)}}function d(t,e,n){var o=t.endContainer,r=t.endOffset;e===t.startContainer&&n===t.startOffset||(Y(e)==Y(o)&&1!=L.comparePoints(e,n,o,r)||(o=e,r=n),i(t,e,n,o,r))}function c(t,e,n){var o=t.startContainer,r=t.startOffset;e===t.endContainer&&n===t.endOffset||(Y(e)==Y(o)&&-1!=L.comparePoints(e,n,o,r)||(o=e,r=n),i(t,o,r,e,n))}function u(t,e,n){e===t.startContainer&&n===t.startOffset&&e===t.endContainer&&n===t.endOffset||i(t,e,n,e,n)}e.prototype=new O,t.util.extend(e.prototype,{setStart:function(t,e){S(this),C(t,!0),b(t,e),d(this,t,e)},setEnd:function(t,e){S(this),C(t,!0),b(t,e),c(this,t,e)},setStartBefore:a(!0,!0),setStartAfter:a(!1,!0),setEndBefore:a(!0,!1),setEndAfter:a(!1,!1),collapse:function(t){R(this),t?i(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):i(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(t){S(this),C(t,!0),i(this,t,0,t,L.getNodeLength(t))},selectNode:function(t){S(this),C(t,!1),x(t,V);var e=r(t),n=s(t);i(this,e.node,e.offset,n.node,n.offset)},extractContents:A(l,i),deleteContents:A(h,i),canSurroundContents:function(){R(this),_(this.startContainer),_(this.endContainer);var t=new p(this,!0),e=t._first&&n(t._first,this)||t._last&&n(t._last,this);return t.detach(),!e},detach:function(){o(this)},splitBoundaries:function(){R(this);var t=this.startContainer,e=this.startOffset,n=this.endContainer,o=this.endOffset,r=t===n;L.isCharacterDataNode(n)&&o>0&&o<n.length&&L.splitDataNode(n,o),L.isCharacterDataNode(t)&&e>0&&e<t.length&&(t=L.splitDataNode(t,e),r?(o-=e,n=t):n==t.parentNode&&o>=L.getNodeIndex(t)&&o++,e=0),i(this,t,e,n,o)},normalizeBoundaries:function(){R(this);var t=this.startContainer,e=this.startOffset,n=this.endContainer,o=this.endOffset,r=function(t){var e=t.nextSibling;e&&e.nodeType==t.nodeType&&(n=t,o=t.length,t.appendData(e.data),e.parentNode.removeChild(e))},s=function(i){var r=i.previousSibling;if(r&&r.nodeType==i.nodeType){t=i;var s=i.length;if(e=r.length,i.insertData(0,r.data),r.parentNode.removeChild(r),t==n)o+=e,n=t;else if(n==i.parentNode){var a=L.getNodeIndex(i);o==a?(n=i,o=s):o>a&&o--}}},a=!0;if(L.isCharacterDataNode(n))n.length==o&&r(n);else{if(o>0){var d=n.childNodes[o-1];d&&L.isCharacterDataNode(d)&&r(d)}a=!this.collapsed}if(a){if(L.isCharacterDataNode(t))0==e&&s(t);else if(e<t.childNodes.length){var c=t.childNodes[e];c&&L.isCharacterDataNode(c)&&s(c)}}else t=n,e=o;i(this,t,e,n,o)},collapseToPoint:function(t,e){S(this),C(t,!0),b(t,e),u(this,t,e)}}),I(e)}function j(t){t.collapsed=t.startContainer===t.endContainer&&t.startOffset===t.endOffset,t.commonAncestorContainer=t.collapsed?t.startContainer:L.getCommonAncestor(t.startContainer,t.endContainer)}function M(t,e,n,i,r){var s=t.startContainer!==e||t.startOffset!==n,a=t.endContainer!==i||t.endOffset!==r;t.startContainer=e,t.startOffset=n,t.endContainer=i,t.endOffset=r,j(t),o(t,"boundarychange",{startMoved:s,endMoved:a})}function P(t){S(t),t.startContainer=t.startOffset=t.endContainer=t.endOffset=null,t.collapsed=t.commonAncestorContainer=null,o(t,"detach",null),t._listeners=null}function k(t){this.startContainer=t,this.startOffset=0,this.endContainer=t,this.endOffset=0,this._listeners={boundarychange:[],detach:[]},j(this)}t.requireModules(["DomUtil"]);var L=t.dom,U=L.DomPosition,B=t.DOMException;p.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 t=this._current=this._next;return t&&(this._next=t!==this._last?t.nextSibling:null,L.isCharacterDataNode(t)&&this.clonePartiallySelectedTextNodes&&(t===this.ec&&(t=t.cloneNode(!0)).deleteData(this.eo,t.length-this.eo),this._current===this.sc&&(t=t.cloneNode(!0)).deleteData(0,this.so))),t},remove:function(){var t,e,n=this._current;!L.isCharacterDataNode(n)||n!==this.sc&&n!==this.ec?n.parentNode&&n.parentNode.removeChild(n):(t=n===this.sc?this.so:0,e=n===this.ec?this.eo:n.length,t!=e&&n.deleteData(t,e-t))},isPartiallySelectedSubtree:function(){return n(this._current,this.range)},getSubtreeIterator:function(){var t;if(this.isSingleCharacterDataNode)t=this.range.cloneRange(),t.collapse();else{t=new k(i(this.range));var e=this._current,n=e,o=0,r=e,s=L.getNodeLength(e);L.isAncestorOf(e,this.sc,!0)&&(n=this.sc,o=this.so),L.isAncestorOf(e,this.ec,!0)&&(r=this.ec,s=this.eo),M(t,n,o,r,s)}return new p(t,this.clonePartiallySelectedTextNodes)},detach:function(t){t&&this.range.detach(),this.range=this._current=this._next=this._first=this._last=this.sc=this.so=this.ec=this.eo=null}},g.prototype={BAD_BOUNDARYPOINTS_ERR:1,INVALID_NODE_TYPE_ERR:2},g.prototype.toString=function(){return this.message},m.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],F=[2,9,11],H=[5,6,10,12],Q=[1,3,4,5,7,8,10,11],W=[1,3,4,5,7,8],Y=L.getRootContainer,J=v([9,11]),z=v(H),X=v([6,10,12]),K=document.createElement("style"),G=!1;try{K.innerHTML="<b>x</b>",G=3==K.firstChild.nodeType}catch(t){}t.features.htmlParsingConforms=G;var Z=G?function(t){var e=this.startContainer,n=L.getDocument(e);if(!e)throw new B("INVALID_STATE_ERR");var i=null;return 1==e.nodeType?i=e:L.isCharacterDataNode(e)&&(i=L.parentElement(e)),i=null===i||"HTML"==i.nodeName&&L.isHtmlNamespace(L.getDocument(i).documentElement)&&L.isHtmlNamespace(i)?n.createElement("body"):i.cloneNode(!1),i.innerHTML=t,L.fragmentFromNodeChildren(i)}:function(t){S(this);var e=i(this),n=e.createElement("body");return n.innerHTML=t,L.fragmentFromNodeChildren(n)},$=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],tt=0,et=1,nt=2,it=3,ot=0,rt=1,st=2,at=3;O.prototype={attachListener:function(t,e){this._listeners[t].push(e)},compareBoundaryPoints:function(t,e){R(this),E(this.startContainer,e.startContainer);var n,i,o,r,s=t==it||t==tt?"start":"end",a=t==et||t==tt?"start":"end";return n=this[s+"Container"],i=this[s+"Offset"],o=e[a+"Container"],r=e[a+"Offset"],L.comparePoints(n,i,o,r)},insertNode:function(t){if(R(this),x(t,Q),_(this.startContainer),L.isAncestorOf(t,this.startContainer,!0))throw new B("HIERARCHY_REQUEST_ERR");var e=a(t,this.startContainer,this.startOffset);this.setStartBefore(e)},cloneContents:function(){R(this);var t,e;if(this.collapsed)return i(this).createDocumentFragment();if(this.startContainer===this.endContainer&&L.isCharacterDataNode(this.startContainer))return t=this.startContainer.cloneNode(!0),t.data=t.data.slice(this.startOffset,this.endOffset),e=i(this).createDocumentFragment(),e.appendChild(t),e;var n=new p(this,!0);return t=d(n),n.detach(),t},canSurroundContents:function(){R(this),_(this.startContainer),_(this.endContainer);var t=new p(this,!0),e=t._first&&n(t._first,this)||t._last&&n(t._last,this);return t.detach(),!e},surroundContents:function(t){if(x(t,W),!this.canSurroundContents())throw new g("BAD_BOUNDARYPOINTS_ERR");var e=this.extractContents();if(t.hasChildNodes())for(;t.lastChild;)t.removeChild(t.lastChild);a(t,this.startContainer,this.startOffset),t.appendChild(e),this.selectNode(t)},cloneRange:function(){R(this);for(var t,e=new k(i(this)),n=$.length;n--;)t=$[n],e[t]=this[t];return e},toString:function(){R(this);var t=this.startContainer;if(t===this.endContainer&&L.isCharacterDataNode(t))return 3==t.nodeType||4==t.nodeType?t.data.slice(this.startOffset,this.endOffset):"";var e=[],n=new p(this,!0);return c(n,function(t){3!=t.nodeType&&4!=t.nodeType||e.push(t.data)}),n.detach(),e.join("")},compareNode:function(t){R(this);var e=t.parentNode,n=L.getNodeIndex(t);if(!e)throw new B("NOT_FOUND_ERR");var i=this.comparePoint(e,n),o=this.comparePoint(e,n+1);return i<0?o>0?st:ot:o>0?rt:at},comparePoint:function(t,e){return R(this),T(t,"HIERARCHY_REQUEST_ERR"),E(t,this.startContainer),L.comparePoints(t,e,this.startContainer,this.startOffset)<0?-1:L.comparePoints(t,e,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:Z,toHtml:function(){R(this);var t=i(this).createElement("div");return t.appendChild(this.cloneContents()),t.innerHTML},intersectsNode:function(t,e){if(R(this),T(t,"NOT_FOUND_ERR"),L.getDocument(t)!==i(this))return!1;var n=t.parentNode,o=L.getNodeIndex(t);T(n,"NOT_FOUND_ERR");var r=L.comparePoints(n,o,this.endContainer,this.endOffset),s=L.comparePoints(n,o+1,this.startContainer,this.startOffset);return e?r<=0&&s>=0:r<0&&s>0},isPointInRange:function(t,e){return R(this),T(t,"HIERARCHY_REQUEST_ERR"),E(t,this.startContainer),L.comparePoints(t,e,this.startContainer,this.startOffset)>=0&&L.comparePoints(t,e,this.endContainer,this.endOffset)<=0},intersectsRange:function(t,e){if(R(this),i(t)!=i(this))throw new B("WRONG_DOCUMENT_ERR");var n=L.comparePoints(this.startContainer,this.startOffset,t.endContainer,t.endOffset),o=L.comparePoints(this.endContainer,this.endOffset,t.startContainer,t.startOffset);return e?n<=0&&o>=0:n<0&&o>0},intersection:function(t){if(this.intersectsRange(t)){var e=L.comparePoints(this.startContainer,this.startOffset,t.startContainer,t.startOffset),n=L.comparePoints(this.endContainer,this.endOffset,t.endContainer,t.endOffset),i=this.cloneRange();return-1==e&&i.setStart(t.startContainer,t.startOffset),1==n&&i.setEnd(t.endContainer,t.endOffset),i}return null},union:function(t){if(this.intersectsRange(t,!0)){var e=this.cloneRange();return-1==L.comparePoints(t.startContainer,t.startOffset,this.startContainer,this.startOffset)&&e.setStart(t.startContainer,t.startOffset),1==L.comparePoints(t.endContainer,t.endOffset,this.endContainer,this.endOffset)&&e.setEnd(t.endContainer,t.endOffset),e}throw new g("Ranges do not intersect")},containsNode:function(t,e){return e?this.intersectsNode(t,!1):this.compareNode(t)==at},containsNodeContents:function(t){return this.comparePoint(t,0)>=0&&this.comparePoint(t,L.getNodeLength(t))<=0},containsRange:function(t){return this.intersection(t).equals(t)},containsNodeText:function(t){var e=this.cloneRange();e.selectNode(t);var n=e.getNodes([3]);if(n.length>0){e.setStart(n[0],0);var i=n.pop();e.setEnd(i,i.length);var o=this.containsRange(e);return e.detach(),o}return this.containsNodeContents(t)},createNodeIterator:function(t,e){return R(this),new m(this,t,e)},getNodes:function(t,e){return R(this),u(this,t,e)},getDocument:function(){return i(this)},collapseBefore:function(t){S(this),this.setEndBefore(t),this.collapse(!1)},collapseAfter:function(t){S(this),this.setStartAfter(t),this.collapse(!0)},getName:function(){return"DomRange"},equals:function(t){return k.rangesEqual(this,t)},isValid:function(){return w(this)},inspect:function(){return f(this)}},q(k,M,P),t.rangePrototype=O.prototype,k.rangeProperties=$,k.RangeIterator=p,k.copyComparisonConstants=I,k.createPrototypeRange=q,k.inspect=f,k.getRangeDocument=i,k.rangesEqual=function(t,e){return t.startContainer===e.startContainer&&t.startOffset===e.startOffset&&t.endContainer===e.endContainer&&t.endOffset===e.endOffset},t.DomRange=k,t.RangeException=g}),rangy.createModule("WrappedRange",function(t,e){function n(t){var e=t.parentElement(),n=t.duplicate();n.collapse(!0);var i=n.parentElement();n=t.duplicate(),n.collapse(!1);var o=n.parentElement(),r=i==o?i:a.getCommonAncestor(i,o);return r==e?r:a.getCommonAncestor(e,r)}function i(t){return 0==t.compareEndPoints("StartToEnd",t)}function o(t,e,n,i){var o=t.duplicate();o.collapse(n);var r=o.parentElement();if(a.isAncestorOf(e,r,!0)||(r=e),!r.canHaveHTML)return new d(r.parentNode,a.getNodeIndex(r));var s,c,h,l,u,f=a.getDocument(r).createElement("span"),p=n?"StartToStart":"StartToEnd";do{r.insertBefore(f,f.previousSibling),o.moveToElementText(f)}while((s=o.compareEndPoints(p,t))>0&&f.previousSibling);if(u=f.nextSibling,-1==s&&u&&a.isCharacterDataNode(u)){o.setEndPoint(n?"EndToStart":"EndToEnd",t);var g;if(/[\r\n]/.test(u.data)){var m=o.duplicate(),v=m.text.replace(/\r\n/g,"\r").length;for(g=m.moveStart("character",v);-1==(s=m.compareEndPoints("StartToEnd",m));)g++,m.moveStart("character",1)}else g=o.text.length;l=new d(u,g)}else c=(i||!n)&&f.previousSibling,h=(i||n)&&f.nextSibling,l=h&&a.isCharacterDataNode(h)?new d(h,0):c&&a.isCharacterDataNode(c)?new d(c,c.length):new d(r,a.getNodeIndex(f));return f.parentNode.removeChild(f),l}function r(t,e){var n,i,o,r,s=t.offset,d=a.getDocument(t.node),c=d.body.createTextRange(),h=a.isCharacterDataNode(t.node);return h?(n=t.node,i=n.parentNode):(r=t.node.childNodes,n=s<r.length?r[s]:null,i=t.node),o=d.createElement("span"),o.innerHTML="&#feff;",n?i.insertBefore(o,n):i.appendChild(o),c.moveToElementText(o),c.collapse(!e),i.removeChild(o),h&&c[e?"moveStart":"moveEnd"]("character",s),c}t.requireModules(["DomUtil","DomRange"]);var s,a=t.dom,d=a.DomPosition,c=t.DomRange;if(!t.features.implementsDomRange||t.features.implementsTextRange&&t.config.preferTextRange){if(t.features.implementsTextRange){s=function(t){this.textRange=t,this.refresh()},s.prototype=new c(document),s.prototype.refresh=function(){var t,e,r=n(this.textRange);i(this.textRange)?e=t=o(this.textRange,r,!0,!0):(t=o(this.textRange,r,!0,!1),e=o(this.textRange,r,!1,!1)),this.setStart(t.node,t.offset),this.setEnd(e.node,e.offset)},c.copyComparisonConstants(s);var h=function(){return this}();"undefined"==typeof h.Range&&(h.Range=s),t.createNativeRange=function(t){return t=t||document,t.body.createTextRange()}}}else!function(){function e(t){for(var e,n=d.length;n--;)e=d[n],t[e]=t.nativeRange[e]}function n(t,e,n,i,o){var r=t.startContainer!==e||t.startOffset!=n,s=t.endContainer!==i||t.endOffset!=o;(r||s)&&(t.setEnd(i,o),t.setStart(e,n))}function i(t){t.nativeRange.detach(),t.detached=!0;for(var e,n=d.length;n--;)e=d[n],t[e]=null}var o,r,d=c.rangeProperties;s=function(t){if(!t)throw new Error("Range must be specified");this.nativeRange=t,e(this)},c.createPrototypeRange(s,n,i),o=s.prototype,o.selectNode=function(t){this.nativeRange.selectNode(t),e(this)},o.deleteContents=function(){this.nativeRange.deleteContents(),e(this)},o.extractContents=function(){var t=this.nativeRange.extractContents();return e(this),t},o.cloneContents=function(){return this.nativeRange.cloneContents()},o.surroundContents=function(t){this.nativeRange.surroundContents(t),e(this)},o.collapse=function(t){this.nativeRange.collapse(t),e(this)},o.cloneRange=function(){return new s(this.nativeRange.cloneRange())},o.refresh=function(){e(this)},o.toString=function(){return this.nativeRange.toString()};var h=document.createTextNode("test");a.getBody(document).appendChild(h);var l=document.createRange();l.setStart(h,0),l.setEnd(h,0);try{l.setStart(h,1),!0,o.setStart=function(t,n){this.nativeRange.setStart(t,n),e(this)},o.setEnd=function(t,n){this.nativeRange.setEnd(t,n),e(this)},r=function(t){return function(n){this.nativeRange[t](n),e(this)}}}catch(t){!1,o.setStart=function(t,n){try{this.nativeRange.setStart(t,n)}catch(e){this.nativeRange.setEnd(t,n),this.nativeRange.setStart(t,n)}e(this)},o.setEnd=function(t,n){try{this.nativeRange.setEnd(t,n)}catch(e){this.nativeRange.setStart(t,n),this.nativeRange.setEnd(t,n)}e(this)},r=function(t,n){return function(i){try{this.nativeRange[t](i)}catch(e){this.nativeRange[n](i),this.nativeRange[t](i)}e(this)}}}o.setStartBefore=r("setStartBefore","setEndBefore"),o.setStartAfter=r("setStartAfter","setEndAfter"),o.setEndBefore=r("setEndBefore","setStartBefore"),o.setEndAfter=r("setEndAfter","setStartAfter"),l.selectNodeContents(h),l.startContainer==h&&l.endContainer==h&&0==l.startOffset&&l.endOffset==h.length?o.selectNodeContents=function(t){this.nativeRange.selectNodeContents(t),e(this)}:o.selectNodeContents=function(t){this.setStart(t,0),this.setEnd(t,c.getEndOffset(t))},l.selectNodeContents(h),l.setEnd(h,3);var u=document.createRange();u.selectNodeContents(h),u.setEnd(h,4),u.setStart(h,2),-1==l.compareBoundaryPoints(l.START_TO_END,u)&1==l.compareBoundaryPoints(l.END_TO_START,u)?o.compareBoundaryPoints=function(t,e){return e=e.nativeRange||e,t==e.START_TO_END?t=e.END_TO_START:t==e.END_TO_START&&(t=e.START_TO_END),this.nativeRange.compareBoundaryPoints(t,e)}:o.compareBoundaryPoints=function(t,e){return this.nativeRange.compareBoundaryPoints(t,e.nativeRange||e)},t.util.isHostMethod(l,"createContextualFragment")&&(o.createContextualFragment=function(t){return this.nativeRange.createContextualFragment(t)}),a.getBody(document).removeChild(h),l.detach(),u.detach()}(),t.createNativeRange=function(t){return t=t||document,t.createRange()};t.features.implementsTextRange&&(s.rangeToTextRange=function(t){if(t.collapsed){return r(new d(t.startContainer,t.startOffset),!0)}var e=r(new d(t.startContainer,t.startOffset),!0),n=r(new d(t.endContainer,t.endOffset),!1),i=a.getDocument(t.startContainer).body.createTextRange();return i.setEndPoint("StartToStart",e),i.setEndPoint("EndToEnd",n),i}),s.prototype.getName=function(){return"WrappedRange"},t.WrappedRange=s,t.createRange=function(e){return e=e||document,new s(t.createNativeRange(e))},t.createRangyRange=function(t){return t=t||document,new c(t)},t.createIframeRange=function(e){return t.createRange(a.getIframeDocument(e))},t.createIframeRangyRange=function(e){return t.createRangyRange(a.getIframeDocument(e))},t.addCreateMissingNativeApiListener(function(e){var n=e.document;"undefined"==typeof n.createRange&&(n.createRange=function(){return t.createRange(this)}),n=e=null})}),rangy.createModule("WrappedSelection",function(t,e){function n(t){return(t||window).getSelection()}function i(t){return(t||window).document.selection}function o(t,e,n){var i=n?"end":"start",o=n?"start":"end";t.anchorNode=e[i+"Container"],t.anchorOffset=e[i+"Offset"],t.focusNode=e[o+"Container"],t.focusOffset=e[o+"Offset"]}function r(t){var e=t.nativeSelection;t.anchorNode=e.anchorNode,t.anchorOffset=e.anchorOffset,t.focusNode=e.focusNode,t.focusOffset=e.focusOffset}function s(t){t.anchorNode=t.focusNode=null,t.anchorOffset=t.focusOffset=0,t.rangeCount=0,t.isCollapsed=!0,t._ranges.length=0}function a(e){var n;return e instanceof T?(n=e._selectionNativeRange)||(n=t.createNativeRange(E.getDocument(e.startContainer)),n.setEnd(e.endContainer,e.endOffset),n.setStart(e.startContainer,e.startOffset),e._selectionNativeRange=n,e.attachListener("detach",function(){this._selectionNativeRange=null})):e instanceof N?n=e.nativeRange:t.features.implementsDomRange&&e instanceof E.getWindow(e.startContainer).Range&&(n=e),n}function d(t){if(!t.length||1!=t[0].nodeType)return!1;for(var e=1,n=t.length;e<n;++e)if(!E.isAncestorOf(t[0],t[e]))return!1;return!0}function c(t){var e=t.getNodes();if(!d(e))throw new Error("getSingleElementFromRange: range "+t.inspect()+" did not consist of a single element");return e[0]}function h(t){return!!t&&"undefined"!=typeof t.text}function l(t,e){var n=new N(e);t._ranges=[n],o(t,n,!1),t.rangeCount=1,t.isCollapsed=n.collapsed}function u(e){if(e._ranges.length=0,"None"==e.docSelection.type)s(e);else{var n=e.docSelection.createRange();if(h(n))l(e,n);else{e.rangeCount=n.length;for(var i,r=E.getDocument(n.item(0)),a=0;a<e.rangeCount;++a)i=t.createRange(r),i.selectNode(n.item(a)),e._ranges.push(i);e.isCollapsed=1==e.rangeCount&&e._ranges[0].collapsed,o(e,e._ranges[e.rangeCount-1],!1)}}}function f(t,e){for(var n=t.docSelection.createRange(),i=c(e),o=E.getDocument(n.item(0)),r=E.getBody(o).createControlRange(),s=0,a=n.length;s<a;++s)r.add(n.item(s));try{r.add(i)}catch(t){throw new Error("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}r.select(),u(t)}function p(t,e,n){this.nativeSelection=t,this.docSelection=e,this._ranges=[],this.win=n,this.refresh()}function g(t,e){for(var n,i=E.getDocument(e[0].startContainer),o=E.getBody(i).createControlRange(),r=0;r<rangeCount;++r){n=c(e[r]);try{o.add(n)}catch(t){throw new Error("setRanges(): Element within the one of the specified Ranges could not be added to control selection (does it have layout?)")}}o.select(),u(t)}function m(t,e){if(t.anchorNode&&E.getDocument(t.anchorNode)!==E.getDocument(e))throw new y("WRONG_DOCUMENT_ERR")}function v(t){var e=[],n=new w(t.anchorNode,t.anchorOffset),i=new w(t.focusNode,t.focusOffset),o="function"==typeof t.getName?t.getName():"Selection";if("undefined"!=typeof t.rangeCount)for(var r=0,s=t.rangeCount;r<s;++r)e[r]=T.inspect(t.getRangeAt(r));return"["+o+"(Ranges: "+e.join(", ")+")(anchor: "+n.inspect()+", focus: "+i.inspect()+"]"}t.requireModules(["DomUtil","DomRange","WrappedRange"]),t.config.checkSelectionRanges=!0;var C,S,x="boolean",b="_rangySelection",E=t.dom,_=t.util,T=t.DomRange,N=t.WrappedRange,y=t.DOMException,w=E.DomPosition,R="Control",O=t.util.isHostMethod(window,"getSelection"),D=t.util.isHostObject(document,"selection"),I=D&&(!O||t.config.preferTextRange);I?(C=i,t.isSelectionValid=function(t){var e=(t||window).document,n=e.selection;return"None"!=n.type||E.getDocument(n.createRange().parentElement())==e}):O?(C=n,t.isSelectionValid=function(){return!0}):e.fail("Neither document.selection or window.getSelection() detected."),t.getNativeSelection=C;var A=C(),q=t.createNativeRange(document),j=E.getBody(document),M=_.areHostObjects(A,["anchorNode","focusNode"]&&_.areHostProperties(A,["anchorOffset","focusOffset"]));t.features.selectionHasAnchorAndFocus=M;var P=_.isHostMethod(A,"extend");t.features.selectionHasExtend=P;var k="number"==typeof A.rangeCount;t.features.selectionHasRangeCount=k;var L=!1,U=!0;_.areHostMethods(A,["addRange","getRangeAt","removeAllRanges"])&&"number"==typeof A.rangeCount&&t.features.implementsDomRange&&function(){var t=document.createElement("iframe");t.frameBorder=0,t.style.position="absolute",t.style.left="-10000px",j.appendChild(t);var e=E.getIframeDocument(t);e.open(),e.write("<html><head></head><body>12</body></html>"),e.close();var n=E.getIframeWindow(t).getSelection(),i=e.documentElement,o=i.lastChild,r=o.firstChild,s=e.createRange();s.setStart(r,1),s.collapse(!0),n.addRange(s),U=1==n.rangeCount,n.removeAllRanges();var a=s.cloneRange();s.setStart(r,0),a.setEnd(r,2),n.addRange(s),n.addRange(a),L=2==n.rangeCount,s.detach(),a.detach(),j.removeChild(t)}(),t.features.selectionSupportsMultipleRanges=L,t.features.collapsedNonEditableSelectionsSupported=U;var B,V=!1;j&&_.isHostMethod(j,"createControlRange")&&(B=j.createControlRange(),_.areHostProperties(B,["item","add"])&&(V=!0)),t.features.implementsControlRange=V,S=M?function(t){return t.anchorNode===t.focusNode&&t.anchorOffset===t.focusOffset}:function(t){return!!t.rangeCount&&t.getRangeAt(t.rangeCount-1).collapsed};var F;_.isHostMethod(A,"getRangeAt")?F=function(t,e){try{return t.getRangeAt(e)}catch(t){return null}}:M&&(F=function(e){var n=E.getDocument(e.anchorNode),i=t.createRange(n);return i.setStart(e.anchorNode,e.anchorOffset),i.setEnd(e.focusNode,e.focusOffset),i.collapsed!==this.isCollapsed&&(i.setStart(e.focusNode,e.focusOffset),i.setEnd(e.anchorNode,e.anchorOffset)),i}),t.getSelection=function(t){t=t||window;var e=t[b],n=C(t),o=D?i(t):null;if(e){e.nativeSelection=n,e.docSelection=o;try{e.refresh(t)}catch(t){}}else e=new p(n,o,t),t[b]=e;return e},t.getIframeSelection=function(e){return t.getSelection(E.getIframeWindow(e))};var H=p.prototype;if(!I&&M&&_.areHostMethods(A,["removeAllRanges","addRange"])){H.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),s(this)};var Q=function(e,n){var i=T.getRangeDocument(n),o=t.createRange(i);o.collapseToPoint(n.endContainer,n.endOffset),e.nativeSelection.addRange(a(o)),e.nativeSelection.extend(n.startContainer,n.startOffset),e.refresh()};H.addRange=k?function(e,n){if(V&&D&&this.docSelection.type==R)f(this,e);else if(n&&P)Q(this,e);else{var i;if(L?i=this.rangeCount:(this.removeAllRanges(),i=0),this.nativeSelection.addRange(a(e)),this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==i+1){if(t.config.checkSelectionRanges){var r=F(this.nativeSelection,this.rangeCount-1);r&&!T.rangesEqual(r,e)&&(e=new N(r))}this._ranges[this.rangeCount-1]=e,o(this,e,J(this.nativeSelection)),this.isCollapsed=S(this)}else this.refresh()}}:function(t,e){e&&P?Q(this,t):(this.nativeSelection.addRange(a(t)),this.refresh())},H.setRanges=function(t){if(V&&t.length>1)g(this,t);else{this.removeAllRanges();for(var e=0,n=t.length;e<n;++e)this.addRange(t[e])}}}else{if(!(_.isHostMethod(A,"empty")&&_.isHostMethod(q,"select")&&V&&I))return e.fail("No means of selecting a Range or TextRange was found"),!1;H.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var t;if(this.anchorNode)t=E.getDocument(this.anchorNode);else if(this.docSelection.type==R){var e=this.docSelection.createRange();e.length&&(t=E.getDocument(e.item(0)).body.createTextRange())}if(t){t.body.createTextRange().select(),this.docSelection.empty()}}}catch(t){}s(this)},H.addRange=function(t){this.docSelection.type==R?f(this,t):(N.rangeToTextRange(t).select(),this._ranges[0]=t,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,o(this,t,!1))},H.setRanges=function(t){this.removeAllRanges();var e=t.length;e>1?g(this,t):e&&this.addRange(t[0])}}H.getRangeAt=function(t){if(t<0||t>=this.rangeCount)throw new y("INDEX_SIZE_ERR");return this._ranges[t]};var W;if(I)W=function(e){var n;t.isSelectionValid(e.win)?n=e.docSelection.createRange():(n=E.getBody(e.win.document).createTextRange(),n.collapse(!0)),e.docSelection.type==R?u(e):h(n)?l(e,n):s(e)};else if(_.isHostMethod(A,"getRangeAt")&&"number"==typeof A.rangeCount)W=function(e){if(V&&D&&e.docSelection.type==R)u(e);else if(e._ranges.length=e.rangeCount=e.nativeSelection.rangeCount,e.rangeCount){for(var n=0,i=e.rangeCount;n<i;++n)e._ranges[n]=new t.WrappedRange(e.nativeSelection.getRangeAt(n));o(e,e._ranges[e.rangeCount-1],J(e.nativeSelection)),e.isCollapsed=S(e)}else s(e)};else{if(!M||typeof A.isCollapsed!=x||typeof q.collapsed!=x||!t.features.implementsDomRange)return e.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;W=function(t){var e,n=t.nativeSelection;n.anchorNode?(e=F(n,0),t._ranges=[e],t.rangeCount=1,r(t),t.isCollapsed=S(t)):s(t)}}H.refresh=function(t){var e=t?this._ranges.slice(0):null;if(W(this),t){var n=e.length;if(n!=this._ranges.length)return!1;for(;n--;)if(!T.rangesEqual(e[n],this._ranges[n]))return!1;return!0}};var Y=function(t,e){var n=t.getAllRanges(),i=!1;t.removeAllRanges();for(var o=0,r=n.length;o<r;++o)i||e!==n[o]?t.addRange(n[o]):i=!0;t.rangeCount||s(t)};H.removeRange=V?function(t){if(this.docSelection.type==R){for(var e,n=this.docSelection.createRange(),i=c(t),o=E.getDocument(n.item(0)),r=E.getBody(o).createControlRange(),s=!1,a=0,d=n.length;a<d;++a)e=n.item(a),e!==i||s?r.add(n.item(a)):s=!0;r.select(),u(this)}else Y(this,t)}:function(t){Y(this,t)};var J;!I&&M&&t.features.implementsDomRange?(J=function(t){var e=!1;return t.anchorNode&&(e=1==E.comparePoints(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset)),e},H.isBackwards=function(){return J(this)}):J=H.isBackwards=function(){return!1},H.toString=function(){for(var t=[],e=0,n=this.rangeCount;e<n;++e)t[e]=""+this._ranges[e];return t.join("")},H.collapse=function(e,n){m(this,e);var i=t.createRange(E.getDocument(e));i.collapseToPoint(e,n),this.removeAllRanges(),this.addRange(i),this.isCollapsed=!0},H.collapseToStart=function(){if(!this.rangeCount)throw new y("INVALID_STATE_ERR");var t=this._ranges[0];this.collapse(t.startContainer,t.startOffset)},H.collapseToEnd=function(){if(!this.rangeCount)throw new y("INVALID_STATE_ERR");var t=this._ranges[this.rangeCount-1];this.collapse(t.endContainer,t.endOffset)},H.selectAllChildren=function(e){m(this,e);var n=t.createRange(E.getDocument(e));n.selectNodeContents(e),this.removeAllRanges(),this.addRange(n)},H.deleteFromDocument=function(){if(V&&D&&this.docSelection.type==R){for(var t,e=this.docSelection.createRange();e.length;)t=e.item(0),e.remove(t),t.parentNode.removeChild(t);this.refresh()}else if(this.rangeCount){var n=this.getAllRanges();this.removeAllRanges();for(var i=0,o=n.length;i<o;++i)n[i].deleteContents();this.addRange(n[o-1])}},H.getAllRanges=function(){return this._ranges.slice(0)},H.setSingleRange=function(t){this.setRanges([t])},H.containsNode=function(t,e){for(var n=0,i=this._ranges.length;n<i;++n)if(this._ranges[n].containsNode(t,e))return!0;return!1},H.toHtml=function(){var t="";if(this.rangeCount){for(var e=T.getRangeDocument(this._ranges[0]).createElement("div"),n=0,i=this._ranges.length;n<i;++n)e.appendChild(this._ranges[n].cloneContents());t=e.innerHTML}return t},H.getName=function(){return"WrappedSelection"},H.inspect=function(){return v(this)},H.detach=function(){this.win[b]=null,this.win=this.anchorNode=this.focusNode=null},p.inspect=v,t.Selection=p,t.selectionPrototype=H,t.addCreateMissingNativeApiListener(function(e){"undefined"==typeof e.getSelection&&(e.getSelection=function(){return t.getSelection(this)}),e=null})})}});