# HG changeset patch # User Edho Arief # Date 1352701878 -25200 # Node ID b72f99d7b8cf50af7defe5b87d6aa247045d5b48 # Parent c24b17044ad177457d1024e56e764d08c3924e40 Dynamic url based on options selected. Yes, I'm having too much fun. diff -r c24b17044ad1 -r b72f99d7b8cf app/assets/javascripts/init.tabs.js --- 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]); } + } }); diff -r c24b17044ad1 -r b72f99d7b8cf app/views/pastes/show.html.erb --- 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 @@ -
+
<%= @paste.paste %>