From c797de93e6d22408301bf1eceed9f9fd5d6e26fa Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 31 May 2013 10:46:26 -0400 Subject: [PATCH] download instruction buttons now work via ajax too --- frontend/templates/base.html | 2 +- static/css/enhanced_download.css | 1 + static/css/enhanced_download_ie.css | 1 + static/js/download_page.js | 37 +++++++++++++------------ static/js/{sitewide.js => sitewide1.js} | 2 +- static/less/enhanced_download.less | 7 +++++ static/less/enhanced_download_ie.less | 12 ++++++++ 7 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 static/css/enhanced_download.css create mode 100644 static/css/enhanced_download_ie.css rename static/js/{sitewide.js => sitewide1.js} (97%) create mode 100644 static/less/enhanced_download.less create mode 100644 static/less/enhanced_download_ie.less diff --git a/frontend/templates/base.html b/frontend/templates/base.html index bc328d18..a9c37434 100644 --- a/frontend/templates/base.html +++ b/frontend/templates/base.html @@ -23,7 +23,7 @@ {% block extra_css %}{% endblock %} - + {% block extra_js %} diff --git a/static/css/enhanced_download.css b/static/css/enhanced_download.css new file mode 100644 index 00000000..dc59aed4 --- /dev/null +++ b/static/css/enhanced_download.css @@ -0,0 +1 @@ +.buttons{display:inherit}.instructions div:not(#trythis_div),.instructions h4{display:none} \ No newline at end of file diff --git a/static/css/enhanced_download_ie.css b/static/css/enhanced_download_ie.css new file mode 100644 index 00000000..35807629 --- /dev/null +++ b/static/css/enhanced_download_ie.css @@ -0,0 +1 @@ +.buttons{display:inherit}.instructions div,.instructions h4{display:none}#trythis_div{display:inherit} \ No newline at end of file diff --git a/static/js/download_page.js b/static/js/download_page.js index 87170ff7..0adc910b 100644 --- a/static/js/download_page.js +++ b/static/js/download_page.js @@ -1,21 +1,22 @@ var $j = jQuery.noConflict(); -$j(document).on('prettifyDownload', function(){ - $j('.buttons').show(); - $j('.instructions div:not(#trythis_div)').hide(); - $j('.instructions h4').hide(); - - $j('.buttons div').on('click', function() { - $j(this).removeClass('modify'); - $j(this).siblings().addClass('modify'); - var buttonID = $j(this).children('a').attr('id'); - var divSelector = '#' + buttonID + '_div'; - var activeDiv = $j(divSelector); - activeDiv.show(); - activeDiv.siblings().hide(); - }); -}); +// must load CSS rather than show/hide jQuery objects; can't trigger an event +// on an element not present on pageload, so binding it via on is useless +if (document.createStyleSheet) { + // make it work in IE <= 8 + document.createStyleSheet('/static/css/enhanced_download_ie.css'); +} +else { + $j('').appendTo('head'); +} -// needs to work both when people go straight to /download and when they get there via hijax link -// ergo can't fire on document ready; needs custom trigger -$j(document).trigger('prettifyDownload'); +// browser has a better sense of DOM changes than jQuery, so user can trigger click element +$j(document).on('click', '.buttons div', function() { + $j(this).removeClass('modify'); + $j(this).siblings().addClass('modify'); + var buttonID = $j(this).children('a').attr('id'); + var divSelector = '#' + buttonID + '_div'; + var activeDiv = $j(divSelector); + activeDiv.show(); + activeDiv.siblings().hide(); +}); \ No newline at end of file diff --git a/static/js/sitewide.js b/static/js/sitewide1.js similarity index 97% rename from static/js/sitewide.js rename to static/js/sitewide1.js index 5137581d..2a1acf2c 100644 --- a/static/js/sitewide.js +++ b/static/js/sitewide1.js @@ -23,7 +23,7 @@ $j(document).ready(function() { if ($j(this).attr("href").indexOf("download") !== -1) { jQuery.getScript('/static/js/download_page.js'); - jQuery.getScript('https://platform.readmill.com/send.js'); + jQuery.getScript('https://platform.readmill.com/send.js'); } //need to push next cookie for sign-in links diff --git a/static/less/enhanced_download.less b/static/less/enhanced_download.less new file mode 100644 index 00000000..99dad3f5 --- /dev/null +++ b/static/less/enhanced_download.less @@ -0,0 +1,7 @@ +.buttons { + display: inherit; +} + +.instructions div:not(#trythis_div), .instructions h4 { + display: none; +} \ No newline at end of file diff --git a/static/less/enhanced_download_ie.less b/static/less/enhanced_download_ie.less new file mode 100644 index 00000000..c48030a6 --- /dev/null +++ b/static/less/enhanced_download_ie.less @@ -0,0 +1,12 @@ +.buttons { + display: inherit; +} + +.instructions div, .instructions h4 { + display: none; +} + +/* the not selector doesn't work in IE <= 8 */ +#trythis_div { + display: inherit; +} \ No newline at end of file