Blogger now support embedded youtube video

This commit is contained in:
Xuan Sang LE 2018-03-05 14:58:20 +01:00
parent 98d57e0bd3
commit 88a78c7eef

View File

@ -311,14 +311,40 @@ class Blogger extends this.OS.GUI.BaseApplication
ctimestr: if sel then sel.ctimestr else d.toString() ctimestr: if sel then sel.ctimestr else d.toString()
utime: d.timestamp() utime: d.timestamp()
utimestr: d.toString() utimestr: d.toString()
rendered: me.editor.options.previewRender(content).asBase64() rendered: me.process(me.editor.options.previewRender(content))
publish: if ((@find "blog-publish").get "swon") then 1 else 0 publish: if ((@find "blog-publish").get "swon") then 1 else 0
data.id = sel.id if sel data.id = sel.id if sel
#save the data #save the data
@blogdb.save data, (r) -> @blogdb.save data, (r) ->
return me.error "Cannot save blog: #{r.error}" if r.error return me.error "Cannot save blog: #{r.error}" if r.error
me.loadBlogs() me.loadBlogs()
process: (text) ->
# find video tag and rendered it
embed = (id) ->
return """
<iframe
class = "embeded-video"
width="560" height="315"
src="https://www.youtube.com/embed/#{id}"
frameborder="0" allow="encrypted-media" allowfullscreen
></iframe>
"""
re = /\[\[([^:]*):([^\]]*)\]\]/g
replace = []
while (found = re.exec text) isnt null
replace.push found
return text.asBase64() unless replace.length > 0
ret = ""
begin = 0
for it in replace
ret += text.substring begin, it.index
ret += embed(it[2])
begin = it.index + it[0].length
ret += text.substring begin, text.length
#console.log ret
return ret.asBase64()
clearEditor:() -> clearEditor:() ->
@.editor.value "" @.editor.value ""
@.inputtags.value = "" @.inputtags.value = ""