changeset 114:b72f99d7b8cf

Dynamic url based on options selected. Yes, I'm having too much fun.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 13:31:18 +0700
parents c24b17044ad1
children 546381cf83c2
files app/assets/javascripts/init.tabs.js app/views/pastes/show.html.erb
diffstat 2 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/app/assets/javascripts/init.tabs.js	Mon Nov 12 13:08:22 2012 +0700
+++ b/app/assets/javascripts/init.tabs.js	Mon Nov 12 13:31:18 2012 +0700
@@ -7,26 +7,43 @@
 
     $('#markdown div').html(marked(raw));
 
+    update_state = function() {
+      var paste = $('#paste'),
+        mode = paste.data('mode'),
+        width = paste.data('width'),
+        qstring = '?' + mode + '.' + width;
+      if ((mode == 'plain') && (width == 'full')) {
+        qstring = '?';
+      }
+      history.replaceState(null, '', qstring);
+    };
+
     paste_resize = function(size) {
       var paste = $('#paste'),
         title = $('#tab-resize a.btn');
       title.html(title.html().replace(/(full|\d+px)/, size));
       if (size == 'full') {
         paste.css('width', '');
-        paste.data('width', '0');
+        paste.data('width', size);
       } else {
         paste.css('width', size);
         paste.data('width', size);
       }
+      update_state();
     }
 
+    $('#paste-tabs > li > a').click(function() {
+      $('#paste').data('mode', $(this).prop('href').split('#')[1]);
+      update_state();
+    });
     $('#tab-resize ul a').click(function() {
       paste_resize($(this).data('size'));
     });
 
     mode = window.location.search.substr(1).split('.');
-    if (mode[0] == 'highlight') { $('#paste-tabs li:eq(1) a').tab('show'); }
-    else if (mode[0] == 'markdown') { $('#paste-tabs li:eq(2) a').tab('show'); }
+    if (mode[0] == 'highlight') { $('#paste-tabs li:eq(1) a').click(); }
+    else if (mode[0] == 'markdown') { $('#paste-tabs li:eq(2) a').click(); }
     if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
+
   }
 });
--- a/app/views/pastes/show.html.erb	Mon Nov 12 13:08:22 2012 +0700
+++ b/app/views/pastes/show.html.erb	Mon Nov 12 13:31:18 2012 +0700
@@ -24,7 +24,7 @@
       </div>
     </li>
   </ul>
-  <div id="paste" data-width="0" class="tab-content">
+  <div id="paste" data-mode="plain" data-width="full" class="tab-content">
     <div class="tab-pane active" id="plain">
       <pre><%= @paste.paste %></pre>
     </div>