view app/assets/javascripts/init.tabs.js @ 112:2b1041e8c35e

Allows parameter-based width passing. Requires switching to .search.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 13:01:31 +0700
parents a92e732a2caa
children b72f99d7b8cf
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));

    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');
      } else {
        paste.css('width', size);
        paste.data('width', size);
      }
    }

    $('#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[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
  }
});