xiao134679hai
小孩嘛
采纳率0%
2017-06-23 06:17

哪位大神知道这是什么意思

 $(document).ready(function () {
   $("#commentTemplateDiv").bind(
   "click",
   function () {
       var tdObj = $("#td_"
               + $("#templateTradeOid").val());
       tdObj.find(".visitCommentsInput").focus();
   });

    $("#btn_commentTemplateDiv_close").bind("click",function () {
       closeCommentTempldateDialog();
   })
    $("span.normal,span.abnormal").bind("click",function () {
        var tVal = $(this).text();
        var tdObj = $("#td_"+ $("#templateTradeOid").val());
        var content = tdObj.find(".visitCommentsInput").val();
        var preCursorPost = getCursorPosition(tdObj.find(".visitCommentsInput"));
        //如果用户已经编辑过今天的数据, 则只有光标位置插入选中的常用词
        //否则,第一行用选中的常用词替换
        if(isTodayEdited)
        {
            if(preCursorPost >0){
                var leftCon = content.substring(0,preCursorPost);
                var rightCon = content.substr(preCursorPost);
                content = leftCon + tVal + rightCon;
                tdObj.find(".visitCommentsInput").val(content);
                setCaretToPos(tdObj.find(".visitCommentsInput")[0],(leftCon + tVal).length)
            }
        }else{
            var firstLineData = appendLine+ " " + tVal;
            content = firstLineData+ "\n"+ getExclueFirstLineContent(content);
            tdObj.find(".visitCommentsInput").val(content);
            setCaretToPos(tdObj.find(".visitCommentsInput")[0],firstLineData.length)
        }
   });

});

function getCursorPosition(obj) {
        var el = obj.get(0);
        var pos = 0;
        if ('selectionStart' in el) {
            pos = el.selectionStart;
        } else if ('selection' in document) {
            el.focus();
            var Sel = document.selection.createRange();
            var SelLength = document.selection.createRange().text.length;
            Sel.moveStart('character', -el.value.length);
            pos = Sel.text.length - SelLength;
        }
        return pos;
    }
function closeCommentTempldateDialog() {
    $("#commentTemplateDiv").hide();
    var tdObj = $("#td_" + $("#templateTradeOid").val());
    tdObj.find(".visitCommentsInput").focus();
}

function setSelectionRange(input, selectionStart, selectionEnd) {
    if (input.setSelectionRange) {
        input.focus();
        input.setSelectionRange(selectionStart, selectionEnd);
    } else if (input.createTextRange) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveEnd('character', selectionEnd);
        range.moveStart('character', selectionStart);
        range.select();
    }
}
//获取第一行的内容
function getFirstLineContent(content) {
    var idx = content.indexOf('\n');
    var firstLineData = content;
    if (idx > 0) {
        firstLineData = content.substring(0, idx);
    }
    return firstLineData;
}
//获取非第一行的内容
function getExclueFirstLineContent(content) {
    var idx = content.indexOf('\n')
    var remainLineContent = "";
    if (idx > 0) {
        remainLineContent = content.substr(idx + 1);
    }
    return remainLineContent;
}
function setCaretToPos(input, pos) {
    setSelectionRange(input, pos, pos);
}

function editVisitComments(tradeOid, ele) {
    tdClickEditVisitComments(tradeOid, null, false);
}

var oldTradeOid = "";
//是否今天的数据已经编辑标识
var isTodayEdited = false;
function tdClickEditVisitComments(tradeOid, td, isBuyerRated) {
    if (isBuyerRated) {
        return;
    }
    oldTradeOid = tradeOid;
    var tdObj = $("#td_" + tradeOid);
    var textWrapper = tdObj.find(".visitCommentsText");
    var input = tdObj.find(".visitCommentsInput");

    var content = textWrapper.text();
    if (input.is(":visible")) {
        content = input.val();
    }
    input.show();

    if(openAutoFlag){
        var ua = window.navigator.userAgent;
        var isFirefox = ua.indexOf("Firefox") != -1;  
        var isEdge = ua.indexOf("Edge") != -1;
        var isChrome = ua.indexOf("Chrome") != -1 && !isEdge;

        var y = tdObj.offset().top;
        var x = input.offset().left;
        var width = 260;
        y = y + input.height() + 5;
        if(isFirefox){
            x -= 1;
        }
        else if(isEdge){
            x -= 4;
        }
        else if(isChrome){
            x += 1;
            y -=1;
        }

        if ($("#templateTradeOid").val() != tradeOid) {
            $("#commentTemplateDiv").css({
                "position" : "absolute",
                "width" : width + "px",
                "left" : x + "px",
                "top" : y + "px",
                "display" : "block"
            });
            $("#templateTradeOid").val(tradeOid);
        }
    }

    caretPos = 0;
    if(openAutoFlag){
        //获取当前comment的第一行的数据
        var firstLineData = getFirstLineContent(content);
        //如果第一行不以"今日"字符串开始, 则插入今日这一行
        caretPos = firstLineData.length;
        if (firstLineData.indexOf(today) != 0) {
            isTodayEdited = false;
            caretPos = appendLine.length + 1;
            if (content.length > 0) {
                content = appendLine + " \n" + content;
            } else {
                content = appendLine + " ";
            }
        } else {
            isTodayEdited = true;
            caretPos = firstLineData.length;
        }
    }
    textWrapper.hide();
    input.val(content);
    if(input.is(":focus") == false){
        if(openAutoFlag){
            setCaretToPos(input[0], caretPos);
        }
        input.focus();
    }
}

