packages feed

notmuch-web-0.1.1: templates/pager.julius

function notmuchUpdatePager(idx) {
    var li = $("#nextthreadli");
    var btn = $("#nextthread");

    document.title = window.notmuchweb_threads[idx].subject;
    $("#pager-cur-num").html((idx+1).toString());

    if (idx >= window.notmuchweb_threads.length - 1) {
        li.addClass("disabled");
        btn.attr("href", "#");
    } else {
        li.removeClass("disabled");
        btn.attr("href", window.notmuchweb_threads[idx+1].url);
        btn.data("notmuch-thread-index", idx+1);
    }
}

$(document).ready(function() {
    $("#nextthread").on("click", function(ev) {
        $.pjax.click(ev,
            { container: $("#threadpane")
            , id: $(this).data("notmuch-thread-index")
            , timeout: 0
            });
    });
    $(document).on("pjax:complete", function(ev, xhr, st, options) {
        notmuchUpdatePager(options.id);
        if ($(window).width() < 700) {
            $(".text-as-markdown a[data-toggle=tab]").click();
        }
    });
    $(document).on("pjax:popstate", function(ev) {
        var i = ev.state.id;

        // The very first page gets an id generated by jquery using getTime so
        // is the number of milliseconds since January 1, 1970.  This will be
        // bigger than any id we have so detect that
        if (i > 1e10) i = 0;

        notmuchUpdatePager(i);
    });
    $("#threadpager").on("click", ".pager-retag", function(ev) {
        var url = $(this).data("notmuch-url");
        var thread = $("#messageThread").data("notmuch-threadid");
        var retagform = $("#retag-csrf-form");
        url = url.replace("\/-\/", "/" + thread + "/");

        $.ajax({
            type: 'POST',
            data: retagform.serialize(),
            dataType: 'json',
            url: url
        })
        .done(function(data) {
            if ($.inArray("unread", data.add)) {
                $("#nextthread").click();
            }
        })
        .fail(function(xhr, err, e) {
            alert("Error " + err + " " + e);
        });
    });
});