Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Oembed Package to Js #6688

Merged
merged 5 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions packages/rocketchat-oembed/client/baseWidget.coffee

This file was deleted.

28 changes: 28 additions & 0 deletions packages/rocketchat-oembed/client/baseWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Template.oembedBaseWidget.helpers({
template() {
let contentType;
if (this.headers) {
contentType = this.headers.contentType;
}

if (this._overrideTemplate) {
return this._overrideTemplate;
}
if (this.headers && contentType && contentType.match(/image\/.*/)) {
return 'oembedImageWidget';
}
if (this.headers && contentType && contentType.match(/audio\/.*/)) {
return 'oembedAudioWidget';
}
if ((this.headers && contentType && contentType.match(/video\/.*/)) || (this.meta && this.meta.twitterPlayerStreamContentType && this.meta.twitterPlayerStreamContentType.match(/video\/.*/))) {
return 'oembedVideoWidget';
}
if (this.meta && this.meta.oembedHtml) {
return 'oembedFrameWidget';
}
if (this.meta && this.meta.sandstorm && this.meta.sandstorm.grain) {
return 'oembedSandstormGrain';
}
return 'oembedUrlWidget';
}
});
7 changes: 0 additions & 7 deletions packages/rocketchat-oembed/client/oembedAudioWidget.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions packages/rocketchat-oembed/client/oembedAudioWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Template.oembedAudioWidget.helpers({
collapsed() {
const user = Meteor.user();
if (this.collapsed) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move the variable declaration here. And there is no need for the parenthesis

}
}
});
7 changes: 0 additions & 7 deletions packages/rocketchat-oembed/client/oembedFrameWidget.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions packages/rocketchat-oembed/client/oembedFrameWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Template.oembedFrameWidget.helpers({
collapsed() {
const user = Meteor.user();
if (this.collapsed) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault) === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

}
}
});
17 changes: 0 additions & 17 deletions packages/rocketchat-oembed/client/oembedImageWidget.coffee

This file was deleted.

22 changes: 22 additions & 0 deletions packages/rocketchat-oembed/client/oembedImageWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Template.oembedImageWidget.helpers({
loadImage() {
const user = Meteor.user();

if (user && user.settings && user.settings.preferences && user.settings.preferences.autoImageLoad === false && this.downloadImages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the correct condition here is this.downloadImages == null

return false;
}
if (Meteor.Device.isPhone() && user() && user.settings && user.settings.preferences && user.settings.preferences.saveMobileBandwidth && this.downloadImages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User is not a function here, you already called the function to get the data. The correct condition for downloadImage is this.downloadImages == null

return false;
}
return true;
},
collapsed() {
const user = Meteor.user();

if (this.collapsed != null) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault) === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the declaration here and remove the parenthesis

}
}
});
17 changes: 0 additions & 17 deletions packages/rocketchat-oembed/client/oembedSandstormGrain.coffee

This file was deleted.

25 changes: 25 additions & 0 deletions packages/rocketchat-oembed/client/oembedSandstormGrain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Template.oembedSandstormGrain.helpers({
token() {
return this.meta.sandstorm.grain.token;
},
appTitle() {
return this.meta.sandstorm.grain.appTitle.defaultText;
},
grainTitle() {
return this.meta.sandstorm.grain.grainTitle;
},
appIconUrl() {
return this.meta.sandstorm.grain.appIconUrl;
},
descriptor() {
return this.meta.sandstorm.grain.descriptor;
}
});

window.sandstormOembed = function(e) {
e = e || window.event;
const src = e.target || e.srcElement;
const token = src.getAttribute('data-token');
const descriptor = src.getAttribute('data-descriptor');
return Meteor.call('sandstormOffer', token, descriptor);
};
57 changes: 0 additions & 57 deletions packages/rocketchat-oembed/client/oembedUrlWidget.coffee

This file was deleted.

67 changes: 67 additions & 0 deletions packages/rocketchat-oembed/client/oembedUrlWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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 _.unescape(description.replace(/(^[“\s]*)|([”\s]*$)/g, ''));
};

Template.oembedUrlWidget.helpers({
description() {
const description = getDescription(this);
if (_.isString(description)) {
return Blaze._escape(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 = this.meta.msapplicationTileImage || decodedOgImage || this.meta.twitterImage;
if (url == null) {
return;
}
if (url.indexOf('//') === 0) {
url = `${ this.parsedUrl.protocol }${ url }`;
} else if (url.indexOf('/') === 0 && (this.parsedUrl && this.parsedUrl.host)) {
url = `${ this.parsedUrl.protocol }//${ this.parsedUrl.host }${ url }`;
}
return url;
},
show() {
return (getDescription(this) != null) || (getTitle(this) != null);
},
collapsed() {
const user = Meteor.user();
if (this.collapsed != null) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault) === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the declaration here and remove the parenthesis

}
}
});
22 changes: 0 additions & 22 deletions packages/rocketchat-oembed/client/oembedVideoWidget.coffee

This file was deleted.

35 changes: 35 additions & 0 deletions packages/rocketchat-oembed/client/oembedVideoWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const getTitle = function(self) {
if (self.meta == null) {
return;
}
return self.meta.ogTitle || self.meta.twitterTitle || self.meta.title || self.meta.pageTitle;
};

Template.oembedVideoWidget.helpers({
url() {
if (this.meta && this.meta.twitterPlayerStream) {
return this.meta.twitterPlayerStream;
} else if (this.url) {
return this.url;
}
},
contentType() {
if (this.meta && this.meta.twitterPlayerStreamContentType) {
return this.meta.twitterPlayerStreamContentType;
} else if (this.headers && this.headers.contentType) {
return this.headers.contentType;
}
},
title() {
return getTitle(this);
},
collapsed() {
const user = Meteor.user();
if (this.collapsed) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault) === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
}

});
7 changes: 0 additions & 7 deletions packages/rocketchat-oembed/client/oembedYoutubeWidget.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions packages/rocketchat-oembed/client/oembedYoutubeWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Template.oembedYoutubeWidget.helpers({
collapsed() {
const user = Meteor.user();
if (this.collapsed) {
return this.collapsed;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences.collapseMediaByDefault) === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
}
});
Loading