mirror of https://github.com/status-im/codimd.git
fix: vimeo won't show up due to the jsonp callback data unable be parsed with jQuery
Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
parent
dd16949222
commit
47bab4266b
|
@ -260,6 +260,23 @@ if (typeof window.mermaid !== 'undefined' && window.mermaid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jsonp(url, callback) {
|
||||||
|
const callbackName = 'jsonp_callback_' + Math.round(1000000000 * Math.random())
|
||||||
|
window[callbackName] = function (data) {
|
||||||
|
delete window[callbackName]
|
||||||
|
document.body.removeChild(script)
|
||||||
|
callback(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = document.createElement('script')
|
||||||
|
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName
|
||||||
|
document.body.appendChild(script)
|
||||||
|
script.onerror = function (e) {
|
||||||
|
console.error(e)
|
||||||
|
script.remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// dynamic event or object binding here
|
// dynamic event or object binding here
|
||||||
export function finishView (view) {
|
export function finishView (view) {
|
||||||
// todo list
|
// todo list
|
||||||
|
@ -304,17 +321,11 @@ export function finishView (view) {
|
||||||
imgPlayiframe(this, '//player.vimeo.com/video/')
|
imgPlayiframe(this, '//player.vimeo.com/video/')
|
||||||
})
|
})
|
||||||
.each((key, value) => {
|
.each((key, value) => {
|
||||||
$.ajax({
|
jsonp(`//vimeo.com/api/v2/video/${$(value).attr('data-videoid')}.json`, function (data) {
|
||||||
type: 'GET',
|
|
||||||
url: `//vimeo.com/api/v2/video/${$(value).attr('data-videoid')}.json`,
|
|
||||||
jsonp: 'callback',
|
|
||||||
dataType: 'jsonp',
|
|
||||||
success (data) {
|
|
||||||
const thumbnailSrc = data[0].thumbnail_large
|
const thumbnailSrc = data[0].thumbnail_large
|
||||||
const image = `<img src="${thumbnailSrc}" />`
|
const image = `<img src="${thumbnailSrc}" />`
|
||||||
$(value).prepend(image)
|
$(value).prepend(image)
|
||||||
if (window.viewAjaxCallback) window.viewAjaxCallback()
|
if (window.viewAjaxCallback) window.viewAjaxCallback()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// gist
|
// gist
|
||||||
|
|
Loading…
Reference in New Issue