(loading typefaces)
Return to Kyle’s Portfolio

Excerpt from media.dvelyk.com/lillucifer/scripts/enhance.js

722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
// Sends a request for the comics new rating after the user has voted
onRate: function(e, href) {
    if(Request.disabled)
        return;

    e.preventDefault();

    // Prevent rating twice
    if(this.rateIndex || this.ratings[this.comics[this.index].id])
        return;

    // Send request
    this.rateIndex = this.index;
    this.ratingRequest.send("get", href.substring(0, href.indexOf("?")),
        this.onRatingChange.bind(this), null, true);
},
// Sets up rating transitions after the request has succeded
onRatingChange: function(req) {
    // Mark this comic as rated
    this.ratings[this.ratings.length] = this.comics[this.rateIndex].id;

    // Determine if the rating has changed
    var oldRating = this.comics[this.rateIndex].rating;
    var newRating = parseInt(req.responseText);
    this.toggleRatings(false);
    if(!isNaN(newRating) && newRating != oldRating) {
        this.comics[this.rateIndex].rating = newRating;

        // If the comic has changed since the request was called, we don't
        // need to make a transition
        if(this.rateIndex != this.index)
            return;

        // Set up the rating transition--text shrinks if rated down, grows if
        // rated up
        var to = (newRating > oldRating) ? 2 : 1;
        var fx = new Animator({duration: 400, transition: Animator.tx.elastic})
            .addSubject(new NumericSS(this.rating, "font-size", 1.5, to, "em"))
            .addSubject(new NumericSS(this.rating, "new-value", oldRating, newRating));
        fx.options.onStep = this.onStep.bind(this);

        fx.options.onComplete = (function() {
            // Reset callbacks
            fx.options.onComplete = function() { }
            fx.options.onStep = function() { }
            fx.seekTo(0);
        }).bind(fx);
        fx.seekTo(1);
    }
    this.rateIndex = null;
},