{"version":3,"sources":["../js/Annotations/AnnotationsUI.js"],"names":["g_oAnnotations","AnnotationUI","ApprovalId","ApprovalType","this","g_iApprovalId","g_iApprovalType","g_iAnnotationType","eAnnotationTypes","Postit","g_oAnnotationsMade","g_oPostitImg","Image","src","width","g_oViewer","c_iDPI","height","heightOffset","widthOffset","g_oCursorMoveIcon","g_oTempAnnotationArray","g_oTempMarqueeDimensions","g_oAnnotationColSelected","zindex","g_bAnnotationsFound","g_iOrigClickX","g_iOrigClickY","g_szPrevCursorStyle","g_oLastAnnotation","g_oLastUsedTool","g_oPreviousSpeechAnnotation","g_oPreviousSpeechAnnotationArrow","g_iAnnotationWidth","g_iSpeechbubbleLeftPosOffset","g_iSpeechbubbleTopTriangleOffset","threeDannotationSize","g_iMinimumFreedrawAnnotationDistance","g_iMaximumFreedrawAnnotationPoints","g_iAnnotationNumberFontSize","g_oAnnotationNumberBox","iBeginX","iBeginY","iWidth","iHeight","g_oAnnotationNumberText","g_iAnnotationDivLineWidth","g_iAnnotationDivLineDash","g_bReturnAll","g_oAnnotationViewer","g_oArtworkViewer","g_szAnnotationContent","g_oAnnotationHub","$","connection","annotationHub","g_oAnnotationCurrentTimeoutArray","g_bNonAnnotationActionInProgress","g_oPreviouslySavedAnnotationCoords","c_szPrimaryArtworkNotSelected","g_szColladaTexture","g_oExistingTextAnnotations","g_bOverrideCloseBubble","g_bForceToggling","g_szTextMeasurementFill","prototype","DrawCoordinatesSet","iId","iAnnoId","iCoordX","iCoordY","iCoordZ","iMarqX","iMarqY","annotationCoordId","annotationId","xCoordinate","yCoordinate","zCoordinate","xMarqueeCoordinate","yMarqueeCoordinate","add3DAnnotation","intersectsPoint","intersectsObject","oArtworkCanvas","oAnnotationCanvas","AnnotationId","uvObj","particle","THREE","Mesh","SphereGeometry","MeshPhongMaterial","color","opacity","transparent","oNewAnnotation","window","Annotation","id","getNextAnnotationId","position","x","y","z","scale","g_iAnnotationScale","Id","g_oScene","add","g_oRenderer","render","g_oCamera","g_oDrawArray","push","ThreeD","g_iAuthor","g_oUserDetails","UserId","g_szAuthorEmail","EmailAddress","g_szColour","status","g_iDocumentId","g_oDoc","documentId","g_iuvX","g_iuvY","createAnnotationDiv","eAnnotationDivType","Popup","annotationColourChange","colour","g_oSettings","g_oUserSettings","AnnotationColour","getHexColour","updateSettingAnnotationColour","annotationColourChangeUI","szColour","getStringColour","remove","charAt","toUpperCase","slice","parents","slideUp","each","css","c_iSkinType","calculateClosestPointAlongBezierCurve","curvePoints","target","Tolerance","i","tempResult","calculatePointAlongCubicBezierCurve","a","b","Math","sqrt","t","p","closeActiveAnnotations","oAnnotationListItems","length","iAnnotationId","replace","click","oNewAnnotations","children","changeDocumentThreeDAnnotations","iDocId","iApprovalId","iApproval3DViewId","bThreeDView","getCanvas","g_oCompare","getAnnotationCanvasId","getLinkedArtworkCanvas","g_szCanvasId","iCompareDocumentId","oJSON","iParentDocumentId","g_oCompareMode","eCompareMode","NoCompare","g_oCompareDocument","document","Approval3DViewId","findfirst","g_oThreeDView","g_oApprovalThreeDViews","ParentDocumentId","documentType","eDocumentTypes","g_oaComboControls","documents","selectedDocumentIndex","greenlightDocumentId","iDocumentId","iCompareApprovalId","ajax","type","url","data","JSON","stringify","contentType","dataType","success","response","oParentAnnotations","parse","Contents","oParentDocument","iParentDocumentPageId","ParentDocumentPageId","ToggleThreeDView","g_oProgressBar","removeProgressBar","oControl","comboControl_GetControlById","setupAnnotations","failure","g_oGreenlightMessages","displayErrorBubble","c_szAnnotationFailedtoSave","error","changeDocumentAnnotations","approval","iDocumentType","isEmptyObject","approvalId","prop","redraw","ex","g_bReadOnly","hide","setAvailableCompareModes","g_oApproval","ReadOnly","g_bAlignmentModeActive","g_oTextCompare","g_bTextCompareInProgress","show","approvalStatus","eApproverStatus","Pending","hub","start","done","server","join","toString","checkIfNewSpeechBubbleExists","bNewSpeechBubbleExists","changePageOnStepThrough","iNumberOfPages","iStartPage","g_iCurrentPage","checkforAnnotationsOnPage","pages","documentPageId","changeCurrentPage","EventService","publish","bAnnotationFound","g_iDocumentPageId","checkAnnotationsExistForUser","getUserAnnotations","checkAnnotationsExistOnApproval","checkAnnotationsExistOnDocument","clearButtonHighlights","annotation","removeClass","undefined","createAnnotationStatus","AnnotationStatus","getDisplayName","emailAddress","displayName","szDisplayName","c_szLeftByMe","threeDCreateAnnotation","e","lockScreen","g_oActiveBubbles","closeBubble","forceToggleAnnotationDocument","setTimeout","unlockScreen","oCoords","getClick","bIsThreeDView","g_oMouseVector","g_oCanvas","clientWidth","clientHeight","g_oRaycaster","setFromCamera","oIntersects","intersectObjects","object","face","daeMaterial","oUvObj","uv","point","repositionSpeechBubbles","displayWarningBubble","distToSegmentSquared","vector1","vector2","l2","dist2","max","min","v","w","squareNumber","number","distToSegment","drawEllipse","event","coords","annContext","g_oContext","oAnnotationCanvasObject","g_iX","g_iY","isClickWithinImageBounds","transformedClick","transformClickForRotation","beginPoint_x","g_iOrigin_x","g_iCenterShift_x","beginPoint_y","g_iOrigin_y","g_iCenterShift_y","dist_x","abs","dist_y","halfPoint_x","halfPoint_y","clearRect","beginPath","width_two_thirds","height_over_2","moveTo","bezierCurveTo","closePath","stroke","strokeStyle","lineWidth","off","dragDiscontinue","drawFreeDraw","oLastAddedPoint","g_iScaledImageWidth","g_iScaledImageHeight","oNewPoint","compareOffset_x","compareOffset_y","lineTo","co","calculateCompareOffsetInPx","trigger","drawInitiate","parentAnnotation","changeCanvasFunction","annotationPointerUp","ShowAnnotations","Freedraw","Rectangle","drawRect","Ellipse","Line","drawLine","drawGlobal","rect","g_iCompareImage_x","g_iCompareImage_y","on","findAnnotation","drawPostit","g_oTransformedClick","drawImage","drawLineToDiv","coordsOrig","coordinates","annotationColour","relatedCanvas","relatedContext","newXBegin","newYBegin","transformedCoords","parseInt","save","setLineDash","restore","drawLineTo3DAnnotation","divCoords","geometry","Geometry","vertices","Vector3","unproject","computeLineDistances","lineDistancesNeedUpdate","material","LineDashedMaterial","dashSize","gapSize","linewidth","line","class","setAnnotationRectangle","redrawAnnotations","oCanvas","rectLeft","rectTop","isIE","exists","getBoundingClientRect","left","top","clientX","clientY","baseCanvas","g_oNavCanvasOver","body","scrollLeft","documentElement","getElementById","scrollTop","szHexColour","eAnnotationColours","blue","red","green","orange","purple","cyan","magenta","yellow","grey","hexColour","szStringColour","getStringStatuses","oStatuses","szStatuses","g_iAnnotationStatus","grep","getTranslationValues","coordValue","bHover","g_oTextTools","g_bHighlightInProgress","checkHandleClicked","checkForUnsavedAnnotation","iCompareRotation","getCompareRotation","relatedArtworkCanvas","CanvasRenderingContext2D","isPointInStroke","imageObjW","imageObjH","dTolerance","g_iZoomLevel","originalEvent","mozInputSource","sourceCapabilities","firesTouchEvents","pointerType","g_oFoundAnnotationStack","iPageId","documentPageNumber","postitAnnotations","ColourDensityMeasurementPostit","g_bSVGHoverAnnotation","g_bSVGSearchAnnotation","postitAnn","oRotatedAnnotationDraw","rotate","rotated_x","rotated_y","postitOffset","xCoords","yCoords","freeDrawAnnotations","SVGPolygon","freeDrawAnn","oRotatedAnnotationDraw2","rectangleAnnotations","TextMeasurement","TextHighlight","TextClassification","BarcodeMeasurement","ColourDensityMeasurement","SVGRectangle","Global","rectAnn","sort","ellipseAnnotations","SVGEllipse","ellipseAnn","rightHandCurvePoints","leftHandCurvePoints","result","lineAnnotations","lineAnn","ann","g_iParentAnnotationId","oParentAnnotation","g_oTextMeasurementWordsArray","oData","oAnnotation","g_bClosed","documentDisplaysAsSVG","c_bFindSVGText","g_oSVGText","removeSVGHoverAnnotations","g_oAnnotationCanvas","hoverSVGText","findSVGText","findThreeDAnnotations","iFoundAnnotationId","oMatchingAnnotation","setAnnotationStatusUpdateAction","annotationStatus","statusCode","eAnnotationStatusUpdateType","updateStatus","deleteStatus","addStatus","iTempAnnotationId","initiateAnnotationDraw","removeStyle","g_oTechTools","clearToolType","g_oAnnotationActions","mouseMoveLite","currentTarget","oTempMarqueeDimensions","iImageObjW","iImageObjH","g_oNewAnnotation","deepCopyArray","g_oMarqueeDrawArray","MinX","MinY","MaxX","MaxY","g_iNumber","apply","map","o","annotationSaveShape","createdDate","moment","utc","Date","ISO_8601","local","rebuildAnnotationList","annotationStack","j","filteredAnnotationStack","modifiedDate","iCounter","l","parent","g_oFilter","applyAnnotationFilters","m","ListItem","updatePrintAnnotationsIcon","copyOverride","szAnnotationCanvasId","oDocument","greenlightApprovalId","toolTypeChange","element","hasClass","LastUsedAnnotationType","syncSettings","presetUserTools","szPresetColour","oToolElement","oColourElement","getAnnotationStackCurrentPage","iFilterId","renderTextCompareAnnotations","oAnnotationContext","oAnnotationStack","iCenterShift_x","iCenterShift_y","iGlobalCounter","counter","bShowAnnotaionsOnCanvas","g_bSVGTextAnnotation","g_oSVGVariable","copyMagicText","g_bSVGPositionUpdated","g_oSVGCopyMagic","getContentBoundingRectDrawArray","switchId","contentDataId","contentId","annotationArray","annCol","annTyp","closed","oAnnotationDraw","g_bVisible","c","newXEnd","d","newYEnd","quadraticCurveTo","applySVGAnnotationStyling","highlightTextMeasurementWords","oCallback","content","artworkCanvas","annotationCanvas","g_bHighlightIsCharacterAccuracy","startingText","character","setHighlightColour","highlightSections","g_szTextHighlightContent","g_oTextData","loadTextData","ShowAnnotationNumbers","annText","font","textBaseline","textalign","areaTextSize","measureText","iGlobalAnnotationShiftX","iGlobalAnnotationShiftY","fillStyle","fill","fillText","isAnnotationClosed","g_bIsAnimating","createAnnotationHandle","mouseMove","focus","bclosed","iparentId","oAnnotaionIndex","clearMesh","oAnnotationMesh","child","removeThreeJSObjects","redraw3DAnnotations","lineSceneObj","oCurrentDocument","g_szTextContent","oCurrentAnnotation","existingAnnotation","existingDiv","visible","existingAnnotationNumber","g_oContainer","offsetLeft","oChildAnnotations","set","annotationNo","TextGeometry","g_oFont","weight","style","size","curveSegments","bevelThickness","bevelSize","bevelEnabled","computeBoundingBox","specular","textMesh","receiveShadow","castShadow","iXTranslate","iYTranslate","applyMatrix","Matrix4","makeTranslation","approverStatusSetEvent","changeCurrentPageEvent","registerEvents","oEventService","subscribe","setupFilters","setExistingTextMeasurementAnnotationWordsList","setTempMarqueeCoordinates","objects","node","dispose","renderPageAnnotationNumbers","iComboControl","oThisPagesAnnotations","find","html","oCompareArtworkCanvas","g_oCompareViewer","iCompareComboControl","szColladaModelTexture","oMasterList","annotationType","g_oAnnotationData","annotationData","annotationDateTime","annotationContent","modifiedDateTime","svgVariableId","g_szSVGOriginalContent","svgOriginalContent","textHighlightContent","replyToAnnotId","approvalUserId","approvalUserEmailAddress","g_szAuthorDisplayName","approvalUserDisplayName","g_bSaved","g_bUnlocked","unlocked","annotationCoords","annotation3dvUVx","annotation3dvUVy","attachments","nCoordSet","annotationX","annotationY","annotationZ","g_oDrawCoordSetArray","marqueeX","marqueeY","Convert2DTo3DAnnotation","iParentPageId","anno","g_oReplies","k","annotationReplies","oNewAnnotationReply","g_oStatuses","annotationStatuses","oNewAnnotationStatus","annotationstatusId","g_iApprovalUserAnnotId","annotationStatusDateTime","_this","_oArtworkCanvas","_oAnnotationCanvas","g_oFontLoader","FontLoader","load","oCompareAnnotationCanvas","g_oCompareAnnotationViewer","_this_Compare","_oArtworkCanvas_Compare","_oAnnotationCanvas_Compare","g_oSVGLoader","applySVGChanges","filteredAnnotationList","bAlreadyAdded","findParentCanvasFromAnnDiv","oParentCanvas","parentCanvas","repositionDivForHeight","currentDiv","outerHeight","attr","iNewDivLeft","iNewDivTop","iRotatedSizeDiff","iScaledImgW","iScaledImgH","iDragOffset_x","iDragOffset_y","szAnnotationColour","oCoordsOrig","iOffsetHeight","iLeftOffset","iTriangleOffset","oResult","oRelatedArtworkCanvas","leftMargin","rightMargin","verticalMargin","iCompareDocType","g_iDragOffset_x","g_iDragOffset_y","referenceCompareViewerOffset","oAnnotationCoords","maxWidth","maxHeight","outerWidth","g_iRotDegrees","addClass","Three","coordsChildOrig","stepThroughAnnotations","previousListItem","closeButton","substring","viewer","tempx","tempy","deleteAnnotationReply","annotationReplyId","bDeletionConfirmed","parentId","getAnnotationReplyParent","sessionId","c_szSessionId","userId","displaySuccessBubble","c_szAnnotationRepyDeleted","removeAnnotationReplyFromParent","canAnnotationBeDeleted","insertDeleteButton","c_szUnexpectedError","jqXHR","exception","ProcessApiError","displayConfirmBubble","c_szConfirmDeleteAnnotationReply","some","reply","filter","prependDomElement","c_szDeleteAnnotation","deleteAnnotation","iAnnId","oAnnotations","oMainScope","iDeletingAnnotationId","bDeletingCopyMagicAnnotation","setTextMeasurementWordVisibility","oJSONSession","SessionId","splice","arrChildIdArray","oSVGInformation","svgVariable","originalContent","removeSVGTextUpdate","oAnnotationObj","indexOf","annotationNumberObj","c_szAnnotationDeleted","UpdateApprovalButtonStates","send","c_szAnnotationCouldNotBeDeleted","oTimer","currentTimeoutListRemove","currentTimeoutListAdd","c_szConfirmDelete","resetAnnotationStatus","deleteAnnotationStatus","iAnnotationID","oWordsArray","oMarqueeDimensions","bFoundUnsavedAnnotation","oTimeout","currentTimeoutListClear","clearTimeout","text","getSelection","oSel","rangeCount","oContainer","createElement","len","appendChild","getRangeAt","cloneContents","innerHTML","innerText","oRange","createRange","selectNode","removeAllRanges","addRange","execCommand","selection","htmlText","oClipboardData","clipboardData","setData","preventDefault","getIdFromElementId","oaElementIdSplit","split","isNaN"],"mappings":"AAYA,IAAIA,eAAiB,IAEpB,WACA,aAMA,SAASC,aAAaC,WAAYC,cACjCC,KAAKC,cAAgBH,WACrBE,KAAKE,gBAAkBH,aACvBC,KAAKG,kBAAoBC,iBAAiBC,OAC1CL,KAAKM,mBAAqB,GAC1BN,KAAKO,aAAe,IAAIC,MACxBR,KAAKO,aAAaE,IAAM,oBACxBT,KAAKO,aAAaG,MAAQ,GAAKC,UAAUC,OACzCZ,KAAKO,aAAaM,OAAS,GAAKF,UAAUC,OAC1CZ,KAAKO,aAAaO,aAAe,GAAKH,UAAUC,OAChDZ,KAAKO,aAAaQ,YAAc,EAAIJ,UAAUC,OAC9CZ,KAAKgB,kBAAoB,IAAIR,MAC7BR,KAAKgB,kBAAkBP,IAAM,2BA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BAAuBwF,oBAGW,IAAtB+C,SAAS8rB,WACO,QAA3B9rB,SAAS8rB,UAAU/qB,OACtBwf,KAAOvgB,SAAS8rB,UAAUL,cAAcM,SACxCnB,KAAO5qB,SAAS8rB,UAAUlB,MAK5B,IAAIoB,eAAiBxjB,MAAMyjB,eAAiBzjB,MAAMkJ,cAAcua,eAAiB5xB,OAAO4xB,cAExFD,eAAeE,QAAQ,YAAa3L,MACpCyL,eAAeE,QAAQ,aAActB,MACrCpiB,MAAM2jB,kBAQP93B,aAAagE,UAAU+zB,mBAAqB,SAAU7xB,IAKrD,IAHA,IAEImE,cAFA2tB,iBAAmB9xB,GAAG+xB,MAAM,KAGvBxuB,EAAI,EAAGA,EAAIuuB,iBAAiB5tB,SACpCC,cAAgBuO,SAASof,iBAAiBvuB,IAGrCyuB,MAAM7tB,gBAJiCZ,KAS7C,OAAOY,eAIRrE,OAAOhG,aAAeA,aAn2IvB","file":"AnnotationsUI-6637aa1128.js","sourcesContent":["/*\r\n* Copyright (c) 2017 SGS Europe. All rights reserved.\r\n*\r\n* This program is the CONFIDENTIAL and PROPRIETARY property of SGS Europe.\r\n* Any unauthorised use, reproduction, or transfer of this program is strictly\r\n* prohibited.\r\n*\r\n* File Name:\tGreenlightAnnotations.js\r\n*\r\n* Description:\tJavaScript code for the UI for Annotations.\r\n*\r\n*/\r\nvar g_oAnnotations = {};\r\n\r\n(function () {\r\n\t\"use strict\";\r\n\r\n\t/**\r\n\t * Prototype for our Annotation UI object.\r\n\t * @class\r\n\t */\r\n\tfunction AnnotationUI(ApprovalId, ApprovalType) {\r\n\t\tthis.g_iApprovalId = ApprovalId;\r\n\t\tthis.g_iApprovalType = ApprovalType;\r\n\t\tthis.g_iAnnotationType = eAnnotationTypes.Postit;\t// Sets the default annotation type\r\n\t\tthis.g_oAnnotationsMade = [];\r\n\t\tthis.g_oPostitImg = new Image();\r\n\t\tthis.g_oPostitImg.src = \"img/Postit_16.png\";\r\n\t\tthis.g_oPostitImg.width = 16 * g_oViewer.c_iDPI;\r\n\t\tthis.g_oPostitImg.height = 16 * g_oViewer.c_iDPI;\r\n\t\tthis.g_oPostitImg.heightOffset = 13 * g_oViewer.c_iDPI;\r\n\t\tthis.g_oPostitImg.widthOffset = 3 * g_oViewer.c_iDPI;\r\n\t\tthis.g_oCursorMoveIcon = new Image();\r\n\t\tthis.g_oCursorMoveIcon.src = \"img/cursor-move-icon.png\";\r\n\t\tthis.g_oTempAnnotationArray = [];\r\n\t\tthis.g_oTempMarqueeDimensions = null;\r\n\t\tthis.g_oAnnotationColSelected = \"blue\";\r\n\t\tthis.zindex = 10;\r\n\t\tthis.g_bAnnotationsFound = false;\r\n\t\tthis.g_iOrigClickX = 0;\r\n\t\tthis.g_iOrigClickY = 0;\r\n\t\tthis.g_szPrevCursorStyle = \"default\";\r\n\t\tthis.g_oLastAnnotation = null;\r\n\t\tthis.g_oLastUsedTool = \"\";\r\n\r\n // Allows us to save the last annotation\r\n this.g_oPreviousSpeechAnnotation = null;\r\n this.g_oPreviousSpeechAnnotationArrow = false;\r\n\r\n // Could be adjustable in future g_oAnnotations.\r\n this.g_iAnnotationWidth = 2 * g_oViewer.c_iDPI;\r\n\t\tthis.g_iSpeechbubbleLeftPosOffset = 65;\r\n\t\tthis.g_iSpeechbubbleTopTriangleOffset = 15;\r\n\t\tthis.threeDannotationSize = 0.004;\r\n\t\tthis.g_iMinimumFreedrawAnnotationDistance = 50;\r\n\t\tthis.g_iMaximumFreedrawAnnotationPoints = 500;\r\n\r\n\t\t// Annotation numbering.\r\n\t\tthis.g_iAnnotationNumberFontSize = 15 * g_oViewer.c_iDPI;\r\n\t\tthis.g_oAnnotationNumberBox = {\r\n\t\t\tiBeginX: 10 * g_oViewer.c_iDPI,\r\n\t\t\tiBeginY: 27 * g_oViewer.c_iDPI,\r\n\t\t\tiWidth: 5 * g_oViewer.c_iDPI,\r\n\t\t\tiHeight: 17 * g_oViewer.c_iDPI\r\n\t\t};\r\n\t\tthis.g_oAnnotationNumberText = {\r\n\t\t\tiBeginX: 7.5 * g_oViewer.c_iDPI,\r\n\t\t\tiBeginY: 10 * g_oViewer.c_iDPI\r\n\t\t};\r\n\r\n\t\t// Settings for the annotation line to div.\r\n\t\tthis.g_iAnnotationDivLineWidth = 1 * g_oViewer.c_iDPI;\r\n\t\tthis.g_iAnnotationDivLineDash = [5 * g_oViewer.c_iDPI, 3 * g_oViewer.c_iDPI];\r\n\r\n\t\t// A boolean set which is (probably) needed for CopyMagic.\r\n\t\tthis.g_bReturnAll = false;\r\n\r\n\t\t// Get the Canvas objects from the main viewer object.\r\n\t\tthis.g_oAnnotationViewer = g_oViewer.g_oAnnotationViewer;\r\n\t\tthis.g_oArtworkViewer = g_oViewer.g_oArtworkViewer;\r\n\r\n\t\tthis.g_szAnnotationContent = \"\";\r\n\t\tthis.g_oAnnotationHub = $.connection.annotationHub;\r\n\r\n\t\tthis.g_oAnnotationCurrentTimeoutArray = [];\r\n\t\tthis.g_bNonAnnotationActionInProgress = false;\t// A flag to stop the setting of the annotation mouse events if another action has already been started.\r\n\r\n\t\tthis.g_oPreviouslySavedAnnotationCoords = null;\r\n\r\n\t\tthis.c_szPrimaryArtworkNotSelected = \"\";\r\n\r\n\t\tthis.g_szColladaTexture = \"\";\r\n\r\n\t\tthis.g_oExistingTextAnnotations = []; // Keep track of existing text annotations to prevent calling the server on annotation save.\r\n\r\n\t\tthis.g_bOverrideCloseBubble = false; // Global boolean to allow the suppression of closing bubbles.\r\n\r\n\t\tthis.g_bForceToggling = false;\r\n\r\n\t\t// The text measurement fill colour.\r\n\t\tthis.g_szTextMeasurementFill = \"rgba(0,200,0,0.5)\";\r\n\t}\r\n\r\n\t/*\r\n\t * - - - P U B L I C M E T H O D S - - -\r\n\t */\r\n\r\n\t/**\r\n\t * Creates a new coordinate object.\r\n\t * @param {int} iId - The id of the coordinate.\r\n\t * @param {int} iAnnoId - The id of the annotation holding the coordinate.\r\n\t * @param {double} iCoordX - The x coordinate.\r\n\t * @param {double} iCoordY - The y coordinate.\r\n\t * @param {double} iCoordZ - The z coordinate.\r\n\t * @param {double} iMarqX - The Marquee x coordinate.\r\n\t * @param {double} iMarqY - THe Marquee y coordinate.\r\n\t */\r\n\tAnnotationUI.prototype.DrawCoordinatesSet = function (iId, iAnnoId, iCoordX, iCoordY, iCoordZ, iMarqX, iMarqY) {\r\n\t\treturn {\r\n\t\t\tannotationCoordId: iId,\r\n\t\t\tannotationId: iAnnoId,\r\n\t\t\txCoordinate: iCoordX,\r\n\t\t\tyCoordinate: iCoordY,\r\n\t\t\tzCoordinate: iCoordZ,\r\n\t\t\txMarqueeCoordinate: (typeof (iMarqX) === \"undefined\") ? null : iMarqX,\r\n\t\t\tyMarqueeCoordinate: (typeof (iMarqY) === \"undefined\") ? null : iMarqY\r\n\t\t};\r\n\t},\r\n\r\n\t/**\r\n\t * Adds a new point to a 3D Canvas and creates a pop-up div.\r\n\t * @param {array} intersectsPoint - The intersection point\r\n\t * @param {object} intersectsObject - The 3D object needed for mapping.\r\n\t * @param {object} uv - Optional parameter used in 3D preview mode to obtain texture UV percentages.\r\n\t */\r\n\tAnnotationUI.prototype.add3DAnnotation = function (intersectsPoint, intersectsObject, oArtworkCanvas, oAnnotationCanvas, AnnotationId, uvObj) {\r\n\t\tvar particle = new THREE.Mesh(new THREE.SphereGeometry(g_oAnnotations.threeDannotationSize, 32, 32), new THREE.MeshPhongMaterial({ color: this.g_oAnnotationColSelected, opacity: 0.8, transparent: true }));\r\n\r\n\t\tvar oNewAnnotation = new window.Annotation(g_oAnnotations.g_iApprovalId);\r\n\t\toNewAnnotation.id = AnnotationId || g_oAnnotations.getNextAnnotationId();\r\n\r\n\t\t// Get the particles.\r\n\t\tparticle.position.x = intersectsPoint.x;\r\n\t\tparticle.position.y = intersectsPoint.y;\r\n\t\tparticle.position.z = intersectsPoint.z;\r\n\t\tparticle.scale.x = oArtworkCanvas.g_iAnnotationScale;\r\n\t\tparticle.scale.y = oArtworkCanvas.g_iAnnotationScale;\r\n\t\tparticle.scale.z = oArtworkCanvas.g_iAnnotationScale;\r\n\t\tparticle.Id = oNewAnnotation.id;\r\n\r\n\t\t// Be aware of Scale, larger the object, the smaller the particle appears.\r\n\t\toArtworkCanvas.g_oScene.add(particle);\r\n\t\toArtworkCanvas.g_oRenderer.render(oArtworkCanvas.g_oScene, oArtworkCanvas.g_oCamera);\r\n\r\n\t\t// Set up the Annotation object.\r\n\t\toNewAnnotation.g_oDrawArray.push([particle.position.x, particle.position.y, particle.position.z]);\r\n\r\n\t\toNewAnnotation.g_iAnnotationType = eAnnotationTypes.ThreeD;\r\n\r\n\t\toNewAnnotation.g_iAuthor = g_oUserDetails.UserId;\r\n\t\toNewAnnotation.g_szAuthorEmail = g_oUserDetails.EmailAddress;\r\n\t\toNewAnnotation.g_szColour = g_oAnnotations.g_oAnnotationColSelected;\r\n\t\toNewAnnotation.status = \"a\";\r\n\t\toNewAnnotation.g_iDocumentId = oArtworkCanvas.g_oDoc.documentId;\r\n\r\n\t\t// If uvObj is defined. uvObj is a point in 3d space.\r\n\t\tif (!(typeof uvObj === \"undefined\")) {\r\n\t\t\toNewAnnotation.g_iuvX = uvObj.x;\r\n\t\t\toNewAnnotation.g_iuvY = uvObj.y;\r\n\t\t}\r\n\r\n\t\tg_oAnnotations.g_oAnnotationsMade.push(oNewAnnotation);\r\n\t\toNewAnnotation.createAnnotationDiv(eAnnotationDivType.Popup, true, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t};\r\n\r\n\t/**\r\n\t * Changes the annotation colour\r\n\t * @param {type} colour - Hex code of the colour selected.\r\n\t */\r\n\tAnnotationUI.prototype.annotationColourChange = function (colour) {\r\n\r\n\t\t// Update the user's preferences.\r\n\t\tg_oSettings.g_oUserSettings.AnnotationColour = g_oAnnotations.getHexColour(colour);\r\n\t\tg_oSettings.updateSettingAnnotationColour(true);\r\n\t};\r\n\r\n\t/**\r\n\t * Updates the annotation colour in the UI.\r\n\t */\r\n\tAnnotationUI.prototype.annotationColourChangeUI = function () {\r\n\r\n\t\t// Get the annotation colour.\r\n\t\tvar szColour = g_oAnnotations.getStringColour(g_oSettings.g_oUserSettings.AnnotationColour)\r\n\r\n\t\t// Remove the colour selection element if this exists.\r\n\t\t$(\"#settingAnnotationColourPopup\").remove();\r\n\r\n\t\t// Update the selected colour.\r\n\t\tg_oAnnotations.g_oAnnotationColSelected = szColour;\r\n\r\n\t\t// Capitalise the first letter of the colour so we can find the ids.\r\n\t\tszColour = szColour.charAt(0).toUpperCase() + szColour.slice(1);\r\n\r\n\t\t// Slide up the container.\r\n\t\t$(\"#annotate\" + szColour).parents(\".dropdown-content\").slideUp(200);\r\n\r\n\t\t// Highlight the colour as selected.\r\n\t\t$(\".annotationColor\").each(function () { $(this).css(\"border-color\", \"transparent\"); });\r\n\t\t$(\"#annotate\" + szColour).css(\"border-color\", g_oSettings.c_iSkinType == 0 ? \"white\" : \"black\");\r\n\t};\r\n\r\n\t/**\r\n\t * Calculates the closest point along a Bézier Curve\r\n\t * @param {array} curvePoints\r\n\t * @param {array} target\r\n\t * @param {int} Tolerance - The tolerance of the curve.\r\n\t * @returns {boolean}\r\n\t */\r\n\tAnnotationUI.prototype.calculateClosestPointAlongBezierCurve = function (curvePoints, target, Tolerance) {\r\n\t\tfor (var i = 0; i < 100; i++) {\r\n\t\t\tvar tempResult = g_oAnnotations.calculatePointAlongCubicBezierCurve(i / 100, curvePoints);\r\n\t\t\tvar a = tempResult.x - target.x;\r\n\t\t\tvar b = tempResult.y - target.y;\r\n\t\t\tvar c = Math.sqrt(a * a + b * b);\r\n\t\t\tif (c < Tolerance) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t};\r\n\r\n\t/**\r\n\t * Calculates Point Along Cubic Bézier Curve.\r\n\t * @param {int} t\r\n\t * @param {int p\r\n\t * @returns {array} - The returning set of coordinates.\r\n\t */\r\n\tAnnotationUI.prototype.calculatePointAlongCubicBezierCurve = function (t, p) {\r\n\t\tvar x, y;\r\n\t\tx = (1 - t) * (1 - t) * (1 - t) * p[0].x + 3 * ((1 - t) * (1 - t)) * t * p[1].x + 3 * (1 - t) * (t * t) * p[2].x + (t * t * t) * p[3].x;\r\n\t\ty = (1 - t) * (1 - t) * (1 - t) * p[0].y + 3 * ((1 - t) * (1 - t)) * t * p[1].y + 3 * (1 - t) * (t * t) * p[2].y + (t * t * t) * p[3].y;\r\n\t\treturn ({ x: x, y: y });\r\n\t};\r\n\r\n\tAnnotationUI.prototype.closeActiveAnnotations = function () {\r\n\r\n\t\t// Grab a list of the annotations in the current list.\r\n\t\tvar oAnnotationListItems = $(\".annotationListItem\");\r\n\r\n\t\t// If there are annotations in the current list.\r\n\t\tif (oAnnotationListItems.length !== 0) {\r\n\r\n\t\t\t// Loop through the list items.\r\n\t\t\tfor (var i = 0; i < oAnnotationListItems.length; i++) {\r\n\r\n\t\t\t\t// Get the id of the list item.\r\n\t\t\t\tvar iAnnotationId = oAnnotationListItems[i].id.replace(/([^0-9-])+/i, \"\");\r\n\r\n\t\t\t\t// If there is an annotation bubble with a close button for this annotation.\r\n\t\t\t\tif ($(\"#\" + iAnnotationId + \"_clo\").length) {\r\n\r\n\t\t\t\t\t// Click the close button for the annotation.\r\n\t\t\t\t\t$(\"#\" + iAnnotationId + \"_clo\").click();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Grab a list of annotations that are new.\r\n\t\tvar oNewAnnotations = $(\".speechbubble\").children(\".HeaderBar\").children(\".deletebutton\");\r\n\r\n\t\t// If there are annotations that are currently unsaved.\r\n\t\tif (oNewAnnotations.length !== 0) {\r\n\r\n\t\t\t// Loop through the new annotations.\r\n\t\t\tfor (var i = 0; i < oNewAnnotations.length; i++) {\r\n\r\n\t\t\t\t// Get the id of the new item.\r\n\t\t\t\tvar iAnnotationId = oNewAnnotations[i].id.replace(/([^0-9-])+/i, \"\");\r\n\r\n\t\t\t\t// If there is an annotation bubble with a bin button for this annotation.\r\n\t\t\t\tif ($(\"#\" + iAnnotationId + \"_del\").length) {\r\n\r\n\t\t\t\t\t// Click the bin button for the annotation.\r\n\t\t\t\t\t$(\"#\" + iAnnotationId + \"_del\").click();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\tAnnotationUI.prototype.changeDocumentThreeDAnnotations = function (iDocId, iApprovalId, iApproval3DViewId) {\r\n\r\n\t\t// Determine if a ThreeD Doc or ThreeD preview\r\n\t\tvar bThreeDView = iApproval3DViewId > 0;\r\n\r\n\t\t// Remove any active speech bubbles from the canvas.\r\n\t\t$(\".speechbubble\").remove();\r\n\r\n\t\t// Clear the annotations list.\r\n\t\tg_oAnnotations.g_oAnnotationsMade = [];\r\n\r\n\t\t// Determine the canvas to used for rendering based on the annotation toggle.\r\n\t\tvar oAnnotationCanvas = g_oViewer.getCanvas(g_oCompare.getAnnotationCanvasId());\r\n\t\tvar oArtworkCanvas = g_oViewer.getLinkedArtworkCanvas(oAnnotationCanvas.g_szCanvasId);\r\n\r\n\t\t// Get any required values.\r\n\t\tvar iDocumentType = 3;\r\n\t\tvar iCompareDocumentId = 0;\r\n\t\tvar oJSON = {};\r\n\t\tvar iParentDocumentId = -1;\r\n\r\n\t\t// If we are in a compare mode, include the annotations for the compare document if a different document has been selected.\r\n\t\tif (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && iDocId != g_oCompare.g_oCompareDocument.document.documentId) {\r\n\t\t\tif (g_oCompare.g_oCompareDocument.document.Approval3DViewId > -1) {\r\n\t\t\t\tvar iParentCompareDocumentId = $.findfirst(g_oThreeDView.g_oApprovalThreeDViews, function (x) {\r\n\t\t\t\t\treturn x.Approval3DViewId === g_oCompare.g_oCompareDocument.document.Approval3DViewId;\r\n\t\t\t\t}).ParentDocumentId;\r\n\t\t\t\tiCompareDocumentId = iParentCompareDocumentId;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tiCompareDocumentId = g_oCompare.g_oCompareDocument.document.documentId;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && g_oCompare.g_oCompareDocument.document.documentType === eDocumentTypes.ThreeD && g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex].document.documentType !== eDocumentTypes.ThreeD) {\r\n\t\t\tiCompareDocumentId = g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex].greenlightDocumentId;\r\n\t\t}\r\n\r\n\t\tif (bThreeDView) {\r\n\t\t\tvar iParentDocumentId = $.findfirst(g_oThreeDView.g_oApprovalThreeDViews, function (x) {\r\n\t\t\t\treturn x.Approval3DViewId === iApproval3DViewId;\r\n\t\t\t}).ParentDocumentId;\r\n\t\t\toJSON = {\r\n\t\t\t\tiApprovalId: null,\r\n\t\t\t\tiDocumentId: iParentDocumentId,\r\n\t\t\t\tiCompareApprovalId: null,\r\n\t\t\t\tiCompareDocumentId: iCompareDocumentId\r\n\t\t\t};\r\n\t\t}\r\n\t\telse {\r\n\t\t\toJSON = {\r\n\t\t\t\tiApprovalId: null,\r\n\t\t\t\tiDocumentId: iDocId,\r\n\t\t\t\tiCompareApprovalId: null,\r\n\t\t\t\tiCompareDocumentId: iCompareDocumentId\r\n\t\t\t};\r\n\t\t}\r\n\t\t// Go the server and request the annotations for the current document.\r\n\t\t$.ajax({\r\n\t\t\ttype: \"POST\",\r\n\t\t\turl: \"internal/GreenlightAnnotation/listAnnotations\",\r\n\t\t\tdata: JSON.stringify(oJSON),\r\n\t\t\tcontentType: \"application/json; charset=utf-8\",\r\n\t\t\tdataType: \"json\",\r\n\t\t\tsuccess: function (response) {\r\n\t\t\t\tif (bThreeDView) {\r\n\t\t\t\t\t// Refresh the g_oAnnotations object with the new details.\r\n\t\t\t\t\tg_oAnnotations.g_iApprovalType = iDocumentType;\r\n\t\t\t\t\tg_oAnnotations.g_iApprovalId = iApprovalId;\r\n\r\n\t\t\t\t\tvar oParentAnnotations = JSON.parse(response.Contents);\r\n\t\t\t\t\tvar oParentDocument = $.findfirst(g_oaComboControls[1].documents, function (x) {\r\n\t\t\t\t\t\treturn x.greenlightDocumentId === iParentDocumentId;\r\n\t\t\t\t\t}).document;\r\n\t\t\t\t\tvar iParentDocumentPageId = $.findfirst(g_oThreeDView.g_oApprovalThreeDViews, function (x) {\r\n\t\t\t\t\t\treturn x.Approval3DViewId === iApproval3DViewId;\r\n\t\t\t\t\t}).ParentDocumentPageId;\r\n\t\t\t\t\tg_oThreeDView.ToggleThreeDView(oParentAnnotations, oParentDocument, iParentDocumentPageId, iDocId, iApprovalId);\r\n\t\t\t\t\t// Remove the progress bar.\r\n\t\t\t\t\tg_oProgressBar.removeProgressBar();\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tvar oControl = comboControl_GetControlById((g_oCompare.getAnnotationCanvasId() == \"CompareAnnotationViewer\" ? \"approvalCompareComboControl\" : \"approvalNameComboControl\"), false);\r\n\t\t\t\t\t// Ensure these annotations are in sync with the current document (Server may have been slow).\r\n\t\t\t\t\tif (iDocId === oControl.documents[oControl.selectedDocumentIndex].greenlightDocumentId || iDocId === 0) {\r\n\t\t\t\t\t\t// Refresh the g_oAnnotations object with the new details.\r\n\t\t\t\t\t\tg_oAnnotations.g_oAnnotationViewer = g_oViewer.g_oAnnotationViewer;\r\n\t\t\t\t\t\tg_oAnnotations.g_oArtworkViewer = g_oViewer.g_oArtworkViewer;\r\n\t\t\t\t\t\tg_oAnnotations.g_iApprovalType = iDocumentType;\r\n\t\t\t\t\t\tg_oAnnotations.g_iApprovalId = iApprovalId;\r\n\r\n\t\t\t\t\t\t// Clear out the annotations.\r\n\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade = [];\r\n\r\n\t\t\t\t\t\t// Setup the annotations.\r\n\t\t\t\t\t\tg_oAnnotations.setupAnnotations(JSON.parse(response.Contents), oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t\t// Remove the progress bar.\r\n\t\t\t\t\t\tg_oProgressBar.removeProgressBar();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tfailure: function (response) {\r\n\t\t\t\tg_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szAnnotationFailedtoSave);\r\n\t\t\t},\r\n\t\t\terror: function (response) {\r\n\t\t\t\tg_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szAnnotationFailedtoSave);\r\n\t\t\t}\r\n\t\t});\r\n\t};\r\n\r\n\t/**\r\n\t * Called to refresh the annotations when changing the document version.\r\n\t * @param {string} approval - Details of the approval.\r\n\t */\r\n\tAnnotationUI.prototype.changeDocumentAnnotations = function (approval) {\r\n\t\t// Get any required values.\r\n\t\tvar iDocId = 0;\r\n\t\tvar iApprovalId = 0;\r\n\t\tvar iDocumentType = 0;\r\n\t\tvar iCompareDocumentId = 0;\r\n\r\n\t\t// Set the approval document if we have one.\r\n\t\tif (!$.isEmptyObject(approval) && approval != null) {\r\n\t\t\tiDocId = approval.documentId;\r\n\t\t\tiApprovalId = approval.approvalId;\r\n\t\t\tiDocumentType = approval.document.documentType;\r\n\t\t}\r\n\r\n\t\t// If we have changed to a 3D document then do not load the annotations until the texture has loaded.\r\n\t\tvar oJSON = {};\r\n\t\tif (!(iDocumentType === 3) || ($(\"#chkAnnotationToggle\").prop(\"checked\") && g_oaComboControls[1].documents[g_oaComboControls[1].selectedDocumentIndex].document.documentType !== eDocumentTypes.ThreeD)) {\r\n\t\t\t// Remove any active speech bubbles from the canvas.\r\n\t\t\t$(\".speechbubble\").remove();\r\n\r\n\t\t\t// Clear the annotations list.\r\n\t\t\tg_oAnnotations.g_oAnnotationsMade = [];\r\n\r\n\t\t\t// Determine the canvas to used for rendering based on the annotation toggle.\r\n\t\t\tvar oAnnotationCanvas = g_oViewer.getCanvas(g_oCompare.getAnnotationCanvasId());\r\n\t\t\tvar oArtworkCanvas = g_oViewer.getLinkedArtworkCanvas(oAnnotationCanvas.g_szCanvasId);\r\n\r\n\t\t\t// If we are in a compare mode, include the annotations for the compare document if a different document has been selected.\r\n\t\t\tif (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && iDocId != g_oCompare.g_oCompareDocument.document.documentId) {\r\n\t\t\t\tiCompareDocumentId = g_oCompare.g_oCompareDocument.document.documentId;\r\n\t\t\t}\r\n\t\t\toJSON = {\r\n\t\t\t\tiApprovalId: null,\r\n\t\t\t\tiDocumentId: iDocId,\r\n\t\t\t\tiCompareApprovalId: null,\r\n\t\t\t\tiCompareDocumentId: iCompareDocumentId\r\n\t\t\t};\r\n\t\t\t// Go the server and request the annotations for the current document.\r\n\t\t\t$.ajax({\r\n\t\t\t\ttype: \"POST\",\r\n\t\t\t\turl: \"internal/GreenlightAnnotation/listAnnotations\",\r\n\t\t\t\tdata: JSON.stringify(oJSON),\r\n\t\t\t\tcontentType: \"application/json; charset=utf-8\",\r\n\t\t\t\tdataType: \"json\",\r\n\t\t\t\tsuccess: function (response) {\r\n\t\t\t\t\tvar oControl = comboControl_GetControlById(\"approvalNameComboControl\", false);\r\n\t\t\t\t\t// Ensure these annotations are in sync with the current document (Server may have been slow).\r\n\t\t\t\t\tif (iDocId === oControl.documents[oControl.selectedDocumentIndex].greenlightDocumentId || iDocId === 0\r\n\t\t\t\t\t\t|| (g_oViewer.g_oCompareMode != eCompareMode.NoCompare\r\n\t\t\t\t\t\t\t&& $(\"#chkAnnotationToggle\").prop(\"checked\")\r\n\t\t\t\t\t\t\t&& g_oaComboControls[1].documents[g_oaComboControls[1].selectedDocumentIndex].document.documentType !== eDocumentTypes.ThreeD\r\n\t\t\t\t\t\t\t&& g_oaComboControls[1].documents[g_oaComboControls[1].selectedDocumentIndex].greenlightDocumentId === iDocId)) {\r\n\t\t\t\t\t\t// Refresh the g_oAnnotations object with the new details.\r\n\t\t\t\t\t\tg_oAnnotations.g_oAnnotationViewer = g_oViewer.g_oAnnotationViewer;\r\n\t\t\t\t\t\tg_oAnnotations.g_oArtworkViewer = g_oViewer.g_oArtworkViewer;\r\n\t\t\t\t\t\tg_oAnnotations.g_iApprovalType = iDocumentType;\r\n\t\t\t\t\t\tg_oAnnotations.g_iApprovalId = iApprovalId;\r\n\r\n\t\t\t\t\t\t// Clear out the annotations.\r\n\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade = [];\r\n\r\n\t\t\t\t\t\t// Setup the annotations.\r\n\t\t\t\t\t\tg_oAnnotations.setupAnnotations(JSON.parse(response.Contents), oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t\t// Redraw the canvas if in compare mode.\r\n\t\t\t\t\t\tif (g_oViewer.g_oCompareMode != eCompareMode.NoCompare) {\r\n\t\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\toArtworkCanvas.redraw(false);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tcatch (ex) {\r\n\t\t\t\t\t\t\t\t// Do nothing\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t},\r\n\t\t\t\tfailure: function (response) {\r\n\t\t\t\t\tg_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szAnnotationFailedtoSave);\r\n\t\t\t\t},\r\n\t\t\t\terror: function (response) {\r\n\t\t\t\t\tg_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szAnnotationFailedtoSave);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\t// If we have an approval.\r\n\t\tif (!$.isEmptyObject(approval) && approval != null) {\r\n\t\t\t// If we are in no compare mode.\r\n\t\t\tif (g_oViewer.g_oCompareMode === eCompareMode.NoCompare) {\r\n\t\t\t\t// Reset the list of available compare types.\r\n\t\t\t\tg_oCompare.setAvailableCompareModes(eCompareMode.NoCompare, iDocumentType, iDocumentType);\r\n\t\t\t}\r\n\r\n\t\t\t// Set the read only properties based on the approval and compare mode.\r\n\t\t\tif (g_oApproval.ReadOnly() || g_oCompare.g_bAlignmentModeActive || g_oTextCompare.g_bTextCompareInProgress) {\r\n\t\t\t\tg_oViewer.g_bReadOnly = true;\r\n\t\t\t\t$(\"#tblAnnotateTools\").hide();\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tg_oViewer.g_bReadOnly = false;\r\n\t\t\t\t$(\"#tblAnnotateTools\").show();\r\n\t\t\t}\r\n\r\n\t\t\t// Add the user to the annotation hub if the approval is pending.\r\n\t\t\tif (approval.approvalStatus == eApproverStatus.Pending) {\r\n\t\t\t\t// Joins people to the Approval's SignalR Group. Is destroyed and recreated as needed.\r\n\t\t\t\t$.connection.hub.start().done(function () {\r\n\t\t\t\t\tg_oAnnotations.g_oAnnotationHub.server.join(approval.approvalId.toString());\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\t// If we do not have an approval.\r\n\t\telse {\r\n\t\t\t// Remove any existing annotations.\r\n\t\t\tg_oViewer.g_bReadOnly = true;\r\n\t\t\t$(\"#tblAnnotateTools\").hide();\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Loops through all the speech bubbles present on the page to see if any are new.\r\n\t */\r\n\tAnnotationUI.prototype.checkIfNewSpeechBubbleExists = function () {\r\n\t\t// Loop through all the existing speech bubbles that may be open.\r\n\t\tvar bNewSpeechBubbleExists = false;\r\n\r\n\t\t$(\".speechbubble\").each(function () {\r\n\t\t\tif (this.id < 0) {\r\n\t\t\t\tbNewSpeechBubbleExists = true;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn bNewSpeechBubbleExists;\r\n\t};\r\n\r\n\t/**\r\n\t * Changes the page to the next page with annotations.\r\n\t * @param {int} iNumberOfPages - The number of pages of the document.\r\n\t * @param {int} iStartPage - The page we initially started on.\r\n\t*/\r\n\tAnnotationUI.prototype.changePageOnStepThrough = function (iNumberOfPages, iStartPage, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar bAnnotationsOnNextPage = false;\r\n\r\n\t\t// If the current page isn't less than to the number of pages we should go forward.\r\n\t\tif (oArtworkCanvas.g_iCurrentPage < iNumberOfPages) {\r\n\t\t\toArtworkCanvas.g_iCurrentPage++;\r\n\r\n\t\t\t// Do we have annotations on this page?\r\n\t\t\tbAnnotationsOnNextPage = g_oAnnotations.checkforAnnotationsOnPage(oArtworkCanvas.g_oDoc.pages[oArtworkCanvas.g_iCurrentPage - 1].documentPageId);\r\n\t\t}\r\n\t\t// Otherwise we should loop back to the first page.\r\n\t\telse {\r\n\t\t\toArtworkCanvas.g_iCurrentPage = 1;\r\n\r\n\t\t\t// Do we have annotations on this page?\r\n\t\t\tbAnnotationsOnNextPage = g_oAnnotations.checkforAnnotationsOnPage(oArtworkCanvas.g_oDoc.pages[oArtworkCanvas.g_iCurrentPage - 1].documentPageId);\r\n\t\t}\r\n\r\n\t\tif (bAnnotationsOnNextPage) {\r\n\t\t\t// This is the only page with annotations, and we've looped through them all.\r\n\t\t\t// So don't bother changing the page.\r\n\t\t\tif (oArtworkCanvas.g_iCurrentPage != iStartPage) {\r\n\t\t\t\toArtworkCanvas.changeCurrentPage();\r\n\t\t\t\tEventService.publish(\"changeCurrentPage\", oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// Recursively call the function to loop through the pages.\r\n\t\t\tg_oAnnotations.changePageOnStepThrough(iNumberOfPages, iStartPage, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Checks if any annotations exist on a page.\r\n\t * @param {int} documentPageId - The document page id we are checking.\r\n\t * @returns {bool} - Returns true or false, depending on if annotations were created.\r\n\t */\r\n\tAnnotationUI.prototype.checkforAnnotationsOnPage = function (documentPageId) {\r\n\t\tvar bAnnotationFound = false;\r\n\r\n\t\t// Loop through all annotation to find a match.\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentPageId == documentPageId) {\r\n\t\t\t\tbAnnotationFound = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (bAnnotationFound) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\telse {\r\n\t\t\treturn false;\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Checks that annotations exist for a user.\r\n\t * @param {int} UserId - The users id.\r\n\t * @return {bool} - Indicating if the annotations exist.\r\n\t */\r\n\tAnnotationUI.prototype.checkAnnotationsExistForUser = function (UserId) {\r\n\t\treturn this.getUserAnnotations(UserId).length > 0;\r\n\t};\r\n\r\n\t/**\r\n\t * Checks that annotations exist the approval.\r\n\t * @returns {bool} - Indicating if the annotations exist.\r\n\t */\r\n\tAnnotationUI.prototype.checkAnnotationsExistOnApproval = function () {\r\n\t\treturn g_oAnnotations.g_oAnnotationsMade.length > 0;\r\n\t};\r\n\r\n\t/**\r\n\t * Checks that annotations exist the approval.\r\n\t * @returns {bool} - Indicating if the annotations exist.\r\n\t */\r\n\tAnnotationUI.prototype.checkAnnotationsExistOnDocument = function () {\r\n\t\treturn g_oAnnotations.g_oAnnotationsMade.length > 0;\r\n\t};\r\n\r\n\t/**\r\n\t * Clears the annotations buttons.\r\n\t * @param {object} annotation\r\n\t */\r\n\tAnnotationUI.prototype.clearButtonHighlights = function (annotation) {\r\n\t\t$(\".AnimateMe\").removeClass(\"selectedButton\");\r\n\t\t// Only hide if the annotation button hasn't been pressed\r\n\t\tif (annotation === undefined) {\r\n\t\t\t$(\"#annotationDropDown\").slideUp(200);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Creates an Annotation Status, from outside this file.\r\n\t * @returns {object} - The newly created prototype.\r\n\t */\r\n\tAnnotationUI.prototype.createAnnotationStatus = function () {\r\n\t\tvar oNewAnnotationStatus = new window.AnnotationStatus();\r\n\r\n\t\treturn oNewAnnotationStatus;\r\n\t};\r\n\r\n\t/**\r\n\t * Gets the display name to be used for a user.\r\n\t * @param {int} userId - The id of the user.\r\n\t * @param {string} emailAddress - The email address of the user.\r\n\t * @returns {string} - The display name to be used.\r\n\t */\r\n\tAnnotationUI.prototype.getDisplayName = function (emailAddress, displayName) {\r\n\t\t\r\n\t\t// Outline the default display name.\r\n\t\tvar szDisplayName = emailAddress;\r\n\r\n\t\t// If this user is the current user.\r\n\t\tif (emailAddress == g_oUserDetails.EmailAddress) {\r\n\r\n\t\t\t// Use 'Me' as the display name.\r\n\t\t\tszDisplayName = g_oAnnotations.c_szLeftByMe;\r\n\t\t}\r\n\t\t// Otherwise check for a custom display name.\r\n\t\telse if (displayName != null && displayName != \"\") {\r\n\r\n\t\t\t// Use the custom display name.\r\n\t\t\tszDisplayName = displayName;\r\n\t\t}\r\n\r\n\t\t// Return the display name.\r\n\t\treturn szDisplayName;\r\n\t};\r\n\r\n\t/**\r\n\t * Prepares the canvas for a 3D Annotation\r\n\t * @param {event} e - The JavaScript click event.\r\n\t */\r\n\tAnnotationUI.prototype.threeDCreateAnnotation = function (e, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// If we need to toggle the annotations mode in compare.\r\n\t\tif ($(\"#chkAnnotationToggle\").prop(\"checked\")) {\r\n\r\n\t\t\t// If we have not already started toggling.\r\n\t\t\tif (!g_oAnnotations.g_bForceToggling) {\r\n\r\n\t\t\t\t// Force toggle.\r\n\t\t\t\tg_oAnnotations.g_bForceToggling = true;\r\n\t\t\t\tlockScreen();\r\n\r\n\t\t\t\t// Close any active bubbles.\r\n\t\t\t\tfor (var i = 0; i < g_oActiveBubbles.length; i++) {\r\n\t\t\t\t\tg_oGreenlightMessages.closeBubble(g_oActiveBubbles[i].id, true, true);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Switch to the correct canvas and load the annotations\r\n\t\t\t\tg_oCompare.forceToggleAnnotationDocument(\"AnnotationViewer\");\r\n\r\n\t\t\t\t// Re-call this function to process the click event after annotations have loaded. Screen is unlocked here so we do not have to rely upon the unlock which is called annotations are loaded.\r\n\t\t\t\tsetTimeout(function () { unlockScreen(); g_oAnnotations.threeDCreateAnnotation(e, oArtworkCanvas, oAnnotationCanvas); }, 1000);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Get the click co-ordinates.\r\n\t\tvar oCoords = g_oAnnotations.getClick(e, oArtworkCanvas);\r\n\t\toCoords[0] /= g_oViewer.c_iDPI;\r\n\t\toCoords[1] /= g_oViewer.c_iDPI;\r\n\r\n\t\t// Get the current document\r\n\t\tvar bIsThreeDView = g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex].document.Approval3DViewId > 0;\r\n\r\n\t\t// Use the ArtworkViewer, as there is no annotation viewer.\r\n\t\toArtworkCanvas.g_oMouseVector.x = (oCoords[0] / oArtworkCanvas.g_oCanvas.clientWidth) * 2 - 1;\r\n\t\toArtworkCanvas.g_oMouseVector.y = -(oCoords[1] / oArtworkCanvas.g_oCanvas.clientHeight) * 2 + 1;\r\n\r\n\t\t// Determine if we intersect.\r\n\t\toArtworkCanvas.g_oRaycaster.setFromCamera(oArtworkCanvas.g_oMouseVector, oArtworkCanvas.g_oCamera);\r\n\t\tvar oIntersects = oArtworkCanvas.g_oRaycaster.intersectObjects(oArtworkCanvas.g_oScene.children, true);\r\n\t\t\r\n\t\t// If we intersect.\r\n\t\tif (oIntersects != null && oIntersects.length > 0) {\r\n\r\n\t\t\t// We have a hit. But did we click on an annotation or on the 3d object?\r\n\t\t\tif (oIntersects[0].object.Id !== undefined) {\r\n\t\t\t\t// We clicked on an annotation. Default behaviour.\r\n\t\t\t}\r\n\t\t\telse if (bIsThreeDView) {\r\n\t\t\t\tif (oIntersects[0].face.daeMaterial === this.g_szColladaTexture) {\r\n\t\t\t\t\tvar oUvObj = oIntersects[0].uv;\r\n\t\t\t\t\t// we want to create a 3D annotation which will be translated back to 2D on save (3D preview).\r\n\t\t\t\t\t// Add the annotation symbol\r\n\t\t\t\t\tg_oAnnotations.add3DAnnotation(oIntersects[0].point, oIntersects[0], oArtworkCanvas, oAnnotationCanvas, null, oUvObj);\r\n\t\t\t\t\tAnnotationUI.prototype.repositionSpeechBubbles(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\t// Close any active bubbles\r\n\t\t\t\t\tfor (var i = 0; i < g_oActiveBubbles.length; i++) {\r\n\t\t\t\t\t\tg_oGreenlightMessages.closeBubble(g_oActiveBubbles[i].id, true, true);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tg_oGreenlightMessages.displayWarningBubble(g_oAnnotations.c_szPrimaryArtworkNotSelected);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// We want to create a normal 3D annotation. Add the annotation symbol.\r\n\t\t\t\tg_oAnnotations.add3DAnnotation(oIntersects[0].point, oIntersects[0], oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\tAnnotationUI.prototype.repositionSpeechBubbles(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Reset the force toggle.\r\n\t\tg_oAnnotations.g_bForceToggling = false;\r\n\t};\r\n\r\n\t/**\r\n\t * Calculates the distance between a distance segment squared\r\n\t * @param {array} point - The clicked point\r\n\t * @param {array} vector1 - The start of the line in vector form.\r\n\t * @param {array} vector2 - The end of the line in vector form.\r\n\t */\r\n\tAnnotationUI.prototype.distToSegmentSquared = function (point, vector1, vector2) {\r\n\t\tvar l2 = g_oAnnotations.dist2(vector1, vector2);\r\n\r\n\t\tif (l2 == 0) {\r\n\t\t\treturn g_oAnnotations.dist2(point, vector1);\r\n\t\t}\r\n\r\n\t\tvar t = ((point.x - vector1.x) * (vector2.x - vector1.x) + (point.y - vector1.y) * (vector2.y - vector1.y)) / l2;\r\n\t\tt = Math.max(0, Math.min(1, t));\r\n\r\n\t\treturn g_oAnnotations.dist2(point, {\r\n\t\t\tx: vector1.x + t * (vector2.x - vector1.x),\r\n\t\t\ty: vector1.y + t * (vector2.y - vector1.y)\r\n\t\t});\r\n\t};\r\n\r\n\t/**\r\n\t * Calculates distance between two points.\r\n\t * @param {array} v - First 2d vector\r\n\t * @param {array} w - Second 2d vector.\r\n\t * @returns {float}\r\n\t */\r\n\tAnnotationUI.prototype.dist2 = function (v, w) {\r\n\t\treturn g_oAnnotations.squareNumber(v.x - w.x) + g_oAnnotations.squareNumber(v.y - w.y);\r\n\t};\r\n\r\n\t/**\r\n\t * Squares a number\r\n\t * @param {int} number - The to square\r\n\t * @returns {int} - The number of squared.\r\n\t */\r\n\tAnnotationUI.prototype.squareNumber = function (number) {\r\n\t\treturn number * number;\r\n\t};\r\n\r\n\t/**\r\n\t * Works out the distance to a segment\r\n\t * @param {array} p - The starting point.\r\n\t * @param {array} v - The first 2d Vector\r\n\t * @param {array} w - The Second 2d vector.\r\n\t * @returns {float} - The distance.\r\n\t */\r\n\tAnnotationUI.prototype.distToSegment = function (p, v, w) {\r\n\t\treturn Math.sqrt(g_oAnnotations.distToSegmentSquared(p, v, w));\r\n\t};\r\n\r\n\t/**\r\n\t * Draws an ellipse on the canvas.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawEllipse = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar coords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\t// Setup some variables to hold the Annotation/Artwork Canvas\r\n\t\tvar oAnnotationCanvasObject = oAnnotationCanvas.g_oCanvas;\r\n\r\n\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\toAnnotationCanvas.g_iY = coords[1];\r\n\t\tif (oAnnotationCanvas.isClickWithinImageBounds(coords[0], coords[1], oArtworkCanvas, oAnnotationCanvas)) {\r\n\r\n\t\t\tvar transformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas);\r\n\t\t\toAnnotationCanvas.g_iX = transformedClick[0];\r\n\t\t\toAnnotationCanvas.g_iY = transformedClick[1];\r\n\r\n\t\t\tvar beginPoint_x = Math.min(oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x, oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x);\r\n\t\t\tvar beginPoint_y = Math.min(oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y, oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y);\r\n\t\t\tvar dist_x = Math.abs((oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x) - (oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x));\r\n\t\t\tvar dist_y = Math.abs((oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y) - (oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y));\r\n\t\t\tvar halfPoint_x = beginPoint_x + (dist_x / 2);\r\n\t\t\tvar halfPoint_y = beginPoint_y + (dist_y / 2);\r\n\r\n\t\t\tannContext.clearRect(0, 0, oAnnotationCanvasObject.width, oAnnotationCanvasObject.height);\r\n\t\t\tannContext.beginPath();\r\n\r\n\t\t\tvar width_two_thirds = dist_x * 2 / 3;\r\n\t\t\tvar height_over_2 = dist_y / 2;\r\n\r\n\t\t\tannContext.beginPath();\r\n\t\t\tannContext.moveTo(halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\tannContext.bezierCurveTo(halfPoint_x + width_two_thirds, halfPoint_y - height_over_2, halfPoint_x + width_two_thirds, halfPoint_y + height_over_2, halfPoint_x, halfPoint_y + height_over_2);\r\n\t\t\tannContext.bezierCurveTo(halfPoint_x - width_two_thirds, halfPoint_y + height_over_2, halfPoint_x - width_two_thirds, halfPoint_y - height_over_2, halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\tannContext.closePath();\r\n\t\t\tannContext.stroke();\r\n\r\n\t\t\tannContext.strokeStyle = g_oAnnotations.getHexColour(g_oAnnotations.g_oAnnotationColSelected);\r\n\t\t\tannContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\tannContext.stroke();\r\n\t\t}\r\n\t\t// if not within bounds of canvas, we want to cancel the annotation draw.\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointermove\", g_oAnnotations.drawEllipse);\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointerup\");\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a free shape on the canvas\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawFreeDraw = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t\r\n\t\tvar coords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\toAnnotationCanvas.g_iY = coords[1];\r\n\r\n\t\t// Ensure we're not beyond canvas boundaries\r\n\t\tif (oAnnotationCanvas.isClickWithinImageBounds(coords[0], coords[1], oArtworkCanvas, oAnnotationCanvas)) {\r\n\r\n\t\t\t// Get the transformed click.\r\n\t\t\tvar transformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas);\r\n\t\t\toAnnotationCanvas.g_iX = transformedClick[0];\r\n\t\t\toAnnotationCanvas.g_iY = transformedClick[1];\r\n\r\n\t\t\t// Hide any existing speech bubbles.\r\n\t\t\t$(\".speechbubble\").hide();\r\n\r\n\t\t\t// Get the last added point.\r\n\t\t\tvar oLastAddedPoint = {\r\n\t\t\t\tx: (g_oAnnotations.g_oTempAnnotationArray.length == 0 ? 0 : g_oAnnotations.g_oTempAnnotationArray[g_oAnnotations.g_oTempAnnotationArray.length - 1][0] * oArtworkCanvas.g_iScaledImageWidth), // Last added X co-ordinate. (Ignoring any zoom)\r\n\t\t\t\ty: (g_oAnnotations.g_oTempAnnotationArray.length == 0 ? 0 : g_oAnnotations.g_oTempAnnotationArray[g_oAnnotations.g_oTempAnnotationArray.length - 1][1] * oArtworkCanvas.g_iScaledImageHeight) // Last added Y co-ordinate. (Ignoring any zoom)\r\n\t\t\t};\r\n\r\n\t\t\t// Get the new point.\r\n\t\t\tvar oNewPoint = {\r\n\t\t\t\tx: oAnnotationCanvas.g_iX, // Current click X co-ordinate. (Ignoring any zoom)\r\n\t\t\t\ty: oAnnotationCanvas.g_iY // Current click Y co-ordinate. (Ignoring any zoom)\r\n\t\t\t};\r\n\r\n\t\t\t// If the point is over the minimum distance from the last annotation point.\r\n\t\t\tif (g_oAnnotations.g_oTempAnnotationArray.length == 0 || g_oAnnotations.dist2(oLastAddedPoint, oNewPoint) > g_oAnnotations.g_iMinimumFreedrawAnnotationDistance) {\r\n\r\n\t\t\t\t// Draw the path to the new annotation point.\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.moveTo((oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x), (oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y));\r\n\t\t\t\tannContext.lineTo((oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x), (oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y));\r\n\t\t\t\tannContext.strokeStyle = g_oAnnotations.getHexColour(g_oAnnotations.g_oAnnotationColSelected);\r\n\t\t\t\tannContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\tannContext.stroke();\r\n\t\t\t\tannContext.closePath();\r\n\r\n\t\t\t\t// Calculate the compare offset of the canvas.\r\n\t\t\t\tvar compareOffset_x, compareOffset_y;\r\n\t\t\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\t\t\tcompareOffset_x = co.x;\r\n\t\t\t\tcompareOffset_y = co.y;\r\n\r\n\t\t\t\t// Push each point in the coordinates to the array\r\n\t\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([(oAnnotationCanvas.g_iX - compareOffset_x) / oArtworkCanvas.g_iScaledImageWidth, (oAnnotationCanvas.g_iY - compareOffset_y) / oArtworkCanvas.g_iScaledImageHeight]);\r\n\t\t\t\toAnnotationCanvas.g_iOrigin_x = oAnnotationCanvas.g_iX;\r\n\t\t\t\toAnnotationCanvas.g_iOrigin_y = oAnnotationCanvas.g_iY;\r\n\r\n\t\t\t\t// If we have hit the maximum number of allowed points.\r\n\t\t\t\tif (g_oAnnotations.g_oTempAnnotationArray.length >= g_oAnnotations.g_iMaximumFreedrawAnnotationPoints) {\r\n\r\n\t\t\t\t\t// Call the pointer up event.\r\n\t\t\t\t\t$(\"#AnnotationViewer\").trigger(\"pointerup\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointermove\", g_oAnnotations.drawFreeDraw);\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointerup\");\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Changes the function of the canvas to draw a shape\r\n\t * @param {object} parentAnnotation - The parent annotation.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawInitiate = function (parentAnnotation, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t// Empty the temp array.\r\n\t\tg_oAnnotations.g_oTempAnnotationArray.length = 0;\r\n\r\n\t\t// Unbind the click event\r\n\t\tchangeCanvasFunction(\".annotationViewer\", \"click\");\r\n\r\n\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointerup\", function (event) {\r\n\t\t\tg_oAnnotations.annotationPointerUp(event, parentAnnotation, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t});\r\n\r\n\t\t// Reshow annotations if they are hidden.\r\n\t\tif (!g_oSettings.g_oUserSettings.ShowAnnotations) {\r\n\t\t\t$(\"#HideAnnotations\").click();\r\n\t\t}\r\n\r\n\t\tvar imageObjW = oArtworkCanvas.g_iScaledImageWidth;\r\n\t\tvar imageObjH = oArtworkCanvas.g_iScaledImageHeight;\r\n\t\tvar transformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas);\r\n\t\toAnnotationCanvas.g_iX = transformedClick[0];\r\n\t\toAnnotationCanvas.g_iY = transformedClick[1];\r\n\t\toAnnotationCanvas.g_iOrigin_x = oAnnotationCanvas.g_iX;\r\n\t\toAnnotationCanvas.g_iOrigin_y = oAnnotationCanvas.g_iY;\r\n\t\tswitch (g_oAnnotations.g_iAnnotationType) {\r\n\t\t\tcase eAnnotationTypes.Freedraw: // free draw\r\n\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove\", function (event) { g_oAnnotations.drawFreeDraw(event, oArtworkCanvas, oAnnotationCanvas); });\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Rectangle: // rectangle\r\n\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove\", function (event) { g_oAnnotations.drawRect(event, oArtworkCanvas, oAnnotationCanvas); });\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Ellipse: // ellipse\r\n\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove\", function (event) { g_oAnnotations.drawEllipse(event, oArtworkCanvas, oAnnotationCanvas); });\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Line: // line\r\n\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove\", function (event) { g_oAnnotations.drawLine(event, oArtworkCanvas, oAnnotationCanvas); });\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a global annotation.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawGlobal = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// Get the annotation context.\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\t// Ensure we're not beyond canvas boundaries.\r\n\t\tif ((oAnnotationCanvas.g_iX < oAnnotationCanvas.g_oCanvas.width - oArtworkCanvas.g_iCenterShift_x && oAnnotationCanvas.g_iX > oArtworkCanvas.g_iCenterShift_x)\r\n\t\t\t&& (oAnnotationCanvas.g_iY < oAnnotationCanvas.g_oCanvas.height - oArtworkCanvas.g_iCenterShift_y && oAnnotationCanvas.g_iY > oArtworkCanvas.g_iCenterShift_y)) {\r\n\r\n\t\t\t// Draw the rectangle.\r\n\t\t\tannContext.beginPath();\r\n\t\t\tannContext.rect(0 + oArtworkCanvas.g_iCenterShift_x, 0 + oArtworkCanvas.g_iCenterShift_y, oArtworkCanvas.g_iCompareImage_x, oArtworkCanvas.g_iCompareImage_y);\r\n\t\t\tannContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\tannContext.strokeStyle = g_oAnnotations.getHexColour(g_oAnnotations.g_oAnnotationColSelected);\r\n\t\t\tannContext.stroke();\r\n\r\n\t\t\t// Push the global co-ordinates to the temporary array.\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([0, 0]);\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([1, 1]);\r\n\t\t}\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").on(\"click\", g_oAnnotations.findAnnotation(event, oArtworkCanvas, oAnnotationCanvas));\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a line annotation\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawLine = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar coords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\t// Setup some variables to hold the Annotation/Artwork Canvas\r\n\t\tvar oAnnotationCanvasObject = oAnnotationCanvas.g_oCanvas;\r\n\r\n\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\toAnnotationCanvas.g_iY = coords[1];\r\n\r\n\t\t// Have we stayed within the bounds of the artwork\r\n\t\tif (oAnnotationCanvas.isClickWithinImageBounds(coords[0], coords[1], oArtworkCanvas, oAnnotationCanvas)) {\r\n\r\n\t\t\tvar transformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas);\r\n\r\n\t\t\toAnnotationCanvas.g_iX = transformedClick[0];\r\n\t\t\toAnnotationCanvas.g_iY = transformedClick[1];\r\n\r\n\t\t\tvar beginPoint_x = oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x;\r\n\t\t\tvar beginPoint_y = oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y;\r\n\t\t\tvar dist_x = oAnnotationCanvas.g_iX - oAnnotationCanvas.g_iOrigin_x;\r\n\t\t\tvar dist_y = oAnnotationCanvas.g_iY - oAnnotationCanvas.g_iOrigin_y;\r\n\r\n\t\t\tannContext.clearRect(0, 0, oAnnotationCanvasObject.width, oAnnotationCanvasObject.height);\r\n\t\t\t$(\".speechbubble\").hide();\r\n\t\t\tannContext.beginPath();\r\n\t\t\tannContext.moveTo(beginPoint_x, beginPoint_y);\r\n\t\t\tannContext.lineTo(beginPoint_x + dist_x, beginPoint_y + dist_y);\r\n\t\t\tannContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\tannContext.strokeStyle = g_oAnnotations.getHexColour(g_oAnnotations.g_oAnnotationColSelected);\r\n\t\t\tannContext.stroke();\r\n\t\t}\r\n\t\t// if not within bounds of canvas, we want to cancel the annotation draw.\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointermove\", g_oAnnotations.drawLine);\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointerup\");\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a post-it annotation on the canvas.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawPostit = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar coords, annContext;\r\n\t\t\r\n\t\tcoords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\r\n\t\t// Link to the Annotation Canvas\r\n\t\tannContext = oAnnotationCanvas.g_oContext;\r\n\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\toAnnotationCanvas.g_iY = coords[1];\r\n\r\n\t\t// Ensure we're not beyond canvas boundaries\r\n\t\tif (oAnnotationCanvas.isClickWithinImageBounds(coords[0], coords[1], oArtworkCanvas, oAnnotationCanvas)) {\r\n\r\n\t\t\tvar g_oTransformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas);\r\n\r\n\t\t\toAnnotationCanvas.g_iX = g_oTransformedClick[0];\r\n\t\t\toAnnotationCanvas.g_iY = g_oTransformedClick[1];\r\n\r\n\t\t\t// Draw Image is part of the HTML5 Canvas Specification.\r\n\t\t\tannContext.drawImage(g_oAnnotations.g_oPostitImg, oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x - g_oAnnotations.g_oPostitImg.widthOffset, oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y - g_oAnnotations.g_oPostitImg.heightOffset, this.g_oPostitImg.width, this.g_oPostitImg.height);\r\n\r\n\t\t\t// Calculate the compare offset of the canvas.\r\n\t\t\tvar compareOffset_x, compareOffset_y;\r\n\t\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\t\tcompareOffset_x = co.x;\r\n\t\t\tcompareOffset_y = co.y;\r\n\r\n\t\t\t// Push the point into the coordinates array.\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([(oAnnotationCanvas.g_iX - compareOffset_x) / oArtworkCanvas.g_iScaledImageWidth, (oAnnotationCanvas.g_iY - compareOffset_y) / oArtworkCanvas.g_iScaledImageHeight]);\r\n\t\t}\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").on(\"click\", g_oAnnotations.findAnnotation(event, oArtworkCanvas, oAnnotationCanvas));\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t* Draws a dashed line from an annotation or element to the pop-up when the pop-up is detached from the element via dragging etc.\r\n\t* @param {array} coordsOrig - The original coordinates\r\n\t* @param {array} coordinates - The new coordinates we've dragged the Div.\r\n\t* @param {string} annotationColour - The colour of the line\r\n\t*/\r\n\tAnnotationUI.prototype.drawLineToDiv = function (coordsOrig, coordinates, annotationColour, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// Grab the related canvases.\r\n\t\tvar relatedCanvas = oArtworkCanvas;\r\n\t\tvar relatedContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\tvar newXBegin = coordsOrig[0];\r\n\t\tvar newYBegin = coordsOrig[1];\r\n\t\tvar transformedCoords = g_oAnnotations.transformClickForRotation(parseInt(coordinates[0]), parseInt(coordinates[1]), relatedCanvas);\r\n\t\tvar newXEnd = transformedCoords[0] + relatedCanvas.g_iCenterShift_x;\r\n\t\tvar newYEnd = transformedCoords[1] + relatedCanvas.g_iCenterShift_y;\r\n\r\n\t\tvar beginPoint_x = newXBegin;\r\n\t\tvar beginPoint_y = newYBegin;\r\n\t\tvar dist_x = newXEnd - newXBegin;\r\n\t\tvar dist_y = newYEnd - newYBegin;\r\n\r\n\t\trelatedContext.save();\r\n\t\trelatedContext.beginPath();\r\n\t\trelatedContext.moveTo(beginPoint_x, beginPoint_y);\r\n\t\trelatedContext.lineTo(beginPoint_x + dist_x, beginPoint_y + dist_y);\r\n\t\trelatedContext.lineWidth = this.g_iAnnotationDivLineWidth;\r\n\t\trelatedContext.strokeStyle = annotationColour;\r\n\t\trelatedContext.setLineDash(this.g_iAnnotationDivLineDash);\r\n\t\trelatedContext.stroke();\r\n\t\trelatedContext.restore();\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a line to a 3D Annotation\r\n\t * @param {array} divCoords - The co-ordinates of the Div we are drawing a line to.\r\n\t * @param {object} annotation - The Annotation we are drawing the line to.\r\n\t */\r\n\tAnnotationUI.prototype.drawLineTo3DAnnotation = function (divCoords, annotation, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar geometry = new THREE.Geometry();\r\n\t\tgeometry.vertices.push(\r\n\t\t\tnew THREE.Vector3(annotation.g_oDrawArray[0][0], annotation.g_oDrawArray[0][1], annotation.g_oDrawArray[0][2]),\r\n\t\t\tnew THREE.Vector3((divCoords[0] / oArtworkCanvas.g_oCanvas.clientWidth) * 2 - 1,\r\n\t\t\t\t-(divCoords[1] / oArtworkCanvas.g_oCanvas.clientHeight) * 2 + 1,\r\n\t\t\t\t0.5)\r\n\t\t\t\t.unproject(oArtworkCanvas.g_oCamera));\r\n\r\n\t\tgeometry.computeLineDistances();\r\n\t\tgeometry.lineDistancesNeedUpdate = true;\r\n\t\tvar material = new THREE.LineDashedMaterial({ color: annotation.g_szColour, dashSize: 200, gapSize: 200, linewidth: 2 });\r\n\t\tvar line = new THREE.Line(geometry, material);\r\n\t\tline.class = \"annLine\";\r\n\t\tline.Id = \"fake\";\r\n\t\toArtworkCanvas.g_oScene.add(line);\r\n\t};\r\n\r\n\t/**\r\n\t * Draws a rectangle annotation on the canvas.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.drawRect = function (event, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\tvar coords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\r\n\t\t// Get the annotation canvas object.\r\n\t\tvar oAnnotationCanvasObject = oAnnotationCanvas.g_oCanvas;\r\n\r\n\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\toAnnotationCanvas.g_iY = coords[1];\r\n\r\n\t\t// Have we stayed within the bounds of the artwork\r\n\t\tif (oAnnotationCanvas.isClickWithinImageBounds(coords[0], coords[1], oArtworkCanvas, oAnnotationCanvas)) {\r\n\r\n\t\t\tvar transformedClick = g_oAnnotations.transformClickForRotation(oAnnotationCanvas.g_iX, oAnnotationCanvas.g_iY, oArtworkCanvas, oAnnotationCanvasObject);\r\n\t\t\toAnnotationCanvas.g_iX = transformedClick[0];\r\n\t\t\toAnnotationCanvas.g_iY = transformedClick[1];\r\n\r\n\t\t\tg_oAnnotations.setAnnotationRectangle(oAnnotationCanvas, oArtworkCanvas, oAnnotationCanvasObject);\r\n\t\t}\r\n\t\t// If not within bounds of canvas, we want to cancel the annotation draw.\r\n\t\telse {\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointermove\", g_oAnnotations.drawRect);\r\n\t\t\t$(\"#AnnotationViewer\").off(\"pointerup\");\r\n\t\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\t\tg_oAnnotations.redrawAnnotations(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Draws the annotation rectangle shape onto the canvas.\r\n\t * @param oAnnotationCanvas {object} - The annotation viewer.\r\n\t * @param oArtworkCanvas {object} - The artwork viewer.\r\n\t * @param oAnnotationCanvasObject {object} - The annotation canvas object.\r\n\t */\r\n\tAnnotationUI.prototype.setAnnotationRectangle = function (oAnnotationCanvas, oArtworkCanvas, oAnnotationCanvasObject) {\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\tvar beginPoint_x = Math.min(oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x, oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x);\r\n\t\tvar beginPoint_y = Math.min(oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y, oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y);\r\n\t\tvar dist_x = Math.abs((oAnnotationCanvas.g_iOrigin_x + oArtworkCanvas.g_iCenterShift_x) - (oAnnotationCanvas.g_iX + oArtworkCanvas.g_iCenterShift_x));\r\n\t\tvar dist_y = Math.abs((oAnnotationCanvas.g_iOrigin_y + oArtworkCanvas.g_iCenterShift_y) - (oAnnotationCanvas.g_iY + oArtworkCanvas.g_iCenterShift_y));\r\n\r\n\t\tannContext.clearRect(0, 0, oAnnotationCanvasObject.width, oAnnotationCanvasObject.height);\r\n\t\t$(\".speechbubble\").hide();\r\n\r\n\t\tannContext.beginPath();\r\n\t\tannContext.rect(beginPoint_x, beginPoint_y, dist_x, dist_y);\r\n\t\tannContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\tannContext.strokeStyle = g_oAnnotations.getHexColour(g_oAnnotations.g_oAnnotationColSelected);\r\n\t\tannContext.stroke();\r\n\t};\r\n\r\n\r\n\t/**\r\n\t * Gets the click coordinates.\r\n\t * @param {e} event - Click event.\r\n\t * @returns {array} - Array representing the co-ordinates.\r\n\t */\r\n\tAnnotationUI.prototype.getClick = function (event, oCanvas) {\r\n\t\tvar x, y;\r\n\t\tvar rectLeft = 0;\r\n\t\tvar rectTop = 0;\r\n\r\n\t\t// add a check if we are IE as there is a known bug with getBoundingClientRect.\r\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Browser_compatibility\r\n\t\tif (!isIE() || $(\"#annotationDropDown\").exists()) {\r\n\t\t\tvar rect = oCanvas.g_oCanvas.getBoundingClientRect();\r\n\t\t\trectLeft = rect.left;\r\n\t\t\trectTop = rect.top;\r\n\t\t}\r\n\r\n\t\tif (event.clientX != undefined && event.clientY != undefined) {\r\n\t\t\tx = event.clientX - rectLeft;\r\n\t\t\ty = event.clientY - rectTop;\r\n\t\t}\r\n\t\t// Firefox method to get the position.\r\n\t\telse {\r\n\t\t\tvar baseCanvas = \"AnnotationViewer\";\r\n\t\t\tif (this === oCanvas.g_oNavCanvasOver) {\r\n\t\t\t\tbaseCanvas = \"navCanvasOverlay\";\r\n\t\t\t}\r\n\t\t\tx = (event.clientX + document.body.scrollLeft +\r\n\t\t\t\tdocument.documentElement.scrollLeft +\r\n\t\t\t\tdocument.getElementById(baseCanvas).scrollLeft)\r\n\t\t\t\t- rectLeft;\r\n\t\t\ty = (event.clientY + document.body.scrollTop +\r\n\t\t\t\tdocument.getElementById(baseCanvas).scrollTop +\r\n\t\t\t\tdocument.documentElement.scrollTop)\r\n\t\t\t\t- rectTop;\r\n\t\t}\r\n\r\n\t\t// Factor in the users DPI for the click co-ordinates.\r\n\t\tx *= g_oViewer.c_iDPI;\r\n\t\ty *= g_oViewer.c_iDPI;\r\n\r\n\t\treturn [x, y];\r\n\t};\r\n\r\n\t/**\r\n\t * Helper method to get the hex colour from a string.\r\n\t * @param {string} The string colour\r\n\t * @returns {string} - The colour in hex code.\r\n\t */\r\n\tAnnotationUI.prototype.getHexColour = function (colour) {\r\n\t\tvar szHexColour = \"\";\r\n\t\t\r\n\t\tswitch (colour) {\r\n\t\t\tcase \"blue\":\r\n\t\t\t\tszHexColour = eAnnotationColours.blue;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"red\":\r\n\t\t\t\tszHexColour = eAnnotationColours.red;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"green\":\r\n\t\t\t\tszHexColour = eAnnotationColours.green;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"orange\":\r\n\t\t\t\tszHexColour = eAnnotationColours.orange;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"purple\":\r\n\t\t\t\tszHexColour = eAnnotationColours.purple;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"cyan\":\r\n\t\t\t\tszHexColour = eAnnotationColours.cyan;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"magenta\":\r\n\t\t\t\tszHexColour = eAnnotationColours.magenta;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"yellow\":\r\n\t\t\t\tszHexColour = eAnnotationColours.yellow;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"grey\":\r\n\t\t\t\tszHexColour = eAnnotationColours.grey;\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tszHexColour = colour;\r\n\t\t}\r\n\r\n\t\treturn szHexColour;\r\n\t};\r\n\r\n\t/**\r\n\t * Helper method to get the string colour from a Hexadecimal value.\r\n\t * @param {string} The colour in Hex\r\n\t * @returns {string} - The colour string.\r\n\t */\r\n\tAnnotationUI.prototype.getStringColour = function (hexColour) {\r\n\t\tvar szStringColour = \"\";\r\n\r\n\t\tswitch (hexColour.toUpperCase()) {\r\n\t\t\tcase \"#0000FF\":\r\n\t\t\t\tszStringColour = \"blue\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#FF0000\":\r\n\t\t\t\tszStringColour = \"red\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#008000\":\r\n\t\t\t\tszStringColour = \"green\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#FFA500\":\r\n\t\t\t\tszStringColour = \"orange\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#800080\":\r\n\t\t\t\tszStringColour = \"purple\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#00FFFF\":\r\n\t\t\t\tszStringColour = \"cyan\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#FF00FF\":\r\n\t\t\t\tszStringColour = \"magenta\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#FFFF00\":\r\n\t\t\t\tszStringColour = \"yellow\";\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"#999999\":\r\n\t\t\t\tszStringColour = \"grey\";\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\t// In this case, the colour may already the correct string, so leave it be.\r\n\t\t\t\tszStringColour = hexColour;\r\n\t\t}\r\n\r\n\t\treturn szStringColour;\r\n\t};\r\n\r\n\t/**\r\n\t * Helper method to get the string statuses from an annotation status array.\r\n\t * @param {object} oStatuses - The statuses array.\r\n\t * @returns {string} - The statuses string.\r\n\t */\r\n\tAnnotationUI.prototype.getStringStatuses = function (oStatuses) {\r\n\r\n\t\t// Outline the string statuses to be returned.\r\n\t\tvar szStatuses = \"\";\r\n\r\n\t\t// If there are no statuses.\r\n\t\tif (oStatuses.length == 0) {\r\n\t\t\tszStatuses = \"Initial\"\r\n\t\t}\r\n\t\t// If there are statuses.\r\n\t\telse {\r\n\r\n\t\t\t// Loop through each of the annotation statuses and add the status string.\r\n\t\t\tfor (var i = 0; i < oStatuses.length; i++) {\r\n\t\t\t\tswitch (oStatuses[i].g_iAnnotationStatus) {\r\n\t\t\t\t\tcase 1:\r\n\t\t\t\t\t\tszStatuses += (i > 0 ? \", \" : \"\") + \"Approved\";\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 2:\r\n\t\t\t\t\t\tszStatuses += (i > 0 ? \", \" : \"\") + \"Rejected\";\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 3:\r\n\t\t\t\t\t\tszStatuses += (i > 0 ? \", \" : \"\") + \"Query\";\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 4:\r\n\t\t\t\t\t\tszStatuses += (i > 0 ? \", \" : \"\") + \"ToDo\";\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Return the result.\r\n\t\treturn szStatuses;\r\n\t};\r\n\r\n\t/*\r\n\t * Gets the users annotations.\r\n\t * @param {int} UserId - Gets the users annotations.\r\n\t * @returns {AnnotationArray} - Array of annotation objects.\r\n\t **/\r\n\tAnnotationUI.prototype.getUserAnnotations = function (UserId) {\r\n\t\treturn $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return UserId == annotation.g_iAuthor; }) || [];\r\n\t};\r\n\r\n\t/**\r\n\t * Gets the translation vector sign, depending if the coordinate value is +ve/-ve\r\n\t * @param {float} coordValue - The co-ordinate to check\r\n\t * @returns {float} - The translation value.\r\n\t */\r\n\tAnnotationUI.prototype.getTranslationValues = function (coordValue) {\r\n\t\tif (coordValue > 0) {\r\n\t\t\treturn 0.004;\r\n\t\t}\r\n\t\telse {\r\n\t\t\treturn -0.008;\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Finds the annotations on the canvas.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oArtworkCanvas - The Artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t * @param {bool} bHover - Whether it's a click or a hover.\r\n\t */\r\n\tAnnotationUI.prototype.findAnnotation = function (event, oArtworkCanvas, oAnnotationCanvas, bHover) {\r\n\t\tbHover = (typeof (bHover) === \"undefined\") ? false : bHover;\r\n\t\t\r\n\t\t// Set that we have not yet found an annotation.\r\n\t\tg_oAnnotations.g_bAnnotationsFound = false;\r\n\r\n\t\t// Don't want to find annotations if we are currently highlighting text.\r\n\t\tif (g_oTextTools.g_bHighlightInProgress) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Don't want to find annotations if we are in text compare, we only want to find handles on click.\r\n\t\tif (g_oTextCompare.g_bTextCompareInProgress) {\r\n\t\t\tif (!bHover) {\r\n\t\t\t\tg_oTextCompare.checkHandleClicked(event, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t}\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Don't want to find annotations if they aren't visible.\r\n\t\tif (g_oSettings.g_oUserSettings.ShowAnnotations === false) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Don't want to find annotations if this isn't the active annotation canvas.\r\n\t\tif (g_oCompare.getAnnotationCanvasId() != oAnnotationCanvas.g_szCanvasId) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Don't want to find annotations if we have unsaved annotations.\r\n\t\tif (g_oAnnotations.checkForUnsavedAnnotation()) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Get the compare offset of the artwork canvas.\r\n\t\tvar compareOffset_x, compareOffset_y;\r\n\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\tcompareOffset_x = co.x;\r\n\t\tcompareOffset_y = co.y;\r\n\r\n\t\t// Get the compare rotation of the canvas.\r\n\t\tvar iCompareRotation = g_oCompare.getCompareRotation(oArtworkCanvas);\r\n\r\n\t\t// Note: Should this be the annotation canvas???\r\n\t\toAnnotationCanvas = oArtworkCanvas;\r\n\t\tvar x, y;\r\n\t\t$(\"#annotationDropDown\").slideUp(200);\r\n\t\tvar relatedArtworkCanvas = oArtworkCanvas;\r\n\r\n\t\tvar coords = g_oAnnotations.getClick(event, oAnnotationCanvas);\r\n\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\tcoords = this.transformClickForRotation(coords[0], coords[1], oAnnotationCanvas);\r\n\t\t\tcoords[0] += relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x;\r\n\t\t\tcoords[1] += relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y;\r\n\t\t}\r\n\r\n\t\t// Determine the co-ordinates.\r\n\t\tx = coords[0];\r\n\t\ty = coords[1];\r\n\r\n\t\t// Get the image width and height.\r\n\t\tvar imageObjW = relatedArtworkCanvas.g_iScaledImageWidth;\r\n\t\tvar imageObjH = relatedArtworkCanvas.g_iScaledImageHeight;\r\n\r\n\t\t// If we have a compare rotation of 90 or 270, swap the image width and height.\r\n\t\tif (iCompareRotation == 90 || iCompareRotation == 270) {\r\n\t\t\timageObjW = relatedArtworkCanvas.g_iScaledImageHeight;\r\n\t\t\timageObjH = relatedArtworkCanvas.g_iScaledImageWidth;\r\n\t\t}\r\n\r\n\t\t// Get the annotation context.\r\n\t\tvar annContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\tif (typeof annContext === \"undefined\") {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t// If this is a mobile browser, multiply the tolerance to allow for less accurate finger press vs mouse.\r\n\t\t// Each browser has a slightly different way of doing this.\r\n\t\tvar dTolerance = 0.02 / oAnnotationCanvas.g_iZoomLevel;\r\n\r\n\t\tif (\r\n\t\t\t/*Firefox*/ (event.originalEvent && event.originalEvent.mozInputSource === 5) ||\r\n\t\t\t/*Chrome*/ (event.originalEvent && event.originalEvent.sourceCapabilities && event.originalEvent.sourceCapabilities.firesTouchEvents) ||\r\n\t\t\t/*IE / Edge*/ (event.originalEvent && event.originalEvent.pointerType && event.originalEvent.pointerType === \"touch\")\r\n\t\t\t/*iOS Safari, regular Safari, Opera, Android etc - TODO*/\r\n\t\t) {\r\n\t\t\tdTolerance *= 3;\r\n\t\t}\r\n\r\n\t\tvar g_oFoundAnnotationStack = [];\r\n\r\n\t\t// Grab the document id.\r\n\t\tvar iDocumentId = 0;\r\n\t\tif (!$.isEmptyObject(oArtworkCanvas.g_oDoc)) {\r\n\t\t\tiDocumentId = oArtworkCanvas.g_oDoc.documentId;\r\n\t\t}\r\n\r\n\t\t// If we have more than one page, grab the page id by looping through the pages.\r\n\t\tvar iPageId = 0;\r\n\t\tif (!$.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\t\t\tfor (var i = 0; i < oArtworkCanvas.g_oDoc.pages.length; i++) {\r\n\t\t\t\tif (oArtworkCanvas.g_oDoc.pages[i].documentPageNumber == oArtworkCanvas.g_iCurrentPage) {\r\n\t\t\t\t\tiPageId = oArtworkCanvas.g_oDoc.pages[i].documentPageId;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Internet Explorer and Edge don't support CanvasRendering2DContext.isPointInStroke\r\n\t\t// There is a polyfill available from google that.. doesn't work.\r\n\t\t// Fall back by implementing individual calculation for each annotation type.\r\n\r\n\t\t// Post-it (type === 0)\r\n\t\tvar postitAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (postitAnnotations) {\r\n\t\t\treturn (postitAnnotations.g_iAnnotationType === eAnnotationTypes.Postit || postitAnnotations.g_iAnnotationType === eAnnotationTypes.ColourDensityMeasurementPostit) &&\r\n\t\t\t\t(iDocumentId == postitAnnotations.g_iDocumentId) && (iPageId == 0 || iPageId == postitAnnotations.g_iDocumentPageId) && (!postitAnnotations.g_bSVGHoverAnnotation && !postitAnnotations.g_bSVGSearchAnnotation);\r\n\t\t});\r\n\t\tfor (var postitAnn in postitAnnotations) {\r\n\t\t\t\r\n\t\t\t// Ensure we have the correct co-ordinates for the annotation.\r\n\t\t\tif (postitAnnotations[postitAnn].g_oDrawArray.length != 1) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\tcoords = [postitAnnotations[postitAnn].g_oDrawArray[0][0], postitAnnotations[postitAnn].g_oDrawArray[0][1]];\r\n\r\n\t\t\t// If the canvas has compare rotation.\r\n\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(coords[0], coords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\tcoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\tcoords[1] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t}\r\n\r\n\t\t\t// 13 / 3 are not magic numbers. They're the offset of the post-it image bounds from its point (where the click is centred).\r\n\t\t\tvar postitOffset = [3, 13];\r\n\t\t\tvar postitSize = 10;\r\n\r\n\t\t\t// Fall back for non-standards compliant IE / Edge.\r\n\t\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\t\tvar xCoords = [((coords[0] * imageObjW) - postitOffset[0]) / imageObjW, ((coords[0] * imageObjW) - postitOffset[0] + postitSize) / imageObjW];\r\n\t\t\t\tvar yCoords = [((coords[1] * imageObjH) - postitOffset[1]) / imageObjH, ((coords[1] * imageObjH) - postitOffset[1] + postitSize) / imageObjH];\r\n\t\t\t\tif (\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(postitAnnotations[postitAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.lineWidth = dTolerance * imageObjW;\r\n\t\t\t\tannContext.rect((coords[0] * imageObjW) + relatedArtworkCanvas.g_iCenterShift_x - postitOffset[0] + compareOffset_x, (coords[1] * imageObjH) + relatedArtworkCanvas.g_iCenterShift_y - postitOffset[1] + compareOffset_y, postitSize, postitSize);\r\n\t\t\t\tannContext.strokeStyle = \"rgba(0, 0, 0, 0)\";\r\n\t\t\t\tannContext.stroke();\r\n\t\t\t\tif (annContext.isPointInStroke(x, y)) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(postitAnnotations[postitAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Free draw (type === 1)\r\n\t\t// SVG Polygon (type === 17)\r\n\t\tvar freeDrawAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (freeDrawAnnotations) {\r\n\t\t\treturn (freeDrawAnnotations.g_iAnnotationType == eAnnotationTypes.Freedraw || freeDrawAnnotations.g_iAnnotationType == eAnnotationTypes.SVGPolygon) &&\r\n\t\t\t\t(iDocumentId == freeDrawAnnotations.g_iDocumentId) && (iPageId == 0 || iPageId == freeDrawAnnotations.g_iDocumentPageId) && (!freeDrawAnnotations.g_bSVGHoverAnnotation && !freeDrawAnnotations.g_bSVGSearchAnnotation);\r\n\t\t});\r\n\r\n\t\tfor (var freeDrawAnn in freeDrawAnnotations) {\r\n\t\t\tfor (var i = 0; i + 1 < freeDrawAnnotations[freeDrawAnn].g_oDrawArray.length; i++) {\r\n\r\n\t\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\t\tvar xCoords = [freeDrawAnnotations[freeDrawAnn].g_oDrawArray[i][0], freeDrawAnnotations[freeDrawAnn].g_oDrawArray[i + 1][0]];\r\n\t\t\t\tvar yCoords = [freeDrawAnnotations[freeDrawAnn].g_oDrawArray[i][1], freeDrawAnnotations[freeDrawAnn].g_oDrawArray[i + 1][1]];\r\n\r\n\t\t\t\t// If the canvas has compare rotation.\r\n\t\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(xCoords[0], yCoords[0], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\t\tvar oRotatedAnnotationDraw2 = oAnnotationCanvas.rotate(xCoords[1], yCoords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\t\txCoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\t\tyCoords[0] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\t\txCoords[1] = oRotatedAnnotationDraw2.rotated_x;\r\n\t\t\t\t\tyCoords[1] = oRotatedAnnotationDraw2.rotated_y;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\t\t\tif (g_oAnnotations.distToSegment({ x: x, y: y },\r\n\t\t\t\t\t\t{ x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)) {\r\n\t\t\t\t\t\tg_oFoundAnnotationStack.push(freeDrawAnnotations[freeDrawAnn]);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tannContext.beginPath();\r\n\t\t\t\t\tannContext.moveTo(xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x, yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y);\r\n\t\t\t\t\tannContext.lineWidth = dTolerance * imageObjW;\r\n\t\t\t\t\tannContext.lineTo(xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x, yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y);\r\n\t\t\t\t\tannContext.strokeStyle = \"rgba(0, 0, 0, 0)\";\r\n\t\t\t\t\tannContext.stroke();\r\n\t\t\t\t\tif (annContext.isPointInStroke(x, y)) {\r\n\t\t\t\t\t\tg_oFoundAnnotationStack.push(freeDrawAnnotations[freeDrawAnn]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Rectangle (type === 2), Global (type === 5), Text Measurement (type === 7),\r\n\t\t// Barcode Measurement (type === 13), Colour Density Measurement (type === 14),\r\n\t\t// SVG Rectangle (type === 15)\r\n\t\tvar rectangleAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (rectangleAnnotations) {\r\n\t\t\treturn (rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.Rectangle\r\n\t\t\t\t|| rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.TextMeasurement\r\n\t\t\t\t|| rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.TextHighlight\r\n\t\t\t\t|| rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.TextClassification\r\n\t\t\t\t|| rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.BarcodeMeasurement\r\n\t\t\t\t|| rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.ColourDensityMeasurement\r\n || rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.SVGRectangle\r\n || rectangleAnnotations.g_iAnnotationType === eAnnotationTypes.Global) &&\r\n // Rectangle but zeroed co-ordinates.\r\n (iDocumentId == rectangleAnnotations.g_iDocumentId) && (iPageId == 0 || iPageId == rectangleAnnotations.g_iDocumentPageId) &&\r\n (!rectangleAnnotations.g_bSVGHoverAnnotation && !rectangleAnnotations.g_bSVGSearchAnnotation);\r\n });\r\n for (var rectAnn in rectangleAnnotations) {\r\n\r\n\t\t\t// Ensure we have the correct co-ordinates for the annotation.\r\n\t\t\tif (rectangleAnnotations[rectAnn].g_oDrawArray.length != 2) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\tvar xCoords = [rectangleAnnotations[rectAnn].g_oDrawArray[0][0], rectangleAnnotations[rectAnn].g_oDrawArray[1][0]];\r\n\t\t\tvar yCoords = [rectangleAnnotations[rectAnn].g_oDrawArray[0][1], rectangleAnnotations[rectAnn].g_oDrawArray[1][1]];\r\n\r\n\t\t\t// Sort the co-ordinates of the annotation.\r\n\t\t\txCoords.sort();\r\n\t\t\tyCoords.sort();\r\n\r\n\t\t\t// If the canvas has compare rotation.\r\n\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(xCoords[0], yCoords[0], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\tvar oRotatedAnnotationDraw2 = oAnnotationCanvas.rotate(xCoords[1], yCoords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\txCoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\tyCoords[0] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\txCoords[1] = oRotatedAnnotationDraw2.rotated_x;\r\n\t\t\t\tyCoords[1] = oRotatedAnnotationDraw2.rotated_y;\r\n\t\t\t}\r\n\r\n\t\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\t\tif (\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t\t||\r\n\t\t\t\t\tg_oAnnotations.distToSegment({ x: x, y: y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)\r\n\t\t\t\t) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(rectangleAnnotations[rectAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.lineWidth = dTolerance * imageObjW;\r\n\t\t\t\tannContext.rect(xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x, yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y, (xCoords[1] - xCoords[0]) * imageObjW, (yCoords[1] - yCoords[0]) * imageObjH);\r\n\t\t\t\tannContext.strokeStyle = \"rgba(0, 0, 0, 0)\";\r\n\t\t\t\tannContext.stroke();\r\n\t\t\t\tif (annContext.isPointInStroke(x, y)) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(rectangleAnnotations[rectAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Ellipse (type === 3)\r\n\t\t// SVG Ellipse (type === 16)\r\n\t\tvar ellipseAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (ellipseAnnotations) {\r\n\t\t\treturn (ellipseAnnotations.g_iAnnotationType == eAnnotationTypes.Ellipse || ellipseAnnotations.g_iAnnotationType == eAnnotationTypes.SVGEllipse) &&\r\n\t\t\t\t(iDocumentId == ellipseAnnotations.g_iDocumentId) && (iPageId == 0 || iPageId == ellipseAnnotations.g_iDocumentPageId) && (!ellipseAnnotations.g_bSVGHoverAnnotation && !ellipseAnnotations.g_bSVGSearchAnnotation);\r\n\t\t});\r\n\t\tfor (var ellipseAnn in ellipseAnnotations) {\r\n\r\n\t\t\t// Ensure we have the correct co-ordinates for the annotation.\r\n\t\t\tif (ellipseAnnotations[ellipseAnn].g_oDrawArray.length != 2) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\tvar xCoords = [ellipseAnnotations[ellipseAnn].g_oDrawArray[0][0], ellipseAnnotations[ellipseAnn].g_oDrawArray[1][0]];\r\n\t\t\tvar yCoords = [ellipseAnnotations[ellipseAnn].g_oDrawArray[0][1], ellipseAnnotations[ellipseAnn].g_oDrawArray[1][1]];\r\n\r\n\t\t\t// Sort the co-ordinates of the annotation.\r\n\t\t\txCoords.sort();\r\n\t\t\tyCoords.sort();\r\n\r\n\t\t\t// If the canvas has compare rotation.\r\n\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(xCoords[0], yCoords[0], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\tvar oRotatedAnnotationDraw2 = oAnnotationCanvas.rotate(xCoords[1], yCoords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\txCoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\tyCoords[0] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\txCoords[1] = oRotatedAnnotationDraw2.rotated_x;\r\n\t\t\t\tyCoords[1] = oRotatedAnnotationDraw2.rotated_y;\r\n\t\t\t}\r\n\r\n\t\t\tvar beginPoint_x = xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x;\r\n\t\t\tvar beginPoint_y = yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y;\r\n\t\t\tvar endPoint_x = xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x;\r\n\t\t\tvar endPoint_y = yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y;\r\n\t\t\tvar dist_x = endPoint_x - beginPoint_x;\r\n\t\t\tvar dist_y = endPoint_y - beginPoint_y;\r\n\t\t\tvar halfPoint_x = beginPoint_x + (dist_x / 2);\r\n\t\t\tvar halfPoint_y = beginPoint_y + (dist_y / 2);\r\n\r\n\t\t\tvar width_two_thirds = dist_x * 2 / 3;\r\n\t\t\tvar height_over_2 = dist_y / 2;\r\n\r\n\t\t\t// Microsoft: Web Browsers? No.\r\n\t\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\t\t// We need to detect a point on the Bézier curve.\r\n\t\t\t\t// There are actually two making the ellipse.\r\n\t\t\t\t// Define the Bézier curve control points into an object.\r\n\t\t\t\tvar rightHandCurvePoints = [{ x: halfPoint_x, y: beginPoint_y }, { x: halfPoint_x + width_two_thirds, y: halfPoint_y - height_over_2 }, { x: halfPoint_x + width_two_thirds, y: halfPoint_y + height_over_2 }, { x: halfPoint_x, y: halfPoint_y + height_over_2 }];\r\n\t\t\t\tvar leftHandCurvePoints = [{ x: halfPoint_x, y: halfPoint_y + height_over_2 }, { x: halfPoint_x - width_two_thirds, y: halfPoint_y + height_over_2 }, { x: halfPoint_x - width_two_thirds, y: halfPoint_y - height_over_2 }, { x: halfPoint_x, y: halfPoint_y - height_over_2 }];\r\n\r\n\t\t\t\tvar result = g_oAnnotations.calculateClosestPointAlongBezierCurve(rightHandCurvePoints, { x: x - compareOffset_x, y: y - compareOffset_y }, dTolerance * ((imageObjW / 2) + (compareOffset_x / 2)));\r\n\t\t\t\tif (!result) {\r\n\t\t\t\t\tresult = g_oAnnotations.calculateClosestPointAlongBezierCurve(leftHandCurvePoints, { x: x - compareOffset_x, y: y - compareOffset_y }, dTolerance * ((imageObjW / 2) + (compareOffset_x / 2)));\r\n\t\t\t\t}\r\n\t\t\t\tif (result) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(ellipseAnnotations[ellipseAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.moveTo(halfPoint_x, beginPoint_y);\r\n\t\t\t\tannContext.lineWidth = dTolerance * imageObjW;\r\n\t\t\t\tannContext.strokeStyle = \"rgba(0,0,0,0)\";\r\n\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.moveTo(halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\t\tannContext.bezierCurveTo(halfPoint_x + width_two_thirds, halfPoint_y - height_over_2, halfPoint_x + width_two_thirds, halfPoint_y + height_over_2, halfPoint_x, halfPoint_y + height_over_2);\r\n\t\t\t\tannContext.bezierCurveTo(halfPoint_x - width_two_thirds, halfPoint_y + height_over_2, halfPoint_x - width_two_thirds, halfPoint_y - height_over_2, halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\t\tannContext.closePath();\r\n\t\t\t\tannContext.stroke();\r\n\r\n\t\t\t\tif (annContext.isPointInStroke(x, y)) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(ellipseAnnotations[ellipseAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Line (type === 4)\r\n\t\tvar lineAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (lineAnnotations) {\r\n\t\t\treturn (lineAnnotations.g_iAnnotationType == eAnnotationTypes.Line) &&\r\n\t\t\t\t(iDocumentId == lineAnnotations.g_iDocumentId) && (iPageId == 0 || iPageId == lineAnnotations.g_iDocumentPageId) && (!lineAnnotations.g_bSVGHoverAnnotation && !lineAnnotations.g_bSVGSearchAnnotation);\r\n\t\t});\r\n\t\tfor (var lineAnn in lineAnnotations) {\r\n\r\n\t\t\t// Ensure we have the correct co-ordinates for the annotation.\r\n\t\t\tif (lineAnnotations[lineAnn].g_oDrawArray.length != 2) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\tvar xCoords = [lineAnnotations[lineAnn].g_oDrawArray[0][0], lineAnnotations[lineAnn].g_oDrawArray[1][0]];\r\n\t\t\tvar yCoords = [lineAnnotations[lineAnn].g_oDrawArray[0][1], lineAnnotations[lineAnn].g_oDrawArray[1][1]];\r\n\r\n\t\t\t// If the canvas has compare rotation.\r\n\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(xCoords[0], yCoords[0], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\tvar oRotatedAnnotationDraw2 = oAnnotationCanvas.rotate(xCoords[1], yCoords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\txCoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\tyCoords[0] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\txCoords[1] = oRotatedAnnotationDraw2.rotated_x;\r\n\t\t\t\tyCoords[1] = oRotatedAnnotationDraw2.rotated_y;\r\n\t\t\t}\r\n\r\n\t\t\t// Boo, IE and Edge.\r\n\t\t\tif (typeof CanvasRenderingContext2D.prototype.isPointInStroke === \"undefined\") {\r\n\t\t\t\tif (g_oAnnotations.distToSegment({ x: x, y: y },\r\n\t\t\t\t\t{ x: xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }, { x: xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x + compareOffset_x, y: yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y + compareOffset_y }) < dTolerance * (imageObjW + compareOffset_x)) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(lineAnnotations[lineAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tannContext.beginPath();\r\n\t\t\t\tannContext.moveTo(xCoords[0] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x, yCoords[0] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y);\r\n\t\t\t\tannContext.lineWidth = dTolerance * imageObjW;\r\n\t\t\t\tannContext.lineTo(xCoords[1] * imageObjW + relatedArtworkCanvas.g_iCenterShift_x + compareOffset_x, yCoords[1] * imageObjH + relatedArtworkCanvas.g_iCenterShift_y + compareOffset_y);\r\n\t\t\t\tannContext.strokeStyle = \"rgba(0, 0, 0, 0)\";\r\n\t\t\t\tannContext.stroke();\r\n\t\t\t\tif (annContext.isPointInStroke(x, y)) {\r\n\t\t\t\t\tg_oFoundAnnotationStack.push(lineAnnotations[lineAnn]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Loop through the found annotations.\r\n\t\tfor (var ann in g_oFoundAnnotationStack) {\r\n\r\n\t\t\t// Only worry about the divs if it's a click, not a hover\r\n\t\t\tif (!bHover) {\r\n\t\t\t\t// If this a shape, find the parent.\r\n\t\t\t\tif (g_oFoundAnnotationStack[ann].g_iParentAnnotationId !== 0) {\r\n\t\t\t\t\tvar oParentAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return annotation.id == g_oFoundAnnotationStack[ann].g_iParentAnnotationId; });\r\n\t\t\t\t\tvar parentDiv = $(\"#\" + oParentAnnotation[0].id + \".speechbubble\");\r\n\t\t\t\t\t// Only create the div if it doesn't exist.\r\n\t\t\t\t\tif (parentDiv.length === 0) {\r\n\t\t\t\t\t\toParentAnnotation[0].createAnnotationDiv(eAnnotationDivType.Popup, true, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tvar annotationDiv = $(\"#\" + g_oFoundAnnotationStack[ann].id + \".speechbubble\");\r\n\t\t\t\t\t// Only create the div if it doesn't exist.\r\n\t\t\t\t\tif (annotationDiv.length === 0) {\r\n\r\n\t\t\t\t\t\t// If this is a text measurement and we do not have the highlighted text.\r\n\t\t\t\t\t\tif (g_oFoundAnnotationStack[ann].g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t\t\t\tg_oFoundAnnotationStack[ann].g_oTextMeasurementWordsArray = [];\r\n\t\t\t\t\t\t\tvar oData = {\r\n\t\t\t\t\t\t\t\toAnnotation: g_oFoundAnnotationStack[ann],\r\n\t\t\t\t\t\t\t\toArtworkCanvas: oArtworkCanvas,\r\n\t\t\t\t\t\t\t\toAnnotationCanvas: oAnnotationCanvas\r\n\t\t\t\t\t\t\t};\r\n\t\t\t\t\t\t\tEventService.publish(\"getTextMeasurementText\", oData);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tg_oFoundAnnotationStack[ann].createAnnotationDiv(eAnnotationDivType.Popup, true, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\t$(\"#\" + g_oFoundAnnotationStack[ann].id).remove();\r\n\t\t\t\t\t\tg_oFoundAnnotationStack[ann].g_bClosed = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Set that an annotation has been found.\r\n\t\t\tg_oAnnotations.g_bAnnotationsFound = true;\r\n\t\t}\r\n\r\n\t\t// If annotations were found, redraw the annotation canvas.\r\n\t\tif (g_oAnnotations.g_bAnnotationsFound) {\r\n\t\t\tif (!bHover) { // Only redraw if not hovering, but clicking\r\n\t\t\t\toAnnotationCanvas.redraw(false);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If this is an SVG document, and we are finding SVG text.\r\n\t\tif (documentDisplaysAsSVG(g_oViewer.g_oArtworkViewer.g_oDoc.documentType) && g_oViewer.c_bFindSVGText) {\r\n\r\n\t\t\t// If no annotations were found.\r\n\t\t\tif (!g_oAnnotations.g_bAnnotationsFound) {\r\n\r\n\t\t\t\t// If this is a hover event.\r\n\t\t\t\tif (bHover) {\r\n\r\n\t\t\t\t\t// Hover SVG text.\r\n\t\t\t\t\tg_oSVGText.hoverSVGText(event, oArtworkCanvas, oArtworkCanvas.g_oAnnotationCanvas);\r\n\t\t\t\t}\r\n\t\t\t\t// If this is a click event.\r\n\t\t\t\telse {\r\n\r\n\t\t\t\t\t// Find SVG text.\r\n\t\t\t\t\tg_oSVGText.findSVGText(event, oArtworkCanvas, oArtworkCanvas.g_oAnnotationCanvas);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// If annotations were found.\r\n\t\t\telse {\r\n\r\n\t\t\t\t// Remove any existing hover annotations.\r\n\t\t\t\tg_oSVGText.removeSVGHoverAnnotations(oArtworkCanvas, oArtworkCanvas.g_oAnnotationCanvas, true);\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Finds a 3D Annotation on the canvas.\r\n\t * @param {type} e - The JavaScript event\r\n\t * @param {type} oCanvas - The Canvas we are passing in.\r\n\t */\r\n\tAnnotationUI.prototype.findThreeDAnnotations = function (e, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t// There is no Annotation Canvas in 3D, use the Artwork viewer.\r\n\t\tvar oCoords = g_oAnnotations.getClick(e, oArtworkCanvas);\r\n\r\n\t\tif (!(typeof oArtworkCanvas.g_oMouseVector === \"undefined\")) {\r\n\r\n\t\t\toCoords[0] /= g_oViewer.c_iDPI;\r\n\t\t\toCoords[1] /= g_oViewer.c_iDPI;\r\n\r\n\t\t\toArtworkCanvas.g_oMouseVector.x = (oCoords[0] / oArtworkCanvas.g_oCanvas.clientWidth) * 2 - 1;\r\n\t\t\toArtworkCanvas.g_oMouseVector.y = -(oCoords[1] / oArtworkCanvas.g_oCanvas.clientHeight) * 2 + 1;\r\n\r\n\t\t\toArtworkCanvas.g_oRaycaster.setFromCamera(oArtworkCanvas.g_oMouseVector, oArtworkCanvas.g_oCamera);\r\n\r\n\t\t\t// Check if we have any points.\r\n\t\t\tvar oIntersects = oArtworkCanvas.g_oRaycaster.intersectObjects(oArtworkCanvas.g_oScene.children, true);\r\n\r\n\t\t\tif (oIntersects != null && oIntersects.length > 0) {\r\n\t\t\t\t// We have a hit. But did we click on an annotation or on the 3d object?\r\n\t\t\t\t// The coordinates of the texture may be of interest if we try to equate annotations in the 3D context to 2D and vice versa.\r\n\t\t\t\tfor (var i = 0; i < oIntersects.length; i++) {\r\n\t\t\t\t\tif (oIntersects[i].object.Id > 0 && oIntersects[i].object.Id !== \"fake\") {\r\n\t\t\t\t\t\tvar iFoundAnnotationId = oIntersects[i].object.Id;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (iFoundAnnotationId !== undefined && iFoundAnnotationId > 0) {\r\n\t\t\t\t\t// We clicked on an annotation. Show a pop-up if one doesn't already exist.\r\n\t\t\t\t\tvar oMatchingAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return annotation.id === iFoundAnnotationId && annotation.g_iAnnotationType === eAnnotationTypes.ThreeD; });\r\n\r\n\t\t\t\t\t// If we clicked on an additional shape then open the div on the parent.\r\n\t\t\t\t\tif (oMatchingAnnotation[0].g_iParentAnnotationId > 0) {\r\n\t\t\t\t\t\toMatchingAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return annotation.id === oMatchingAnnotation[0].g_iParentAnnotationId && annotation.g_iAnnotationType === eAnnotationTypes.ThreeD; });\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tvar annotationDiv = $(\"#\" + oMatchingAnnotation[0].id + \".speechbubble\");\r\n\t\t\t\t\tif (annotationDiv.length === 0) {\r\n\t\t\t\t\t\toMatchingAnnotation[0].createAnnotationDiv(eAnnotationDivType.Popup, true, oCoords, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\tAnnotationUI.prototype.repositionSpeechBubbles(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Sets the action to take when changing an annotation status.\r\n\t * @param {object} annotationStatus - The passed in anotation status. This may not have a value.\r\n\t * @param {number} statusCode - The status code the user is setting.\r\n\t */\r\n\tAnnotationUI.prototype.setAnnotationStatusUpdateAction = function (annotationStatus, statusCode) {\r\n\r\n\t\t// If we have no existing status, this is an add action.\r\n\t\tif (!annotationStatus.length) {\r\n\t\t\treturn eAnnotationStatusUpdateType.addStatus;\r\n\t\t}\r\n\t\t// If the status code has been changed, this is an update action.\r\n\t\telse if (annotationStatus[0].g_iAnnotationStatus !== statusCode) {\r\n\t\t\treturn eAnnotationStatusUpdateType.updateStatus;\r\n\t\t}\r\n\t\t// If the status code has been toggled, this is a delete status.\r\n\t\telse {\r\n\t\t\treturn eAnnotationStatusUpdateType.deleteStatus;\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Selects a temporary unique number for a new Annotation.\r\n\t */\r\n\tAnnotationUI.prototype.getNextAnnotationId = function () {\r\n\t\tvar iTempAnnotationId = 0;\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\tiTempAnnotationId = Math.min(iTempAnnotationId, g_oAnnotations.g_oAnnotationsMade[i].id);\r\n\t\t}\r\n\t\treturn iTempAnnotationId - 1;\r\n\t};\r\n\r\n\t/**\r\n\t * Gets the canvas ready for drawing.\r\n\t * @param {object} oParentAnnotation - The parent annotation.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.initiateAnnotationDraw = function (oParentAnnotation, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t// If a new annotation is currently open, we don't want to re-add the draw canvas events.\r\n\t\tif (!g_oAnnotations.checkIfNewSpeechBubbleExists() && !g_oAnnotations.checkForUnsavedAnnotation()) {\r\n\r\n\t\t\t// If this is not a 3D approval and the current document is not a 3D type.\r\n\t\t\tif (g_oAnnotations.g_iApprovalType != eDocumentTypes.ThreeD || g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex].document.documentType !== eDocumentTypes.ThreeD) {\r\n\r\n\t\t\t\tvar coords;\r\n\t\t\t\t$(\".annotationType\").show();\r\n\r\n\t\t\t\tif (g_oAnnotations.g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t\tif (!g_oViewer.g_bReadOnly) {\r\n\t\t\t\t\t\t$(\"#divTechToolsText\").click();\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Clear Annotation option highlighting.\r\n\t\t\t\t\t$(\".annotationType\").removeStyle();\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\t// Clear Tech Tools option highlighting.\r\n\t\t\t\t\tg_oTechTools.clearToolType();\r\n\r\n\t\t\t\t\tchangeCanvasFunction(\".annotationViewer\", \"pointerdown\");\r\n\t\t\t\t\tchangeCanvasFunction(\".annotationViewer\", \"pointermove\");\r\n\r\n\t\t\t\t\t// Close all annotations\r\n\t\t\t\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade[i].g_bClosed = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// Enable annotation hover\r\n\t\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove.annotationUI\", function (event) {\r\n\t\t\t\t\t\tg_oAnnotationActions.mouseMoveLite(event, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\tchangeCanvasFunction(\".annotationViewer\", \"click\", function (event) {\r\n\t\t\t\t\t\tvar e = event;\r\n\t\t\t\t\t\tg_oAnnotations.findAnnotation(e, g_oViewer.getLinkedArtworkCanvas(event.currentTarget.id), g_oViewer.getCanvas(event.currentTarget.id));\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\t$(\"#AnnotationViewer\").css(\"cursor\", \"crosshair\");\r\n\t\t\t\t\tg_oAnnotations.g_szPrevCursorStyle = \"crosshair\";\r\n\t\t\t\t\t$(\"#CompareAnnotationViewer\").css(\"cursor\", \"default\");\r\n\r\n\t\t\t\t\t// Initiate draw of the annotation once the user has clicked\r\n\t\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointerdown\", function (event) {\r\n\t\t\t\t\t\t// If a new annotation is currently open, or we have an unsaved annotation, we down want to allow drawing of a new annotation yet.\r\n\t\t\t\t\t\tif (!g_oAnnotations.checkIfNewSpeechBubbleExists() && !g_oAnnotations.checkForUnsavedAnnotation()) {\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// Ensure the annotation document is toggled to this document.\r\n\t\t\t\t\t\t\tg_oCompare.forceToggleAnnotationDocument(oAnnotationCanvas.g_szCanvasId);\r\n\r\n\t\t\t\t\t\t\t$(\"#annotationDropDown\").slideUp(200);\r\n\t\t\t\t\t\t\tcoords = g_oAnnotations.getClick(event, oArtworkCanvas);\r\n\t\t\t\t\t\t\toAnnotationCanvas.g_iX = coords[0];\r\n\t\t\t\t\t\t\toAnnotationCanvas.g_iY = coords[1];\r\n\r\n\t\t\t\t\t\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointerup\", function (event) {\r\n\t\t\t\t\t\t\t\tg_oAnnotations.annotationPointerUp(event, oParentAnnotation, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\t\tif (g_oAnnotations.g_iAnnotationType === eAnnotationTypes.Postit || g_oAnnotations.g_iAnnotationType === eAnnotationTypes.Global) {\r\n\t\t\t\t\t\t\t\tg_oAnnotations.g_oTempAnnotationArray.length = 0;\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t// Try to find an existing annotation first.\r\n\t\t\t\t\t\t\t\tg_oAnnotations.findAnnotation(event, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t\tif (!g_oAnnotations.g_bAnnotationsFound) {\r\n\t\t\t\t\t\t\t\t\t// Reshow annotations if they are hidden.\r\n\t\t\t\t\t\t\t\t\tif (!g_oSettings.g_oUserSettings.ShowAnnotations) {\r\n\t\t\t\t\t\t\t\t\t\t$(\"#HideAnnotations\").click();\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\tg_oAnnotations.g_iAnnotationType === eAnnotationTypes.Postit ? g_oAnnotations.drawPostit(event, oArtworkCanvas, oAnnotationCanvas) : g_oAnnotations.drawGlobal(event, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse {\r\n\t\t\t\t\t\t\t\t\tg_oAnnotations.drawInitiate(oParentAnnotation, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse {\r\n\t\t\t\t\t\t\t\tg_oAnnotations.drawInitiate(oParentAnnotation, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// If this is a threeD approval.\r\n\t\t\telse {\r\n\r\n\t\t\t\t// Hide the annotation type options.\r\n\t\t\t\t$(\".annotationType\").hide();\r\n\r\n\t\t\t\t// Set the pointer down event.\r\n\t\t\t\t$(oArtworkCanvas.g_oCanvas).on(\"pointerdown\", function (e) {\r\n\r\n\t\t\t\t\t// If we move the pointer after clicking.\r\n\t\t\t\t\t$(oArtworkCanvas.g_oCanvas).on(\"pointermove\", function (e) {\r\n\r\n\t\t\t\t\t\t// Unbind the pointer up event.\r\n\t\t\t\t\t\t$(oArtworkCanvas.g_oCanvas).off(\"pointerup\");\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\t// If we pointer up before moving.\r\n\t\t\t\t\t$(oArtworkCanvas.g_oCanvas).on(\"pointerup\", function (e) {\r\n\r\n\t\t\t\t\t\t// Unbind the pointer move event.\r\n\t\t\t\t\t\t$(oArtworkCanvas.g_oCanvas).off(\"pointermove\");\r\n\r\n\t\t\t\t\t\t// Create a new threeD annotation.\r\n\t\t\t\t\t\tg_oAnnotations.threeDCreateAnnotation(e, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t});\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Mouse/Pointer up even for when a new annotation is being drawn.\r\n\t * @param {event} event - The event.\r\n\t * @param {object} oParentAnnotation - The parent annotation if any.\r\n\t * @param {object} oTempMarqueeDimensions - The temporary Marquee dimensions.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.annotationPointerUp = function (event, oParentAnnotation, oTempMarqueeDimensions, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// We only create the annotation if the user has actually moved the mouse from anchor point\r\n\t\tif (g_oAnnotations.g_iAnnotationType !== eAnnotationTypes.Postit &&\r\n\t\t\tg_oAnnotations.g_iAnnotationType !== eAnnotationTypes.Freedraw &&\r\n\t\t\tg_oAnnotations.g_iAnnotationType !== eAnnotationTypes.Global &&\r\n\t\t\t(oAnnotationCanvas.g_iX !== oAnnotationCanvas.g_iOrigin_x || oAnnotationCanvas.g_iY !== oAnnotationCanvas.g_iOrigin_y)) {\r\n\t\t\tvar iImageObjW = oArtworkCanvas.g_iScaledImageWidth;\r\n\t\t\tvar iImageObjH = oArtworkCanvas.g_iScaledImageHeight;\r\n\r\n\t\t\t// Calculate the compare offset of the canvas.\r\n\t\t\tvar compareOffset_x, compareOffset_y;\r\n\t\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\t\tcompareOffset_x = co.x;\r\n\t\t\tcompareOffset_y = co.y;\r\n\r\n\t\t\t// As this is not a post it note annotation, push these to the temp array.\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([(oAnnotationCanvas.g_iOrigin_x - compareOffset_x) / iImageObjW, (oAnnotationCanvas.g_iOrigin_y - compareOffset_y) / iImageObjH]);\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.push([(oAnnotationCanvas.g_iX - compareOffset_x) / iImageObjW, (oAnnotationCanvas.g_iY - compareOffset_y) / iImageObjH]);\r\n\t\t}\r\n\t\t\r\n\t\t// We have the number of points required for the annotation.\r\n\t\t// 1 for Postit.\r\n\t\t// 2+ for Freedraw.\r\n\t\t// 2 for all other annotation types.\r\n\t\tif ((g_oAnnotations.g_iAnnotationType != eAnnotationTypes.Postit && g_oAnnotations.g_iAnnotationType != eAnnotationTypes.Freedraw && g_oAnnotations.g_oTempAnnotationArray.length == 2) ||\r\n\t\t\t(g_oAnnotations.g_iAnnotationType == eAnnotationTypes.Freedraw && g_oAnnotations.g_oTempAnnotationArray.length >= 2) ||\r\n\t\t\t(g_oAnnotations.g_iAnnotationType == eAnnotationTypes.Postit && g_oAnnotations.g_oTempAnnotationArray.length == 1)) {\r\n\r\n\t\t\t// Create a new annotation.\r\n\t\t\tvar g_oNewAnnotation = new window.Annotation(g_oAnnotations.g_iApprovalId);\r\n\r\n\t\t\t// Set up the new annotation.\r\n\t\t\tg_oNewAnnotation.id = g_oAnnotations.getNextAnnotationId();\r\n\t\t\tg_oNewAnnotation.g_iAuthor = g_oUserDetails.UserId;\r\n\t\t\tg_oNewAnnotation.g_szAuthorEmail = g_oUserDetails.EmailAddress;\r\n\t\t\tg_oNewAnnotation.g_iAnnotationType = g_oAnnotations.g_iAnnotationType;\r\n\t\t\tg_oNewAnnotation.g_szColour = oParentAnnotation.g_szColour || g_oAnnotations.g_oAnnotationColSelected;\r\n\t\t\tg_oNewAnnotation.g_oDrawArray = deepCopyArray(g_oAnnotations.g_oTempAnnotationArray);\t\t// Deep copy of the array.\r\n\r\n\t\t\tg_oAnnotations.g_oTempAnnotationArray.length = 0;\t\t\t\t\t\t\t\t\t\t\t\t\t\t// Clear out the temp array now that we've copied the contents.\r\n\r\n\t\t\tg_oNewAnnotation.status = \"a\";\r\n\t\t\tg_oNewAnnotation.g_iDocumentId = oArtworkCanvas.g_oDoc.documentId;\r\n\r\n\t\t\tif ((g_oAnnotations.g_iAnnotationType === eAnnotationTypes.TextMeasurement) &&\r\n\t\t\t\t(oTempMarqueeDimensions !== undefined && oTempMarqueeDimensions !== null)) {\r\n\t\t\t\tg_oNewAnnotation.g_oMarqueeDrawArray.push([oTempMarqueeDimensions.MinX,\r\n\t\t\t\toTempMarqueeDimensions.MinY]);\r\n\t\t\t\tg_oNewAnnotation.g_oMarqueeDrawArray.push([oTempMarqueeDimensions.MaxX,\r\n\t\t\t\toTempMarqueeDimensions.MaxY]);\r\n\t\t\t\tvar oData = {\r\n\t\t\t\t\toAnnotation: g_oNewAnnotation,\r\n\t\t\t\t\toArtworkCanvas: oArtworkCanvas,\r\n\t\t\t\t\toAnnotationCanvas: oAnnotationCanvas\r\n\t\t\t\t};\r\n\t\t\t\tEventService.publish(\"getTextMeasurementText\", oData);\r\n\t\t\t}\r\n\r\n\t\t\t// If we have more than one page, grab the page id by looping through the pages.\r\n\t\t\tif (!$.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\t\t\t\tfor (var i = 0; i < oArtworkCanvas.g_oDoc.pages.length; i++) {\r\n\t\t\t\t\tif (oArtworkCanvas.g_oDoc.pages[i].documentPageNumber == oArtworkCanvas.g_iCurrentPage) {\r\n\t\t\t\t\t\tg_oNewAnnotation.g_iDocumentPageId = oArtworkCanvas.g_oDoc.pages[i].documentPageId;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tg_oNewAnnotation.g_iParentAnnotationId = oParentAnnotation ? g_oNewAnnotation.g_iParentAnnotationId = oParentAnnotation.id : 0;\r\n\r\n\t\t\t// Find max annotation number and add 1. We have our new annotation number\r\n\t\t\t// If there are no annotations we must do a max of the result or 1. Otherwise -infinity is returned\r\n\t\t\t// Which actually evaluates to isNaN = false!\r\n\t\t\tg_oNewAnnotation.g_iNumber = oParentAnnotation ? oParentAnnotation.g_iNumber : Math.max(1, Math.max.apply(Math, g_oAnnotations.g_oAnnotationsMade.map(function (o) { return o.g_iNumber; })) + 1);\r\n\r\n\t\t\t// Push the new annotation into the Annotations made Array\r\n\t\t\tg_oAnnotations.g_oAnnotationsMade.push(g_oNewAnnotation);\r\n\t\t\tif (g_oNewAnnotation.g_iParentAnnotationId === 0) {\r\n\t\t\t\tg_oNewAnnotation.createAnnotationDiv(eAnnotationDivType.Popup, true, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// We need to directly save the newly drawn shape\r\n\t\t\t\tif (g_oAnnotations.g_iApprovalId === g_oNewAnnotation.g_iApprovalId) {\r\n\t\t\t\t\tg_oNewAnnotation.annotationSaveShape(oAnnotationCanvas, false);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\tvar e = arguments[0] || event;\r\n\t\t\tg_oAnnotations.findAnnotation(e, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t}\r\n\t\tif (g_oNewAnnotation) {\r\n\t\t\tg_oNewAnnotation.createdDate = moment.utc(new Date(), moment.ISO_8601).local();\r\n\t\t}\r\n\r\n\t\toAnnotationCanvas.dragDiscontinue(false, []);\r\n\t\tg_oAnnotations.redrawAnnotations(oArtworkCanvas, oAnnotationCanvas);\r\n\t};\r\n\r\n\t/**\r\n\t * Rebuilds the annotation list.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.rebuildAnnotationList = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// Remove the existing annotations from the list.\r\n\t\t$(\".annotationListItem\").remove();\r\n\r\n\t\t// Grab the annotations for the current page.\r\n\t\tvar annotationStack = [];\r\n\r\n\t\t// Loop through each of the annotations in the list.\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\r\n\t\t\t// If this is a new annotation, do not add it to the list.\r\n\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].id < 0) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// If the document has no pages.\r\n\t\t\tif ($.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\r\n\t\t\t\t// Ensure the annotation is on the document.\r\n\t\t\t\tif (oArtworkCanvas.g_oDoc.documentId == g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentId) {\r\n\r\n\t\t\t\t\t// Add the annotation to the list.\r\n\t\t\t\t\tannotationStack.push(g_oAnnotations.g_oAnnotationsMade[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// If the document has pages.\r\n\t\t\telse {\r\n\r\n\t\t\t\t// Loop through the pages.\r\n\t\t\t\tfor (var j = 0; j < oArtworkCanvas.g_oDoc.pages.length; j++) {\r\n\r\n\t\t\t\t\t// Ensure the annotation is on the document page.\r\n\t\t\t\t\tif (oArtworkCanvas.g_oDoc.pages[j].documentPageId == g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentPageId &&\r\n\t\t\t\t\t\t(oArtworkCanvas.g_iCurrentPage == oArtworkCanvas.g_oDoc.pages[j].documentPageNumber)) {\r\n\r\n\t\t\t\t\t\t// Add the annotation to the list.\r\n\t\t\t\t\t\tannotationStack.push(g_oAnnotations.g_oAnnotationsMade[i]);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t// Filter the annotation stack.\r\n\t\tannotationStack = g_oAnnotations.filteredAnnotationStack(annotationStack);\r\n\r\n\t\t// Sort the annotations by date.\r\n\t\tannotationStack.sort(function (a, b) {\r\n\t\t\tif (a.modifiedDate === null) {\t\t\t// new annotations do not have a modified date set.\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\telse if (b.modifiedDate === null) {\t\t// new annotations do not have a modified date set.\r\n\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t\telse if (a.createdDate === b.createdDate) {\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\treturn a.createdDate < b.createdDate ? -1 : 1;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\t// Number the newly sorted annotations.\r\n\t\tvar iCounter = 1;\r\n\t\tfor (var l = 0; l < annotationStack.length; l++) {\r\n\t\t\tif (annotationStack[l].g_iParentAnnotationId == 0) {\r\n\t\t\t\tannotationStack[l].g_iNumber = iCounter;\r\n\t\t\t\tiCounter++;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// For the child annotations in the stack, we need to set their number to their parents.\r\n\t\t\t\tvar oParentAnnotation = $.grep(annotationStack, function (parent) {\r\n\t\t\t\t\treturn parent.id == annotationStack[l].g_iParentAnnotationId;\r\n\t\t\t\t});\r\n\r\n\t\t\t\tannotationStack[l].g_iNumber = oParentAnnotation[0].g_iNumber;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Apply any annotation filters.\r\n\t\tannotationStack = g_oFilter.applyAnnotationFilters(annotationStack);\r\n\r\n\t\t// Create the annotations.\r\n\t\tfor (var m = 0; m < annotationStack.length; m++) {\r\n\t\t\tif (annotationStack[m].g_iParentAnnotationId === 0 || annotationStack[m].g_iParentAnnotationId === \"undefined\") {\r\n\t\t\t\tannotationStack[m].createAnnotationDiv(eAnnotationDivType.ListItem, true, null, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Update the print annotations icon.\r\n\t\tg_oAnnotations.updatePrintAnnotationsIcon();\r\n\r\n\t\t// Override the copy method to remove any colour formatting\r\n\t\t// In-line styling can still break it.\r\n\t\t$(\".annotationListItem\").off('copy');\r\n\t\t$(\".annotationListItem\").on('copy', function (event) { AnnotationUI.prototype.copyOverride(event); });\r\n\t};\r\n\r\n\t/**\r\n\t * Updates the print annotation icon based on the selected document.\r\n\t */\r\n\tAnnotationUI.prototype.updatePrintAnnotationsIcon = function () {\r\n\t\t\r\n\t\t// Get the active annotation canvas.\r\n\t\tvar szAnnotationCanvasId = g_oCompare.getAnnotationCanvasId();\r\n\r\n\t\t// Get the control based on the annotation canvas.\r\n\t\tvar oControl = comboControl_GetControlById(szAnnotationCanvasId == \"AnnotationViewer\" ? \"approvalNameComboControl\" : \"approvalCompareComboControl\", false);\r\n\r\n\t\t// Get the selected document from the control.\r\n\t\tvar oDocument = oControl.documents[oControl.selectedDocumentIndex];\r\n\r\n\t\t// Show or hide the icon based on if the document has an approval.\r\n\t\t$(\"#btnPrintAnnotations\").css(\"display\", (oDocument.greenlightApprovalId > 0 ? \"\" : \"none\"));\r\n\t};\r\n\r\n\t/**\r\n\t * Helper method that changes tool type when a new one is clicked.\r\n\t * @param {string} element - The element being clicked.\r\n\t * @param {number} type - The annotation type that is being changed.\r\n\t */\r\n\tAnnotationUI.prototype.toolTypeChange = function (element, type) {\r\n\t\t$(element).parent().parent().slideUp(200);\r\n\r\n\t\tif ($(element).hasClass(\"annotationType\")) {\r\n\t\t\t$(\".annotationType\").removeStyle();\r\n\t\t\tg_oAnnotations.g_iAnnotationType = type;\r\n\t\t\tg_oSettings.g_oUserSettings.LastUsedAnnotationType = type;\r\n\t\t\tg_oSettings.syncSettings();\r\n\t\t}\r\n\r\n\t\t$(element).css(\"background-color\", \"grey\");\r\n\r\n\t\t// Change the cursor to a crosshair\r\n\t\t$('#AnnotationViewer').css(\"cursor\", \"crosshair\");\r\n\t\tg_oAnnotations.g_szPrevCursorStyle = \"crosshair\";\r\n\t\t// Remove the handle detection event\r\n\t\t$('#AnnotationViewer').off(\"pointermove.annotationUI\");\r\n\t\t// Close all annotations\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\tg_oAnnotations.g_oAnnotationsMade[i].g_bClosed = true;\r\n\t\t}\r\n\t\t// Redraw?\r\n\r\n\t\t// Set the current tool\r\n\t\tswitch (type) {\r\n\t\t\tcase eAnnotationTypes.Postit:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Postit\");\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Freedraw:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Freedraw\");\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Rectangle:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Rectangle\");\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Ellipse:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Ellipse\");\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Line:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Line\");\r\n\t\t\t\tbreak;\r\n\t\t\tcase eAnnotationTypes.Global:\r\n\t\t\t\tg_oAnnotations.g_oLastUsedTool = $(\"#Global\");\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t};\r\n\r\n\t/**\r\n\t * Pre-sets a user's tool and colour from the last time.\r\n\t */\r\n\tAnnotationUI.prototype.presetUserTools = function () {\r\n\r\n\t\t// Set the user to their colour.\r\n\t\tvar szPresetColour = g_oAnnotations.getStringColour(g_oSettings.g_oUserSettings.AnnotationColour);\r\n\r\n\t\t// Update the annotations object with the preferences.\r\n\t\tg_oAnnotations.g_oAnnotationColSelected = szPresetColour;\r\n\t\tg_oAnnotations.g_iAnnotationType = g_oSettings.g_oUserSettings.LastUsedAnnotationType;\r\n\r\n\t\t// Select the tool.\r\n\t\tvar oToolElement = $(\"*[data-annotationtype=\\\"\" + g_oAnnotations.g_iAnnotationType + \"\\\"]\");\r\n\t\t$(oToolElement).css(\"background-color\", \"grey\");\r\n\r\n\t\t// Select the colour.\r\n\t\tvar oColourElement = $(\"*[data-annotationcolour=\\\"\" + szPresetColour + \"\\\"]\");\r\n\t\t$(oColourElement).css(\"border-color\", g_oSettings.c_iSkinType == 0 ? \"white\" : \"black\");\r\n },\r\n\r\n\t/**\r\n\t * Gets all the annotations on the current page.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t */\r\n\tAnnotationUI.prototype.getAnnotationStackCurrentPage = function (oArtworkCanvas) {\r\n\t\t// Grab the annotations for the current page.\r\n\t\tvar annotationStack = [];\r\n\r\n\t\t// Add each of the annotations that are on the current document to the list.\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\t// If they aren't any pages, this means this a jpg/png approval, so use matching document IDs.\r\n\t\t\tif ($.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\t\t\t\toArtworkCanvas.g_oDoc.documentId == g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentId ? annotationStack.push(g_oAnnotations.g_oAnnotationsMade[i]) : \"\";\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// Loop through the pages\r\n\t\t\t\tfor (var j = 0; j < oArtworkCanvas.g_oDoc.pages.length; j++) {\r\n\t\t\t\t\tif (oArtworkCanvas.g_oDoc.pages[j].documentPageId == g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentPageId &&\r\n\t\t\t\t\t\t(oArtworkCanvas.g_iCurrentPage == oArtworkCanvas.g_oDoc.pages[j].documentPageNumber)) {\r\n\t\t\t\t\t\tannotationStack.push(g_oAnnotations.g_oAnnotationsMade[i]);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn annotationStack;\r\n\t};\r\n\r\n\t/**\r\n\t * Redraws the annotations.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t * @param {int} iFilterId - The annotation Id if only one annotation wants to be shown.\r\n\t */\r\n\tAnnotationUI.prototype.redrawAnnotations = function (oArtworkCanvas, oAnnotationCanvas, iFilterId) {\r\n\r\n\t\t// If we are in a text compare, redraw the text compare annotations instead.\r\n\t\tif (g_oTextCompare.g_bTextCompareInProgress) {\r\n\t\t\tg_oTextCompare.renderTextCompareAnnotations();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Don't redraw if we are in the process of a text highlight.\r\n\t\tif (g_oTextTools.g_bHighlightInProgress) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\t// Determine the filter.\r\n\t\tiFilterId = (typeof (iFilterId) === \"undefined\") ? -1 : iFilterId;\r\n\r\n\t\t// Outline any required variables.\r\n\t\tvar oAnnotationContext, iImageObjW, iImageObjH, oAnnotationStack, iCenterShift_x, iCenterShift_y;\r\n\t\toAnnotationContext = oAnnotationCanvas.g_oContext;\r\n\r\n\t\t// Keep track of the global annotation number.\r\n\t\tvar iGlobalCounter = 0;\r\n\r\n\t\t// Calculate the compare offset on the artwork canvas.\r\n\t\tvar compareOffset_x, compareOffset_y;\r\n\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\tcompareOffset_x = co.x;\r\n\t\tcompareOffset_y = co.y;\r\n\r\n\t\t// Grab the annotations for the current page.\r\n\t\toAnnotationStack = this.getAnnotationStackCurrentPage(oArtworkCanvas);\r\n\r\n\t\t// Filter the annotations stack.\r\n\t\toAnnotationStack = g_oAnnotations.filteredAnnotationStack(oAnnotationStack);\r\n\r\n\t\t// Get the width and shift of the artwork canvas.\r\n\t\tiImageObjW = oArtworkCanvas.g_iScaledImageWidth;\r\n\t\tiImageObjH = oArtworkCanvas.g_iScaledImageHeight;\r\n\t\tiCenterShift_x = oArtworkCanvas.g_iCenterShift_x;\r\n\t\tiCenterShift_y = oArtworkCanvas.g_iCenterShift_y;\r\n\r\n\t\t// Sort the annotations by date.\r\n\t\toAnnotationStack.sort(function (a, b) {\r\n\t\t\tif (a.modifiedDate === null) {\t\t\t// new annotations do not have a modified date set.\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\telse if (b.modifiedDate === null) {\t\t// new annotations do not have a modified date set.\r\n\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t\telse if (a.createdDate === b.createdDate) {\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\treturn a.createdDate < b.createdDate ? -1 : 1;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\t// Number the newly sorted annotations\r\n\t\tvar counter = 1;\r\n\t\tfor (var l = 0; l < oAnnotationStack.length; l++) {\r\n\t\t\tif (oAnnotationStack[l].g_oDrawArray[0][2] === 0 || oAnnotationStack[l].g_oDrawArray[0][2] == undefined) {\r\n\t\t\t\tif (oAnnotationStack[l].g_iParentAnnotationId == 0) {\r\n\t\t\t\t\toAnnotationStack[l].g_iNumber = counter;\r\n\t\t\t\t\tcounter++;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\t// For the child annotations in the stack, we need to set their number to their parents.\r\n\t\t\t\t\tvar oParentAnnotation = $.grep(oAnnotationStack, function (parent) {\r\n\t\t\t\t\t\treturn parent.id == oAnnotationStack[l].g_iParentAnnotationId;\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\toAnnotationStack[l].g_iNumber = oParentAnnotation[0].g_iNumber;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Determine if the annotations should be shown for this canvas.\r\n\t\tvar bShowAnnotaionsOnCanvas = (oAnnotationCanvas.g_szCanvasId == g_oCompare.getAnnotationCanvasId());\r\n\r\n\t\t// Get the compare rotation of the canvas.\r\n\t\tvar iCompareRotation = g_oCompare.getCompareRotation(oArtworkCanvas);\r\n\r\n\t\t// If we have a compare rotation of 90 or 270, swap the image object width and height.\r\n\t\tif (iCompareRotation == 90 || iCompareRotation == 270) {\r\n\t\t\tiImageObjW = oArtworkCanvas.g_iScaledImageHeight;\r\n\t\t\tiImageObjH = oArtworkCanvas.g_iScaledImageWidth;\r\n\t\t}\r\n\r\n\t\t// If we only want to draw a specific annotation, filter to the matching annotation.\r\n\t\tif (iFilterId > 0) {\r\n\t\t\toAnnotationStack = $.grep(oAnnotationStack, function (ann) { return ann.id == iFilterId; });\r\n\t\t}\r\n\r\n\t\t// Loop through each of the annotations in the stack.\r\n\t\tfor (var annotation in oAnnotationStack) {\r\n\t\t\tif (oAnnotationStack[annotation].g_iAnnotationType !== eAnnotationTypes.ThreeD) {\r\n\r\n\t\t\t\t// If this is a copy magic annotation, and the SVG text has changed, update the draw array to ensure this is drawn correctly for changing content.\r\n\t\t\t\tif (oAnnotationStack[annotation].g_bSVGTextAnnotation && oAnnotationStack[annotation].g_oSVGVariable.copyMagicText & oAnnotationStack[annotation].g_bSVGPositionUpdated) {\r\n\t\t\t\t\toAnnotationStack[annotation].g_oDrawArray = g_oSVGCopyMagic.getContentBoundingRectDrawArray(oAnnotationStack[annotation].g_oSVGVariable.switchId, oAnnotationStack[annotation].g_oSVGVariable.contentDataId, oAnnotationStack[annotation].g_oSVGVariable.contentId, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\toAnnotationStack[annotation].g_bSVGPositionUpdated = false;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Get the annotation details.\r\n\t\t\t\tvar annotationArray = deepCopyArray(oAnnotationStack[annotation].g_oDrawArray);\r\n\t\t\t\tvar annCol = oAnnotationStack[annotation].g_szColour;\r\n\t\t\t\tvar annTyp = oAnnotationStack[annotation].g_iAnnotationType;\r\n\t\t\t\tvar closed = oAnnotationStack[annotation].g_bClosed;\r\n\r\n\t\t\t\t// If the canvas has compare rotation.\r\n\t\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t\t// Rotate each of the annotation draw positions.\r\n\t\t\t\t\tfor (var oAnnotationDraw in annotationArray) {\r\n\r\n\t\t\t\t\t\t// Rotate the annotation draw positions.\r\n\t\t\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(annotationArray[oAnnotationDraw][0], annotationArray[oAnnotationDraw][1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\t\t\tannotationArray[oAnnotationDraw][0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\t\t\tannotationArray[oAnnotationDraw][1] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// If the annotation is visible, annotations should be shown and annotations should be shown on this canvas.\r\n\t\t\t\tif (oAnnotationStack[annotation].g_bVisible && g_oSettings.g_oUserSettings.ShowAnnotations && bShowAnnotaionsOnCanvas) {\r\n\t\t\t\t\tswitch (annTyp) {\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.ColourDensityMeasurementPostit:\r\n\t\t\t\t\t\tcase eAnnotationTypes.Postit:\r\n\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[0][0] * iImageObjW)) + iCenterShift_x - g_oAnnotations.g_oPostitImg.widthOffset + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[0][1] * iImageObjH)) + iCenterShift_y - g_oAnnotations.g_oPostitImg.heightOffset + compareOffset_y;\r\n\t\t\t\t\t\t\toAnnotationContext.drawImage(g_oAnnotations.g_oPostitImg, newXBegin, newYBegin, this.g_oPostitImg.width, this.g_oPostitImg.height);\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.Freedraw:\r\n\t\t\t\t\t\tcase eAnnotationTypes.SVGPolygon:\r\n\t\t\t\t\t\t\toAnnotationContext.strokeStyle = annCol;\r\n\t\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\t\t\t\t\t\t\toAnnotationContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\t\t\t\toAnnotationContext.moveTo(annotationArray[0][0], annotationArray[0][1]);\r\n\t\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\r\n\t\t\t\t\t\t\t// Loop through each of the vectors.\r\n\t\t\t\t\t\t\tfor (var i = 0; i < annotationArray.length; i++) {\r\n\t\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[i][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[i][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\t\t// Ensure we haven't reached the end of the array.\r\n\t\t\t\t\t\t\t\tif (annotationArray[i + 1] !== undefined) {\r\n\t\t\t\t\t\t\t\t\tvar newXEnd = ((annotationArray[i + 1][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\t\t\tvar newYEnd = ((annotationArray[i + 1][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\t\t\tvar c = (newXBegin + newXEnd) / 2;\r\n\t\t\t\t\t\t\t\t\tvar d = (newYBegin + newYEnd) / 2;\r\n\r\n\t\t\t\t\t\t\t\t\t// If this is a freedraw annotation, use a quadratic curve.\r\n\t\t\t\t\t\t\t\t\tif (annTyp == eAnnotationTypes.Freedraw) {\r\n\t\t\t\t\t\t\t\t\t\toAnnotationContext.quadraticCurveTo(newXBegin, newYBegin, c, d);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t// If this is an SVG polygon, use a straight line.\r\n\t\t\t\t\t\t\t\t\telse if (annTyp === eAnnotationTypes.SVGPolygon) {\r\n\t\t\t\t\t\t\t\t\t\toAnnotationContext.lineTo(newXBegin, newYBegin);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t// If this is the final point.\r\n\t\t\t\t\t\t\t\telse {\r\n\t\t\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[i - 1][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[i - 1][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\t\t\t\t\t\t\t\t\tvar newXEnd = ((annotationArray[i][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\t\t\tvar newYEnd = ((annotationArray[i][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\t\t\tvar c = (newXBegin + newXEnd) / 2;\r\n\t\t\t\t\t\t\t\t\tvar d = (newYBegin + newYEnd) / 2;\r\n\r\n\t\t\t\t\t\t\t\t\t// If this is a freedraw annotation, use a quadratic curve.\r\n\t\t\t\t\t\t\t\t\tif (annTyp == eAnnotationTypes.Freedraw) {\r\n\t\t\t\t\t\t\t\t\t\toAnnotationContext.quadraticCurveTo(newXBegin, newYBegin, c, d);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t// If this is an SVG polygon, use a straight line.\r\n\t\t\t\t\t\t\t\t\telse if (annTyp === eAnnotationTypes.SVGPolygon) {\r\n\t\t\t\t\t\t\t\t\t\tnewXBegin = ((annotationArray[i][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\t\t\t\tnewYBegin = ((annotationArray[i][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\t\t\t\t\t\t\t\t\t\toAnnotationContext.lineTo(newXBegin, newYBegin);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// If this is an SVG annotation.\r\n\t\t\t\t\t\t\tif (oAnnotationStack[annotation].g_bSVGTextAnnotation === true) {\r\n\r\n\t\t\t\t\t\t\t\t// Apply the SVG annotation styling.\r\n\t\t\t\t\t\t\t\tg_oSVGText.applySVGAnnotationStyling(oAnnotationContext, oAnnotationStack[annotation]);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// It's more efficient to process all drawing operations for a line at once.\r\n\t\t\t\t\t\t\toAnnotationContext.stroke();\r\n\t\t\t\t\t\t\toAnnotationContext.closePath();\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.Ellipse:\r\n\t\t\t\t\t\tcase eAnnotationTypes.SVGEllipse:\r\n\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[0][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[0][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\t\t\t\t\t\t\tvar newXEnd = ((annotationArray[1][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYEnd = ((annotationArray[1][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\tvar beginPoint_x = Math.min(newXBegin, newXEnd);\r\n\t\t\t\t\t\t\tvar beginPoint_y = Math.min(newYBegin, newYEnd);\r\n\t\t\t\t\t\t\tvar dist_x = Math.abs(newXBegin - newXEnd);\r\n\t\t\t\t\t\t\tvar dist_y = Math.abs(newYBegin - newYEnd);\r\n\t\t\t\t\t\t\tvar halfPoint_x = beginPoint_x + (dist_x / 2);\r\n\t\t\t\t\t\t\tvar halfPoint_y = beginPoint_y + (dist_y / 2);\r\n\r\n\t\t\t\t\t\t\tvar width_two_thirds = dist_x * 2 / 3;\r\n\t\t\t\t\t\t\tvar height_over_2 = dist_y / 2;\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\t\t\t\t\t\t\toAnnotationContext.moveTo(halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\t\t\t\t\toAnnotationContext.bezierCurveTo(halfPoint_x + width_two_thirds, halfPoint_y - height_over_2, halfPoint_x + width_two_thirds, halfPoint_y + height_over_2, halfPoint_x, halfPoint_y + height_over_2);\r\n\t\t\t\t\t\t\toAnnotationContext.bezierCurveTo(halfPoint_x - width_two_thirds, halfPoint_y + height_over_2, halfPoint_x - width_two_thirds, halfPoint_y - height_over_2, halfPoint_x, halfPoint_y - height_over_2);\r\n\t\t\t\t\t\t\toAnnotationContext.closePath();\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\t\t\t\toAnnotationContext.strokeStyle = annCol;\r\n\t\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\r\n\t\t\t\t\t\t\t// If this is an SVG annotation.\r\n\t\t\t\t\t\t\tif (oAnnotationStack[annotation].g_bSVGTextAnnotation === true) {\r\n\r\n\t\t\t\t\t\t\t\t// Apply the SVG annotation styling.\r\n\t\t\t\t\t\t\t\tg_oSVGText.applySVGAnnotationStyling(oAnnotationContext, oAnnotationStack[annotation]);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.stroke();\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.BarcodeMeasurement:\r\n\t\t\t\t\t\tcase eAnnotationTypes.ColourDensityMeasurement:\r\n\t\t\t\t\t\tcase eAnnotationTypes.TextMeasurement:\r\n\t\t\t\t\t\tcase eAnnotationTypes.TextHighlight:\r\n\t\t\t\t\t\tcase eAnnotationTypes.TextClassification:\r\n\t\t\t\t\t\tcase eAnnotationTypes.Rectangle:\r\n\t\t\t\t\t\tcase eAnnotationTypes.SVGRectangle:\r\n\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[0][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[0][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\t\t\t\t\t\t\tvar newXEnd = ((annotationArray[1][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYEnd = ((annotationArray[1][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\tvar beginPoint_x = Math.min(newXBegin, newXEnd);\r\n\t\t\t\t\t\t\tvar beginPoint_y = Math.min(newYBegin, newYEnd);\r\n\t\t\t\t\t\t\tvar dist_x = Math.abs(newXBegin - newXEnd);\r\n\t\t\t\t\t\t\tvar dist_y = Math.abs(newYBegin - newYEnd);\r\n\r\n\t\t\t\t\t\t\t// If this is a text measurement, first highlight the text measurement words.\r\n\t\t\t\t\t\t\tif (annTyp === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t\t\t\t\toAnnotationStack[annotation].highlightTextMeasurementWords(!closed, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// If this is a text highlight, first highlight the text highlight sections.\r\n\t\t\t\t\t\t\tif (annTyp === eAnnotationTypes.TextHighlight || annTyp === eAnnotationTypes.TextClassification) {\r\n\r\n\t\t\t\t\t\t\t\t// Highlight the sections once the data has loaded.\r\n\t\t\t\t\t\t\t\t// Using in scope variables so these are not updated by references.\r\n\t\t\t\t\t\t\t\tvar oCallback = (function (colour, content, artworkCanvas, annotationCanvas) {\r\n\t\t\t\t\t\t\t\t\treturn function () {\r\n\r\n\t\t\t\t\t\t\t\t\t\t// Set the accuracy level.\r\n\t\t\t\t\t\t\t\t\t\tg_oTextTools.g_bHighlightIsCharacterAccuracy = JSON.parse(content)[0].startingText.character != undefined;\r\n\r\n\t\t\t\t\t\t\t\t\t\t// Set the highlight colour.\r\n\t\t\t\t\t\t\t\t\t\tg_oTextTools.setHighlightColour(colour);\r\n\r\n\t\t\t\t\t\t\t\t\t\t// Highlight the text content.\r\n\t\t\t\t\t\t\t\t\t\tg_oTextTools.highlightSections(JSON.parse(content), artworkCanvas, annotationCanvas);\r\n\t\t\t\t\t\t\t\t\t};\r\n\t\t\t\t\t\t\t\t})(annCol, oAnnotationStack[annotation].g_szTextHighlightContent, oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t\t\t\t// Load the text data.\r\n\t\t\t\t\t\t\t\tg_oTextData.loadTextData(oArtworkCanvas.g_oDoc.documentId, oArtworkCanvas.g_iCurrentPage, true, oCallback);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\t\t\t\t\t\t\toAnnotationContext.rect(beginPoint_x, beginPoint_y, dist_x, dist_y);\r\n\t\t\t\t\t\t\toAnnotationContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\t\t\t\toAnnotationContext.strokeStyle = annCol;\r\n\t\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\r\n\t\t\t\t\t\t\t// If this is an SVG annotation.\r\n\t\t\t\t\t\t\tif (oAnnotationStack[annotation].g_bSVGTextAnnotation === true) {\r\n\r\n\t\t\t\t\t\t\t\t// Apply the SVG annotation styling.\r\n\t\t\t\t\t\t\t\tg_oSVGText.applySVGAnnotationStyling(oAnnotationContext, oAnnotationStack[annotation]);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.stroke();\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.Line:\r\n\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[0][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[0][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\t\t\t\t\t\t\tvar newXEnd = ((annotationArray[1][0] * iImageObjW)) + iCenterShift_x + compareOffset_x;\r\n\t\t\t\t\t\t\tvar newYEnd = ((annotationArray[1][1] * iImageObjH)) + iCenterShift_y + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\tvar beginPoint_x = newXBegin;\r\n\t\t\t\t\t\t\tvar beginPoint_y = newYBegin;\r\n\t\t\t\t\t\t\tvar dist_x = newXEnd - newXBegin;\r\n\t\t\t\t\t\t\tvar dist_y = newYEnd - newYBegin;\r\n\r\n\t\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\t\t\t\t\t\t\toAnnotationContext.moveTo(beginPoint_x, beginPoint_y);\r\n\t\t\t\t\t\t\toAnnotationContext.lineTo(beginPoint_x + dist_x, beginPoint_y + dist_y);\r\n\t\t\t\t\t\t\toAnnotationContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\t\t\t\toAnnotationContext.strokeStyle = annCol;\r\n\t\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\t\t\t\t\t\t\toAnnotationContext.stroke();\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase eAnnotationTypes.Global:\r\n\t\t\t\t\t\t\tvar newXBegin = ((annotationArray[0][0])) + iCenterShift_x;\r\n\t\t\t\t\t\t\tvar newYBegin = ((annotationArray[0][1])) + iCenterShift_y;\r\n\r\n\t\t\t\t\t\t\tvar dist_x = oArtworkCanvas.g_iCompareImage_x;\r\n\t\t\t\t\t\t\tvar dist_y = oArtworkCanvas.g_iCompareImage_y;\r\n\t\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\t\t\t\t\t\t\toAnnotationContext.rect(newXBegin, newYBegin, dist_x, dist_y);\r\n\t\t\t\t\t\t\toAnnotationContext.lineWidth = g_oAnnotations.g_iAnnotationWidth;\r\n\t\t\t\t\t\t\toAnnotationContext.strokeStyle = annCol;\r\n\t\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\t\t\t\t\t\t\toAnnotationContext.stroke();\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tdefault:\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Draw the annotation number if required.\r\n\t\t\t\t\tif (g_oSettings.g_oUserSettings.ShowAnnotationNumbers && oAnnotationStack[annotation].g_bSVGHoverAnnotation !== true && oAnnotationStack[annotation].g_bSVGSearchAnnotation !== true) {\r\n\t\t\t\t\t\tvar annText = oAnnotationStack[annotation].g_iNumber;\r\n\t\t\t\t\t\toAnnotationContext.font = g_oAnnotations.g_iAnnotationNumberFontSize + \"px Varela Round\";\r\n\t\t\t\t\t\toAnnotationContext.textBaseline = \"bottom\";\r\n\t\t\t\t\t\toAnnotationContext.textalign = \"center\";\r\n\t\t\t\t\t\tvar areaTextSize = oAnnotationContext.measureText(annText);\r\n\t\t\t\t\t\tvar iGlobalAnnotationShiftX = 0;\r\n\t\t\t\t\t\tvar iGlobalAnnotationShiftY = 0;\r\n\r\n\t\t\t\t\t\t// If this is a global annotation.\r\n\t\t\t\t\t\tif (annTyp == eAnnotationTypes.Global) {\r\n\r\n\t\t\t\t\t\t\t// Move the annotation number down and left by default.\r\n\t\t\t\t\t\t\tiGlobalAnnotationShiftY = 40;\r\n\t\t\t\t\t\t\tiGlobalAnnotationShiftX -= areaTextSize.width;\r\n\r\n\t\t\t\t\t\t\t// Move the annotation number down by 20 for each of the previous global annotations.\r\n\t\t\t\t\t\t\tiGlobalAnnotationShiftY += (iGlobalCounter * 20);\r\n\r\n\t\t\t\t\t\t\t// If there is a compare rotation of 90 or 270.\r\n\t\t\t\t\t\t\tif (iCompareRotation == 180 || iCompareRotation == 270) {\r\n\r\n\t\t\t\t\t\t\t\t// Reverse the iGlobalAnnotationShiftY.\r\n\t\t\t\t\t\t\t\tiGlobalAnnotationShiftY = (1 - iGlobalAnnotationShiftY);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Increment the global annotation counter.\r\n\t\t\t\t\t\t\tiGlobalCounter++;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t// Start the drawing.\r\n\t\t\t\t\t\toAnnotationContext.fillStyle = annCol;\r\n\t\t\t\t\t\toAnnotationContext.setLineDash([]);\r\n\t\t\t\t\t\toAnnotationContext.beginPath();\r\n\r\n\t\t\t\t\t\t// Add the number background.\r\n\t\t\t\t\t\toAnnotationContext.rect(annotationArray[0][0] * iImageObjW + iCenterShift_x + compareOffset_x - g_oAnnotations.g_oAnnotationNumberBox.iBeginX + iGlobalAnnotationShiftX, annotationArray[0][1] * iImageObjH + iCenterShift_y + compareOffset_y - g_oAnnotations.g_oAnnotationNumberBox.iBeginY + iGlobalAnnotationShiftY, areaTextSize.width + g_oAnnotations.g_oAnnotationNumberBox.iWidth, g_oAnnotations.g_oAnnotationNumberBox.iHeight);\r\n\t\t\t\t\t\toAnnotationContext.fill();\r\n\r\n\t\t\t\t\t\t// For readability yellow or cyan annotations should be black.\r\n\t\t\t\t\t\tif (annCol === \"yellow\" || annCol === \"#FFFF00\" || annCol === \"cyan\" || annCol === \"#00FFFF\") {\r\n\t\t\t\t\t\t\toAnnotationContext.fillStyle = \"#000000\";\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse {\r\n\t\t\t\t\t\t\toAnnotationContext.fillStyle = \"#fff\";\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t// Add the number text.\r\n\t\t\t\t\t\toAnnotationContext.fillText(annText, annotationArray[0][0] * iImageObjW + iCenterShift_x + compareOffset_x - g_oAnnotations.g_oAnnotationNumberText.iBeginX + iGlobalAnnotationShiftX, annotationArray[0][1] * iImageObjH + iCenterShift_y + compareOffset_y - g_oAnnotations.g_oAnnotationNumberText.iBeginY + iGlobalAnnotationShiftY);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Draw the drag icons if the viewer is editable and the type is not TextMeasurement, Text Highlight, Global, SVG or 3D and the annotation has been selected (not closed).\r\n\t\t\t\tif (!g_oViewer.g_bReadOnly\r\n\t\t\t\t\t&& annTyp !== eAnnotationTypes.TextMeasurement\r\n\t\t\t\t\t&& annTyp !== eAnnotationTypes.TextHighlight\r\n\t\t\t\t\t&& annTyp !== eAnnotationTypes.TextClassification\r\n\t\t\t\t\t&& annTyp !== eAnnotationTypes.Global\r\n\t\t\t\t\t&& annTyp !== eAnnotationTypes.ThreeD\r\n\t\t\t\t\t&& oAnnotationStack[annotation].g_bSVGTextAnnotation === false\r\n\t\t\t\t\t&& !this.isAnnotationClosed(oAnnotationStack[annotation], oAnnotationStack)\r\n\t\t\t\t\t&& oAnnotationStack[annotation].g_bVisible && g_oSettings.g_oUserSettings.ShowAnnotations\r\n\t\t\t\t\t&& bShowAnnotaionsOnCanvas && !oAnnotationCanvas.g_bIsAnimating) {\r\n\t\t\t\t\tg_oAnnotationActions.createAnnotationHandle(oAnnotationStack[annotation]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Bind the handle detection. Need unique event class as to not unbind old logic, but still only bind this once.\r\n\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove.annotationUIRedraw\", function (event) {\r\n\t\t\tg_oAnnotationActions.mouseMove(event, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t});\r\n\r\n\t\t// Focus any open editors.\r\n\t\t$(\".jqte_editor\").focus();\r\n\t};\r\n\r\n\tAnnotationUI.prototype.isAnnotationClosed = function (oAnnotation, oAnnotationStack) {\r\n\t\tvar bclosed = oAnnotation.g_bClosed;\r\n\t\tvar iparentId = oAnnotation.g_iParentAnnotationId;\r\n\r\n\t\tif (bclosed && iparentId > 0) { // Check if parent is open.\r\n\t\t\tfor (var oAnnotaionIndex in oAnnotationStack) {\r\n\t\t\t\tif (oAnnotationStack[oAnnotaionIndex].id === iparentId) {\r\n\t\t\t\t\tbclosed = oAnnotationStack[oAnnotaionIndex].g_bClosed;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn bclosed;\r\n\t};\r\n\r\n\t/*\r\n\t * Removes all 3D Annotations from the Canvas.\r\n\t */\r\n\tAnnotationUI.prototype.clearMesh = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t// Remove the Meshes (Annotations)\r\n\t\tif (!(typeof oArtworkCanvas.g_oScene === \"undefined\")) {\r\n\t\t\tvar oAnnotationMesh = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.type == \"Mesh\"; });\r\n\t\t\tg_oAnnotations.removeThreeJSObjects(oAnnotationMesh, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t}\r\n\t};\r\n\r\n\t/*\r\n\t * Redraws 3D Annotations to the Canvas.\r\n\t */\r\n\tAnnotationUI.prototype.redraw3DAnnotations = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\tif (oArtworkCanvas === null || typeof (oArtworkCanvas.g_oScene) === \"undefined\") {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// We get rid of / redraw the annotation lines at each iteration of the loop.\r\n\t\tvar lineSceneObj = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.class == \"annLine\"; });\r\n\t\tthis.removeThreeJSObjects(lineSceneObj, oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t// Determine if the annotations should be shown for this canvas.\r\n\t\tvar bShowAnnotaionsOnCanvas = (oAnnotationCanvas.g_szCanvasId == g_oCompare.getAnnotationCanvasId());\r\n\r\n\t\t// Number the annotations ignoring annotations not on the active annotations canvas.\r\n\t\tvar counter = 1;\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\t//if we are in compare mode and on the compare document\r\n\t\t\tif (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && $(\"#chkAnnotationToggle\").prop(\"checked\")) {\r\n\t\t\t\tvar oCurrentDocument = g_oaComboControls[1].documents[g_oaComboControls[1].selectedDocumentIndex];\r\n\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentId !== oCurrentDocument.document.documentId) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tvar oCurrentDocument = g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex];\r\n\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iDocumentId !== oCurrentDocument.document.documentId) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iParentAnnotationId == 0) {\r\n\t\t\t\tg_oAnnotations.g_oAnnotationsMade[i].g_iNumber = counter;\r\n\t\t\t\tcounter++;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// For the child annotations in the list, we need to set their number and text to their parents.\r\n\t\t\t\tvar oParentAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (parent) {\r\n\t\t\t\t\treturn parent.id == g_oAnnotations.g_oAnnotationsMade[i].g_iParentAnnotationId;\r\n\t\t\t\t});\r\n\t\t\t\tg_oAnnotations.g_oAnnotationsMade[i].g_iNumber = oParentAnnotation[0].g_iNumber;\r\n\t\t\t\tg_oAnnotations.g_oAnnotationsMade[i].g_szTextContent = oParentAnnotation[0].g_szTextContent;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Loop through each of the annotations in the stack.\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\t// Loop through all the annotations we have.\r\n\t\t\tvar oCurrentAnnotation = g_oAnnotations.g_oAnnotationsMade[i];\r\n\r\n\t\t\t// Ensure the annotation is part of the current document.\r\n\t\t\tif (oArtworkCanvas.g_oDoc.documentId != oCurrentAnnotation.g_iDocumentId) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// If this Annotation currently exists.\r\n\t\t\tvar existingAnnotation = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.Id == oCurrentAnnotation.id; });\r\n\t\t\tvar existingDiv = $(\"#\" + oCurrentAnnotation.id);\r\n\r\n\t\t\t// Hide and set visibility options based on approval options.\r\n\t\t\tif (existingAnnotation.length > 0) {\r\n\t\t\t\tfor (var j = 0; j < existingAnnotation.length; j++) {\r\n\t\t\t\t\texistingAnnotation[j].visible = (oCurrentAnnotation.g_bVisible && g_oSettings.g_oUserSettings.ShowAnnotations && bShowAnnotaionsOnCanvas);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tvar existingAnnotationNumber = $.grep(oArtworkCanvas.g_oScene.children, function (child) {\r\n\t\t\t\treturn child.Id == \"annNo_\" + oCurrentAnnotation.id;\r\n\t\t\t});\r\n\t\t\tif (existingAnnotationNumber.length > 0) {\r\n\t\t\t\tfor (var j = 0; j < existingAnnotationNumber.length; j++) {\r\n\t\t\t\t\texistingAnnotationNumber[j].visible = (oCurrentAnnotation.g_bVisible && g_oSettings.g_oUserSettings.ShowAnnotationNumbers && bShowAnnotaionsOnCanvas && g_oSettings.g_oUserSettings.ShowAnnotationNumbers);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// If there is a scene already present.\r\n\t\t\tif (existingDiv.length > 0) {\r\n\t\t\t\tvar oCoords = [parseInt($(existingDiv[0]).css(\"left\")), parseInt($(existingDiv[0]).css(\"top\"))];\r\n\t\t\t\toCoords[0] -= oArtworkCanvas.g_oContainer.offsetLeft;\r\n\t\t\t\tif (oCurrentAnnotation.g_bVisible && bShowAnnotaionsOnCanvas) {\r\n\t\t\t\t\tvar oChildAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return annotation.g_iParentAnnotationId === oCurrentAnnotation.id && annotation.g_iAnnotationType === eAnnotationTypes.ThreeD; });\r\n\t\t\t\t\tg_oAnnotations.drawLineTo3DAnnotation(oCoords, oCurrentAnnotation, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\tfor (var j = 0; j < oChildAnnotations.length; j++) {\r\n\t\t\t\t\t\tg_oAnnotations.drawLineTo3DAnnotation(oCoords, oChildAnnotations[j], oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (existingAnnotation.length > 0) {\r\n\t\t\t\t// Reset its colour back to normal\r\n\t\t\t\texistingAnnotation[0].material.color.set(oCurrentAnnotation.g_szColour);\r\n\t\t\t\t// We need to generate a new particle shape for the canvas.\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tif (g_oSettings.g_oUserSettings.ShowAnnotations && bShowAnnotaionsOnCanvas) {\r\n\t\t\t\t\tvar particle = new THREE.Mesh(new THREE.SphereGeometry(g_oAnnotations.threeDannotationSize, 32, 32), new THREE.MeshPhongMaterial({ color: oCurrentAnnotation.g_szColour, opacity: 0.8, transparent: true }));\r\n\t\t\t\t\tparticle.position.x = oCurrentAnnotation.g_oDrawArray[0][0];\r\n\t\t\t\t\tparticle.position.y = oCurrentAnnotation.g_oDrawArray[0][1];\r\n\t\t\t\t\tparticle.position.z = oCurrentAnnotation.g_oDrawArray[0][2];\r\n\t\t\t\t\tparticle.scale.x = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\tparticle.scale.y = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\tparticle.scale.z = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\tparticle.Id = oCurrentAnnotation.id;\r\n\t\t\t\t\toArtworkCanvas.g_oScene.add(particle);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (g_oSettings.g_oUserSettings.ShowAnnotations && bShowAnnotaionsOnCanvas) {\r\n\t\t\t\tvar existingAnnotationNumberObj = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.Id == \"annNo_\" + oCurrentAnnotation.id; });\r\n\t\t\t\tif (existingAnnotationNumberObj.length === 0 && g_oSettings.g_oUserSettings.ShowAnnotationNumbers) {\r\n\t\t\t\t\t// Draw annotation number\r\n\r\n\t\t\t\t\tvar annotationNo = new THREE.TextGeometry(g_oAnnotations.g_oAnnotationsMade[i].g_iNumber, {\r\n\t\t\t\t\t\tfont: oArtworkCanvas.g_oFont,\r\n\t\t\t\t\t\tweight: \"normal\",\r\n\t\t\t\t\t\tstyle: \"normal\",\r\n\t\t\t\t\t\tsize: 0.005,\r\n\t\t\t\t\t\theight: 0.0005,\r\n\t\t\t\t\t\tcurveSegments: 55,\r\n\t\t\t\t\t\tbevelThickness: 0.0005,\r\n\t\t\t\t\t\tbevelSize: 0.0005,\r\n\t\t\t\t\t\tbevelEnabled: true\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\tannotationNo.computeBoundingBox();\r\n\t\t\t\t\tvar material = new THREE.MeshPhongMaterial({ color: oCurrentAnnotation.g_szColour, specular: 0xffffff });\r\n\t\t\t\t\tvar textMesh = new THREE.Mesh(annotationNo, material);\r\n\t\t\t\t\ttextMesh.position.x = oCurrentAnnotation.g_oDrawArray[0][0];\r\n\t\t\t\t\ttextMesh.position.y = oCurrentAnnotation.g_oDrawArray[0][1];\r\n\t\t\t\t\ttextMesh.position.z = oCurrentAnnotation.g_oDrawArray[0][2];\r\n\t\t\t\t\ttextMesh.scale.x = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\ttextMesh.scale.y = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\ttextMesh.scale.z = oArtworkCanvas.g_iAnnotationScale;\r\n\t\t\t\t\ttextMesh.Id = \"annNo_\" + oCurrentAnnotation.id;\r\n\t\t\t\t\ttextMesh.receiveShadow = true;\r\n\t\t\t\t\ttextMesh.castShadow = true;\r\n\r\n\t\t\t\t\tvar iXTranslate = g_oAnnotations.getTranslationValues(oCurrentAnnotation.g_oDrawArray[0][0]);\r\n\t\t\t\t\tvar iYTranslate = g_oAnnotations.getTranslationValues(oCurrentAnnotation.g_oDrawArray[0][1]);\r\n\r\n\t\t\t\t\t// We want to offset the annotation number from the annotation itself.\r\n\t\t\t\t\ttextMesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(iXTranslate, iYTranslate, 0));\r\n\t\t\t\t\toArtworkCanvas.g_oScene.add(textMesh);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * The function called when completing an approval status.\r\n\t */\r\n\tAnnotationUI.prototype.approverStatusSetEvent = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t$(\"#tblAnnotateTools\").hide();\r\n\t\tg_oViewer.g_bReadOnly = true;\r\n\t\tg_oAnnotations.rebuildAnnotationList(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t$(\".annotationViewer\").off();\r\n\t};\r\n\r\n\t/**\r\n\t * The function called when changing pages.\r\n\t */\r\n\tAnnotationUI.prototype.changeCurrentPageEvent = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t// Remove any open bubbles and clear the list.\r\n\t\t$(\".speechbubble\").remove();\r\n\t\t$(\".annotationListItem\").remove();\r\n\t\tg_oAnnotations.rebuildAnnotationList(oArtworkCanvas, oAnnotationCanvas);\t\t// Add the highlight.\r\n\t};\r\n\r\n\t/**\r\n\t * Registers the approvals events.\r\n\t * @param {object} oEventService - The event service we are registering the events to.\r\n\t */\r\n\tAnnotationUI.prototype.registerEvents = function (oEventService) {\r\n\t\toEventService.subscribe(\"approverStatusSet\", g_oAnnotations.approverStatusSetEvent);\r\n\t\toEventService.subscribe(\"changeCurrentPage\", g_oAnnotations.changeCurrentPageEvent);\r\n\t\toEventService.subscribe(\"approvalSet\", g_oAnnotations.changeDocumentAnnotations);\r\n\t\toEventService.subscribe(\"approvalSet\", g_oFilter.setupFilters);\r\n\t\toEventService.subscribe(\"setExistingTextMeasurementAnnotationWordsList\", g_oAnnotations.setExistingTextMeasurementAnnotationWordsList);\r\n\t\toEventService.subscribe(\"setTempMarqueeCoordinates\", g_oAnnotations.setTempMarqueeCoordinates);\r\n\t};\r\n\r\n\t/**\r\n\t * To free resources in 3D JS we must manually release the resourced. This method will\r\n\t * free the annotation resources.\r\n\t * @param {var} objects- Objects which need releasing.\r\n\t */\r\n\tAnnotationUI.prototype.removeThreeJSObjects = function (objects, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\tfor (var i = 0; i < objects.length; i++) {\r\n\t\t\tvar object = objects[i];\r\n\t\t\tvar children = oArtworkCanvas.g_oScene.children;\r\n\t\t\tfor (var j = 0; j < children.length; j++) {\r\n\t\t\t\tvar node = children[j];\r\n\t\t\t\tif (node.id == object.id) {\r\n\t\t\t\t\toArtworkCanvas.g_oScene.remove(object);\r\n\t\t\t\t\tnode.geometry.dispose();\r\n\t\t\t\t\tnode.material.dispose();\r\n\t\t\t\t\tif (node.material.map) {\r\n\t\t\t\t\t\tnode.material.map.dispose();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnode = undefined;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Renders in the number of annotations for the page icons.\r\n\t */\r\n\tAnnotationUI.prototype.renderPageAnnotationNumbers = function () {\r\n\r\n\t\t// Get the artwork canvas.\r\n\t\tvar oArtworkCanvas = g_oViewer.g_oArtworkViewer;\r\n\r\n\t\t// Only do this if the pages object isn't empty!\r\n\t\tif (!$.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\r\n\t\t\t// Get the index of the approval document combo control.\r\n\t\t\tvar iComboControl = comboControl_GetControlById(\"approvalNameComboControl\", true);\r\n\r\n\t\t\t// Loop through all the pages.\r\n\t\t\tfor (var i = 0; i < oArtworkCanvas.g_oDoc.pages.length; i++) {\r\n\r\n\t\t\t\t// Find the annotations for this page.\r\n\t\t\t\tvar oThisPagesAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) {\r\n\t\t\t\t\treturn annotation.g_iDocumentPageId == oArtworkCanvas.g_oDoc.pages[i].documentPageId && annotation.g_szTextContent != \"\" && annotation.g_iAnnotationType !== eAnnotationTypes.ThreeD && annotation.g_iParentAnnotationId === 0;\r\n\t\t\t\t});\r\n\r\n\t\t\t\t// If there are any annotations for the page, update the icons.\r\n\t\t\t\tif (oThisPagesAnnotations.length > 0) {\r\n\t\t\t\t\t$(\"#divComboControlList_\" + iComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iComboControl].selectedDocumentIndex).find(\"#spnComboDocumentPage_\" + i + \"_annotationNumberText\").html(oThisPagesAnnotations.length);\r\n\t\t\t\t\t$(\"#divComboControlList_\" + iComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iComboControl].selectedDocumentIndex).find(\"#trComboDocumentPage_\" + i + \"_annotationNumber\").show();\r\n\t\t\t\t}\r\n\t\t\t\t// If there aren't any annotations found for this page, hide the icons.\r\n\t\t\t\telse {\r\n\t\t\t\t\t$(\"#tblComboControlList_\" + iComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iComboControl].selectedDocumentIndex).find(\"#spnComboDocumentPage_\" + i + \"_annotationNumberText\").html(0);\r\n\t\t\t\t\t$(\"#tblComboControlList_\" + iComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iComboControl].selectedDocumentIndex).find(\"#trComboDocumentPage_\" + i + \"_annotationNumber\").hide();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// If we are in a compare mode.\r\n\t\tif (g_oViewer.g_oCompareMode !== eCompareMode.NoCompare) {\r\n\r\n\t\t\t// Get the compare artwork canvas.\r\n\t\t\tvar oCompareArtworkCanvas = g_oCompare.g_oCompareViewer;\r\n\r\n\t\t\t// If the compare artwork canvas has pages.\r\n\t\t\tif (!$.isEmptyObject(oCompareArtworkCanvas.g_oDoc.pages)) {\r\n\r\n\t\t\t\t// Get the index of the compare document combo control.\r\n\t\t\t\tvar iCompareComboControl = comboControl_GetControlById(\"approvalCompareComboControl\", true);\r\n\r\n\t\t\t\t// Loop through all the pages.\r\n\t\t\t\tfor (var i = 0; i < oCompareArtworkCanvas.g_oDoc.pages.length; i++) {\r\n\r\n\t\t\t\t\t// Find the annotations for this page.\r\n\t\t\t\t\tvar oThisPagesAnnotations = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) {\r\n\t\t\t\t\t\treturn annotation.g_iDocumentPageId == oCompareArtworkCanvas.g_oDoc.pages[i].documentPageId && annotation.g_szTextContent != \"\" && annotation.g_iAnnotationType !== eAnnotationTypes.ThreeD;\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\t// If there are any annotations for the page, update the icons.\r\n\t\t\t\t\tif (oThisPagesAnnotations.length > 0) {\r\n\t\t\t\t\t\t$(\"#divComboControlList_\" + iCompareComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iCompareComboControl].selectedDocumentIndex).find(\"#spnComboDocumentPage_\" + i + \"_annotationNumberText\").html(oThisPagesAnnotations.length);\r\n\t\t\t\t\t\t$(\"#divComboControlList_\" + iCompareComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iCompareComboControl].selectedDocumentIndex).find(\"#trComboDocumentPage_\" + i + \"_annotationNumber\").show();\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// If there aren't any annotations found for this page, hide the icons.\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\t$(\"#tblComboControlList_\" + iCompareComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iCompareComboControl].selectedDocumentIndex).find(\"#spnComboDocumentPage_\" + i + \"_annotationNumberText\").html(0);\r\n\t\t\t\t\t\t$(\"#tblComboControlList_\" + iCompareComboControl).find(\"#divComboDocumentPages_\" + g_oaComboControls[iCompareComboControl].selectedDocumentIndex).find(\"#trComboDocumentPage_\" + i + \"_annotationNumber\").hide();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t* Sets up the annotations initial load\r\n\t* @param {string} oJSON - The string containing all the annotations\r\n\t*\r\n\t*/\r\n\tAnnotationUI.prototype.setupAnnotations = function (oJSON, oArtworkCanvas, oAnnotationCanvas, szColladaModelTexture) {\r\n\r\n\t\t// Extract the list of annotations returned.\r\n\t\tvar oMasterList = oJSON;\r\n\r\n\t\t// Loop through the returned objects.\r\n\t\tfor (var i = 0; i < oMasterList.length; i++) {\r\n\t\t\tvar oNewAnnotation = new window.Annotation(g_oAnnotations.g_iApprovalId);\r\n\r\n\t\t\toNewAnnotation.id = oMasterList[i].annotationId;\r\n\t\t\toNewAnnotation.g_szColour = oMasterList[i].annotationColour;\r\n\t\t\toNewAnnotation.g_iAnnotationType = oMasterList[i].annotationType;\r\n\t\t\toNewAnnotation.g_oAnnotationData = oMasterList[i].annotationData == \"\" ? null : JSON.parse(oMasterList[i].annotationData);\r\n\t\t\toNewAnnotation.createdDate = moment.utc(oMasterList[i].annotationDateTime, moment.ISO_8601).local();\r\n\t\t\toNewAnnotation.g_szTextContent = oMasterList[i].annotationContent;\r\n\t\t\toNewAnnotation.modifiedDate = moment.utc(oMasterList[i].modifiedDateTime, moment.ISO_8601).local();\r\n\t\t\toNewAnnotation.g_oSVGVariable = oMasterList[i].svgVariableId == \"\" ? null : JSON.parse(oMasterList[i].svgVariableId);\r\n\t\t\toNewAnnotation.g_szSVGOriginalContent = oMasterList[i].svgOriginalContent;\r\n\t\t\toNewAnnotation.g_szTextHighlightContent = oMasterList[i].textHighlightContent;\r\n\t\t\tif (oNewAnnotation.g_oSVGVariable != null) {\r\n\t\t\t\toNewAnnotation.g_bSVGTextAnnotation = true;\r\n\t\t\t\toNewAnnotation.g_bSVGPositionUpdated = true;\r\n\t\t\t}\r\n\t\t\toNewAnnotation.g_iParentAnnotationId = oMasterList[i].replyToAnnotId;\r\n\t\t\toNewAnnotation.g_iDocumentId = oMasterList[i].documentId;\r\n\t\t\toNewAnnotation.g_iDocumentPageId = oMasterList[i].documentPageId;\r\n\t\t\toNewAnnotation.g_iAuthor = oMasterList[i].approvalUserId;\r\n\t\t\toNewAnnotation.g_szAuthorEmail = oMasterList[i].approvalUserEmailAddress;\r\n\t\t\toNewAnnotation.g_szAuthorDisplayName = oMasterList[i].approvalUserDisplayName;\r\n\t\t\toNewAnnotation.g_bSaved = true;\r\n\t\t\toNewAnnotation.g_bUnlocked = oMasterList[i].unlocked;\r\n\t\t\toNewAnnotation.g_iuvX = oMasterList[i].annotationCoords[0].annotation3dvUVx;\r\n\t\t\toNewAnnotation.g_iuvY = oMasterList[i].annotationCoords[0].annotation3dvUVy;\r\n\t\t\toNewAnnotation.szColladaModelTexture = typeof szColladaModelTexture === \"undefined\" ? \"\" : szColladaModelTexture;\r\n\t\t\toNewAnnotation.attachments = oMasterList[i].attachments;\r\n\r\n\t\t\t// Now loop through the coordinates to add them to the draw Array.\r\n\t\t\tfor (var j = 0; j < oMasterList[i].annotationCoords.length; j++) {\r\n\t\t\t\tvar nCoordSet = this.DrawCoordinatesSet(oMasterList[i].annotationCoords[j].annotationCoordId,\r\n\t\t\t\t\toMasterList[i].annotationCoords[j].annotationId,\r\n\t\t\t\t\toMasterList[i].annotationCoords[j].annotationX,\r\n\t\t\t\t\toMasterList[i].annotationCoords[j].annotationY,\r\n\t\t\t\t\toMasterList[i].annotationCoords[j].annotationZ != null ? oMasterList[i].annotationCoords[j].annotationZ : \"\");\r\n\r\n\t\t\t\toNewAnnotation.g_oDrawCoordSetArray.push(nCoordSet);\r\n\r\n\t\t\t\toNewAnnotation.g_oDrawArray.push([oMasterList[i].annotationCoords[j].annotationX,\r\n\t\t\t\toMasterList[i].annotationCoords[j].annotationY,\r\n\t\t\t\toMasterList[i].annotationCoords[j].annotationZ != null ? oMasterList[i].annotationCoords[j].annotationZ : \"\"]);\r\n\r\n\t\t\t\tif (oNewAnnotation.g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t\toNewAnnotation.g_oMarqueeDrawArray.push([oMasterList[i].annotationCoords[j].marqueeX,\r\n\t\t\t\t\toMasterList[i].annotationCoords[j].marqueeY]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (oMasterList[i].annotationCoords[0].annotation3dvUVx !== -1 && oMasterList[i].annotationCoords[0].annotation3dvUVy !== -1) {\r\n\t\t\t\toNewAnnotation.Convert2DTo3DAnnotation(oMasterList[i].annotationCoords[0].annotation3dvUVx, oMasterList[i].annotationCoords[0].annotation3dvUVy, szColladaModelTexture, oArtworkCanvas.g_oScene);\r\n\t\t\t}\r\n\r\n\t\t\t// Get the current page.\r\n\t\t\tvar iPageId = 0;\r\n\t\t\tif (!$.isEmptyObject(oArtworkCanvas.g_oDoc.pages)) {\r\n\t\t\t\tfor (var m = 0; m < oArtworkCanvas.g_oDoc.pages.length; m++) {\r\n\t\t\t\t\tif (oArtworkCanvas.g_oDoc.pages[m].documentPageNumber == oArtworkCanvas.g_iCurrentPage) {\r\n\t\t\t\t\t\tiPageId = oArtworkCanvas.g_oDoc.pages[m].documentPageId;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse if (oArtworkCanvas.g_oDoc.Approval3DViewId > -1) {\r\n\t\t\t\t// Get the 3D previews parent page Id\r\n\t\t\t\tvar iParentPageId = $.findfirst(g_oThreeDView.g_oApprovalThreeDViews, function (x) {\r\n\t\t\t\t\treturn x.Approval3DViewId === oArtworkCanvas.g_oDoc.Approval3DViewId;\r\n\t\t\t\t}).ParentDocumentPageId;\r\n\t\t\t\tiPageId = iParentPageId;\r\n\r\n\t\t\t\t// Do not add the 3D previews annotation if its not from its parents page.\r\n\t\t\t\tif (oNewAnnotation.g_iDocumentPageId !== iParentPageId && oNewAnnotation.g_iAnnotationType === eAnnotationTypes.ThreeD) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (oNewAnnotation.g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t// Check whether the annotation is already loaded.\r\n\t\t\t\tvar existingAnnotation = $.findfirst(this.g_oExistingTextAnnotations, function (anno) { return anno.id === oNewAnnotation.id; });\r\n\t\t\t\tif ((!existingAnnotation) && (oNewAnnotation.g_oTextMeasurementWordsArray.length === 0 && (iPageId == 0 || iPageId == oNewAnnotation.g_iDocumentPageId))) {\r\n\t\t\t\t\tvar oData = {\r\n\t\t\t\t\t\toAnnotation: oNewAnnotation,\r\n\t\t\t\t\t\toArtworkCanvas: oArtworkCanvas,\r\n\t\t\t\t\t\toAnnotationCanvas: oAnnotationCanvas\r\n\t\t\t\t\t};\r\n\t\t\t\t\tEventService.publish(\"getTextMeasurementText\", oData);\r\n\t\t\t\t}\r\n\t\t\t\telse if (!!existingAnnotation) {\r\n\t\t\t\t\toNewAnnotation.g_oTextMeasurementWordsArray = existingAnnotation.g_oTextMeasurementWordsArray;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Add the annotation replies.\r\n\t\t\toNewAnnotation.g_oReplies = [];\r\n\t\t\tfor (var k = 0; k < oMasterList[i].annotationReplies.length; k++) {\r\n\t\t\t\tvar oNewAnnotationReply = new window.Annotation(g_oAnnotations.g_iApprovalId);\r\n\r\n\t\t\t\toNewAnnotationReply.id = oMasterList[i].annotationReplies[k].annotationId;\r\n\t\t\t\toNewAnnotationReply.g_szColour = oMasterList[i].annotationReplies[k].annotationColour;\r\n\t\t\t\toNewAnnotationReply.g_iAnnotationType = oMasterList[i].annotationReplies[k].annotationType;\r\n\t\t\t\toNewAnnotationReply.g_oAnnotationData = oMasterList[i].annotationReplies[k].annotationData == \"\" ? null : JSON.parse(oMasterList[i].annotationReplies[k].annotationData);\r\n\t\t\t\toNewAnnotationReply.createdDate = moment.utc(oMasterList[i].annotationReplies[k].annotationDateTime, moment.ISO_8601).local();\r\n\t\t\t\toNewAnnotationReply.g_szTextContent = oMasterList[i].annotationReplies[k].annotationContent;\r\n\t\t\t\toNewAnnotationReply.modifiedDate = moment.utc(oMasterList[i].annotationReplies[k].modifiedDateTime, moment.ISO_8601).local();\r\n\t\t\t\toNewAnnotationReply.g_iParentAnnotationId = oMasterList[i].annotationReplies[k].replyToAnnotId;\r\n\t\t\t\toNewAnnotationReply.g_iDocumentId = oMasterList[i].annotationReplies[k].documentId;\r\n\t\t\t\toNewAnnotationReply.g_iDocumentPageId = oMasterList[i].annotationReplies[k].documentPageId;\r\n\t\t\t\toNewAnnotationReply.g_iAuthor = oMasterList[i].annotationReplies[k].approvalUserId;\r\n\t\t\t\toNewAnnotationReply.g_szAuthorEmail = oMasterList[i].annotationReplies[k].approvalUserEmailAddress;\r\n\t\t\t\toNewAnnotationReply.g_szAuthorDisplayName = oMasterList[i].annotationReplies[k].approvalUserDisplayName;\r\n\t\t\t\toNewAnnotationReply.g_bSaved = true;\r\n\t\t\t\toNewAnnotationReply.g_bUnlocked = oMasterList[i].annotationReplies[k].unlocked;\r\n\r\n\t\t\t\toNewAnnotation.g_oReplies.push(oNewAnnotationReply);\r\n\t\t\t}\r\n\t\t\tg_oAnnotations.g_oAnnotationsMade.push(oNewAnnotation);\r\n\r\n\t\t\t// Now we can add in the Statuses.\r\n\t\t\toNewAnnotation.g_oStatuses = [];\r\n\t\t\tfor (var l = 0; l < oMasterList[i].annotationStatuses.length; l++) {\r\n\t\t\t\tvar oNewAnnotationStatus = new window.AnnotationStatus();\r\n\r\n\t\t\t\toNewAnnotationStatus.id = oMasterList[i].annotationStatuses[l].annotationstatusId;\r\n\t\t\t\toNewAnnotationStatus.g_iAuthor = oMasterList[i].annotationStatuses[l].approvalUserId;\r\n\t\t\t\toNewAnnotationStatus.g_szAuthorEmail = oMasterList[i].annotationStatuses[l].approvalUserEmailAddress;\r\n\t\t\t\toNewAnnotationStatus.g_szAuthorDisplayName = oMasterList[i].annotationStatuses[l].approvalUserDisplayName;\r\n\t\t\t\toNewAnnotationStatus.g_iAnnotationStatus = oMasterList[i].annotationStatuses[l].annotationStatus;\r\n\t\t\t\toNewAnnotationStatus.g_iApprovalUserAnnotId = oMasterList[i].annotationStatuses[l].annotationId;\r\n\t\t\t\toNewAnnotationStatus.annotationStatusDateTime = moment.utc(oMasterList[i].annotationStatuses[l].annotationStatusDateTime, moment.ISO_8601).local();\r\n\r\n\t\t\t\toNewAnnotation.g_oStatuses.push(oNewAnnotationStatus);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Rebuild the annotation list.\r\n\t\tg_oAnnotations.rebuildAnnotationList(oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t// For 3D Annotations.\r\n\t\tif (oArtworkCanvas.g_oDoc.documentType === eDocumentTypes.ThreeD) {\r\n\t\t\t// Clicking will try to find an annotation, as with the main viewer.\r\n\t\t\t$(oArtworkCanvas.g_oCanvas).on(\"click\", function (e) {\r\n\t\t\t\tg_oAnnotations.findThreeDAnnotations(e, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t});\r\n\t\t\tvar _this = g_oAnnotations;\r\n\t\t\tvar _oArtworkCanvas = oArtworkCanvas;\r\n\t\t\tvar _oAnnotationCanvas = oAnnotationCanvas;\r\n\t\t\t// Load in the font.\r\n\t\t\toArtworkCanvas.g_oFontLoader = new THREE.FontLoader();\r\n\t\t\toArtworkCanvas.g_oFontLoader.load(\"/fonts/helvetiker_regular.typeface.json\", function (font) {\r\n\t\t\t\t_oArtworkCanvas.g_oFont = font;\r\n\t\t\t\t_this.redraw3DAnnotations(_oArtworkCanvas, _oAnnotationCanvas);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\t// For compare 3D Annotations.\r\n\t\tif (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && g_oCompare.g_oCompareViewer.g_oDoc.documentType == eDocumentTypes.ThreeD) {\r\n\t\t\tvar oCompareArtworkCanvas = g_oCompare.g_oCompareViewer;\r\n\t\t\tvar oCompareAnnotationCanvas = g_oCompare.g_oCompareAnnotationViewer;\r\n\r\n\t\t\t// Clicking will try to find an annotation, as with the main viewer.\r\n\t\t\t$(oCompareArtworkCanvas.g_oCanvas).on(\"click\", function (e) {\r\n\t\t\t\tg_oAnnotations.findThreeDAnnotations(e, oCompareArtworkCanvas, oCompareAnnotationCanvas);\r\n\t\t\t});\r\n\r\n\t\t\tvar _this_Compare = g_oAnnotations;\r\n\t\t\tvar _oArtworkCanvas_Compare = oCompareArtworkCanvas;\r\n\t\t\tvar _oAnnotationCanvas_Compare = oCompareAnnotationCanvas;\r\n\r\n\t\t\t// Load in the font.\r\n\t\t\toArtworkCanvas.g_oFontLoader = new THREE.FontLoader();\r\n\t\t\toArtworkCanvas.g_oFontLoader.load(\"/fonts/helvetiker_regular.typeface.json\", function (font) {\r\n\t\t\t\t_oArtworkCanvas_Compare.g_oFont = font;\r\n\t\t\t\t_this_Compare.redraw3DAnnotations(_oArtworkCanvas_Compare, _oAnnotationCanvas_Compare);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\t// For SVG documents.\r\n\t\tif (documentDisplaysAsSVG(oArtworkCanvas.g_oDoc.documentType)) {\r\n\r\n\t\t\t// Apply any SVG text updates to the document.\r\n\t\t\tg_oSVGLoader.applySVGChanges(oArtworkCanvas, oAnnotationCanvas, true);\r\n\t\t}\r\n\r\n\t\t// For SVG compare documents.\r\n\t\tif (g_oViewer.g_oCompareMode !== eCompareMode.NoCompare && documentDisplaysAsSVG(g_oCompare.g_oCompareViewer.g_oDoc.documentType)) {\r\n\t\t\tvar oCompareArtworkCanvas = g_oCompare.g_oCompareViewer;\r\n\t\t\tvar oCompareAnnotationCanvas = g_oCompare.g_oCompareAnnotationViewer;\r\n\r\n\t\t\t// Apply any SVG text updated to the document.\r\n\t\t\tg_oSVGLoader.applySVGChanges(oCompareArtworkCanvas, oCompareAnnotationCanvas, true);\r\n\t\t}\r\n\r\n\t\t// Call the change canvas function to bind the find annotations.\r\n\t\tchangeCanvasFunction();\r\n\t\tchangeCanvasFunction(\"#AnnotationViewer\", \"pointermove.annotationUI\", function (e) {\r\n\t\t\tg_oAnnotationActions.mouseMoveLite(e, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t});\r\n\r\n\t\t// Select tool/colour if they exist for the user.\r\n\t\tif (!g_oViewer.g_bReadOnly) {\r\n\t\t\tg_oAnnotations.presetUserTools();\r\n\t\t}\r\n\r\n\t\t// Recalculate the page annotation numbers.\r\n\t\tg_oAnnotations.renderPageAnnotationNumbers();\r\n\t}\r\n\r\n\t/**\r\n\t * Filters the annotation list for when we are comparing 3D Previews with their parents.\r\n\t * */\r\n\tAnnotationUI.prototype.filteredAnnotationStack = function (annotationStack) {\r\n\t\tvar filteredAnnotationList = [];\r\n\t\tvar oCurrentDocument = (g_oViewer.g_oCompareMode != eCompareMode.NoCompare && $(\"#chkAnnotationToggle\").prop(\"checked\")) ? g_oaComboControls[1].documents[g_oaComboControls[1].selectedDocumentIndex] : g_oaComboControls[0].documents[g_oaComboControls[0].selectedDocumentIndex];\r\n\r\n\t\tfor (var i = 0; i < annotationStack.length; i++) {\r\n\t\t\tvar bAlreadyAdded = false;\r\n\t\t\t// Check if Annotations is duplicated from parent.\r\n\t\t\tif (filteredAnnotationList.length > 0) {\r\n\t\t\t\tvar bAlreadyAdded = $.findfirst(filteredAnnotationList, function (x) {\r\n\t\t\t\t\treturn x.id === annotationStack[i].id && oCurrentDocument.document.documentId === x.g_iDocumentId;\r\n\t\t\t\t});\r\n\t\t\t}\r\n\r\n\t\t\tif (!bAlreadyAdded) {\r\n\t\t\t\tif (annotationStack[i].g_iDocumentId === oCurrentDocument.document.documentId) {\r\n\t\t\t\t\tif (oCurrentDocument.document.documentType !== eDocumentTypes.ThreeD && annotationStack[i].g_iAnnotationType !== eAnnotationTypes.ThreeD) {\r\n\t\t\t\t\t\tfilteredAnnotationList.push(annotationStack[i]);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (oCurrentDocument.document.documentType === eDocumentTypes.ThreeD && annotationStack[i].g_iAnnotationType === eAnnotationTypes.ThreeD) {\r\n\t\t\t\t\t\tfilteredAnnotationList.push(annotationStack[i]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn filteredAnnotationList;\r\n\t};\r\n\r\n\t/**\r\n\t * Finds the parent canvas through a passed in Speechbubble div\r\n\t * @param {string} id - The Div to search on\r\n\t * @returns {object} - The annotation itself and the parent canvas of the annotation\r\n\t */\r\n\tAnnotationUI.prototype.findParentCanvasFromAnnDiv = function (id, oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\tvar oParentCanvas = g_oAnnotations.g_iApprovalType !== 3 ? oAnnotationCanvas : oArtworkCanvas;\r\n\r\n\t\tvar oAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (ann) { return ann.id == id; });\r\n\r\n\t\t// If we have found a matching element, return.\r\n\t\tif (oAnnotation.length > 0) {\r\n\t\t\tif (g_oAnnotations.g_iApprovalType === 3) {\r\n\t\t\t\tif (oAnnotation[0].g_iAnnotationType === eAnnotationTypes.ThreeD) {\r\n\t\t\t\t\treturn { annotation: oAnnotation[0], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t\telse if (oAnnotation.length > 1) {\r\n\t\t\t\t\treturn { annotation: oAnnotation[1], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\treturn { annotation: oAnnotation[0], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tif (oAnnotation[0].g_iAnnotationType !== eAnnotationTypes.ThreeD) {\r\n\t\t\t\t\treturn { annotation: oAnnotation[0], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t\telse if (oAnnotation.length > 1) {\r\n\t\t\t\t\treturn { annotation: oAnnotation[1], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\treturn { annotation: oAnnotation[0], parentCanvas: oParentCanvas };\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Repositions an annotation pop-up when its height is changed.\r\n\t * @param {string} currentDiv - The current div of the lots.\r\n\t * @returns {int} - The height offset of the div\r\n\t */\r\n\tAnnotationUI.prototype.repositionDivForHeight = function (currentDiv) {\r\n\t\tvar iOffsetPxHeight = $(\"#\" + currentDiv).outerHeight();\r\n\t\treturn iOffsetPxHeight;\r\n\t};\r\n\r\n\t/**\r\n\t * Repositions the speech bubbles where they need to be.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.repositionSpeechBubbles = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\r\n\t\t// Reposition each pop-up and highlight box on zoom or pan change.\r\n\t\tif (!oAnnotationCanvas.g_bIsAnimating || !oArtworkCanvas.g_bIsAnimating) {\r\n\r\n\t\t\t// Calculate the compare offset of the artwork canvas.\r\n\t\t\tvar compareOffset_x, compareOffset_y;\r\n\t\t\tvar co = g_oCompare.calculateCompareOffsetInPx(oArtworkCanvas);\r\n\t\t\tcompareOffset_x = co.x / g_oViewer.c_iDPI;\r\n\t\t\tcompareOffset_y = co.y / g_oViewer.c_iDPI;\r\n\r\n\t\t\t// Get the compare rotation of the canvas.\r\n\t\t\tvar iCompareRotation = g_oCompare.getCompareRotation(oArtworkCanvas);\r\n\r\n\t\t\t// Loop through each of the speech bubbles.\r\n\t\t\t$(\".speechbubble\").each(function () {\r\n\r\n\t\t\t\t// If this annotation is not part of this canvas, do not reposition.\r\n\t\t\t\tif ($(this).attr(\"data-artworkcanvas\") != oArtworkCanvas.g_szCanvasId) {\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar oAnnotation, iId, oCoords, iNewDivLeft, iNewDivTop, iRotatedSizeDiff, bDirtystate,\r\n\t\t\t\t\timageObjW, imageObjH, iScaledImgW, iScaledImgH, iCenterShift_x, iCenterShift_y, iDragOffset_x, iDragOffset_y, oParentCanvas,\r\n\t\t\t\t\tszAnnotationColour, oCoordsOrig, iOffsetHeight, iLeftOffset, iTriangleOffset, iMargin, oResult,\r\n\t\t\t\t\toRelatedArtworkCanvas;\r\n\r\n\t\t\t\tiLeftOffset = g_oAnnotations.g_iSpeechbubbleLeftPosOffset;\r\n\t\t\t\tiTriangleOffset = g_oAnnotations.g_iSpeechbubbleTopTriangleOffset;\r\n\t\t\t\tiOffsetHeight = 0;\r\n\r\n\t\t\t\t// Margins to the sidebars.\r\n\t\t\t\tvar leftMargin, rightMargin, verticalMargin;\r\n\r\n\t\t\t\t// Margin to edges\r\n\t\t\t\tiMargin = 10;\r\n\t\t\t\tverticalMargin = leftMargin = rightMargin = iMargin;\r\n\r\n\t\t\t\t$(this).css({ \"width\": 350 });\r\n\r\n\t\t\t\tiId = $(this).attr(\"id\");\r\n\t\t\t\toResult = g_oAnnotations.findParentCanvasFromAnnDiv(iId, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\toParentCanvas = oArtworkCanvas;\r\n\r\n\t\t\t\t// Get the related artwork canvas.\r\n\t\t\t\tif (g_oViewer.g_oCompareMode !== eCompareMode.NoCompare && $(\"#chkAnnotationToggle\").prop(\"checked\")) {\r\n\t\t\t\t\t// Get document type.\r\n\r\n\t\t\t\t\tvar iCompareDocType = g_oCompare.g_oCompareViewer.g_oDoc.documentType;\r\n\r\n\t\t\t\t\tif (iCompareDocType == eAnnotationTypes.Ellipse) {\r\n\t\t\t\t\t\toRelatedArtworkCanvas = oAnnotationCanvas;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\toRelatedArtworkCanvas = oArtworkCanvas;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (g_oAnnotations.g_iApprovalType == eAnnotationTypes.Ellipse) {\r\n\t\t\t\t\t\toRelatedArtworkCanvas = oAnnotationCanvas;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\toRelatedArtworkCanvas = oArtworkCanvas;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (oResult && oResult.parentCanvas && oResult.annotation) {\r\n\t\t\t\t\toParentCanvas = oResult.parentCanvas;\r\n\t\t\t\t\tif (!(g_oViewer.g_oCompareMode !== eCompareMode.NoCompare && $(\"#chkAnnotationToggle\").prop(\"checked\"))) {\r\n\t\t\t\t\t\toRelatedArtworkCanvas = (oParentCanvas === oAnnotationCanvas ? oArtworkCanvas : oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\tif (iCompareDocType === eAnnotationTypes.Ellipse) {\r\n\t\t\t\t\t\t\toRelatedArtworkCanvas = (oParentCanvas === oAnnotationCanvas ? oArtworkCanvas : oAnnotationCanvas);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\toAnnotation = oResult.annotation;\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Ensure bubbles don't overlay the slide outs if they are open.\r\n\t\t\t\t// Increment the margins left and right by slide out sizes if these overlap.\r\n\t\t\t\tif (parseInt(document.getElementById(\"divAnnDiv\").clientWidth) > oRelatedArtworkCanvas.g_oContainer.offsetLeft) {\r\n\t\t\t\t\tleftMargin += parseInt(document.getElementById(\"divAnnDiv\").clientWidth);\r\n\t\t\t\t}\r\n\t\t\t\tif ($(\"#divViewerCell\").width() - parseInt(document.getElementById(\"divSepDiv\").clientWidth) < oRelatedArtworkCanvas.g_oContainer.offsetLeft + (oRelatedArtworkCanvas.g_oCanvas.width / g_oViewer.c_iDPI)) {\r\n\t\t\t\t\trightMargin += parseInt(document.getElementById(\"divSepDiv\").clientWidth);\r\n\t\t\t\t}\r\n\t\t\t\tif ($(\"#divViewerCell\").width() - parseInt(document.getElementById(\"divCopyMagicDiv\").clientWidth) < oRelatedArtworkCanvas.g_oContainer.offsetLeft + (oRelatedArtworkCanvas.g_oCanvas.width / g_oViewer.c_iDPI)) {\r\n\t\t\t\t\trightMargin += parseInt(document.getElementById(\"divCopyMagicDiv\").clientWidth);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Get the details of the canvas.\r\n\t\t\t\tiCenterShift_x = oRelatedArtworkCanvas.g_iCenterShift_x > 0 ? oRelatedArtworkCanvas.g_iCenterShift_x : oArtworkCanvas.g_iCenterShift_x;\r\n\t\t\t\tiCenterShift_y = oRelatedArtworkCanvas.g_iCenterShift_y > 0 ? oRelatedArtworkCanvas.g_iCenterShift_y : oArtworkCanvas.g_iCenterShift_y;\r\n\t\t\t\tiDragOffset_x = oRelatedArtworkCanvas.g_iDragOffset_x > 0 ? oRelatedArtworkCanvas.g_iDragOffset_x : oArtworkCanvas.g_iDragOffset_x;\r\n\t\t\t\tiDragOffset_y = oRelatedArtworkCanvas.g_iDragOffset_y > 0 ? oRelatedArtworkCanvas.g_iDragOffset_y : oArtworkCanvas.g_iDragOffset_y;\r\n\t\t\t\timageObjW = oRelatedArtworkCanvas.g_iCompareImage_x > 0 ? oRelatedArtworkCanvas.g_iCompareImage_x : oArtworkCanvas.g_iCompareImage_x;\r\n\t\t\t\timageObjH = oRelatedArtworkCanvas.g_iCompareImage_y > 0 ? oRelatedArtworkCanvas.g_iCompareImage_y : oArtworkCanvas.g_iCompareImage_y;\r\n\t\t\t\tiScaledImgW = oRelatedArtworkCanvas.g_iScaledImageWidth > 0 ? oRelatedArtworkCanvas.g_iScaledImageWidth : oArtworkCanvas.g_iScaledImageWidth;\r\n\t\t\t\tiScaledImgH = oRelatedArtworkCanvas.g_iScaledImageHeight > 0 ? oRelatedArtworkCanvas.g_iScaledImageHeight : oArtworkCanvas.g_iScaledImageHeight;\r\n\r\n\t\t\t\t// The compare viewer offset of the canvas.\r\n\t\t\t\tvar referenceCompareViewerOffset = oRelatedArtworkCanvas.g_oContainer.offsetLeft;\r\n\r\n\t\t\t\t// We need to know the colour so we can draw the line if needed. (colour for dotted line)\r\n\t\t\t\tszAnnotationColour = oAnnotation.g_szColour;\r\n\r\n\t\t\t\t// Get the co-ordinates of the annotation.\r\n\t\t\t\tvar oAnnotationCoords = [oAnnotation.g_oDrawArray[0][0], oAnnotation.g_oDrawArray[0][1]];\r\n\r\n\t\t\t\t// If the canvas has compare rotation.\r\n\t\t\t\tif (iCompareRotation > 0) {\r\n\r\n\t\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(oAnnotationCoords[0], oAnnotationCoords[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\t\toAnnotationCoords[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\t\toAnnotationCoords[1] = oRotatedAnnotationDraw.rotated_y;\r\n\r\n\t\t\t\t\t// If we have a compare rotation of 90 or 270, swap the width and height.\r\n\t\t\t\t\tif (iCompareRotation == 90 || iCompareRotation == 270) {\r\n\t\t\t\t\t\timageObjW = oRelatedArtworkCanvas.g_iCompareImage_y;\r\n\t\t\t\t\t\timageObjH = oRelatedArtworkCanvas.g_iCompareImage_x;\r\n\t\t\t\t\t\tiScaledImgW = oRelatedArtworkCanvas.g_iScaledImageHeight;\r\n\t\t\t\t\t\tiScaledImgH = oRelatedArtworkCanvas.g_iScaledImageWidth;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Determine the co-ordinates.\r\n\t\t\t\toCoords = [\r\n\t\t\t\t\t(oAnnotationCoords[0] * iScaledImgW / g_oViewer.c_iDPI) + (iCenterShift_x / g_oViewer.c_iDPI) + compareOffset_x,\r\n\t\t\t\t\t(oAnnotationCoords[1] * iScaledImgH / g_oViewer.c_iDPI) + (iCenterShift_y / g_oViewer.c_iDPI) + compareOffset_y\r\n\t\t\t\t];\r\n\r\n\t\t\t\t// Override the coordinates if the div has been dragged manually\r\n\t\t\t\tif ($(this).hasClass(\"noAfter\")) {\r\n\r\n\t\t\t\t\t// We need to know the origin to draw the line from.\r\n\t\t\t\t\toCoordsOrig = oCoords;\r\n\r\n\t\t\t\t\t// Now override the coordinates with its current position.\r\n\t\t\t\t\toCoords = [parseInt($(this).css(\"left\")), parseInt($(this).css(\"top\"))];\r\n\r\n\t\t\t\t\t// Remove the reference compare viewer offset from the x co-ordinate.\r\n\t\t\t\t\toCoords[0] -= referenceCompareViewerOffset;\r\n\r\n\t\t\t\t\t// Correct if we are going to go too close to the edges.\r\n\t\t\t\t\tvar maxWidth = oRelatedArtworkCanvas.g_oCanvas.width / g_oViewer.c_iDPI - rightMargin;\r\n\t\t\t\t\tvar maxHeight = oRelatedArtworkCanvas.g_oCanvas.height / g_oViewer.c_iDPI - verticalMargin;\r\n\r\n\t\t\t\t\t// If this is a threeD annotation, update the max width and height to match that of the scene.\r\n\t\t\t\t\tif (g_oAnnotations.g_iApprovalType == eAnnotationTypes.Ellipse) {\r\n\t\t\t\t\t\tmaxWidth = oArtworkCanvas.g_oCanvas.width / g_oViewer.c_iDPI - rightMargin;\r\n\t\t\t\t\t\tmaxHeight = oArtworkCanvas.g_oCanvas.height / g_oViewer.c_iDPI - verticalMargin;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (oCoords[0] < leftMargin) {\r\n\t\t\t\t\t\toCoords[0] = leftMargin;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (oCoords[0] + $(this).outerWidth() > maxWidth) {\r\n\t\t\t\t\t\toCoords[0] = maxWidth - $(this).outerWidth();\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (oCoords[1] < iMargin) {\r\n\t\t\t\t\t\toCoords[1] = iMargin;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (oCoords[1] + $(this).outerHeight() > maxHeight) {\r\n\t\t\t\t\t\toCoords[1] = maxHeight - $(this).outerHeight();\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tiNewDivLeft = oCoords[0];\r\n\t\t\t\t\tiNewDivTop = oCoords[1];\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\t// Display the new div correctly based on canvas rotation.\r\n\t\t\t\t\tswitch (oRelatedArtworkCanvas.g_iRotDegrees) {\r\n\t\t\t\t\t\tcase 90:\r\n\t\t\t\t\t\t\t// Compensate for rotated image with the new div bubble.\r\n\t\t\t\t\t\t\t// The difference to the \"default\" method is that we will need to accommodate for;\r\n\t\t\t\t\t\t\t// 1. The left and top coordinates will be swapped.\r\n\t\t\t\t\t\t\t// 2. We need to de-apply the \"wrong\" drag offset and re-apply in the opposite direction.\r\n\t\t\t\t\t\t\t// 3. If there is a difference in the image height and width, we need to allow for this when rotated.\r\n\t\t\t\t\t\t\tiNewDivLeft = ((imageObjH / g_oViewer.c_iDPI) - (oCoords[1] - (iCenterShift_y / g_oViewer.c_iDPI)))\r\n\t\t\t\t\t\t\t\t// Then we have to add the center shift back on, but with the drag offset \"reflected\" the other way.\r\n\t\t\t\t\t\t\t\t+ ((iCenterShift_x / g_oViewer.c_iDPI) + (iDragOffset_x / g_oViewer.c_iDPI) + (iDragOffset_y / g_oViewer.c_iDPI));\r\n\t\t\t\t\t\t\t// Same deal for the x coordinates.\r\n\t\t\t\t\t\t\tiNewDivTop = (oCoords[0] - (iCenterShift_x / g_oViewer.c_iDPI)) + ((iCenterShift_y / g_oViewer.c_iDPI) + (iDragOffset_y / g_oViewer.c_iDPI) - (iDragOffset_x / g_oViewer.c_iDPI));\r\n\t\t\t\t\t\t\tiRotatedSizeDiff = ((imageObjW / g_oViewer.c_iDPI) - (imageObjH / g_oViewer.c_iDPI)) / 2;\r\n\t\t\t\t\t\t\tiNewDivTop -= iRotatedSizeDiff;\r\n\t\t\t\t\t\t\tiNewDivLeft += iRotatedSizeDiff;\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase 180:\r\n\t\t\t\t\t\t\t// Compensate for inverted image with the new div bubble.\r\n\t\t\t\t\t\t\t// Measure the y coordinates backwards from the image height.\r\n\t\t\t\t\t\t\t// This requires removing the center shift value first.\r\n\t\t\t\t\t\t\tiNewDivTop = ((imageObjH / g_oViewer.c_iDPI) - (oCoords[1] - (iCenterShift_y / g_oViewer.c_iDPI)))\r\n\t\t\t\t\t\t\t\t// Then we have to add the center shift back on, but with the drag offset \"reflected\" the other way.\r\n\t\t\t\t\t\t\t\t+ ((iCenterShift_y / g_oViewer.c_iDPI) + (iDragOffset_y / g_oViewer.c_iDPI * 2));\r\n\t\t\t\t\t\t\t// Same deal for the x coordinates.\r\n\t\t\t\t\t\t\tiNewDivLeft = ((imageObjW / g_oViewer.c_iDPI) - (oCoords[0] - (iCenterShift_x / g_oViewer.c_iDPI))) + ((iCenterShift_x / g_oViewer.c_iDPI) + (iDragOffset_x / g_oViewer.c_iDPI * 2));\r\n\t\t\t\t\t\t\t// Make the highlight more visible by subtracting rectangle height.\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tcase 270:\r\n\t\t\t\t\t\t\t// Compensate for rotated image with the new div bubble.\r\n\t\t\t\t\t\t\t// The difference to the \"default\" method is that we will need to accommodate for;\r\n\t\t\t\t\t\t\t// 1. The left and top coordinates will be swapped.\r\n\t\t\t\t\t\t\t// 2. We need to de-apply the \"wrong\" drag offset and re-apply in the opposite direction.\r\n\t\t\t\t\t\t\t// 3. If there is a difference in the image height and width, we need to allow for this when rotated.\r\n\t\t\t\t\t\t\t// 4. Subtract recdist[0] to make the highlight and text visible.\r\n\t\t\t\t\t\t\tiNewDivLeft = (oCoords[1] - (iCenterShift_y / g_oViewer.c_iDPI))\r\n\t\t\t\t\t\t\t\t// Then we have to add the center shift back on, but with the drag offset \"reflected\" the other way.\r\n\t\t\t\t\t\t\t\t+ ((iCenterShift_x / g_oViewer.c_iDPI) + (iDragOffset_x / g_oViewer.c_iDPI) - (iDragOffset_y / g_oViewer.c_iDPI));\r\n\t\t\t\t\t\t\t// Same deal for the x coordinates.\r\n\t\t\t\t\t\t\tiNewDivTop = ((imageObjW / g_oViewer.c_iDPI) - (oCoords[0] - (iCenterShift_x / g_oViewer.c_iDPI))) + ((iCenterShift_y / g_oViewer.c_iDPI) + (iDragOffset_y / g_oViewer.c_iDPI) + (iDragOffset_x / g_oViewer.c_iDPI));\r\n\t\t\t\t\t\t\tiRotatedSizeDiff = ((imageObjW / g_oViewer.c_iDPI) - (imageObjH / g_oViewer.c_iDPI)) / 2;\r\n\t\t\t\t\t\t\tiNewDivTop -= iRotatedSizeDiff;\r\n\t\t\t\t\t\t\tiNewDivLeft += iRotatedSizeDiff;\r\n\t\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t\tdefault:\r\n\t\t\t\t\t\t\tif (oAnnotation.g_iAnnotationType === eAnnotationTypes.Postit) {\r\n\t\t\t\t\t\t\t\toCoords[1] -= 10; // the size of the post-it image in px\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tiNewDivLeft = oCoords[0];\r\n\t\t\t\t\t\t\tiNewDivTop = oCoords[1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Correct if we are going to go too close to the edges.\r\n\t\t\t\t\tvar maxWidth = oRelatedArtworkCanvas.g_oCanvas.width / g_oViewer.c_iDPI - rightMargin;\r\n\t\t\t\t\tvar maxHeight = oRelatedArtworkCanvas.g_oCanvas.height / g_oViewer.c_iDPI - verticalMargin;\r\n\r\n\t\t\t\t\t// If the div is too far left.\r\n\t\t\t\t\tif ((iNewDivLeft - iLeftOffset) < leftMargin) {\r\n\r\n\t\t\t\t\t\t// Update the div position.\r\n\t\t\t\t\t\tiNewDivTop = iNewDivTop;\r\n\t\t\t\t\t\tiNewDivLeft = leftMargin;\r\n\r\n\t\t\t\t\t\t// Add the noAfter class.\r\n\t\t\t\t\t\t$(this).addClass(\"noAfter\");\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If the div is too far right.\r\n\t\t\t\t\tif ((iNewDivLeft + ($(this).outerWidth() - iLeftOffset)) > maxWidth) {\r\n\r\n\t\t\t\t\t\t// Update the div position.\r\n\t\t\t\t\t\tiNewDivTop = iNewDivTop;\r\n\t\t\t\t\t\tiNewDivLeft = maxWidth - $(this).outerWidth();\r\n\r\n\t\t\t\t\t\t// Add the noAfter class.\r\n\t\t\t\t\t\t$(this).addClass(\"noAfter\");\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If the div is too far up.\r\n\t\t\t\t\tif (iNewDivTop - ($(this).outerHeight() + iTriangleOffset) < iMargin) {\r\n\r\n\t\t\t\t\t\t// Update the div position.\r\n\t\t\t\t\t\tiNewDivTop = iMargin;\r\n\t\t\t\t\t\tiNewDivLeft = iNewDivLeft;\r\n\r\n\t\t\t\t\t\t// Add the noAfter class.\r\n\t\t\t\t\t\t$(this).addClass(\"noAfter\");\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If the div is too far down.\r\n\t\t\t\t\tif (iNewDivTop + iTriangleOffset > maxHeight) {\r\n\r\n\t\t\t\t\t\t// Update the div position.\r\n\t\t\t\t\t\tiNewDivTop = maxHeight - $(this).outerHeight();\r\n\t\t\t\t\t\tiNewDivLeft = iNewDivLeft;\r\n\r\n\t\t\t\t\t\t// Add the noAfter class.\r\n\t\t\t\t\t\t$(this).addClass(\"noAfter\");\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If the no after class has been added to the div.\r\n\t\t\t\t\tif ($(this).hasClass(\"noAfter\")) {\r\n\r\n\t\t\t\t\t\t// We need to know the origin to draw the line from.\r\n\t\t\t\t\t\toCoordsOrig = [oCoords[0], oCoords[1]];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Copy Magic.\r\n\t\t\t\tif (!g_oAnnotations.g_bReturnAll) {\r\n\t\t\t\t\t$(this).show();\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\t$(this).hide();\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// If this annotation has been moved from the original position.\r\n\t\t\t\tif (g_oAnnotations.g_iAnnotationType !== eDocumentTypes.Three && $(this).hasClass(\"noAfter\")) {\r\n\r\n\t\t\t\t\t// Draw the line to the div.\r\n\t\t\t\t\tg_oAnnotations.drawLineToDiv([oCoordsOrig[0] * g_oViewer.c_iDPI, oCoordsOrig[1] * g_oViewer.c_iDPI], [iNewDivLeft * g_oViewer.c_iDPI, iNewDivTop * g_oViewer.c_iDPI], szAnnotationColour, oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t// Figure out if there are children of the shape.\r\n\t\t\t\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\t\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iParentAnnotationId.toString() == iId) {\r\n\t\t\t\t\t\t\tvar coordsChildOrig = [g_oAnnotations.g_oAnnotationsMade[i].g_oDrawArray[0][0], g_oAnnotations.g_oAnnotationsMade[i].g_oDrawArray[0][1]];\r\n\t\t\t\t\t\t\tif (iCompareRotation > 0) {\r\n\t\t\t\t\t\t\t\t// If we have a compare rotation of 90 or 270, swap the width and height.\r\n\t\t\t\t\t\t\t\tif (iCompareRotation == 90 || iCompareRotation == 270) {\r\n\t\t\t\t\t\t\t\t\tiScaledImgW = oRelatedArtworkCanvas.g_iScaledImageHeight;\r\n\t\t\t\t\t\t\t\t\tiScaledImgH = oRelatedArtworkCanvas.g_iScaledImageWidth;\r\n\t\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t\t// Rotate the annotation co-ordinates.\r\n\t\t\t\t\t\t\t\tvar oRotatedAnnotationDraw = oAnnotationCanvas.rotate(coordsChildOrig[0], coordsChildOrig[1], 0.5, 0.5, iCompareRotation);\r\n\t\t\t\t\t\t\t\tcoordsChildOrig[0] = oRotatedAnnotationDraw.rotated_x;\r\n\t\t\t\t\t\t\t\tcoordsChildOrig[1] = oRotatedAnnotationDraw.rotated_y;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tcoordsChildOrig[0] = (coordsChildOrig[0] * iScaledImgW / g_oViewer.c_iDPI) + (iCenterShift_x / g_oViewer.c_iDPI) + compareOffset_x;\r\n\t\t\t\t\t\t\tcoordsChildOrig[1] = (coordsChildOrig[1] * iScaledImgH / g_oViewer.c_iDPI) + (iCenterShift_y / g_oViewer.c_iDPI) + compareOffset_y;\r\n\r\n\t\t\t\t\t\t\t// Draw a line to the child annotation.\r\n\t\t\t\t\t\t\tg_oAnnotations.drawLineToDiv([coordsChildOrig[0] * g_oViewer.c_iDPI, coordsChildOrig[1] * g_oViewer.c_iDPI], [iNewDivLeft * g_oViewer.c_iDPI, iNewDivTop * g_oViewer.c_iDPI], szAnnotationColour, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Set the position of the div.\r\n\t\t\t\t\t$(this).css({ top: iNewDivTop, left: iNewDivLeft + referenceCompareViewerOffset, position: \"absolute\" });\r\n\r\n\t\t\t\t\t// Focus the JQTE editor if available.\r\n\t\t\t\t\t$(\".jqte_editor\").focus();\r\n\t\t\t\t}\r\n\t\t\t\t// If this annotation is in the original position.\r\n\t\t\t\telse {\r\n\r\n\t\t\t\t\t// Calculate the offset height of the div.\r\n\t\t\t\t\tiOffsetHeight = g_oAnnotations.repositionDivForHeight(this.id);\r\n\r\n\t\t\t\t\t// Set the position of the div.\r\n\t\t\t\t\t$(this).css({ top: (iNewDivTop) - iOffsetHeight - iTriangleOffset, left: (iNewDivLeft) - iLeftOffset + referenceCompareViewerOffset, position: \"absolute\" });\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t\t// If we are animating, then we don't want to show the pop-ups.\r\n\t\telse {\r\n\t\t\t$(\".speechbubble\").each(function () {\r\n\t\t\t\t$(this).slideUp(100);\r\n\t\t\t});\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Steps through the annotations.\r\n\t */\r\n\tAnnotationUI.prototype.stepThroughAnnotations = function (oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t\r\n\t\t// Don't step through if there are NO annotations made.\r\n\t\tif (!$.isEmptyObject(g_oAnnotations.g_oAnnotationsMade)) {\r\n\r\n\t\t\t// Get the number of pages.\r\n\t\t\tvar iNumberOfPages = oArtworkCanvas.g_oDoc.pages.length;\r\n\t\t\tvar iStartPage = oArtworkCanvas.g_iCurrentPage;\r\n\r\n\t\t\t// Grab a list of the annotations in the list.\r\n\t\t\tvar oAnnotationListItems = $(\".annotationListItem:visible\");\r\n\t\t\tif (oAnnotationListItems.length !== 0) {\r\n\t\t\t\t// Loop through the list items.\r\n\t\t\t\tfor (var i = 0; i < oAnnotationListItems.length; i++) {\r\n\t\t\t\t\tif ($(oAnnotationListItems[i]).hasClass(\"annotationListItemSelected\")) {\r\n\t\t\t\t\t\t// Check we don't try to access something outside of the array.\r\n\t\t\t\t\t\tif (i + 1 !== oAnnotationListItems.length) {\r\n\t\t\t\t\t\t\t// Set the previous list item to one we are selected.\r\n\t\t\t\t\t\t\tvar previousListItem = oAnnotationListItems[i];\r\n\t\t\t\t\t\t\t// Find the close button on the list and click it through JS.\r\n\t\t\t\t\t\t\tvar closeButton = $(\"#\" + previousListItem.id.substring(3)).children(\".HeaderBar\").children(\".closebutton\");\r\n\t\t\t\t\t\t\t$(closeButton[0]).click();\r\n\t\t\t\t\t\t\t// Open the new list item.\r\n\t\t\t\t\t\t\tvar currentlistItem = oAnnotationListItems[i + 1];\r\n\t\t\t\t\t\t\tcurrentlistItem.click();\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar closeButton = $(\"#\" + oAnnotationListItems[oAnnotationListItems.length - 1].id.substring(3)).children(\".HeaderBar\").children(\".closebutton\");\r\n\r\n\t\t\t\t// If there is a close button, and we've reached this point, this is the last annotation on the page.\r\n\t\t\t\tif (closeButton.length > 0) {\r\n\t\t\t\t\t// Close the pop-up.\r\n\t\t\t\t\t$(closeButton[0]).click();\r\n\r\n\t\t\t\t\t// Don't bother changing pages for single page documents.\r\n\t\t\t\t\tif (iNumberOfPages > 0) {\r\n\t\t\t\t\t\tg_oAnnotations.changePageOnStepThrough(iNumberOfPages, iStartPage, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Click the first annotation on the page.\r\n\t\t\t\t\toAnnotationListItems = $(\".annotationListItem:visible\");\r\n\r\n\t\t\t\t\tif (oAnnotationListItems.length > 0) {\r\n\t\t\t\t\t\tvar currentlistItem = oAnnotationListItems[0];\r\n\t\t\t\t\t\tcurrentlistItem.click();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// This means we should just select the first item on the current page.\r\n\t\t\t\telse {\r\n\t\t\t\t\tcurrentlistItem = oAnnotationListItems[0];\r\n\t\t\t\t\tcurrentlistItem.click();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\t// Step through to the next page and check for annotations there.\r\n\t\t\t\tif (iNumberOfPages > 0) {\r\n\t\t\t\t\tg_oAnnotations.changePageOnStepThrough(iNumberOfPages, iStartPage, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t$(\"#imgStepThroughAnnotations\").click(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Reverses drag, rotate, zoom back from the click coordinates to find the point that the user clicked on in upright space.\r\n\t * @param {int} x - The x coordinate\r\n\t * @param {int} y - The y coordinate\r\n\t * @param {object} viewer - The viewer object that holds the coordinates\r\n\t * @returns {array} - The transformed co-ordinates.\r\n\t */\r\n\tAnnotationUI.prototype.transformClickForRotation = function (x, y, viewer) {\r\n\t\tvar tempx, tempy, imageObjW, imageObjH;\r\n\t\tvar artworkViewer = viewer;\r\n\t\tx -= artworkViewer.g_iCenterShift_x;\r\n\t\ty -= artworkViewer.g_iCenterShift_y;\r\n\t\timageObjW = artworkViewer.g_iCompareImage_x;\r\n\t\timageObjH = artworkViewer.g_iCompareImage_y;\r\n\r\n\t\tswitch (viewer.g_iRotDegrees) {\r\n\t\t\tcase 90:\r\n\t\t\t\t// We need to swap x and y.\r\n\t\t\t\ttempx = x;\r\n\t\t\t\ttempy = y;\r\n\t\t\t\ty = tempx;\r\n\t\t\t\tx = tempy;\r\n\t\t\t\t// We are measuring from the right side to left to get the y coordinates.\r\n\t\t\t\ty = imageObjH - y;\r\n\t\t\t\t// Account for the difference in image object width / height since it's rotated and the center shift will be wrong.\r\n\t\t\t\ty += (imageObjW - imageObjH) / 2;\r\n\t\t\t\tx += (imageObjW - imageObjH) / 2;\r\n\t\t\t\t// Account for drag offset too\r\n\t\t\t\ty += viewer.g_iDragOffset_y;\r\n\t\t\t\tx -= viewer.g_iDragOffset_y;\r\n\t\t\t\ty += viewer.g_iDragOffset_x;\r\n\t\t\t\tx += viewer.g_iDragOffset_x;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 180:\r\n\t\t\t\t// If we're upside down we simply need to measure from the opposite side.\r\n\t\t\t\ty = imageObjH - y;\r\n\t\t\t\tx = imageObjW - x;\r\n\t\t\t\t// Account for drag offset\r\n\t\t\t\t// It was originally calculated for the right-way-up orientation so we need to double up the opposite way\r\n\t\t\t\tx += viewer.g_iDragOffset_x * 2;\r\n\t\t\t\ty += viewer.g_iDragOffset_y * 2;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase 270:\r\n\t\t\t\t// We need to swap x and y.\r\n\t\t\t\ttempx = x;\r\n\t\t\t\ttempy = y;\r\n\t\t\t\ty = tempx;\r\n\t\t\t\tx = tempy;\r\n\t\t\t\t// We are measuring from the bottom up to get the x coordinate.\r\n\t\t\t\tx = imageObjW - x;\r\n\t\t\t\t// Account for the difference in image object width / height since it's rotated and the center shift will be wrong.\r\n\t\t\t\ty -= (imageObjW - imageObjH) / 2;\r\n\t\t\t\tx -= (imageObjW - imageObjH) / 2;\r\n\t\t\t\t// Account for drag offset too\r\n\t\t\t\ty += viewer.g_iDragOffset_y;\r\n\t\t\t\tx += viewer.g_iDragOffset_y;\r\n\t\t\t\ty -= viewer.g_iDragOffset_x;\r\n\t\t\t\tx += viewer.g_iDragOffset_x;\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n return [x, y];\r\n }\r\n\r\n /**\r\n * Deletes the annotation reply\r\n * @param {int} annotationReplyId - The unique identifier for the annotation reply\r\n * @param {object} oArtworkCanvas - The artwork canvas\r\n * @param {object} oAnnotationCanvas - The annotation canvas\r\n * @param {boolean} bDeletionConfirmed - Whether the deletion has been confirmed.\r\n */\r\n AnnotationUI.prototype.deleteAnnotationReply = function (annotationReplyId, oArtworkCanvas, oAnnotationCanvas, bDeletionConfirmed) {\r\n if (!bDeletionConfirmed) {\r\n var onConfirm = function () { g_oAnnotations.deleteAnnotationReply(annotationReplyId, oArtworkCanvas, oAnnotationCanvas, true); }\r\n var onCancel = function () { }\r\n g_oGreenlightMessages.displayConfirmBubble(g_oAnnotations.c_szConfirmDeleteAnnotationReply, onConfirm, onCancel);\r\n return;\r\n }\r\n\r\n var parentId = getAnnotationReplyParent(annotationReplyId);\r\n\r\n var oJSON = {\r\n sessionId: g_oAnnotations.c_szSessionId,\r\n annotationId: annotationReplyId,\r\n approvalId: this.g_iApprovalId,\r\n userId: g_oUserDetails.UserId,\r\n emailAddress: g_oUserDetails.EmailAddress\r\n };\r\n\r\n $.ajax({\r\n type: \"DELETE\",\r\n url: \"internal/GreenlightAnnotation/DeleteAnnotationReply\",\r\n data: JSON.stringify(oJSON),\r\n contentType: \"application/json; charset=utf-8\",\r\n success: function () {\r\n\t\t\t\tg_oGreenlightMessages.displaySuccessBubble(g_oAnnotations.c_szAnnotationRepyDeleted);\r\n\r\n // Hide the reply (flyout + popup)\r\n $(\"#rc_\" + parentId + \" #_p\" + annotationReplyId).parent().slideUp();\r\n $(\"#rc_li_\" + parentId + \" #_p\" + annotationReplyId).parent().slideUp();\r\n\r\n removeAnnotationReplyFromParent(annotationReplyId);\r\n\r\n // If criteria is met to show delete button, then reinsert it.\r\n\t\t\t\tif (g_oAnnotations.canAnnotationBeDeleted(parentId)) {\r\n g_oAnnotations.insertDeleteButton(parentId);\r\n }\r\n\r\n g_oAnnotations.rebuildAnnotationList(oArtworkCanvas, oAnnotationCanvas);\r\n },\r\n failure: function () {\r\n g_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szUnexpectedError);\r\n },\r\n error: function (jqXHR, exception) {\r\n ProcessApiError(jqXHR, exception, true);\r\n }\r\n });\r\n };\r\n\r\n /**\r\n * Determines the parent of the annotation reply.\r\n * @param {number} annotationReplyId - The unique identifier corresponding to the anotation reply.\r\n * @returns {number} The parent annotation id.\r\n */\r\n var getAnnotationReplyParent = function (annotationReplyId) {\r\n for (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n if (g_oAnnotations.g_oAnnotationsMade[i].g_oReplies.some(function (reply) { return reply.id === annotationReplyId; })) {\r\n return g_oAnnotations.g_oAnnotationsMade[i].id;\r\n }\r\n }\r\n\r\n return 0;\r\n };\r\n\r\n /**\r\n * Removes the annotation reply from the parent.\r\n * @param {number} annotationReplyId - The unique identifier corresponding to the anotation reply.\r\n */\r\n var removeAnnotationReplyFromParent = function (annotationReplyId) {\r\n var parentId = getAnnotationReplyParent(annotationReplyId);\r\n var annotation = g_oAnnotations.g_oAnnotationsMade.filter(function (x) { return x.id === parentId; })[0];\r\n\r\n annotation.g_oReplies = annotation.g_oReplies.filter(function (reply) { return reply.id !== annotationReplyId; });\r\n };\r\n\r\n /**\r\n * Determine where a given annotation can be deleted.\r\n * Criteria are: no replies, no status + annotation belongs to the approver.\r\n * @param {number} annotationId - The unique identifier of the annotation\r\n */\r\n\tAnnotationUI.prototype.canAnnotationBeDeleted = function (annotationId) {\r\n var annotation = g_oAnnotations.g_oAnnotationsMade.filter(function (x) { return x.id === annotationId; })[0];\r\n\r\n return annotation.g_oReplies.length === 0\r\n && annotation.g_oStatuses.length === 0\r\n && g_oUserDetails.UserId === annotation.g_iAuthor;\r\n };\r\n\r\n /**\r\n * Creates the delete button elements and inserts them into the header bar of the specified annotation.\r\n * @param {number} annotationId - The unique identifier of the annotation\r\n */\r\n\tAnnotationUI.prototype.insertDeleteButton = function (annotationId) {\r\n if ($(\"#hb_\" + annotationId).exists()) {\r\n prependDomElement(annotationId + \"_del\", \"input\", \"img/Delete_wht_24.png\", \"deletebutton\", g_oAnnotations.c_szDeleteAnnotation, null, $(\"#hb_\" + annotationId)[0]);\r\n }\r\n if ($(\"#hb_li_\" + annotationId).exists()) {\r\n prependDomElement(annotationId + \"_del\", \"input\", \"img/Delete_wht_24.png\", \"deletebutton\", g_oAnnotations.c_szDeleteAnnotation, null, $(\"#hb_li_\" + annotationId)[0]);\r\n }\r\n };\r\n\r\n\t/**\r\n\t * Deletes the annotation and any child shapes.\r\n\t * @param {int} iAnnId - Annotation to be deleted.\r\n\t * @param {object} oAnnotations - List of annotations.\r\n\t * @param {bool} bDeletionConfirmed - Whether it's confirmed for deletion.\r\n\t * @param {object} oArtworkCanvas - The artwork canvas.\r\n\t * @param {object} oAnnotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.deleteAnnotation = function (iAnnId, oAnnotations, bDeletionConfirmed, oArtworkCanvas, oAnnotationCanvas) {\r\n\t\t\r\n\t\t// Get the main scope.\r\n\t\tvar oMainScope = this;\r\n\r\n // Determine if the confirmation can be automatically made for deletion.\r\n if (!bDeletionConfirmed && (parseInt(iAnnId, 10) < 0 && oAnnotations.length == 1)) {\r\n bDeletionConfirmed = true;\r\n }\r\n\r\n // Determine if the confirmation needs to be been made for the deletion.\r\n if (!bDeletionConfirmed) {\r\n // Setup the confirmation/rejection actions.\r\n var oConfirmAction = function () {\r\n g_oAnnotations.deleteAnnotation(iAnnId, oAnnotations, true, oArtworkCanvas, oAnnotationCanvas);\r\n };\r\n var oRejectionAction = function () { };\r\n\r\n\t\t\t// Display the confirmation bubble.\r\n\t\t\tg_oGreenlightMessages.displayConfirmBubble(g_oAnnotations.c_szConfirmDelete, oConfirmAction, oRejectionAction);\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n // If this Annotation hasn't being saved, just splice it out of the array.\r\n\t\tif (iAnnId < 0) {\r\n\t\t\t\r\n // Find the correct annotation index and delete it.\r\n for (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\r\n\t\t\t\t// If this is the matching annotation.\r\n\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].id === iAnnId) {\r\n\r\n\t\t\t\t\t// Get the id op the annotaion we are deleting.\r\n\t\t\t\t\tvar iDeletingAnnotationId = g_oAnnotations.g_oAnnotationsMade[i].id;\r\n\r\n\t\t\t\t\t// Check if this is a copy magic annotation.\r\n\t\t\t\t\tvar bDeletingCopyMagicAnnotation = g_oAnnotations.g_oAnnotationsMade[i].g_bSVGTextAnnotation && g_oAnnotations.g_oAnnotationsMade[i].g_oSVGVariable.copyMagicText;\r\n\r\n\t\t\t\t\t// If this is a text measurement, remove the word visibility.\r\n if (g_oAnnotations.g_oAnnotationsMade[i].g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n g_oTechTools.setTextMeasurementWordVisibility(g_oAnnotations.g_oAnnotationsMade[i].g_oTextMeasurementWordsArray, false);\r\n }\r\n\r\n\t\t\t\t\t// Clear users attachments from the cache.\r\n\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].attachments.length > 0) {\r\n\t\t\t\t\t\tvar oJSONSession = {\r\n\t\t\t\t\t\t\tSessionId: g_oAnnotations.c_szSessionId\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t\t$.ajax({\r\n\t\t\t\t\t\t\turl: \"internal/GreenlightAnnotation/DeleteUserAttachmentCache\",\r\n\t\t\t\t\t\t\tdata: JSON.stringify(oJSONSession),\r\n\t\t\t\t\t\t\tcontentType: \"application/json; charset=utf-8\",\r\n\t\t\t\t\t\t\tdataType: \"json\",\r\n\t\t\t\t\t\t\ttype: 'POST'\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Remove the annotation and div.\r\n\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade.splice(i, 1);\r\n\t\t\t\t\t$(\"#\" + iAnnId).remove();\r\n\r\n\t\t\t\t\t// For CM Annotations we need to remove any additional shapes that may have been created.\r\n\t\t\t\t\tif (bDeletingCopyMagicAnnotation) {\r\n\t\t\t\t\t\tfor (var j = 0; j < g_oAnnotations.g_oAnnotationsMade.length; j++) {\r\n\t\t\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[j].g_iParentAnnotationId == iDeletingAnnotationId) {\r\n\t\t\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade.splice(j, 1);\r\n\t\t\t\t\t\t\t\tj--;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// For 3D Annotations we need to remove the points out of the THREE.js scene.\r\n\t\t\t\t\tif (g_oAnnotations.g_oArtworkViewer.g_oDoc.documentType === 3) {\r\n\t\t\t\t\t\toArtworkCanvas.g_oScene.children = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.Id != iAnnId; });\r\n\t\t\t\t\t\toArtworkCanvas.g_oScene.children = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return child.Id != \"annNo_\" + iAnnId; });\r\n\t\t\t\t\t\tg_oAnnotations.redraw3DAnnotations(oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\toArtworkCanvas.g_oRenderer.render(oArtworkCanvas.g_oScene, oArtworkCanvas.g_oCamera);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Recalculate the page annotation numbers.\r\n\t\t\t\t\tg_oAnnotations.renderPageAnnotationNumbers();\r\n\r\n // Rebind mouseHover.\r\n\t\t\t\t\tchangeCanvasFunction();\r\n\r\n\t\t\t\t\t// If this is a copy magic change, re-draw the annotations.\r\n\t\t\t\t\tif (bDeletingCopyMagicAnnotation) {\r\n\t\t\t\t\t\toAnnotationCanvas.redraw(false);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Stop the loop.\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n // Build up the JSON object.\r\n var oJSON = {\r\n sessionId: g_oAnnotations.c_szSessionId,\r\n approvalId: this.g_iApprovalId,\r\n annotationId: iAnnId,\r\n userId: g_oUserDetails.UserId,\r\n emailAddress: g_oUserDetails.EmailAddress\r\n };\r\n\r\n $.ajax({\r\n type: \"DELETE\",\r\n url: \"internal/GreenlightAnnotation/DeleteAnnotation\",\r\n data: JSON.stringify(oJSON),\r\n contentType: \"application/json; charset=utf-8\",\r\n success: function () {\r\n $(\"#li_\" + iAnnId).remove();\r\n $(\"#\" + iAnnId).remove();\r\n\r\n\t\t\t\t\t// Declare an array to hold any child annotation Ids.\r\n var arrChildIdArray = [];\r\n\r\n\t\t\t\t\t// Declare an object to hold the svg information.\r\n\t\t\t\t\tvar oSVGInformation = null;\r\n\r\n\t\t\t\t\t// Splice the deleted annotations out of the array.\r\n\t\t\t\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\r\n\t\t\t\t\t\t// If this is the deleted annotation.\r\n\t\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].id == parseInt(iAnnId, 10)) {\r\n\r\n\t\t\t\t\t\t\t// If this is a text measurement.\r\n\t\t\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_iAnnotationType === eAnnotationTypes.TextMeasurement) {\r\n\t\t\t\t\t\t\t\tg_oTechTools.setTextMeasurementWordVisibility(g_oAnnotations.g_oAnnotationsMade[i].g_oTextMeasurementWordsArray, false);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Extract the svg information.\r\n\t\t\t\t\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_bSVGTextAnnotation) {\r\n\t\t\t\t\t\t\t\toSVGInformation = {\r\n\t\t\t\t\t\t\t\t\tsvgVariable: g_oAnnotations.g_oAnnotationsMade[i].g_oSVGVariable,\r\n\t\t\t\t\t\t\t\t\toriginalContent: g_oAnnotations.g_oAnnotationsMade[i].g_szSVGOriginalContent\r\n\t\t\t\t\t\t\t\t};\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Splice the annotation.\r\n\t\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade.splice(i, 1);\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t// If this is a child of the deleted annotation.\r\n\t\t\t\t\t\telse if (g_oAnnotations.g_oAnnotationsMade[i].g_iParentAnnotationId == parseInt(iAnnId, 10)) {\r\n\t\t\t\t\t\t\tarrChildIdArray.push(g_oAnnotations.g_oAnnotationsMade[i].id);\r\n\r\n\t\t\t\t\t\t\t// Splice the annotation.\r\n\t\t\t\t\t\t\tg_oAnnotations.g_oAnnotationsMade.splice(i, 1);\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// If this is an svg annotation.\r\n\t\t\t\t\tif (oSVGInformation != null) {\r\n\r\n\t\t\t\t\t\t// Remove the text changes made by the annotation.\r\n\t\t\t\t\t\tg_oSVGText.removeSVGTextUpdate(oSVGInformation.svgVariable, oSVGInformation.originalContent, oArtworkCanvas, oAnnotationCanvas, true);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// For 3D Annotations we need to remove the points out of the THREE.js scene.\r\n\t\t\t\t\telse if (g_oAnnotations.g_oArtworkViewer.g_oDoc.documentType === 3) {\r\n\r\n\t\t\t\t\t\t// Get the objects which need releasing in memory and send to function to release.\r\n\t\t\t\t\t\tvar oAnnotationObj = $.grep(oArtworkCanvas.g_oScene.children, function (child) { return (child.Id == iAnnId) || arrChildIdArray.indexOf(child.Id) > -1 });\r\n\t\t\t\t\t\toMainScope.removeThreeJSObjects(oAnnotationObj, oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t\tvar annotationNumberObj = $.grep(oArtworkCanvas.g_oScene.children, function (child) {\r\n\t\t\t\t\t\t\tif (!child.Id || !child.Id.indexOf) {\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn child.Id.indexOf(\"annNo_\") > -1;\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t\toMainScope.removeThreeJSObjects(annotationNumberObj, oArtworkCanvas, oAnnotationCanvas);\r\n\t\t\t\t\t\tg_oAnnotations.redraw3DAnnotations(oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t\t$(document).off(\"pointerdown\");\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\toAnnotationCanvas.redraw(false);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// Rebuild the annotation list.\r\n\t\t\t\t\tg_oAnnotations.rebuildAnnotationList(oArtworkCanvas, oAnnotationCanvas);\r\n\r\n\t\t\t\t\t// Recalculate the page annotation numbers.\r\n\t\t\t\t\tg_oAnnotations.renderPageAnnotationNumbers();\r\n\r\n\t\t\t\t\t// Display the success bubble.\r\n\t\t\t\t\tg_oGreenlightMessages.displaySuccessBubble(g_oAnnotations.c_szAnnotationDeleted);\r\n\r\n\t\t\t\t\t// Update the canvas function.\r\n\t\t\t\t\t$(\"#AnnotationViewer\").css(\"cursor\", \"default\");\r\n\t\t\t\t\tg_oAnnotations.g_szPrevCursorStyle = \"default\";\r\n\t\t\t\t\tchangeCanvasFunction();\r\n\r\n\t\t\t\t\t// Update the approval button states.\r\n\t\t\t\t\tg_oApproval.UpdateApprovalButtonStates();\r\n\r\n\t\t\t\t\t// Send the signalR update.\r\n g_oAnnotations.g_oAnnotationHub.server.send(g_oAnnotations.g_iApprovalId, g_oUserDetails.EmailAddress);\r\n },\r\n failure: function () {\r\n g_oGreenlightMessages.displayErrorBubble(g_oAnnotations.c_szAnnotationCouldNotBeDeleted);\r\n },\r\n error: function (jqXHR, exception) {\r\n ProcessApiError(jqXHR, exception, true);\r\n }\r\n });\r\n }\r\n\r\n\t\t// Rebind the draw functions once annotation saves.\r\n\t\t// Use setTimeout to make sure we ONLY rebind the canvas functions,\r\n\t\t// once they have finished, as they will execute twice!.\r\n\t\tvar oTimer = setTimeout(function () {\r\n\t\t\tg_oAnnotations.currentTimeoutListRemove(oTimer);\r\n\r\n\t\t\t// Only reset the annotation mouse events if there are no other actions in progress (i.e. Pan or Marquee Zoom).\r\n\t\t\tif (!g_oAnnotations.g_bNonAnnotationActionInProgress) {\r\n\t\t\t\t$(\"#AnnotationViewer\").css(\"cursor\", \"default\");\r\n\t\t\t\tg_oAnnotations.g_szPrevCursorStyle = \"default\";\r\n\t\t\t\tchangeCanvasFunction();\r\n\t\t\t}\r\n\t\t}, 0);\r\n\r\n\t\tg_oAnnotations.currentTimeoutListAdd(oTimer);\r\n\t};\r\n\r\n\t/**\r\n\t * Resets the annotation status for an annotation.\r\n\t * @param {object} annotation - The annotation to have its status reset.\r\n\t * @param {object} artworkCanvas - The artwork canvas.\r\n\t * @param {object} annotationCanvas - The annotation canvas.\r\n\t */\r\n\tAnnotationUI.prototype.resetAnnotationStatus = function (annotation, artworkCanvas, annotationCanvas) {\r\n\r\n\t\t// Loop through each of the annotation statuses on the annotation.\r\n\t\tfor (var i = 0; i < annotation.g_oStatuses.length; i++) {\r\n\r\n\t\t\t// Delete the annotation status.\r\n\t\t\tannotation.g_oStatuses[i].deleteAnnotationStatus(annotation, annotation.g_oStatuses[i].id, artworkCanvas, annotationCanvas, false, false, (i === annotation.g_oStatuses.length - 1));\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * A function to set the word array for an existing Text Measurement annotation.\r\n\t * This is how the saved Text Measurement annotations have their highlighted word list re-populated.\r\n\t * @param oJSON {object} - A JSON object containing the Text Measurement Word Array and the Annotation ID of the Annotation the word array is to be applied to.\r\n\t */\r\n\tAnnotationUI.prototype.setExistingTextMeasurementAnnotationWordsList = function (oJSON) {\r\n\t\tvar oMatchingAnnotation = $.grep(g_oAnnotations.g_oAnnotationsMade, function (annotation) { return annotation.id == oJSON.iAnnotationID; });\r\n\r\n\t\tif (oMatchingAnnotation !== undefined && oMatchingAnnotation !== null) {\r\n\t\t\toMatchingAnnotation[0].g_oTextMeasurementWordsArray = oJSON.oWordsArray;\r\n\t\t\tg_oTechTools.setTextMeasurementWordVisibility(oMatchingAnnotation[0].g_oTextMeasurementWordsArray, !oMatchingAnnotation[0].g_bClosed);\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * A function used by the Event Subscription functionality to set the original Marquee coordinates for a Text Measurement annotation.\r\n\t * This is to that the original selected area can be used to re-select the highlighted words when required.\r\n\t * @param oMarqueeDimensions {object} - The original marquee dimensions.\r\n\t */\r\n\tAnnotationUI.prototype.setTempMarqueeCoordinates = function (oMarqueeDimensions) {\r\n\t\tg_oAnnotations.g_oTempMarqueeDimensions = oMarqueeDimensions;\r\n\t};\r\n\r\n\t/**\r\n\t * Helper method to check for any unsaved annotations.\r\n\t * @returns {boolean} Returns TRUE is there are any unsaved annotations; otherwise FALSE.\r\n\t */\r\n\tAnnotationUI.prototype.checkForUnsavedAnnotation = function () {\r\n\t\tvar bFoundUnsavedAnnotation = false;\r\n\r\n\t\t// Loop through each of the annotations made.\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationsMade.length; i++) {\r\n\r\n\t\t\t// If this is an SVG hover or search annotation, skip this.\r\n\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_bSVGHoverAnnotation || g_oAnnotations.g_oAnnotationsMade[i].g_bSVGSearchAnnotation) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\t// If this is an unsaved annotation.\r\n\t\t\tif (g_oAnnotations.g_oAnnotationsMade[i].g_bSaved === false) {\r\n\r\n\t\t\t\t// Set that an unsaved annotation has been found.\r\n\t\t\t\tbFoundUnsavedAnnotation = true;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn bFoundUnsavedAnnotation;\r\n\t};\r\n\r\n\t/**\r\n\t * Stores the provided setTimeout object in an array.\r\n\t * @param oTimeout {object} - The setTimeout object.\r\n\t */\r\n\tAnnotationUI.prototype.currentTimeoutListAdd = function (oTimeout) {\r\n\t\tg_oAnnotations.g_oAnnotationCurrentTimeoutArray.push(oTimeout);\r\n\t};\r\n\r\n\t/**\r\n\t * Removes the provided setTimeout object from the array.\r\n\t * @param oTimeout {object} - The setTimeout object.\r\n\t */\r\n\tAnnotationUI.prototype.currentTimeoutListRemove = function (oTimeout) {\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationCurrentTimeoutArray.length; i++) {\r\n\t\t\tif (g_oAnnotations.g_oAnnotationCurrentTimeoutArray[i] === oTimeout) {\r\n\t\t\t\tg_oAnnotations.g_oAnnotationCurrentTimeoutArray.splice(i, 1);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t/**\r\n\t * Cancels all the timeout objects before clearing the array of all objects.\r\n\t */\r\n\tAnnotationUI.prototype.currentTimeoutListClear = function () {\r\n\t\tg_oAnnotations.g_bNonAnnotationActionInProgress = true;\r\n\r\n\t\tfor (var i = 0; i < g_oAnnotations.g_oAnnotationCurrentTimeoutArray.length; i++) {\r\n\t\t\tclearTimeout(g_oAnnotations.g_oAnnotationCurrentTimeoutArray[i]);\r\n\t\t}\r\n\r\n\t\tg_oAnnotations.g_oAnnotationCurrentTimeoutArray.length = 0;\r\n\t};\r\n\r\n\t/**\r\n\t * The copy event override that prevents certain text formatting from reaching the clipboard.\r\n\t * @param {event} event - The copy event.\r\n\t */\r\n\tAnnotationUI.prototype.copyOverride = function (event) {\r\n\t\tvar html = \"\";\r\n\t\tvar text = \"\";\r\n\t\tif (typeof window.getSelection != \"undefined\") {\r\n\t\t\tvar oSel = window.getSelection();\r\n\t\t\tif (oSel.rangeCount) {\r\n\t\t\t\t// Create a temporary container\r\n\t\t\t\tvar oContainer = document.createElement(\"div\");\r\n\t\t\t\tfor (var i = 0, len = oSel.rangeCount; i < len; ++i) {\r\n\t\t\t\t\toContainer.appendChild(oSel.getRangeAt(i).cloneContents());\r\n\t\t\t\t}\r\n\t\t\t\t// Grab the inner html to avoid styles applied by the annotation div\r\n\t\t\t\thtml = oContainer.innerHTML;\r\n\t\t\t\ttext = oContainer.innerText;\r\n\t\t\t\tvar oRange = document.createRange();\r\n\t\t\t\toContainer.id = \"temporaryContainer\";\r\n\t\t\t\tdocument.getElementById(\"divContainer\").appendChild(oContainer);\r\n\t\t\t\toRange.selectNode(oContainer);\r\n\t\t\t\toSel.removeAllRanges();\r\n\t\t\t\toSel.addRange(oRange);\r\n\t\t\t\tdocument.execCommand(\"copy\");\r\n\t\t\t\t$(\"#temporaryContainer\").remove();\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (typeof document.selection != \"undefined\") {\r\n\t\t\tif (document.selection.type == \"Text\") {\r\n\t\t\t\thtml = document.selection.createRange().htmlText;\r\n\t\t\t\ttext = document.selection.text;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Grab the clipboardData object (window.clipboardData = IE, event.originalEvent.clipboardData = Firefox, event.clipboardData = Chrome & Safari)\r\n\t\tvar oClipboardData = event.clipboardData || event.originalEvent.clipboardData || window.clipboardData;\r\n\t\t// Set the clipboard data to the inner html instead of the whole thing\r\n\t\toClipboardData.setData('text/html', html);\r\n\t\toClipboardData.setData('text/plain', text);\r\n\t\tevent.preventDefault();\r\n\t};\r\n\r\n\t/**\r\n\t * Function to extract the first numerical ID value from an UI Element ID that is separated by the _ character.\r\n\t * @param {string} id - The ID of the UI Element, e.g. \"li_1021_del\".\r\n\t * @returns {number} - Returns the first ID number in the Element ID. If there is no number contained in the Element ID then 'NaN' will be returned.\r\n\t */\r\n\tAnnotationUI.prototype.getIdFromElementId = function (id) {\r\n\t\t// Get the id of the annotation.\r\n\t\tvar oaElementIdSplit = id.split(\"_\");\r\n\r\n\t\tvar iAnnotationId;\r\n\t\tfor (var i = 0; i < oaElementIdSplit.length; i++) {\r\n\t\t\tiAnnotationId = parseInt(oaElementIdSplit[i]);\r\n\r\n\t\t\t// Need to find the first number in the UI element ID as it could have strings prepended like \"li_\" for being a list item.\r\n\t\t\tif (!isNaN(iAnnotationId)) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn iAnnotationId;\r\n\t};\r\n\r\n\t// Add the Annotation UI object to the window.\r\n\twindow.AnnotationUI = AnnotationUI;\r\n}());"]}