aboutsummaryrefslogtreecommitdiffstats
path: root/guides/assets/javascripts
diff options
context:
space:
mode:
authorJoe Fiorini <joe@joefiorini.com>2012-04-05 00:53:10 -0400
committerJoe Fiorini <joe@joefiorini.com>2012-10-06 16:40:51 -0400
commit65a2977cdd55678d3eab06434625375914511786 (patch)
treeab2dbb879196f0879af1d4bce06480975492ff6e /guides/assets/javascripts
parent03bcd416b04c411973456e33a95756edab4244cd (diff)
downloadrails-65a2977cdd55678d3eab06434625375914511786.tar.gz
rails-65a2977cdd55678d3eab06434625375914511786.tar.bz2
rails-65a2977cdd55678d3eab06434625375914511786.zip
[Guides] Format content for small devices
Diffstat (limited to 'guides/assets/javascripts')
-rwxr-xr-xguides/assets/javascripts/responsive-tables.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/guides/assets/javascripts/responsive-tables.js b/guides/assets/javascripts/responsive-tables.js
new file mode 100755
index 0000000000..8554a1343b
--- /dev/null
+++ b/guides/assets/javascripts/responsive-tables.js
@@ -0,0 +1,43 @@
+$(document).ready(function() {
+ var switched = false;
+ $("table").not(".syntaxhighlighter").addClass("responsive");
+ var updateTables = function() {
+ if (($(window).width() < 767) && !switched ){
+ switched = true;
+ $("table.responsive").each(function(i, element) {
+ splitTable($(element));
+ });
+ return true;
+ }
+ else if (switched && ($(window).width() > 767)) {
+ switched = false;
+ $("table.responsive").each(function(i, element) {
+ unsplitTable($(element));
+ });
+ }
+ };
+
+ $(window).load(updateTables);
+ $(window).bind("resize", updateTables);
+
+
+ function splitTable(original)
+ {
+ original.wrap("<div class='table-wrapper' />");
+
+ var copy = original.clone();
+ copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none");
+ copy.removeClass("responsive");
+
+ original.closest(".table-wrapper").append(copy);
+ copy.wrap("<div class='pinned' />");
+ original.wrap("<div class='scrollable' />");
+ }
+
+ function unsplitTable(original) {
+ original.closest(".table-wrapper").find(".pinned").remove();
+ original.unwrap();
+ original.unwrap();
+ }
+
+});