The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/oembed/client/oembedUrlWidget.js

60 lines
1.6 KiB

import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import _ from 'underscore';
import s from 'underscore.string';
const getTitle = function(self) {
if (self.meta == null) {
return;
}
return self.meta.ogTitle || self.meta.twitterTitle || self.meta.title || self.meta.pageTitle;
};
const getDescription = function(self) {
if (self.meta == null) {
return;
}
const description = self.meta.ogDescription || self.meta.twitterDescription || self.meta.description;
if (description == null) {
return;
}
return s.unescapeHTML(description.replace(/(^[“\s]*)|([”\s]*$)/g, ''));
};
Template.oembedUrlWidget.helpers({
description() {
const description = getDescription(this);
if (_.isString(description)) {
return description;
}
},
title() {
const title = getTitle(this);
if (_.isString(title)) {
return Blaze._escape(title);
}
},
target() {
if (!(this.parsedUrl && this.parsedUrl.host) || !(document && document.location && document.location.host) || (this.parsedUrl && this.parsedUrl.host !== document.location.host)) {
return '_blank';
}
},
image() {
if (this.meta == null) {
return;
}
let decodedOgImage;
if (this.meta.ogImage && this.meta.ogImage.replace) {
decodedOgImage = this.meta.ogImage.replace(/&/g, '&');
}
let url = decodedOgImage || this.meta.twitterImage || this.meta.msapplicationTileImage;
if (url == null) {
return;
}
url = new URL(url, `${ this.parsedUrl.protocol }//${ this.parsedUrl.host }`).href;
return url;
},
show() {
return (getDescription(this) != null) || (getTitle(this) != null);
},
});