Mercurial > zeropaste
view app/assets/javascripts/init.tabs.js @ 115:546381cf83c2
auto sounds better than full.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 13:35:11 +0700 |
parents | b72f99d7b8cf |
children | 9ac24e112ea7 |
line wrap: on
line source
$(document).ready(function() { if ($('#paste-tabs').length == 1) { raw = $('#plain pre').text(); $('#highlight pre').text(raw); window.prettyPrint && prettyPrint(); $('#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 == 'auto')) { qstring = '?'; } history.replaceState(null, '', qstring); }; paste_resize = function(size) { var paste = $('#paste'), title = $('#tab-resize a.btn'); title.html(title.html().replace(/(auto|\d+px)/, size)); if (size == 'auto') { paste.css('width', ''); 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').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]); } } });