/** * Yobi, Project Hosting SW * * Copyright 2013 NAVER Corp. * http://yobi.io * * @author Yi EungJun * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ yobi = yobi || {}; yobi.CodeCommentBox = (function(){ "use strict"; var htVar = {}; var htElement = {}; /** * @private */ function _init(htOptions){ _initVar(htOptions); _initElement(); _attachEvent(); _initFileUploader(); } /** * Initialize Variables * @param htOptions * @private */ function _initVar(htOptions){ htVar.sTplFileItem = htOptions.sTplFileItem || $('#tplAttachedFile').text(); } /** * Initialize Elements * @private */ function _initElement(){ htElement.welCommentWrap = $("#review-form"); htElement.welCommentForm = htElement.welCommentWrap.find("form"); htElement.welCommentTextarea = htElement.welCommentForm.find('textarea[data-editor-mode="code-review-body"]'); htElement.welCommentUploader = htElement.welCommentForm.find(".upload-wrap"); htElement.welInitialParent = htElement.welCommentWrap.parent(); } /** * Attach event handlers * @private */ function _attachEvent(){ htElement.welCommentForm.on("click", '[data-toggle="close"]', _hide); } function _show(welTarget, htOptions) { htOptions = htOptions || {}; // show comment form var sPlacement = (htOptions.sPlacement || "bottom").toLowerCase(); _setArrowPlacement(sPlacement); _placeReviewForm(welTarget, sPlacement); htElement.welCommentWrap.show(); htElement.welCommentTextarea.focus(); $.event.trigger("CodeCommentBox:aftershow"); } /** * Set arrow placement of welCommentWrap * arrow will be placed on opposite side to sPlacement * * @param sPlacement Where to show commentBox from welTarget (top or bottom) * @private */ function _setArrowPlacement(sPlacement){ htVar.htArrowPlacement = htVar.htArrowPlacement || { "top": "bottom", "bottom": "top" }; htElement.welCommentWrap.removeClass("arrow-top arrow-bottom") .addClass("arrow-" + htVar.htArrowPlacement[sPlacement]); } /** * Place welCommentWrap in proper position with welTarget * * @param welTarget * @param sPlacement * @private */ function _placeReviewForm(welTarget, sPlacement){ var welFormTarget = _getReviewFormTarget(welTarget); var welFormPlace = _getReviewFormPlace(welFormTarget, sPlacement); _setReviewFormFields(_getReviewFormFieldData(welFormTarget)); welFormPlace.find(".write-comment-form").append(htElement.welCommentWrap); } /** * Get target element to place review form * * @param welTarget * @returns {Wrapped Element} * @private */ function _getReviewFormTarget(welTarget){ if(!welTarget.data("thread-id") && !welTarget.data("line")){ return welTarget.prevUntil("tr[data-line]"); } return welTarget; } /** * Get element to append review form * * @param welTarget * @param sPlacement * @returns {Wrapped Element} * @private */ function _getReviewFormPlace(welTarget, sPlacement){ if(welTarget.data("thread-id")){ return welTarget.closest(".comment-thread-wrap") } var welPlace = $('