var XWiki=function(f){f.Selection=Class.create({container:!1,selectionText:!1,selectionContext:!1,selectionOffset:!1,range:!1,highlightWrappers:!1,offsetX:!1,offsetY:!1,step:5,initialize:function(a){a&&(this.container=a)},computeSelection:function(){this.highlightWrappers=this.selectionOffset=this.selectionContext=this.range=this.selectionText=!1;this.container&&window.getSelection().rangeCount&&(this.range=window.getSelection().getRangeAt(0),this.isDescendantOrSelf(this.container,this.range.commonAncestorContainer)&&
(this.selectionText=this.range.toString(),""==this.selectionText.strip()&&(this.selectionText=!1)))},isDescendantOrSelf:function(a,b){return a==b||Element.descendantOf(b,a)},computeContext:function(){window.getSelection?this.computeContextFF():this.computeContextIE()},highlightSelection:function(a){if(this.range){var b=new Element("span",{style:"background-color: "+a,"class":"selection-highlight"});a=this.getRangeTextNodes();window.getSelection().removeAllRanges();this.highlightWrappers=[];a.each(function(c){var d=
b.clone();d.update(c.textContent.escapeHTML());c.parentNode.replaceChild(d,c);this.highlightWrappers.push(d)}.bind(this))}},getRangeTextNodes:function(){var a=this.range.startContainer,b=this.range.endContainer,c=this.range.startOffset,d=this.range.endOffset,e=this.getFirstLeafInRange(this.range),h=this.getLastLeafInRange(this.range);e=this.getLeafsBetween(e,h).findAll(function(g){return 3==g.nodeType});a==e[0]&&0!=c&&(e[0]=a.splitText(c),a==b&&(d-=c,b=e[0]));b==e[e.length-1]&&d!=b.length&&(b=b.splitText(d));
return e},getLeafsBetween:function(a,b){var c=[],d=a;for(c.push(a);d!=b;)d=this.getNextLeaf(d),c.push(d);return c},getFirstLeafInRange:function(a){return a.startContainer.hasChildNodes()?a.collapsed?null:a.startOffset>=a.startContainer.childNodes.length?this.getNextLeaf(a.startContainer):this.getFirstLeaf(a.startContainer.childNodes[a.startOffset]):a.startContainer},getLastLeafInRange:function(a){return a.endContainer.hasChildNodes()?a.collapsed?null:0==a.endOffset?this.getPreviousLeaf(a.endContainer):
this.getLastLeaf(a.endContainer.childNodes[a.endOffset-1]):a.endContainer},getNextLeaf:function(a){for(;null!=a&&null==a.nextSibling;)a=a.parentNode;return null==a?null:this.getFirstLeaf(a.nextSibling)},getPreviousLeaf:function(a){for(;null!=a&&null==a.previousSibling;)a=a.parentNode;return null==a?null:this.getLastLeaf(a.previousSibling)},getFirstLeaf:function(a){for(;a.hasChildNodes();)a=a.firstChild;return a},getLastLeaf:function(a){for(;a.hasChildNodes();)a=a.lastChild;return a},removeSelectionHighlight:function(){this.highlightWrappers.each(function(a){a.replace(a.innerHTML)})},
getPositionNextToSelection:function(){if(!this.range)return{left:0,top:0};var a=0,b=0;window.getSelection?0<this.highlightWrappers.length&&(a=this.highlightWrappers[0].cumulativeOffset().left,b=this.highlightWrappers[this.highlightWrappers.length-1],b=b.cumulativeOffset().top+b.getHeight()):(a=this.offsetX,b=this.offsetY);return{left:a,top:b}},getRightDocument:function(a){var b="";a==this.container&&(b=this.getRightDocument(a.parentNode));for(a=a.nextSibling;null!=a;a=a.nextSibling)b+=a.textContent;
return b},getLeftDocument:function(a){var b="";a==this.container&&(b=this.getLeftDocument(a.parentNode));var c=a.parentNode;if(c.childNodes)for(var d=0;d<c.childNodes.length&&c.childNodes[d]!=a;++d)b+=c.childNodes[d].textContent;return b},computeContextFF:function(){for(var a=this.getLeftDocument(this.range.startContainer)+this.range.startContainer.textContent.substring(0,this.range.startOffset),b="",c=this.range.endContainer.textContent.substring(this.range.endOffset,this.range.endContainer.textContent.length)+
this.getRightDocument(this.range.endContainer),d="",e=this.range.toString(),h=0,g=0;d!=c||b!=a;){var k=this.container.textContent.indexOf(e);if(-1==this.container.textContent.indexOf(e,k+1))break;h=Math.min(a.length,h+this.step);g=Math.min(c.length,g+this.step);d=c.substring(0,g);b=a.substring(a.length-h,a.length)}this.selectionContext=b+this.selectionText+d;this.selectionOffset=Math.max(b.length,0)},computeContextIE:function(){for(var a=this.container.innerText,b=this.range.duplicate(),c=0,d=!0;!this.isUnique(a,
b.text)&&d;){d=!1;var e=b.text.length;b.moveStart("word",-1);this.isDescendantOrSelf(this.container,b.parentElement())?(c+=b.text.length-e,d=!0):b.moveStart("word",1);b.moveEnd("word",1);this.isDescendantOrSelf(this.container,b.parentElement())?d=!0:b.moveEnd("word",-1)}this.selectionContext=b.text;this.selectionOffset=c},isUnique:function(a,b){var c=a.indexOf(b);return 0<=c?0>a.indexOf(b,c+1):!0}});return f}(XWiki||{});
XWiki=function(f){f.Annotation=Class.create({annotatedElement:!1,annTabname:"Comments",annTabTemplate:"commentsinline.vm",fetchedAnnotations:!1,displayingAnnotations:!1,displayAnnotationsCheckbox:!1,displayHighlight:!0,addAnnotationShortcuts:["Meta+M","Meta+I"],toggleAnnotationsShortcuts:["Alt+A"],closeDialogShortcuts:["Esc"],selectionService:!1,bubbles:[],currentFilter:{},initialize:function(a,b,c){this.displayHighlight=a;(this.annotatedElement=b)?(this.hookMenuButton(),document.observe("xwiki:docextra:loaded",
this.addDeleteListenersInTab.bindAsEventListener(this)),document.observe("xwiki:docextra:loaded",this.addEditListenersInTab.bindAsEventListener(this)),document.observe("xwiki:docextra:loaded",this.addValidateListenersInTab.bindAsEventListener(this)),require(["jquery"],d=>{d(document).on("click","blockquote.annotatedText",e=>{if(this.fetchedAnnotations)this.setAnnotationVisibility(!0),this.toggleAnnotations(this.displayingAnnotations);else{this.fetchAnnotations(!0);e.preventDefault();const h=setInterval(()=>
{this.fetchedAnnotations&&(clearInterval(h),window.location=d(e.target).parents("a").attr("href"))})}})}),document.observe("xwiki:annotation:tab:deleted",this.refreshAnnotationsOnCommentDelete.bindAsEventListener(this)),this.registerAddAnnotationShortcut(),this.registerToggleAnnotationsShortcut(),this.registerCloseDialogShortcut(),this.selectionService=new f.Selection(this.annotatedElement),document.observe("xwiki:annotations:filter:changed",this.onFilterChange.bindAsEventListener(this)),this.annotatedElement.observe("xwiki:actions:edit",
this.beforeInPlaceEdit.bindAsEventListener(this)),this.annotatedElement.observe("xwiki:actions:view",this.afterInPlaceEdit.bindAsEventListener(this)),"#edit"===window.location.hash||"#translate"===window.location.hash?this.displayingAnnotations=c:c&&("xwiki/1.0"!=f.docsyntax?this.fetchAnnotations(!0):new f.widgets.Notification("Annotations are not available for pages written in XWiki/1.0 syntax.","warning"))):c&&new f.widgets.Notification("Annotations could not be loaded because the content is not available.",
"warning")},beforeInPlaceEdit:function(){this.shouldDisplayAnnotationsAfterInPlaceEdit=this.displayingAnnotations;this.toggleAnnotations(!1);this.settingsPanel?.addClassName("hidden");$("tmAnnotationsTrigger")?.up("li")?.addClassName("disabled")},afterInPlaceEdit:function(){$("tmAnnotationsTrigger")?.up("li")?.removeClassName("disabled");this.fetchedAnnotations=!1;this.shouldDisplayAnnotationsAfterInPlaceEdit&&this.fetchAnnotations(!0)},hookMenuButton:function(){var a=$("tmAnnotationsTrigger");a&&
a.observe("click",this.toggleSettingsPanel.bind(this))},setAnnotationVisibility:function(a){this.displayingAnnotations=a;this.displayAnnotationsCheckbox&&(this.displayAnnotationsCheckbox.checked=a)},toggleSettingsPanel:function(a){var b=a.element();a.stop();b.disabled||b.up("li")?.hasClassName("disabled")||(window.document.body.hasClassName("skin-flamingo")&&$("tmMoreActions").removeClassName("open"),this.settingsPanel?this.settingsPanel.toggleClassName("hidden"):new Ajax.Request("/xwiki/bin/view/AnnotationCode/Settings?xpage\x3dplain",
{parameters:{target:f.currentWiki+":"+f.currentSpace+"."+f.currentPage},onCreate:function(){b.disabled=!0;b._x_notification=new f.widgets.Notification("Loading annotation settings","inprogress")},onSuccess:function(c){if(window.document.body.hasClassName("skin-flamingo")){var d=$$(".xcontent \x3e hr")[0];d.insert({after:c.responseText});this.settingsPanel=d.next()}else $("contentmenu").insert({after:c.responseText}),this.settingsPanel=$("contentmenu").next();this.settingsPanel.fire("xwiki:annotations:settings:loaded");
b._x_notification.hide();this.displayAnnotationsCheckbox=$("annotationsdisplay");this.displayAnnotationsCheckbox.checked=this.displayingAnnotations;this.attachSettingsListeners()}.bind(this),onFailure:function(c){b._x_notification.replace(new f.widgets.Notification("Failed:"+(c.statusText||"Server not responding"),"error",{timeout:5}))},on0:function(c){c.request.options.onFailure(c)},onComplete:function(){b.disabled=!1}}))},attachSettingsListeners:function(){this.displayAnnotationsCheckbox.observe("click",
function(a){a=this.displayAnnotationsCheckbox.checked;this.displayAnnotationsCheckbox.disabled||(this.displayAnnotationsCheckbox.disabled=!0,!this.fetchedAnnotations&&a?this.fetchAnnotations(!0):(this.toggleAnnotations(a),this.displayAnnotationsCheckbox.disabled=!1))}.bindAsEventListener(this))},toggleAnnotations:function(a){this.displayHighlight&&this.annotatedElement.select(".annotation").invoke("toggleClassName","annotation-highlight",!!a);this.annotatedElement.select(".annotation-marker").invoke("toggleClassName",
"hidden",!a);this.setAnnotationVisibility(a);if(!a)for(;this.bubbles.length;)this.closeOpenBubble()},toggleAnnotationHighlight:function(a,b){this.annotatedElement.select(".annotation.ID"+a).invoke("toggleClassName","annotation-highlight",!!b)},onFilterChange:function(a){a.memo&&(this.currentFilter=a.memo);this.displayAnnotationsCheckbox&&this.displayAnnotationsCheckbox.checked&&this.fetchAnnotations(!0)},getExtraFields:function(){return[]},getFilter:function(){return this.currentFilter},prepareRequestParameters:function(a){for(var b=
this.getFilter(),c=0;c<b.length;c++){var d=b[c],e="filter_"+d.name;a.get(e)||a.set(e,[]);a.get(e).push(d.value)}b=this.getExtraFields();b.length&&a.set("request_field",[]);for(c=0;c<b.length;c++)a.get("request_field").push(b[c]);return a},fetchAnnotations:function(a,b){require(["xwiki-meta"],function(c){new Ajax.Request(c.restURL+"/annotations?media\x3djson",{method:"GET",parameters:this.prepareRequestParameters(new Hash),onCreate:function(){this._x_notification=new f.widgets.Notification("Loading annotated page",
"inprogress")}.bind(this),onSuccess:function(d){this.checkResponseCodeAndFail(d)||(this._x_notification.hide(),this.loadAnnotations(d.responseJSON.annotatedContent,a,!1,b),this.fetchedAnnotations=!0,this.setAnnotationVisibility(a))}.bind(this),onFailure:function(d){this._x_notification.replace(new f.widgets.Notification("Failed:"+(d.statusText||"Server not responding"),"error",{timeout:5}));this.setAnnotationVisibility(!1)}.bind(this),on0:function(d){d.request.options.onFailure(d)}.bind(this),onComplete:function(){this.displayAnnotationsCheckbox&&
(this.displayAnnotationsCheckbox.disabled=!1)}.bind(this)})}.bind(this))},checkResponseCodeAndFail:function(a){if(a.responseJSON&&null!=a.responseJSON.responseCode&&0==a.responseJSON.responseCode)return!1;a.statusText=a.responseJSON?a.responseJSON.responseMessage:"Wrongly formatted server response";a.request.options.onFailure(a);return!0},addAnnotationsMarkup:function(a){a.each(function(b){this.addAnnotationMarkup(b)}.bind(this))},addAnnotationMarkup:function(a){var b=a.fields.find(d=>"plainTextStartOffset"==
d.name),c=a.fields.find(d=>"plainTextEndOffset"==d.name);if(null===b.value||null===c.value)return!1;b=this.getDOMRange(this.annotatedElement,b.value,c.value);b=this.fixRangeEndPoints(b);this.getTextNodesInRange(b).forEach(d=>this.markAnnotation(d,a));b=this.annotatedElement.select("[class~\x3dID"+a.annotationId+"]");b.length&&(b=b[b.length-1],c=new Element("span",{id:"ID"+a.annotationId,"class":"hidden annotation-marker "+a.state}),b.insert({after:c}),c.observe("click",this.onMarkerClick.bindAsEventListener(this,
a.annotationId)))},markAnnotation:function(a,b){var c=document.createElement("span");c.addClassName("annotation");c.addClassName("ID"+b.annotationId);a.parentElement.replaceChild(c,a);c.appendChild(a)},fixRangeEndPoints:function(a){var b=new Range;0<a.endOffset&&a.endOffset<a.endContainer.length&&a.endContainer.splitText(a.endOffset);0<a.endOffset?b.setEndAfter(a.endContainer):b.setEndBefore(a.endContainer);0<a.startOffset&&a.startOffset<a.startContainer.length&&a.startContainer.splitText(a.startOffset);
0<a.startOffset?b.setStartAfter(a.startContainer):b.setStartBefore(a.startContainer);return b},getDOMRange:function(a,b,c){b=this.getTextNodeAtPlainTextOffset(a,b,!0);a=this.getTextNodeAtPlainTextOffset(a,c,!1);c=new Range;c.setStart(b.node,b.offset);c.setEnd(a.node,a.offset);return c},getTextNodeAtPlainTextOffset:function(a,b,c){a=a.childNodes;var d=0;for(let g=0;g<a.length;g++){var e=a[g];if(3==e.nodeType){var h=d;d+=e.textContent.replace(/\s/g,"").length;if(c&&b<d||!c&&b<=d)return{node:e,offset:this.getNodeSpecificOffset(e,
b-h,c)}}else if(0<e.childNodes.length){e=this.getTextNodeAtPlainTextOffset(e,b-d,c);if(e.node)return e;d+=e.offset}}return{offset:d}},getNodeSpecificOffset:function(a,b,c){a=Array.from(a.textContent);for(let d=0;d<a.length;d++){if(0==b&&(!c||c&&!/\s/.test(a[d])))return d;/\s/.test(a[d])||b--}return a.length},getTextNodesInRange:function(a){for(var b=document.createNodeIterator(a.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode:function(e){if(/\S/.test(e.data))return NodeFilter.FILTER_ACCEPT}}),
c=[],d=document.createRange();b.nextNode()&&(d.selectNode(b.referenceNode),-1===d.compareBoundaryPoints(Range.START_TO_START,a)||(c.push(b.referenceNode),0!==d.compareBoundaryPoints(Range.END_TO_END,a))););return c},removeAnnotationsAndSelectionMarkups:function(){document.querySelectorAll("span.annotation, span.selection-highlight").forEach(a=>a.replaceWith(...a.childNodes));document.querySelectorAll("span.annotation-marker").forEach(a=>a.remove());this.fetchedAnnotations=!1},reloadTab:function(a){var b=
$(this.annTabname+"pane");b&&(b.update(""),b.addClassName("empty"),b.hasClassName("hidden")||f.displayDocExtra(this.annTabname,this.annTabTemplate,a))},addDeleteListenersInTab:function(){$$("#Annotationspane .annotation a.delete").each(function(a){this.addDeleteListener(a)}.bind(this))},addEditListenersInTab:function(){$$("#Annotationspane .annotation a.edit").each(function(a){var b=a.up(".annotation"),c=b.id.substring(16);this.addEditListener(a,c,b.up())}.bind(this))},addValidateListenersInTab:function(){$$(".annotation a.validate").each(function(a){var b=
a.up(".annotation"),c=b.id.substring(16);this.addValidateListener(a,c,b)}.bind(this))},addDeleteListener:function(a,b,c){a.observe("click",function(d){a.blur();d.stop();a.disabled||new f.widgets.ConfirmedAjaxRequest(a.href,{parameters:this.prepareRequestParameters(new Hash),onCreate:function(){a.disabled=!0},onSuccess:function(e){this.checkResponseCodeAndFail(e)||(b&&this.hideBubble(c),this.fetchedAnnotations=!0,this.loadAnnotations(e.responseJSON.annotatedContent,this.displayingAnnotations,!b,!0))}.bind(this),
onComplete:function(){a.disabled=!1}},{confirmationText:"Are you sure you want to delete this annotation?",progressMessageText:"Deleting annotation...",successMessageText:"Annotation deleted",failureMessageText:"Failed to delete annotation:"})}.bindAsEventListener(this))},addValidateListener:function(a,b,c,d){a.observe("click",function(e){a.blur();e.stop();this.updateAnnotationAsync(c,b,d,a.href,"POST",new Hash({state:"SAFE",originalSelection:""}),{successText:"Annotation validated.",failureText:"Failed:"})}.bindAsEventListener(this))},
addEditListener:function(a,b,c,d){a.observe("click",function(e){a.blur();e.stop();a.disabled||require(["xwiki-meta"],function(h){new Ajax.Request(f.currentDocument.getURL("get"),{parameters:{sheet:"AnnotationCode.EditForm",id:b},onCreate:function(){c.originalContentHTML=c.innerHTML;a.disabled=!0;c.update(new Element("div",{"class":"loading"}))},onSuccess:function(g){this.fillEditForm(c,g.responseText,b,d)}.bind(this),onFailure:function(g){this._x_notification=new f.widgets.Notification("annotations.action.edit.form.loaderror"+
(g.statusText||"Server not responding"),"error",{timeout:5});this.fillViewPanel(c,c.originalContentHTML,b,d)}.bind(this),on0:function(g){g.request.options.onFailure(g)}.bind(this),onComplete:function(){a.disabled=!1}})}.bind(this))}.bindAsEventListener(this))},onMarkerClick:function(a,b){var c="annotation-bubble-"+b,d=$(c);this.displayHighlight||this.toggleAnnotationHighlight(b,!d);d?this.hideBubble(d):(d=this.displayLoadingBubble(a.element().cumulativeOffset().top,a.element().cumulativeOffset().left),
d.writeAttribute("id",c),this.fetchAndShowAnnotationDetails(b,d))},fetchAndShowAnnotationDetails:function(a,b){require(["xwiki-meta"],function(c){new Ajax.Request(f.currentDocument.getURL("get"),{parameters:{id:a,sheet:"AnnotationCode.DisplayForm"},onSuccess:function(d){this.fillViewPanel(b,d.responseText,a,!0)}.bind(this),onFailure:function(d){d=d.statusText||"Server not responding";this.hideBubble(newBubble);this._x_notification=new f.widgets.Notification("Failed:"+d,"error",{timeout:5})}.bind(this),
on0:function(d){d.request.options.onFailure(d)}.bind(this)})}.bind(this))},displayLoadingBubble:function(a,b){var c=new Element("div",{"class":"annotation-bubble"});c.insert({top:new Element("div",{"class":"loading"})});c.style.top=a+"px";c.style.left="-100%";document.body.insert({bottom:c});this.bubbles.push(c);a=getComputedStyle(c);a=c.offsetWidth+parseInt(a.marginLeft)+parseInt(a.marginRight);b<a||b+a<window.innerWidth?c.style.left=b+"px":(c.style.left=b-a+"px",c.toggleClassName("annotation-bubble-position-left"));
return c},displayAnnotationViewBubble:function(a){},safeUpdate:function(a,b){if(!a.parentNode)return!1;a.update(b);document.fire("xwiki:dom:updated",{elements:[a]});return!0},fillEditForm:function(a,b,c,d){this.safeUpdate(a,b)&&(a.stopObserving("mouseout"),(b=a.down("a.delete"))&&this.addDeleteListener(b,d,a),(b=a.down("a.validate"))&&this.addValidateListener(b,c,a,d),a.down("form").focusFirstElement(),a.down("input[type\x3dsubmit]").observe("click",this.onAnnotationEdit.bindAsEventListener(this,
a,c,d)),a.down("input[type\x3dreset]").observe("click",function(e){d?this.hideBubble(a):this.fillViewPanel(a,a.originalContentHTML,c,!1)}.bindAsEventListener(this)))},onAnnotationEdit:function(a,b,c,d){a.stop();document.fire("xwiki:actions:beforeSave");a=b.down("form");var e=new Hash(a.serialize(!0));this.updateAnnotationAsync(b,c,d,a.action,a.method,e,{successText:"Annotation updated.",failureText:"Failed:"})},updateAnnotationAsync:function(a,b,c,d,e,h,g){new Ajax.Request(d,{method:e,parameters:this.prepareRequestParameters(h),
onCreate:function(){a.parentNode&&a.update(new Element("div",{"class":"loading"}))},onSuccess:function(k){this.checkResponseCodeAndFail(k)||(this._x_notification=new f.widgets.Notification(g.successText,"done"),c&&this.hideBubble(a),this.fetchedAnnotations=!0,this.loadAnnotations(k.responseJSON.annotatedContent,this.displayingAnnotations,!c))}.bind(this),onFailure:function(k){this._x_notification.replace(new f.widgets.Notification(g.failureText+(k.statusText||"Server not responding"),"error",{timeout:5}));
c?this.hideBubble(a):this.fillViewPanel(a,a.originalContentHTML,b,!1)}.bind(this),on0:function(k){k.request.options.onFailure(k)}})},fillViewPanel:function(a,b,c,d){if(this.safeUpdate(a,b)&&((b=a.down("a.delete"))&&this.addDeleteListener(b,d,a),(b=a.down("a.validate"))&&this.addValidateListener(b,c,a,d),(b=a.down("a.edit"))&&this.addEditListener(b,c,a,d),d=a.down("a.reply"))){var e=$$("#Commentspane #xwikicomment_"+c+" a.commentreply")[0];e?d.observe("click",function(h){h.stop();e=$$("#Commentspane #xwikicomment_"+
c+" a.commentreply")[0];e.focus();e.click();e.scrollIntoView();a.blur()}):d.hide()}},hideBubble:function(a){a.parentNode&&(document.fire("xwiki:actions:cancel"),a.remove(),a=this.bubbles.indexOf(a),0<=a&&this.bubbles.splice(a,1))},registerShortcuts:function(a,b){for(var c=0;c<a.length;++c)shortcut.add(a[c],b.bindAsEventListener(this))},unregisterShortcuts:function(a){for(var b=0;b<a.length;++b)shortcut.remove(a[b])},registerAddAnnotationShortcut:function(){this.registerShortcuts(this.addAnnotationShortcuts,
this.onAddAnnotationShortcut)},unregisterAddAnnotationShortcut:function(){this.unregisterShortcuts(this.addAnnotationShortcuts)},registerCloseDialogShortcut:function(){this.registerShortcuts(this.closeDialogShortcuts,this.closeOpenBubble)},registerToggleAnnotationsShortcut:function(){this.registerShortcuts(this.toggleAnnotationsShortcuts,this.onToggleAnnotationsShortcut)},onToggleAnnotationsShortcut:function(){$("tmAnnotationsTrigger")?.up("li")?.hasClassName("disabled")||(this.fetchedAnnotations?
(this.setAnnotationVisibility(!this.displayingAnnotations),this.toggleAnnotations(this.displayingAnnotations),this.displayingAnnotations||this.removeAnnotationsAndSelectionMarkups()):this.fetchAnnotations(!0))},closeOpenBubble:function(){if(0<this.bubbles.length){var a=this.bubbles[this.bubbles.length-1];a==this.createPanel?this.hideAnnotationCreationForm():this.hideBubble(a)}},onAddAnnotationShortcut:function(){if("xwiki/1.0"==f.docsyntax)new f.widgets.Notification("Annotations are not available for pages written in XWiki/1.0 syntax.",
"warning");else if(!$("tmAnnotationsTrigger")?.up("li")?.hasClassName("disabled")){this.selectionService.computeSelection();var a=this.selectionService.selectionText;a?(this.selectionService.computeContext(),require(["xwiki-meta"],function(b){new Ajax.Request(f.currentDocument.getURL("get"),{parameters:{selection:a,selectionContext:this.selectionService.selectionContext,selectionOffset:this.selectionService.selectionOffset,sheet:"AnnotationCode.CreateForm"},onCreate:function(){this.displayAnnotationCreationForm()}.bind(this),
onSuccess:function(c){this.fillCreateForm(this.createPanel,c.responseText)}.bind(this),onFailure:function(c){this._x_notification=new f.widgets.Notification("Failed:"+(c.statusText||"Server not responding"),"error",{timeout:5});this.hideAnnotationCreationForm()}.bind(this),on0:function(c){c.request.options.onFailure(c)}.bind(this)})}.bind(this))):new f.widgets.Notification("Please select a non-empty text in the page content.","error",{timeout:5})}},displayAnnotationCreationForm:function(){this.selectionService.highlightSelection("#FFEE99");
var a=this.selectionService.getPositionNextToSelection();this.createPanel=this.displayLoadingBubble(a.top,a.left);this.unregisterAddAnnotationShortcut()},fillCreateForm:function(a,b){this.safeUpdate(this.createPanel,b)&&(this.createPanel.select("form").first().focusFirstElement(),this.createPanel.down("input[type\x3dsubmit]").observe("click",this.onAnnotationAdd.bindAsEventListener(this)),this.createPanel.down("input[type\x3dreset]").observe("click",function(){this.hideAnnotationCreationForm()}.bind(this)))},
hideAnnotationCreationForm:function(a){this.hideBubble(this.createPanel);a||this.selectionService.removeSelectionHighlight();this.registerAddAnnotationShortcut()},onAnnotationAdd:function(a){a.stop();document.fire("xwiki:actions:beforeSave");var b=this.createPanel.down("form");a=new Hash(b.serialize(!0));new Ajax.Request(b.action,{method:b.method,parameters:this.prepareRequestParameters(a),onCreate:function(){this.createPanel.update(new Element("div",{"class":"loading"}))}.bind(this),onSuccess:function(c){this.checkResponseCodeAndFail(c)||
(this.setAnnotationVisibility(!0),this.loadAnnotations(c.responseJSON.annotatedContent,!0),this.fetchedAnnotations=!0,b._x_notification=new f.widgets.Notification("Annotation added.","done"),this.hideAnnotationCreationForm(!0))}.bind(this),onFailure:function(c){this.hideAnnotationCreationForm();this._x_notification=new f.widgets.Notification("Failed:"+(c.statusText||"Server not responding"),"error",{timeout:5})}.bind(this),on0:function(c){c.request.options.onFailure(c)}})},refreshAnnotationsOnCommentDelete:function(a){this.displayingAnnotations?
this.fetchAnnotations(!0,!0):this.fetchedAnnotations=!1}});return f}(XWiki||{});require.config({paths:{"fast-diff":"/xwiki/webjars/wiki%3Agsoc/fast-diff/1.3.0/diff"}});define("node-module",["jquery"],function(f){return{load:function(a,b,c,d){f.get(b.toUrl(a+".js"),function(e){c.fromText(`define(function(require, exports, module) {${e}});`)},"text")}}});
define("xwiki-text-offset-updater",["jquery","node-module!fast-diff"],function(f,a){return{getChanges:function(b,c){return a(b,c)},findOffsetAfterChanges:function(b,c){for(var d=0,e=c,h=0;h<b.length&&d<c;h++){var g=b[h];0>g[0]?(e=d+g[1].length>c?e-(c-d):e-g[1].length,d+=g[1].length):0<g[0]?e+=g[1].length:d+=g[1].length}return e}}});
require(["jquery","xwiki-text-offset-updater","xwiki-events-bridge"],function(f,a){f(function(){"view"==XWiki.contextaction&&f("xwikicontent")&&(f.extend(XWiki.Annotation.prototype,{loadAnnotations:function(b,c,d,e){if(b.annotations.length||e)this.removeAnnotationsAndSelectionMarkups(),this.updateAnnotationsOffsets(b),this.addAnnotationsMarkup(b.annotations),f(document).trigger("xwiki:dom:updated",{elements:[this.annotatedElement]}),this.reloadTab(d),c&&this.toggleAnnotations(!0)},updateAnnotationsOffsets:function(b){var c=
f("\x3cdiv\x3e\x3c/div\x3e").html(b.content).text().replace(/\s/g,""),d=f("#xwikicontent").text().replace(/\s/g,""),e=a.getChanges(c,d);b.annotations.forEach(h=>this.updateAnnotationOffsets(h,e))},updateAnnotationOffsets:function(b,c){var d=b.fields.find(e=>"plainTextStartOffset"==e.name);b=b.fields.find(e=>"plainTextEndOffset"==e.name);null!==d.value&&null!==b.value&&(d.value=a.findOffsetAfterChanges(c,parseInt(d.value)),b.value=a.findOffsetAfterChanges(c,parseInt(b.value)))}}),0>[].indexOf(XWiki.currentSpace)&&
new XWiki.Annotation(!0,f("#xwikicontent")[0],!1))})});