Example #1
0
    bindEvents: function () {
        var me = this;
        var $main = $('#comments-main');
        var $send = $('.send');

        $main.off('click');
        $main.on('click', '.delete', function () {
            var target = $(this).parent();

            MidUI.alert({
                content: me.page.lang.alertRemoveComment,
                onApply: function () {
                    me.removeData(target);
                }
            });
        });

        $send.off('click');
        $send.on('click', function () {
            if (!$send.hasClass('unable') && me.attach.isAttachesReady() && me.isCanSubmit) {
                me.isCanSubmit = false;
                me.addComment();
            }
        });

        me.attach = AttachWrapper.initAttach({
            container: '#attachList',
            addBtn: '#addAttach',
            callback: function () {
                var hasAttach = !!me.attach.getModifyAttaches().length;
                var words = $send.data('notNull');
                if (hasAttach) {
                    if (!$send.data('toLong')) {
                        $send.removeClass('unable');
                    }
                    $send.data({attach: true});
                }
                else {
                    $send.data({attach: false});
                }
                if (!hasAttach && !words) {
                    $send.addClass('unable');
                }
            }
        });
    },
Example #2
0
            .done(function (result) {

                if (!result || result.meta.code !== 200) {
                    return;
                }
                // 添加成功
                if (result.meta.code === 200) {
                    // 共用 ./item.tpl
                    var data = {
                        objList: [result.data]
                    };
                    
                    dealData(data, me.page);

                    me.page.render($('.comments dd').eq(0), data, {
                        tmpl: tmplItem,
                        type: 'before'
                    });

                    me.refreshTotal(total + 1);

                    getUserAndPhoto([result.data]);

                    // 待优化
                    // 这里可以判断是否已经有了当前用户的信息
                    renderUser(me.$main, data.objList);
                    $send.data({attach: false});
                    me.page.virtualInput.reset();
                    $('#attachList ul').remove();
                    me.$listNull.addClass('hide');
                    var p = $('#addAttach').parent();
                    $('#addAttach').off().remove();
                    p.prepend('<span class="button" id="addAttach"></span>');
                    me.attach = AttachWrapper.initAttach({
                        container: '#attachList',
                        addBtn: '#addAttach',
                        callback: function () {
                            var hasAttach = !!me.attach.getModifyAttaches().length;
                            var words = $send.data('notNull');
                            if (hasAttach) {
                                if (!$send.data('toLong')) {
                                    $send.removeClass('unable');
                                }
                                $send.data({attach: true});
                            }
                            else {
                                $send.data({attach: false});
                            }
                            if (!hasAttach && !words) {
                                $send.addClass('unable');
                            }
                        }
                    });

                    // 滚动到comments顶部
                    me.scrollCommentsTop();
                }
                else {

                }
            })