(function(){var$,Annotator,Delegator,LinkParser,Range,findChild,fn,functions,g,getNodeName,getNodePosition,gettext,simpleXPathJQuery,simpleXPathPure,util,_Annotator,_gettext,_i,_j,_len,_len1,_ref,_ref1,_t,__slice=[].slice,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(varkeyinparent){if(__hasProp.call(parent,key))child[key]=parent[key]}functionctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=newctor;child.__super__=parent.prototype;returnchild},__bind=function(fn,me){returnfunction(){returnfn.apply(me,arguments)}};simpleXPathJQuery=function(relativeRoot){varjq;jq=this.map(function(){varelem,idx,path,tagName;path="";elem=this;while(elem&&elem.nodeType===1&&elem!==relativeRoot){tagName=elem.tagName.replace(":","\\:");idx=$(elem.parentNode).children(tagName).index(elem)+1;idx="["+idx+"]";path="/"+elem.tagName.toLowerCase()+idx+path;elem=elem.parentNode}returnpath});returnjq.get()};simpleXPathPure=function(relativeRoot){vargetPathSegment,getPathTo,jq,rootNode;getPathSegment=function(node){varname,pos;name=getNodeName(node);pos=getNodePosition(node);return""+name+"["+pos+"]"};rootNode=relativeRoot;getPathTo=function(node){varxpath;xpath="";while(node!==rootNode){if(node==null){thrownewError("Called getPathTo on a node which was not a descendant of @rootNode. "+rootNode)}xpath=getPathSegment(node)+"/"+xpath;node=node.parentNode}xpath="/"+xpath;xpath=xpath.replace(/\/$/,"");returnxpath};jq=this.map(function(){varpath;path=getPathTo(this);returnpath});returnjq.get()};findChild=function(node,type,index){varchild,children,found,name,_i,_len;if(!node.hasChildNodes()){thrownewError("XPath error: node has no children!")}children=node.childNodes;found=0;for(_i=0,_len=children.length;_i<_len;_i++){child=children[_i];name=getNodeName(child);if(name===type){found+=1;if(found===index){returnchild}}}thrownewError("XPath error: wanted child not found.")};getNodeName=function(node){varnodeName;nodeName=node.nodeName.toLowerCase();switch(nodeName){case"#text":return"text()";case"#comment":return"comment()";case"#cdata-section":return"cdata-section()";default:returnnodeName}};getNodePosition=function(node){varpos,tmp;pos=0;tmp=node;while(tmp){if(tmp.nodeName===node.nodeName){pos++}tmp=tmp.previousSibling}returnpos};gettext=null;if(typeofGettext!=="undefined"&&Gettext!==null){_gettext=newGettext({domain:"annotator"});gettext=function(msgid){return_gettext.gettext(msgid)}}else{gettext=function(msgid){returnmsgid}}_t=function(msgid){returngettext(msgid)};if(!(typeofjQuery!=="undefined"&&jQuery!==null?(_ref=jQuery.fn)!=null?_ref.jquery:void0:void0)){console.error(_t("Annotator requires jQuery: have you included lib/vendor/jquery.js?"))}if(!(JSON&&JSON.parse&&JSON.stringify)){console.error(_t("Annotator requires a JSON implementation: have you included lib/vendor/json2.js?"))}$=jQuery.sub();$.flatten=function(array){varflatten;flatten=function(ary){varel,flat,_i,_len;flat=[];for(_i=0,_len=ary.length;_i<_len;_i++){el=ary[_i];flat=flat.concat(el&&$.isArray(el)?flatten(el):el)}returnflat};returnflatten(array)};$.plugin=function(name,object){returnjQuery.fn[name]=function(options){varargs;args=Array.prototype.slice.call(arguments,1);returnthis.each(function(){varinstance;instance=$.data(this,name);if(instance){returnoptions&&instance[options].apply(instance,args)}else{instance=newobject(this,options);return$.data(this,name,instance)}})}};$.fn.textNodes=function(){vargetTextNodes;getTextNodes=function(node){varnodes;if(node&&node.nodeType!==3){nodes=[];if(node.nodeType!==8){node=node.lastChild;while(node){nodes.push(getTextNodes(node));node=node.previousSibling}}returnnodes.reverse()}else{returnnode}};returnthis.map(function(){return$.flatten(getTextNodes(this))})};$.fn.xpath=function(relativeRoot){varexception,result;try{result=simpleXPathJQuery.call(this,relativeRoot)}catch(_error){exception=_error;console.log("jQuery-based XPath construction failed! Falling back to manual.");result=simpleXPathPure.call(this,relativeRoot)}returnresult};$.xpath=function(xp,root){varidx,name,node,step,steps,_i,_len,_ref1;steps=xp.substring(1).split("/");node=root;for(_i=0,_len=steps.length;_i<_len;_i++){step=steps[_i];_ref1=step.split("["),name=_ref1[0],idx=_ref1[1];idx=idx!=null?parseInt((idx!=null?idx.split("]"):void0)[0]):1;node=findChild(node,name.toLowerCase(),idx)}returnnode};$.escape=function(html){returnhtml.replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")};$.fn.escape=function(html){if(arguments.length){returnthis.html($.escape(html))}returnthis.html()};$.fn.reverse=[]._reverse||[].reverse;functions=["log","debug","info","warn","exception","assert","dir","dirxml","trace","group","groupEnd","groupCollapsed","time","timeEnd","profile","profileEnd","count","clear","table","error","notifyFirebug","firebug","userObjects"];if(typeofconsole!=="undefined"&&console!==null){if(console.group==null){console.group=function(name){returnconsole.log("GROUP: ",name)}}if(console.groupCollapsed==null){console.groupCollapsed=console.group}for(_i=0,_len=functions.length;_i<_len;_i++){fn=functions[_i];if(console[fn]==null){console[fn]=function(){returnconsole.log(_t("Not implemented:")+(" console."+name))}}}}else{this.console={};for(_j=0,_len1=functions.length;_j<_len1;_j++){fn=functions[_j];this.console[fn]=function(){}}this.console["error"]=function(){varargs;args=1<=arguments.length?__slice.call(arguments,0):[];returnalert("ERROR: "+args.join(", "))};this.console["warn"]=function(){varargs;args=1<=arguments.length?__slice.call(arguments,0):[];returnalert("WARNING: "+args.join(", "))}}Delegator=function(){Delegator.prototype.events={};Delegator.prototype.options={};Delegator.prototype.element=null;functionDelegator(element,options){this.options=$.extend(true,{},this.options,options);this.element=$(element);this.on=this.subscribe;this.addEvents()}Delegator.prototype.addEvents=function(){varevent,functionName,sel,selector,_k,_ref1,_ref2,_results;_ref1=this.events;_results=[];for(selin_ref1){functionName=_ref1[sel];_ref2=sel.split(" "),selector=2<=_ref2.length?__slice.call(_ref2,0,_k=_ref2.length-1):(_k=0,[]),event=_ref2[_k++];_results.push(this.addEvent(selector.join(" "),event,functionName))}return_results};Delegator.prototype.addEvent=function(bindTo,event,functionName){varclosure,isBlankSelector,_this=this;closure=function(){return_this[functionName].apply(_this,arguments)};isBlankSelector=typeofbindTo==="string"&&bindTo.replace(/\s+/g,"")==="";if(isBlankSelector){bindTo=this.element}if(typeofbindTo==="string"){this.element.delegate(bindTo,event,closure)}else{if(this.isCustomEvent(event)){this.subscribe(event,closure)}else{$(bindTo).bind(event,closure)}}returnthis};Delegator.prototype.isCustomEvent=function(event){event=event.split(".")[0];return$.inArray(event,Delegator.natives)===-1};Delegator.prototype.publish=function(){this.element.triggerHandler.apply(this.element,arguments);returnthis};Delegator.prototype.subscribe=function(event,callback){varclosure;closure=function(){returncallback.apply(this,[].slice.call(arguments,1))};closure.guid=callback.guid=$.guid+=1;this.element.bind(event,closure);returnthis};Delegator.prototype.unsubscribe=function(){this.element.unbind.apply(this.element,arguments);returnthis};returnDelegator}();Delegator.natives=function(){varkey,specials,val;specials=function(){var_ref1,_results;_ref1=jQuery.event.special;_results=[];for(keyin_ref1){if(!__hasProp.call(_ref1,key))continue;val=_ref1[key];_results.push(key)}return_results}();return"blur focus focusin focusout load resize scroll unload click dblclick\nmousedown mouseup mousemove mouseover mouseout mouseenter mouseleave\nchange select submit keydown keypress keyup error".split(/[^a-z]+/).concat(specials)}();Range={};Range.sniff=function(r){if(r.commonAncestorContainer!=null){returnnewRange.BrowserRange(r)}elseif(typeofr.start==="string"){returnnewRange.SerializedRange(r)}elseif(r.start&&typeofr.start==="object"){returnnewRange.NormalizedRange(r)}else{console.error(_t("Could not sniff range type"));returnfalse}};Range.nodeFromXPath=function(xpath,root){varcustomResolver,evaluateXPath,namespace,node,segment;if(root==null){root=document}evaluateXPath=function(xp,nsResolver){varexception;if(nsResolver==null){nsResolver=null}try{returndocument.evaluate("."+xp,root,nsResolver,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(_error){exception=_error;console.log("XPath evaluation failed.");console.log("Trying fallback...");return$.xpath(xp,root)}};if(!$.isXMLDoc(document.documentElement)){returnevaluateXPath(xpath)}else{customResolver=document.createNSResolver(document.ownerDocument===null?document.documentElement:document.ownerDocument.documentElement);node=evaluateXPath(xpath,customResolver);if(!node){xpath=function(){var_k,_len2,_ref1,_results;_ref1=xpath.split("/");_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){segment=_ref1[_k];if(segment&&segment.indexOf(":")===-1){_results.push(segment.replace(/^([a-z]+)/,"xhtml:$1"))}else{_results.push(segment)}}return_results}().join("/");namespace=document.lookupNamespaceURI(null);customResolver=function(ns){if(ns==="xhtml"){returnnamespace}else{returndocument.documentElement.getAttribute("xmlns:"+ns)}};node=evaluateXPath(xpath,customResolver)}returnnode}};Range.RangeError=function(_super){__extends(RangeError,_super);functionRangeError(type,message,parent){this.type=type;this.message=message;this.parent=parent!=null?parent:null;RangeError.__super__.constructor.call(this,this.message)}returnRangeError}(Error);Range.BrowserRange=function(){functionBrowserRange(obj){this.commonAncestorContainer=obj.commonAncestorContainer;this.startContainer=obj.startContainer;this.startOffset=obj.startOffset;this.endContainer=obj.endContainer;this.endOffset=obj.endOffset}BrowserRange.prototype.normalize=function(root){varit,node,nr,offset,p,r,_k,_len2,_ref1;if(this.tainted){console.error(_t("You may only call normalize() once on a BrowserRange!"));returnfalse}else{this.tainted=true}r={};nr={};_ref1=["start","end"];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){p=_ref1[_k];node=this[p+"Container"];offset=this[p+"Offset"];if(node.nodeType===1){it=node.childNodes[offset];node=it||node.childNodes[offset-1];if(node.nodeType===1&&!node.firstChild){it=null;node=node.previousSibling}while(node.nodeType!==3){node=node.firstChild}offset=it?0:node.nodeValue.length}r[p]=node;r[p+"Offset"]=offset}nr.start=r.startOffset>0?r.start.splitText(r.startOffset):r.start;if(r.start===r.end){if(r.endOffset-r.startOffset<nr.start.nodeValue.length){nr.start.splitText(r.endOffset-r.startOffset)}nr.end=nr.start}else{if(r.endOffset<r.end.nodeValue.length){r.end.splitText(r.endOffset)}nr.end=r.end}nr.commonAncestor=this.commonAncestorContainer;while(nr.commonAncestor.nodeType!==1){nr.commonAncestor=nr.commonAncestor.parentNode}returnnewRange.NormalizedRange(nr)};BrowserRange.prototype.serialize=function(root,ignoreSelector){returnthis.normalize(root).serialize(root,ignoreSelector)};returnBrowserRange}();Range.NormalizedRange=function(){functionNormalizedRange(obj){this.commonAncestor=obj.commonAncestor;this.start=obj.start;this.end=obj.end}NormalizedRange.prototype.normalize=function(root){returnthis};NormalizedRange.prototype.limit=function(bounds){varnodes,parent,startParents,_k,_len2,_ref1;nodes=$.grep(this.textNodes(),function(node){returnnode.parentNode===bounds||$.contains(bounds,node.parentNode)});if(!nodes.length){returnnull}this.start=nodes[0];this.end=nodes[nodes.length-1];startParents=$(this.start).parents();_ref1=$(this.end).parents();for(_k=0,_len2=_ref1.length;_k<_len2;_k++){parent=_ref1[_k];if(startParents.index(parent)!==-1){this.commonAncestor=parent;break}}returnthis};NormalizedRange.prototype.serialize=function(root,ignoreSelector){varend,serialization,start;serialization=function(node,isEnd){varn,nodes,offset,origParent,textNodes,xpath,_k,_len2;if(ignoreSelector){origParent=$(node).parents(":not("+ignoreSelector+")").eq(0)}else{origParent=$(node).parent()}xpath=origParent.xpath(root)[0];textNodes=origParent.textNodes();nodes=textNodes.slice(0,textNodes.index(node));offset=0;for(_k=0,_len2=nodes.length;_k<_len2;_k++){n=nodes[_k];offset+=n.nodeValue.length}if(isEnd){return[xpath,offset+node.nodeValue.length]}else{return[xpath,offset]}};start=serialization(this.start);end=serialization(this.end,true);returnnewRange.SerializedRange({start:start[0],end:end[0],startOffset:start[1],endOffset:end[1]})};NormalizedRange.prototype.text=function(){varnode;returnfunction(){var_k,_len2,_ref1,_results;_ref1=this.textNodes();_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){node=_ref1[_k];_results.push(node.nodeValue)}return_results}.call(this).join("")};NormalizedRange.prototype.textNodes=function(){varend,start,textNodes,_ref1;textNodes=$(this.commonAncestor).textNodes();_ref1=[textNodes.index(this.start),textNodes.index(this.end)],start=_ref1[0],end=_ref1[1];return$.makeArray(textNodes.slice(start,+end+1||9e9))};NormalizedRange.prototype.toRange=function(){varrange;range=document.createRange();range.setStartBefore(this.start);range.setEndAfter(this.end);returnrange};returnNormalizedRange}();Range.SerializedRange=function(){functionSerializedRange(obj){this.start=obj.start;this.startOffset=obj.startOffset;this.end=obj.end;this.endOffset=obj.endOffset}SerializedRange.prototype.normalize=function(root){varcontains,e,length,node,p,range,tn,_k,_l,_len2,_len3,_ref1,_ref2;range={};_ref1=["start","end"];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){p=_ref1[_k];try{node=Range.nodeFromXPath(this[p],root)}catch(_error){e=_error;thrownewRange.RangeError(p,"Error while finding "+p+" node: "+this[p]+": "+e,e)}if(!node){thrownewRange.RangeError(p,"Couldn't find "+p+" node: "+this[p])}length=0;_ref2=$(node).textNodes();for(_l=0,_len3=_ref2.length;_l<_len3;_l++){tn=_ref2[_l];if(length+tn.nodeValue.length>=this[p+"Offset"]){range[p+"Container"]=tn;range[p+"Offset"]=this[p+"Offset"]-length;break}else{length+=tn.nodeValue.length}}if(range[p+"Offset"]==null){thrownewRange.RangeError(""+p+"offset","Couldn't find offset "+this[p+"Offset"]+" in element "+this[p])}}contains=document.compareDocumentPosition==null?function(a,b){returna.contains(b)}:function(a,b){returna.compareDocumentPosition(b)&16};$(range.startContainer).parents().each(function(){if(contains(this,range.endContainer)){range.commonAncestorContainer=this;returnfalse}});returnnewRange.BrowserRange(range).normalize(root)};SerializedRange.prototype.serialize=function(root,ignoreSelector){returnthis.normalize(root).serialize(root,ignoreSelector)};SerializedRange.prototype.toObject=function(){return{start:this.start,startOffset:this.startOffset,end:this.end,endOffset:this.endOffset}};returnSerializedRange}();util={uuid:function(){varcounter;counter=0;returnfunction(){returncounter++}}(),getGlobal:function(){returnfunction(){returnthis}()},maxZIndex:function($elements){varall,el;all=function(){var_k,_len2,_results;_results=[];for(_k=0,_len2=$elements.length;_k<_len2;_k++){el=$elements[_k];if($(el).css("position")==="static"){_results.push(-1)}else{_results.push(parseInt($(el).css("z-index"),10)||-1)}}return_results}();returnMath.max.apply(Math,all)},mousePosition:function(e,offsetEl){varoffset;offset=$(offsetEl).position();return{top:e.pageY-offset.top,left:e.pageX-offset.left}},preventEventDefault:function(event){returnevent!=null?typeofevent.preventDefault==="function"?event.preventDefault():void0:void0}};_Annotator=this.Annotator;Annotator=function(_super){__extends(Annotator,_super);Annotator.prototype.events={".annotator-adder button click":"onAdderClick",".annotator-adder button mousedown":"onAdderMousedown",".annotator-hl mouseover":"onHighlightMouseover",".annotator-hl mouseout":"startViewerHideTimer"};Annotator.prototype.html={adder:'<div class="annotator-adder"><button>'+_t("Annotate")+"</button></div>",wrapper:'<div class="annotator-wrapper"></div>'};Annotator.prototype.options={readOnly:false};Annotator.prototype.plugins={};Annotator.prototype.editor=null;Annotator.prototype.viewer=null;Annotator.prototype.selectedRanges=null;Annotator.prototype.mouseIsDown=false;Annotator.prototype.ignoreMouseup=false;Annotator.prototype.viewerHideTimer=null;functionAnnotator(element,options){this.onDeleteAnnotation=__bind(this.onDeleteAnnotation,this);this.onEditAnnotation=__bind(this.onEditAnnotation,this);this.onAdderClick=__bind(this.onAdderClick,this);this.onAdderMousedown=__bind(this.onAdderMousedown,this);this.onHighlightMouseover=__bind(this.onHighlightMouseover,this);this.checkForEndSelection=__bind(this.checkForEndSelection,this);this.checkForStartSelection=__bind(this.checkForStartSelection,this);this.clearViewerHideTimer=__bind(this.clearViewerHideTimer,this);this.startViewerHideTimer=__bind(this.startViewerHideTimer,this);this.showViewer=__bind(this.showViewer,this);this.onEditorSubmit=__bind(this.onEditorSubmit,this);this.onEditorHide=__bind(this.onEditorHide,this);this.showEditor=__bind(this.showEditor,this);Annotator.__super__.constructor.apply(this,arguments);this.plugins={};if(!Annotator.supported()){returnthis}if(!this.options.readOnly){this._setupDocumentEvents()}this._setupWrapper()._setupViewer()._setupEditor();this._setupDynamicStyle();this.adder=$(this.html.adder).appendTo(this.wrapper).hide()}Annotator.prototype._setupWrapper=function(){this.wrapper=$(this.html.wrapper);this.element.find("script").remove();this.element.wrapInner(this.wrapper);this.wrapper=this.element.find(".annotator-wrapper");returnthis};Annotator.prototype._setupViewer=function(){var_this=this;this.viewer=newAnnotator.Viewer({readOnly:this.options.readOnly});this.viewer.hide().on("edit",this.onEditAnnotation).on("delete",this.onDeleteAnnotation).addField({load:function(field,annotation){if(annotation.text){$(field).escape(annotation.text)}else{$(field).html("<i>"+_t("No Comment")+"</i>")}return_this.publish("annotationViewerTextField",[field,annotation])}}).element.appendTo(this.wrapper).bind({mouseover:this.clearViewerHideTimer,mouseout:this.startViewerHideTimer});returnthis};Annotator.prototype._setupEditor=function(){this.editor=newAnnotator.Editor;this.editor.hide().on("hide",this.onEditorHide).on("save",this.onEditorSubmit).addField({type:"textarea",label:_t("Comments")+"…",load:function(field,annotation){return$(field).find("textarea").val(annotation.text||"")},submit:function(field,annotation){returnannotation.text=$(field).find("textarea").val()}});this.editor.element.appendTo(this.wrapper);returnthis};Annotator.prototype._setupDocumentEvents=function(){$(document).bind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});returnthis};Annotator.prototype._setupDynamicStyle=function(){varmax,sel,style,x;style=$("#annotator-dynamic-style");if(!style.length){style=$('<style id="annotator-dynamic-style"></style>').appendTo(document.head)}sel="*"+function(){var_k,_len2,_ref1,_results;_ref1=["adder","outer","notice","filter"];_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){x=_ref1[_k];_results.push(":not(.annotator-"+x+")")}return_results}().join("");max=util.maxZIndex($(document.body).find(sel));max=Math.max(max,1e3);style.text([".annotator-adder, .annotator-outer, .annotator-notice {"," z-index: "+(max+20)+";","}",".annotator-filter {"," z-index: "+(max+10)+";","}"].join("\n"));returnthis};Annotator.prototype.getSelectedRanges=function(){varbrowserRange,i,normedRange,r,ranges,rangesToIgnore,selection,_k,_len2;selection=util.getGlobal().getSelection();ranges=[];rangesToIgnore=[];if(!selection.isCollapsed){ranges=function(){var_k,_ref1,_results;_results=[];for(i=_k=0,_ref1=selection.rangeCount;0<=_ref1?_k<_ref1:_k>_ref1;i=0<=_ref1?++_k:--_k){r=selection.getRangeAt(i);browserRange=newRange.BrowserRange(r);normedRange=browserRange.normalize().limit(this.wrapper[0]);if(normedRange===null){rangesToIgnore.push(r)}_results.push(normedRange)}return_results}.call(this);selection.removeAllRanges()}for(_k=0,_len2=rangesToIgnore.length;_k<_len2;_k++){r=rangesToIgnore[_k];selection.addRange(r)}return$.grep(ranges,function(range){if(range){selection.addRange(range.toRange())}returnrange})};Annotator.prototype.createAnnotation=function(){varannotation;annotation={};this.publish("beforeAnnotationCreated",[annotation]);returnannotation};Annotator.prototype.setupAnnotation=function(annotation){vare,normed,normedRanges,r,root,_k,_l,_len2,_len3,_ref1;root=this.wrapper[0];annotation.ranges||(annotation.ranges=this.selectedRanges);normedRanges=[];_ref1=annotation.ranges;for(_k=0,_len2=_ref1.length;_k<_len2;_k++){r=_ref1[_k];try{normedRanges.push(Range.sniff(r).normalize(root))}catch(_error){e=_error;if(einstanceofRange.RangeError){this.publish("rangeNormalizeFail",[annotation,r,e])}else{throwe}}}annotation.quote=[];annotation.ranges=[];annotation.highlights=[];for(_l=0,_len3=normedRanges.length;_l<_len3;_l++){normed=normedRanges[_l];annotation.quote.push($.trim(normed.text()));annotation.ranges.push(normed.serialize(this.wrapper[0],".annotator-hl"));$.merge(annotation.highlights,this.highlightRange(normed))}annotation.quote=annotation.quote.join(" / ");$(annotation.highlights).data("annotation",annotation);returnannotation};Annotator.prototype.updateAnnotation=function(annotation){this.publish("beforeAnnotationUpdated",[annotation]);this.publish("annotationUpdated",[annotation]);returnannotation};Annotator.prototype.deleteAnnotation=function(annotation){varchild,h,_k,_len2,_ref1;if(annotation.highlights!=null){_ref1=annotation.highlights;for(_k=0,_len2=_ref1.length;_k<_len2;_k++){h=_ref1[_k];if(!(h.parentNode!=null)){continue}child=h.childNodes[0];$(h).replaceWith(h.childNodes)}}this.publish("annotationDeleted",[annotation]);returnannotation};Annotator.prototype.loadAnnotations=function(annotations){varclone,loader,_this=this;if(annotations==null){annotations=[]}loader=function(annList){varn,now,_k,_len2;if(annList==null){annList=[]}now=annList.splice(0,10);for(_k=0,_len2=now.length;_k<_len2;_k++){n=now[_k];_this.setupAnnotation(n)}if(annList.length>0){returnsetTimeout(function(){returnloader(annList)},10)}else{return_this.publish("annotationsLoaded",[clone])}};clone=annotations.slice();if(annotations.length){loader(annotations)}returnthis};Annotator.prototype.dumpAnnotations=function(){if(this.plugins["Store"]){returnthis.plugins["Store"].dumpAnnotations()}else{console.warn(_t("Can't dump annotations without Store plugin."));returnfalse}};Annotator.prototype.highlightRange=function(normedRange,cssClass){varhl,node,white,_k,_len2,_ref1,_results;if(cssClass==null){cssClass="annotator-hl"}white=/^\s*$/;hl=$("<span class='"+cssClass+"'></span>");_ref1=normedRange.textNodes();_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){node=_ref1[_k];if(!white.test(node.nodeValue)){_results.push($(node).wrapAll(hl).parent().show()[0])}}return_results};Annotator.prototype.highlightRanges=function(normedRanges,cssClass){varhighlights,r,_k,_len2;if(cssClass==null){cssClass="annotator-hl"}highlights=[];for(_k=0,_len2=normedRanges.length;_k<_len2;_k++){r=normedRanges[_k];$.merge(highlights,this.highlightRange(r,cssClass))}returnhighlights};Annotator.prototype.addPlugin=function(name,options){varklass,_base;if(this.plugins[name]){console.error(_t("You cannot have more than one instance of any plugin."))}else{klass=Annotator.Plugin[name];if(typeofklass==="function"){this.plugins[name]=newklass(this.element[0],options);this.plugins[name].annotator=this;if(typeof(_base=this.plugins[name]).pluginInit==="function"){_base.pluginInit()}}else{console.error(_t("Could not load ")+name+_t(" plugin. Have you included the appropriate <script> tag?"))}}returnthis};Annotator.prototype.showEditor=function(annotation,location){this.editor.element.css(location);this.editor.load(annotation);this.publish("annotationEditorShown",[this.editor,annotation]);returnthis};Annotator.prototype.onEditorHide=function(){this.publish("annotationEditorHidden",[this.editor]);returnthis.ignoreMouseup=false};Annotator.prototype.onEditorSubmit=function(annotation){returnthis.publish("annotationEditorSubmit",[this.editor,annotation])};Annotator.prototype.showViewer=function(annotations,location){this.viewer.element.css(location);this.viewer.load(annotations);returnthis.publish("annotationViewerShown",[this.viewer,annotations])};Annotator.prototype.startViewerHideTimer=function(){if(!this.viewerHideTimer){returnthis.viewerHideTimer=setTimeout(this.viewer.hide,250)}};Annotator.prototype.clearViewerHideTimer=function(){clearTimeout(this.viewerHideTimer);returnthis.viewerHideTimer=false};Annotator.prototype.checkForStartSelection=function(event){if(!(event&&this.isAnnotator(event.target))){this.startViewerHideTimer();returnthis.mouseIsDown=true}};Annotator.prototype.checkForEndSelection=function(event){varcontainer,range,_k,_len2,_ref1;this.mouseIsDown=false;if(this.ignoreMouseup){return}this.selectedRanges=this.getSelectedRanges();_ref1=this.selectedRanges;for(_k=0,_len2=_ref1.length;_k<_len2;_k++){range=_ref1[_k];container=range.commonAncestor;if($(container).hasClass("annotator-hl")){container=$(container).parents("[class^=annotator-hl]")[0]}if(this.isAnnotator(container)){return}}if(event&&this.selectedRanges.length){returnthis.adder.css(util.mousePosition(event,this.wrapper[0])).show()}else{returnthis.adder.hide()}};Annotator.prototype.isAnnotator=function(element){return!!$(element).parents().andSelf().filter("[class^=annotator-]").not(this.wrapper).length};Annotator.prototype.onHighlightMouseover=function(event){varannotations;this.clearViewerHideTimer();if(this.mouseIsDown||this.viewer.isShown()){returnfalse}annotations=$(event.target).parents(".annotator-hl").andSelf().map(function(){return$(this).data("annotation")});returnthis.showViewer($.makeArray(annotations),util.mousePosition(event,this.wrapper[0]))};Annotator.prototype.onAdderMousedown=function(event){if(event!=null){event.preventDefault()}returnthis.ignoreMouseup=true};Annotator.prototype.onAdderClick=function(event){varannotation,cancel,cleanup,position,save,_this=this;if(event!=null){event.preventDefault()}position=this.adder.position();this.adder.hide();annotation=this.setupAnnotation(this.createAnnotation());$(annotation.highlights).addClass("annotator-hl-temporary");save=function(){cleanup();$(annotation.highlights).removeClass("annotator-hl-temporary");return_this.publish("annotationCreated",[annotation])};cancel=function(){cleanup();return_this.deleteAnnotation(annotation)};cleanup=function(){_this.unsubscribe("annotationEditorHidden",cancel);return_this.unsubscribe("annotationEditorSubmit",save)};this.subscribe("annotationEditorHidden",cancel);this.subscribe("annotationEditorSubmit",save);returnthis.showEditor(annotation,position)};Annotator.prototype.onEditAnnotation=function(annotation){varcleanup,offset,update,_this=this;offset=this.viewer.element.position();update=function(){cleanup();return_this.updateAnnotation(annotation)};cleanup=function(){_this.unsubscribe("annotationEditorHidden",cleanup);return_this.unsubscribe("annotationEditorSubmit",update)};this.subscribe("annotationEditorHidden",cleanup);this.subscribe("annotationEditorSubmit",update);this.viewer.hide();returnthis.showEditor(annotation,offset)};Annotator.prototype.onDeleteAnnotation=function(annotation){this.viewer.hide();returnthis.deleteAnnotation(annotation)};returnAnnotator}(Delegator);Annotator.Plugin=function(_super){__extends(Plugin,_super);functionPlugin(element,options){Plugin.__super__.constructor.apply(this,arguments)}Plugin.prototype.pluginInit=function(){};returnPlugin}(Delegator);g=util.getGlobal();if(((_ref1=g.document)!=null?_ref1.evaluate:void0)==null){$.getScript("http://assets.annotateit.org/vendor/xpath.min.js")}if(g.getSelection==null){$.getScript("http://assets.annotateit.org/vendor/ierange.min.js")}if(g.JSON==null){$.getScript("http://assets.annotateit.org/vendor/json2.min.js")}Annotator.$=$;Annotator.Delegator=Delegator;Annotator.Range=Range;Annotator._t=_t;Annotator.supported=function(){returnfunction(){return!!this.getSelection}()};Annotator.noConflict=function(){util.getGlobal().Annotator=_Annotator;returnthis};$.plugin("annotator",Annotator);this.Annotator=Annotator;Annotator.Widget=function(_super){__extends(Widget,_super);Widget.prototype.classes={hide:"annotator-hide",invert:{x:"annotator-invert-x",y:"annotator-invert-y"}};functionWidget(element,options){Widget.__super__.constructor.apply(this,arguments);this.classes=$.extend({},Annotator.Widget.prototype.classes,this.classes)}Widget.prototype.checkOrientation=function(){varcurrent,offset,viewport,widget,window;this.resetOrientation();window=$(util.getGlobal());widget=this.element.children(":first");offset=widget.offset();viewport={top:window.scrollTop(),right:window.width()+window.scrollLeft()};current={top:offset.top,right:offset.left+widget.width()};if(current.top-viewport.top<0){this.invertY()}if(current.right-viewport.right>0){this.invertX()}returnthis};Widget.prototype.resetOrientation=function(){this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y);returnthis};Widget.prototype.invertX=function(){this.element.addClass(this.classes.invert.x);returnthis};Widget.prototype.invertY=function(){this.element.addClass(this.classes.invert.y);returnthis};Widget.prototype.isInvertedY=function(){returnthis.element.hasClass(this.classes.invert.y)};Widget.prototype.isInvertedX=function(){returnthis.element.hasClass(this.classes.invert.x)};returnWidget}(Delegator);Annotator.Editor=function(_super){__extends(Editor,_super);Editor.prototype.events={"form submit":"submit",".annotator-save click":"submit",".annotator-cancel click":"hide",".annotator-cancel mouseover":"onCancelButtonMouseover","textarea keydown":"processKeypress"};Editor.prototype.classes={hide:"annotator-hide",focus:"annotator-focus"};Editor.prototype.html='<div class="annotator-outer annotator-editor">\n <form class="annotator-widget">\n <ul class="annotator-listing"></ul>\n <div class="annotator-controls">\n <a href="#cancel" class="annotator-cancel">'+_t("Cancel")+'</a>\n<a href="#save" class="annotator-save annotator-focus">'+_t("Save")+"</a>\n </div>\n </form>\n</div>";Editor.prototype.options={};functionEditor(options){this.onCancelButtonMouseover=__bind(this.onCancelButtonMouseover,this);this.processKeypress=__bind(this.processKeypress,this);this.submit=__bind(this.submit,this);this.load=__bind(this.load,this);this.hide=__bind(this.hide,this);this.show=__bind(this.show,this);Editor.__super__.constructor.call(this,$(this.html)[0],options);this.fields=[];this.annotation={}}Editor.prototype.show=function(event){util.preventEventDefault(event);this.element.removeClass(this.classes.hide);this.element.find(".annotator-save").addClass(this.classes.focus);this.checkOrientation();this.element.find(":input:first").focus();this.setupDraggables();returnthis.publish("show")};Editor.prototype.hide=function(event){util.preventEventDefault(event);this.element.addClass(this.classes.hide);returnthis.publish("hide")};Editor.prototype.load=function(annotation){varfield,_k,_len2,_ref2;this.annotation=annotation;this.publish("load",[this.annotation]);_ref2=this.fields;for(_k=0,_len2=_ref2.length;_k<_len2;_k++){field=_ref2[_k];field.load(field.element,this.annotation)}returnthis.show()};Editor.prototype.submit=function(event){varfield,_k,_len2,_ref2;util.preventEventDefault(event);_ref2=this.fields;for(_k=0,_len2=_ref2.length;_k<_len2;_k++){field=_ref2[_k];field.submit(field.element,this.annotation)}this.publish("save",[this.annotation]);returnthis.hide()};Editor.prototype.addField=function(options){varelement,field,input;field=$.extend({id:"annotator-field-"+util.uuid(),type:"input",label:"",load:function(){},submit:function(){}},options);input=null;element=$('<li class="annotator-item" />');field.element=element[0];switch(field.type){case"textarea":input=$("<textarea />");break;case"input":case"checkbox":input=$("<input />")}element.append(input);input.attr({id:field.id,placeholder:field.label});if(field.type==="checkbox"){input[0].type="checkbox";element.addClass("annotator-checkbox");element.append($("<label />",{"for":field.id,html:field.label}))}this.element.find("ul:first").append(element);this.fields.push(field);returnfield.element};Editor.prototype.checkOrientation=function(){varcontrols,list;Editor.__super__.checkOrientation.apply(this,arguments);list=this.element.find("ul");controls=this.element.find(".annotator-controls");if(this.element.hasClass(this.classes.invert.y)){controls.insertBefore(list)}elseif(controls.is(":first-child")){controls.insertAfter(list)}returnthis};Editor.prototype.processKeypress=function(event){if(event.keyCode===27){returnthis.hide()}elseif(event.keyCode===13&&!event.shiftKey){returnthis.submit()}};Editor.prototype.onCancelButtonMouseover=function(){returnthis.element.find("."+this.classes.focus).removeClass(this.classes.focus)};Editor.prototype.setupDraggables=function(){varclasses,controls,cornerItem,editor,mousedown,onMousedown,onMousemove,onMouseup,resize,textarea,throttle,_this=this;this.element.find(".annotator-resize").remove();if(this.element.hasClass(this.classes.invert.y)){cornerItem=this.element.find(".annotator-item:last")}else{cornerItem=this.element.find(".annotator-item:first")}if(cornerItem){$('<span class="annotator-resize"></span>').appendTo(cornerItem)}mousedown=null;classes=this.classes;editor=this.element;textarea=null;resize=editor.find(".annotator-resize");controls=editor.find(".annotator-controls");throttle=false;onMousedown=function(event){if(event.target===this){mousedown={element:this,top:event.pageY,left:event.pageX};textarea=editor.find("textarea:first");$(window).bind({"mouseup.annotator-editor-resize":onMouseup,"mousemove.annotator-editor-resize":onMousemove});returnevent.preventDefault()}};onMouseup=function(){mousedown=null;return$(window).unbind(".annotator-editor-resize")};onMousemove=function(event){vardiff,directionX,directionY,height,width;if(mousedown&&throttle===false){diff={top:event.pageY-mousedown.top,left:event.pageX-mousedown.left};if(mousedown.element===resize[0]){height=textarea.outerHeight();width=textarea.outerWidth();directionX=editor.hasClass(classes.invert.x)?-1:1;directionY=editor.hasClass(classes.invert.y)?1:-1;textarea.height(height+diff.top*directionY);textarea.width(width+diff.left*directionX);if(textarea.outerHeight()!==height){mousedown.top=event.pageY}if(textarea.outerWidth()!==width){mousedown.left=event.pageX}}elseif(mousedown.element===controls[0]){editor.css({top:parseInt(editor.css("top"),10)+diff.top,left:parseInt(editor.css("left"),10)+diff.left});mousedown.top=event.pageY;mousedown.left=event.pageX}throttle=true;returnsetTimeout(function(){returnthrottle=false},1e3/60)}};resize.bind("mousedown",onMousedown);returncontrols.bind("mousedown",onMousedown)};returnEditor}(Annotator.Widget);Annotator.Viewer=function(_super){__extends(Viewer,_super);Viewer.prototype.events={".annotator-edit click":"onEditClick",".annotator-delete click":"onDeleteClick"};Viewer.prototype.classes={hide:"annotator-hide",showControls:"annotator-visible"};Viewer.prototype.html={element:'<div class="annotator-outer annotator-viewer">\n <ul class="annotator-widget annotator-listing"></ul>\n</div>',item:'<li class="annotator-annotation annotator-item">\n <span class="annotator-controls">\n <a href="#" title="View as webpage" class="annotator-link">View as webpage</a>\n <button title="Edit" class="annotator-edit">Edit</button>\n <button title="Delete" class="annotator-delete">Delete</button>\n </span>\n</li>'};Viewer.prototype.options={readOnly:false};functionViewer(options){this.onDeleteClick=__bind(this.onDeleteClick,this);this.onEditClick=__bind(this.onEditClick,this);this.load=__bind(this.load,this);this.hide=__bind(this.hide,this);this.show=__bind(this.show,this);Viewer.__super__.constructor.call(this,$(this.html.element)[0],options);this.item=$(this.html.item)[0];this.fields=[];this.annotations=[]}Viewer.prototype.show=function(event){varcontrols,_this=this;util.preventEventDefault(event);controls=this.element.find(".annotator-controls").addClass(this.classes.showControls);setTimeout(function(){returncontrols.removeClass(_this.classes.showControls)},500);this.element.removeClass(this.classes.hide);returnthis.checkOrientation().publish("show")};Viewer.prototype.isShown=function(){return!this.element.hasClass(this.classes.hide)};Viewer.prototype.hide=function(event){util.preventEventDefault(event);this.element.addClass(this.classes.hide);returnthis.publish("hide")};Viewer.prototype.load=function(annotations){varannotation,controller,controls,del,edit,element,field,item,link,links,list,_k,_l,_len2,_len3,_ref2,_ref3;this.annotations=annotations||[];list=this.element.find("ul:first").empty();_ref2=this.annotations;for(_k=0,_len2=_ref2.length;_k<_len2;_k++){annotation=_ref2[_k];item=$(this.item).clone().appendTo(list).data("annotation",annotation);controls=item.find(".annotator-controls");link=controls.find(".annotator-link");edit=controls.find(".annotator-edit");del=controls.find(".annotator-delete");links=newLinkParser(annotation.links||[]).get("alternate",{type:"text/html"});if(links.length===0||links[0].href==null){link.remove()}else{link.attr("href",links[0].href)}if(this.options.readOnly){edit.remove();del.remove()}else{controller={showEdit:function(){returnedit.removeAttr("disabled")},hideEdit:function(){returnedit.attr("disabled","disabled")},showDelete:function(){returndel.removeAttr("disabled")},hideDelete:function(){returndel.attr("disabled","disabled")}}}_ref3=this.fields;for(_l=0,_len3=_ref3.length;_l<_len3;_l++){field=_ref3[_l];element=$(field.element).clone().appendTo(item)[0];field.load(element,annotation,controller)}}this.publish("load",[this.annotations]);returnthis.show()};Viewer.prototype.addField=function(options){varfield;field=$.extend({load:function(){}},options);field.element=$("<div />")[0];this.fields.push(field);field.element;returnthis};Viewer.prototype.onEditClick=function(event){returnthis.onButtonClick(event,"edit")};Viewer.prototype.onDeleteClick=function(event){returnthis.onButtonClick(event,"delete")};Viewer.prototype.onButtonClick=function(event,type){varitem;item=$(event.target).parents(".annotator-annotation");returnthis.publish(type,[item.data("annotation")])};returnViewer}(Annotator.Widget);LinkParser=function(){functionLinkParser(data){this.data=data}LinkParser.prototype.get=function(rel,cond){vard,k,keys,match,v,_k,_len2,_ref2,_results;if(cond==null){cond={}}cond=$.extend({},cond,{rel:rel});keys=function(){var_results;_results=[];for(kincond){if(!__hasProp.call(cond,k))continue;v=cond[k];_results.push(k)}return_results}();_ref2=this.data;_results=[];for(_k=0,_len2=_ref2.length;_k<_len2;_k++){d=_ref2[_k];match=keys.reduce(function(m,k){returnm&&d[k]===cond[k]},true);if(match){_results.push(d)}else{continue}}return_results};returnLinkParser}();Annotator=Annotator||{};Annotator.Notification=function(_super){__extends(Notification,_super);Notification.prototype.events={click:"hide"};Notification.prototype.options={html:"<div class='annotator-notice'></div>",classes:{show:"annotator-notice-show",info:"annotator-notice-info",success:"annotator-notice-success",error:"annotator-notice-error"}};functionNotification(options){this.hide=__bind(this.hide,this);this.show=__bind(this.show,this);Notification.__super__.constructor.call(this,$(this.options.html).appendTo(document.body)[0],options)}Notification.prototype.show=function(message,status){if(status==null){status=Annotator.Notification.INFO}$(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message||"");setTimeout(this.hide,5e3);returnthis};Notification.prototype.hide=function(){$(this.element).removeClass(this.options.classes.show);returnthis};returnNotification}(Delegator);Annotator.Notification.INFO="show";Annotator.Notification.SUCCESS="success";Annotator.Notification.ERROR="error";$(function(){varnotification;notification=newAnnotator.Notification;Annotator.showNotification=notification.show;returnAnnotator.hideNotification=notification.hide})}).call(this);