SHARE
TWEET

Bitbucket #6315 work-around

skrymir01 Aug 1st, 2014 374 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fixImages () {
  2.  
  3.   $('#readme img').each(function () {
  4.     var $this = $(this);
  5.     var src = $this.attr('src');
  6.     var url = document.URL;
  7.     var branch = document.URL.match(/\?at=(.*)/i);
  8.  
  9.     // Ignore images that have absolute paths
  10.     if (src.indexOf('http') > -1) {
  11.       return false;
  12.     }
  13.    
  14.     if (branch === null) {
  15.  
  16.       // Remove "overview" and trailing slashes
  17.       url = url
  18.         .replace(/\/overview.*/, '')
  19.         .replace(/\/src.*/, '')
  20.         .replace(/\/$/, '');
  21.       src = url + '/raw/master/' + src;
  22.  
  23.     } else {
  24.  
  25.       // Remove trailing URL
  26.       url = url.replace(/\/src\/.*/i, '');
  27.       src = url + '/raw/' + branch[1] + '/' + src;
  28.     }
  29.    
  30.     $this.attr('src', src);
  31.   });
  32.  
  33. }
  34.  
  35. fixImages();
  36.  
  37. // Handle changing branch
  38. $(document).on('click', '.pjax-trigger', function () {
  39.   setTimeout(fixImages, 3000);
  40. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top