*/((function(){vara,b,c,d,e=Object.prototype.hasOwnProperty,f=function(a,b){functiond(){this.constructor=a}for(varcinb)e.call(b,c)&&(a[c]=b[c]);returnd.prototype=b.prototype,a.prototype=newd,a.__super__=b.prototype,a};c=function(a){varb,c,d,e,f,g;returne="([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})))?)?)?)?",b=a.match(newRegExp(e)),d=0,c=newDate(b[1],0,1),b[3]&&c.setMonth(b[3]-1),b[5]&&c.setDate(b[5]),b[7]&&c.setHours(b[7]),b[8]&&c.setMinutes(b[8]),b[10]&&c.setSeconds(b[10]),b[12]&&c.setMilliseconds(Number("0."+b[12])*1e3),b[14]&&(d=Number(b[16])*60+Number(b[17]),d*=(g=b[15]==="-")!=null?g:{1:-1}),d-=c.getTimezoneOffset(),f=Number(c)+d*60*1e3,c.setTime(Number(f)),c},a=function(a){varb,c,d,e,f,g,h,i,j,k,l,m,n;if(typeofatob!="undefined"&&atob!==null)returnatob(a);c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",j=0,b=0,e="",n=[];if(!a)returna;a+="";while(j<a.length)f=c.indexOf(a.charAt(j++)),g=c.indexOf(a.charAt(j++)),h=c.indexOf(a.charAt(j++)),i=c.indexOf(a.charAt(j++)),d=f<<18|g<<12|h<<6|i,k=d>>16&255,l=d>>8&255,m=d&255,h===64?n[b++]=String.fromCharCode(k):i===64?n[b++]=String.fromCharCode(k,l):n[b++]=String.fromCharCode(k,l,m);returnn.join("")},b=function(b){varc,d,e;d=b.length%4;if(d!==0)for(c=0,e=4-d;0<=e?c<e:c>e;0<=e?c++:c--)b+="=";returnb=b.replace(/-/g,"+"),b=b.replace(/_/g,"/"),a(b)},d=function(a){varc,d,e,f;returnf=a.split("."),c=f[0],d=f[1],e=f[2],JSON.parse(b(d))},Annotator.Plugin.Auth=function(a){functionb(a,c){b.__super__.constructor.apply(this,arguments),this.waitingForToken=[],this.options.token?this.setToken(this.options.token):this.requestToken()}returnf(b,a),b.prototype.options={token:null,tokenUrl:"/auth/token",autoFetch:!0},b.prototype.requestToken=function(){vara=this;returnthis.requestInProgress=!0,$.ajax({url:this.options.tokenUrl,dataType:"text",xhrFields:{withCredentials:!0}}).done(function(b,c,d){returna.setToken(b)}).fail(function(a,b,c){vard;returnd=Annotator._t("Couldn't get auth token:"),console.error(""+d+" "+c,a),Annotator.showNotification(""+d+" "+a.responseText,Annotator.Notification.ERROR)}).always(function(){returna.requestInProgress=!1})},b.prototype.setToken=function(a){varb,c=this;this.token=a,this._unsafeToken=d(a);if(this.haveValidToken()){this.options.autoFetch&&(this.refreshTimeout=setTimeout(function(){returnc.requestToken()},(this.timeToExpiry()-2)*1e3)),this.updateHeaders(),b=[];while(this.waitingForToken.length>0)b.push(this.waitingForToken.pop()(this._unsafeToken));returnb}console.warn(Annotator._t("Didn't get a valid token."));if(this.options.autoFetch)returnconsole.warn(Annotator._t("Getting a new token in 10s.")),setTimeout(function(){returnc.requestToken()},1e4)},b.prototype.haveValidToken=function(){vara;returna=this._unsafeToken&&this._unsafeToken.issuedAt&&this._unsafeToken.ttl&&this._unsafeToken.consumerKey,a&&this.timeToExpiry()>0},b.prototype.timeToExpiry=function(){vara,b,d,e;returnd=(newDate).getTime()/1e3,b=c(this._unsafeToken.issuedAt).getTime()/1e3,a=b+this._unsafeToken.ttl,e=a-d,e>0?e:0},b.prototype.updateHeaders=function(){vara;returna=this.element.data("annotator:headers"),this.element.data("annotator:headers",$.extend(a,{"x-annotator-auth-token":this.token}))},b.prototype.withToken=function(a){if(a==null)return;if(this.haveValidToken())returna(this._unsafeToken);this.waitingForToken.push(a);if(!this.requestInProgress)returnthis.requestToken()},b}(Annotator.Plugin)})).call(this);
*/((function(){vara=function(a,b){returnfunction(){returna.apply(b,arguments)}},b=Object.prototype.hasOwnProperty,c=function(a,c){functione(){this.constructor=a}for(vardinc)b.call(c,d)&&(a[d]=c[d]);returne.prototype=c.prototype,a.prototype=newe,a.__super__=c.prototype,a};Annotator.Plugin.Permissions=function(b){functiond(b,c){this._setAuthFromToken=a(this._setAuthFromToken,this),this.updateViewer=a(this.updateViewer,this),this.updateAnnotationPermissions=a(this.updateAnnotationPermissions,this),this.updatePermissionsField=a(this.updatePermissionsField,this),this.addFieldsToAnnotation=a(this.addFieldsToAnnotation,this),d.__super__.constructor.apply(this,arguments),this.options.user&&(this.setUser(this.options.user),deletethis.options.user)}returnc(d,b),d.prototype.events={beforeAnnotationCreated:"addFieldsToAnnotation"},d.prototype.options={showViewPermissionsCheckbox:!0,showEditPermissionsCheckbox:!0,userId:function(a){returna},userString:function(a){returna},userAuthorize:function(a,b,c){vard,e,f,g;if(b.permissions){e=b.permissions[a]||[];if(e.length===0)return!0;for(f=0,g=e.length;f<g;f++){d=e[f];if(this.userId(c)===d)return!0}return!1}returnb.user?c&&this.userId(c)===this.userId(b.user):!0},user:"",permissions:{read:[],update:[],"delete":[],admin:[]}},d.prototype.pluginInit=function(){vara,b,c=this;if(!Annotator.supported())return;b=this,a=function(a,c){returnfunction(d,e){returnb[a].call(b,c,d,e)}},!this.user&&this.annotator.plugins.Auth&&this.annotator.plugins.Auth.withToken(this._setAuthFromToken),this.options.showViewPermissionsCheckbox===!0&&this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>view</strong> this annotation"),load:a("updatePermissionsField","read"),submit:a("updateAnnotationPermissions","read")}),this.options.showEditPermissionsCheckbox===!0&&this.annotator.editor.addField({type:"checkbox",label:Annotator._t("Allow anyone to <strong>edit</strong> this annotation"),load:a("updatePermissionsField","update"),submit:a("updateAnnotationPermissions","update")}),this.annotator.viewer.addField({load:this.updateViewer});if(this.annotator.plugins.Filter)returnthis.annotator.plugins.Filter.addFilter({label:Annotator._t("User"),property:"user",isFiltered:function(a,b){vard,e,f,g;b=c.options.userString(b);if(!a||!b)return!1;g=a.split(/\s*/);for(e=0,f=g.length;e<f;e++){d=g[e];if(b.indexOf(d)===-1)return!1}return!0}})},d.prototype.setUser=function(a){returnthis.user=a},d.prototype.addFieldsToAnnotation=function(a){if(a){a.permissions=this.options.permissions;if(this.user)returna.user=this.user}},d.prototype.authorize=function(a,b,c){returnc===void0&&(c=this.user),this.options.userAuthorize?this.options.userAuthorize.call(this.options,a,b,c):!0},d.prototype.updatePermissionsField=function(a,b,c){vard;returnb=$(b).show(),d=b.find("input").removeAttr("disabled"),this.authorize("admin",c)||b.hide(),this.authorize(a,c||{},null)?d.attr("checked","checked"):d.removeAttr("checked")},d.prototype.updateAnnotationPermissions=function(a,b,c){vard;returnc.permissions||(c.permissions=this.options.permissions),d=a+"-permissions",$(b).find("input").is(":checked")?c.permissions[a]=[]:c.permissions[a]=[this.user]},d.prototype.updateViewer=function(a,b,c){vard,e;a=$(a),e=this.options.userString(b.user),b.user&&e&&typeofe=="string"?(d=Annotator.$.escape(this.options.userString(b.user)),a.html(d).addClass("annotator-user")):a.remove(),this.authorize("update",b)||c.hideEdit();if(!this.authorize("delete",b))returnc.hideDelete()},d.prototype._setAuthFromToken=function(a){returnthis.setUser(a.userId)},d}(Annotator.Plugin)})).call(this);
*/((function(){vara=function(a,b){returnfunction(){returna.apply(b,arguments)}},b=Object.prototype.hasOwnProperty,c=function(a,c){functione(){this.constructor=a}for(vardinc)b.call(c,d)&&(a[d]=c[d]);returne.prototype=c.prototype,a.prototype=newe,a.__super__=c.prototype,a},d=Array.prototype.indexOf||function(a){for(varb=0,c=this.length;b<c;b++)if(binthis&&this[b]===a)returnb;return-1};Annotator.Plugin.Store=function(b){functione(b,c){this._onError=a(this._onError,this),this._onLoadAnnotationsFromSearch=a(this._onLoadAnnotationsFromSearch,this),this._onLoadAnnotations=a(this._onLoadAnnotations,this),this._getAnnotations=a(this._getAnnotations,this),e.__super__.constructor.apply(this,arguments),this.annotations=[]}returnc(e,b),e.prototype.events={annotationCreated:"annotationCreated",annotationDeleted:"annotationDeleted",annotationUpdated:"annotationUpdated"},e.prototype.options={prefix:"/store",autoFetch:!0,annotationData:{},loadFromSearch:!1,urls:{create:"/annotations",read:"/annotations/:id",update:"/annotations/:id",destroy:"/annotations/:id",search:"/search"}},e.prototype.pluginInit=function(){if(!Annotator.supported())return;returnthis.annotator.plugins.Auth?this.annotator.plugins.Auth.withToken(this._getAnnotations):this._getAnnotations()},e.prototype._getAnnotations=function(){returnthis.options.loadFromSearch?this.loadAnnotationsFromSearch(this.options.loadFromSearch):this.loadAnnotations()},e.prototype.annotationCreated=function(a){varb=this;returnd.call(this.annotations,a)<0?(this.registerAnnotation(a),this._apiRequest("create",a,function(c){returnc.id==null&&console.warn(Annotator._t("Warning: No ID returned from server for annotation "),a),b.updateAnnotation(a,c)})):this.updateAnnotation(a,{})},e.prototype.annotationUpdated=function(a){varb=this;if(d.call(this.annotations,a)>=0)returnthis._apiRequest("update",a,function(c){returnb.updateAnnotation(a,c)})},e.prototype.annotationDeleted=function(a){varb=this;if(d.call(this.annotations,a)>=0)returnthis._apiRequest("destroy",a,function(){returnb.unregisterAnnotation(a)})},e.prototype.registerAnnotation=function(a){returnthis.annotations.push(a)},e.prototype.unregisterAnnotation=function(a){returnthis.annotations.splice(this.annotations.indexOf(a),1)},e.prototype.updateAnnotation=function(a,b){returnd.call(this.annotations,a)<0?console.error(Annotator._t("Trying to update unregistered annotation!")):$.extend(a,b),$(a.highlights).data("annotation",a)},e.prototype.loadAnnotations=function(){returnthis._apiRequest("read",null,this._onLoadAnnotations)},e.prototype._onLoadAnnotations=function(a){returna==null&&(a=[]),this.annotations=a,this.annotator.loadAnnotations(a.slice())},e.prototype.loadAnnotationsFromSearch=function(a){returnthis._apiRequest("search",a,this._onLoadAnnotationsFromSearch)},e.prototype._onLoadAnnotationsFromSearch=function(a){returna==null&&(a={}),this._onLoadAnnotations(a.rows||[])},e.prototype.dumpAnnotations=function(){vara,b,c,d,e;d=this.annotations,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(JSON.parse(this._dataFor(a)));returne},e.prototype._apiRequest=function(a,b,c){vard,e,f,g;returnd=b&&b.id,g=this._urlFor(a,d),e=this._apiRequestOptions(a,b,c),f=$.ajax(g,e),f._id=d,f._action=a,f},e.prototype._apiRequestOptions=function(a,b,c){vard;returnd={type:this._methodFor(a),headers:this.element.data("annotator:headers"),dataType:"json",success:c||function(){},error:this._onError},a==="search"?d=$.extend(d,{data:b}):d=$.extend(d,{data:b&&this._dataFor(b),contentType:"application/json; charset=utf-8"}),d},e.prototype._urlFor=function(a,b){varc,d;returnc=b!=null?"/"+b:"",d=this.options.prefix||"/",d+=this.options.urls[a],d=d.replace(/\/:id/,c),d},e.prototype._methodFor=function(a){varb;returnb={create:"POST",read:"GET",update:"PUT",destroy:"DELETE",search:"GET"},b[a]},e.prototype._dataFor=function(a){varb,c;returnc=a.highlights,deletea.highlights,$.extend(a,this.options.annotationData),b=JSON.stringify(a),c&&(a.highlights=c),b},e.prototype._onError=function(a){varb,c;b=a._action,c=Annotator._t("Sorry we could not ")+b+Annotator._t(" this annotation"),a._action==="search"?c=Annotator._t("Sorry we could not search the store for annotations"):a._action==="read"&&!a._id&&(c=Annotator._t("Sorry we could not ")+b+Annotator._t(" the annotations from the store"));switch(a.status){case401:c=Annotator._t("Sorry you are not allowed to ")+b+Annotator._t(" this annotation");break;case404:c=Annotator._t("Sorry we could not connect to the annotations store");break;case500:c=Annotator._t("Sorry something went wrong with the annotation store")}returnAnnotator.showNotification(c,Annotator.Notification.ERROR),console.error(Annotator._t("API request failed:")+(" '"+a.status+"'"))},e}(Annotator.Plugin)})).call(this);