From d2d29b2cf958d071e54ca201b3ecc7c605969a46 Mon Sep 17 00:00:00 2001 From: Calen Pennington <calen.pennington@gmail.com> Date: Mon, 23 Jul 2012 11:16:13 -0400 Subject: [PATCH] Move most javascript loading to below the body, rather than head --- lms/templates/courseware.html | 4 +- lms/templates/dashboard.html | 46 ++++++------ lms/templates/gradebook.html | 5 +- lms/templates/gradebook_profilegraphs.html | 2 +- lms/templates/main.html | 20 +++--- lms/templates/portal/course_about.html | 72 ++++++++++--------- lms/templates/profile.html | 2 +- lms/templates/simplewiki/simplewiki_base.html | 2 +- 8 files changed, 80 insertions(+), 73 deletions(-) diff --git a/lms/templates/courseware.html b/lms/templates/courseware.html index 29178374fe5..f6133860f45 100644 --- a/lms/templates/courseware.html +++ b/lms/templates/courseware.html @@ -3,7 +3,7 @@ <%block name="bodyclass">courseware</%block> <%block name="title"><title>Courseware – MITx 6.002x</title></%block> -<%block name="headextra"> +<%block name="js_extra"> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script> <link rel="stylesheet" href="${static.url('css/vendor/jquery.treeview.css')}" type="text/css" media="all" /> @@ -27,9 +27,7 @@ <%static:js group='courseware'/> <%include file="mathjax_include.html" /> -</%block> -<%block name="js_extra"> <!-- TODO: http://docs.jquery.com/Plugins/Validation --> <script type="text/javascript"> document.write('\x3Cscript type="text/javascript" src="' + diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 676b9587c61..c0273ef7096 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -8,6 +8,30 @@ <%block name="title"><title>Dashboard</title></%block> +<%block name="js_extra"> + <script type="text/javascript"> + (function() { + + $(".unenroll").click(function(event) { + $("#unenroll_course_id").val( $(event.target).data("course-id") ); + $("#unenroll_course_number").text( $(event.target).data("course-number") ); + + }); + + $(document).delegate('#unenroll_form', 'ajax:success', function(data, json, xhr) { + if(json.success) { + location.href="${reverse('dashboard')}"; + } else { + if($('#unenroll_error').length == 0) { + $('#unenroll_form').prepend('<div id="unenroll_error" class="modal-form-error"></div>'); + } + $('#unenroll_error').text(json.error).stop().css("display", "block"); + } + }); + })(this) + </script> +</%block> + <section class="container dashboard"> <section class="dashboard-banner"> @@ -110,25 +134,3 @@ </section> -<script type="text/javascript"> -(function() { - - $(".unenroll").click(function(event) { - $("#unenroll_course_id").val( $(event.target).data("course-id") ); - $("#unenroll_course_number").text( $(event.target).data("course-number") ); - - }); - - $(document).delegate('#unenroll_form', 'ajax:success', function(data, json, xhr) { - if(json.success) { - location.href="${reverse('dashboard')}"; - } else { - if($('#unenroll_error').length == 0) { - $('#unenroll_form').prepend('<div id="unenroll_error" class="modal-form-error"></div>'); - } - $('#unenroll_error').text(json.error).stop().css("display", "block"); - } - }); -})(this) -</script> - diff --git a/lms/templates/gradebook.html b/lms/templates/gradebook.html index 12f820c8c90..7c2908dc777 100644 --- a/lms/templates/gradebook.html +++ b/lms/templates/gradebook.html @@ -1,10 +1,13 @@ <%inherit file="main.html" /> <%namespace name='static' file='static_content.html'/> -<%block name="headextra"> +<%block name="js_extra"> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.stack.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.symbol.js')}"></script> +</%block> + +<%block name="headextra"> <style type="text/css"> .grade_a {color:green;} diff --git a/lms/templates/gradebook_profilegraphs.html b/lms/templates/gradebook_profilegraphs.html index 137c994bad5..18995cbb4c4 100644 --- a/lms/templates/gradebook_profilegraphs.html +++ b/lms/templates/gradebook_profilegraphs.html @@ -2,7 +2,7 @@ <%namespace name='static' file='static_content.html'/> <%namespace name="profile_graphs" file="profile_graphs.js"/> -<%block name="headextra"> +<%block name="js_extra"> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.stack.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.symbol.js')}"></script> diff --git a/lms/templates/main.html b/lms/templates/main.html index b8bac37dd24..5f767700323 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -8,19 +8,12 @@ <link href='http://fonts.googleapis.com/css?family=Open+Sans:800italic,400,800' rel='stylesheet' type='text/css'> - <%static:css group='application'/> + <%static:css group='application'/> <!--[if lt IE 9]> <%static:css group='ie-fixes'/> <![endif]--> - - <%static:js group='main_vendor'/> - <%static:js group='application'/> - - <!--[if lt IE 9]> - <script src="${static.url('js/html5shiv.js')}"></script> - <![endif]--> - - <%block name="headextra"/> + <%static:js group='main_vendor'/> + <%block name="headextra"/> <meta name="path_prefix" content="${MITX_ROOT_URL}"> </head> @@ -33,6 +26,13 @@ <%block name="bodyextra"/> <%include file="footer.html" /> + + <%static:js group='application'/> + + <!--[if lt IE 9]> + <script src="${static.url('js/html5shiv.js')}"></script> + <![endif]--> + <%block name="js_extra"/> <script src="${static.url('js/my_courses_dropdown.js')}"></script> <script src="${static.url('js/toggle_login_modal.js')}"></script> diff --git a/lms/templates/portal/course_about.html b/lms/templates/portal/course_about.html index 3a33723949e..0c6958c16ce 100644 --- a/lms/templates/portal/course_about.html +++ b/lms/templates/portal/course_about.html @@ -3,12 +3,48 @@ from courseware.courses import course_image_url, get_course_about_section %> <%namespace name='static' file='../static_content.html'/> + +<%inherit file="../main.html" /> + <%block name="js_extra"> + % if not registered: + %if user.is_authenticated(): + ## If the user is authenticated, clicking the enroll button just submits a form + <script type="text/javascript"> + (function() { + $(".register").click(function() { + $("#class_enroll_form").submit(); + }); + + $(document).delegate('#class_enroll_form', 'ajax:success', function(data, json, xhr) { + if(json.success) { + location.href="${reverse('dashboard')}"; + } + }); + })(this) + </script> + %else: + ## If the user is not authenticated, clicking the enroll button pops up the register + ## field. We also slip in the registration fields into the login/register fields so + ## the user is automatically registered after logging in / registering + <script type="text/javascript"> + (function() { + $(".register").click(function() { + if ($("#login_form .enroll_fieldset").length === 0) { + $("#login_form").append( $(".enroll_fieldset").first().clone() ); + } + if ($("#register_form .enroll_fieldset").length === 0) { + $("#register_form").append( $(".enroll_fieldset").first().clone() ); + } + }); + })(this) + </script> + %endif + %endif + <script src="${static.url('js/course_info.js')}"></script> </%block> -<%inherit file="../main.html" /> - <%block name="title"><title>About ${course.number}</title></%block> @@ -119,38 +155,6 @@ </div> </form> </div> - %if user.is_authenticated(): - ## If the user is authenticated, clicking the enroll button just submits a form - <script type="text/javascript"> - (function() { - $(".register").click(function() { - $("#class_enroll_form").submit(); - }); - - $(document).delegate('#class_enroll_form', 'ajax:success', function(data, json, xhr) { - if(json.success) { - location.href="${reverse('dashboard')}"; - } - }); - })(this) - </script> - %else: - ## If the user is not authenticated, clicking the enroll button pops up the register - ## field. We also slip in the registration fields into the login/register fields so - ## the user is automatically registered after logging in / registering - <script type="text/javascript"> - (function() { - $(".register").click(function() { - if ($("#login_form .enroll_fieldset").length === 0) { - $("#login_form").append( $(".enroll_fieldset").first().clone() ); - } - if ($("#register_form .enroll_fieldset").length === 0) { - $("#register_form").append( $(".enroll_fieldset").first().clone() ); - } - }); - })(this) - </script> - %endif %endif diff --git a/lms/templates/profile.html b/lms/templates/profile.html index c45961fc6de..2d54cddb133 100644 --- a/lms/templates/profile.html +++ b/lms/templates/profile.html @@ -8,7 +8,7 @@ from django.core.urlresolvers import reverse %> -<%block name="headextra"> +<%block name="js_extra"> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.stack.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.symbol.js')}"></script> diff --git a/lms/templates/simplewiki/simplewiki_base.html b/lms/templates/simplewiki/simplewiki_base.html index b70dab9f406..37f6afc75ac 100644 --- a/lms/templates/simplewiki/simplewiki_base.html +++ b/lms/templates/simplewiki/simplewiki_base.html @@ -8,7 +8,7 @@ from simplewiki.views import wiki_reverse %> -<%block name="headextra"> +<%block name="js_extra"> <script type="text/javascript" src="${static.url('js/simplewiki-AutoSuggest_c_2.0.js')}"></script> ## TODO (cpennington): Remove this when we have a good way for modules to specify js to load on the page -- GitLab