view webapp/src/main/webapp/jquery/annotator-dl.min.js @ 1123:1fad569ccb4f

provide annotator javascript for digilib.annotator plugin.
author robcast
date Fri, 09 Nov 2012 11:28:44 +0100
parents
children
line wrap: on
line source

/*
** Annotator 1.2.5-dev-34a1d4e
** https://github.com/okfn/annotator/
**
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE
**
** Built at: 2012-11-08 19:26:45Z
*/(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x=[].slice,T={}.hasOwnProperty,N=function(e,t){function r(){this.constructor=e}for(var n in t)T.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e},C=function(e,t){return function(){return e.apply(t,arguments)}},k=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};c=null,typeof Gettext!="undefined"&&Gettext!==null?(v=new Gettext({domain:"annotator"}),c=function(e){return v.gettext(e)}):c=function(e){return e},S=function(e){return c(e)},(typeof jQuery!="undefined"&&jQuery!==null?(w=jQuery.fn)!=null?w.jquery:void 0:void 0)||console.error(S("Annotator requires jQuery: have you included lib/vendor/jquery.js?")),JSON&&JSON.parse&&JSON.stringify||console.error(S("Annotator requires a JSON implementation: have you included lib/vendor/json2.js?")),e=jQuery.sub(),e.flatten=function(t){var n;return n=function(t){var r,i,s,o;i=[];for(s=0,o=t.length;s<o;s++)r=t[s],i=i.concat(r&&e.isArray(r)?n(r):r);return i},n(t)},e.plugin=function(t,n){return jQuery.fn[t]=function(r){var i;return i=Array.prototype.slice.call(arguments,1),this.each(function(){var s;return s=e.data(this,t),s?r&&s[r].apply(s,i):(s=new n(this,r),e.data(this,t,s))})}},e.fn.textNodes=function(){var t;return t=function(e){var n;if(e&&e.nodeType!==3){n=[];if(e.nodeType!==8){e=e.lastChild;while(e)n.push(t(e)),e=e.previousSibling}return n.reverse()}return e},this.map(function(){return e.flatten(t(this))})},e.fn.xpath=function(t){var n;return n=this.map(function(){var n,r,i;i="",n=this;while(n&&n.nodeType===1&&n!==t)r=e(n.parentNode).children(n.tagName).index(n)+1,r="["+r+"]",i="/"+n.tagName.toLowerCase()+r+i,n=n.parentNode;return i}),n.get()},e.escape=function(e){return e.replace(/&(?!\w+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e.fn.escape=function(t){return arguments.length?this.html(e.escape(t)):this.html()},e.fn.reverse=[]._reverse||[].reverse,f=["log","debug","info","warn","exception","assert","dir","dirxml","trace","group","groupEnd","groupCollapsed","time","timeEnd","profile","profileEnd","count","clear","table","error","notifyFirebug","firebug","userObjects"];if(typeof console!="undefined"&&console!==null){console.group==null&&(console.group=function(e){return console.log("GROUP: ",e)}),console.groupCollapsed==null&&(console.groupCollapsed=console.group);for(m=0,y=f.length;m<y;m++)a=f[m],console[a]==null&&(console[a]=function(){return console.log(S("Not implemented:")+(" console."+name))})}else{this.console={};for(g=0,b=f.length;g<b;g++)a=f[g],this.console[a]=function(){};this.console.error=function(){var e;return e=1<=arguments.length?x.call(arguments,0):[],alert("ERROR: "+e.join(", "))},this.console.warn=function(){var e;return e=1<=arguments.length?x.call(arguments,0):[],alert("WARNING: "+e.join(", "))}}n=function(){function t(t,n){this.options=e.extend(!0,{},this.options,n),this.element=e(t),this.on=this.subscribe,this.addEvents()}return t.prototype.events={},t.prototype.options={},t.prototype.element=null,t.prototype.addEvents=function(){var e,t,n,r,i,s,o,u;s=this.events,u=[];for(n in s)t=s[n],o=n.split(" "),r=2<=o.length?x.call(o,0,i=o.length-1):(i=0,[]),e=o[i++],u.push(this.addEvent(r.join(" "),e,t));return u},t.prototype.addEvent=function(t,n,r){var i,s,o=this;return i=function(){return o[r].apply(o,arguments)},s=typeof t=="string"&&t.replace(/\s+/g,"")==="",s&&(t=this.element),typeof t=="string"?this.element.delegate(t,n,i):this.isCustomEvent(n)?this.subscribe(n,i):e(t).bind(n,i),this},t.prototype.isCustomEvent=function(n){return n=n.split(".")[0],e.inArray(n,t.natives)===-1},t.prototype.publish=function(){return this.element.triggerHandler.apply(this.element,arguments),this},t.prototype.subscribe=function(t,n){var r;return r=function(){return n.apply(this,[].slice.call(arguments,1))},r.guid=n.guid=e.guid+=1,this.element.bind(t,r),this},t.prototype.unsubscribe=function(){return this.element.unbind.apply(this.element,arguments),this},t}(),n.natives=function(){var e,t,n;return t=function(){var t,r;t=jQuery.event.special,r=[];for(e in t){if(!T.call(t,e))continue;n=t[e],r.push(e)}return r}(),"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(t)}(),i={},i.sniff=function(e){return e.commonAncestorContainer!=null?new i.BrowserRange(e):typeof e.start=="string"?new i.SerializedRange(e):e.start&&typeof e.start=="object"?new i.NormalizedRange(e):(console.error(S("Could not sniff range type")),!1)},i.nodeFromXPath=function(t,n){var r,i,s,o,u;return n==null&&(n=document),i=function(e,t){return t==null&&(t=null),document.evaluate("."+e,n,t,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},e.isXMLDoc(document.documentElement)?(r=document.createNSResolver(document.ownerDocument===null?document.documentElement:document.ownerDocument.documentElement),o=i(t,r),o||(t=function(){var e,n,r,i;r=t.split("/"),i=[];for(e=0,n=r.length;e<n;e++)u=r[e],u&&u.indexOf(":")===-1?i.push(u.replace(/^([a-z]+)/,"xhtml:$1")):i.push(u);return i}().join("/"),s=document.lookupNamespaceURI(null),r=function(e){return e==="xhtml"?s:document.documentElement.getAttribute("xmlns:"+e)},o=i(t,r)),o):i(t)},i.RangeError=function(e){function t(e,n,r){this.type=e,this.message=n,this.parent=r!=null?r:null,t.__super__.constructor.call(this,this.message)}return N(t,e),t}(Error),i.BrowserRange=function(){function e(e){this.commonAncestorContainer=e.commonAncestorContainer,this.startContainer=e.startContainer,this.startOffset=e.startOffset,this.endContainer=e.endContainer,this.endOffset=e.endOffset}return e.prototype.normalize=function(e){var t,n,r,s,o,u,a,f,l;if(this.tainted)return console.error(S("You may only call normalize() once on a BrowserRange!")),!1;this.tainted=!0,u={},r={},l=["start","end"];for(a=0,f=l.length;a<f;a++){o=l[a],n=this[o+"Container"],s=this[o+"Offset"];if(n==null||s==null)return!1;if(n.nodeType===1){t=n.childNodes[s],n=t||n.childNodes[s-1],n.nodeType===1&&!n.firstChild&&(t=null,n=n.previousSibling);while(n.nodeType!==3)n=n.firstChild;s=t?0:n.nodeValue.length}u[o]=n,u[o+"Offset"]=s}r.start=u.startOffset>0?u.start.splitText(u.startOffset):u.start,u.start===u.end?(u.endOffset-u.startOffset<r.start.nodeValue.length&&r.start.splitText(u.endOffset-u.startOffset),r.end=r.start):(u.endOffset<u.end.nodeValue.length&&u.end.splitText(u.endOffset),r.end=u.end),r.commonAncestor=this.commonAncestorContainer;while(r.commonAncestor.nodeType!==1)r.commonAncestor=r.commonAncestor.parentNode;return new i.NormalizedRange(r)},e.prototype.serialize=function(e,t){return this.normalize(e).serialize(e,t)},e}(),i.NormalizedRange=function(){function t(e){this.commonAncestor=e.commonAncestor,this.start=e.start,this.end=e.end}return t.prototype.normalize=function(e){return this},t.prototype.limit=function(t){var n,r,i,s,o,u;n=e.grep(this.textNodes(),function(n){return n.parentNode===t||e.contains(t,n.parentNode)});if(!n.length)return null;this.start=n[0],this.end=n[n.length-1],i=e(this.start).parents(),u=e(this.end).parents();for(s=0,o=u.length;s<o;s++){r=u[s];if(i.index(r)!==-1){this.commonAncestor=r;break}}return this},t.prototype.serialize=function(t,n){var r,s,o;return s=function(r,i){var s,o,u,a,f,l,c,h;n?a=e(r).parents(":not("+n+")").eq(0):a=e(r).parent(),l=a.xpath(t)[0],f=a.textNodes(),o=f.slice(0,f.index(r)),u=0;for(c=0,h=o.length;c<h;c++)s=o[c],u+=s.nodeValue.length;return i?[l,u+r.nodeValue.length]:[l,u]},o=s(this.start),r=s(this.end,!0),new i.SerializedRange({start:o[0],end:r[0],startOffset:o[1],endOffset:r[1]})},t.prototype.text=function(){var e;return function(){var t,n,r,i;r=this.textNodes(),i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.nodeValue);return i}.call(this).join("")},t.prototype.textNodes=function(){var t,n,r,i;return r=e(this.commonAncestor).textNodes(),i=[r.index(this.start),r.index(this.end)],n=i[0],t=i[1],e.makeArray(r.slice(n,t+1||9e9))},t.prototype.toRange=function(){var e;return e=document.createRange(),e.setStartBefore(this.start),e.setEndAfter(this.end),e},t}(),i.SerializedRange=function(){function t(e){this.start=e.start,this.startOffset=e.startOffset,this.end=e.end,this.endOffset=e.endOffset}return t.prototype.normalize=function(t){var n,r,s,o,u,a,f,l,c,h,p,d;u={},p=["start","end"];for(f=0,c=p.length;f<c;f++){o=p[f];try{s=i.nodeFromXPath(this[o],t)}catch(v){throw new i.RangeError(o,"Error while finding "+o+" node: "+this[o]+": "+v,v)}if(!s)throw new i.RangeError(o,"Couldn't find "+o+" node: "+this[o]);r=0,d=e(s).textNodes();for(l=0,h=d.length;l<h;l++){a=d[l];if(r+a.nodeValue.length>=this[o+"Offset"]){u[o+"Container"]=a,u[o+"Offset"]=this[o+"Offset"]-r;break}r+=a.nodeValue.length}if(u[o+"Offset"]==null)throw new i.RangeError(""+o+"offset","Couldn't find offset "+this[o+"Offset"]+" in element "+this[o])}return n=document.compareDocumentPosition==null?function(e,t){return e.contains(t)}:function(e,t){return e.compareDocumentPosition(t)&16},e(u.startContainer).parents().reverse().each(function(){if(n(this,u.endContainer))return u.commonAncestorContainer=this,!1}),(new i.BrowserRange(u)).normalize(t)},t.prototype.serialize=function(e,t){return this.normalize(e).serialize(e,t)},t.prototype.toObject=function(){return{start:this.start,startOffset:this.startOffset,end:this.end,endOffset:this.endOffset}},t}(),p={uuid:function(){var e;return e=0,function(){return e++}}(),getGlobal:function(){return function(){return this}()},maxZIndex:function(t){var n,r;return n=function(){var n,i,s;s=[];for(n=0,i=t.length;n<i;n++)r=t[n],e(r).css("position")==="static"?s.push(-1):s.push(parseInt(e(r).css("z-index"),10)||-1);return s}(),Math.max.apply(Math,n)},mousePosition:function(t,n){var r;return r=e(n).offset(),{top:t.pageY-r.top,left:t.pageX-r.left}},preventEventDefault:function(e){return e!=null?typeof e.preventDefault=="function"?e.preventDefault():void 0:void 0}},d=this.Annotator,t=function(t){function n(t,r){this.onDeleteAnnotation=C(this.onDeleteAnnotation,this),this.onEditAnnotation=C(this.onEditAnnotation,this),this.onAdderClick=C(this.onAdderClick,this),this.onAdderMousedown=C(this.onAdderMousedown,this),this.onHighlightMouseover=C(this.onHighlightMouseover,this),this.checkForEndSelection=C(this.checkForEndSelection,this),this.checkForStartSelection=C(this.checkForStartSelection,this),this.clearViewerHideTimer=C(this.clearViewerHideTimer,this),this.startViewerHideTimer=C(this.startViewerHideTimer,this),this.showViewer=C(this.showViewer,this),this.onEditorSubmit=C(this.onEditorSubmit,this),this.onEditorHide=C(this.onEditorHide,this),this.showEditor=C(this.showEditor,this),n.__super__.constructor.apply(this,arguments),this.plugins={};if(!n.supported())return this;this.options.readOnly||this._setupDocumentEvents(),this._setupWrapper()._setupViewer()._setupEditor(),this._setupDynamicStyle(),this.adder=e(this.html.adder).appendTo(this.wrapper).hide()}return N(n,t),n.prototype.events={".annotator-adder button click":"onAdderClick",".annotator-adder button mousedown":"onAdderMousedown",".annotator-hl mouseover":"onHighlightMouseover",".annotator-hl mouseout":"startViewerHideTimer"},n.prototype.html={adder:'<div class="annotator-adder"><button>'+S("Annotate")+"</button></div>",wrapper:'<div class="annotator-wrapper"></div>'},n.prototype.options={readOnly:!1},n.prototype.plugins={},n.prototype.editor=null,n.prototype.viewer=null,n.prototype.selectedRanges=null,n.prototype.mouseIsDown=!1,n.prototype.ignoreMouseup=!1,n.prototype.viewerHideTimer=null,n.prototype._setupWrapper=function(){return this.wrapper=e(this.html.wrapper),this.element.find("script").remove(),this.element.wrapInner(this.wrapper),this.wrapper=this.element.find(".annotator-wrapper"),this},n.prototype._setupViewer=function(){var t=this;return this.viewer=new n.Viewer({readOnly:this.options.readOnly}),this.viewer.hide().on("edit",this.onEditAnnotation).on("delete",this.onDeleteAnnotation).addField({load:function(n,r){return r.text?e(n).escape(r.text):e(n).html("<i>"+S("No Comment")+"</i>"),t.publish("annotationViewerTextField",[n,r])}}).element.appendTo(this.wrapper).bind({mouseover:this.clearViewerHideTimer,mouseout:this.startViewerHideTimer}),this},n.prototype._setupEditor=function(){return this.editor=new n.Editor,this.editor.hide().on("hide",this.onEditorHide).on("save",this.onEditorSubmit).addField({type:"textarea",label:S("Comments")+"…",load:function(t,n){return e(t).find("textarea").val(n.text||"")},submit:function(t,n){return n.text=e(t).find("textarea").val()}}),this.editor.element.appendTo(this.wrapper),this},n.prototype._setupDocumentEvents=function(){return e(document).bind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection}),this},n.prototype._setupDynamicStyle=function(){var t,n,r,i;return r=e("#annotator-dynamic-style"),r.length||(r=e('<style id="annotator-dynamic-style"></style>').appendTo(document.head)),n="*"+function(){var e,t,n,r;n=["adder","outer","notice","filter"],r=[];for(e=0,t=n.length;e<t;e++)i=n[e],r.push(":not(.annotator-"+i+")");return r}().join(""),t=p.maxZIndex(e(document.body).find(n)),t=Math.max(t,1e3),r.text([".annotator-adder, .annotator-outer, .annotator-notice {","  z-index: "+(t+20)+";","}",".annotator-filter {","  z-index: "+(t+10)+";","}"].join("\n")),this},n.prototype.getSelectedRanges=function(){var t,n,r,s,o,u,a,f,l;a=p.getGlobal().getSelection(),o=[],u=[],a.isCollapsed||(o=function(){var e,o,f;f=[];for(n=e=0,o=a.rangeCount;0<=o?e<o:e>o;n=0<=o?++e:--e)s=a.getRangeAt(n),t=new i.BrowserRange(s),r=t.normalize().limit(this.wrapper[0]),r===null&&u.push(s),f.push(r);return f}.call(this),a.removeAllRanges());for(f=0,l=u.length;f<l;f++)s=u[f],a.addRange(s);return e.grep(o,function(e){return e&&a.addRange(e.toRange()),e})},n.prototype.createAnnotation=function(){var e;return e={},this.publish("beforeAnnotationCreated",[e]),e},n.prototype.setupAnnotation=function(t,n){var r,s,o,u,a,f,l,c,h;n==null&&(n=!0),u=this.wrapper[0],t.ranges||(t.ranges=this.selectedRanges),s=[],h=t.ranges;for(a=0,l=h.length;a<l;a++){o=h[a];try{s.push(i.sniff(o).normalize(u))}catch(p){if(!(p instanceof i.RangeError))throw p;this.publish("rangeNormalizeFail",[t,o,p])}}t.quote=[],t.ranges=[],t.highlights=[];for(f=0,c=s.length;f<c;f++)r=s[f],t.quote.push(e.trim(r.text())),t.ranges.push(r.serialize(this.wrapper[0],".annotator-hl")),e.merge(t.highlights,this.highlightRange(r));return t.quote=t.quote.join(" / "),e(t.highlights).data("annotation",t),n&&this.publish("annotationCreated",[t]),t},n.prototype.updateAnnotation=function(e){return this.publish("beforeAnnotationUpdated",[e]),this.publish("annotationUpdated",[e]),e},n.prototype.deleteAnnotation=function(t){var n,r,i,s;s=t.highlights;for(r=0,i=s.length;r<i;r++)n=s[r],e(n).replaceWith(n.childNodes);return this.publish("annotationDeleted",[t]),t},n.prototype.loadAnnotations=function(e){var t,n,r=this;return e==null&&(e=[]),n=function(e){var i,s,o,u;e==null&&(e=[]),s=e.splice(0,10);for(o=0,u=s.length;o<u;o++)i=s[o],r.setupAnnotation(i,!1);return e.length>0?setTimeout(function(){return n(e)},10):r.publish("annotationsLoaded",[t])},t=e.slice(),e.length&&n(e),this},n.prototype.dumpAnnotations=function(){return this.plugins.Store?this.plugins.Store.dumpAnnotations():console.warn(S("Can't dump annotations without Store plugin."))},n.prototype.highlightRange=function(t,n){var r,i,s,o,u,a,f;n==null&&(n="annotator-hl"),s=/^\s*$/,r=e("<span class='"+n+"'></span>"),a=t.textNodes(),f=[];for(o=0,u=a.length;o<u;o++)i=a[o],s.test(i.nodeValue)||f.push(e(i).wrapAll(r).parent().show()[0]);return f},n.prototype.highlightRanges=function(t,n){var r,i,s,o;n==null&&(n="annotator-hl"),r=[];for(s=0,o=t.length;s<o;s++)i=t[s],e.merge(r,this.highlightRange(i,n));return r},n.prototype.addPlugin=function(e,t){var r,i;return this.plugins[e]?console.error(S("You cannot have more than one instance of any plugin.")):(r=n.Plugin[e],typeof r=="function"?(this.plugins[e]=new r(this.element[0],t),this.plugins[e].annotator=this,typeof (i=this.plugins[e]).pluginInit=="function"&&i.pluginInit()):console.error(S("Could not load ")+e+S(" plugin. Have you included the appropriate <script> tag?"))),this},n.prototype.showEditor=function(e,t){return this.editor.element.css(t),this.editor.load(e),this.publish("annotationEditorShown",[this.editor,e]),this},n.prototype.onEditorHide=function(){return this.publish("annotationEditorHidden",[this.editor]),this.ignoreMouseup=!1},n.prototype.onEditorSubmit=function(e){return this.publish("annotationEditorSubmit",[this.editor,e]),e.ranges===void 0?this.setupAnnotation(e):this.updateAnnotation(e)},n.prototype.showViewer=function(e,t){return this.viewer.element.css(t),this.viewer.load(e),this.publish("annotationViewerShown",[this.viewer,e])},n.prototype.startViewerHideTimer=function(){if(!this.viewerHideTimer)return this.viewerHideTimer=setTimeout(this.viewer.hide,250)},n.prototype.clearViewerHideTimer=function(){return clearTimeout(this.viewerHideTimer),this.viewerHideTimer=!1},n.prototype.checkForStartSelection=function(e){if(!e||!this.isAnnotator(e.target))return this.startViewerHideTimer(),this.mouseIsDown=!0},n.prototype.checkForEndSelection=function(t){var n,r,i,s,o;this.mouseIsDown=!1;if(this.ignoreMouseup)return;this.selectedRanges=this.getSelectedRanges(),o=this.selectedRanges;for(i=0,s=o.length;i<s;i++){r=o[i],n=r.commonAncestor,e(n).hasClass("annotator-hl")&&(n=e(n).parents("[class^=annotator-hl]")[0]);if(this.isAnnotator(n))return}return t&&this.selectedRanges.length?this.adder.css(p.mousePosition(t,this.wrapper[0])).show():this.adder.hide()},n.prototype.isAnnotator=function(t){return!!e(t).parents().andSelf().filter("[class^=annotator-]").not(this.wrapper).length},n.prototype.onHighlightMouseover=function(t){var n;return this.clearViewerHideTimer(),this.mouseIsDown||this.viewer.isShown()?!1:(n=e(t.target).parents(".annotator-hl").andSelf().map(function(){return e(this).data("annotation")}),this.showViewer(e.makeArray(n),p.mousePosition(t,this.wrapper[0])))},n.prototype.onAdderMousedown=function(e){return e!=null&&e.preventDefault(),this.ignoreMouseup=!0},n.prototype.onAdderClick=function(t){var n,r,s,o;return t!=null&&t.preventDefault(),r=this.adder.position(),this.adder.hide(),this.selectedRanges&&this.selectedRanges.length&&(o=function(){var e,t,n,r;n=this.selectedRanges,r=[];for(e=0,t=n.length;e<t;e++)s=n[e],r.push(i.sniff(s).normalize());return r}.call(this),n=this.highlightRanges(o,"annotator-hl annotator-hl-temporary"),this.editor.element.one("hide",function(){var t,r,i,s;s=[];for(r=0,i=n.length;r<i;r++)t=n[r],s.push(e(t).replaceWith(t.childNodes));return s})),this.showEditor(this.createAnnotation(),r)},n.prototype.onEditAnnotation=function(e){var t;return t=this.viewer.element.position(),this.viewer.hide(),this.showEditor(e,t)},n.prototype.onDeleteAnnotation=function(e){return this.viewer.hide(),this.deleteAnnotation(e)},n}(n),t.Plugin=function(e){function t(e,n){t.__super__.constructor.apply(this,arguments)}return N(t,e),t.prototype.pluginInit=function(){},t}(n),l=p.getGlobal(),((E=l.document)!=null?E.evaluate:void 0)==null&&e.getScript("http://assets.annotateit.org/vendor/xpath.min.js"),l.getSelection==null&&e.getScript("http://assets.annotateit.org/vendor/ierange.min.js"),l.JSON==null&&e.getScript("http://assets.annotateit.org/vendor/json2.min.js"),t.$=e,t.Delegator=n,t.Range=i,t._t=S,t.supported=function(){return function(){return!!this.getSelection}()},t.noConflict=function(){return p.getGlobal().Annotator=d,this},e.plugin("annotator",t),this.Annotator=t,t.Widget=function(n){function r(n,i){r.__super__.constructor.apply(this,arguments),this.classes=e.extend({},t.Widget.prototype.classes,this.classes)}return N(r,n),r.prototype.classes={hide:"annotator-hide",invert:{x:"annotator-invert-x",y:"annotator-invert-y"}},r.prototype.checkOrientation=function(){var t,n,r,i,s;return this.resetOrientation(),s=e(p.getGlobal()),i=this.element.children(":first"),n=i.offset(),r={top:s.scrollTop(),right:s.width()+s.scrollLeft()},t={top:n.top,right:n.left+i.width()},t.top-r.top<0&&this.invertY(),t.right-r.right>0&&this.invertX(),this},r.prototype.resetOrientation=function(){return this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y),this},r.prototype.invertX=function(){return this.element.addClass(this.classes.invert.x),this},r.prototype.invertY=function(){return this.element.addClass(this.classes.invert.y),this},r.prototype.isInvertedY=function(){return this.element.hasClass(this.classes.invert.y)},r.prototype.isInvertedX=function(){return this.element.hasClass(this.classes.invert.x)},r}(n),t.Editor=function(t){function n(t){this.onCancelButtonMouseover=C(this.onCancelButtonMouseover,this),this.processKeypress=C(this.processKeypress,this),this.submit=C(this.submit,this),this.load=C(this.load,this),this.hide=C(this.hide,this),this.show=C(this.show,this),n.__super__.constructor.call(this,e(this.html)[0],t),this.fields=[],this.annotation={}}return N(n,t),n.prototype.events={"form submit":"submit",".annotator-save click":"submit",".annotator-cancel click":"hide",".annotator-cancel mouseover":"onCancelButtonMouseover","textarea keydown":"processKeypress"},n.prototype.classes={hide:"annotator-hide",focus:"annotator-focus"},n.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">'+S("Cancel")+'</a>\n<a href="#save" class="annotator-save annotator-focus">'+S("Save")+"</a>\n    </div>\n  </form>\n</div>",n.prototype.options={},n.prototype.show=function(e){return p.preventEventDefault(e),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(),this.publish("show")},n.prototype.hide=function(e){return p.preventEventDefault(e),this.element.addClass(this.classes.hide),this.publish("hide")},n.prototype.load=function(e){var t,n,r,i;this.annotation=e,this.publish("load",[this.annotation]),i=this.fields;for(n=0,r=i.length;n<r;n++)t=i[n],t.load(t.element,this.annotation);return this.show()},n.prototype.submit=function(e){var t,n,r,i;p.preventEventDefault(e),i=this.fields;for(n=0,r=i.length;n<r;n++)t=i[n],t.submit(t.element,this.annotation);return this.publish("save",[this.annotation]),this.hide()},n.prototype.addField=function(t){var n,r,i;r=e.extend({id:"annotator-field-"+p.uuid(),type:"input",label:"",load:function(){},submit:function(){}},t),i=null,n=e('<li class="annotator-item" />'),r.element=n[0];switch(r.type){case"textarea":i=e("<textarea />");break;case"input":case"checkbox":i=e("<input />")}return n.append(i),i.attr({id:r.id,placeholder:r.label}),r.type==="checkbox"&&(i[0].type="checkbox",n.addClass("annotator-checkbox"),n.append(e("<label />",{"for":r.id,html:r.label}))),this.element.find("ul:first").append(n),this.fields.push(r),r.element},n.prototype.checkOrientation=function(){var e,t;return n.__super__.checkOrientation.apply(this,arguments),t=this.element.find("ul"),e=this.element.find(".annotator-controls"),this.element.hasClass(this.classes.invert.y)?e.insertBefore(t):e.is(":first-child")&&e.insertAfter(t),this},n.prototype.processKeypress=function(e){if(e.keyCode===27)return this.hide();if(e.keyCode===13&&!e.shiftKey)return this.submit()},n.prototype.onCancelButtonMouseover=function(){return this.element.find("."+this.classes.focus).removeClass(this.classes.focus)},n.prototype.setupDraggables=function(){var t,n,r,i,s,o,u,a,f,l,c,h=this;return this.element.find(".annotator-resize").remove(),this.element.hasClass(this.classes.invert.y)?r=this.element.find(".annotator-item:last"):r=this.element.find(".annotator-item:first"),r&&e('<span class="annotator-resize"></span>').appendTo(r),s=null,t=this.classes,i=this.element,l=null,f=i.find(".annotator-resize"),n=i.find(".annotator-controls"),c=!1,o=function(t){if(t.target===this)return s={element:this,top:t.pageY,left:t.pageX},l=i.find("textarea:first"),e(window).bind({"mouseup.annotator-editor-resize":a,"mousemove.annotator-editor-resize":u}),t.preventDefault()},a=function(){return s=null,e(window).unbind(".annotator-editor-resize")},u=function(e){var r,o,u,a,h;if(s&&c===!1)return r={top:e.pageY-s.top,left:e.pageX-s.left},s.element===f[0]?(a=l.outerHeight(),h=l.outerWidth(),o=i.hasClass(t.invert.x)?-1:1,u=i.hasClass(t.invert.y)?1:-1,l.height(a+r.top*u),l.width(h+r.left*o),l.outerHeight()!==a&&(s.top=e.pageY),l.outerWidth()!==h&&(s.left=e.pageX)):s.element===n[0]&&(i.css({top:parseInt(i.css("top"),10)+r.top,left:parseInt(i.css("left"),10)+r.left}),s.top=e.pageY,s.left=e.pageX),c=!0,setTimeout(function(){return c=!1},1e3/60)},f.bind("mousedown",o),n.bind("mousedown",o)},n}(t.Widget),t.Viewer=function(t){function n(t){this.onDeleteClick=C(this.onDeleteClick,this),this.onEditClick=C(this.onEditClick,this),this.load=C(this.load,this),this.hide=C(this.hide,this),this.show=C(this.show,this),n.__super__.constructor.call(this,e(this.html.element)[0],t),this.item=e(this.html.item)[0],this.fields=[],this.annotations=[]}return N(n,t),n.prototype.events={".annotator-edit click":"onEditClick",".annotator-delete click":"onDeleteClick"},n.prototype.classes={hide:"annotator-hide",showControls:"annotator-visible"},n.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>'},n.prototype.options={readOnly:!1},n.prototype.show=function(e){var t,n=this;return p.preventEventDefault(e),t=this.element.find(".annotator-controls").addClass(this.classes.showControls),setTimeout(function(){return t.removeClass(n.classes.showControls)},500),this.element.removeClass(this.classes.hide),this.checkOrientation().publish("show")},n.prototype.isShown=function(){return!this.element.hasClass(this.classes.hide)},n.prototype.hide=function(e){return p.preventEventDefault(e),this.element.addClass(this.classes.hide),this.publish("hide")},n.prototype.load=function(t){var n,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b;this.annotations=t||[],p=this.element.find("ul:first").empty(),y=this.annotations;for(d=0,m=y.length;d<m;d++){n=y[d],l=e(this.item).clone().appendTo(p).data("annotation",n),s=l.find(".annotator-controls"),c=s.find(".annotator-link"),u=s.find(".annotator-edit"),o=s.find(".annotator-delete"),h=(new r(n.links||[])).get("alternate",{type:"text/html"}),h.length===0||h[0].href==null?c.remove():c.attr("href",h[0].href),this.options.readOnly?(u.remove(),o.remove()):i={showEdit:function(){return u.removeAttr("disabled")},hideEdit:function(){return u.attr("disabled","disabled")},showDelete:function(){return o.removeAttr("disabled")},hideDelete:function(){return o.attr("disabled","disabled")}},b=this.fields;for(v=0,g=b.length;v<g;v++)f=b[v],a=e(f.element).clone().appendTo(l)[0],f.load(a,n,i)}return this.publish("load",[this.annotations]),this.show()},n.prototype.addField=function(t){var n;return n=e.extend({load:function(){}},t),n.element=e("<div />")[0],this.fields.push(n),n.element,this},n.prototype.onEditClick=function(e){return this.onButtonClick(e,"edit")},n.prototype.onDeleteClick=function(e){return this.onButtonClick(e,"delete")},n.prototype.onButtonClick=function(t,n){var r;return r=e(t.target).parents(".annotator-annotation"),this.publish(n,[r.data("annotation")])},n}(t.Widget),r=function(){function t(e){this.data=e}return t.prototype.get=function(t,n){var r,i,s,o,u,a,f,l,c;n==null&&(n={}),n=e.extend({},n,{rel:t}),s=function(){var e;e=[];for(i in n){if(!T.call(n,i))continue;u=n[i],e.push(i)}return e}(),l=this.data,c=[];for(a=0,f=l.length;a<f;a++){r=l[a],o=s.reduce(function(e,t){return e&&r[t]===n[t]},!0);if(!o)continue;c.push(r)}return c},t}(),t=t||{},t.Notification=function(n){function r(t){this.hide=C(this.hide,this),this.show=C(this.show,this),r.__super__.constructor.call(this,e(this.options.html).appendTo(document.body)[0],t)}return N(r,n),r.prototype.events={click:"hide"},r.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"}},r.prototype.show=function(n,r){return r==null&&(r=t.Notification.INFO),e(this.element).addClass(this.options.classes.show).addClass(this.options.classes[r]).escape(n||""),setTimeout(this.hide,5e3),this},r.prototype.hide=function(){return e(this.element).removeClass(this.options.classes.show),this},r}(n),t.Notification.INFO="show",t.Notification.SUCCESS="success",t.Notification.ERROR="error",e(function(){var e;return e=new t.Notification,t.showNotification=e.show,t.hideNotification=e.hide}),t.Plugin.Unsupported=function(n){function r(){return r.__super__.constructor.apply(this,arguments)}return N(r,n),r.prototype.options={message:t._t("Sorry your current browser does not support the Annotator")},r.prototype.pluginInit=function(){var n=this;if(!t.supported())return e(function(){t.showNotification(n.options.message);if(window.XMLHttpRequest===void 0&&ActiveXObject!==void 0)return e("html").addClass("ie6")})},r}(t.Plugin),u=function(e){var t,n,r,i,s,o;return i="([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?",t=e.match(new RegExp(i)),r=0,n=new Date(t[1],0,1),t[3]&&n.setMonth(t[3]-1),t[5]&&n.setDate(t[5]),t[7]&&n.setHours(t[7]),t[8]&&n.setMinutes(t[8]),t[10]&&n.setSeconds(t[10]),t[12]&&n.setMilliseconds(Number("0."+t[12])*1e3),t[14]&&(r=Number(t[16])*60+Number(t[17]),r*=(o=t[15]==="-")!=null?o:{1:-1}),r-=n.getTimezoneOffset(),s=Number(n)+r*60*1e3,n.setTime(Number(s)),n},s=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p;if(typeof atob!="undefined"&&atob!==null)return atob(e);n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",f=0,t=0,i="",p=[];if(!e)return e;e+="";while(f<e.length)s=n.indexOf(e.charAt(f++)),o=n.indexOf(e.charAt(f++)),u=n.indexOf(e.charAt(f++)),a=n.indexOf(e.charAt(f++)),r=s<<18|o<<12|u<<6|a,l=r>>16&255,c=r>>8&255,h=r&255,u===64?p[t++]=String.fromCharCode(l):a===64?p[t++]=String.fromCharCode(l,c):p[t++]=String.fromCharCode(l,c,h);return p.join("")},o=function(e){var t,n,r,i;n=e.length%4;if(n!==0)for(t=r=0,i=4-n;0<=i?r<i:r>i;t=0<=i?++r:--r)e+="=";return e=e.replace(/-/g,"+"),e=e.replace(/_/g,"/"),s(e)},h=function(e){var t,n,r,i;return i=e.split("."),t=i[0],n=i[1],r=i[2],JSON.parse(o(n))},t.Plugin.Auth=function(n){function r(e,t){r.__super__.constructor.apply(this,arguments),this.waitingForToken=[],this.options.token?this.setToken(this.options.token):this.requestToken()}return N(r,n),r.prototype.options={token:null,tokenUrl:"/auth/token",autoFetch:!0,requestMethod:"GET",requestData:null,unauthorizedCallback:null},r.prototype.requestToken=function(){var n=this;return this.requestInProgress=!0,e.ajax({url:this.options.tokenUrl,dataType:"text",data:this.options.requestData,type:this.options.requestMethod,xhrFields:{withCredentials:!0}}).done(function(e,t,r){return n.setToken(e)}).fail(function(e,r,i){var s,o;if(e.status===401){s=n.options.unauthorizedCallback;if(s!=null&&s(n)){n.retryTimeout=setTimeout(function(){return n.requestToken()},1e3);return}}return o=t._t("Couldn't get auth token:"),console.error(""+o+" "+i,e),t.showNotification(""+o+" "+e.responseText,t.Notification.ERROR)}).always(function(){return n.requestInProgress=!1})},r.prototype.setToken=function(e){var n,r=this;this.token=e,this._unsafeToken=h(e);if(this.haveValidToken()){this.options.autoFetch&&(this.refreshTimeout=setTimeout(function(){return r.requestToken()},(this.timeToExpiry()-2)*1e3)),this.updateHeaders(),n=[];while(this.waitingForToken.length>0)n.push(this.waitingForToken.pop()(this._unsafeToken));return n}console.warn(t._t("Didn't get a valid token."));if(this.options.autoFetch)return console.warn(t._t("Getting a new token in 10s.")),setTimeout(function(){return r.requestToken()},1e4)},r.prototype.haveValidToken=function(){var e;return e=this._unsafeToken&&this.
_unsafeToken.issuedAt&&this._unsafeToken.ttl&&this._unsafeToken.consumerKey,e&&this.timeToExpiry()>0},r.prototype.timeToExpiry=function(){var e,t,n,r;return n=(new Date).getTime()/1e3,t=u(this._unsafeToken.issuedAt).getTime()/1e3,e=t+this._unsafeToken.ttl,r=e-n,r>0?r:0},r.prototype.updateHeaders=function(){var t;return t=this.element.data("annotator:headers"),this.element.data("annotator:headers",e.extend(t,{"x-annotator-auth-token":this.token}))},r.prototype.withToken=function(e){if(e==null)return;if(this.haveValidToken())return e(this._unsafeToken);this.waitingForToken.push(e);if(!this.requestInProgress)return this.requestToken()},r}(t.Plugin),t.Plugin.Store=function(n){function r(e,t){this._onError=C(this._onError,this),this._onLoadAnnotationsFromSearch=C(this._onLoadAnnotationsFromSearch,this),this._onLoadAnnotations=C(this._onLoadAnnotations,this),this._getAnnotations=C(this._getAnnotations,this),r.__super__.constructor.apply(this,arguments),this.annotations=[]}return N(r,n),r.prototype.events={annotationCreated:"annotationCreated",annotationDeleted:"annotationDeleted",annotationUpdated:"annotationUpdated"},r.prototype.options={prefix:"/store",autoFetch:!0,annotationData:{},loadFromSearch:!1,urls:{create:"/annotations",read:"/annotations/:id",update:"/annotations/:id",destroy:"/annotations/:id",search:"/search"}},r.prototype.pluginInit=function(){if(!t.supported())return;return this.annotator.plugins.Auth?this.annotator.plugins.Auth.withToken(this._getAnnotations):this._getAnnotations()},r.prototype._getAnnotations=function(){return this.options.loadFromSearch?this.loadAnnotationsFromSearch(this.options.loadFromSearch):this.loadAnnotations()},r.prototype.annotationCreated=function(e){var n=this;return k.call(this.annotations,e)<0?(this.registerAnnotation(e),this._apiRequest("create",e,function(r){return r.id==null&&console.warn(t._t("Warning: No ID returned from server for annotation "),e),n.updateAnnotation(e,r)})):this.updateAnnotation(e,{})},r.prototype.annotationUpdated=function(e){var t=this;if(k.call(this.annotations,e)>=0)return this._apiRequest("update",e,function(n){return t.updateAnnotation(e,n)})},r.prototype.annotationDeleted=function(e){var t=this;if(k.call(this.annotations,e)>=0)return this._apiRequest("destroy",e,function(){return t.unregisterAnnotation(e)})},r.prototype.registerAnnotation=function(e){return this.annotations.push(e)},r.prototype.unregisterAnnotation=function(e){return this.annotations.splice(this.annotations.indexOf(e),1)},r.prototype.updateAnnotation=function(n,r){return k.call(this.annotations,n)<0?console.error(t._t("Trying to update unregistered annotation!")):e.extend(n,r),e(n.highlights).data("annotation",n)},r.prototype.loadAnnotations=function(){return this._apiRequest("read",null,this._onLoadAnnotations)},r.prototype._onLoadAnnotations=function(e){return e==null&&(e=[]),this.annotations=e,this.annotator.loadAnnotations(e.slice())},r.prototype.loadAnnotationsFromSearch=function(e){return this._apiRequest("search",e,this._onLoadAnnotationsFromSearch)},r.prototype._onLoadAnnotationsFromSearch=function(e){return e==null&&(e={}),this._onLoadAnnotations(e.rows||[])},r.prototype.dumpAnnotations=function(){var e,t,n,r,i;r=this.annotations,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(JSON.parse(this._dataFor(e)));return i},r.prototype._apiRequest=function(t,n,r){var i,s,o,u;return i=n&&n.id,u=this._urlFor(t,i),s=this._apiRequestOptions(t,n,r),o=e.ajax(u,s),o._id=i,o._action=t,o},r.prototype._apiRequestOptions=function(t,n,r){var i;return i={type:this._methodFor(t),headers:this.element.data("annotator:headers"),dataType:"json",success:r||function(){},error:this._onError},t==="search"?i=e.extend(i,{data:n}):i=e.extend(i,{data:n&&this._dataFor(n),contentType:"application/json; charset=utf-8"}),i},r.prototype._urlFor=function(e,t){var n,r;return n=t!=null?"/"+t:"",r=this.options.prefix||"/",r+=this.options.urls[e],r=r.replace(/\/:id/,n),r},r.prototype._methodFor=function(e){var t;return t={create:"POST",read:"GET",update:"PUT",destroy:"DELETE",search:"GET"},t[e]},r.prototype._dataFor=function(t){var n,r;return r=t.highlights,delete t.highlights,e.extend(t,this.options.annotationData),n=JSON.stringify(t),r&&(t.highlights=r),n},r.prototype._onError=function(e){var n,r;n=e._action,r=t._t("Sorry we could not ")+n+t._t(" this annotation"),e._action==="search"?r=t._t("Sorry we could not search the store for annotations"):e._action==="read"&&!e._id&&(r=t._t("Sorry we could not ")+n+t._t(" the annotations from the store"));switch(e.status){case 401:r=t._t("Sorry you are not allowed to ")+n+t._t(" this annotation");break;case 404:r=t._t("Sorry we could not connect to the annotations store");break;case 500:r=t._t("Sorry something went wrong with the annotation store")}return t.showNotification(r,t.Notification.ERROR),console.error(t._t("API request failed:")+(" '"+e.status+"'"))},r}(t.Plugin),t.Plugin.Permissions=function(n){function r(e,t){this._setAuthFromToken=C(this._setAuthFromToken,this),this.updateViewer=C(this.updateViewer,this),this.updateAnnotationPermissions=C(this.updateAnnotationPermissions,this),this.updatePermissionsField=C(this.updatePermissionsField,this),this.addFieldsToAnnotation=C(this.addFieldsToAnnotation,this),r.__super__.constructor.apply(this,arguments),this.options.user&&(this.setUser(this.options.user),delete this.options.user)}return N(r,n),r.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"},r.prototype.options={showViewPermissionsCheckbox:!0,showEditPermissionsCheckbox:!0,userId:function(e){return e},userString:function(e){return e},userAuthorize:function(e,t,n){var r,i,s,o;if(t.permissions){i=t.permissions[e]||[];if(i.length===0)return!0;for(s=0,o=i.length;s<o;s++){r=i[s];if(this.userId(n)===r)return!0}return!1}return t.user?n&&this.userId(n)===this.userId(t.user):!0},user:"",permissions:{read:[],update:[],"delete":[],admin:[]}},r.prototype.pluginInit=function(){var e,n,r=this;if(!t.supported())return;n=this,e=function(e,t){return function(r,i){return n[e].call(n,t,r,i)}},!this.user&&this.annotator.plugins.Auth&&this.annotator.plugins.Auth.withToken(this._setAuthFromToken),this.options.showViewPermissionsCheckbox===!0&&this.annotator.editor.addField({type:"checkbox",label:t._t("Allow anyone to <strong>view</strong> this annotation"),load:e("updatePermissionsField","read"),submit:e("updateAnnotationPermissions","read")}),this.options.showEditPermissionsCheckbox===!0&&this.annotator.editor.addField({type:"checkbox",label:t._t("Allow anyone to <strong>edit</strong> this annotation"),load:e("updatePermissionsField","update"),submit:e("updateAnnotationPermissions","update")}),this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter)return this.annotator.plugins.Filter.addFilter({label:t._t("User"),property:"user",isFiltered:function(e,t){var n,i,s,o;t=r.options.userString(t);if(!e||!t)return!1;o=e.split(/\s*/);for(i=0,s=o.length;i<s;i++){n=o[i];if(t.indexOf(n)===-1)return!1}return!0}})},r.prototype.setUser=function(e){return this.user=e},r.prototype.addFieldsToAnnotation=function(e){if(e){e.permissions=this.options.permissions;if(this.user)return e.user=this.user}},r.prototype.authorize=function(e,t,n){return n===void 0&&(n=this.user),this.options.userAuthorize?this.options.userAuthorize.call(this.options,e,t,n):!0},r.prototype.updatePermissionsField=function(t,n,r){var i;return n=e(n).show(),i=n.find("input").removeAttr("disabled"),this.authorize("admin",r)||n.hide(),this.authorize(t,r||{},null)?i.attr("checked","checked"):i.removeAttr("checked")},r.prototype.updateAnnotationPermissions=function(t,n,r){var i;return r.permissions||(r.permissions=this.options.permissions),i=t+"-permissions",e(n).find("input").is(":checked")?r.permissions[t]=[]:r.permissions[t]=[this.user]},r.prototype.updateViewer=function(n,r,i){var s,o;n=e(n),o=this.options.userString(r.user),r.user&&o&&typeof o=="string"?(s=t.$.escape(this.options.userString(r.user)),n.html(s).addClass("annotator-user")):n.remove();if(i){this.authorize("update",r)||i.hideEdit();if(!this.authorize("delete",r))return i.hideDelete()}},r.prototype._setAuthFromToken=function(e){return this.setUser(e.userId)},r}(t.Plugin),t.Plugin.Filter=function(n){function r(t,n){this._onPreviousClick=C(this._onPreviousClick,this),this._onNextClick=C(this._onNextClick,this),this._onFilterKeyup=C(this._onFilterKeyup,this),this._onFilterBlur=C(this._onFilterBlur,this),this._onFilterFocus=C(this._onFilterFocus,this),this.updateHighlights=C(this.updateHighlights,this);var i;t=e(this.html.element).appendTo((n!=null?n.appendTo:void 0)||this.options.appendTo),r.__super__.constructor.call(this,t,n),(i=this.options).filters||(i.filters=[]),this.filter=e(this.html.filter),this.filters=[],this.current=0}return N(r,n),r.prototype.events={".annotator-filter-property input focus":"_onFilterFocus",".annotator-filter-property input blur":"_onFilterBlur",".annotator-filter-property input keyup":"_onFilterKeyup",".annotator-filter-previous click":"_onPreviousClick",".annotator-filter-next click":"_onNextClick",".annotator-filter-clear click":"_onClearClick"},r.prototype.classes={active:"annotator-filter-active",hl:{hide:"annotator-hl-filtered",active:"annotator-hl-active"}},r.prototype.html={element:'<div class="annotator-filter">\n  <strong>'+t._t("Navigate:")+'</strong>\n<span class="annotator-filter-navigation">\n  <button class="annotator-filter-previous">'+t._t("Previous")+'</button>\n<button class="annotator-filter-next">'+t._t("Next")+"</button>\n</span>\n<strong>"+t._t("Filter by:")+"</strong>\n</div>",filter:'<span class="annotator-filter-property">\n  <label></label>\n  <input/>\n  <button class="annotator-filter-clear">'+t._t("Clear")+"</button>\n</span>"},r.prototype.options={appendTo:"body",filters:[],addAnnotationFilter:!0,isFiltered:function(e,t){var n,r,i,s;if(!e||!t)return!1;s=e.split(/\s*/);for(r=0,i=s.length;r<i;r++){n=s[r];if(t.indexOf(n)===-1)return!1}return!0}},r.prototype.pluginInit=function(){var e,n,r,i;i=this.options.filters;for(n=0,r=i.length;n<r;n++)e=i[n],this.addFilter(e);this.updateHighlights(),this._setupListeners()._insertSpacer();if(this.options.addAnnotationFilter===!0)return this.addFilter({label:t._t("Annotation"),property:"text"})},r.prototype._insertSpacer=function(){var t,n;return n=e("html"),t=parseInt(n.css("padding-top"),10)||0,n.css("padding-top",t+this.element.outerHeight()),this},r.prototype._setupListeners=function(){var e,t,n,r;t=["annotationsLoaded","annotationCreated","annotationUpdated","annotationDeleted"];for(n=0,r=t.length;n<r;n++)e=t[n],this.annotator.subscribe(e,this.updateHighlights);return this},r.prototype.addFilter=function(n){var r,i;i=e.extend({label:"",property:"",isFiltered:this.options.isFiltered},n);if(!function(){var e,t,n,s;n=this.filters,s=[];for(e=0,t=n.length;e<t;e++)r=n[e],r.property===i.property&&s.push(r);return s}.call(this).length)i.id="annotator-filter-"+i.property,i.annotations=[],i.element=this.filter.clone().appendTo(this.element),i.element.find("label").html(i.label).attr("for",i.id),i.element.find("input").attr({id:i.id,placeholder:t._t("Filter by ")+i.label+"…"}),i.element.find("button").hide(),i.element.data("filter",i),this.filters.push(i);return this},r.prototype.updateFilter=function(t){var n,r,i,s,o,u,a;t.annotations=[],this.updateHighlights(),this.resetHighlights(),i=e.trim(t.element.find("input").val());if(i){r=this.highlights.map(function(){return e(this).data("annotation")}),a=e.makeArray(r);for(o=0,u=a.length;o<u;o++)n=a[o],s=n[t.property],t.isFiltered(i,s)&&t.annotations.push(n);return this.filterHighlights()}},r.prototype.updateHighlights=function(){return this.highlights=this.annotator.element.find(".annotator-hl:visible"),this.filtered=this.highlights.not(this.classes.hl.hide)},r.prototype.filterHighlights=function(){var t,n,r,i,s,o,u,a,f,l;t=e.grep(this.filters,function(e){return!!e.annotations.length}),i=((l=t[0])!=null?l.annotations:void 0)||[],t.length>1&&(r=[],e.each(t,function(){return e.merge(r,this.annotations)}),u=[],i=[],e.each(r,function(){return e.inArray(this,u)===-1?u.push(this):i.push(this)})),s=this.highlights;for(o=a=0,f=i.length;a<f;o=++a)n=i[o],s=s.not(n.highlights);return s.addClass(this.classes.hl.hide),this.filtered=this.highlights.not(this.classes.hl.hide),this},r.prototype.resetHighlights=function(){return this.highlights.removeClass(this.classes.hl.hide),this.filtered=this.highlights,this},r.prototype._onFilterFocus=function(t){var n;return n=e(t.target),n.parent().addClass(this.classes.active),n.next("button").show()},r.prototype._onFilterBlur=function(t){var n;if(!t.target.value)return n=e(t.target),n.parent().removeClass(this.classes.active),n.next("button").hide()},r.prototype._onFilterKeyup=function(t){var n;n=e(t.target).parent().data("filter");if(n)return this.updateFilter(n)},r.prototype._findNextHighlight=function(e){var t,n,r,i,s,o,u,a;return this.highlights.length?(o=e?0:-1,a=e?-1:0,u=e?"lt":"gt",t=this.highlights.not("."+this.classes.hl.hide),r=t.filter("."+this.classes.hl.active),r.length||(r=t.eq(o)),n=r.data("annotation"),i=t.index(r[0]),s=t.filter(":"+u+"("+i+")").not(n.highlights).eq(a),s.length||(s=t.eq(a)),this._scrollToHighlight(s.data("annotation").highlights)):this},r.prototype._onNextClick=function(e){return this._findNextHighlight()},r.prototype._onPreviousClick=function(e){return this._findNextHighlight(!0)},r.prototype._scrollToHighlight=function(t){return t=e(t),this.highlights.removeClass(this.classes.hl.active),t.addClass(this.classes.hl.active),e("html, body").animate({scrollTop:t.offset().top-(this.element.height()+20)},150)},r.prototype._onClearClick=function(t){return e(t.target).prev("input").val("").keyup().blur()},r}(t.Plugin),t.Plugin.Markdown=function(n){function r(e,n){this.updateTextField=C(this.updateTextField,this),(typeof Showdown!=="undefined"&&Showdown!==null?Showdown.converter:void 0)!=null?(r.__super__.constructor.apply(this,arguments),this.converter=new Showdown.converter):console.error(t._t("To use the Markdown plugin, you must include Showdown into the page first."))}return N(r,n),r.prototype.events={annotationViewerTextField:"updateTextField"},r.prototype.updateTextField=function(n,r){var i;return i=t.$.escape(r.text||""),e(n).html(this.convert(i))},r.prototype.convert=function(e){return this.converter.makeHtml(e)},r}(t.Plugin),t.Plugin.Tags=function(n){function r(){return this.setAnnotationTags=C(this.setAnnotationTags,this),this.updateField=C(this.updateField,this),r.__super__.constructor.apply(this,arguments)}return N(r,n),r.prototype.options={parseTags:function(t){var n;return t=e.trim(t),n=[],t&&(n=t.split(/\s+/)),n},stringifyTags:function(e){return e.join(" ")}},r.prototype.field=null,r.prototype.input=null,r.prototype.pluginInit=function(){if(!t.supported())return;return this.field=this.annotator.editor.addField({label:t._t("Add some tags here")+"…",load:this.updateField,submit:this.setAnnotationTags}),this.annotator.viewer.addField({load:this.updateViewer}),this.annotator.plugins.Filter&&this.annotator.plugins.Filter.addFilter({label:t._t("Tag"),property:"tags",isFiltered:t.Plugin.Tags.filterCallback}),this.input=e(this.field).find(":input")},r.prototype.parseTags=function(e){return this.options.parseTags(e)},r.prototype.stringifyTags=function(e){return this.options.stringifyTags(e)},r.prototype.updateField=function(e,t){var n;return n="",t.tags&&(n=this.stringifyTags(t.tags)),this.input.val(n)},r.prototype.setAnnotationTags=function(e,t){return t.tags=this.parseTags(this.input.val())},r.prototype.updateViewer=function(n,r){return n=e(n),r.tags&&e.isArray(r.tags)&&r.tags.length?n.addClass("annotator-tags").html(function(){var n;return n=e.map(r.tags,function(e){return'<span class="annotator-tag">'+t.$.escape(e)+"</span>"}).join(" ")}):n.remove()},r}(t.Plugin),t.Plugin.Tags.filterCallback=function(e,t){var n,r,i,s,o,u,a,f;t==null&&(t=[]),i=0,r=[];if(e){r=e.split(/\s+/g);for(o=0,a=r.length;o<a;o++){n=r[o];if(t.length)for(u=0,f=t.length;u<f;u++)s=t[u],s.indexOf(n)!==-1&&(i+=1)}}return i===r.length},t.Plugin.DigilibIntegrator=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return N(t,e),t.prototype.events={annotationDeleted:"annotationDeleted"},t.prototype.options={hooks:null},t.prototype.pluginInit=function(){return console.debug("DigilibIntegrator plugin init"),this.annotator.digilib=this.options.hooks,this.annotator.setupRangeAnnotation=this.annotator.setupAnnotation,this.annotator.setupAnnotation=this._setupAnnotation,this},t.prototype._setupAnnotation=function(e,t){return t==null&&(t=!0),this.selectedAreas!=null||e.areas!=null?(console.debug("setupAnnotation for areas!"),e.areas||(e.areas=this.selectedAreas),e.highlights=[],e.ranges=[],this.digilib.setupAnnotation(e),t&&this.publish("annotationCreated",[e]),e):this.setupRangeAnnotation.apply(this,arguments)},t.prototype.annotationDeleted=function(e){return this.options.hooks.annotationDeleted(e)},t}(t.Plugin)}).call(this);