"].join("\n"),filter:[''," "," ",' ",""].join("\n")};Filter.options={appendTo:"body",filterElement:"body",filters:[],addAnnotationFilter:true,isFiltered:function(input,property){if(!(input&&property)){return false}var keywords=input.split(/\s+/);for(var i=0,len=keywords.length;i0){setTimeout(function(){loader(annList)},self.options.chunkDelay)}else{resolve(highlights)}}var clone=annotations.slice();loader(clone)});return p};Highlighter.prototype.draw=function(annotation){var normedRanges=[];for(var i=0,ilen=annotation.ranges.length;imax){max=zIndex}}}return max}function injectDynamicStyle(){util.$("#annotator-dynamic-style").remove();var sel="*"+":not(annotator-adder)"+":not(annotator-outer)"+":not(annotator-notice)"+":not(annotator-filter)";var max=maxZIndex(util.$(global.document.body).find(sel).get());max=Math.max(max,1e3);var rules=[".annotator-adder, .annotator-outer, .annotator-notice {"," z-index: "+(max+20)+";","}",".annotator-filter {"," z-index: "+(max+10)+";","}"].join("\n");util.$("").attr("id","annotator-dynamic-style").attr("type","text/css").appendTo("head")}function removeDynamicStyle(){util.$("#annotator-dynamic-style").remove()}function addPermissionsCheckboxes(editor,ident,authz){function createLoadCallback(action){return function loadCallback(field,annotation){field=util.$(field).show();var u=ident.who();var input=field.find("input");if(typeof u==="undefined"||u===null){field.hide()}if(!authz.permits("admin",annotation,u)){field.hide()}if(authz.permits(action,annotation,null)){input.attr("checked","checked")}else{input.removeAttr("checked")}}}function createSubmitCallback(action){return function submitCallback(field,annotation){var u=ident.who();if(typeof u==="undefined"||u===null){return}if(!annotation.permissions){annotation.permissions={}}if(util.$(field).find("input").is(":checked")){delete annotation.permissions[action]}else{annotation.permissions[action]=[authz.authorizedUserId(u)]}}}editor.addField({type:"checkbox",label:_t("Allow anyone to view this annotation"),load:createLoadCallback("read"),submit:createSubmitCallback("read")});editor.addField({type:"checkbox",label:_t("Allow anyone to edit this annotation"),load:createLoadCallback("update"),submit:createSubmitCallback("update")})}function main(options){if(typeof options==="undefined"||options===null){options={}}options.element=options.element||global.document.body;options.editorExtensions=options.editorExtensions||[];options.viewerExtensions=options.viewerExtensions||[];var makeAnnotation=annotationFactory(options.element,".annotator-hl");var s={interactionPoint:null};function start(app){var ident=app.registry.getUtility("identityPolicy");var authz=app.registry.getUtility("authorizationPolicy");s.adder=new adder.Adder({onCreate:function(ann){app.annotations.create(ann)}});s.adder.attach();s.editor=new editor.Editor({extensions:options.editorExtensions});s.editor.attach();addPermissionsCheckboxes(s.editor,ident,authz);s.highlighter=new highlighter.Highlighter(options.element);s.textselector=new textselector.TextSelector(options.element,{onSelection:function(ranges,event){if(ranges.length>0){var annotation=makeAnnotation(ranges);s.interactionPoint=util.mousePosition(event);s.adder.load(annotation,s.interactionPoint)}else{s.adder.hide()}}});s.viewer=new viewer.Viewer({onEdit:function(ann){s.interactionPoint=util.$(s.viewer.element).css(["top","left"]);app.annotations.update(ann)},onDelete:function(ann){app.annotations["delete"](ann)},permitEdit:function(ann){return authz.permits("update",ann,ident.who())},permitDelete:function(ann){return authz.permits("delete",ann,ident.who())},autoViewHighlights:options.element,extensions:options.viewerExtensions});s.viewer.attach();injectDynamicStyle()}return{start:start,destroy:function(){s.adder.destroy();s.editor.destroy();s.highlighter.destroy();s.textselector.destroy();s.viewer.destroy();removeDynamicStyle()},annotationsLoaded:function(anns){s.highlighter.drawAll(anns)},annotationCreated:function(ann){s.highlighter.draw(ann)},annotationDeleted:function(ann){s.highlighter.undraw(ann)},annotationUpdated:function(ann){s.highlighter.redraw(ann)},beforeAnnotationCreated:function(annotation){return s.editor.load(annotation,s.interactionPoint)},beforeAnnotationUpdated:function(annotation){return s.editor.load(annotation,s.interactionPoint)}}}exports.main=main}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"../util":39,"./adder":29,"./editor":30,"./highlighter":32,"./textselector":36,"./viewer":37}],34:[function(require,module,exports){(function(global){"use strict";var util=require("../util");var _t=util.gettext;var render=exports.render=function render(annotation){var convert=util.escapeHtml;if(global.showdown&&typeof global.showdown.Converter==="function"){convert=(new global.showdown.Converter).makeHtml}if(annotation.text){return convert(annotation.text)}else{return""+_t("No comment")+""}};exports.viewerExtension=function viewerExtension(viewer){if(!global.showdown||typeof global.showdown.Converter!=="function"){console.warn(_t("To use the Markdown plugin, you must "+"include Showdown into the page first."))}viewer.setRenderer(render)}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"../util":39}],35:[function(require,module,exports){"use strict";var util=require("../util");var $=util.$;var _t=util.gettext;function stringifyTags(array){return array.join(" ")}function parseTags(string){string=$.trim(string);var tags=[];if(string){tags=string.split(/\s+/)}return tags}exports.viewerExtension=function viewerExtension(v){function updateViewer(field,annotation){field=$(field);if(annotation.tags&&$.isArray(annotation.tags)&&annotation.tags.length){field.addClass("annotator-tags").html(function(){return $.map(annotation.tags,function(tag){return''+util.escapeHtml(tag)+""}).join(" ")})}else{field.remove()}}v.addField({load:updateViewer})};exports.editorExtension=function editorExtension(e){var field=null;var input=null;function updateField(field,annotation){var value="";if(annotation.tags){value=stringifyTags(annotation.tags)}input.val(value)}function setAnnotationTags(field,annotation){annotation.tags=parseTags(input.val())}field=e.addField({label:_t("Add some tags here")+"…",load:updateField,submit:setAnnotationTags});input=$(field).find(":input")}},{"../util":39}],36:[function(require,module,exports){(function(global){"use strict";var Range=require("xpath-range").Range;var util=require("../util");var $=util.$;var TEXTSELECTOR_NS="annotator-textselector";function isAnnotator(element){var elAndParents=$(element).parents().addBack();return elAndParents.filter("[class^=annotator-]").length!==0}function TextSelector(element,options){this.element=element;this.options=$.extend(true,{},TextSelector.options,options);this.onSelection=this.options.onSelection;if(typeof this.element.ownerDocument!=="undefined"&&this.element.ownerDocument!==null){var self=this;this.document=this.element.ownerDocument;$(this.document.body).on("mouseup."+TEXTSELECTOR_NS,function(e){self._checkForEndSelection(e)})}else{console.warn("You created an instance of the TextSelector on an "+"element that doesn't have an ownerDocument. This won't "+"work! Please ensure the element is added to the DOM "+"before the plugin is configured:",this.element)}}TextSelector.prototype.destroy=function(){if(this.document){$(this.document.body).off("."+TEXTSELECTOR_NS)}};TextSelector.prototype.captureDocumentSelection=function(){var i,len,ranges=[],rangesToIgnore=[],selection=global.getSelection();if(selection.isCollapsed){return[]}for(i=0;i"+_t("No comment")+""}};var self=this;if(this.options.defaultFields){this.addField({load:function(field,annotation){$(field).html(self.render(annotation))}})}if(typeof this.options.onEdit!=="function"){throw new TypeError("onEdit callback must be a function")}if(typeof this.options.onDelete!=="function"){throw new TypeError("onDelete callback must be a function")}if(typeof this.options.permitEdit!=="function"){throw new TypeError("permitEdit callback must be a function")}if(typeof this.options.permitDelete!=="function"){throw new TypeError("permitDelete callback must be a function")}if(this.options.autoViewHighlights){this.document=this.options.autoViewHighlights.ownerDocument;$(this.options.autoViewHighlights).on("mouseover."+NS,".annotator-hl",function(event){if(event.target===this){self._onHighlightMouseover(event)}}).on("mouseleave."+NS,".annotator-hl",function(){self._startHideTimer()});$(this.document.body).on("mousedown."+NS,function(e){if(e.which===1){self.mouseDown=true}}).on("mouseup."+NS,function(e){if(e.which===1){self.mouseDown=false}})}this.element.on("click."+NS,".annotator-edit",function(e){self._onEditClick(e)}).on("click."+NS,".annotator-delete",function(e){self._onDeleteClick(e)}).on("mouseenter."+NS,function(){self._clearHideTimer()}).on("mouseleave."+NS,function(){self._startHideTimer()})},destroy:function(){if(this.options.autoViewHighlights){$(this.options.autoViewHighlights).off("."+NS);$(this.document.body).off("."+NS)}this.element.off("."+NS);Widget.prototype.destroy.call(this)},show:function(position){if(typeof position!=="undefined"&&position!==null){this.element.css({top:position.top,left:position.left})}var controls=this.element.find(".annotator-controls").addClass(this.classes.showControls);var self=this;setTimeout(function(){controls.removeClass(self.classes.showControls)},500);Widget.prototype.show.call(this)},load:function(annotations,position){this.annotations=annotations||[];var list=this.element.find("ul:first").empty();for(var i=0,len=this.annotations.length;i0&&typeof links[0].href!=="undefined"&&links[0].href!==null;if(hasValidLink){link.attr("href",links[0].href)}else{link.remove()}var controller={};if(this.options.permitEdit(annotation)){controller.showEdit=function(){edit.removeAttr("disabled")};controller.hideEdit=function(){edit.attr("disabled","disabled")}}else{edit.remove()}if(this.options.permitDelete(annotation)){controller.showDelete=function(){del.removeAttr("disabled")};controller.hideDelete=function(){del.attr("disabled","disabled")}}else{del.remove()}for(var i=0,len=this.fields.length;i")[0];this.fields.push(field);return this},_onEditClick:function(event){var item=$(event.target).parents(".annotator-annotation").data("annotation");this.hide();this.options.onEdit(item)},_onDeleteClick:function(event){var item=$(event.target).parents(".annotator-annotation").data("annotation");this.hide();this.options.onDelete(item)},_onHighlightMouseover:function(event){if(this.mouseDown){return}var self=this;this._startHideTimer(true).done(function(){var annotations=$(event.target).parents(".annotator-hl").addBack().map(function(_,elem){return $(elem).data("annotation")}).toArray();self.load(annotations,util.mousePosition(event))})},_startHideTimer:function(activity){if(typeof activity==="undefined"||activity===null){activity=false}if(this.hideTimer){if(activity===false||this.hideTimerActivity===activity){return this.hideTimerDfd}else{this._clearHideTimer()}}var timeout;if(activity){timeout=this.options.activityDelay}else{timeout=this.options.inactivityDelay}this.hideTimerDfd=$.Deferred();if(!this.isShown()){this.hideTimer=null;this.hideTimerDfd.resolve();this.hideTimerActivity=null}else{var self=this;this.hideTimer=setTimeout(function(){self.hide();self.hideTimerDfd.resolve();self.hideTimer=null},timeout);this.hideTimerActivity=Boolean(activity)}return this.hideTimerDfd.promise()},_clearHideTimer:function(){clearTimeout(this.hideTimer);this.hideTimer=null;this.hideTimerDfd.reject();this.hideTimerActivity=null}});Viewer.classes={showControls:"annotator-visible"};Viewer.template=['