<commit_before>/**
 * Created by bowei on 2015/4/25.
 */
function post_callback(data, ret_status){
    preload_counter = 0;
    console.log('post_callback:' + ret_status);
    console.log(data);
    if(ret_status != 'success'){
        console.log('post_callback: Connection failed.');
    }
    var jsonval = jQuery.parseJSON(data);
    switch (jsonval.status){
        case 2:
            alert('err type 2');
            break;
        case 1:
            //window.location.href='finish';
            get_expand_status(jsonval.can_expand);
            break;
        case 0:
            refreshZoomImage($('#img_a'), jsonval.img_src1);
            refreshZoomImage($('#img_b'), jsonval.img_src2);

            $('#img_a').one('load', function(){
                console.log('img1 loaded.');
                switchLoadImg('a', false);
                set_image_margin();
                setZoomImage($(this), 1);

                preload_counter++;
                if(preload_counter < 2)
                    return;

                on_img_load(jsonval.next_img_src1, jsonval.next_img_src2);

            }).each(function() {
                if(this.complete) $(this).load();
            });

            $('#img_b').one('load', function(){
                console.log('img2 loaded.');
                switchLoadImg('b', false);
                set_image_margin();
                setZoomImage($(this), 11);
                preload_counter++;
                if(preload_counter < 2)
                    return;
                on_img_load(jsonval.next_img_src1, jsonval.next_img_src2);

            }).each(function() {
                if(this.complete) $(this).load();
            });

            var q_type = jsonval.q_type;
            if(q_type == 0){
                $('#cmp_usability').css('display', 'none');
                $('#cmp_creativity').css('display', 'inline');
            }else if(q_type == 1){
                $('#cmp_usability').css('display', 'inline');
                $('#cmp_creativity').css('display', 'none');
            }else{
                alert('qtype error');
            }
            if(q_type != last_q_type){
                //Show hint when q_type changes
                console.log('q_type changed.');
                show_hint(q_type);
            }
            last_q_type = q_type;

            $('#curr_index').text(jsonval.prog_current);
            $('#total_index').text(jsonval.prog_total);
            var progress = jsonval.prog_current/jsonval.prog_total*100 + "%";
            $('#meter_span').css('width', progress);
            //Clear radio button
            //$(".radio").each(function(){
            //    $(this).prop('checked', false);
            //});
            $('input').iCheck('uncheck');
            
            start_time = new Date().getTime();

            //Set button status
            //var max_cmp_size = jsonval.max_size;
            //if((jsonval.prog_current == jsonval.prog_total)
            //    && jsonval.can_expand){
            //    switch_double_button(true);
            //} else {
                switch_double_button(false);
            //}

            break;
        default :
            alert('wtf');
    }

}

function on_img_load(img1, img2){
    if(!img1 ||
        !img2){
        return;
    }
    start_time = new Date().getTime();
    console.log('perload started.');
    pre_load_image([
        img1,
        img2
    ]);
}

function pre_load_image(arrayOfImages){
    $(arrayOfImages).each(function () {
        (new Image()).src = this;
    });
}

function show_hint(q_type){
    if(q_type == 0){
        $('#q_type_span').text("创新性");
    } else {
        $('#q_type_span').text("实用性");
    }
    $('#hint_container').show();
    $('#finish_hint_container').hide();
    $('#hint_mask').show();
}

//检查表单填写完整性
function check_validity(){
    var val_c = $("input[name='creativity']:checked").val();
    var val_u = $("input[name='usability']:checked").val();
    if(val_c == undefined && val_u == undefined){
        return false;
    }
    return true;
}

function refreshZoomImage(img_obj, img_src){
    $('.zoomContainer').remove();
    img_obj.removeData('elevateZoom');
    img_obj.attr('src', img_src);
    img_obj.data('zoom-image', img_src);
    //
}

