var XWiki=function(f){f.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,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(){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="",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)),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);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(){$("tmAnnotationsTrigger").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("/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(d){if(window.document.body.hasClassName("skin-flamingo")){var e=
$$(".xcontent \x3e hr")[0];e.insert({after:d.responseText});this.settingsPanel=e.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 e=d.statusText;if(""==d.statusText||12031==
d.status)e="Server not responding";b._x_notification.replace(new f.widgets.Notification("Failed:"+e,"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],e="filter_"+d.name;a.get(e)||a.set(e,[]);a.get(e).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 f.widgets.Notification("Loading annotated page","inprogress")}.bind(this),onSuccess:function(d){this.checkResponseCodeAndFail(d)||(this._x_notification.hide(),this.loadAnnotatedContent(d.responseJSON.annotatedContent,
a,!1,b),this.fetchedAnnotations=!0,this.setAnnotationVisibility(a))}.bind(this),onFailure:function(d){var e=d.statusText;if(""==d.statusText||12031==d.status)e="Server not responding";this._x_notification.replace(new f.widgets.Notification("Failed:"+e,"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},loadAnnotatedContent:function(a,b,c,d){if(a.annotations&&0<a.annotations.size()||d)this.annotatedElement.update(a.content),this.addAnnotationMarkers(a.annotations),document.fire("xwiki:dom:updated",{elements:[this.annotatedElement]}),
this.reloadTab(c);b&&this.toggleAnnotations(!0)},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.loadAnnotatedContent(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("/view/AnnotationCode/EditForm",{parameters:{xpage:"plain",wiki:f.currentWiki,space:f.currentSpace,page:f.currentPage,reference:h.document,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){var k=g.statusText;if(""==g.statusText||12031==g.status)k="Server not responding";this._x_notification=new f.widgets.Notification("annotations.action.edit.form.loaderror"+k,"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))},addAnnotationMarkers:function(a){a.each(function(b){var c=this.annotatedElement.select("[class~\x3dID"+b.annotationId+"]");if(0!=c.size()){c=c[c.size()-1];var d=new Element("span",{id:"ID"+b.annotationId,"class":"hidden annotation-marker "+b.state});c.insert({after:d});d.observe("click",this.onMarkerClick.bindAsEventListener(this,b.annotationId))}}.bind(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("/view/AnnotationCode/DisplayForm",{parameters:{id:a,xpage:"plain",wiki:f.currentWiki,space:f.currentSpace,page:f.currentPage,reference:c.document},onSuccess:function(d){this.fillViewPanel(b,d.responseText,a,!0)}.bind(this),
onFailure:function(d){var e=d.statusText;if(""==d.statusText||12031==d.status)e="Server not responding";this.hideBubble(newBubble);this._x_notification=new f.widgets.Notification("Failed:"+e,"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(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.loadAnnotatedContent(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 f.widgets.Notification(g.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 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.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.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{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("/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(e){this.fillCreateForm(this.createPanel,e.responseText)}.bind(this),onFailure:function(e){var h=e.statusText;if(""==e.statusText||12031==e.status)h="Server not responding";this._x_notification=new f.widgets.Notification("Failed:"+h,"error",{timeout:5});this.hideAnnotationCreationForm()}.bind(this),on0:function(e){e.request.options.onFailure(e)}.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.loadAnnotatedContent(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();
var d=c.statusText;if(""==c.statusText||12031==c.status)d="Server not responding";this._x_notification=new f.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 f}(XWiki||{});
document.observe("xwiki:dom:loaded",function(){"view"==XWiki.contextaction&&$("xwikicontent")&&0>[].indexOf(XWiki.currentSpace)&&new XWiki.Annotation(!0,$("xwikicontent"),!1)});