forked from thelounge/thelounge
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request thelounge#1276 from thelounge/xpaw/refactor-toggle
Refactor link previews
- Loading branch information
Showing
16 changed files
with
250 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
|
||
const $ = require("jquery"); | ||
const socket = require("../socket"); | ||
const templates = require("../../views"); | ||
const options = require("../options"); | ||
|
||
socket.on("msg:preview", function(data) { | ||
data.preview.shown = options.shouldOpenMessagePreview(data.preview.type); | ||
|
||
const msg = $("#msg-" + data.id); | ||
const container = msg.parent(".messages"); | ||
const bottom = container.isScrollBottom(); | ||
|
||
msg.find(".text").append(templates.msg_preview({preview: data.preview})); | ||
|
||
if (data.preview.shown && bottom) { | ||
handleImageInPreview(msg.find(".toggle-content"), container); | ||
} | ||
|
||
container.trigger("keepToBottom"); | ||
}); | ||
|
||
$("#chat").on("click", ".toggle-button", function() { | ||
const self = $(this); | ||
const container = self.closest(".messages"); | ||
const content = self.parent().next(".toggle-content"); | ||
const bottom = container.isScrollBottom(); | ||
|
||
if (bottom && !content.hasClass("show")) { | ||
handleImageInPreview(content, container); | ||
} | ||
|
||
content.toggleClass("show"); | ||
|
||
// If scrollbar was at the bottom before toggling the preview, keep it at the bottom | ||
if (bottom) { | ||
container.scrollBottom(); | ||
} | ||
}); | ||
|
||
function handleImageInPreview(content, container) { | ||
const img = content.find("img"); | ||
|
||
// Trigger scroll logic after the image loads | ||
if (img.length && !img.width()) { | ||
img.on("load", function() { | ||
container.trigger("keepToBottom"); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{#preview}} | ||
<div> | ||
<button class="toggle-button" aria-label="Toggle prefetched media"></button> | ||
</div> | ||
<a href="{{link}}" target="_blank" rel="noopener" class="toggle-content toggle-type-{{type}}{{#if shown}} show{{/if}}"> | ||
{{#equal type "image"}} | ||
<img src="{{link}}"> | ||
{{else}} | ||
{{#if thumb}} | ||
<img src="{{thumb}}" class="thumb"> | ||
{{/if}} | ||
<div class="head">{{head}}</div> | ||
<div class="body"> | ||
{{body}} | ||
</div> | ||
{{/equal}} | ||
</a> | ||
{{/preview}} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.