function setZoomImage(img_obj, zoompos){
    var zoomConfig = {
        scrollZoom : true,
        zoomWindowPosition: zoompos,
        zoomWindowWidth: 512,
        zoomWindowHeight: 512
    };<commit_msg>change zoom lens behavior<commit_after>/**
 * Created by bowei on 2015/4/25.
 */
function post_callback(data, ret_status){
    preload_counter = 0;
    console.log('post_callback:' + ret_status);
    console.log(data);
    if(ret_status != 'success'){
        console.log('post_callback: 网络连接失败，请重试.');
    }
    var jsonval = jQuery.parseJSON(data);
    switch (jsonval.status){
        case 2:
            alert('err type 2');
            break;
        case 1:
            //window.location.href='finish';
            get_expand_status(jsonval.can_expand);
            break;
        case 0:
            refreshZoomImage($('#img_a'), jsonval.img_src1);
            refreshZoomImage($('#img_b'), jsonval.img_src2);

            $('#img_a').one('load', function(){
                console.log('img1 loaded.');
                switchLoadImg('a', false);
                set_image_margin();
                setZoomImage($(this), 1);

                preload_counter++;
                if(preload_counter < 2)
                    return;

                on_img_load(jsonval.next_img_src1, jsonval.next_img_src2);

            }).each(function() {
                if(this.complete) $(this).load();
            });

            $('#img_b').one('load', function(){
                console.log('img2 loaded.');
                switchLoadImg('b', false);
                set_image_margin();
                setZoomImage($(this), 11);
                preload_counter++;
                if(preload_counter < 2)
                    return;
                on_img_load(jsonval.next_img_src1, jsonval.next_img_src2);

            }).each(function() {
                if(this.complete) $(this).load();
            });

            var q_type = jsonval.q_type;
            if(q_type == 0){
                $('#cmp_usability').css('display', 'none');
                $('#cmp_creativity').css('display', 'inline');
            }else if(q_type == 1){
                $('#cmp_usability').css('display', 'inline');
                $('#cmp_creativity').css('display', 'none');
            }else{
                alert('qtype error');
            }
            if(q_type != last_q_type){
                //Show hint when q_type changes
                console.log('q_type changed.');
                show_hint(q_type);
            }
            last_q_type = q_type;

            $('#curr_index').text(jsonval.prog_current);
            $('#total_index').text(jsonval.prog_total);
            var progress = jsonval.prog_current/jsonval.prog_total*100 + "%";
            $('#meter_span').css('width', progress);
            //Clear radio button
            //$(".radio").each(function(){
            //    $(this).prop('checked', false);
            //});
            $('input').iCheck('uncheck');
            
            start_time = new Date().getTime();

            //Set button status
            //var max_cmp_size = jsonval.max_size;
            //if((jsonval.prog_current == jsonval.prog_total)
            //    && jsonval.can_expand){
            //    switch_double_button(true);
            //} else {
            //  switch_double_button(false);
            //}

            break;
        default :
            alert('wtf');
    }

}

function on_img_load(img1, img2){
    if(!img1 ||
        !img2){
        return;
    }
    start_time = new Date().getTime();
    console.log('perload started.');
    pre_load_image([
        img1,
        img2
    ]);
}

function pre_load_image(arrayOfImages){
    $(arrayOfImages).each(function () {
        (new Image()).src = this;
    });
}

function show_hint(q_type){
    if(q_type == 0){
        $('#q_type_span').text("创新性");
    } else {
        $('#q_type_span').text("实用性");
    }
    $('#hint_container').show();
    $('#finish_hint_container').hide();
    $('#hint_mask').show();
}

//检查表单填写完整性
function check_validity(){
    var val_c = $("input[name='creativity']:checked").val();
    var val_u = $("input[name='usability']:checked").val();
    if(val_c == undefined && val_u == undefined){
        return false;
    }
    return true;
}

function refreshZoomImage(img_obj, img_src){
    $('.zoomContainer').remove();
    img_obj.removeData('elevateZoom');
    img_obj.attr('src', img_src);
    img_obj.data('zoom-image', img_src);
    //
}

function setZoomImage(img_obj, zoompos){
    //var zoomConfig = {
    //    scrollZoom : true,
    //    zoomWindowPosition: zoompos,
    //    zoomWindowWidth: 512,
    //    zoomWindowHeight: 512
    //};
    var zoomConfig = {
        zoomType	    : "lens",
        lensSize        : 300,
        scrollZoom      : true,
        //containLensZoom : true,
        borderColour    : '#fff',
        lensBorder      : 1 ,
        lensShape   : 'round'
    }
{'fraction_non_alphanumeric': 0.15784908933217692, 'fraction_numerical': 0.009757155247181267, 'mean_word_length': 1.7504472271914133, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6677127', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2754, 'n_words': 436}