/**
 * @file mip-hs-praise 组件
 * @author
 */

define(function (require) {
    var $ = require('zepto');
    var util = require('util');
    var platform = util.platform;
    var customElement = require('customElement').create();

    customElement.prototype.firstInviewCallback = function () {
        var $el = $(this.element);

        function closearticle($modelbg, $model) {
            $modelbg.fadeOut(300);
            $model.fadeOut(300);
        }

        function openarticle($modelbg, $model, $text) {
            $el.find('.text').text($text);
            $modelbg.fadeIn(300);
            $model.fadeIn(300);
        }

        function openAlart($showtext, callback) {
            openarticle($el.find('.model_bg'), $el.find('.article_model'), $showtext);
            if (callback) {
                $el.find('.article_close').click(function () {
                    closearticle($el.find('.model_bg'), $el.find('.article_model'));
                    callback();
                });
            }
        }

        $el.find('.article_close').click(function () {
            closearticle($el.find('.model_bg'), $el.find('.article_model'));
        });
        $el.find('.qx_close').click(function () {
            closearticle($el.find('.model_bg'), $el.find('.article_model'));
        });
        $el.find('.praise').click(function () {
            var That = $(this);
            var unzan = That.parent().attr('url-unzan');
            var zan = That.parent().attr('url-zan');
            var num = That.parent().siblings('.constants').html();
            if (That.hasClass('praiseon')) {
                $.ajax({
                    type: 'post',
                    url: unzan,
                    data: {
                        'answer_id': num
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status === 0) {
                            var b = That.children('i').text();
                            var oText = parseFloat(b);
                            That.children('i').text(oText - 1);
                            That.removeClass('praiseon');
                        }
                        else {
                            openarticle($el.find('.model_bg'), $el.find('.article_model'), data.msg);
                        }
                    },
                    error: function (data) {
                        if (data.statusText === 'Unauthorized') {
                            openAlart('请登录', function () {
                                window.top.location.href = '/login?service=welcome';
                            });
                        }

                    }
                });
            }
            else {
                $.ajax({
                    type: 'post',
                    url: zan,
                    data: {
                        'answer_id': num
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status === 0) {
                            var b = That.children('i').text();
                            var oText = parseFloat(b);
                            That.addClass('praiseon');
                            That.children('i').text(oText + 1);
                        }
                        else {
                            openarticle($el.find('.model_bg'), $el.find('.article_model'), data.msg);
                        }
                    },
                    error: function (data) {
                        if (data.statusText === 'Unauthorized') {
                            openAlart('请登录', function () {
                                window.top.location.href = '/login?service=welcome';
                            });
                        }

                    }
                });
            }
        });
    };
    return customElement;
});

@@ -101,74 +101,8 @@
 ');%0A
-    var util = require('util');%0A    var platform = util.platform;%0A
     
@@ -156,16 +156,16 @@
 eate();%0A
+
 %0A    cus
@@ -604,32 +604,74 @@
 xt, callback) %7B%0A
+            $el.find('.qx_close').show();%0A
             open
@@ -1118,32 +1118,80 @@
 ticle_model'));%0A
+            $el.find('.qx_close').fadeOut(300);%0A
         %7D);%0A    
@@ -1228,32 +1228,32 @@
 k(function () %7B%0A
-
             clos
@@ -1305,32 +1305,80 @@
 ticle_model'));%0A
+            $el.find('.qx_close').fadeOut(300);%0A
         %7D);%0A    

update extensions