on-demand release 4.0dev+
[moodle.git] / mod / assign / feedback / editpdf / yui / build / moodle-assignfeedback_editpdf-editor / moodle-assignfeedback_editpdf-editor-min.js
1 YUI.add("moodle-assignfeedback_editpdf-editor",function(u,t){var e,i,s,n,a,o,r,d,c,h,l,g,p,f,_,m,b,w,k,y,v,x,A,S,N=M.cfg.wwwroot+"/mod/assign/feedback/editpdf/ajax.php",D=M.cfg.wwwroot+"/mod/assign/feedback/editpdf/ajax_progress.php",T="assignfeedback_editpdf_widget",I=".navigate-previous-button",C=" .navigate-next-button",q=".searchcommentsbutton",z=".expcolcommentsbutton",E=".assignfeedback_editpdf_commentsearch input",Y=".assignfeedback_editpdf_commentsearch ul",R=".navigate-page-select",X=".loading",L=".progress-info.progress-striped",P=".drawingregion",j=".drawingcanvas",O=".commentcolourbutton",B=".annotationcolourbutton",H=".warningmessages",J=".infoicon",F='input[name="assignfeedback_editpdf_haschanges"]',V=".currentstampbutton",G='[data-region="user-info"]',K=".rotateleftbutton",W=".rotaterightbutton",U="rgba(200, 200, 255, 0.9)",$="rgba(200, 200, 255, 0.5)",Q="rgb(51, 51, 51)",Z={white:"rgb(255,255,255)",yellow:"rgb(255,236,174)",red:"rgb(249,181,179)",green:"rgb(214,234,178)",blue:"rgb(203,217,237)",clear:"rgba(255,255,255, 0)"},tt={white:"rgb(255,255,255)",yellow:"rgb(255,207,53)",red:"rgb(239,69,64)",green:"rgb(152,202,62)",blue:"rgb(125,159,211)",black:"rgb(51,51,51)"},et=300,it={comment:".commentbutton",pen:".penbutton",line:".linebutton",rectangle:".rectanglebutton",oval:".ovalbutton",stamp:".stampbutton",select:".selectbutton",drag:".dragbutton",highlight:".highlightbutton"},st=4,nt=function(t,e){this.x=parseInt(t,10),this.y=parseInt(e,10),this.clip=function(t){return this.x<t.x&&(this.x=t.x),this.x>t.x+t.width&&(this.x=t.x+t.width),this.y<t.y&&(this.y=t.y),this.y>t.y+t.height&&(this.y=t.y+t.height),this}};M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.point=nt,e=function(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s,this.bound=function(t){var e,i=0,s=0,n=0,a=0,o=0;for(o=0;o<t.length;o++)((e=t[o]).x<i||0===o)&&(i=e.x),(e.x>s||0===o)&&(s=e.x),(e.y<n||0===o)&&(n=e.y),(e.y>a||0===o)&&(a=e.y);return this.x=i,this.y=n,this.width=s-i,this.height=a-n,this},this.has_min_width=function(){return 5<=this.width},this.has_min_height=function(){return 5<=this.height},this.set_min_width=function(){this.width=5},this.set_min_height=function(){this.height=5}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.rect=e,i=function(){this.start=!1,this.end=!1,this.starttime=0,this.annotationstart=!1,this.tool="drag",this.commentcolour="yellow",this.annotationcolour="red",this.stamp="",this.path=[]},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.edit=i,s=function(t){this.editor=t,this.shapes=[],this.nodes=[],this.erase=function(){if(this.shapes)for(;0<this.shapes.length;)this.editor.graphic.removeShape(this.shapes.pop());if(this.nodes)for(;0<this.nodes.length;)this.nodes.pop().remove()},this.scroll_update=function(t,e){var i,s,n;for(i=0;i<this.nodes.length;i++)s=this.nodes[i].getData("x"),n=this.nodes[i].getData("y"),s!==undefined&&n!==undefined&&(this.nodes[i].setX(parseInt(s,10)-t),this.nodes[i].setY(parseInt(n,10)-e))},this.store_position=function(t,e,i){var s,n,a;s=this.editor.get_dialogue_element(P),n=parseInt(s.get("scrollLeft"),10),a=parseInt(s.get("scrollTop"),10),t.setData("x",e+n),t.setData("y",i+a)}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.drawable=s,(n=function(t){n.superclass.constructor.apply(this,[t])}).NAME="annotation",n.ATTRS={},u.extend(n,u.Base,{editor:null,gradeid:0,pageno:0,x:0,y:0,endx:0,endy:0,path:"",type:"rect",colour:"red",drawable:!1,initializer:function(t){this.editor=t.editor||null,this.gradeid=parseInt(t.gradeid,10)||0,this.pageno=parseInt(t.pageno,10)||0,this.x=parseInt(t.x,10)||0,this.y=parseInt(t.y,10)||0,this.endx=parseInt(t.endx,10)||0,this.endy=parseInt(t.endy,10)||0,this.path=t.path||"",this.type=t.type||"rect",this.colour=t.colour||"red",this.drawable=!1},clean:function(){return{gradeid:this.gradeid,x:parseInt(this.x,10),y:parseInt(this.y,10),endx:parseInt(this.endx,10),endy:parseInt(this.endy,10),type:this.type,path:this.path,pageno:this.pageno,colour:this.colour}},draw_highlight:function(){var t,e,i,s,n=this.editor.get_dialogue_element(P),a=this.editor.get_dialogue_element(j).getXY();return this.editor.currentannotation===this&&((t=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(this.x,this.y),new M.assignfeedback_editpdf.point(this.endx,this.endy)]),e=this.editor.graphic.addShape({type:u.Rect,width:t.width,height:t.height,stroke:{weight:st,color:U},fill:{color:$},x:t.x,y:t.y}),this.drawable.shapes.push(e),i=u.Node.create('<img src="'+M.util.image_url("trash","assignfeedback_editpdf")+'"/>'),s=u.Node.create('<a href="#" role="button"></a>'),i.setAttrs({alt:M.util.get_string("deleteannotation","assignfeedback_editpdf")}),i.setStyles({backgroundColor:"white"}),s.addClass("deleteannotationbutton"),s.append(i),n.append(s),s.setData("annotation",this),s.on("click",this.remove,this),s.on("key",this.remove,"space,enter",this),s.setX(a[0]+t.x+t.width-18),s.setY(a[1]+t.y+6),this.drawable.nodes.push(s)),this.drawable},draw:function(){return this.draw_highlight(),this.drawable},remove:function(t){var e,i;for(t.preventDefault(),e=this.editor.pages[this.editor.currentpage].annotations,i=0;i<e.length;i++)if(e[i]===this)return e.splice(i,1),this.drawable&&this.drawable.erase(),this.editor.currentannotation=!1,void this.editor.save_current_page()},move:function(t,e){var i,s,n,a,o,r=t-this.x,d=e-this.y;this.x+=r,this.y+=d,this.endx+=r,this.endy+=d,this.path&&(i=[],s=this.path.split(":"),u.each(s,function(t){n=t.split(","),a=parseInt(n[0],10),o=parseInt(n[1],10),i.push(a+r+","+(o+d))}),this.path=i.join(":")),this.drawable&&this.drawable.erase(),this.editor.drawables.push(this.draw())},draw_current_edit:function(t){return t&&!1},init_from_edit:function(t){var e=new M.assignfeedback_editpdf.rect;return e.bound([t.start,t.end]),this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,
2 this.x=e.x,this.y=e.y,this.endx=e.x+e.width,this.endy=e.y+e.height,this.colour=t.annotationcolour,this.path="",e.has_min_width()&&e.has_min_height()}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotation=n,(a=function(t){a.superclass.constructor.apply(this,[t])}).NAME="annotationline",a.ATTRS={},u.extend(a,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e;return t=new M.assignfeedback_editpdf.drawable(this.editor),(e=this.editor.graphic.addShape({type:u.Path,fill:!1,stroke:{weight:st,color:tt[this.colour]}})).moveTo(this.x,this.y),e.lineTo(this.endx,this.endy),e.end(),t.shapes.push(e),this.drawable=t,a.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i=new M.assignfeedback_editpdf.drawable(this.editor);return(e=this.editor.graphic.addShape({type:u.Path,fill:!1,stroke:{weight:st,color:tt[t.annotationcolour]}})).moveTo(t.start.x,t.start.y),e.lineTo(t.end.x,t.end.y),e.end(),i.shapes.push(e),i},init_from_edit:function(t){return this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=t.start.x,this.y=t.start.y,this.endx=t.end.x,this.endy=t.end.y,this.colour=t.annotationcolour,this.path="",!(this.endx-this.x==0&&this.endy-this.y==0)}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationline=a,(o=function(t){o.superclass.constructor.apply(this,[t])}).NAME="annotationrectangle",o.ATTRS={},u.extend(o,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e,i;return t=new M.assignfeedback_editpdf.drawable(this.editor),(e=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(this.x,this.y),new M.assignfeedback_editpdf.point(this.endx,this.endy)]),i=this.editor.graphic.addShape({type:u.Rect,width:e.width,height:e.height,stroke:{weight:st,color:tt[this.colour]},x:e.x,y:e.y}),t.shapes.push(i),this.drawable=t,o.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i,s=new M.assignfeedback_editpdf.drawable(this.editor);return(i=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(t.start.x,t.start.y),new M.assignfeedback_editpdf.point(t.end.x,t.end.y)]),i.has_min_width()||i.set_min_width(),i.has_min_height()||i.set_min_height(),e=this.editor.graphic.addShape({type:u.Rect,width:i.width,height:i.height,stroke:{weight:st,color:tt[t.annotationcolour]},x:i.x,y:i.y}),s.shapes.push(e),s}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationrectangle=o,(r=function(t){r.superclass.constructor.apply(this,[t])}).NAME="annotationoval",r.ATTRS={},u.extend(r,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e,i;return t=new M.assignfeedback_editpdf.drawable(this.editor),(e=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(this.x,this.y),new M.assignfeedback_editpdf.point(this.endx,this.endy)]),i=this.editor.graphic.addShape({type:u.Ellipse,width:e.width,height:e.height,stroke:{weight:st,color:tt[this.colour]},x:e.x,y:e.y}),t.shapes.push(i),this.drawable=t,r.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i,s=new M.assignfeedback_editpdf.drawable(this.editor);return(i=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(t.start.x,t.start.y),new M.assignfeedback_editpdf.point(t.end.x,t.end.y)]),i.has_min_width()||i.set_min_width(),i.has_min_height()||i.set_min_height(),e=this.editor.graphic.addShape({type:u.Ellipse,width:i.width,height:i.height,stroke:{weight:st,color:tt[t.annotationcolour]},x:i.x,y:i.y}),s.shapes.push(e),s}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationoval=r,(d=function(t){d.superclass.constructor.apply(this,[t])}).NAME="annotationpen",d.ATTRS={},u.extend(d,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e,i,s,n;return t=new M.assignfeedback_editpdf.drawable(this.editor),e=this.editor.graphic.addShape({type:u.Path,fill:!1,stroke:{weight:st,color:tt[this.colour]}}),i=!0,s=this.path.split(":"),u.each(s,function(t){n=t.split(","),i?(e.moveTo(n[0],n[1]),i=!1):e.lineTo(n[0],n[1])},this),e.end(),t.shapes.push(e),this.drawable=t,d.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i,s=new M.assignfeedback_editpdf.drawable(this.editor);return e=this.editor.graphic.addShape({type:u.Path,fill:!1,stroke:{weight:st,color:tt[t.annotationcolour]}}),i=!0,u.each(t.path,function(t){i?(e.moveTo(t.x,t.y),i=!1):e.lineTo(t.x,t.y)},this),e.end(),s.shapes.push(e),s},init_from_edit:function(t){var e=new M.assignfeedback_editpdf.rect,i=[],s=0;for(e.bound(t.path),s=0;s<t.path.length;s++)i.push(parseInt(t.path[s].x,10)+","+parseInt(t.path[s].y,10));return this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=e.x,this.y=e.y,this.endx=e.x+e.width,this.endy=e.y+e.height,this.colour=t.annotationcolour,this.path=i.join(":"),e.has_min_width()||e.has_min_height()}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationpen=d,(c=function(t){c.superclass.constructor.apply(this,[t])}).NAME="annotationhighlight",c.ATTRS={},u.extend(c,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e,i,s;return t=new M.assignfeedback_editpdf.drawable(this.editor),(i=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(this.x,this.y),new M.assignfeedback_editpdf.point(this.endx,this.endy)]),s=(s=(s=tt[this.colour]).replace("rgb","rgba")).replace(")",",0.5)"),e=this.editor.graphic.addShape({type:u.Rect,width:i.width,height:i.height,stroke:!1,fill:{color:s},x:i.x,y:i.y}),t.shapes.push(e),this.drawable=t,c.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i,s,n=new M.assignfeedback_editpdf.drawable(this.editor);return(i=new M.assignfeedback_editpdf.rect).bound([new M.assignfeedback_editpdf.point(t.start.x,t.start.y),new M.assignfeedback_editpdf.point(t.end.x,t.end.y)]),i.has_min_width()||i.set_min_width(),s=(s=(s=tt[t.annotationcolour]).replace("rgb","rgba")).replace(")",
3 ",0.5)"),e=this.editor.graphic.addShape({type:u.Rect,width:i.width,height:20,stroke:!1,fill:{color:s},x:i.x,y:t.start.y-10}),n.shapes.push(e),n},init_from_edit:function(t){var e=new M.assignfeedback_editpdf.rect;return e.bound([t.start,t.end]),this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=e.x,this.y=t.start.y-10,this.endx=e.x+e.width,this.endy=t.start.y+10,this.colour=t.annotationcolour,this.page="",e.has_min_width()}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationhighlight=c,(h=function(t){h.superclass.constructor.apply(this,[t])}).NAME="annotationstamp",h.ATTRS={},u.extend(h,M.assignfeedback_editpdf.annotation,{draw:function(){var t,e,i=new M.assignfeedback_editpdf.drawable(this.editor),s=this.editor.get_dialogue_element(j);return e=this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(this.x,this.y)),(t=u.Node.create("<div/>")).addClass("annotation"),t.addClass("stamp"),t.setStyles({position:"absolute",display:"inline-block",backgroundImage:"url("+this.editor.get_stamp_image_url(this.path)+")",width:this.endx-this.x,height:this.endy-this.y,backgroundSize:"100% 100%"}),s.append(t),t.setX(e.x),t.setY(e.y),i.store_position(t,e.x,e.y),this.editor.get("readonly")||(t.on("gesturemovestart",this.editor.edit_start,null,this.editor),t.on("gesturemove",this.editor.edit_move,null,this.editor),t.on("gesturemoveend",this.editor.edit_end,null,this.editor)),i.nodes.push(t),this.drawable=i,h.superclass.draw.apply(this)},draw_current_edit:function(t){var e,i,s=new M.assignfeedback_editpdf.rect,n=new M.assignfeedback_editpdf.drawable(this.editor),a=this.editor.get_dialogue_element(P);return s.bound([t.start,t.end]),i=this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(s.x,s.y)),(e=u.Node.create("<div/>")).addClass("annotation"),e.addClass("stamp"),e.setStyles({position:"absolute",display:"inline-block",backgroundImage:"url("+this.editor.get_stamp_image_url(t.stamp)+")",width:s.width,height:s.height,backgroundSize:"100% 100%"}),a.append(e),e.setX(i.x),e.setY(i.y),n.store_position(e,i.x,i.y),n.nodes.push(e),n},init_from_edit:function(t){var e=new M.assignfeedback_editpdf.rect;return e.bound([t.start,t.end]),e.width<40&&(e.width=40),e.height<40&&(e.height=40),this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=e.x,this.y=e.y,this.endx=e.x+e.width,this.endy=e.y+e.height,this.colour=t.annotationcolour,this.path=t.stamp,!0},move:function(t,e){var i=t-this.x,s=e-this.y;this.x+=i,this.y+=s,this.endx+=i,this.endy+=s,this.drawable&&this.drawable.erase(),this.editor.drawables.push(this.draw())}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationstamp=h,l="Dropdown menu",g=function(t){t.draggable=!1,t.centered=!1,t.width="auto",t.visible=!1,t.footerContent="",g.superclass.constructor.apply(this,[t])},u.extend(g,M.core.dialogue,{initializer:function(t){var e,i,s;g.superclass.initializer.call(this,t),this.get("boundingBox").addClass("assignfeedback_editpdf_dropdown"),e=this.get("buttonNode"),i=this.bodyNode,(s=u.Node.create("<h3/>")).addClass("accesshide"),s.setHTML(this.get("headerText")),i.prepend(s),i.on("clickoutside",function(t){this.get("visible")&&t.target.get("id")!==e.get("id")&&t.target.ancestor().get("id")!==e.get("id")&&(t.preventDefault(),this.hide())},this),e.on("click",function(t){t.preventDefault(),this.show()},this),e.on("key",this.show,"enter,space",this)},show:function(){var t=this.get("buttonNode"),e=g.superclass.show.call(this);return this.align(t,[u.WidgetPositionAlign.TL,u.WidgetPositionAlign.BL]),e}},{NAME:l,ATTRS:{headerText:{value:""},buttonNode:{value:null}}}),u.Base.modifyAttrs(g,{modal:{getter:function(){return!1}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.dropdown=g,p="Colourpicker",f=function(t){f.superclass.constructor.apply(this,[t])},u.extend(f,M.assignfeedback_editpdf.dropdown,{initializer:function(t){var e,r=u.Node.create('<ul role="menu" class="assignfeedback_editpdf_menu"/>');u.each(this.get("colours"),function(t,e){var i,s,n,a,o;n=M.util.get_string(e,"assignfeedback_editpdf"),o=this.get("iconprefix")+e,a=M.util.image_url(o,"assignfeedback_editpdf"),(i=u.Node.create('<button><img alt="'+n+'" src="'+a+'"/></button>')).setAttribute("data-colour",e),i.setAttribute("data-rgb",t),i.setAttribute("role","menuitem"),i.setStyle("backgroundImage","none"),(s=u.Node.create("<li/>")).append(i),s.setAttribute("role","none"),r.append(s)},this),e=u.Node.create("<div/>"),r.delegate("click",this.callback_handler,"button",this),r.delegate("key",this.callback_handler,"down:13","button",this),this.set("headerText",M.util.get_string("colourpicker","assignfeedback_editpdf")),e.append(r),this.set("bodyContent",e),f.superclass.initializer.call(this,t)},callback_handler:function(t){t.preventDefault();var e=this.get("callback"),i=this.get("context");this.hide(),u.bind(e,i,t)()}},{NAME:p,ATTRS:{colours:{value:{}},callback:{value:null},context:{value:null},iconprefix:{value:"colour_"}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.colourpicker=f,_="Colourpicker",m=function(t){m.superclass.constructor.apply(this,[t])},u.extend(m,M.assignfeedback_editpdf.dropdown,{initializer:function(t){var n=u.Node.create('<ul role="menu" class="assignfeedback_editpdf_menu"/>');u.each(this.get("stamps"),function(t){var e,i,s;s=M.util.get_string("stamp","assignfeedback_editpdf"),(e=u.Node.create('<button><img height="16" width="16" alt="'+s+'" src="'+t+'"/></button>')).setAttribute("data-stamp",t),e.setAttribute("role","menuitem"),e.setStyle("backgroundImage","none"),(i=u.Node.create("<li/>")).append(e),i.setAttribute("role","none"),n.append(i)},this),n.delegate("click",this.callback_handler,"button",this),n.delegate("key",this.callback_handler,"down:13","button",this),this.set("headerText",M.util.get_string("stamppicker","assignfeedback_editpdf")),this.set(
4 "bodyContent",n),m.superclass.initializer.call(this,t)},callback_handler:function(t){t.preventDefault();var e=this.get("callback"),i=this.get("context");this.hide(),u.bind(e,i,t)()}},{NAME:_,ATTRS:{stamps:{value:[]},callback:{value:null},context:{value:null}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.stamppicker=m,b="Commentmenu",w=function(t){w.superclass.constructor.apply(this,[t])},u.extend(w,M.assignfeedback_editpdf.dropdown,{initializer:function(t){var e,i,s,n;n=this.get("comment"),e=u.Node.create('<ul role="menu" class="assignfeedback_editpdf_menu"/>'),(i=u.Node.create('<li><a tabindex="-1" href="#">'+M.util.get_string("addtoquicklist","assignfeedback_editpdf")+"</a></li>")).on("click",n.add_to_quicklist,n),i.on("key",n.add_to_quicklist,"enter,space",n),e.append(i),(i=u.Node.create('<li><a tabindex="-1" href="#">'+M.util.get_string("deletecomment","assignfeedback_editpdf")+"</a></li>")).on("click",function(t){t.preventDefault(),this.menu.hide(),this.remove()},n),i.on("key",function(){n.menu.hide(),n.remove()},"enter,space",n),e.append(i),i=u.Node.create("<li><hr/></li>"),e.append(i),this.set("headerText",M.util.get_string("commentcontextmenu","assignfeedback_editpdf")),(s=u.Node.create("<div/>")).append(e),this.set("bodyContent",s),w.superclass.initializer.call(this,t)},show:function(){var n,a=this.get("boundingBox").one("ul");a.all(".quicklist_comment").remove(!0),(n=this.get("comment")).deleteme=!1,u.each(n.editor.quicklist.comments,function(t){var e=u.Node.create('<li class="quicklist_comment"></li>'),i=u.Node.create('<a href="#" tabindex="-1">'+t.rawtext+"</a>"),s=u.Node.create('<a href="#" tabindex="-1" class="delete_quicklist_comment"><img src="'+M.util.image_url("t/delete","core")+'" alt="'+M.util.get_string("deletecomment","assignfeedback_editpdf")+'"/></a>');i.setAttribute("title",t.rawtext),e.append(i),e.append(s),a.append(e),e.on("click",n.set_from_quick_comment,n,t),e.on("key",n.set_from_quick_comment,"space,enter",n,t),s.on("click",n.remove_from_quicklist,n,t),s.on("key",n.remove_from_quicklist,"space,enter",n,t)},this),w.superclass.show.call(this)}},{NAME:b,ATTRS:{comment:{value:null}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.commentmenu=w,k="commentsearch",y=function(t){t.draggable=!1,t.centered=!0,t.width="400px",t.visible=!1,t.headerContent=M.util.get_string("searchcomments","assignfeedback_editpdf"),t.footerContent="",y.superclass.constructor.apply(this,[t])},u.extend(y,M.core.dialogue,{initializer:function(t){var e,i,s,n;this.get("boundingBox").addClass("assignfeedback_editpdf_commentsearch"),this.get("editor"),e=u.Node.create("<div/>"),i=M.util.get_string("filter","assignfeedback_editpdf"),s=u.Node.create('<input type="text" size="20" placeholder="'+i+'"/>'),e.append(s),n=u.Node.create('<ul role="menu" class="assignfeedback_editpdf_search"/>'),e.append(n),s.on("keyup",this.filter_search_comments,this),n.delegate("click",this.focus_on_comment,"a",this),n.delegate("key",this.focus_on_comment,"enter,space","a",this),this.set("bodyContent",e),y.superclass.initializer.call(this,t)},filter_search_comments:function(){var t,e,i,s;s=this.get("id"),t=u.one("#"+s+E),e=u.one("#"+s+Y),i=t.get("value"),e.all("li").each(function(t){-1!==t.get("text").indexOf(i)?t.show():t.hide()})},focus_on_comment:function(t){t.preventDefault();var e=t.target.ancestor("li").getData("comment"),i=this.get("editor");this.hide(),e.pageno=e.clean().pageno,e.pageno!==i.currentpage&&(i.currentpage=e.pageno,i.change_page()),e.node=e.drawable.nodes[0].one("textarea"),e.node.ancestor("div").removeClass("commentcollapsed"),e.node.focus()},show:function(){var i=this.get("boundingBox").one("ul"),t=this.get("editor");i.all("li").remove(!0),u.each(t.pages,function(t){u.each(t.comments,function(t){var e=u.Node.create('<li><a href="#" tabindex="-1"><pre>'+t.rawtext+"</pre></a></li>");i.append(e),e.setData("comment",t)},this)},this),this.centerDialogue(),y.superclass.show.call(this)}},{NAME:k,ATTRS:{editor:{value:null}}}),u.Base.modifyAttrs(y,{modal:{getter:function(){return!0}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.commentsearch=y,v=function(h,t,e,i,s,n,a,o){this.editor=h,this.gradeid=t||0,this.x=parseInt(i,10)||0,this.y=parseInt(s,10)||0,this.width=parseInt(n,10)||0,this.rawtext=o||"",this.pageno=e||0,this.colour=a||"yellow",this.drawable=!1,this.deleteme=!1,this.menulink=null,this.menu=null,this.clean=function(){return{gradeid:this.gradeid,x:parseInt(this.x,10),y:parseInt(this.y,10),width:parseInt(this.width,10),rawtext:this.rawtext,pageno:parseInt(this.pageno,10),colour:this.colour}},this.draw=function(t){var e,i,s,n,a,o,r,d=new M.assignfeedback_editpdf.drawable(this.editor),c=this.editor.get_dialogue_element(j);return e=u.Node.create("<textarea/>"),i=u.Node.create('<div class="commentdrawable"/>'),s=u.Node.create("<label/>"),n=u.Node.create('<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.5 -0.5 13 13" preserveAspectRatio="xMinYMin meet"><path d="M11 0H1C.4 0 0 .4 0 1v6c0 .6.4 1 1 1h1v4l4-4h5c.6 0 1-.4 1-1V1c0-.6-.4-1-1-1z" fill="currentColor" opacity="0.9" stroke="rgb(153, 153, 153)" stroke-width="0.5"/></svg>'),a=u.Node.create('<a href="#"><img src="'+M.util.image_url("t/contextmenu","core")+'"/></a>'),this.menulink=a,i.append(s),s.append(e),i.append(n),i.setAttribute("tabindex","-1"),s.setAttribute("tabindex","0"),e.setAttribute("tabindex","-1"),a.setAttribute("tabindex","0"),this.editor.get("readonly")?e.setAttribute("readonly","readonly"):i.append(a),this.width<100&&(this.width=100),o=this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(this.x,this.y)),e.setStyles({width:this.width+"px",backgroundColor:Z[this.colour],color:Q}),c.append(i),i.setStyle("position","absolute"),i.setX(o.x),i.setY(o.y),d.store_position(i,o.x,o.y),d.nodes.push(i),e.set("value",this.rawtext),r=e.get("scrollHeight"),e.setStyles({height:r+"px",overflow:"hidden"}),n.setStyle("color",
5 Z[this.colour]),this.attach_events(e,a),t?e.focus():h.collapsecomments&&i.addClass("commentcollapsed"),this.drawable=d},this.delete_comment_later=function(){this.deleteme&&!this.is_menu_active()&&this.remove()},this.is_menu_active=function(){return this.menu.get("visible")},this.attach_events=function(o,e){var r=o.ancestor("div"),t=o.ancestor("label"),i=t.next("svg");o.collapse=function(t){o.collapse.delay=u.later(t,o,function(){h.collapsecomments&&!this.is_menu_active()&&r.addClass("commentcollapsed")}.bind(this))}.bind(this),o.expand=function(){!0!==o.getData("dragging")&&(o.collapse.delay&&o.collapse.delay.cancel(),r.removeClass("commentcollapsed"))},r.on("mouseenter",function(){"comment"!==h.currentedit.tool&&"select"!==h.currentedit.tool&&!this.editor.get("readonly")||o.expand()},this),r.on("click|tap",function(){o.expand(),o.focus()},this),o.on("keyup",function(t){9===t.keyCode&&t.shiftKey&&"0"===e.getAttribute("tabindex")&&e.focus(),e.setAttribute("tabindex","0")},this),e.on("keydown",function(t){9===t.keyCode&&t.shiftKey&&e.setAttribute("tabindex","-1")},this),t.on("focus",function(){o.active=!0,o.collapse.delay&&o.collapse.delay.cancel(),o.setAttribute("tabindex","0"),o.expand(),o.focus(),t.setAttribute("tabindex","-1")},this),e.on("focus",function(){o.active=!0,o.collapse.delay&&o.collapse.delay.cancel(),this.deleteme=!1,t.setAttribute("tabindex","0")},this),o.on("blur",function(){o.setAttribute("tabindex","-1")},this),t.on("blur",function(){t.setAttribute("tabindex","0")},this),r.on("mouseleave",function(){h.collapsecomments&&!0!==o.active&&o.collapse(400)},this),r.on("blur",function(){o.active=!1,o.collapse(800)},this),this.editor.get("readonly")||(o.on("blur",function(){this.rawtext=o.get("value"),this.width=parseInt(o.getStyle("width"),10),""===this.rawtext.replace(/^\s+|\s+$/g,"")&&(this.deleteme=!0,u.later(400,this,this.delete_comment_later)),this.editor.save_current_page(),this.editor.editingcomment=!1},this),e.setData("comment",this),o.on("keyup",function(){o.setStyle("height","auto");var t=o.get("scrollHeight");t===parseInt(o.getStyle("height"),10)+8&&(t-=8),o.setStyle("height",t+"px")}),o.on("gesturemovestart",function(t){"select"===h.currentedit.tool&&(t.preventDefault(),h.collapsecomments?(o.setData("offsetx",8),o.setData("offsety",8)):(o.setData("offsetx",t.clientX-r.getX()),o.setData("offsety",t.clientY-r.getY())))}),o.on("gesturemove",function(t){if("select"===h.currentedit.tool){var e,i,s,n=t.clientX-o.getData("offsetx"),a=t.clientY-o.getData("offsety");!0!==o.getData("dragging")&&(o.collapse(0),o.setData("dragging",!0)),e=this.editor.get_canvas_coordinates(new M.assignfeedback_editpdf.point(n,a)),(s=this.editor.get_canvas_bounds(!0)).x=0,s.y=0,s.width-=24,s.height-=24,e.clip(s),this.x=e.x,this.y=e.y,i=this.editor.get_window_coordinates(e),r.setX(i.x),r.setY(i.y),this.drawable.store_position(r,i.x,i.y)}},null,this),o.on("gesturemoveend",function(){"select"===h.currentedit.tool&&(!0===o.getData("dragging")&&o.setData("dragging",!1),this.editor.save_current_page())},null,this),i.on("gesturemovestart",function(t){"select"===h.currentedit.tool&&(t.preventDefault(),o.setData("offsetx",t.clientX-r.getX()),o.setData("offsety",t.clientY-r.getY()),o.expand())}),i.on("gesturemove",function(t){if("select"===h.currentedit.tool){var e,i,s,n=t.clientX-o.getData("offsetx"),a=t.clientY-o.getData("offsety");!0!==o.getData("dragging")&&(o.collapse(100),o.setData("dragging",!0)),e=this.editor.get_canvas_coordinates(new M.assignfeedback_editpdf.point(n,a)),(s=this.editor.get_canvas_bounds(!0)).x=0,s.y=0,s.width-=24,s.height-=24,e.clip(s),this.x=e.x,this.y=e.y,i=this.editor.get_window_coordinates(e),r.setX(i.x),r.setY(i.y),this.drawable.store_position(r,i.x,i.y)}},null,this),i.on("gesturemoveend",function(){"select"===h.currentedit.tool&&(!0===o.getData("dragging")&&o.setData("dragging",!1),this.editor.save_current_page())},null,this),this.menu=new M.assignfeedback_editpdf.commentmenu({buttonNode:this.menulink,comment:this}))},this.remove=function(){var t=0,e=this.editor.pages[this.editor.currentpage].comments;for(t=0;t<e.length;t++)if(e[t]===this)return e.splice(t,1),this.drawable.erase(),void this.editor.save_current_page()},this.remove_from_quicklist=function(t,e){t.preventDefault(),t.stopPropagation(),this.menu.hide(),this.editor.quicklist.remove(e)},this.set_from_quick_comment=function(t,e){t.preventDefault(),this.menu.hide(),this.deleteme=!1,this.rawtext=e.rawtext,this.width=e.width,this.colour=e.colour,this.editor.save_current_page(),this.editor.redraw(),this.node=this.drawable.nodes[0].one("textarea"),this.node.ancestor("div").removeClass("commentcollapsed"),this.node.focus()},this.add_to_quicklist=function(t){t.preventDefault(),this.menu.hide(),this.editor.quicklist.add(this)},this.draw_current_edit=function(t){var e,i,s=new M.assignfeedback_editpdf.drawable(this.editor);return(i=new M.assignfeedback_editpdf.rect).bound([t.start,t.end]),e=this.editor.graphic.addShape({type:u.Rect,width:i.width,height:i.height,fill:{color:Z[t.commentcolour]},x:i.x,y:i.y}),s.shapes.push(e),s},this.init_from_edit=function(t){var e=new M.assignfeedback_editpdf.rect;return e.bound([t.start,t.end]),e.width<100&&(e.width=100),this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=e.x,this.y=e.y,this.width=e.width,this.colour=t.commentcolour,this.rawtext="",e.has_min_width()&&e.has_min_height()},this.updatePosition=function(){var t=this.drawable.nodes[0].one("textarea"),e=t.ancestor("div"),i=new M.assignfeedback_editpdf.point(this.x,this.y),s=this.editor.get_window_coordinates(i);e.setX(s.x),e.setY(s.y),this.drawable.store_position(e,s.x,s.y)}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.comment=v,x=function(t,e,i,s){this.rawtext=e||"",this.id=t||0,this.width=i||100,this.colour=s||"yellow"},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.quickcomment=x,A=function(t){this.editor=t,this.comments=[],
6 this.add=function(t){var e,i=N;""!==t.rawtext&&(e={method:"post",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"addtoquicklist",userid:this.editor.get("userid"),commenttext:t.rawtext,width:t.width,colour:t.colour,attemptnumber:this.editor.get("attemptnumber"),assignmentid:this.editor.get("assignmentid")},on:{success:function(t,e){var i,s;try{if((i=u.JSON.parse(e.responseText)).error)return new M.core.ajaxException(i);s=new M.assignfeedback_editpdf.quickcomment(i.id,i.rawtext,i.width,i.colour),this.comments.push(s),this.comments.sort(function(t,e){return t.rawtext.localeCompare(e.rawtext)})}catch(n){return new M.core.exception(n)}},failure:function(t,e){return M.core.exception(e.responseText)}}},u.io(i,e))},this.remove=function(e){var t,i=N;e&&(t={method:"post",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"removefromquicklist",userid:this.editor.get("userid"),commentid:e.id,attemptnumber:this.editor.get("attemptnumber"),assignmentid:this.editor.get("assignmentid")},on:{success:function(){var t;0<=(t=this.comments.indexOf(e))&&this.comments.splice(t,1)},failure:function(t,e){return M.core.exception(e.responseText)}}},u.io(i,t))},this.load=function(){var t,e=N;t={method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"loadquicklist",userid:this.editor.get("userid"),attemptnumber:this.editor.get("attemptnumber"),assignmentid:this.editor.get("assignmentid")},on:{success:function(t,e){var i;try{if((i=u.JSON.parse(e.responseText)).error)return new M.core.ajaxException(i);u.each(i,function(t){var e=new M.assignfeedback_editpdf.quickcomment(t.id,t.rawtext,t.width,t.colour);this.comments.push(e)},this),this.comments.sort(function(t,e){return t.rawtext.localeCompare(e.rawtext)})}catch(s){return new M.core.exception(s)}},failure:function(t,e){return M.core.exception(e.responseText)}}},u.io(e,t)}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.quickcommentlist=A,(S=function(){S.superclass.constructor.apply(this,arguments)}).prototype={oldannotationcoordinates:null,dialogue:null,panel:null,pagecount:0,currentpage:0,pages:[],documentstatus:0,loadingicon:null,pageimage:null,graphic:null,currentedit:new M.assignfeedback_editpdf.edit,currentdrawable:!1,drawables:[],currentcomment:null,currentannotation:null,lastannotation:null,lastannotationtool:"pen",quicklist:null,searchcommentswindow:null,currentstamp:null,stamps:[],editingcomment:!1,collapsecomments:!0,initializer:function(){var s;(s=u.one("#"+this.get("linkid")))&&(s.on("click",this.link_handler,this),s.on("key",this.link_handler,"down:13",this),require(["mod_assign/grading_review_panel"],function(t){var e=new t,i=e.getReviewPanel("assignfeedback_editpdf");i&&((i=u.one(i)).empty(),s.ancestor(".fitem").hide(),this.open_in_panel(i)),this.currentedit.start=!1,this.currentedit.end=!1,this.get("readonly")||(this.quicklist=new M.assignfeedback_editpdf.quickcommentlist(this))}.bind(this)))},refresh_button_state:function(){var t,e,i,s,n;switch(t=this.get_dialogue_element(O),i=M.util.image_url("background_colour_"+this.currentedit.commentcolour,"assignfeedback_editpdf"),t.one("img").setAttribute("src",i),"clear"===this.currentedit.commentcolour?t.one("img").setStyle("borderStyle","dashed"):t.one("img").setStyle("borderStyle","solid"),t=this.get_dialogue_element(B),i=M.util.image_url("colour_"+this.currentedit.annotationcolour,"assignfeedback_editpdf"),t.one("img").setAttribute("src",i),(e=this.get_dialogue_element(it[this.currentedit.tool])).addClass("assignfeedback_editpdf_selectedbutton"),e.setAttribute("aria-pressed","true"),this.get_dialogue_element(P).setAttribute("data-currenttool",this.currentedit.tool),t=this.get_dialogue_element(V),s=this.get_stamp_image_url(this.currentedit.stamp),t.one("img").setAttrs({src:s,height:"16",width:"16"}),n=this.get_dialogue_element(j),this.currentedit.tool){case"drag":n.setStyle("cursor","move");break;case"highlight":n.setStyle("cursor","text");break;case"select":n.setStyle("cursor","default");break;case"stamp":n.setStyle("cursor","url("+s+"), crosshair");break;default:n.setStyle("cursor","crosshair")}},get_canvas_bounds:function(){var t=this.get_dialogue_element(j),e=t.getXY(),i=e[0],s=e[1],n=parseInt(t.getStyle("width"),10),a=parseInt(t.getStyle("height"),10);return new M.assignfeedback_editpdf.rect(i,s,n,a)},get_canvas_coordinates:function(t){var e=this.get_canvas_bounds(),i=new M.assignfeedback_editpdf.point(t.x-e.x,t.y-e.y);return e.x=e.y=0,i.clip(e),i},get_window_coordinates:function(t){var e=this.get_canvas_bounds();return new M.assignfeedback_editpdf.point(t.x+e.x,t.y+e.y)},open_in_panel:function(t){var e;(this.panel=t).append(this.get("body")),t.addClass(T),this.loadingicon=this.get_dialogue_element(X),e=this.get_dialogue_element(j),this.graphic=new u.Graphic({render:e}),this.get("readonly")||(e.on("gesturemovestart",this.edit_start,null,this),e.on("gesturemove",this.edit_move,null,this),e.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation()},link_handler:function(t){var e,i=!0;t.preventDefault(),this.dialogue||(this.dialogue=new M.core.dialogue({headerContent:this.get("header"),bodyContent:this.get("body"),footerContent:this.get("footer"),modal:!0,width:"840px",visible:!1,draggable:!0}),this.dialogue.get("boundingBox").addClass(T),this.loadingicon=this.get_dialogue_element(X),e=this.get_dialogue_element(j),this.graphic=new u.Graphic({render:e}),this.get("readonly")||(e.on("gesturemovestart",this.edit_start,null,this),e.on("gesturemove",this.edit_move,null,this),e.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation(),e.on("windowresize",this.resize,this),i=!1),this.dialogue.centerDialogue(),this.dialogue.show(),this.dialogue.dd.on("drag:end",this.redraw,this),i&&this.resize()},start_generation:function(){this.poll_document_conversion_status()},poll_document_conversion_status:function(){var o=this.get("userid");u.io(N,{method:"get",context:this,sync:!1,data:{
7 sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(t,e){var i,s,n,a=u.one(G);a&&(i=a.getAttribute("data-userid"))&&i!=o||(n=!1,(s=this.handle_response_data(e))&&(this.documentstatus=s.status,0===s.status||1===s.status||3===s.status?n=!0:2!==s.status&&-1!==s.status||(this.pagecount=s.pagecount,s.pageready==s.pagecount?this.prepare_pages_for_display(s):(this.update_page_load_progress(),this.start_document_to_image_conversion())),n&&u.later(1e3,this,this.poll_document_conversion_status)))},failure:function(t,e){return new M.core.exception(e.responseText)}}})},start_document_to_image_conversion:function(){u.io(N,{method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(t,e){var i=this.handle_response_data(e);i&&(this.documentstatus=i.status,2===i.status&&this.prepare_pages_for_display(i))},failure:function(t,e){return new M.core.exception(e.responseText)}}})},warning:function(t,e){var i,s=this.get_dialogue_element(J),n=this.get_dialogue_element(H),a=15,o=1,r="assignfeedback_editpdf_warningmessages alert alert-warning";e&&(a=4,r="assignfeedback_editpdf_warningmessages alert alert-info"),(i=u.Node.create('<div class="'+r+'" role="alert"></div>')).append(s.one("*").cloneNode()),i.append(t),n.prepend(i),i.transition({duration:o,delay:a,opacity:0},function(){i.remove()})},prepare_pages_for_display:function(t){var e,i,s,n;if(!t.pagecount)return this.dialogue&&this.dialogue.hide(),void new M.core.alert({message:M.util.get_string("cannotopenpdf","assignfeedback_editpdf")}).show();for(this.pages=t.pages,e=0;e<this.pages.length;e++){for(i=0;i<this.pages[e].comments.length;i++)s=this.pages[e].comments[i],this.pages[e].comments[i]=new M.assignfeedback_editpdf.comment(this,s.gradeid,s.pageno,s.x,s.y,s.width,s.colour,s.rawtext);for(i=0;i<this.pages[e].annotations.length;i++)n=this.pages[e].annotations[i],this.pages[e].annotations[i]=this.create_annotation(n.type,n)}!this.get("readonly")&&t.partial&&this.warning(M.util.get_string("partialwarning","assignfeedback_editpdf"),!1),this.quicklist&&this.quicklist.load(),this.setup_navigation(),this.setup_toolbar(),this.change_page()},update_page_load_progress:function(){var n,a=0;this.get_dialogue_element(L+" .bar")&&(n={method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"conversionstatus",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid")},on:{success:function(t,e){var i,s;i=a=0,(s=this.get_dialogue_element(L+" .bar"))&&(i=e.response/this.pagecount*100,s.setStyle("width",i+"%"),s.ancestor(L).setAttribute("aria-valuenow",i),i<100&&(M.util.js_pending("checkconversionstatus"),u.later(1e3,this,function(){M.util.js_complete("checkconversionstatus"),u.io(D,n)})))},failure:function(t,e){return a+=1,0===this.pagecount&&a<5&&(M.util.js_pending("checkconversionstatus"),u.later(1e3,this,function(){M.util.js_complete("checkconversionstatus"),u.io(D,n)})),new M.core.exception(e.responseText)}}},M.util.js_pending("checkconversionstatus"),u.later(1e3,this,function(){a=0,M.util.js_complete("checkconversionstatus"),u.io(D,n)}))},handle_response_data:function(t){var e;try{if(!(e=u.JSON.parse(t.responseText)).error)return e;this.dialogue&&this.dialogue.hide(),new M.core.alert({message:M.util.get_string("cannotopenpdf","assignfeedback_editpdf"),visible:!0})}catch(i){this.dialogue&&this.dialogue.hide(),new M.core.alert({title:M.util.get_string("cannotopenpdf","assignfeedback_editpdf"),visible:!0})}},get_stamp_image_url:function(e){var t=this.get("stampfiles"),i="";return u.Array.each(t,function(t){0<t.indexOf(e)&&(i=t)},this),i},setup_toolbar:function(){var i,t,e,s,n,a,o,r,d,c;(s=this.get_dialogue_element(q)).on("click",this.open_search_comments,this),s.on("key",this.open_search_comments,"down:13",this),(n=this.get_dialogue_element(z)).on("click",this.expandCollapseComments,this),n.on("key",this.expandCollapseComments,"down:13",this),this.get("readonly")||((a=this.get_dialogue_element(K)).on("click",this.rotatePDF,this,!0),a.on("key",this.rotatePDF,"down:13",this,!0),(o=this.get_dialogue_element(W)).on("click",this.rotatePDF,this,!1),o.on("key",this.rotatePDF,"down:13",this,!1),this.disable_touch_scroll(),u.each(it,function(t,e){(i=this.get_dialogue_element(t)).on("click",this.handle_tool_button,this,e),i.on("key",this.handle_tool_button,"down:13",this,e),i.setAttribute("aria-pressed","false")},this),t=this.get_dialogue_element(O),new M.assignfeedback_editpdf.colourpicker({buttonNode:t,colours:Z,iconprefix:"background_colour_",callback:function(t){var e=t.target.getAttribute("data-colour");e=e||t.target.ancestor().getAttribute("data-colour"),this.currentedit.commentcolour=e,this.handle_tool_button(t,"comment")},context:this}),e=this.get_dialogue_element(B),new M.assignfeedback_editpdf.colourpicker({buttonNode:e,iconprefix:"colour_",colours:tt,callback:function(t){var e=t.target.getAttribute("data-colour");e=e||t.target.ancestor().getAttribute("data-colour"),this.currentedit.annotationcolour=e,this.lastannotationtool?this.handle_tool_button(t,this.lastannotationtool):this.handle_tool_button(t,"pen")},context:this}),(d=this.get("stampfiles")).length<=0?this.get_dialogue_element(it.stamp).ancestor().hide():(c=d[0].substr(d[0].lastIndexOf("/")+1),this.currentedit.stamp=c,r=this.get_dialogue_element(V),new M.assignfeedback_editpdf.stamppicker({buttonNode:r,stamps:d,callback:function(t){var e,i=t.target.getAttribute("data-stamp");e=(i=i||t.target.ancestor().getAttribute("data-stamp")).substr(i.lastIndexOf("/")),this.currentedit.stamp=e,this.handle_tool_button(t,"stamp")},context:this}),this.refresh_button_state()))},handle_tool_button:function(t,e){var i;t.preventDefault(),(
8 i=this.get_dialogue_element(it[this.currentedit.tool])).removeClass("assignfeedback_editpdf_selectedbutton"),i.setAttribute("aria-pressed","false"),"comment"!==(this.currentedit.tool=e)&&"select"!==e&&"drag"!==e&&"stamp"!==e&&(this.lastannotationtool=e),this.refresh_button_state()},stringify_current_page:function(){var t,e=[],i=[],s=0;for(s=0;s<this.pages[this.currentpage].comments.length;s++)e[s]=this.pages[this.currentpage].comments[s].clean();for(s=0;s<this.pages[this.currentpage].annotations.length;s++)i[s]=this.pages[this.currentpage].annotations[s].clean();return t={comments:e,annotations:i},u.JSON.stringify(t)},get_current_drawable:function(){var t,e=!1;return!(!this.currentedit.start||!this.currentedit.end)&&("comment"===this.currentedit.tool?e=new M.assignfeedback_editpdf.comment(this).draw_current_edit(this.currentedit):(t=this.create_annotation(this.currentedit.tool,{}))&&(e=t.draw_current_edit(this.currentedit)),e)},get_dialogue_element:function(t){return this.panel?this.panel.one(t):this.dialogue.get("boundingBox").one(t)},redraw_current_edit:function(){this.currentdrawable&&this.currentdrawable.erase(),this.currentdrawable=this.get_current_drawable()},edit_start:function(t){var e,i,s,n=this.get_dialogue_element(j),a=n.getXY(),o=n.get("docScrollY"),r=n.get("docScrollX"),d={x:t.clientX-a[0]+r,y:t.clientY-a[1]+o},c=!1;3!==t.button&&(this.currentedit.starttime||this.editingcomment||(this.currentedit.starttime=(new Date).getTime(),this.currentedit.start=d,this.currentedit.end={x:d.x,y:d.y},"select"===this.currentedit.tool&&(e=this.currentedit.end.x,i=this.currentedit.end.y,s=this.pages[this.currentpage].annotations,u.each(s,function(t){(e-t.x)*(e-t.endx)<=0&&(i-t.y)*(i-t.endy)<=0&&(c=t)}),c?(this.lastannotation=this.currentannotation,this.currentannotation=c,this.lastannotation&&this.lastannotation!==c&&this.lastannotation.drawable&&(this.lastannotation.drawable.erase(),this.drawables.push(this.lastannotation.draw())),this.currentannotation.drawable&&this.currentannotation.drawable.erase(),this.drawables.push(this.currentannotation.draw())):(this.lastannotation=this.currentannotation,this.currentannotation=null,this.lastannotation&&this.lastannotation.drawable&&(this.lastannotation.drawable.erase(),this.drawables.push(this.lastannotation.draw())))),this.currentannotation&&(this.currentedit.annotationstart={x:this.currentannotation.x,y:this.currentannotation.y})))},edit_move:function(t){var e,i,s=this.get_canvas_bounds(),n=this.get_dialogue_element(j),a=this.get_dialogue_element(P),o=new M.assignfeedback_editpdf.point(t.clientX+n.get("docScrollX"),t.clientY+n.get("docScrollY")),r=this.get_canvas_coordinates(o);"textarea"!==document.activeElement.type&&(t.preventDefault(),r.x<0||r.x>s.width||r.y<0||r.y>s.height||("pen"===this.currentedit.tool&&this.currentedit.path.push(r),"select"===this.currentedit.tool?this.currentannotation&&this.currentedit&&this.currentannotation.move(this.currentedit.annotationstart.x+r.x-this.currentedit.start.x,this.currentedit.annotationstart.y+r.y-this.currentedit.start.y):"drag"===this.currentedit.tool?(e=r.x-this.currentedit.start.x,i=r.y-this.currentedit.start.y,a.getDOMNode().scrollLeft-=e,a.getDOMNode().scrollTop-=i):this.currentedit.start&&(this.currentedit.end=r,this.redraw_current_edit())))},edit_end:function(){var t,e;(new Date).getTime()-this.currentedit.start<et||!1===this.currentedit.start||("comment"===this.currentedit.tool?(this.currentdrawable&&this.currentdrawable.erase(),this.currentdrawable=!1,(t=new M.assignfeedback_editpdf.comment(this)).init_from_edit(this.currentedit)&&(this.pages[this.currentpage].comments.push(t),this.drawables.push(t.draw(!0)),this.editingcomment=!0)):(e=this.create_annotation(this.currentedit.tool,{}))&&(this.currentdrawable&&this.currentdrawable.erase(),this.currentdrawable=!1,e.init_from_edit(this.currentedit)&&(this.pages[this.currentpage].annotations.push(e),this.drawables.push(e.draw()))),this.save_current_page(),this.currentedit.starttime=0,this.currentedit.start=!1,this.currentedit.end=!1,this.currentedit.path=[])},resize:function(){var t,e;if(this.dialogue){if(!this.dialogue.get("visible"))return;this.dialogue.centerDialogue()}return(e=u.one("body").get("winHeight")-120)<100&&(e=100),t=this.get_dialogue_element(P),this.dialogue&&t.setStyle("maxHeight",e+"px"),this.redraw(),!0},create_annotation:function(t,e){return e.type=t,e.editor=this,"line"===t?new M.assignfeedback_editpdf.annotationline(e):"rectangle"===t?new M.assignfeedback_editpdf.annotationrectangle(e):"oval"===t?new M.assignfeedback_editpdf.annotationoval(e):"pen"===t?new M.assignfeedback_editpdf.annotationpen(e):"highlight"===t?new M.assignfeedback_editpdf.annotationhighlight(e):"stamp"===t&&new M.assignfeedback_editpdf.annotationstamp(e)},save_current_page:function(){this.clear_warnings(!1);var t,e=N;t={method:"post",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"savepage",index:this.currentpage,userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),page:this.stringify_current_page()},on:{success:function(t,e){var i;try{if((i=u.JSON.parse(e.responseText)).error)return new M.core.ajaxException(i);u.one(F).set("value","true"),this.warning(M.util.get_string("draftchangessaved","assignfeedback_editpdf"),!0)}catch(s){return new M.core.exception(s)}},failure:function(t,e){return new M.core.exception(e.responseText)}}},u.io(e,t)},open_search_comments:function(t){this.searchcommentswindow||(this.searchcommentswindow=new M.assignfeedback_editpdf.commentsearch({editor:this})),this.searchcommentswindow.show(),t.preventDefault()},expandCollapseComments:function(){var t=u.all(".commentdrawable");this.collapsecomments?(this.collapsecomments=!1,t.removeClass("commentcollapsed")):(this.collapsecomments=!0,t.addClass("commentcollapsed"))},redraw:function(){var t,e;if((e=this.pages[this.currentpage])!==undefined){for(;0<this.drawables.length;)this.drawables.pop().erase();for(
9 t=0;t<e.annotations.length;t++)this.drawables.push(e.annotations[t].draw());for(t=0;t<e.comments.length;t++)this.drawables.push(e.comments[t].draw(!1))}},clear_warnings:function(t){var e=this.get_dialogue_element(H);t?e.empty():e.all(".alert-info").remove(!0)},change_page:function(){var t,e,i,s=this.get_dialogue_element(j);e=this.get_dialogue_element(I),i=this.get_dialogue_element(C),0<this.currentpage?e.removeAttribute("disabled"):e.setAttribute("disabled","true"),this.currentpage<this.pagecount-1?i.removeAttribute("disabled"):i.setAttribute("disabled","true"),t=this.pages[this.currentpage],this.loadingicon&&this.loadingicon.hide(),s.setStyle("backgroundImage",'url("'+t.url+'")'),s.setStyle("width",t.width+"px"),s.setStyle("height",t.height+"px"),s.scrollIntoView(),this.get_dialogue_element(R).set("selectedIndex",this.currentpage),this.resize()},setup_navigation:function(){var t,e,i,s,n,a=this.get_dialogue_element(R),o=a.all("option");if(o.size()<=1)for(t=0;t<this.pages.length;t++)(i=u.Node.create("<option/>")).setAttribute("value",t),e={page:t+1,total:this.pages.length},i.setHTML(M.util.get_string("pagexofy","assignfeedback_editpdf",e)),a.append(i);a.removeAttribute("disabled"),a.on("change",function(){this.currentpage=a.get("value"),this.clear_warnings(!1),this.change_page()},this),s=this.get_dialogue_element(I),n=this.get_dialogue_element(C),s.on("click",this.previous_page,this),s.on("key",this.previous_page,"down:13",this),n.on("click",this.next_page,this),n.on("key",this.next_page,"down:13",this)},previous_page:function(t){t.preventDefault(),this.currentpage--,this.currentpage<0&&(this.currentpage=0),this.clear_warnings(!1),this.change_page()},next_page:function(t){t.preventDefault(),this.currentpage++,this.currentpage>=this.pages.length&&(this.currentpage=this.pages.length-1),this.clear_warnings(!1),this.change_page()},move_canvas:function(){var t,e,i,s;for(t=this.get_dialogue_element(P),e=parseInt(t.get("scrollLeft"),10),i=parseInt(t.get("scrollTop"),10),s=0;s<this.drawables.length;s++)this.drawables[s].scroll_update(e,i)},rotatePDF:function(h,t){var l,e,i,s,n,a;if(h.preventDefault(),!this.get("destroyed")){for((l=this).oldannotationcoordinates=[],i=this.pages[this.currentpage].annotations,e=0;e<i.length;e++)s=i[e],this.oldannotationcoordinates.push([s.x,s.y]);n=N,a={method:"post",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"rotatepage",index:this.currentpage,userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),rotateleft:t},on:{success:function(t,e){var i,s,n,a,o,r,d,c;try{for(i=u.JSON.parse(e.responseText),(s=l.pages[l.currentpage]).url=i.page.url,s.width=i.page.width,s.height=i.page.height,l.loadingicon.hide(),(n=l.get_dialogue_element(j)).setStyle("backgroundImage",'url("'+s.url+'")'),n.setStyle("width",s.width+"px"),n.setStyle("height",s.height+"px"),o=s.annotations,a=0;a<o.length;a++)l.oldannotationcoordinates&&l.oldannotationcoordinates[a]&&(r=l.oldannotationcoordinates[a][0],d=l.oldannotationcoordinates[a][1],o[a].move(r,d));for(c=s.comments,a=0;a<c.length;a++)c[a].updatePosition();return l.save_current_page()}catch(h){return new M.core.exception(h)}},failure:function(t,e){return new M.core.exception(e.responseText)}}},u.io(n,a)}},event_listener_options_supported:function(){var t,e=!1,i="testpassiveeventoptions";try{t=Object.defineProperty({},"passive",{get:function(){e=!0}}),document.addEventListener(i,t,t),document.removeEventListener(i,t,t)}catch(s){e=!1}return e},disable_touch_scroll:function(){this.event_listener_options_supported()&&document.addEventListener("touchmove",this.stop_touch_scroll.bind(this),{passive:!1})},stop_touch_scroll:function(t){this.get_dialogue_element(P).contains(t.target)&&(t.stopPropagation(),t.preventDefault())}},u.extend(S,u.Base,S.prototype,{NAME:"moodle-assignfeedback_editpdf-editor",ATTRS:{userid:{validator:u.Lang.isInteger,value:0},assignmentid:{validator:u.Lang.isInteger,value:0},attemptnumber:{validator:u.Lang.isInteger,value:0},header:{validator:u.Lang.isString,value:""},body:{validator:u.Lang.isString,value:""},footer:{validator:u.Lang.isString,value:""},linkid:{validator:u.Lang.isString,value:""},deletelinkid:{validator:u.Lang.isString,value:""},readonly:{validator:u.Lang.isBoolean,value:!0},stampfiles:{validator:u.Lang.isArray,value:""}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.editor=M.assignfeedback_editpdf.editor||{},M.assignfeedback_editpdf.editor.init=M.assignfeedback_editpdf.editor.init||function(t){return M.assignfeedback_editpdf.instance=new S(t),M.assignfeedback_editpdf.instance}},"@VERSION@",{requires:["base","event","node","io","graphics","json","event-move","event-resize","transition","querystring-stringify-simple","moodle-core-notification-dialog","moodle-core-notification-alert","moodle-core-notification-warning","moodle-core-notification-exception","moodle-core-notification-ajaxexception"]});