Mercurial > hg > digilib
changeset 1602:bd88824db017 release-2.5
Merge from default
fdc1ba44753952affe626abbcd804796a9f1207b
author | robcast |
---|---|
date | Mon, 13 Feb 2017 19:54:43 +0100 |
parents | e52ac05b302d (current diff) fdc1ba447539 (diff) |
children | 87e26192f7fa |
files | common/src/main/java/digilib/conf/DigilibConfiguration.java webapp/src/main/webapp/jquery/jquery.digilib.js |
diffstat | 10 files changed, 47 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/common/src/main/java/digilib/conf/DigilibConfiguration.java Mon Feb 13 17:08:04 2017 +0100 +++ b/common/src/main/java/digilib/conf/DigilibConfiguration.java Mon Feb 13 19:54:43 2017 +0100 @@ -57,7 +57,7 @@ /** digilib version */ public static String getClassVersion() { - return "2.5.0"; + return "2.5.1"; } /* non-static getVersion for Java inheritance */
--- a/webapp/src/main/webapp/api/ImgInfo-json.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/ImgInfo-json.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -37,7 +37,7 @@ System.out.println(e); } } -%><% +%><%@ page contentType="application/json" pageEncoding="UTF-8" %><% // parsing the query docBean.setRequest(request); // get file
--- a/webapp/src/main/webapp/api/dirInfo-json.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/dirInfo-json.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -40,7 +40,7 @@ System.out.println(e); } } -%><%@ page contentType="application/json" %><% +%><%@ page contentType="application/json" pageEncoding="UTF-8" %><% // process request docBean.setRequest(request); // get directory
--- a/webapp/src/main/webapp/api/dirInfo-xml.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/dirInfo-xml.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -40,7 +40,7 @@ System.out.println(e); } } -%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ page contentType="text/xml" %><?xml version="1.0" encoding="UTF-8" ?> +%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ page contentType="text/xml" pageEncoding="UTF-8"%><?xml version="1.0" encoding="UTF-8" ?> <% // process request docBean.setRequest(request);
--- a/webapp/src/main/webapp/api/dlContext-xml.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/dlContext-xml.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -38,7 +38,7 @@ System.out.println(e); } } -%><?xml version="1.0" encoding="UTF-8" ?> +%><%@ page contentType="text/xml" pageEncoding="UTF-8"%><?xml version="1.0" encoding="UTF-8" ?> <% // process request // get digilib config
--- a/webapp/src/main/webapp/api/dlInfo-json.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/dlInfo-json.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -34,7 +34,7 @@ System.out.println(e); } } -%><% +%><%@ page contentType="application/json" pageEncoding="UTF-8" %><% // parsing the query DigilibServletRequest dlRequest = new DigilibServletRequest(request); docBean.setRequest(dlRequest);
--- a/webapp/src/main/webapp/api/dlInfo-xml.jsp Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/api/dlInfo-xml.jsp Mon Feb 13 19:54:43 2017 +0100 @@ -34,7 +34,7 @@ System.out.println(e); } } -%><?xml version="1.0" encoding="UTF-8" ?> +%><%@ page contentType="text/xml" pageEncoding="UTF-8"%><?xml version="1.0" encoding="UTF-8" ?> <% // process request // parsing the query
--- a/webapp/src/main/webapp/jquery/annotator-dl.js Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/jquery/annotator-dl.js Mon Feb 13 19:54:43 2017 +0100 @@ -1,13 +1,13 @@ /* -** Annotator v1.2.9-dev-cab39d7 +** Annotator v1.2.10-dev-976a5f0 ** https://github.com/okfn/annotator/ ** -** Copyright 2015, the Annotator project contributors. +** Copyright 2017, the Annotator project contributors. ** Dual licensed under the MIT and GPLv3 licenses. ** https://github.com/okfn/annotator/blob/master/LICENSE ** -** Built at: 2015-02-20 19:20:03Z +** Built at: 2017-02-13 17:46:12Z */ @@ -613,7 +613,11 @@ } } if (r.end == null) { - node = this.endContainer.childNodes[this.endOffset - 1]; + if (this.endOffset) { + node = this.endContainer.childNodes[this.endOffset - 1]; + } else { + node = this.endContainer.previousSibling; + } r.end = Util.getLastTextNodeUpTo(node); r.endOffset = r.end.nodeValue.length; } @@ -1249,7 +1253,7 @@ }; Annotator.prototype.isAnnotator = function(element) { - return !!$(element).parents().addBack().filter('[class^=annotator-]').not('[class=annotator-hl]').not(this.wrapper).length; + return !!$(element).parents().addBack().filter('[class^=annotator-]').not('[class^=annotator-hl]').not(this.wrapper).length; }; Annotator.prototype.onHighlightMouseover = function(event) { @@ -1677,16 +1681,16 @@ left: event.pageX - mousedown.left }; if (mousedown.element === resize[0]) { - height = textarea.outerHeight(); - width = textarea.outerWidth(); + height = textarea.height(); + width = textarea.width(); 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) { + if (textarea.height() !== height) { mousedown.top = event.pageY; } - if (textarea.outerWidth() !== width) { + if (textarea.width() !== width) { mousedown.left = event.pageX; } } else if (mousedown.element === controls[0]) { @@ -2277,7 +2281,7 @@ var _this = this; if (__indexOf.call(this.annotations, annotation) >= 0) { return this._apiRequest('destroy', annotation, (function() { - _this.publish("annotationDestroyed", [annotation]); + _this.publish('annotationDestroyed', [annotation]); return _this.unregisterAnnotation(annotation); })); } @@ -2297,7 +2301,7 @@ } else { $.extend(annotation, data); } - this.publish("annotationStored", [data]); + this.publish('annotationStored', [data]); return $(annotation.highlights).data('annotation', annotation); }; @@ -2307,10 +2311,10 @@ Store.prototype._onLoadAnnotations = function(data) { var a, annotation, annotationMap, newData, _k, _l, _len2, _len3, _ref3; - this.publish("annotationRead", [this.annotations, data]); if (data == null) { data = []; } + this.publish("annotationRead", [this.annotations, data]); annotationMap = {}; _ref3 = this.annotations; for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { @@ -2339,7 +2343,7 @@ if (data == null) { data = {}; } - this.publish("annotationSearchResult", [this.annotations, data]); + this.publish('annotationSearchResult', [this.annotations, data]); return this._onLoadAnnotations(data.rows || []); }; @@ -2930,7 +2934,8 @@ GroupPermissions.prototype._cleanPermissions = function(annotation) { var perm, type, _k, _len2, _ref3, _results; perm = annotation.permissions['admin']; - _ref3 = ['delete', 'update', 'read']; + annotation.permissions['delete'] = perm; + _ref3 = ['update', 'read']; _results = []; for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { type = _ref3[_k];
--- a/webapp/src/main/webapp/jquery/annotator-dl.min.js Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/jquery/annotator-dl.min.js Mon Feb 13 19:54:43 2017 +0100 @@ -1,1 +1,20 @@ -(function(){var y,d,b,s,I,c,H,a,e,t,v,q,G,D,u,h,J,x,k,C,z,F,E,r,i,A,p,n,m,l,B,w=[].slice,K={}.hasOwnProperty,j=function(N,L){for(var g in L){if(K.call(L,g)){N[g]=L[g]}}function M(){this.constructor=N}M.prototype=L.prototype;N.prototype=new M();N.__super__=L.prototype;return N},f=function(g,L){return function(){return g.apply(L,arguments)}},o=[].indexOf||function(M){for(var L=0,g=this.length;L<g;L++){if(L in this&&this[L]===M){return L}}return -1};x=function(g){var L;L=this.map(function(){var O,M,P,N;P="";O=this;while((O!=null?O.nodeType:void 0)===Node.ELEMENT_NODE&&O!==g){N=O.tagName.replace(":","\\:");M=y(O.parentNode).children(N).index(O)+1;M="["+M+"]";P="/"+O.tagName.toLowerCase()+M+P;O=O.parentNode}return P});return L.get()};k=function(M){var N,L,O,g;N=function(Q){var P,R;P=D(Q);R=u(Q);return""+P+"["+R+"]"};g=M;L=function(Q){var P;P="";while(Q!==g){if(Q==null){throw new Error("Called getPathTo on a node which was not a descendant of @rootNode. "+g)}P=(N(Q))+"/"+P;Q=Q.parentNode}P="/"+P;P=P.replace(/\/$/,"");return P};O=this.map(function(){var P;P=L(this);return P});return O.get()};t=function(N,Q,P){var L,M,S,g,O,R;if(!N.hasChildNodes()){throw new Error("XPath error: node has no children!")}M=N.childNodes;S=0;for(O=0,R=M.length;O<R;O++){L=M[O];g=D(L);if(g===Q){S+=1;if(S===P){return L}}}throw new Error("XPath error: wanted child not found.")};D=function(g){var L;L=g.nodeName.toLowerCase();switch(L){case"#text":return"text()";case"#comment":return"comment()";case"#cdata-section":return"cdata-section()";default:return L}};u=function(L){var M,g;M=0;g=L;while(g){if(g.nodeName===L.nodeName){M++}g=g.previousSibling}return M};h=null;if(typeof Gettext!=="undefined"&&Gettext!==null){z=new Gettext({domain:"annotator"});h=function(g){return z.gettext(g)}}else{h=function(g){return g}}B=function(g){return h(g)};if(!(typeof jQuery!=="undefined"&&jQuery!==null?(A=jQuery.fn)!=null?A.jquery:void 0:void 0)){console.error(B("Annotator requires jQuery: have you included lib/vendor/jquery.js?"))}if(!(JSON&&JSON.parse&&JSON.stringify)){console.error(B("Annotator requires a JSON implementation: have you included lib/vendor/json2.js?"))}y=jQuery;c={};c.flatten=function(L){var g;g=function(N){var O,Q,P,M;Q=[];for(P=0,M=N.length;P<M;P++){O=N[P];Q=Q.concat(O&&y.isArray(O)?g(O):O)}return Q};return g(L)};c.contains=function(g,M){var L;L=M;while(L!=null){if(L===g){return true}L=L.parentNode}return false};c.getTextNodes=function(L){var g;g=function(N){var M;if(N&&N.nodeType!==Node.TEXT_NODE){M=[];if(N.nodeType!==Node.COMMENT_NODE){N=N.lastChild;while(N){M.push(g(N));N=N.previousSibling}}return M.reverse()}else{return N}};return L.map(function(){return c.flatten(g(this))})};c.getLastTextNodeUpTo=function(L){var g;switch(L.nodeType){case Node.TEXT_NODE:return L;case Node.ELEMENT_NODE:if(L.lastChild!=null){g=c.getLastTextNodeUpTo(L.lastChild);if(g!=null){return g}}break}L=L.previousSibling;if(L!=null){return c.getLastTextNodeUpTo(L)}else{return null}};c.getFirstTextNodeNotBefore=function(L){var g;switch(L.nodeType){case Node.TEXT_NODE:return L;case Node.ELEMENT_NODE:if(L.firstChild!=null){g=c.getFirstTextNodeNotBefore(L.firstChild);if(g!=null){return g}}break}L=L.nextSibling;if(L!=null){return c.getFirstTextNodeNotBefore(L)}else{return null}};c.readRangeViaSelection=function(g){var L;L=c.getGlobal().getSelection();L.removeAllRanges();L.addRange(g.toRange());return L.toString()};c.xpathFromNode=function(M,N){var L,g;try{g=x.call(M,N)}catch(O){L=O;console.log("jQuery-based XPath construction failed! Falling back to manual.");g=k.call(M,N)}return g};c.nodeFromXPath=function(P,R){var T,g,M,L,Q,O,S,N;Q=P.substring(1).split("/");M=R;for(O=0,S=Q.length;O<S;O++){L=Q[O];N=L.split("["),g=N[0],T=N[1];T=T!=null?parseInt((T!=null?T.split("]"):void 0)[0]):1;M=t(M,g.toLowerCase(),T)}return M};c.escape=function(g){return g.replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")};c.uuid=(function(){var g;g=0;return function(){return g++}})();c.getGlobal=function(){return(function(){return this})()};c.maxZIndex=function(M){var L,g;L=(function(){var P,O,N;N=[];for(P=0,O=M.length;P<O;P++){g=M[P];if(y(g).css("position")==="static"){N.push(-1)}else{N.push(parseFloat(y(g).css("z-index"))||-1)}}return N})();return Math.max.apply(Math,L)};c.mousePosition=function(L,N){var M,g;if((g=y(N).css("position"))!=="absolute"&&g!=="fixed"&&g!=="relative"){N=y(N).offsetParent()[0]}M=y(N).offset();return{top:L.pageY-M.top,left:L.pageX-M.left}};c.preventEventDefault=function(g){return g!=null?typeof g.preventDefault==="function"?g.preventDefault():void 0:void 0};q=["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){if(console.group==null){console.group=function(g){return console.log("GROUP: ",g)}}if(console.groupCollapsed==null){console.groupCollapsed=console.group}for(F=0,r=q.length;F<r;F++){v=q[F];if(console[v]==null){console[v]=function(){return console.log(B("Not implemented:")+(" console."+name))}}}}else{this.console={};for(E=0,i=q.length;E<i;E++){v=q[E];this.console[v]=function(){}}this.console.error=function(){var g;g=1<=arguments.length?w.call(arguments,0):[];return alert("ERROR: "+(g.join(", ")))};this.console.warn=function(){var g;g=1<=arguments.length?w.call(arguments,0):[];return alert("WARNING: "+(g.join(", ")))}}b=(function(){g.prototype.events={};g.prototype.options={};g.prototype.element=null;function g(M,L){this.options=y.extend(true,{},this.options,L);this.element=y(M);this._closures={};this.on=this.subscribe;this.addEvents()}g.prototype.destroy=function(){return this.removeEvents()};g.prototype.addEvents=function(){var P,O,M,L,N;L=g._parseEvents(this.events);N=[];for(O=0,M=L.length;O<M;O++){P=L[O];N.push(this._addEvent(P.selector,P.event,P.functionName))}return N};g.prototype.removeEvents=function(){var P,O,M,L,N;L=g._parseEvents(this.events);N=[];for(O=0,M=L.length;O<M;O++){P=L[O];N.push(this._removeEvent(P.selector,P.event,P.functionName))}return N};g.prototype._addEvent=function(L,M,N){var P,O=this;P=function(){return O[N].apply(O,arguments)};if(L===""&&g._isCustomEvent(M)){this.subscribe(M,P)}else{this.element.delegate(L,M,P)}this._closures[""+L+"/"+M+"/"+N]=P;return this};g.prototype._removeEvent=function(L,M,N){var O;O=this._closures[""+L+"/"+M+"/"+N];if(L===""&&g._isCustomEvent(M)){this.unsubscribe(M,O)}else{this.element.undelegate(L,M,O)}delete this._closures[""+L+"/"+M+"/"+N];return this};g.prototype.publish=function(){this.element.triggerHandler.apply(this.element,arguments);return this};g.prototype.subscribe=function(L,N){var M;M=function(){return N.apply(this,[].slice.call(arguments,1))};M.guid=N.guid=(y.guid+=1);this.element.bind(L,M);return this};g.prototype.unsubscribe=function(){this.element.unbind.apply(this.element,arguments);return this};return g})();b._parseEvents=function(M){var P,N,R,Q,L,O,g;N=[];for(Q in M){R=M[Q];g=Q.split(" "),L=2<=g.length?w.call(g,0,O=g.length-1):(O=0,[]),P=g[O++];N.push({selector:L.join(" "),event:P,functionName:R})}return N};b.natives=(function(){var L,g,M;g=(function(){var N,O;N=jQuery.event.special;O=[];for(L in N){if(!K.call(N,L)){continue}M=N[L];O.push(L)}return O})();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(g)})();b._isCustomEvent=function(g){g=g.split(".")[0];return y.inArray(g,b.natives)===-1};I={};I.sniff=function(g){if(g.commonAncestorContainer!=null){return new I.BrowserRange(g)}else{if(typeof g.start==="string"){return new I.SerializedRange(g)}else{if(g.start&&typeof g.start==="object"){return new I.NormalizedRange(g)}else{console.error(B("Could not sniff range type"));return false}}}};I.nodeFromXPath=function(L,g){var Q,P,M,O,N;if(g==null){g=document}P=function(T,R){var S;if(R==null){R=null}try{return document.evaluate("."+T,g,R,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(U){S=U;console.log("XPath evaluation failed.");console.log("Trying fallback...");return c.nodeFromXPath(T,g)}};if(!y.isXMLDoc(document.documentElement)){return P(L)}else{Q=document.createNSResolver(document.ownerDocument===null?document.documentElement:document.ownerDocument.documentElement);O=P(L,Q);if(!O){L=((function(){var U,S,R,T;R=L.split("/");T=[];for(U=0,S=R.length;U<S;U++){N=R[U];if(N&&N.indexOf(":")===-1){T.push(N.replace(/^([a-z]+)/,"xhtml:$1"))}else{T.push(N)}}return T})()).join("/");M=document.lookupNamespaceURI(null);Q=function(R){if(R==="xhtml"){return M}else{return document.documentElement.getAttribute("xmlns:"+R)}};O=P(L,Q)}return O}};I.RangeError=(function(g){j(L,g);function L(N,O,M){this.type=N;this.message=O;this.parent=M!=null?M:null;L.__super__.constructor.call(this,this.message)}return L})(Error);I.BrowserRange=(function(){function g(L){this.commonAncestorContainer=L.commonAncestorContainer;this.startContainer=L.startContainer;this.startOffset=L.startOffset;this.endContainer=L.endContainer;this.endOffset=L.endOffset}g.prototype.normalize=function(L){var P,O,N,M;if(this.tainted){console.error(B("You may only call normalize() once on a BrowserRange!"));return false}else{this.tainted=true}M={};if(this.startContainer.nodeType===Node.ELEMENT_NODE){M.start=c.getFirstTextNodeNotBefore(this.startContainer.childNodes[this.startOffset]);M.startOffset=0}else{M.start=this.startContainer;M.startOffset=this.startOffset}if(this.endContainer.nodeType===Node.ELEMENT_NODE){O=this.endContainer.childNodes[this.endOffset];if(O!=null){P=O;while((P!=null)&&(P.nodeType!==Node.TEXT_NODE)){P=P.firstChild}if(P!=null){M.end=P;M.endOffset=0}}if(M.end==null){O=this.endContainer.childNodes[this.endOffset-1];M.end=c.getLastTextNodeUpTo(O);M.endOffset=M.end.nodeValue.length}}else{M.end=this.endContainer;M.endOffset=this.endOffset}N={};if(M.startOffset>0){if(M.start.nodeValue.length>M.startOffset){N.start=M.start.splitText(M.startOffset)}else{N.start=M.start.nextSibling}}else{N.start=M.start}if(M.start===M.end){if(N.start.nodeValue.length>(M.endOffset-M.startOffset)){N.start.splitText(M.endOffset-M.startOffset)}N.end=N.start}else{if(M.end.nodeValue.length>M.endOffset){M.end.splitText(M.endOffset)}N.end=M.end}N.commonAncestor=this.commonAncestorContainer;while(N.commonAncestor.nodeType!==Node.ELEMENT_NODE){N.commonAncestor=N.commonAncestor.parentNode}return new I.NormalizedRange(N)};g.prototype.serialize=function(L,M){return this.normalize(L).serialize(L,M)};return g})();I.NormalizedRange=(function(){function g(L){this.commonAncestor=L.commonAncestor;this.start=L.start;this.end=L.end}g.prototype.normalize=function(L){return this};g.prototype.limit=function(R){var N,Q,O,P,M,L;N=y.grep(this.textNodes(),function(S){return S.parentNode===R||y.contains(R,S.parentNode)});if(!N.length){return null}this.start=N[0];this.end=N[N.length-1];O=y(this.start).parents();L=y(this.end).parents();for(P=0,M=L.length;P<M;P++){Q=L[P];if(O.index(Q)!==-1){this.commonAncestor=Q;break}}return this};g.prototype.serialize=function(N,O){var M,L,P;L=function(U,T){var S,R,W,Z,Y,X,V,Q;if(O){Z=y(U).parents(":not("+O+")").eq(0)}else{Z=y(U).parent()}X=c.xpathFromNode(Z,N)[0];Y=c.getTextNodes(Z);R=Y.slice(0,Y.index(U));W=0;for(V=0,Q=R.length;V<Q;V++){S=R[V];W+=S.nodeValue.length}if(T){return[X,W+U.nodeValue.length]}else{return[X,W]}};P=L(this.start);M=L(this.end,true);return new I.SerializedRange({start:P[0],end:M[0],startOffset:P[1],endOffset:M[1]})};g.prototype.text=function(){var L;return((function(){var P,N,M,O;M=this.textNodes();O=[];for(P=0,N=M.length;P<N;P++){L=M[P];O.push(L.nodeValue)}return O}).call(this)).join("")};g.prototype.textNodes=function(){var M,O,N,L;N=c.getTextNodes(y(this.commonAncestor));L=[N.index(this.start),N.index(this.end)],O=L[0],M=L[1];return y.makeArray(N.slice(O,+M+1||9000000000))};g.prototype.toRange=function(){var L;L=document.createRange();L.setStartBefore(this.start);L.setEndAfter(this.end);return L};return g})();I.SerializedRange=(function(){function g(L){this.start=L.start;this.startOffset=L.startOffset;this.end=L.end;this.endOffset=L.endOffset}g.prototype.normalize=function(X){var T,W,O,Q,N,V,aa,Z,S,P,M,L,U,R;V={};U=["start","end"];for(S=0,M=U.length;S<M;S++){N=U[S];try{Q=I.nodeFromXPath(this[N],X)}catch(Y){W=Y;throw new I.RangeError(N,("Error while finding "+N+" node: "+this[N]+": ")+W,W)}if(!Q){throw new I.RangeError(N,"Couldn't find "+N+" node: "+this[N])}O=0;aa=this[N+"Offset"];if(N==="end"){aa--}R=c.getTextNodes(y(Q));for(P=0,L=R.length;P<L;P++){Z=R[P];if(O+Z.nodeValue.length>aa){V[N+"Container"]=Z;V[N+"Offset"]=this[N+"Offset"]-O;break}else{O+=Z.nodeValue.length}}if(V[N+"Offset"]==null){throw new I.RangeError(""+N+"offset","Couldn't find offset "+this[N+"Offset"]+" in element "+this[N])}}T=document.compareDocumentPosition==null?function(ac,ab){return ac.contains(ab)}:function(ac,ab){return ac.compareDocumentPosition(ab)&16};y(V.startContainer).parents().each(function(){if(T(this,V.endContainer)){V.commonAncestorContainer=this;return false}});return new I.BrowserRange(V).normalize(X)};g.prototype.serialize=function(L,M){return this.normalize(L).serialize(L,M)};g.prototype.toObject=function(){return{start:this.start,startOffset:this.startOffset,end:this.end,endOffset:this.endOffset}};return g})();C=this.Annotator;d=(function(g){j(L,g);L.prototype.events={".annotator-adder button click":"onAdderClick",".annotator-adder button mousedown":"onAdderMousedown",".annotator-hl mouseover":"onHighlightMouseover",".annotator-hl mouseout":"startViewerHideTimer"};L.prototype.html={adder:'<div class="annotator-adder"><button>'+B("Annotate")+"</button></div>",wrapper:'<div class="annotator-wrapper"></div>'};L.prototype.options={readOnly:false};L.prototype.plugins={};L.prototype.editor=null;L.prototype.viewer=null;L.prototype.selectedRanges=null;L.prototype.mouseIsDown=false;L.prototype.ignoreMouseup=false;L.prototype.viewerHideTimer=null;function L(N,M){this.onDeleteAnnotation=f(this.onDeleteAnnotation,this);this.onEditAnnotation=f(this.onEditAnnotation,this);this.onAdderClick=f(this.onAdderClick,this);this.onAdderMousedown=f(this.onAdderMousedown,this);this.onHighlightMouseover=f(this.onHighlightMouseover,this);this.checkForEndSelection=f(this.checkForEndSelection,this);this.checkForStartSelection=f(this.checkForStartSelection,this);this.clearViewerHideTimer=f(this.clearViewerHideTimer,this);this.startViewerHideTimer=f(this.startViewerHideTimer,this);this.showViewer=f(this.showViewer,this);this.onEditorSubmit=f(this.onEditorSubmit,this);this.onEditorHide=f(this.onEditorHide,this);this.showEditor=f(this.showEditor,this);L.__super__.constructor.apply(this,arguments);this.plugins={};if(!L.supported()){return this}if(!this.options.readOnly){this._setupDocumentEvents()}this._setupWrapper()._setupViewer()._setupEditor();this._setupDynamicStyle();this.adder=y(this.html.adder).appendTo(this.wrapper).hide();L._instances.push(this)}L.prototype._setupWrapper=function(){this.wrapper=y(this.html.wrapper);this.element.find("script").remove();this.element.wrapInner(this.wrapper);this.wrapper=this.element.find(".annotator-wrapper");return this};L.prototype._setupViewer=function(){var M=this;this.viewer=new L.Viewer({readOnly:this.options.readOnly});this.viewer.hide().on("edit",this.onEditAnnotation).on("delete",this.onDeleteAnnotation).addField({load:function(O,N){if(N.text){y(O).html(c.escape(N.text))}else{y(O).html("<i>"+(B("No Comment"))+"</i>")}return M.publish("annotationViewerTextField",[O,N])}}).element.appendTo(this.wrapper).bind({mouseover:this.clearViewerHideTimer,mouseout:this.startViewerHideTimer});return this};L.prototype._setupEditor=function(){this.editor=new L.Editor();this.editor.hide().on("hide",this.onEditorHide).on("save",this.onEditorSubmit).addField({type:"textarea",label:B("Comments")+"\u2026",load:function(N,M){return y(N).find("textarea").val(M.text||"")},submit:function(N,M){return M.text=y(N).find("textarea").val()}});this.editor.element.appendTo(this.wrapper);return this};L.prototype._setupDocumentEvents=function(){y(document).bind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});return this};L.prototype._setupDynamicStyle=function(){var N,P,O,M;O=y("#annotator-dynamic-style");if(!O.length){O=y('<style id="annotator-dynamic-style"></style>').appendTo(document.head)}P="*"+((function(){var T,R,Q,S;Q=["adder","outer","notice","filter"];S=[];for(T=0,R=Q.length;T<R;T++){M=Q[T];S.push(":not(.annotator-"+M+")")}return S})()).join("");N=c.maxZIndex(y(document.body).find(P));N=Math.max(N,1000);O.text([".annotator-adder, .annotator-outer, .annotator-notice {"," z-index: "+(N+20)+";","}",".annotator-filter {"," z-index: "+(N+10)+";","}"].join("\n"));return this};L.prototype.destroy=function(){var N,O,Q,P,M;L.__super__.destroy.apply(this,arguments);y(document).unbind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});y("#annotator-dynamic-style").remove();this.adder.remove();this.viewer.destroy();this.editor.destroy();this.wrapper.find(".annotator-hl").each(function(){y(this).contents().insertBefore(this);return y(this).remove()});this.wrapper.contents().insertBefore(this.wrapper);this.wrapper.remove();this.element.data("annotator",null);M=this.plugins;for(O in M){Q=M[O];if(typeof(P=this.plugins[O]).destroy==="function"){P.destroy()}}N=L._instances.indexOf(this);if(N!==-1){return L._instances.splice(N,1)}};L.prototype.getSelectedRanges=function(){var P,S,Q,M,O,T,U,R,N;U=c.getGlobal().getSelection();O=[];T=[];if(!U.isCollapsed){O=(function(){var X,V,W;W=[];for(S=X=0,V=U.rangeCount;0<=V?X<V:X>V;S=0<=V?++X:--X){M=U.getRangeAt(S);P=new I.BrowserRange(M);Q=P.normalize().limit(this.wrapper[0]);if(Q===null){T.push(M)}W.push(Q)}return W}).call(this);U.removeAllRanges()}for(R=0,N=T.length;R<N;R++){M=T[R];U.addRange(M)}return y.grep(O,function(V){if(V){U.addRange(V.toRange())}return V})};L.prototype.createAnnotation=function(){var M;M={};this.publish("beforeAnnotationCreated",[M]);return M};L.prototype.setupAnnotation=function(R){var V,U,T,N,W,Q,P,O,M,S;W=this.wrapper[0];R.ranges||(R.ranges=this.selectedRanges);T=[];S=R.ranges;for(Q=0,O=S.length;Q<O;Q++){N=S[Q];try{T.push(I.sniff(N).normalize(W))}catch(X){V=X;if(V instanceof I.RangeError){this.publish("rangeNormalizeFail",[R,N,V])}else{throw V}}}R.quote=[];R.ranges=[];R.highlights=[];for(P=0,M=T.length;P<M;P++){U=T[P];R.quote.push(y.trim(U.text()));R.ranges.push(U.serialize(this.wrapper[0],".annotator-hl"));y.merge(R.highlights,this.highlightRange(U))}R.quote=R.quote.join(" / ");y(R.highlights).data("annotation",R);y(R.highlights).attr("data-annotation-id",R.id);return R};L.prototype.updateAnnotation=function(M){this.publish("beforeAnnotationUpdated",[M]);y(M.highlights).attr("data-annotation-id",M.id);this.publish("annotationUpdated",[M]);return M};L.prototype.deleteAnnotation=function(O){var R,Q,P,N,M;if(O.highlights!=null){M=O.highlights;for(P=0,N=M.length;P<N;P++){Q=M[P];if(!(Q.parentNode!=null)){continue}R=Q.childNodes[0];y(Q).replaceWith(Q.childNodes)}}this.publish("annotationDeleted",[O]);return O};L.prototype.loadAnnotations=function(N){var P,M,O=this;if(N==null){N=[]}M=function(T){var U,R,S,Q;if(T==null){T=[]}R=T.splice(0,10);for(S=0,Q=R.length;S<Q;S++){U=R[S];O.setupAnnotation(U)}if(T.length>0){return setTimeout((function(){return M(T)}),10)}else{return O.publish("annotationsLoaded",[P])}};P=N.slice();M(N);return this};L.prototype.dumpAnnotations=function(){if(this.plugins.Store){return this.plugins.Store.dumpAnnotations()}else{console.warn(B("Can't dump annotations without Store plugin."));return false}};L.prototype.highlightRange=function(P,U){var N,O,T,Q,M,S,R;if(U==null){U="annotator-hl"}T=/^\s*$/;N=y("<span class='"+U+"'></span>");S=P.textNodes();R=[];for(Q=0,M=S.length;Q<M;Q++){O=S[Q];if(!T.test(O.nodeValue)){R.push(y(O).wrapAll(N).parent().show()[0])}}return R};L.prototype.highlightRanges=function(Q,N){var R,P,O,M;if(N==null){N="annotator-hl"}R=[];for(O=0,M=Q.length;O<M;O++){P=Q[O];y.merge(R,this.highlightRange(P,N))}return R};L.prototype.addPlugin=function(O,N){var M,P;if(this.plugins[O]){console.error(B("You cannot have more than one instance of any plugin."))}else{M=L.Plugin[O];if(typeof M==="function"){this.plugins[O]=new M(this.element[0],N);this.plugins[O].annotator=this;if(typeof(P=this.plugins[O]).pluginInit==="function"){P.pluginInit()}}else{console.error(B("Could not load ")+O+B(" plugin. Have you included the appropriate <script> tag?"))}}return this};L.prototype.showEditor=function(M,N){this.editor.element.css(N);this.editor.load(M);this.publish("annotationEditorShown",[this.editor,M]);return this};L.prototype.onEditorHide=function(){this.publish("annotationEditorHidden",[this.editor]);return this.ignoreMouseup=false};L.prototype.onEditorSubmit=function(M){return this.publish("annotationEditorSubmit",[this.editor,M])};L.prototype.showViewer=function(N,M){this.viewer.element.css(M);this.viewer.load(N);return this.publish("annotationViewerShown",[this.viewer,N])};L.prototype.startViewerHideTimer=function(){if(!this.viewerHideTimer){return this.viewerHideTimer=setTimeout(this.viewer.hide,250)}};L.prototype.clearViewerHideTimer=function(){clearTimeout(this.viewerHideTimer);return this.viewerHideTimer=false};L.prototype.checkForStartSelection=function(M){if(!(M&&this.isAnnotator(M.target))){this.startViewerHideTimer()}return this.mouseIsDown=true};L.prototype.checkForEndSelection=function(R){var O,P,Q,N,M;this.mouseIsDown=false;if(this.ignoreMouseup){return}this.selectedRanges=this.getSelectedRanges();M=this.selectedRanges;for(Q=0,N=M.length;Q<N;Q++){P=M[Q];O=P.commonAncestor;if(this.isAnnotator(O)){return}}if(R&&this.selectedRanges.length){return this.adder.css(c.mousePosition(R,this.wrapper[0])).show()}else{return this.adder.hide()}};L.prototype.isAnnotator=function(M){return !!y(M).parents().addBack().filter("[class^=annotator-]").not("[class=annotator-hl]").not(this.wrapper).length};L.prototype.onHighlightMouseover=function(M){var N;this.clearViewerHideTimer();if(this.mouseIsDown){return false}if(this.viewer.isShown()){this.viewer.hide()}N=y(M.target).parents(".annotator-hl").addBack().map(function(){return y(this).data("annotation")}).toArray();return this.showViewer(N,c.mousePosition(M,this.wrapper[0]))};L.prototype.onAdderMousedown=function(M){if(M!=null){M.preventDefault()}return this.ignoreMouseup=true};L.prototype.onAdderClick=function(R){var N,Q,O,M,P,S=this;if(R!=null){R.preventDefault()}M=this.adder.position();this.adder.hide();N=this.setupAnnotation(this.createAnnotation());y(N.highlights).addClass("annotator-hl-temporary");P=function(){O();y(N.highlights).removeClass("annotator-hl-temporary");return S.publish("annotationCreated",[N])};Q=function(){O();return S.deleteAnnotation(N)};O=function(){S.unsubscribe("annotationEditorHidden",Q);return S.unsubscribe("annotationEditorSubmit",P)};this.subscribe("annotationEditorHidden",Q);this.subscribe("annotationEditorSubmit",P);return this.showEditor(N,M)};L.prototype.onEditAnnotation=function(M){var N,O,Q,P=this;O=this.viewer.element.position();Q=function(){N();return P.updateAnnotation(M)};N=function(){P.unsubscribe("annotationEditorHidden",N);return P.unsubscribe("annotationEditorSubmit",Q)};this.subscribe("annotationEditorHidden",N);this.subscribe("annotationEditorSubmit",Q);this.viewer.hide();return this.showEditor(M,O)};L.prototype.onDeleteAnnotation=function(M){this.viewer.hide();return this.deleteAnnotation(M)};return L})(b);d.Plugin=(function(L){j(g,L);function g(N,M){g.__super__.constructor.apply(this,arguments)}g.prototype.pluginInit=function(){};return g})(b);G=c.getGlobal();if(((p=G.document)!=null?p.evaluate:void 0)==null){y.getScript("http://assets.annotateit.org/vendor/xpath.min.js")}if(G.getSelection==null){y.getScript("http://assets.annotateit.org/vendor/ierange.min.js")}if(G.JSON==null){y.getScript("http://assets.annotateit.org/vendor/json2.min.js")}if(G.Node==null){G.Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12}}d.$=y;d.Delegator=b;d.Range=I;d.Util=c;d._instances=[];d._t=B;d.supported=function(){return(function(){return !!this.getSelection})()};d.noConflict=function(){c.getGlobal().Annotator=C;return this};y.fn.annotator=function(L){var g;g=Array.prototype.slice.call(arguments,1);return this.each(function(){var M;M=y.data(this,"annotator");if(L==="destroy"){y.removeData(this,"annotator");return M!=null?M.destroy(g):void 0}else{if(M){return L&&M[L].apply(M,g)}else{M=new d(this,L);return y.data(this,"annotator",M)}}})};this.Annotator=d;d.Widget=(function(L){j(g,L);g.prototype.classes={hide:"annotator-hide",invert:{x:"annotator-invert-x",y:"annotator-invert-y"}};function g(N,M){g.__super__.constructor.apply(this,arguments);this.classes=y.extend({},d.Widget.prototype.classes,this.classes)}g.prototype.destroy=function(){this.removeEvents();return this.element.remove()};g.prototype.checkOrientation=function(){var P,Q,M,O,N;this.resetOrientation();N=y(d.Util.getGlobal());O=this.element.children(":first");Q=O.offset();M={top:N.scrollTop(),right:N.width()+N.scrollLeft()};P={top:Q.top,right:Q.left+O.width()};if((P.top-M.top)<0){this.invertY()}if((P.right-M.right)>0){this.invertX()}return this};g.prototype.resetOrientation=function(){this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y);return this};g.prototype.invertX=function(){this.element.addClass(this.classes.invert.x);return this};g.prototype.invertY=function(){this.element.addClass(this.classes.invert.y);return this};g.prototype.isInvertedY=function(){return this.element.hasClass(this.classes.invert.y)};g.prototype.isInvertedX=function(){return this.element.hasClass(this.classes.invert.x)};return g})(b);d.Editor=(function(L){j(g,L);g.prototype.events={"form submit":"submit",".annotator-save click":"submit",".annotator-cancel click":"hide",".annotator-cancel mouseover":"onCancelButtonMouseover","textarea keydown":"processKeypress"};g.prototype.classes={hide:"annotator-hide",focus:"annotator-focus"};g.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">'+B("Cancel")+'</a>\n<a href="#save" class="annotator-save annotator-focus">'+B("Save")+"</a>\n </div>\n </form>\n</div>";g.prototype.options={};function g(M){this.onCancelButtonMouseover=f(this.onCancelButtonMouseover,this);this.processKeypress=f(this.processKeypress,this);this.submit=f(this.submit,this);this.load=f(this.load,this);this.hide=f(this.hide,this);this.show=f(this.show,this);g.__super__.constructor.call(this,y(this.html)[0],M);this.fields=[];this.annotation={}}g.prototype.show=function(M){d.Util.preventEventDefault(M);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();return this.publish("show")};g.prototype.hide=function(M){d.Util.preventEventDefault(M);this.element.addClass(this.classes.hide);return this.publish("hide")};g.prototype.load=function(N){var P,O,M,Q;this.annotation=N;this.publish("load",[this.annotation]);Q=this.fields;for(O=0,M=Q.length;O<M;O++){P=Q[O];P.load(P.element,this.annotation)}return this.show()};g.prototype.submit=function(O){var P,N,M,Q;d.Util.preventEventDefault(O);Q=this.fields;for(N=0,M=Q.length;N<M;N++){P=Q[N];P.submit(P.element,this.annotation)}this.publish("save",[this.annotation]);return this.hide()};g.prototype.addField=function(N){var O,P,M;P=y.extend({id:"annotator-field-"+d.Util.uuid(),type:"input",label:"",load:function(){},submit:function(){}},N);M=null;O=y('<li class="annotator-item" />');P.element=O[0];switch(P.type){case"textarea":M=y("<textarea />");break;case"input":case"checkbox":M=y("<input />");break;case"select":M=y("<select />")}O.append(M);M.attr({id:P.id,placeholder:P.label});if(P.type==="checkbox"){M[0].type="checkbox";O.addClass("annotator-checkbox");O.append(y("<label />",{"for":P.id,html:P.label}))}else{if(P.type==="select"){O.addClass("annotator-select");O.append(y("<label />",{"for":P.id,html:P.label}))}}this.element.find("ul:first").append(O);this.fields.push(P);return P.element};g.prototype.checkOrientation=function(){var M,N;g.__super__.checkOrientation.apply(this,arguments);N=this.element.find("ul");M=this.element.find(".annotator-controls");if(this.element.hasClass(this.classes.invert.y)){M.insertBefore(N)}else{if(M.is(":first-child")){M.insertAfter(N)}}return this};g.prototype.processKeypress=function(M){if(M.keyCode===27){return this.hide()}else{if(M.keyCode===13&&!M.shiftKey){return this.submit()}}};g.prototype.onCancelButtonMouseover=function(){return this.element.find("."+this.classes.focus).removeClass(this.classes.focus)};g.prototype.setupDraggables=function(){var P,X,O,T,M,R,V,Q,N,U,W,S=this;this.element.find(".annotator-resize").remove();if(this.element.hasClass(this.classes.invert.y)){O=this.element.find(".annotator-item:last")}else{O=this.element.find(".annotator-item:first")}if(O){y('<span class="annotator-resize"></span>').appendTo(O)}M=null;P=this.classes;T=this.element;U=null;N=T.find(".annotator-resize");X=T.find(".annotator-controls");W=false;R=function(Y){if(Y.target===this){M={element:this,top:Y.pageY,left:Y.pageX};U=T.find("textarea:first");y(window).bind({"mouseup.annotator-editor-resize":Q,"mousemove.annotator-editor-resize":V});return Y.preventDefault()}};Q=function(){M=null;return y(window).unbind(".annotator-editor-resize")};V=function(ac){var ad,aa,Z,Y,ab;if(M&&W===false){ad={top:ac.pageY-M.top,left:ac.pageX-M.left};if(M.element===N[0]){Y=U.outerHeight();ab=U.outerWidth();aa=T.hasClass(P.invert.x)?-1:1;Z=T.hasClass(P.invert.y)?1:-1;U.height(Y+(ad.top*Z));U.width(ab+(ad.left*aa));if(U.outerHeight()!==Y){M.top=ac.pageY}if(U.outerWidth()!==ab){M.left=ac.pageX}}else{if(M.element===X[0]){T.css({top:parseInt(T.css("top"),10)+ad.top,left:parseInt(T.css("left"),10)+ad.left});M.top=ac.pageY;M.left=ac.pageX}}W=true;return setTimeout(function(){return W=false},1000/60)}};N.bind("mousedown",R);return X.bind("mousedown",R)};return g})(d.Widget);d.Viewer=(function(g){j(L,g);L.prototype.events={".annotator-edit click":"onEditClick",".annotator-delete click":"onDeleteClick"};L.prototype.classes={hide:"annotator-hide",showControls:"annotator-visible"};L.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>'};L.prototype.options={readOnly:false};function L(M){this.onDeleteClick=f(this.onDeleteClick,this);this.onEditClick=f(this.onEditClick,this);this.load=f(this.load,this);this.hide=f(this.hide,this);this.show=f(this.show,this);L.__super__.constructor.call(this,y(this.html.element)[0],M);this.item=y(this.html.item)[0];this.fields=[];this.annotations=[]}L.prototype.show=function(N){var M,O=this;d.Util.preventEventDefault(N);M=this.element.find(".annotator-controls").addClass(this.classes.showControls);setTimeout((function(){return M.removeClass(O.classes.showControls)}),500);this.element.removeClass(this.classes.hide);return this.checkOrientation().publish("show")};L.prototype.isShown=function(){return !this.element.hasClass(this.classes.hide)};L.prototype.hide=function(M){d.Util.preventEventDefault(M);this.element.addClass(this.classes.hide);return this.publish("hide")};L.prototype.load=function(M){var U,Y,X,W,Z,S,P,ab,V,R,aa,O,N,ad,ac,T,Q;this.annotations=M||[];aa=this.element.find("ul:first").empty();T=this.annotations;for(O=0,ad=T.length;O<ad;O++){U=T[O];ab=y(this.item).clone().appendTo(aa).data("annotation",U);X=ab.find(".annotator-controls");V=X.find(".annotator-link");Z=X.find(".annotator-edit");W=X.find(".annotator-delete");R=new s(U.links||[]).get("alternate",{type:"text/html"});if(R.length===0||(R[0].href==null)){V.remove()}else{V.attr("href",R[0].href)}if(this.options.readOnly){Z.remove();W.remove()}else{Y={showEdit:function(){return Z.removeAttr("disabled")},hideEdit:function(){return Z.attr("disabled","disabled")},showDelete:function(){return W.removeAttr("disabled")},hideDelete:function(){return W.attr("disabled","disabled")}}}Q=this.fields;for(N=0,ac=Q.length;N<ac;N++){P=Q[N];S=y(P.element).clone().appendTo(ab)[0];P.load(S,U,Y)}}this.publish("load",[this.annotations]);return this.show()};L.prototype.addField=function(M){var N;N=y.extend({load:function(){}},M);N.element=y("<div />")[0];this.fields.push(N);N.element;return this};L.prototype.onEditClick=function(M){return this.onButtonClick(M,"edit")};L.prototype.onDeleteClick=function(M){return this.onButtonClick(M,"delete")};L.prototype.onButtonClick=function(O,M){var N;N=y(O.target).parents(".annotator-annotation");return this.publish(M,[N.data("annotation")])};return L})(d.Widget);s=(function(){function g(L){this.data=L}g.prototype.get=function(V,S){var R,P,U,Q,T,N,L,M,O;if(S==null){S={}}S=y.extend({},S,{rel:V});U=(function(){var W;W=[];for(P in S){if(!K.call(S,P)){continue}T=S[P];W.push(P)}return W})();M=this.data;O=[];for(N=0,L=M.length;N<L;N++){R=M[N];Q=U.reduce((function(W,X){return W&&(R[X]===S[X])}),true);if(Q){O.push(R)}else{continue}}return O};return g})();d=d||{};d.Notification=(function(g){j(L,g);L.prototype.events={click:"hide"};L.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"}};function L(M){this.hide=f(this.hide,this);this.show=f(this.show,this);L.__super__.constructor.call(this,y(this.options.html).appendTo(document.body)[0],M)}L.prototype.show=function(N,M){if(M==null){M=d.Notification.INFO}this.currentStatus=M;y(this.element).addClass(this.options.classes.show).addClass(this.options.classes[this.currentStatus]).html(c.escape(N||""));setTimeout(this.hide,5000);return this};L.prototype.hide=function(){if(this.currentStatus==null){this.currentStatus=d.Notification.INFO}y(this.element).removeClass(this.options.classes.show).removeClass(this.options.classes[this.currentStatus]);return this};return L})(b);d.Notification.INFO="info";d.Notification.SUCCESS="success";d.Notification.ERROR="error";y(function(){var g;g=new d.Notification;d.showNotification=g.show;return d.hideNotification=g.hide});d.Plugin.Unsupported=(function(g){j(L,g);function L(){n=L.__super__.constructor.apply(this,arguments);return n}L.prototype.options={message:d._t("Sorry your current browser does not support the Annotator")};L.prototype.pluginInit=function(){var M=this;if(!d.supported()){return y(function(){d.showNotification(M.options.message);if((window.XMLHttpRequest===void 0)&&(ActiveXObject!==void 0)){return y("html").addClass("ie6")}})}};return L})(d.Plugin);e=function(L){var Q,g,P,M,N,O;M="([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})))?)?)?)?";Q=L.match(new RegExp(M));P=0;g=new Date(Q[1],0,1);if(Q[3]){g.setMonth(Q[3]-1)}if(Q[5]){g.setDate(Q[5])}if(Q[7]){g.setHours(Q[7])}if(Q[8]){g.setMinutes(Q[8])}if(Q[10]){g.setSeconds(Q[10])}if(Q[12]){g.setMilliseconds(Number("0."+Q[12])*1000)}if(Q[14]){P=(Number(Q[16])*60)+Number(Q[17]);P*=(O=Q[15]==="-")!=null?O:{1:-1}}P-=g.getTimezoneOffset();N=Number(g)+(P*60*1000);g.setTime(Number(N));return g};H=function(R){var X,N,W,O,V,U,T,S,Q,M,L,g,P;if(typeof atob!=="undefined"&&atob!==null){return atob(R)}else{N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";Q=0;X=0;O="";P=[];if(!R){return R}R+="";while(Q<R.length){V=N.indexOf(R.charAt(Q++));U=N.indexOf(R.charAt(Q++));T=N.indexOf(R.charAt(Q++));S=N.indexOf(R.charAt(Q++));W=V<<18|U<<12|T<<6|S;M=W>>16&255;L=W>>8&255;g=W&255;if(T===64){P[X++]=String.fromCharCode(M)}else{if(S===64){P[X++]=String.fromCharCode(M,L)}else{P[X++]=String.fromCharCode(M,L,g)}}}return P.join("")}};a=function(N){var L,g,M,O;g=N.length%4;if(g!==0){for(L=M=0,O=4-g;0<=O?M<O:M>O;L=0<=O?++M:--M){N+="="}}N=N.replace(/-/g,"+");N=N.replace(/_/g,"/");return H(N)};J=function(L){var g,M,O,N;N=L.split("."),g=N[0],M=N[1],O=N[2];return JSON.parse(a(M))};d.Plugin.Auth=(function(L){j(g,L);g.prototype.options={token:null,tokenUrl:"/auth/token",autoFetch:true,requestMethod:"GET",requestData:null,unauthorizedCallback:null};function g(N,M){g.__super__.constructor.apply(this,arguments);this.waitingForToken=[];if(this.options.token){this.setToken(this.options.token)}else{this.requestToken()}}g.prototype.requestToken=function(){var M=this;this.requestInProgress=true;return y.ajax({url:this.options.tokenUrl,dataType:"text",data:this.options.requestData,type:this.options.requestMethod,xhrFields:{withCredentials:true}}).done(function(O,N,P){return M.setToken(O)}).fail(function(Q,N,O){var R,P;if(Q.status===401){R=M.options.unauthorizedCallback;if((R!=null)&&R(M)){M.retryTimeout=setTimeout((function(){return M.requestToken()}),1000);return}}P=d._t("Couldn't get auth token:");console.error(""+P+" "+O,Q);return d.showNotification(""+P+" "+Q.responseText,d.Notification.ERROR)}).always(function(){return M.requestInProgress=false})};g.prototype.setToken=function(N){var M,O=this;this.token=N;this._unsafeToken=J(N);if(this.haveValidToken()){if(this.options.autoFetch){this.refreshTimeout=setTimeout((function(){return O.requestToken()}),(this.timeToExpiry()-2)*1000)}this.updateHeaders();M=[];while(this.waitingForToken.length>0){M.push(this.waitingForToken.pop()(this._unsafeToken))}return M}else{console.warn(d._t("Didn't get a valid token."));if(this.options.autoFetch){console.warn(d._t("Getting a new token in 10s."));return setTimeout((function(){return O.requestToken()}),10*1000)}}};g.prototype.haveValidToken=function(){var M;M=this._unsafeToken&&this._unsafeToken.issuedAt&&this._unsafeToken.ttl&&this._unsafeToken.consumerKey;if(M&&this.timeToExpiry()>0){return true}else{return false}};g.prototype.timeToExpiry=function(){var O,M,N,P;N=new Date().getTime()/1000;M=e(this._unsafeToken.issuedAt).getTime()/1000;O=M+this._unsafeToken.ttl;P=O-N;if(P>0){return P}else{return 0}};g.prototype.updateHeaders=function(){var M;M=this.element.data("annotator:headers");return this.element.data("annotator:headers",y.extend(M,{"x-annotator-auth-token":this.token}))};g.prototype.withToken=function(M){if(M==null){return}if(this.haveValidToken()){return M(this._unsafeToken)}else{this.waitingForToken.push(M);if(!this.requestInProgress){return this.requestToken()}}};return g})(d.Plugin);d.Plugin.Store=(function(g){j(L,g);L.prototype.events={annotationCreated:"annotationCreated",annotationDeleted:"annotationDeleted",annotationUpdated:"annotationUpdated"};L.prototype.options={annotationData:{},emulateHTTP:false,loadFromSearch:false,prefix:"/store",urls:{create:"/annotations",read:"/annotations/:id",update:"/annotations/:id",destroy:"/annotations/:id",search:"/search"}};function L(N,M){this._onError=f(this._onError,this);this._onLoadAnnotationsFromSearch=f(this._onLoadAnnotationsFromSearch,this);this._onLoadAnnotations=f(this._onLoadAnnotations,this);this._getAnnotations=f(this._getAnnotations,this);L.__super__.constructor.apply(this,arguments);this.annotations=[]}L.prototype.pluginInit=function(){if(!d.supported()){return}if(this.annotator.plugins.Auth){return this.annotator.plugins.Auth.withToken(this._getAnnotations)}else{return this._getAnnotations()}};L.prototype._getAnnotations=function(){if(this.options.loadFromSearch){return this.loadAnnotationsFromSearch(this.options.loadFromSearch)}else{return this.loadAnnotations()}};L.prototype.annotationCreated=function(M){var N=this;if(o.call(this.annotations,M)<0){this.registerAnnotation(M);return this._apiRequest("create",M,function(O){if(O.id==null){console.warn(d._t("Warning: No ID returned from server for annotation "),M)}return N.updateAnnotation(M,O)})}else{return this.updateAnnotation(M,{})}};L.prototype.annotationUpdated=function(M){var N=this;if(o.call(this.annotations,M)>=0){return this._apiRequest("update",M,(function(O){return N.updateAnnotation(M,O)}))}};L.prototype.annotationDeleted=function(M){var N=this;if(o.call(this.annotations,M)>=0){return this._apiRequest("destroy",M,(function(){N.publish("annotationDestroyed",[M]);return N.unregisterAnnotation(M)}))}};L.prototype.registerAnnotation=function(M){return this.annotations.push(M)};L.prototype.unregisterAnnotation=function(M){return this.annotations.splice(this.annotations.indexOf(M),1)};L.prototype.updateAnnotation=function(M,N){if(o.call(this.annotations,M)<0){console.error(d._t("Trying to update unregistered annotation!"))}else{y.extend(M,N)}this.publish("annotationStored",[N]);return y(M.highlights).data("annotation",M)};L.prototype.loadAnnotations=function(){return this._apiRequest("read",null,this._onLoadAnnotations)};L.prototype._onLoadAnnotations=function(S){var U,R,T,V,Q,P,N,M,O;this.publish("annotationRead",[this.annotations,S]);if(S==null){S=[]}T={};O=this.annotations;for(Q=0,N=O.length;Q<N;Q++){U=O[Q];T[U.id]=U}V=[];for(P=0,M=S.length;P<M;P++){U=S[P];if(T[U.id]){R=T[U.id];this.updateAnnotation(R,U)}else{V.push(U)}}this.annotations=this.annotations.concat(V);return this.annotator.loadAnnotations(V.slice())};L.prototype.loadAnnotationsFromSearch=function(M){return this._apiRequest("search",M,this._onLoadAnnotationsFromSearch)};L.prototype._onLoadAnnotationsFromSearch=function(M){if(M==null){M={}}this.publish("annotationSearchResult",[this.annotations,M]);return this._onLoadAnnotations(M.rows||[])};L.prototype.dumpAnnotations=function(){var P,O,M,Q,N;Q=this.annotations;N=[];for(O=0,M=Q.length;O<M;O++){P=Q[O];N.push(JSON.parse(this._dataFor(P)))}return N};L.prototype._apiRequest=function(P,Q,R){var S,N,O,M;S=Q&&Q.id;M=this._urlFor(P,S);N=this._apiRequestOptions(P,Q,R);O=y.ajax(M,N);O._id=S;O._action=P;return O};L.prototype._apiRequestOptions=function(O,P,Q){var N,R,M;R=this._methodFor(O);M={type:R,headers:this.element.data("annotator:headers"),dataType:"json",success:Q||function(){},error:this._onError};if(this.options.emulateHTTP&&(R==="PUT"||R==="DELETE")){M.headers=y.extend(M.headers,{"X-HTTP-Method-Override":R});M.type="POST"}if(O==="search"){M=y.extend(M,{data:P});return M}N=P&&this._dataFor(P);if(this.options.emulateJSON){M.data={json:N};if(this.options.emulateHTTP){M.data._method=R}return M}M=y.extend(M,{data:N,contentType:"application/json; charset=utf-8"});return M};L.prototype._urlFor=function(N,O){var M;M=this.options.prefix!=null?this.options.prefix:"";M+=this.options.urls[N];M=M.replace(/\/:id/,O!=null?"/"+O:"");M=M.replace(/:id/,O!=null?O:"");return M};L.prototype._methodFor=function(N){var M;M={create:"POST",read:"GET",update:"PUT",destroy:"DELETE",search:"GET"};return M[N]};L.prototype._dataFor=function(M){var N,O;O=M.highlights;delete M.highlights;y.extend(M,this.options.annotationData);N=JSON.stringify(M);if(O){M.highlights=O}return N};L.prototype._onError=function(O){var N,M;N=O._action;M=d._t("Sorry we could not ")+N+d._t(" this annotation");if(O._action==="search"){M=d._t("Sorry we could not search the store for annotations")}else{if(O._action==="read"&&!O._id){M=d._t("Sorry we could not ")+N+d._t(" the annotations from the store")}}switch(O.status){case 401:M=d._t("Sorry you are not allowed to ")+N+d._t(" this annotation");break;case 404:M=d._t("Sorry we could not connect to the annotations store");break;case 500:M=d._t("Sorry something went wrong with the annotation store")}d.showNotification(M,d.Notification.ERROR);return console.error(d._t("API request failed:")+(" '"+O.status+"'"))};return L})(d.Plugin);d.Plugin.Permissions=(function(g){j(L,g);L.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"};L.prototype.options={showViewPermissionsCheckbox:true,showEditPermissionsCheckbox:true,userId:function(M){return M},userString:function(M){return M},userAuthorize:function(R,N,O){var P,S,Q,M;if(N.permissions){S=N.permissions[R]||[];if(S.length===0){return true}for(Q=0,M=S.length;Q<M;Q++){P=S[Q];if(this.userId(O)===P){return true}}return false}else{if(N.user){if(O){return this.userId(O)===this.userId(N.user)}else{return false}}}return true},user:"",permissions:{read:[],update:[],"delete":[],admin:[]}};function L(N,M){this._setAuthFromToken=f(this._setAuthFromToken,this);this.updateViewer=f(this.updateViewer,this);this.updateAnnotationPermissions=f(this.updateAnnotationPermissions,this);this.updatePermissionsField=f(this.updatePermissionsField,this);this.addFieldsToAnnotation=f(this.addFieldsToAnnotation,this);L.__super__.constructor.apply(this,arguments);if(this.options.user){this.setUser(this.options.user);delete this.options.user}}L.prototype.pluginInit=function(){var M,N,O=this;if(!d.supported()){return}N=this;M=function(Q,P){return function(S,R){return N[Q].call(N,P,S,R)}};if(!this.user&&this.annotator.plugins.Auth){this.annotator.plugins.Auth.withToken(this._setAuthFromToken)}if(this.options.showViewPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:d._t("Allow anyone to <strong>view</strong> this annotation"),load:M("updatePermissionsField","read"),submit:M("updateAnnotationPermissions","read")})}if(this.options.showEditPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:d._t("Allow anyone to <strong>edit</strong> this annotation"),load:M("updatePermissionsField","update"),submit:M("updateAnnotationPermissions","update")})}this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){return this.annotator.plugins.Filter.addFilter({label:d._t("User"),property:"user",isFiltered:function(S,R){var Q,T,P,U;R=O.options.userString(R);if(!(S&&R)){return false}U=S.split(/\s*/);for(T=0,P=U.length;T<P;T++){Q=U[T];if(R.indexOf(Q)===-1){return false}}return true}})}};L.prototype.setUser=function(M){return this.user=M};L.prototype.addFieldsToAnnotation=function(M){if(M){M.permissions=y.extend(true,{},this.options.permissions);if(this.user){return M.user=this.user}}};L.prototype.authorize=function(O,M,N){if(N===void 0){N=this.user}if(this.options.userAuthorize){return this.options.userAuthorize.call(this.options,O,M,N)}else{return true}};L.prototype.updatePermissionsField=function(O,P,M){var N;P=y(P).show();N=P.find("input").removeAttr("disabled");if(!this.authorize("admin",M)){P.hide()}if(this.authorize(O,M||{},null)){return N.attr("checked","checked")}else{return N.removeAttr("checked")}};L.prototype.updateAnnotationPermissions=function(N,O,M){var P;if(!M.permissions){M.permissions=y.extend(true,{},this.options.permissions)}P=N+"-permissions";if(y(O).find("input").is(":checked")){return M.permissions[N]=[]}else{return M.permissions[N]=[this.options.userId(this.user)]}};L.prototype.updateViewer=function(P,M,O){var N,Q;P=y(P);Q=this.options.userString(M.user);if(M.user&&Q&&typeof Q==="string"){N=d.Util.escape(this.options.userString(M.user));P.html(N).addClass("annotator-user")}else{P.remove()}if(O){if(!this.authorize("update",M)){O.hideEdit()}if(!this.authorize("delete",M)){return O.hideDelete()}}};L.prototype._setAuthFromToken=function(M){return this.setUser(M.userId)};return L})(d.Plugin);d.Plugin.GroupPermissions=(function(g){j(L,g);L.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"};L.prototype.options={showViewPermissionsCheckbox:true,showEditPermissionsCheckbox:true,showAdminGroupSelection:true,userId:function(M){if((M!=null?M.id:void 0)!=null){return M.id}else{return M}},userString:function(M){if((M!=null?M.name:void 0)!=null){return M.name}else{return M}},userAuthorize:function(R,N,O){var P,S,Q,M;if(N.permissions){S=N.permissions[R]||[];if(S.length===0){return true}for(Q=0,M=S.length;Q<M;Q++){P=S[Q];if(this.userId(O)===P){return true}else{if(((O!=null?O.groups:void 0)!=null)&&o.call(O.groups,P)>=0){return true}}}return false}else{if(N.user){if(O){return this.userId(O)===this.userId(N.user)}else{return false}}}return true},user:"",groups:[],permissions:{read:[],update:[],"delete":[],admin:[]}};function L(N,M){this._setAuthFromToken=f(this._setAuthFromToken,this);this._cleanPermissions=f(this._cleanPermissions,this);this.updateViewer=f(this.updateViewer,this);this.updateAnnotationPermissions=f(this.updateAnnotationPermissions,this);this.updateGroupPermissionsField=f(this.updateGroupPermissionsField,this);this.updatePermissionsField=f(this.updatePermissionsField,this);this.addFieldsToAnnotation=f(this.addFieldsToAnnotation,this);L.__super__.constructor.apply(this,arguments);if(this.options.user){this.setUser(this.options.user);delete this.options.user}if(this.options.groups&&this.options.groups.length>0){this.setGroups(this.options.groups);delete this.options.groups}}L.prototype.pluginInit=function(){var M,N,O=this;if(!d.supported()){return}N=this;M=function(Q,P){return function(S,R){return N[Q].call(N,P,S,R)}};if(!this.user&&this.annotator.plugins.Auth){this.annotator.plugins.Auth.withToken(this._setAuthFromToken)}if(this.options.showViewPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:d._t("Allow anyone to <strong>view</strong> this annotation"),load:M("updatePermissionsField","read"),submit:M("updateAnnotationPermissions","read")})}if(this.options.showEditPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:d._t("Allow anyone to <strong>edit</strong> this annotation"),load:M("updatePermissionsField","update"),submit:M("updateAnnotationPermissions","update")})}if(this.options.showAdminGroupSelection===true){this.annotator.editor.addField({type:"select",label:d._t(" group <strong>manages</strong> this annotation"),load:M("updateGroupPermissionsField","admin"),submit:M("updateAnnotationPermissions","admin")})}this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){return this.annotator.plugins.Filter.addFilter({label:d._t("User"),property:"user",isFiltered:function(S,R){var Q,T,P,U;R=O.options.userString(R);if(!(S&&R)){return false}U=S.split(/\s*/);for(T=0,P=U.length;T<P;T++){Q=U[T];if(R.indexOf(Q)===-1){return false}}return true}})}};L.prototype.setUser=function(M){if(typeof M==="string"){return this.user={id:M,name:M}}else{return this.user=M}};L.prototype.setGroups=function(M){this.groups=M;return this.user.groups=(function(){var P,N,O;O=[];for(P=0,N=M.length;P<N;P++){G=M[P];O.push("group:"+G)}return O})()};L.prototype.addFieldsToAnnotation=function(M){if(M){M.permissions=y.extend(true,{},this.options.permissions);if(this.user){return M.user=this.user}}};L.prototype.authorize=function(O,M,N){if(N===void 0){N=this.user}if(this.options.userAuthorize){return this.options.userAuthorize.call(this.options,O,M,N)}else{return true}};L.prototype.updatePermissionsField=function(O,P,M){var N;P=y(P).show();N=P.find("input").removeAttr("disabled");if(!this.authorize("admin",M)){P.hide()}return N.prop("checked",this.authorize(O,M,null))};L.prototype.updateGroupPermissionsField=function(T,V,R){var W,U,Q,M,P,O,N,S;V=y(V);if(!(this.authorize("admin",R)&&((P=this.groups)!=null?P.length:void 0)>0)){V.hide();return}V.show();W=V.find("select").removeAttr("disabled");U=((O=R.permissions)!=null?O[T][0]:void 0)||this.options.userId(this.user);W.empty();W.append(y("<option>",{selected:U===this.options.userId(this.user),html:" "}));N=this.groups;S=[];for(Q=0,M=N.length;Q<M;Q++){G=N[Q];S.push(W.append(y("<option>",{selected:U==="group:"+G,html:G})))}return S};L.prototype.updateAnnotationPermissions=function(N,P,M){var Q,O;if(!M.permissions){M.permissions=y.extend(true,{},this.options.permissions)}Q=N+"-permissions";if(O=y(P).find("select").val()){M.permissions[N]=["group:"+O]}else{if(y(P).find("input").is(":checked")){M.permissions[N]=[]}else{M.permissions[N]=[this.options.userId(this.user)]}}if(N==="admin"){return this._cleanPermissions(M)}};L.prototype.updateViewer=function(Q,M,O){var N,S,R,P;Q=y(Q);S=this.options.userString(M.user);if(M.user&&S&&typeof S==="string"){N=d.Util.escape(this.options.userString(M.user));if(((R=M.permissions)!=null?(P=R.admin)!=null?P[0].indexOf("group:"):void 0:void 0)===0){N+=" (Group "+M.permissions.admin[0].substr(6)+")"}Q.html(N).addClass("annotator-user")}else{Q.remove()}if(O){if(!this.authorize("update",M)){O.hideEdit()}if(!this.authorize("delete",M)){return O.hideDelete()}}};L.prototype._cleanPermissions=function(N){var R,Q,P,M,S,O;R=N.permissions.admin;S=["delete","update","read"];O=[];for(P=0,M=S.length;P<M;P++){Q=S[P];if(N.permissions[Q].length===0){O.push(R=[])}else{O.push(N.permissions[Q]=R)}}return O};L.prototype._setAuthFromToken=function(M){this.setUser(M.userId);if(M.memberOf!=null){return this.setGroups(M.memberOf)}};return L})(d.Plugin);d.Plugin.Filter=(function(L){j(g,L);g.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"};g.prototype.classes={active:"annotator-filter-active",hl:{hide:"annotator-hl-filtered",active:"annotator-hl-active"}};g.prototype.html={element:'<div class="annotator-filter">\n <strong>'+d._t("Navigate:")+'</strong>\n<span class="annotator-filter-navigation">\n <button class="annotator-filter-previous">'+d._t("Previous")+'</button>\n<button class="annotator-filter-next">'+d._t("Next")+"</button>\n</span>\n<strong>"+d._t("Filter by:")+"</strong>\n</div>",filter:'<span class="annotator-filter-property">\n <label></label>\n <input/>\n <button class="annotator-filter-clear">'+d._t("Clear")+"</button>\n</span>"};g.prototype.options={appendTo:"body",filters:[],addAnnotationFilter:true,isFiltered:function(O,Q){var N,P,M,R;if(!(O&&Q)){return false}R=O.split(/\s+/);for(P=0,M=R.length;P<M;P++){N=R[P];if(Q.indexOf(N)===-1){return false}}return true}};function g(N,M){this._onPreviousClick=f(this._onPreviousClick,this);this._onNextClick=f(this._onNextClick,this);this._onFilterKeyup=f(this._onFilterKeyup,this);this._onFilterBlur=f(this._onFilterBlur,this);this._onFilterFocus=f(this._onFilterFocus,this);this.updateHighlights=f(this.updateHighlights,this);var O;N=y(this.html.element).appendTo((M!=null?M.appendTo:void 0)||this.options.appendTo);g.__super__.constructor.call(this,N,M);(O=this.options).filters||(O.filters=[]);this.filter=y(this.html.filter);this.filters=[];this.current=0}g.prototype.pluginInit=function(){var O,N,M,P;P=this.options.filters;for(N=0,M=P.length;N<M;N++){O=P[N];this.addFilter(O)}this.updateHighlights();this._setupListeners()._insertSpacer();if(this.options.addAnnotationFilter===true){return this.addFilter({label:d._t("Annotation"),property:"text"})}};g.prototype.destroy=function(){var N,M;g.__super__.destroy.apply(this,arguments);M=y("html");N=parseInt(M.css("padding-top"),10)||0;M.css("padding-top",N-this.element.outerHeight());return this.element.remove()};g.prototype._insertSpacer=function(){var N,M;M=y("html");N=parseInt(M.css("padding-top"),10)||0;M.css("padding-top",N+this.element.outerHeight());return this};g.prototype._setupListeners=function(){var P,N,O,M;N=["annotationsLoaded","annotationCreated","annotationUpdated","annotationDeleted"];for(O=0,M=N.length;O<M;O++){P=N[O];this.annotator.subscribe(P,this.updateHighlights)}return this};g.prototype.addFilter=function(M){var O,N;N=y.extend({label:"",property:"",isFiltered:this.options.isFiltered},M);if(!((function(){var R,P,S,Q;S=this.filters;Q=[];for(R=0,P=S.length;R<P;R++){O=S[R];if(O.property===N.property){Q.push(O)}}return Q}).call(this)).length){N.id="annotator-filter-"+N.property;N.annotations=[];N.element=this.filter.clone().appendTo(this.element);N.element.find("label").html(N.label).attr("for",N.id);N.element.find("input").attr({id:N.id,placeholder:d._t("Filter by ")+N.label+"\u2026"});N.element.find("button").hide();N.element.data("filter",N);this.filters.push(N)}return this};g.prototype.updateFilter=function(Q){var N,S,O,R,P,M,T;Q.annotations=[];this.updateHighlights();this.resetHighlights();O=y.trim(Q.element.find("input").val());if(O){S=this.highlights.map(function(){return y(this).data("annotation")});T=y.makeArray(S);for(P=0,M=T.length;P<M;P++){N=T[P];R=N[Q.property];if(Q.isFiltered(O,R)){Q.annotations.push(N)}}return this.filterHighlights()}};g.prototype.updateHighlights=function(){this.highlights=this.annotator.element.find(".annotator-hl:visible");return this.filtered=this.highlights.not(this.classes.hl.hide)};g.prototype.filterHighlights=function(){var N,Q,R,U,S,T,V,P,M,O;N=y.grep(this.filters,function(W){return !!W.annotations.length});U=((O=N[0])!=null?O.annotations:void 0)||[];if(N.length>1){R=[];y.each(N,function(){return y.merge(R,this.annotations)});V=[];U=[];y.each(R,function(){if(y.inArray(this,V)===-1){return V.push(this)}else{return U.push(this)}})}S=this.highlights;for(T=P=0,M=U.length;P<M;T=++P){Q=U[T];S=S.not(Q.highlights)}S.addClass(this.classes.hl.hide);this.filtered=this.highlights.not(this.classes.hl.hide);return this};g.prototype.resetHighlights=function(){this.highlights.removeClass(this.classes.hl.hide);this.filtered=this.highlights;return this};g.prototype._onFilterFocus=function(N){var M;M=y(N.target);M.parent().addClass(this.classes.active);return M.next("button").show()};g.prototype._onFilterBlur=function(N){var M;if(!N.target.value){M=y(N.target);M.parent().removeClass(this.classes.active);return M.next("button").hide()}};g.prototype._onFilterKeyup=function(N){var M;M=y(N.target).parent().data("filter");if(M){return this.updateFilter(M)}};g.prototype._findNextHighlight=function(R){var N,O,T,S,Q,P,M,U;if(!this.highlights.length){return this}P=R?0:-1;U=R?-1:0;M=R?"lt":"gt";N=this.highlights.not("."+this.classes.hl.hide);T=N.filter("."+this.classes.hl.active);if(!T.length){T=N.eq(P)}O=T.data("annotation");S=N.index(T[0]);Q=N.filter(":"+M+"("+S+")").not(O.highlights).eq(U);if(!Q.length){Q=N.eq(U)}return this._scrollToHighlight(Q.data("annotation").highlights)};g.prototype._onNextClick=function(M){return this._findNextHighlight()};g.prototype._onPreviousClick=function(M){return this._findNextHighlight(true)};g.prototype._scrollToHighlight=function(M){M=y(M);this.highlights.removeClass(this.classes.hl.active);M.addClass(this.classes.hl.active);return y("html, body").animate({scrollTop:M.offset().top-(this.element.height()+20)},150)};g.prototype._onClearClick=function(M){return y(M.target).prev("input").val("").keyup().blur()};return g})(d.Plugin);d.Plugin.Markdown=(function(L){j(g,L);g.prototype.events={annotationViewerTextField:"updateTextField"};function g(N,M){this.updateTextField=f(this.updateTextField,this);if((typeof Showdown!=="undefined"&&Showdown!==null?Showdown.converter:void 0)!=null){g.__super__.constructor.apply(this,arguments);this.converter=new Showdown.converter()}else{console.error(d._t("To use the Markdown plugin, you must include Showdown into the page first."))}}g.prototype.updateTextField=function(N,M){var O;O=d.Util.escape(M.text||"");return y(N).html(this.convert(O))};g.prototype.convert=function(M){return this.converter.makeHtml(M)};return g})(d.Plugin);d.Plugin.Tags=(function(L){j(g,L);function g(){this.setAnnotationTags=f(this.setAnnotationTags,this);this.updateField=f(this.updateField,this);m=g.__super__.constructor.apply(this,arguments);return m}g.prototype.options={parseTags:function(N){var M;N=y.trim(N);M=[];if(N){M=N.split(/\s+/)}return M},stringifyTags:function(M){return M.join(" ")}};g.prototype.field=null;g.prototype.input=null;g.prototype.pluginInit=function(){if(!d.supported()){return}this.field=this.annotator.editor.addField({label:d._t("Add some tags here")+"\u2026",load:this.updateField,submit:this.setAnnotationTags});this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){this.annotator.plugins.Filter.addFilter({label:d._t("Tag"),property:"tags",isFiltered:d.Plugin.Tags.filterCallback})}return this.input=y(this.field).find(":input")};g.prototype.parseTags=function(M){return this.options.parseTags(M)};g.prototype.stringifyTags=function(M){return this.options.stringifyTags(M)};g.prototype.updateField=function(O,M){var N;N="";if(M.tags){N=this.stringifyTags(M.tags)}return this.input.val(N)};g.prototype.setAnnotationTags=function(N,M){return M.tags=this.parseTags(this.input.val())};g.prototype.updateViewer=function(N,M){N=y(N);if(M.tags&&y.isArray(M.tags)&&M.tags.length){return N.addClass("annotator-tags").html(function(){var O;return O=y.map(M.tags,function(P){return'<span class="annotator-tag">'+d.Util.escape(P)+"</span>"}).join(" ")})}else{return N.remove()}};return g})(d.Plugin);d.Plugin.Tags.filterCallback=function(R,S){var Q,P,O,T,N,M,L,g;if(S==null){S=[]}O=0;P=[];if(R){P=R.split(/\s+/g);for(N=0,L=P.length;N<L;N++){Q=P[N];if(S.length){for(M=0,g=S.length;M<g;M++){T=S[M];if(T.indexOf(Q)!==-1){O+=1}}}}}return O===P.length};d.Plugin.DigilibIntegrator=(function(g){j(L,g);function L(){l=L.__super__.constructor.apply(this,arguments);return l}L.prototype.events={annotationDeleted:"annotationDeleted"};L.prototype.options={hooks:null};L.prototype.pluginInit=function(){this.annotator.digilib=this.options.hooks;this.annotator.setupRangeAnnotation=this.annotator.setupAnnotation;this.annotator.setupAnnotation=this._setupAnnotation;return this};L.prototype._setupAnnotation=function(M){if(this.selectedShapes||(M.shapes!=null)||(this.selectedAreas!=null)||(M.areas!=null)){M.shapes||(M.shapes=this.selectedShapes);M.highlights=[];M.ranges=[];this.digilib.setupAnnotation(M);return M}else{return this.setupRangeAnnotation.apply(this,arguments)}};L.prototype.annotationDeleted=function(M){return this.options.hooks.annotationDeleted(M)};return L})(d.Plugin)}).call(this); \ No newline at end of file + +/* +** Annotator v1.2.10-dev-976a5f0 +** https://github.com/okfn/annotator/ +** +** Copyright 2017, the Annotator project contributors. +** Dual licensed under the MIT and GPLv3 licenses. +** https://github.com/okfn/annotator/blob/master/LICENSE +** +** Built at: 2017-02-13 17:46:12Z + */ + + +// + +!function(){var $,Annotator,Delegator,LinkParser,Range,Util,base64Decode,base64UrlDecode,createDateFromISO8601,findChild,fn,functions,g,getNodeName,getNodePosition,gettext,parseToken,simpleXPathJQuery,simpleXPathPure,_Annotator,_gettext,_i,_j,_len,_len1,_ref,_ref1,_ref2,_ref3,_ref4,_t,__slice=[].slice,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child},__bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;i<l;i++){if(i in this&&this[i]===item)return i}return-1};simpleXPathJQuery=function(relativeRoot){var jq;jq=this.map(function(){var elem,idx,path,tagName;path="";elem=this;while((elem!=null?elem.nodeType:void 0)===Node.ELEMENT_NODE&&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}return path});return jq.get()};simpleXPathPure=function(relativeRoot){var getPathSegment,getPathTo,jq,rootNode;getPathSegment=function(node){var name,pos;name=getNodeName(node);pos=getNodePosition(node);return""+name+"["+pos+"]"};rootNode=relativeRoot;getPathTo=function(node){var xpath;xpath="";while(node!==rootNode){if(node==null){throw new Error("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(/\/$/,"");return xpath};jq=this.map(function(){var path;path=getPathTo(this);return path});return jq.get()};findChild=function(node,type,index){var child,children,found,name,_i,_len;if(!node.hasChildNodes()){throw new Error("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){return child}}}throw new Error("XPath error: wanted child not found.")};getNodeName=function(node){var nodeName;nodeName=node.nodeName.toLowerCase();switch(nodeName){case"#text":return"text()";case"#comment":return"comment()";case"#cdata-section":return"cdata-section()";default:return nodeName}};getNodePosition=function(node){var pos,tmp;pos=0;tmp=node;while(tmp){if(tmp.nodeName===node.nodeName){pos++}tmp=tmp.previousSibling}return pos};gettext=null;if(typeof Gettext!=="undefined"&&Gettext!==null){_gettext=new Gettext({domain:"annotator"});gettext=function(msgid){return _gettext.gettext(msgid)}}else{gettext=function(msgid){return msgid}}_t=function(msgid){return gettext(msgid)};if(!(typeof jQuery!=="undefined"&&jQuery!==null?(_ref=jQuery.fn)!=null?_ref.jquery:void 0:void 0)){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;Util={};Util.flatten=function(array){var flatten;flatten=function(ary){var el,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)}return flat};return flatten(array)};Util.contains=function(parent,child){var node;node=child;while(node!=null){if(node===parent){return true}node=node.parentNode}return false};Util.getTextNodes=function(jq){var getTextNodes;getTextNodes=function(node){var nodes;if(node&&node.nodeType!==Node.TEXT_NODE){nodes=[];if(node.nodeType!==Node.COMMENT_NODE){node=node.lastChild;while(node){nodes.push(getTextNodes(node));node=node.previousSibling}}return nodes.reverse()}else{return node}};return jq.map(function(){return Util.flatten(getTextNodes(this))})};Util.getLastTextNodeUpTo=function(n){var result;switch(n.nodeType){case Node.TEXT_NODE:return n;case Node.ELEMENT_NODE:if(n.lastChild!=null){result=Util.getLastTextNodeUpTo(n.lastChild);if(result!=null){return result}}break}n=n.previousSibling;if(n!=null){return Util.getLastTextNodeUpTo(n)}else{return null}};Util.getFirstTextNodeNotBefore=function(n){var result;switch(n.nodeType){case Node.TEXT_NODE:return n;case Node.ELEMENT_NODE:if(n.firstChild!=null){result=Util.getFirstTextNodeNotBefore(n.firstChild);if(result!=null){return result}}break}n=n.nextSibling;if(n!=null){return Util.getFirstTextNodeNotBefore(n)}else{return null}};Util.readRangeViaSelection=function(range){var sel;sel=Util.getGlobal().getSelection();sel.removeAllRanges();sel.addRange(range.toRange());return sel.toString()};Util.xpathFromNode=function(el,relativeRoot){var exception,result;try{result=simpleXPathJQuery.call(el,relativeRoot)}catch(_error){exception=_error;console.log("jQuery-based XPath construction failed! Falling back to manual.");result=simpleXPathPure.call(el,relativeRoot)}return result};Util.nodeFromXPath=function(xp,root){var idx,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("]"):void 0)[0]):1;node=findChild(node,name.toLowerCase(),idx)}return node};Util.escape=function(html){return html.replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")};Util.uuid=function(){var counter;counter=0;return function(){return counter++}}();Util.getGlobal=function(){return function(){return this}()};Util.maxZIndex=function($elements){var all,el;all=function(){var _i,_len,_results;_results=[];for(_i=0,_len=$elements.length;_i<_len;_i++){el=$elements[_i];if($(el).css("position")==="static"){_results.push(-1)}else{_results.push(parseFloat($(el).css("z-index"))||-1)}}return _results}();return Math.max.apply(Math,all)};Util.mousePosition=function(e,offsetEl){var offset,_ref1;if((_ref1=$(offsetEl).css("position"))!=="absolute"&&_ref1!=="fixed"&&_ref1!=="relative"){offsetEl=$(offsetEl).offsetParent()[0]}offset=$(offsetEl).offset();return{top:e.pageY-offset.top,left:e.pageX-offset.left}};Util.preventEventDefault=function(event){return event!=null?typeof event.preventDefault==="function"?event.preventDefault():void 0:void 0};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(typeof console!=="undefined"&&console!==null){if(console.group==null){console.group=function(name){return console.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(){return console.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(){var args;args=1<=arguments.length?__slice.call(arguments,0):[];return alert("ERROR: "+args.join(", "))};this.console["warn"]=function(){var args;args=1<=arguments.length?__slice.call(arguments,0):[];return alert("WARNING: "+args.join(", "))}}Delegator=function(){Delegator.prototype.events={};Delegator.prototype.options={};Delegator.prototype.element=null;function Delegator(element,options){this.options=$.extend(true,{},this.options,options);this.element=$(element);this._closures={};this.on=this.subscribe;this.addEvents()}Delegator.prototype.destroy=function(){return this.removeEvents()};Delegator.prototype.addEvents=function(){var event,_k,_len2,_ref1,_results;_ref1=Delegator._parseEvents(this.events);_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){event=_ref1[_k];_results.push(this._addEvent(event.selector,event.event,event.functionName))}return _results};Delegator.prototype.removeEvents=function(){var event,_k,_len2,_ref1,_results;_ref1=Delegator._parseEvents(this.events);_results=[];for(_k=0,_len2=_ref1.length;_k<_len2;_k++){event=_ref1[_k];_results.push(this._removeEvent(event.selector,event.event,event.functionName))}return _results};Delegator.prototype._addEvent=function(selector,event,functionName){var closure,_this=this;closure=function(){return _this[functionName].apply(_this,arguments)};if(selector===""&&Delegator._isCustomEvent(event)){this.subscribe(event,closure)}else{this.element.delegate(selector,event,closure)}this._closures[""+selector+"/"+event+"/"+functionName]=closure;return this};Delegator.prototype._removeEvent=function(selector,event,functionName){var closure;closure=this._closures[""+selector+"/"+event+"/"+functionName];if(selector===""&&Delegator._isCustomEvent(event)){this.unsubscribe(event,closure)}else{this.element.undelegate(selector,event,closure)}delete this._closures[""+selector+"/"+event+"/"+functionName];return this};Delegator.prototype.publish=function(){this.element.triggerHandler.apply(this.element,arguments);return this};Delegator.prototype.subscribe=function(event,callback){var closure;closure=function(){return callback.apply(this,[].slice.call(arguments,1))};closure.guid=callback.guid=$.guid+=1;this.element.bind(event,closure);return this};Delegator.prototype.unsubscribe=function(){this.element.unbind.apply(this.element,arguments);return this};return Delegator}();Delegator._parseEvents=function(eventsObj){var event,events,functionName,sel,selector,_k,_ref1;events=[];for(sel in eventsObj){functionName=eventsObj[sel];_ref1=sel.split(" "),selector=2<=_ref1.length?__slice.call(_ref1,0,_k=_ref1.length-1):(_k=0,[]),event=_ref1[_k++];events.push({selector:selector.join(" "),event:event,functionName:functionName})}return events};Delegator.natives=function(){var key,specials,val;specials=function(){var _ref1,_results;_ref1=jQuery.event.special;_results=[];for(key in _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)}();Delegator._isCustomEvent=function(event){event=event.split(".")[0];return $.inArray(event,Delegator.natives)===-1};Range={};Range.sniff=function(r){if(r.commonAncestorContainer!=null){return new Range.BrowserRange(r)}else if(typeof r.start==="string"){return new Range.SerializedRange(r)}else if(r.start&&typeof r.start==="object"){return new Range.NormalizedRange(r)}else{console.error(_t("Could not sniff range type"));return false}};Range.nodeFromXPath=function(xpath,root){var customResolver,evaluateXPath,namespace,node,segment;if(root==null){root=document}evaluateXPath=function(xp,nsResolver){var exception;if(nsResolver==null){nsResolver=null}try{return document.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 Util.nodeFromXPath(xp,root)}};if(!$.isXMLDoc(document.documentElement)){return evaluateXPath(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"){return namespace}else{return document.documentElement.getAttribute("xmlns:"+ns)}};node=evaluateXPath(xpath,customResolver)}return node}};Range.RangeError=function(_super){__extends(RangeError,_super);function RangeError(type,message,parent){this.type=type;this.message=message;this.parent=parent!=null?parent:null;RangeError.__super__.constructor.call(this,this.message)}return RangeError}(Error);Range.BrowserRange=function(){function BrowserRange(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){var n,node,nr,r;if(this.tainted){console.error(_t("You may only call normalize() once on a BrowserRange!"));return false}else{this.tainted=true}r={};if(this.startContainer.nodeType===Node.ELEMENT_NODE){r.start=Util.getFirstTextNodeNotBefore(this.startContainer.childNodes[this.startOffset]);r.startOffset=0}else{r.start=this.startContainer;r.startOffset=this.startOffset}if(this.endContainer.nodeType===Node.ELEMENT_NODE){node=this.endContainer.childNodes[this.endOffset];if(node!=null){n=node;while(n!=null&&n.nodeType!==Node.TEXT_NODE){n=n.firstChild}if(n!=null){r.end=n;r.endOffset=0}}if(r.end==null){if(this.endOffset){node=this.endContainer.childNodes[this.endOffset-1]}else{node=this.endContainer.previousSibling}r.end=Util.getLastTextNodeUpTo(node);r.endOffset=r.end.nodeValue.length}}else{r.end=this.endContainer;r.endOffset=this.endOffset}nr={};if(r.startOffset>0){if(r.start.nodeValue.length>r.startOffset){nr.start=r.start.splitText(r.startOffset)}else{nr.start=r.start.nextSibling}}else{nr.start=r.start}if(r.start===r.end){if(nr.start.nodeValue.length>r.endOffset-r.startOffset){nr.start.splitText(r.endOffset-r.startOffset)}nr.end=nr.start}else{if(r.end.nodeValue.length>r.endOffset){r.end.splitText(r.endOffset)}nr.end=r.end}nr.commonAncestor=this.commonAncestorContainer;while(nr.commonAncestor.nodeType!==Node.ELEMENT_NODE){nr.commonAncestor=nr.commonAncestor.parentNode}return new Range.NormalizedRange(nr)};BrowserRange.prototype.serialize=function(root,ignoreSelector){return this.normalize(root).serialize(root,ignoreSelector)};return BrowserRange}();Range.NormalizedRange=function(){function NormalizedRange(obj){this.commonAncestor=obj.commonAncestor;this.start=obj.start;this.end=obj.end}NormalizedRange.prototype.normalize=function(root){return this};NormalizedRange.prototype.limit=function(bounds){var nodes,parent,startParents,_k,_len2,_ref1;nodes=$.grep(this.textNodes(),function(node){return node.parentNode===bounds||$.contains(bounds,node.parentNode)});if(!nodes.length){return null}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}}return this};NormalizedRange.prototype.serialize=function(root,ignoreSelector){var end,serialization,start;serialization=function(node,isEnd){var n,nodes,offset,origParent,textNodes,xpath,_k,_len2;if(ignoreSelector){origParent=$(node).parents(":not("+ignoreSelector+")").eq(0)}else{origParent=$(node).parent()}xpath=Util.xpathFromNode(origParent,root)[0];textNodes=Util.getTextNodes(origParent);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);return new Range.SerializedRange({start:start[0],end:end[0],startOffset:start[1],endOffset:end[1]})};NormalizedRange.prototype.text=function(){var node;return function(){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(){var end,start,textNodes,_ref1;textNodes=Util.getTextNodes($(this.commonAncestor));_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(){var range;range=document.createRange();range.setStartBefore(this.start);range.setEndAfter(this.end);return range};return NormalizedRange}();Range.SerializedRange=function(){function SerializedRange(obj){this.start=obj.start;this.startOffset=obj.startOffset;this.end=obj.end;this.endOffset=obj.endOffset}SerializedRange.prototype.normalize=function(root){var contains,e,length,node,p,range,targetOffset,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;throw new Range.RangeError(p,"Error while finding "+p+" node: "+this[p]+": "+e,e)}if(!node){throw new Range.RangeError(p,"Couldn't find "+p+" node: "+this[p])}length=0;targetOffset=this[p+"Offset"];if(p==="end"){targetOffset--}_ref2=Util.getTextNodes($(node));for(_l=0,_len3=_ref2.length;_l<_len3;_l++){tn=_ref2[_l];if(length+tn.nodeValue.length>targetOffset){range[p+"Container"]=tn;range[p+"Offset"]=this[p+"Offset"]-length;break}else{length+=tn.nodeValue.length}}if(range[p+"Offset"]==null){throw new Range.RangeError(""+p+"offset","Couldn't find offset "+this[p+"Offset"]+" in element "+this[p])}}contains=document.compareDocumentPosition==null?function(a,b){return a.contains(b)}:function(a,b){return a.compareDocumentPosition(b)&16};$(range.startContainer).parents().each(function(){if(contains(this,range.endContainer)){range.commonAncestorContainer=this;return false}});return new Range.BrowserRange(range).normalize(root)};SerializedRange.prototype.serialize=function(root,ignoreSelector){return this.normalize(root).serialize(root,ignoreSelector)};SerializedRange.prototype.toObject=function(){return{start:this.start,startOffset:this.startOffset,end:this.end,endOffset:this.endOffset}};return SerializedRange}();_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;function Annotator(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()){return this}if(!this.options.readOnly){this._setupDocumentEvents()}this._setupWrapper()._setupViewer()._setupEditor();this._setupDynamicStyle();this.adder=$(this.html.adder).appendTo(this.wrapper).hide();Annotator._instances.push(this)}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");return this};Annotator.prototype._setupViewer=function(){var _this=this;this.viewer=new Annotator.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).html(Util.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});return this};Annotator.prototype._setupEditor=function(){this.editor=new Annotator.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){return annotation.text=$(field).find("textarea").val()}});this.editor.element.appendTo(this.wrapper);return this};Annotator.prototype._setupDocumentEvents=function(){$(document).bind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});return this};Annotator.prototype._setupDynamicStyle=function(){var max,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"));return this};Annotator.prototype.destroy=function(){var idx,name,plugin,_base,_ref1;Annotator.__super__.destroy.apply(this,arguments);$(document).unbind({mouseup:this.checkForEndSelection,mousedown:this.checkForStartSelection});$("#annotator-dynamic-style").remove();this.adder.remove();this.viewer.destroy();this.editor.destroy();this.wrapper.find(".annotator-hl").each(function(){$(this).contents().insertBefore(this);return $(this).remove()});this.wrapper.contents().insertBefore(this.wrapper);this.wrapper.remove();this.element.data("annotator",null);_ref1=this.plugins;for(name in _ref1){plugin=_ref1[name];if(typeof(_base=this.plugins[name]).destroy==="function"){_base.destroy()}}idx=Annotator._instances.indexOf(this);if(idx!==-1){return Annotator._instances.splice(idx,1)}};Annotator.prototype.getSelectedRanges=function(){var browserRange,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=new Range.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())}return range})};Annotator.prototype.createAnnotation=function(){var annotation;annotation={};this.publish("beforeAnnotationCreated",[annotation]);return annotation};Annotator.prototype.setupAnnotation=function(annotation){var e,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(e instanceof Range.RangeError){this.publish("rangeNormalizeFail",[annotation,r,e])}else{throw e}}}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);$(annotation.highlights).attr("data-annotation-id",annotation.id);return annotation};Annotator.prototype.updateAnnotation=function(annotation){this.publish("beforeAnnotationUpdated",[annotation]);$(annotation.highlights).attr("data-annotation-id",annotation.id);this.publish("annotationUpdated",[annotation]);return annotation};Annotator.prototype.deleteAnnotation=function(annotation){var child,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]);return annotation};Annotator.prototype.loadAnnotations=function(annotations){var clone,loader,_this=this;if(annotations==null){annotations=[]}loader=function(annList){var n,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){return setTimeout(function(){return loader(annList)},10)}else{return _this.publish("annotationsLoaded",[clone])}};clone=annotations.slice();loader(annotations);return this};Annotator.prototype.dumpAnnotations=function(){if(this.plugins["Store"]){return this.plugins["Store"].dumpAnnotations()}else{console.warn(_t("Can't dump annotations without Store plugin."));return false}};Annotator.prototype.highlightRange=function(normedRange,cssClass){var hl,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){var highlights,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))}return highlights};Annotator.prototype.addPlugin=function(name,options){var klass,_base;if(this.plugins[name]){console.error(_t("You cannot have more than one instance of any plugin."))}else{klass=Annotator.Plugin[name];if(typeof klass==="function"){this.plugins[name]=new klass(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?"))}}return this};Annotator.prototype.showEditor=function(annotation,location){this.editor.element.css(location);this.editor.load(annotation);this.publish("annotationEditorShown",[this.editor,annotation]);return this};Annotator.prototype.onEditorHide=function(){this.publish("annotationEditorHidden",[this.editor]);return this.ignoreMouseup=false};Annotator.prototype.onEditorSubmit=function(annotation){return this.publish("annotationEditorSubmit",[this.editor,annotation])};Annotator.prototype.showViewer=function(annotations,location){this.viewer.element.css(location);this.viewer.load(annotations);return this.publish("annotationViewerShown",[this.viewer,annotations])};Annotator.prototype.startViewerHideTimer=function(){if(!this.viewerHideTimer){return this.viewerHideTimer=setTimeout(this.viewer.hide,250)}};Annotator.prototype.clearViewerHideTimer=function(){clearTimeout(this.viewerHideTimer);return this.viewerHideTimer=false};Annotator.prototype.checkForStartSelection=function(event){if(!(event&&this.isAnnotator(event.target))){this.startViewerHideTimer()}return this.mouseIsDown=true};Annotator.prototype.checkForEndSelection=function(event){var container,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(this.isAnnotator(container)){return}}if(event&&this.selectedRanges.length){return this.adder.css(Util.mousePosition(event,this.wrapper[0])).show()}else{return this.adder.hide()}};Annotator.prototype.isAnnotator=function(element){return!!$(element).parents().addBack().filter("[class^=annotator-]").not("[class^=annotator-hl]").not(this.wrapper).length};Annotator.prototype.onHighlightMouseover=function(event){var annotations;this.clearViewerHideTimer();if(this.mouseIsDown){return false}if(this.viewer.isShown()){this.viewer.hide()}annotations=$(event.target).parents(".annotator-hl").addBack().map(function(){return $(this).data("annotation")}).toArray();return this.showViewer(annotations,Util.mousePosition(event,this.wrapper[0]))};Annotator.prototype.onAdderMousedown=function(event){if(event!=null){event.preventDefault()}return this.ignoreMouseup=true};Annotator.prototype.onAdderClick=function(event){var annotation,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);return this.showEditor(annotation,position)};Annotator.prototype.onEditAnnotation=function(annotation){var cleanup,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();return this.showEditor(annotation,offset)};Annotator.prototype.onDeleteAnnotation=function(annotation){this.viewer.hide();return this.deleteAnnotation(annotation)};return Annotator}(Delegator);Annotator.Plugin=function(_super){__extends(Plugin,_super);function Plugin(element,options){Plugin.__super__.constructor.apply(this,arguments)}Plugin.prototype.pluginInit=function(){};return Plugin}(Delegator);g=Util.getGlobal();if(((_ref1=g.document)!=null?_ref1.evaluate:void 0)==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")}if(g.Node==null){g.Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12}}Annotator.$=$;Annotator.Delegator=Delegator;Annotator.Range=Range;Annotator.Util=Util;Annotator._instances=[];Annotator._t=_t;Annotator.supported=function(){return function(){return!!this.getSelection}()};Annotator.noConflict=function(){Util.getGlobal().Annotator=_Annotator;return this};$.fn.annotator=function(options){var args;args=Array.prototype.slice.call(arguments,1);return this.each(function(){var instance;instance=$.data(this,"annotator"); +if(options==="destroy"){$.removeData(this,"annotator");return instance!=null?instance.destroy(args):void 0}else if(instance){return options&&instance[options].apply(instance,args)}else{instance=new Annotator(this,options);return $.data(this,"annotator",instance)}})};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"}};function Widget(element,options){Widget.__super__.constructor.apply(this,arguments);this.classes=$.extend({},Annotator.Widget.prototype.classes,this.classes)}Widget.prototype.destroy=function(){this.removeEvents();return this.element.remove()};Widget.prototype.checkOrientation=function(){var current,offset,viewport,widget,window;this.resetOrientation();window=$(Annotator.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()}return this};Widget.prototype.resetOrientation=function(){this.element.removeClass(this.classes.invert.x).removeClass(this.classes.invert.y);return this};Widget.prototype.invertX=function(){this.element.addClass(this.classes.invert.x);return this};Widget.prototype.invertY=function(){this.element.addClass(this.classes.invert.y);return this};Widget.prototype.isInvertedY=function(){return this.element.hasClass(this.classes.invert.y)};Widget.prototype.isInvertedX=function(){return this.element.hasClass(this.classes.invert.x)};return Widget}(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={};function Editor(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){Annotator.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();return this.publish("show")};Editor.prototype.hide=function(event){Annotator.Util.preventEventDefault(event);this.element.addClass(this.classes.hide);return this.publish("hide")};Editor.prototype.load=function(annotation){var field,_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)}return this.show()};Editor.prototype.submit=function(event){var field,_k,_len2,_ref2;Annotator.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]);return this.hide()};Editor.prototype.addField=function(options){var element,field,input;field=$.extend({id:"annotator-field-"+Annotator.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 />");break;case"select":input=$("<select />")}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}))}else if(field.type==="select"){element.addClass("annotator-select");element.append($("<label />",{"for":field.id,html:field.label}))}this.element.find("ul:first").append(element);this.fields.push(field);return field.element};Editor.prototype.checkOrientation=function(){var controls,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)}else if(controls.is(":first-child")){controls.insertAfter(list)}return this};Editor.prototype.processKeypress=function(event){if(event.keyCode===27){return this.hide()}else if(event.keyCode===13&&!event.shiftKey){return this.submit()}};Editor.prototype.onCancelButtonMouseover=function(){return this.element.find("."+this.classes.focus).removeClass(this.classes.focus)};Editor.prototype.setupDraggables=function(){var classes,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});return event.preventDefault()}};onMouseup=function(){mousedown=null;return $(window).unbind(".annotator-editor-resize")};onMousemove=function(event){var diff,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.height();width=textarea.width();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.height()!==height){mousedown.top=event.pageY}if(textarea.width()!==width){mousedown.left=event.pageX}}else if(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;return setTimeout(function(){return throttle=false},1e3/60)}};resize.bind("mousedown",onMousedown);return controls.bind("mousedown",onMousedown)};return Editor}(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};function Viewer(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){var controls,_this=this;Annotator.Util.preventEventDefault(event);controls=this.element.find(".annotator-controls").addClass(this.classes.showControls);setTimeout(function(){return controls.removeClass(_this.classes.showControls)},500);this.element.removeClass(this.classes.hide);return this.checkOrientation().publish("show")};Viewer.prototype.isShown=function(){return!this.element.hasClass(this.classes.hide)};Viewer.prototype.hide=function(event){Annotator.Util.preventEventDefault(event);this.element.addClass(this.classes.hide);return this.publish("hide")};Viewer.prototype.load=function(annotations){var annotation,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=new LinkParser(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(){return edit.removeAttr("disabled")},hideEdit:function(){return edit.attr("disabled","disabled")},showDelete:function(){return del.removeAttr("disabled")},hideDelete:function(){return del.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]);return this.show()};Viewer.prototype.addField=function(options){var field;field=$.extend({load:function(){}},options);field.element=$("<div />")[0];this.fields.push(field);field.element;return this};Viewer.prototype.onEditClick=function(event){return this.onButtonClick(event,"edit")};Viewer.prototype.onDeleteClick=function(event){return this.onButtonClick(event,"delete")};Viewer.prototype.onButtonClick=function(event,type){var item;item=$(event.target).parents(".annotator-annotation");return this.publish(type,[item.data("annotation")])};return Viewer}(Annotator.Widget);LinkParser=function(){function LinkParser(data){this.data=data}LinkParser.prototype.get=function(rel,cond){var d,k,keys,match,v,_k,_len2,_ref2,_results;if(cond==null){cond={}}cond=$.extend({},cond,{rel:rel});keys=function(){var _results;_results=[];for(k in cond){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){return m&&d[k]===cond[k]},true);if(match){_results.push(d)}else{continue}}return _results};return LinkParser}();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"}};function Notification(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.currentStatus=status;$(this.element).addClass(this.options.classes.show).addClass(this.options.classes[this.currentStatus]).html(Util.escape(message||""));setTimeout(this.hide,5e3);return this};Notification.prototype.hide=function(){if(this.currentStatus==null){this.currentStatus=Annotator.Notification.INFO}$(this.element).removeClass(this.options.classes.show).removeClass(this.options.classes[this.currentStatus]);return this};return Notification}(Delegator);Annotator.Notification.INFO="info";Annotator.Notification.SUCCESS="success";Annotator.Notification.ERROR="error";$(function(){var notification;notification=new Annotator.Notification;Annotator.showNotification=notification.show;return Annotator.hideNotification=notification.hide});Annotator.Plugin.Unsupported=function(_super){__extends(Unsupported,_super);function Unsupported(){_ref2=Unsupported.__super__.constructor.apply(this,arguments);return _ref2}Unsupported.prototype.options={message:Annotator._t("Sorry your current browser does not support the Annotator")};Unsupported.prototype.pluginInit=function(){var _this=this;if(!Annotator.supported()){return $(function(){Annotator.showNotification(_this.options.message);if(window.XMLHttpRequest===void 0&&ActiveXObject!==void 0){return $("html").addClass("ie6")}})}};return Unsupported}(Annotator.Plugin);createDateFromISO8601=function(string){var d,date,offset,regexp,time,_ref3;regexp="([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})))?)?)?)?";d=string.match(new RegExp(regexp));offset=0;date=new Date(d[1],0,1);if(d[3]){date.setMonth(d[3]-1)}if(d[5]){date.setDate(d[5])}if(d[7]){date.setHours(d[7])}if(d[8]){date.setMinutes(d[8])}if(d[10]){date.setSeconds(d[10])}if(d[12]){date.setMilliseconds(Number("0."+d[12])*1e3)}if(d[14]){offset=Number(d[16])*60+Number(d[17]);offset*=(_ref3=d[15]==="-")!=null?_ref3:{1:-1}}offset-=date.getTimezoneOffset();time=Number(date)+offset*60*1e3;date.setTime(Number(time));return date};base64Decode=function(data){var ac,b64,bits,dec,h1,h2,h3,h4,i,o1,o2,o3,tmp_arr;if(typeof atob!=="undefined"&&atob!==null){return atob(data)}else{b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";i=0;ac=0;dec="";tmp_arr=[];if(!data){return data}data+="";while(i<data.length){h1=b64.indexOf(data.charAt(i++));h2=b64.indexOf(data.charAt(i++));h3=b64.indexOf(data.charAt(i++));h4=b64.indexOf(data.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;o1=bits>>16&255;o2=bits>>8&255;o3=bits&255;if(h3===64){tmp_arr[ac++]=String.fromCharCode(o1)}else if(h4===64){tmp_arr[ac++]=String.fromCharCode(o1,o2)}else{tmp_arr[ac++]=String.fromCharCode(o1,o2,o3)}}return tmp_arr.join("")}};base64UrlDecode=function(data){var i,m,_k,_ref3;m=data.length%4;if(m!==0){for(i=_k=0,_ref3=4-m;0<=_ref3?_k<_ref3:_k>_ref3;i=0<=_ref3?++_k:--_k){data+="="}}data=data.replace(/-/g,"+");data=data.replace(/_/g,"/");return base64Decode(data)};parseToken=function(token){var head,payload,sig,_ref3;_ref3=token.split("."),head=_ref3[0],payload=_ref3[1],sig=_ref3[2];return JSON.parse(base64UrlDecode(payload))};Annotator.Plugin.Auth=function(_super){__extends(Auth,_super);Auth.prototype.options={token:null,tokenUrl:"/auth/token",autoFetch:true,requestMethod:"GET",requestData:null,unauthorizedCallback:null};function Auth(element,options){Auth.__super__.constructor.apply(this,arguments);this.waitingForToken=[];if(this.options.token){this.setToken(this.options.token)}else{this.requestToken()}}Auth.prototype.requestToken=function(){var _this=this;this.requestInProgress=true;return $.ajax({url:this.options.tokenUrl,dataType:"text",data:this.options.requestData,type:this.options.requestMethod,xhrFields:{withCredentials:true}}).done(function(data,status,xhr){return _this.setToken(data)}).fail(function(xhr,status,err){var callback,msg;if(xhr.status===401){callback=_this.options.unauthorizedCallback;if(callback!=null&&callback(_this)){_this.retryTimeout=setTimeout(function(){return _this.requestToken()},1e3);return}}msg=Annotator._t("Couldn't get auth token:");console.error(""+msg+" "+err,xhr);return Annotator.showNotification(""+msg+" "+xhr.responseText,Annotator.Notification.ERROR)}).always(function(){return _this.requestInProgress=false})};Auth.prototype.setToken=function(token){var _results,_this=this;this.token=token;this._unsafeToken=parseToken(token);if(this.haveValidToken()){if(this.options.autoFetch){this.refreshTimeout=setTimeout(function(){return _this.requestToken()},(this.timeToExpiry()-2)*1e3)}this.updateHeaders();_results=[];while(this.waitingForToken.length>0){_results.push(this.waitingForToken.pop()(this._unsafeToken))}return _results}else{console.warn(Annotator._t("Didn't get a valid token."));if(this.options.autoFetch){console.warn(Annotator._t("Getting a new token in 10s."));return setTimeout(function(){return _this.requestToken()},10*1e3)}}};Auth.prototype.haveValidToken=function(){var allFields;allFields=this._unsafeToken&&this._unsafeToken.issuedAt&&this._unsafeToken.ttl&&this._unsafeToken.consumerKey;if(allFields&&this.timeToExpiry()>0){return true}else{return false}};Auth.prototype.timeToExpiry=function(){var expiry,issue,now,timeToExpiry;now=(new Date).getTime()/1e3;issue=createDateFromISO8601(this._unsafeToken.issuedAt).getTime()/1e3;expiry=issue+this._unsafeToken.ttl;timeToExpiry=expiry-now;if(timeToExpiry>0){return timeToExpiry}else{return 0}};Auth.prototype.updateHeaders=function(){var current;current=this.element.data("annotator:headers");return this.element.data("annotator:headers",$.extend(current,{"x-annotator-auth-token":this.token}))};Auth.prototype.withToken=function(callback){if(callback==null){return}if(this.haveValidToken()){return callback(this._unsafeToken)}else{this.waitingForToken.push(callback);if(!this.requestInProgress){return this.requestToken()}}};return Auth}(Annotator.Plugin);Annotator.Plugin.Store=function(_super){__extends(Store,_super);Store.prototype.events={annotationCreated:"annotationCreated",annotationDeleted:"annotationDeleted",annotationUpdated:"annotationUpdated"};Store.prototype.options={annotationData:{},emulateHTTP:false,loadFromSearch:false,prefix:"/store",urls:{create:"/annotations",read:"/annotations/:id",update:"/annotations/:id",destroy:"/annotations/:id",search:"/search"}};function Store(element,options){this._onError=__bind(this._onError,this);this._onLoadAnnotationsFromSearch=__bind(this._onLoadAnnotationsFromSearch,this);this._onLoadAnnotations=__bind(this._onLoadAnnotations,this);this._getAnnotations=__bind(this._getAnnotations,this);Store.__super__.constructor.apply(this,arguments);this.annotations=[]}Store.prototype.pluginInit=function(){if(!Annotator.supported()){return}if(this.annotator.plugins.Auth){return this.annotator.plugins.Auth.withToken(this._getAnnotations)}else{return this._getAnnotations()}};Store.prototype._getAnnotations=function(){if(this.options.loadFromSearch){return this.loadAnnotationsFromSearch(this.options.loadFromSearch)}else{return this.loadAnnotations()}};Store.prototype.annotationCreated=function(annotation){var _this=this;if(__indexOf.call(this.annotations,annotation)<0){this.registerAnnotation(annotation);return this._apiRequest("create",annotation,function(data){if(data.id==null){console.warn(Annotator._t("Warning: No ID returned from server for annotation "),annotation)}return _this.updateAnnotation(annotation,data)})}else{return this.updateAnnotation(annotation,{})}};Store.prototype.annotationUpdated=function(annotation){var _this=this;if(__indexOf.call(this.annotations,annotation)>=0){return this._apiRequest("update",annotation,function(data){return _this.updateAnnotation(annotation,data)})}};Store.prototype.annotationDeleted=function(annotation){var _this=this;if(__indexOf.call(this.annotations,annotation)>=0){return this._apiRequest("destroy",annotation,function(){_this.publish("annotationDestroyed",[annotation]);return _this.unregisterAnnotation(annotation)})}};Store.prototype.registerAnnotation=function(annotation){return this.annotations.push(annotation)};Store.prototype.unregisterAnnotation=function(annotation){return this.annotations.splice(this.annotations.indexOf(annotation),1)};Store.prototype.updateAnnotation=function(annotation,data){if(__indexOf.call(this.annotations,annotation)<0){console.error(Annotator._t("Trying to update unregistered annotation!"))}else{$.extend(annotation,data)}this.publish("annotationStored",[data]);return $(annotation.highlights).data("annotation",annotation)};Store.prototype.loadAnnotations=function(){return this._apiRequest("read",null,this._onLoadAnnotations)};Store.prototype._onLoadAnnotations=function(data){var a,annotation,annotationMap,newData,_k,_l,_len2,_len3,_ref3;if(data==null){data=[]}this.publish("annotationRead",[this.annotations,data]);annotationMap={};_ref3=this.annotations;for(_k=0,_len2=_ref3.length;_k<_len2;_k++){a=_ref3[_k];annotationMap[a.id]=a}newData=[];for(_l=0,_len3=data.length;_l<_len3;_l++){a=data[_l];if(annotationMap[a.id]){annotation=annotationMap[a.id];this.updateAnnotation(annotation,a)}else{newData.push(a)}}this.annotations=this.annotations.concat(newData);return this.annotator.loadAnnotations(newData.slice())};Store.prototype.loadAnnotationsFromSearch=function(searchOptions){return this._apiRequest("search",searchOptions,this._onLoadAnnotationsFromSearch)};Store.prototype._onLoadAnnotationsFromSearch=function(data){if(data==null){data={}}this.publish("annotationSearchResult",[this.annotations,data]);return this._onLoadAnnotations(data.rows||[])};Store.prototype.dumpAnnotations=function(){var ann,_k,_len2,_ref3,_results;_ref3=this.annotations;_results=[];for(_k=0,_len2=_ref3.length;_k<_len2;_k++){ann=_ref3[_k];_results.push(JSON.parse(this._dataFor(ann)))}return _results};Store.prototype._apiRequest=function(action,obj,onSuccess){var id,options,request,url;id=obj&&obj.id;url=this._urlFor(action,id);options=this._apiRequestOptions(action,obj,onSuccess);request=$.ajax(url,options);request._id=id;request._action=action;return request};Store.prototype._apiRequestOptions=function(action,obj,onSuccess){var data,method,opts;method=this._methodFor(action);opts={type:method,headers:this.element.data("annotator:headers"),dataType:"json",success:onSuccess||function(){},error:this._onError};if(this.options.emulateHTTP&&(method==="PUT"||method==="DELETE")){opts.headers=$.extend(opts.headers,{"X-HTTP-Method-Override":method});opts.type="POST"}if(action==="search"){opts=$.extend(opts,{data:obj});return opts}data=obj&&this._dataFor(obj);if(this.options.emulateJSON){opts.data={json:data};if(this.options.emulateHTTP){opts.data._method=method}return opts}opts=$.extend(opts,{data:data,contentType:"application/json; charset=utf-8"});return opts};Store.prototype._urlFor=function(action,id){var url;url=this.options.prefix!=null?this.options.prefix:"";url+=this.options.urls[action];url=url.replace(/\/:id/,id!=null?"/"+id:"");url=url.replace(/:id/,id!=null?id:"");return url};Store.prototype._methodFor=function(action){var table;table={create:"POST",read:"GET",update:"PUT",destroy:"DELETE",search:"GET"};return table[action]};Store.prototype._dataFor=function(annotation){var data,highlights;highlights=annotation.highlights;delete annotation.highlights;$.extend(annotation,this.options.annotationData);data=JSON.stringify(annotation);if(highlights){annotation.highlights=highlights}return data};Store.prototype._onError=function(xhr){var action,message;action=xhr._action;message=Annotator._t("Sorry we could not ")+action+Annotator._t(" this annotation");if(xhr._action==="search"){message=Annotator._t("Sorry we could not search the store for annotations")}else if(xhr._action==="read"&&!xhr._id){message=Annotator._t("Sorry we could not ")+action+Annotator._t(" the annotations from the store")}switch(xhr.status){case 401:message=Annotator._t("Sorry you are not allowed to ")+action+Annotator._t(" this annotation");break;case 404:message=Annotator._t("Sorry we could not connect to the annotations store");break;case 500:message=Annotator._t("Sorry something went wrong with the annotation store")}Annotator.showNotification(message,Annotator.Notification.ERROR);return console.error(Annotator._t("API request failed:")+(" '"+xhr.status+"'"))};return Store}(Annotator.Plugin);Annotator.Plugin.Permissions=function(_super){__extends(Permissions,_super);Permissions.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"};Permissions.prototype.options={showViewPermissionsCheckbox:true,showEditPermissionsCheckbox:true,userId:function(user){return user},userString:function(user){return user},userAuthorize:function(action,annotation,user){var token,tokens,_k,_len2;if(annotation.permissions){tokens=annotation.permissions[action]||[];if(tokens.length===0){return true}for(_k=0,_len2=tokens.length;_k<_len2;_k++){token=tokens[_k];if(this.userId(user)===token){return true}}return false}else if(annotation.user){if(user){return this.userId(user)===this.userId(annotation.user)}else{return false}}return true},user:"",permissions:{read:[],update:[],"delete":[],admin:[]}};function Permissions(element,options){this._setAuthFromToken=__bind(this._setAuthFromToken,this);this.updateViewer=__bind(this.updateViewer,this);this.updateAnnotationPermissions=__bind(this.updateAnnotationPermissions,this);this.updatePermissionsField=__bind(this.updatePermissionsField,this);this.addFieldsToAnnotation=__bind(this.addFieldsToAnnotation,this);Permissions.__super__.constructor.apply(this,arguments);if(this.options.user){this.setUser(this.options.user);delete this.options.user}}Permissions.prototype.pluginInit=function(){var createCallback,self,_this=this;if(!Annotator.supported()){return}self=this;createCallback=function(method,type){return function(field,annotation){return self[method].call(self,type,field,annotation)}};if(!this.user&&this.annotator.plugins.Auth){this.annotator.plugins.Auth.withToken(this._setAuthFromToken)}if(this.options.showViewPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>view</strong> this annotation"),load:createCallback("updatePermissionsField","read"),submit:createCallback("updateAnnotationPermissions","read")})}if(this.options.showEditPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>edit</strong> this annotation"),load:createCallback("updatePermissionsField","update"),submit:createCallback("updateAnnotationPermissions","update")})}this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){return this.annotator.plugins.Filter.addFilter({label:Annotator._t("User"),property:"user",isFiltered:function(input,user){var keyword,_k,_len2,_ref3;user=_this.options.userString(user);if(!(input&&user)){return false}_ref3=input.split(/\s*/);for(_k=0,_len2=_ref3.length;_k<_len2;_k++){keyword=_ref3[_k];if(user.indexOf(keyword)===-1){return false}}return true}})}};Permissions.prototype.setUser=function(user){return this.user=user};Permissions.prototype.addFieldsToAnnotation=function(annotation){if(annotation){annotation.permissions=$.extend(true,{},this.options.permissions);if(this.user){return annotation.user=this.user}}};Permissions.prototype.authorize=function(action,annotation,user){if(user===void 0){user=this.user}if(this.options.userAuthorize){return this.options.userAuthorize.call(this.options,action,annotation,user)}else{return true}};Permissions.prototype.updatePermissionsField=function(action,field,annotation){var input;field=$(field).show();input=field.find("input").removeAttr("disabled");if(!this.authorize("admin",annotation)){field.hide()}if(this.authorize(action,annotation||{},null)){return input.attr("checked","checked")}else{return input.removeAttr("checked")}};Permissions.prototype.updateAnnotationPermissions=function(type,field,annotation){var dataKey;if(!annotation.permissions){annotation.permissions=$.extend(true,{},this.options.permissions)}dataKey=type+"-permissions";if($(field).find("input").is(":checked")){return annotation.permissions[type]=[]}else{return annotation.permissions[type]=[this.options.userId(this.user)]}};Permissions.prototype.updateViewer=function(field,annotation,controls){var user,username;field=$(field);username=this.options.userString(annotation.user);if(annotation.user&&username&&typeof username==="string"){user=Annotator.Util.escape(this.options.userString(annotation.user));field.html(user).addClass("annotator-user")}else{field.remove()}if(controls){if(!this.authorize("update",annotation)){controls.hideEdit()}if(!this.authorize("delete",annotation)){return controls.hideDelete()}}};Permissions.prototype._setAuthFromToken=function(token){return this.setUser(token.userId)};return Permissions}(Annotator.Plugin);Annotator.Plugin.GroupPermissions=function(_super){__extends(GroupPermissions,_super);GroupPermissions.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"};GroupPermissions.prototype.options={showViewPermissionsCheckbox:true,showEditPermissionsCheckbox:true,showAdminGroupSelection:true,userId:function(user){if((user!=null?user.id:void 0)!=null){return user.id}else{return user}},userString:function(user){if((user!=null?user.name:void 0)!=null){return user.name}else{return user}},userAuthorize:function(action,annotation,user){var token,tokens,_k,_len2;if(annotation.permissions){tokens=annotation.permissions[action]||[];if(tokens.length===0){return true}for(_k=0,_len2=tokens.length;_k<_len2;_k++){token=tokens[_k];if(this.userId(user)===token){return true}else if((user!=null?user.groups:void 0)!=null&&__indexOf.call(user.groups,token)>=0){return true}}return false}else if(annotation.user){if(user){return this.userId(user)===this.userId(annotation.user)}else{return false}}return true},user:"",groups:[],permissions:{read:[],update:[],"delete":[],admin:[]}};function GroupPermissions(element,options){this._setAuthFromToken=__bind(this._setAuthFromToken,this);this._cleanPermissions=__bind(this._cleanPermissions,this);this.updateViewer=__bind(this.updateViewer,this);this.updateAnnotationPermissions=__bind(this.updateAnnotationPermissions,this);this.updateGroupPermissionsField=__bind(this.updateGroupPermissionsField,this);this.updatePermissionsField=__bind(this.updatePermissionsField,this);this.addFieldsToAnnotation=__bind(this.addFieldsToAnnotation,this);GroupPermissions.__super__.constructor.apply(this,arguments);if(this.options.user){this.setUser(this.options.user);delete this.options.user}if(this.options.groups&&this.options.groups.length>0){this.setGroups(this.options.groups);delete this.options.groups}}GroupPermissions.prototype.pluginInit=function(){var createCallback,self,_this=this;if(!Annotator.supported()){return}self=this;createCallback=function(method,type){return function(field,annotation){return self[method].call(self,type,field,annotation)}};if(!this.user&&this.annotator.plugins.Auth){this.annotator.plugins.Auth.withToken(this._setAuthFromToken)}if(this.options.showViewPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>view</strong> this annotation"),load:createCallback("updatePermissionsField","read"),submit:createCallback("updateAnnotationPermissions","read")})}if(this.options.showEditPermissionsCheckbox===true){this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>edit</strong> this annotation"),load:createCallback("updatePermissionsField","update"),submit:createCallback("updateAnnotationPermissions","update")})}if(this.options.showAdminGroupSelection===true){this.annotator.editor.addField({type:"select",label:Annotator._t(" group <strong>manages</strong> this annotation"),load:createCallback("updateGroupPermissionsField","admin"),submit:createCallback("updateAnnotationPermissions","admin")})}this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){return this.annotator.plugins.Filter.addFilter({label:Annotator._t("User"),property:"user",isFiltered:function(input,user){var keyword,_k,_len2,_ref3; +user=_this.options.userString(user);if(!(input&&user)){return false}_ref3=input.split(/\s*/);for(_k=0,_len2=_ref3.length;_k<_len2;_k++){keyword=_ref3[_k];if(user.indexOf(keyword)===-1){return false}}return true}})}};GroupPermissions.prototype.setUser=function(user){if(typeof user==="string"){return this.user={id:user,name:user}}else{return this.user=user}};GroupPermissions.prototype.setGroups=function(groups){this.groups=groups;return this.user.groups=function(){var _k,_len2,_results;_results=[];for(_k=0,_len2=groups.length;_k<_len2;_k++){g=groups[_k];_results.push("group:"+g)}return _results}()};GroupPermissions.prototype.addFieldsToAnnotation=function(annotation){if(annotation){annotation.permissions=$.extend(true,{},this.options.permissions);if(this.user){return annotation.user=this.user}}};GroupPermissions.prototype.authorize=function(action,annotation,user){if(user===void 0){user=this.user}if(this.options.userAuthorize){return this.options.userAuthorize.call(this.options,action,annotation,user)}else{return true}};GroupPermissions.prototype.updatePermissionsField=function(action,field,annotation){var input;field=$(field).show();input=field.find("input").removeAttr("disabled");if(!this.authorize("admin",annotation)){field.hide()}return input.prop("checked",this.authorize(action,annotation,null))};GroupPermissions.prototype.updateGroupPermissionsField=function(action,field,annotation){var input,permuser,_k,_len2,_ref3,_ref4,_ref5,_results;field=$(field);if(!(this.authorize("admin",annotation)&&((_ref3=this.groups)!=null?_ref3.length:void 0)>0)){field.hide();return}field.show();input=field.find("select").removeAttr("disabled");permuser=((_ref4=annotation.permissions)!=null?_ref4[action][0]:void 0)||this.options.userId(this.user);input.empty();input.append($("<option>",{selected:permuser===this.options.userId(this.user),html:" "}));_ref5=this.groups;_results=[];for(_k=0,_len2=_ref5.length;_k<_len2;_k++){g=_ref5[_k];_results.push(input.append($("<option>",{selected:permuser==="group:"+g,html:g})))}return _results};GroupPermissions.prototype.updateAnnotationPermissions=function(type,field,annotation){var dataKey,group;if(!annotation.permissions){annotation.permissions=$.extend(true,{},this.options.permissions)}dataKey=type+"-permissions";if(group=$(field).find("select").val()){annotation.permissions[type]=["group:"+group]}else if($(field).find("input").is(":checked")){annotation.permissions[type]=[]}else{annotation.permissions[type]=[this.options.userId(this.user)]}if(type==="admin"){return this._cleanPermissions(annotation)}};GroupPermissions.prototype.updateViewer=function(field,annotation,controls){var user,username,_ref3,_ref4;field=$(field);username=this.options.userString(annotation.user);if(annotation.user&&username&&typeof username==="string"){user=Annotator.Util.escape(this.options.userString(annotation.user));if(((_ref3=annotation.permissions)!=null?(_ref4=_ref3.admin)!=null?_ref4[0].indexOf("group:"):void 0:void 0)===0){user+=" (Group "+annotation.permissions.admin[0].substr(6)+")"}field.html(user).addClass("annotator-user")}else{field.remove()}if(controls){if(!this.authorize("update",annotation)){controls.hideEdit()}if(!this.authorize("delete",annotation)){return controls.hideDelete()}}};GroupPermissions.prototype._cleanPermissions=function(annotation){var perm,type,_k,_len2,_ref3,_results;perm=annotation.permissions["admin"];annotation.permissions["delete"]=perm;_ref3=["update","read"];_results=[];for(_k=0,_len2=_ref3.length;_k<_len2;_k++){type=_ref3[_k];if(annotation.permissions[type].length===0){_results.push(perm=[])}else{_results.push(annotation.permissions[type]=perm)}}return _results};GroupPermissions.prototype._setAuthFromToken=function(token){this.setUser(token.userId);if(token.memberOf!=null){return this.setGroups(token.memberOf)}};return GroupPermissions}(Annotator.Plugin);Annotator.Plugin.Filter=function(_super){__extends(Filter,_super);Filter.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"};Filter.prototype.classes={active:"annotator-filter-active",hl:{hide:"annotator-hl-filtered",active:"annotator-hl-active"}};Filter.prototype.html={element:'<div class="annotator-filter">\n <strong>'+Annotator._t("Navigate:")+'</strong>\n<span class="annotator-filter-navigation">\n <button class="annotator-filter-previous">'+Annotator._t("Previous")+'</button>\n<button class="annotator-filter-next">'+Annotator._t("Next")+"</button>\n</span>\n<strong>"+Annotator._t("Filter by:")+"</strong>\n</div>",filter:'<span class="annotator-filter-property">\n <label></label>\n <input/>\n <button class="annotator-filter-clear">'+Annotator._t("Clear")+"</button>\n</span>"};Filter.prototype.options={appendTo:"body",filters:[],addAnnotationFilter:true,isFiltered:function(input,property){var keyword,_k,_len2,_ref3;if(!(input&&property)){return false}_ref3=input.split(/\s+/);for(_k=0,_len2=_ref3.length;_k<_len2;_k++){keyword=_ref3[_k];if(property.indexOf(keyword)===-1){return false}}return true}};function Filter(element,options){this._onPreviousClick=__bind(this._onPreviousClick,this);this._onNextClick=__bind(this._onNextClick,this);this._onFilterKeyup=__bind(this._onFilterKeyup,this);this._onFilterBlur=__bind(this._onFilterBlur,this);this._onFilterFocus=__bind(this._onFilterFocus,this);this.updateHighlights=__bind(this.updateHighlights,this);var _base;element=$(this.html.element).appendTo((options!=null?options.appendTo:void 0)||this.options.appendTo);Filter.__super__.constructor.call(this,element,options);(_base=this.options).filters||(_base.filters=[]);this.filter=$(this.html.filter);this.filters=[];this.current=0}Filter.prototype.pluginInit=function(){var filter,_k,_len2,_ref3;_ref3=this.options.filters;for(_k=0,_len2=_ref3.length;_k<_len2;_k++){filter=_ref3[_k];this.addFilter(filter)}this.updateHighlights();this._setupListeners()._insertSpacer();if(this.options.addAnnotationFilter===true){return this.addFilter({label:Annotator._t("Annotation"),property:"text"})}};Filter.prototype.destroy=function(){var currentMargin,html;Filter.__super__.destroy.apply(this,arguments);html=$("html");currentMargin=parseInt(html.css("padding-top"),10)||0;html.css("padding-top",currentMargin-this.element.outerHeight());return this.element.remove()};Filter.prototype._insertSpacer=function(){var currentMargin,html;html=$("html");currentMargin=parseInt(html.css("padding-top"),10)||0;html.css("padding-top",currentMargin+this.element.outerHeight());return this};Filter.prototype._setupListeners=function(){var event,events,_k,_len2;events=["annotationsLoaded","annotationCreated","annotationUpdated","annotationDeleted"];for(_k=0,_len2=events.length;_k<_len2;_k++){event=events[_k];this.annotator.subscribe(event,this.updateHighlights)}return this};Filter.prototype.addFilter=function(options){var f,filter;filter=$.extend({label:"",property:"",isFiltered:this.options.isFiltered},options);if(!function(){var _k,_len2,_ref3,_results;_ref3=this.filters;_results=[];for(_k=0,_len2=_ref3.length;_k<_len2;_k++){f=_ref3[_k];if(f.property===filter.property){_results.push(f)}}return _results}.call(this).length){filter.id="annotator-filter-"+filter.property;filter.annotations=[];filter.element=this.filter.clone().appendTo(this.element);filter.element.find("label").html(filter.label).attr("for",filter.id);filter.element.find("input").attr({id:filter.id,placeholder:Annotator._t("Filter by ")+filter.label+"…"});filter.element.find("button").hide();filter.element.data("filter",filter);this.filters.push(filter)}return this};Filter.prototype.updateFilter=function(filter){var annotation,annotations,input,property,_k,_len2,_ref3;filter.annotations=[];this.updateHighlights();this.resetHighlights();input=$.trim(filter.element.find("input").val());if(input){annotations=this.highlights.map(function(){return $(this).data("annotation")});_ref3=$.makeArray(annotations);for(_k=0,_len2=_ref3.length;_k<_len2;_k++){annotation=_ref3[_k];property=annotation[filter.property];if(filter.isFiltered(input,property)){filter.annotations.push(annotation)}}return this.filterHighlights()}};Filter.prototype.updateHighlights=function(){this.highlights=this.annotator.element.find(".annotator-hl:visible");return this.filtered=this.highlights.not(this.classes.hl.hide)};Filter.prototype.filterHighlights=function(){var activeFilters,annotation,annotations,filtered,highlights,index,uniques,_k,_len2,_ref3;activeFilters=$.grep(this.filters,function(filter){return!!filter.annotations.length});filtered=((_ref3=activeFilters[0])!=null?_ref3.annotations:void 0)||[];if(activeFilters.length>1){annotations=[];$.each(activeFilters,function(){return $.merge(annotations,this.annotations)});uniques=[];filtered=[];$.each(annotations,function(){if($.inArray(this,uniques)===-1){return uniques.push(this)}else{return filtered.push(this)}})}highlights=this.highlights;for(index=_k=0,_len2=filtered.length;_k<_len2;index=++_k){annotation=filtered[index];highlights=highlights.not(annotation.highlights)}highlights.addClass(this.classes.hl.hide);this.filtered=this.highlights.not(this.classes.hl.hide);return this};Filter.prototype.resetHighlights=function(){this.highlights.removeClass(this.classes.hl.hide);this.filtered=this.highlights;return this};Filter.prototype._onFilterFocus=function(event){var input;input=$(event.target);input.parent().addClass(this.classes.active);return input.next("button").show()};Filter.prototype._onFilterBlur=function(event){var input;if(!event.target.value){input=$(event.target);input.parent().removeClass(this.classes.active);return input.next("button").hide()}};Filter.prototype._onFilterKeyup=function(event){var filter;filter=$(event.target).parent().data("filter");if(filter){return this.updateFilter(filter)}};Filter.prototype._findNextHighlight=function(previous){var active,annotation,current,index,next,offset,operator,resetOffset;if(!this.highlights.length){return this}offset=previous?0:-1;resetOffset=previous?-1:0;operator=previous?"lt":"gt";active=this.highlights.not("."+this.classes.hl.hide);current=active.filter("."+this.classes.hl.active);if(!current.length){current=active.eq(offset)}annotation=current.data("annotation");index=active.index(current[0]);next=active.filter(":"+operator+"("+index+")").not(annotation.highlights).eq(resetOffset);if(!next.length){next=active.eq(resetOffset)}return this._scrollToHighlight(next.data("annotation").highlights)};Filter.prototype._onNextClick=function(event){return this._findNextHighlight()};Filter.prototype._onPreviousClick=function(event){return this._findNextHighlight(true)};Filter.prototype._scrollToHighlight=function(highlight){highlight=$(highlight);this.highlights.removeClass(this.classes.hl.active);highlight.addClass(this.classes.hl.active);return $("html, body").animate({scrollTop:highlight.offset().top-(this.element.height()+20)},150)};Filter.prototype._onClearClick=function(event){return $(event.target).prev("input").val("").keyup().blur()};return Filter}(Annotator.Plugin);Annotator.Plugin.Markdown=function(_super){__extends(Markdown,_super);Markdown.prototype.events={annotationViewerTextField:"updateTextField"};function Markdown(element,options){this.updateTextField=__bind(this.updateTextField,this);if((typeof Showdown!=="undefined"&&Showdown!==null?Showdown.converter:void 0)!=null){Markdown.__super__.constructor.apply(this,arguments);this.converter=new Showdown.converter}else{console.error(Annotator._t("To use the Markdown plugin, you must include Showdown into the page first."))}}Markdown.prototype.updateTextField=function(field,annotation){var text;text=Annotator.Util.escape(annotation.text||"");return $(field).html(this.convert(text))};Markdown.prototype.convert=function(text){return this.converter.makeHtml(text)};return Markdown}(Annotator.Plugin);Annotator.Plugin.Tags=function(_super){__extends(Tags,_super);function Tags(){this.setAnnotationTags=__bind(this.setAnnotationTags,this);this.updateField=__bind(this.updateField,this);_ref3=Tags.__super__.constructor.apply(this,arguments);return _ref3}Tags.prototype.options={parseTags:function(string){var tags;string=$.trim(string);tags=[];if(string){tags=string.split(/\s+/)}return tags},stringifyTags:function(array){return array.join(" ")}};Tags.prototype.field=null;Tags.prototype.input=null;Tags.prototype.pluginInit=function(){if(!Annotator.supported()){return}this.field=this.annotator.editor.addField({label:Annotator._t("Add some tags here")+"…",load:this.updateField,submit:this.setAnnotationTags});this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter){this.annotator.plugins.Filter.addFilter({label:Annotator._t("Tag"),property:"tags",isFiltered:Annotator.Plugin.Tags.filterCallback})}return this.input=$(this.field).find(":input")};Tags.prototype.parseTags=function(string){return this.options.parseTags(string)};Tags.prototype.stringifyTags=function(array){return this.options.stringifyTags(array)};Tags.prototype.updateField=function(field,annotation){var value;value="";if(annotation.tags){value=this.stringifyTags(annotation.tags)}return this.input.val(value)};Tags.prototype.setAnnotationTags=function(field,annotation){return annotation.tags=this.parseTags(this.input.val())};Tags.prototype.updateViewer=function(field,annotation){field=$(field);if(annotation.tags&&$.isArray(annotation.tags)&&annotation.tags.length){return field.addClass("annotator-tags").html(function(){var string;return string=$.map(annotation.tags,function(tag){return'<span class="annotator-tag">'+Annotator.Util.escape(tag)+"</span>"}).join(" ")})}else{return field.remove()}};return Tags}(Annotator.Plugin);Annotator.Plugin.Tags.filterCallback=function(input,tags){var keyword,keywords,matches,tag,_k,_l,_len2,_len3;if(tags==null){tags=[]}matches=0;keywords=[];if(input){keywords=input.split(/\s+/g);for(_k=0,_len2=keywords.length;_k<_len2;_k++){keyword=keywords[_k];if(tags.length){for(_l=0,_len3=tags.length;_l<_len3;_l++){tag=tags[_l];if(tag.indexOf(keyword)!==-1){matches+=1}}}}}return matches===keywords.length};Annotator.Plugin.DigilibIntegrator=function(_super){__extends(DigilibIntegrator,_super);function DigilibIntegrator(){_ref4=DigilibIntegrator.__super__.constructor.apply(this,arguments);return _ref4}DigilibIntegrator.prototype.events={annotationDeleted:"annotationDeleted"};DigilibIntegrator.prototype.options={hooks:null};DigilibIntegrator.prototype.pluginInit=function(){this.annotator.digilib=this.options.hooks;this.annotator.setupRangeAnnotation=this.annotator.setupAnnotation;this.annotator.setupAnnotation=this._setupAnnotation;return this};DigilibIntegrator.prototype._setupAnnotation=function(annotation){if(this.selectedShapes||annotation.shapes!=null||this.selectedAreas!=null||annotation.areas!=null){annotation.shapes||(annotation.shapes=this.selectedShapes);annotation.highlights=[];annotation.ranges=[];this.digilib.setupAnnotation(annotation);return annotation}else{return this.setupRangeAnnotation.apply(this,arguments)}};DigilibIntegrator.prototype.annotationDeleted=function(annotation){return this.options.hooks.annotationDeleted(annotation)};return DigilibIntegrator}(Annotator.Plugin)}.call(this); +// +//# sourceMappingURL=annotator-dl.min.map \ No newline at end of file
--- a/webapp/src/main/webapp/jquery/jquery.digilib.js Mon Feb 13 17:08:04 2017 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.js Mon Feb 13 19:54:43 2017 +0100 @@ -45,7 +45,7 @@ var defaults = { // version of this script - 'version' : 'jquery.digilib.js 2.5.0', + 'version' : 'jquery.digilib.js 2.5.1', // logo url 'logoUrl' : 'img/digilib-logo-text1.png', // homepage url (behind logo)