var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(e){return e.raw=e};$jscomp.createTemplateTagFirstArgWithRaw=function(e,a){e.raw=a;return e};$jscomp.arrayIteratorImpl=function(e){var a=0;return function(){return a<e.length?{done:!1,value:e[a++]}:{done:!0}}};$jscomp.arrayIterator=function(e){return{next:$jscomp.arrayIteratorImpl(e)}};$jscomp.makeIterator=function(e){var a="undefined"!=typeof Symbol&&Symbol.iterator&&e[Symbol.iterator];return a?a.call(e):$jscomp.arrayIterator(e)};
$jscomp.arrayFromIterator=function(e){for(var a,b=[];!(a=e.next()).done;)b.push(a.value);return b};$jscomp.arrayFromIterable=function(e){return e instanceof Array?e:$jscomp.arrayFromIterator($jscomp.makeIterator(e))};$jscomp.findInternal=function(e,a,b){e instanceof String&&(e=String(e));for(var c=e.length,d=0;d<c;d++){var f=e[d];if(a.call(b,f,d,e))return{i:d,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;
$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(e,a,b){if(e==Array.prototype||e==Object.prototype)return e;e[a]=b.value;return e};
$jscomp.getGlobal=function(e){e=["object"==typeof globalThis&&globalThis,e,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var a=0;a<e.length;++a){var b=e[a];if(b&&b.Math==Math)return b}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);$jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};
$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(e,a){var b=$jscomp.propertyToPolyfillSymbol[a];if(null==b)return e[a];b=e[b];return void 0!==b?b:e[a]};$jscomp.polyfill=function(e,a,b,c){a&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(e,a,b,c):$jscomp.polyfillUnisolated(e,a,b,c))};
$jscomp.polyfillUnisolated=function(e,a,b,c){b=$jscomp.global;e=e.split(".");for(c=0;c<e.length-1;c++){var d=e[c];if(!(d in b))return;b=b[d]}e=e[e.length-1];c=b[e];a=a(c);a!=c&&null!=a&&$jscomp.defineProperty(b,e,{configurable:!0,writable:!0,value:a})};
$jscomp.polyfillIsolated=function(e,a,b,c){var d=e.split(".");e=1===d.length;c=d[0];c=!e&&c in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var f=0;f<d.length-1;f++){var g=d[f];if(!(g in c))return;c=c[g]}d=d[d.length-1];b=$jscomp.IS_SYMBOL_NATIVE&&"es6"===b?c[d]:null;a=a(b);null!=a&&(e?$jscomp.defineProperty($jscomp.polyfills,d,{configurable:!0,writable:!0,value:a}):a!==b&&(void 0===$jscomp.propertyToPolyfillSymbol[d]&&($jscomp.propertyToPolyfillSymbol[d]=$jscomp.IS_SYMBOL_NATIVE?$jscomp.global.Symbol(d):
$jscomp.POLYFILL_PREFIX+d),$jscomp.defineProperty(c,$jscomp.propertyToPolyfillSymbol[d],{configurable:!0,writable:!0,value:a})))};$jscomp.polyfill("Array.prototype.find",function(e){return e?e:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");
$jscomp.polyfill("Array.from",function(e){return e?e:function(a,b,c){b=null!=b?b:function(h){return h};var d=[],f="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];if("function"==typeof f){a=f.call(a);for(var g=0;!(f=a.next()).done;)d.push(b.call(c,f.value,g++))}else for(f=a.length,g=0;g<f;g++)d.push(b.call(c,a[g],g));return d}},"es6","es3");
var XWiki=function(e){e.Selection=Class.create({container:!1,selectionText:!1,selectionContext:!1,selectionOffset:!1,range:!1,highlightWrappers:!1,selectionParent:!1,selectionParentInnerHTML:!1,offsetX:!1,offsetY:!1,step:5,wordStep:1,initialize:function(a){a&&(this.container=a,window.getSelection||this.container.observe("mousedown",function(b){this.offsetX=b.pointerX();this.offsetY=b.pointerY()}.bindAsEventListener(this)))},computeSelection:function(){this.selectionParentInnerHTML=this.selectionParent=
this.highlightWrappers=this.selectionOffset=this.selectionContext=this.range=this.selectionText=!1;if(this.container){if(window.getSelection){if(0==window.getSelection().rangeCount)return;this.range=window.getSelection().getRangeAt(0);if(!this.isDescendantOrSelf(this.container,this.range.commonAncestorContainer))return;this.selectionText=this.range.toString()}else if("Text"==document.selection.type){this.range=document.selection.createRange();if(!this.isDescendantOrSelf(this.container,this.range.parentElement()))return;
this.selectionText=this.range.text}""==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)if(window.getSelection){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))}else this.selectionParent=this.range.parentElement(),this.selectionParentInnerHTML=this.selectionParent.innerHTML,this.range.execCommand("BackColor",!1,a)},getRangeTextNodes:function(){var a=this.range.startContainer,b=this.range.endContainer,c=this.range.startOffset,d=this.range.endOffset,f=this.getFirstLeafInRange(this.range),g=this.getLastLeafInRange(this.range);
f=this.getLeafsBetween(f,g).findAll(function(h){return 3==h.nodeType});a==f[0]&&0!=c&&(f[0]=a.splitText(c),a==b&&(d-=c,b=f[0]));b==f[f.length-1]&&d!=b.length&&(b=b.splitText(d));return f},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(){window.getSelection?this.highlightWrappers.each(function(a){a.replace(a.innerHTML)}):this.selectionParent.update(this.selectionParentInnerHTML)},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="",f=this.range.toString(),g=0,h=0;d!=c||b!=a;){var k=this.container.textContent.indexOf(f);if(-1==this.container.textContent.indexOf(f,k+1))break;g=Math.min(a.length,g+this.step);h=Math.min(c.length,h+this.step);
d=c.substring(0,h);b=a.substring(a.length-g,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 f=b.text.length;b.moveStart("word",-1);this.isDescendantOrSelf(this.container,b.parentElement())?(c+=b.text.length-f,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 e}(XWiki||{});
XWiki=function(e){e.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)),document.observe("xwiki:annotation:tab:deleted",this.refreshAnnotationsOnCommentDelete.bindAsEventListener(this)),this.registerAddAnnotationShortcut(),this.registerToggleAnnotationsShortcut(),this.registerCloseDialogShortcut(),this.selectionService=new e.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"!=e.docsyntax?this.fetchAnnotations(!0):new e.widgets.Notification("Annotations are not available for pages written in XWiki/1.0 syntax.",
"warning"))):c&&new e.widgets.Notification("Annotations could not be loaded because the content is not available.","warning")},beforeInPlaceEdit:function(){this.shouldDisplayAnnotationsAfterInPlaceEdit=this.displayingAnnotations;this.toggleAnnotations(!1);var a;null==(a=this.settingsPanel)||a.addClassName("hidden");var b,c;null==(b=$("tmAnnotationsTrigger"))||null==(c=b.up("li"))||c.addClassName("disabled")},afterInPlaceEdit:function(){var a,b;null==(a=$("tmAnnotationsTrigger"))||null==(b=a.up("li"))||
b.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();var c;b.disabled||(null==(c=b.up("li"))?0:c.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:e.currentWiki+":"+e.currentSpace+"."+e.currentPage},onCreate:function(){b.disabled=!0;b._x_notification=new e.widgets.Notification("Loading annotation settings","inprogress")},onSuccess:function(d){if(window.document.body.hasClassName("skin-flamingo")){var f=
$$(".xcontent \x3e hr")[0];f.insert({after:d.responseText});this.settingsPanel=f.next()}else $("contentmenu").insert({after:d.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(d){var f=d.statusText;if(""==d.statusText||12031==
d.status)f="Server not responding";b._x_notification.replace(new e.widgets.Notification("Failed:"+f,"error",{timeout:5}))},on0:function(d){d.request.options.onFailure(d)},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],f="filter_"+d.name;a.get(f)||a.set(f,[]);a.get(f).push(d.value)}b=this.getExtraFields();0<b.size()&&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 e.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){var f=d.statusText;if(""==d.statusText||12031==d.status)f="Server not responding";this._x_notification.replace(new e.widgets.Notification("Failed:"+f,"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=this,c=a.fields.find(function(f){return"plainTextStartOffset"==f.name}),d=a.fields.find(function(f){return"plainTextEndOffset"==
f.name});if(null===c.value||null===d.value)return!1;c=this.getDOMRange(this.annotatedElement,c.value,d.value);c=this.fixRangeEndPoints(c);this.getTextNodesInRange(c).forEach(function(f){return b.markAnnotation(f,a)});c=this.annotatedElement.select("[class~\x3dID"+a.annotationId+"]");0!=c.size()&&(c=c[c.size()-1],d=new Element("span",{id:"ID"+a.annotationId,"class":"hidden annotation-marker "+a.state}),c.insert({after:d}),d.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.parentNode.replaceChild(c,a);c.appendChild(a)},fixRangeEndPoints:function(a){var b=document.createRange();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=document.createRange();c.setStart(b.node,b.offset);c.setEnd(a.node,a.offset);return c},getTextNodeAtPlainTextOffset:function(a,b,c){a=a.childNodes;for(var d,f=0,g=0;g<a.length;g++)if(d=a[g],3==d.nodeType){var h=f;f+=d.textContent.replace(/\s/g,"").length;if(c&&b<f||!c&&b<=f)return{node:d,offset:this.getNodeSpecificOffset(d,
b-h,c)}}else if(0<d.childNodes.length){d=this.getTextNodeAtPlainTextOffset(d,b-f,c);if(d.node)return d;f+=d.offset}return{offset:f}},getNodeSpecificOffset:function(a,b,c){a=Array.from(a.textContent);for(var 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,function(f){if(/\S/.test(f.data))return NodeFilter.FILTER_ACCEPT},!1),c=[],
d=document.createRange();(node=b.nextNode())&&(d.selectNode(node),-1===d.compareBoundaryPoints(Range.START_TO_START,a)||(c.push(node),0!==d.compareBoundaryPoints(Range.END_TO_END,a))););return c},reloadTab:function(a){var b=$(this.annTabname+"pane");b&&(b.update(""),b.addClassName("empty"),b.hasClassName("hidden")||e.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 e.widgets.ConfirmedAjaxRequest(a.href,{parameters:this.prepareRequestParameters(new Hash),
onCreate:function(){a.disabled=!0},onSuccess:function(f){this.checkResponseCodeAndFail(f)||(b&&this.hideBubble(c),this.fetchedAnnotations=!0,this.loadAnnotations(f.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(f){a.blur();f.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(f){a.blur();f.stop();a.disabled||require(["xwiki-meta"],function(g){new Ajax.Request("/xwiki/bin/view/AnnotationCode/EditForm",{parameters:{xpage:"plain",wiki:e.currentWiki,
space:e.currentSpace,page:e.currentPage,reference:g.document,id:b},onCreate:function(){c.originalContentHTML=c.innerHTML;a.disabled=!0;c.update(new Element("div",{"class":"loading"}))},onSuccess:function(h){this.fillEditForm(c,h.responseText,b,d)}.bind(this),onFailure:function(h){var k=h.statusText;if(""==h.statusText||12031==h.status)k="Server not responding";this._x_notification=new e.widgets.Notification("annotations.action.edit.form.loaderror"+k,"error",{timeout:5});this.fillViewPanel(c,c.originalContentHTML,
b,d)}.bind(this),on0:function(h){h.request.options.onFailure(h)}.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("/xwiki/bin/view/AnnotationCode/DisplayForm",{parameters:{id:a,xpage:"plain",wiki:e.currentWiki,space:e.currentSpace,page:e.currentPage,reference:c.document},onSuccess:function(d){this.fillViewPanel(b,d.responseText,a,!0)}.bind(this),onFailure:function(d){var f=d.statusText;if(""==d.statusText||12031==d.status)f="Server not responding";this.hideBubble(newBubble);this._x_notification=new e.widgets.Notification("Failed:"+f,"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"})});document.body.insert({bottom:c});c.toggleClassName("hidden");c.style.left=b+"px";c.style.top=a+"px";c.toggleClassName("hidden");this.bubbles.push(c);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(f){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 f=new Hash(a.serialize(!0));this.updateAnnotationAsync(b,c,d,a.action,a.method,f,{successText:"Annotation updated.",failureText:"Failed:"})},updateAnnotationAsync:function(a,b,c,d,f,g,h){new Ajax.Request(d,{method:f,parameters:this.prepareRequestParameters(g),onCreate:function(){a.parentNode&&a.update(new Element("div",{"class":"loading"}))},onSuccess:function(k){this.checkResponseCodeAndFail(k)||
(this._x_notification=new e.widgets.Notification(h.successText,"done"),c&&this.hideBubble(a),this.fetchedAnnotations=!0,this.loadAnnotations(k.responseJSON.annotatedContent,this.displayingAnnotations,!c))}.bind(this),onFailure:function(k){var l=k.statusText;if(""==k.statusText||12031==k.status)l="Server not responding";this._x_notification.replace(new e.widgets.Notification(h.failureText+l,"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 f=$$("#Commentspane #xwikicomment_"+c+" a.commentreply")[0];f?d.observe("click",function(g){g.stop();f=$$("#Commentspane #xwikicomment_"+c+" a.commentreply")[0];f.focus();f.click();f.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.size();++c)shortcut.add(a[c],b.bindAsEventListener(this))},unregisterShortcuts:function(a){for(var b=0;b<a.size();++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(){var a,b;(null==(a=$("tmAnnotationsTrigger"))?0:null==(b=a.up("li"))?0:b.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"==e.docsyntax)new e.widgets.Notification("Annotations are not available for pages written in XWiki/1.0 syntax.","warning");else{var a,b;if(!(null==(a=$("tmAnnotationsTrigger"))?0:null==
(b=a.up("li"))?0:b.hasClassName("disabled"))){this.selectionService.computeSelection();var c=this.selectionService.selectionText;c?(this.selectionService.computeContext(),require(["xwiki-meta"],function(d){new Ajax.Request("/xwiki/bin/view/AnnotationCode/CreateForm",{parameters:{xpage:"plain",selection:c,selectionContext:this.selectionService.selectionContext,selectionOffset:this.selectionService.selectionOffset,reference:d.document},onCreate:function(){this.displayAnnotationCreationForm()}.bind(this),
onSuccess:function(f){this.fillCreateForm(this.createPanel,f.responseText)}.bind(this),onFailure:function(f){var g=f.statusText;if(""==f.statusText||12031==f.status)g="Server not responding";this._x_notification=new e.widgets.Notification("Failed:"+g,"error",{timeout:5});this.hideAnnotationCreationForm()}.bind(this),on0:function(f){f.request.options.onFailure(f)}.bind(this)})}.bind(this))):new e.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 e.widgets.Notification("Annotation added.","done"),this.hideAnnotationCreationForm(!0))}.bind(this),onFailure:function(c){this.hideAnnotationCreationForm();var d=c.statusText;if(""==c.statusText||12031==c.status)d="Server not responding";this._x_notification=new e.widgets.Notification("Failed:"+d,"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 e}(XWiki||{});require.config({paths:{"fast-diff":"/xwiki/webjars/wiki%3Awiki/fast-diff/1.2.0/diff"}});define("node-module",["jquery"],function(e){return{load:function(a,b,c,d){e.get(b.toUrl(a+".js"),function(f){c.fromText("define(function(require, exports, module) {"+f+"});")},"text")}}});
define("xwiki-text-offset-updater",["jquery","node-module!fast-diff"],function(e,a){return{getChanges:function(b,c){return a(b,c)},findOffsetAfterChanges:function(b,c){for(var d=0,f=c,g=0;g<b.length&&d<c;g++){var h=b[g];0>h[0]?(f=d+h[1].length>c?f-(c-d):f-h[1].length,d+=h[1].length):0<h[0]?f+=h[1].length:d+=h[1].length}return f}}});
require(["jquery","xwiki-text-offset-updater","xwiki-events-bridge"],function(e,a){e(function(){"view"==XWiki.contextaction&&e("xwikicontent")&&(e.extend(XWiki.Annotation.prototype,{loadAnnotations:function(b,c,d,f){if(0!=b.annotations.size()||f)this.removeAnnotationsAndSelectionMarkups(),this.updateAnnotationsOffsets(b),this.addAnnotationsMarkup(b.annotations),e(document).trigger("xwiki:dom:updated",{elements:[this.annotatedElement]}),this.reloadTab(d),c&&this.toggleAnnotations(!0)},updateAnnotationsOffsets:function(b){var c=
this,d=e("\x3cdiv\x3e\x3c/div\x3e").html(b.content).text().replace(/\s/g,""),f=e("#xwikicontent").text().replace(/\s/g,""),g=a.getChanges(d,f);b.annotations.forEach(function(h){return c.updateAnnotationOffsets(h,g)})},updateAnnotationOffsets:function(b,c){var d=b.fields.find(function(f){return"plainTextStartOffset"==f.name});b=b.fields.find(function(f){return"plainTextEndOffset"==f.name});null!==d.value&&null!==b.value&&(d.value=a.findOffsetAfterChanges(c,parseInt(d.value)),b.value=a.findOffsetAfterChanges(c,
parseInt(b.value)))},removeAnnotationsAndSelectionMarkups:function(){[].concat($jscomp.arrayFromIterable(document.querySelectorAll("span.annotation, span.selection-highlight"))).forEach(function(b){var c;return(c=e(b)).replaceWith.apply(c,$jscomp.arrayFromIterable(b.childNodes))});[].concat($jscomp.arrayFromIterable(document.querySelectorAll("span.annotation-marker"))).forEach(function(b){return b.remove()});this.fetchedAnnotations=!1}}),0>[].indexOf(XWiki.currentSpace)&&new XWiki.Annotation(!0,e("#xwikicontent")[0],
!1))})});