Skip to content

Commit c8035be

Browse files
committed
Merge branch 'issue-5-1awwhg4'
2 parents cc74f7d + 090fd2f commit c8035be

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

src/css/content.css

+6
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ p, ul, ol {
112112
border-radius: 4px;
113113

114114
font-size: 12px;
115+
}
116+
117+
118+
.image-placeholder {
119+
padding: 8px 16px;
120+
background-color: #EEE;
115121
}

src/js/repo.js

+53-13
Original file line numberDiff line numberDiff line change
@@ -1274,29 +1274,69 @@ class Repository {
12741274
if(!this.markedOptions) {
12751275
let issueParser = "<a href=\"/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/issues/view/?" + this.address + "/$1@$2\">#$1@$2</a>";
12761276
let pullRequestParser = "<a href=\"/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/pull-requests/view/?" + this.address + "/$1@$2\">#P$1@$2</a>";
1277+
let allowed_prefixes = ["/gitcenter.bit", "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t"];
1278+
1279+
let self = this;
12771280

12781281
let renderer = new marked.Renderer();
12791282
renderer.image = function(href, title, text) {
12801283
if(href.indexOf("./") == 0) {
12811284
// Relative to current file showing
12821285
href = href.replace("./", "");
12831286
href = root ? root + "/" + href : href;
1284-
if(window.branch) {
1285-
href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" + branch;
1286-
} else {
1287-
href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@";
1288-
}
1289-
} else if(href[0] == "/") {
1287+
} else if(href[0] == "/" && !allowed_prefixes.some(prefix => link.indexOf(prefix) == 0)) {
12901288
// Relative to repository root
12911289
href = href.replace("/", "");
1292-
if(window.branch) {
1293-
href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@" + branch;
1294-
} else {
1295-
href = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@";
1296-
}
1290+
} else {
1291+
return this.__proto__.image.call(this, href, title, text); // super() analog
1292+
}
1293+
1294+
let nodeId = "image_placeholder_" + Math.random().toString(36).substr(2);
1295+
1296+
let node = document.createElement("div");
1297+
node.className = "image-placeholder";
1298+
node.id = nodeId;
1299+
node.textContent = "Loading " + (title || href) + "...";
1300+
1301+
let filename = href.split("/").slice(-1)[0] || "";
1302+
let extension = filename.split(".").slice(-1)[0] || "";
1303+
let type = {
1304+
tif: "image/tiff",
1305+
tiff: "image/tiff",
1306+
gif: "image/gif",
1307+
jpeg: "image/jpeg",
1308+
jpg: "image/jpeg",
1309+
jif: "image/jpeg",
1310+
jiff: "image/jpeg",
1311+
jp2: "image/jpeg",
1312+
jpx: "image/jpeg",
1313+
j2k: "image/jpeg",
1314+
j2c: "image/jpeg",
1315+
png: "image/png",
1316+
svg: "image/svg+xml",
1317+
webp: "image/webp"
1318+
}[extension];
1319+
if(!type) {
1320+
node.textContent = "Could not detect image type of " + (title || href);
1321+
return node.outerHTML;
12971322
}
12981323

1299-
return this.__proto__.image.call(this, href, title, text); // super() analog
1324+
// Load image manually
1325+
self.getFile(branch, href)
1326+
.then(blob => {
1327+
blob = new Blob([blob], {type: type});
1328+
let url = URL.createObjectURL(blob);
1329+
1330+
let node = document.getElementById(nodeId);
1331+
if(node) {
1332+
let img = document.createElement("img");
1333+
img.src = url;
1334+
img.title = title;
1335+
node.parentNode.replaceChild(img, node);
1336+
}
1337+
});
1338+
1339+
return node.outerHTML;
13001340
};
13011341
renderer.text = function(text) {
13021342
return text
@@ -1313,7 +1353,7 @@ class Repository {
13131353
} else {
13141354
link = "/1GitLiXB6t5r8vuU2zC6a8GYj9ME6HMQ4t/repo/file/?" + address + "/" + link + "@";
13151355
}
1316-
} else if(link[0] == "/") {
1356+
} else if(link[0] == "/" && !allowed_prefixes.some(prefix => link.indexOf(prefix) == 0)) {
13171357
// Relative to repository root
13181358
link = link.replace("/", "");
13191359
if(window.branch) {

src/repo/css/comments.css

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
background-color: #FFC;
3535
}
3636

37+
.comment-content img {
38+
max-width: 100%;
39+
}
40+
3741
.comment-textarea {
3842
display: block;
3943
width: calc(100% - 32px);

src/repo/css/files.css

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@
5858
border-radius: 4px;
5959

6060
font-size: 16px;
61+
}
62+
63+
.readme img {
64+
max-width: 100%;
6165
}

0 commit comments

Comments
 (0)