treconomics_project/static/javascripts/search_helpers.js
/*
Binds anchor clicks with class doc-link with the following code.
Used to enforce "document download" delay times.
*/
Binds anchor clicks with class doc-link with the following code.
Used to enforce "document download" delay times.
Binds anchor clicks with class doc - link with the following code . Used to enforce " document download " delay times .
function bindDocumentClicks() {
    $('.doc-link').click(
        function(event) {
            event.preventDefault();
            if (INTERFACE_ENABLED) {
                var delay = parseInt($('#delay_docview').val());
                var targetURL = event.target.href;
                if (delay == "") {
                    delay = 0;
                }
                if (delay > 0) {
                    changeInteractionStatus(false, true);
                    var parent = $(event.target).closest('div[class="search_result"]');
                    var trecID = $(parent[0]).attr('id');
                    var whooshID = $(parent[0]).attr('whooshid');
                    var rank = $(parent[0]).attr('rank');
                    var page = $(parent[0]).attr('page');
                    $.ajax({
                        url: '/treconomics/docview_delay/',
                        data: {'trecID': trecID, 'whooshID': whooshID, 'rank': rank, 'page': page}
                        }).fail(function(data) {
                            var responseData = $.parseJSON(data.responseText);
                            if ('timeout' in responseData) {
                                alert("Your time for this task has expired. We will now redirect you to the next step.");
                                window.location = '/treconomics/next/';
                            }
                    });
                    setTimeout(function() {window.location = targetURL;}, (delay * 1000));
                }
                else {
                    window.location = targetURL;
                }
            }
            else {
                alert("We're processing your previous request; please wait.");
            }
    });
}
function bindDocumentClicks ( ) { $ ( '.doc-link' ) . click ( function ( event ) { event . preventDefault ( ) ; if ( INTERFACE_ENABLED ) { var delay = parseInt ( $ ( '#delay_docview' ) . val ( ) ) ; var targetURL = event . target . href ; if ( delay == "" ) { delay = 0 ; } if ( delay > 0 ) { changeInteractionStatus ( false , true ) ; var parent = $ ( event . target ) . closest ( 'div[class="search_result"]' ) ; var trecID = $ ( parent [ 0 ] ) . attr ( 'id' ) ; var whooshID = $ ( parent [ 0 ] ) . attr ( 'whooshid' ) ; var rank = $ ( parent [ 0 ] ) . attr ( 'rank' ) ; var page = $ ( parent [ 0 ] ) . attr ( 'page' ) ; $ . ajax ( { url : '/treconomics/docview_delay/' , data : { 'trecID' : trecID , 'whooshID' : whooshID , 'rank' : rank , 'page' : page } } ) . fail ( function ( data ) { var responseData = $ . parseJSON ( data . responseText ) ; if ( 'timeout' in responseData ) { alert ( "Your time for this task has expired. We will now redirect you to the next step." ) ; window . location = '/treconomics/next/' ; } } ) ; setTimeout ( function ( ) { window . location = targetURL ; } , ( delay * 1000 ) ) ; } else { window . location = targetURL ; } } else { alert ( "We're processing your previous request; please wait." ) ; } } ) ; }
Binds anchor clicks with class doc-link with the following code.
Binds anchor clicks with class doc - link with the following code .
// Gather information for, and initiate, an AJAX call to indicate that the result is delayed.