function saveVisitComments(tradeOid, tid, ele, visitType) {
    var tdObj = $("#td_" + $("#templateTradeOid").val());
    var allObj = tdObj.find(".visitCommentsInput");
    if(oldTradeOid == tradeOid){
        if (tdObj.find(".visitCommentsInput").is(":focus") ) {
            return;
        }
    }
    if(oldTradeOid == tradeOid){
        $("#templateTradeOid").val("");
        $("#commentTemplateDiv").hide();
    }
    var td = ele.offsetParent;
    var textWrapper = $(td).find(".visitCommentsText");
    var oldText = textWrapper.text();
    var input = $(td).find(".visitCommentsInput");
    var text = input.val();
    if(openAutoFlag){
        if ((text == appendLine + ' ' || text == appendLine) && oldText == "") {
            text = "";
        }
    }

    textWrapper.text(text);
    textWrapper.show();
    input.hide();
    if (oldText == text) {
        return;
    }
    if(openAutoFlag &&( (appendLine +" \n" + oldText) == text)){
        textWrapper.text(oldText);
        return;
    }
    $.ajax({
            type : 'POST',
            url : "${pageContext.request.contextPath}/dsr/tbReturnVisit!saveVisitComments.action",
            data : {
                "returnVisitVo.visitComments" : text,
                "returnVisitVo.tradeOid" : tradeOid,
                "returnVisitVo.tid" : tid,
                "returnVisitVo.visitTypeCode" : visitType
            },
            success : function (data) {
                if ('success' == data) {
                    //showMsg("saving", "保存成功!");
                } else if (hasReloginScript(data)) {
                    alert("登录超时!请重新登录。");
                    $("body").html(data);
                } else if ("OperatorIsNotAssignedVisitor" == data) {
                    //alert("对不起,您当前登录账号不是该订单所属卖家下的账号!请重新登录。");
                    alert("买家已评价,无法备注。");
                    //window.top.location.href = "${pageContext.request.contextPath}/indexAction!logout.action";
                } else {
                    //                          showMsg("saving", "保存失败,请稍后重试!");
                    alert("保存失败,请稍后重试!");
                }
            },
            error : function (data) {
                //                      showMsg("saving", "保存出错,请稍后重试!" + data);
                alert("保存出错,请稍后重试!\n" + data);
            }
        });
}
//创建一个函数,用于返回一个无参数函数 
function _newSaveVisitComments(tradeOid, tid, ele, visitType) {
    return function () {
        saveVisitComments(tradeOid, tid, ele, visitType);
    }
}
function newSaveVisitComments(tradeOid, tid, ele, visitType) {
    //做一个超时器, 检查用户是否选择的是panel
    if(openAutoFlag){
        window.setTimeout(_newSaveVisitComments(tradeOid, tid, ele, visitType),
            300);
    }else{
        saveVisitComments(tradeOid, tid, ele, visitType);
    }
}
function dbClickEditVisitCommentsArea(tradeOid)
{
    $("#commentTemplateDiv").show();
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • qq_34730277 南宫文凯 4年前

    开始是在一个id上定义一个事件,触发后获取了很多的参数,进行判断,然后拼接,修改参数的样式,用ajax发送到后台,得到后台查询的数据后拼接判断,显示多行进行。。。。。

    你能具体一个问题吗?这样一股脑复制粘贴上来!我们看了也很头疼啊!难不成又粘贴下来,一句一句翻译,也太多了!

    点赞 5 评论 复制链接分享
  • bk_rookie bk_rookie 4年前

    应该是绑定了一个点击事件,然后执行了点击方法,代码太多,看着头晕

    点赞 评论 复制链接分享
  • xiao134679hai 小孩嘛 4年前

    我想问的是这个代码里不让修改的 怎么能让他修改了

    点赞 评论 复制链接分享
  • xiao134679hai 小孩嘛 4年前

    不好意思哈 因为看不懂才粘贴的

    点赞 评论 复制链接分享

相关推荐