Changeset - 86ef51db5dff
[Not reviewed]
0 2 0
Brett Smith (brett) - 7 years ago 2016-09-09 16:10:41
brett@sfconservancy.org
Supporter page: Refactor JavaScript.

This isn't intended to have any functional change, it's just DRYing up
the code to simplify functional changes later.
2 files changed with 36 insertions and 60 deletions:
0 comments (0 inline, 0 general)
www/conservancy/static/css/conservancy.css
Show inline comments
...
 
@@ -399,48 +399,58 @@ body.conservancy-supporter #navbar ul li.supporter a
 
  float: left;
 
  margin-top: 10px;
 
  text-align: center;
 
  list-style: none;
 
  margin-right: 5px;
 
}
 

	
 
#subbox {
 
   position: absolute;
 
   padding-top: 10px;
 
   right: 0px;
 
   width: 200px;
 
   font-size: 12px;
 
}
 

	
 
img.inside-faq {
 
  max-width: 100%;
 
  width: auto;
 
  overflow: scroll;
 
}
 
pre {
 
  overflow: auto;
 
}
 

	
 
.supporter-type-selector a {
 
    font-size: 125%;
 
    font-weight: normal;
 
}
 

	
 
.supporter-type-selector a.supporter-type-selector-selected {
 
    font-size: 127%;
 
    font-weight: bold;
 
}
 

	
 
/* Make dl's ( such as for FAQ entries) look nice on screens, both big and small. */
 

	
 
dl {
 
    border: 3px double #ccc;
 
    padding: 0.5em;
 
}
 
dt {
 
    text-align: center;
 
    margin: 0em 1em 0.5em 0.5em;
 
    font-weight: bold;
 
    color: green; }
 
dd {
 
    margin: 0 0 1.5em 2em;
 
}
 

	
 
@media only screen and (min-width: 685px) {
 
dl {
 
    border: 3px double #ccc;
 
    padding: 0.5em;
 
}
 
dt {
 
    float: left;
 
    text-align: center;
 
    width: 10em;
www/conservancy/static/js/supporter-page.js
Show inline comments
...
 
@@ -183,106 +183,72 @@ $(document).ready(function() {
 
        }
 
    });
 
    var validateFormAtSubmission = function(element, event) {
 
            var valid = element.hasClass("valid");
 
            if (! valid) {
 
                $("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
 
                                        .css("font-weight", "bold").css("font-size", "150%");
 
	        event.preventDefault();
 
            } else {
 
                $("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
 
            }
 
    };
 
    $(".supporter-form-submit#monthly").click(function (event) {
 
        validateFormAtSubmission($(".supporter-form#monthly input#amount"), event);
 
    });
 
    $(".supporter-form-submit#annual").click(function (event) {
 
        validateFormAtSubmission($(".supporter-form#annual input#amount"), event);
 
    });
 
    $(".supporter-form-submit#renewal").click(function (event) {
 
        validateFormAtSubmission($(".supporter-form#renewal input#amount"), event);
 
    });
 
    $(".dinner-form-submit").click(function (event) {
 
        validateFormAtSubmission($(".dinner-form input#amount"), event);
 
    });
 
    /* Handle toggling of annual/monthly form selections */
 
    $('.supporter-type-selection#monthly').hide();
 
    $('.supporter-type-selection#renewal').hide();
 
    $('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
 

	
 
    $("a[href$='monthly']").bind('click', function() {
 
        $('.supporter-type-selection#annual').hide();
 
        $('.supporter-type-selection#renewal').hide();
 
        $('.supporter-type-selection#monthly').show();
 
        $('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
 
        $('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
 
        $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
 
    var selectSupportType = function(event) {
 
        var $selectedLink = $(event.target);
 
        $(".supporter-type-selector a").removeClass("supporter-type-selector-selected");
 
        $selectedLink.addClass("supporter-type-selector-selected");
 
        $(".supporter-type-selection").each(function(index, element) {
 
            var $element = $(element);
 
            if (event.target.href.endsWith("#" + element.id)) {
 
                $element.show();
 
            } else {
 
                $element.hide();
 
            }
 
        });
 
        $("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
 
    });
 
    $("a[href$='annual']").bind('click', function() {
 
        $('.supporter-type-selection#renewal').hide();
 
        $('.supporter-type-selection#monthly').hide();
 
        $('.supporter-type-selection#annual').show();
 
        $('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
 
        $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
 
        $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
 
    });
 
    $("a[href$='renewal']").bind('click', function() {
 
        $('.supporter-type-selection#annual').hide();
 
        $('.supporter-type-selection#monthly').hide();
 
        $('.supporter-type-selection#renewal').show();
 
        $('#renewalSelector').css("font-weight", "bold").css("font-size", "127%");
 
        $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
 
        $('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
 
    });
 
    };
 
    $(".supporter-type-selector a").bind("click", selectSupportType);
 

	
 
    var selectSupportTypeFromHash = function() {
 
        var urlHash = window.location.hash;
 
        if ((urlHash !== "#monthly") && (urlHash !== "#renewal")) {
 
            urlHash = "#annual";
 
        }
 
        $(".supporter-type-selector a[href=" + urlHash + "]").click();
 
        console.log("fromHash done");
 
    };
 
    $(window).bind("hashchange", selectSupportTypeFromHash);
 
    selectSupportTypeFromHash();
 

	
 
    $( ".footnote-mark" ).tooltip({
 
        items: "a",
 
        hide: { duration: 5000 },
 
        position: {
 
            my: "center bottom-20",
 
            at: "center left",
 
            using: function( position, feedback ) {
 
                $( this ).css( position );
 
                $( "<div>" )
 
                    .addClass( "arrow" )
 
                    .addClass( feedback.vertical )
 
                    .addClass( feedback.horizontal )
 
                    .appendTo( this );
 
            }
 
        },
 
        content: function() {
 
            return $('.footnote-1-text').text();
 
        }
 
    });
 
});
 

	
 
$(window).load(function () {
 
    verifySelctionCorrectOnPageLoad = function() {
 
        var ourURL = document.URL;
 
        if (ourURL.search("#monthly") > 0) {
 
            $('.supporter-type-selection#annual').hide();
 
            $('.supporter-type-selection#monthly').show();
 
            $('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
 
            $('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
 
            $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
 
        }
 
        if (ourURL.search("#annual") > 0) {
 
            $('.supporter-type-selection#monthly').hide();
 
            $('.supporter-type-selection#annual').show();
 
            $('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
 
            $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
 
            $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
 
        }
 
        if (ourURL.search("#renewal") > 0) {
 
            $('.supporter-type-selection#monthly').hide();
 
            $('.supporter-type-selection#annual').hide();
 
            $('.supporter-type-selection#renewal').show();
 
            $('#renewalSelector').css("font-weight", "bold").css("font-size", "127%");
 
            $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
 
            $('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
 
        }
 
    }
 
    if (location.hash) {
 
        setTimeout(verifySelctionCorrectOnPageLoad, 1);
 
    }
 
    window.addEventListener("hashchange", verifySelctionCorrectOnPageLoad);
 
});
0 comments (0 inline, 0 general)