-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Changes from 3 commits
1e443da
1cfdba4
09d9b19
c64792c
8f31683
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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'; | ||
} | ||
}); |
This file was deleted.
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); | ||
} | ||
} | ||
}); |
This file was deleted.
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here |
||
} | ||
} | ||
}); |
This file was deleted.
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the correct condition here is |
||
return false; | ||
} | ||
if (Meteor.Device.isPhone() && user() && user.settings && user.settings.preferences && user.settings.preferences.saveMobileBandwidth && this.downloadImages) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the declaration here and remove the parenthesis |
||
} | ||
} | ||
}); |
This file was deleted.
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); | ||
}; |
This file was deleted.
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the declaration here and remove the parenthesis |
||
} | ||
} | ||
}); |
This file was deleted.
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
} | ||
|
||
}); |
This file was deleted.
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
} | ||
}); |
There was a problem hiding this comment.
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