Add function cover preview.

This commit is contained in:
noface 2016-11-27 00:22:34 +01:00
parent 0094826c51
commit 03bafe98b0
2 changed files with 26 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Embedding = Embedding =
init: -> init: ->
return unless Conf['Embedding'] or Conf['Link Title'] return unless Conf['Embedding'] or Conf['Link Title'] or Conf['Cover Preview']
@types = {} @types = {}
@types[type.key] = type for type in @ordered_types @types[type.key] = type for type in @ordered_types
@ -31,12 +31,13 @@ Embedding =
return return
process: (link, post) -> process: (link, post) ->
return unless Conf['Embedding'] or Conf['Link Title'] return unless Conf['Embedding'] or Conf['Link Title'] or Conf['Cover Preview']
return if $.x 'ancestor::pre', link return if $.x 'ancestor::pre', link
if data = Embedding.services link if data = Embedding.services link
data.post = post data.post = post
Embedding.embed data if Conf['Embedding'] Embedding.embed data if Conf['Embedding']
Embedding.title data if Conf['Link Title'] Embedding.title data if Conf['Link Title']
Embedding.preview data if Conf['Cover Preview']
services: (link) -> services: (link) ->
{href} = link {href} = link
@ -119,6 +120,22 @@ Embedding =
$.extend data.link, <%= html('[${data.key}] <span class="warning">Title Link Blocked</span> (are you using NoScript?)</a>') %> $.extend data.link, <%= html('[${data.key}] <span class="warning">Title Link Blocked</span> (are you using NoScript?)</a>') %>
return return
preview: (data) ->
{key, uid, link} = data
service = Embedding.types[key].preview
$.on link, 'mouseover', (e) ->
src = service.call uid
el = $.el 'img',
src: src
id: 'ihover'
$.add d.body, el
UI.hover
root: link
el: el
latestEvent: e
endEvents: 'mouseout click'
asapTest: -> el.height
cb: cb:
click: (e) -> click: (e) ->
e.preventDefault() e.preventDefault()
@ -418,4 +435,6 @@ Embedding =
for item in data.items when item.id is uid for item in data.items when item.id is uid
return item.snippet.title return item.snippet.title
'Not Found' 'Not Found'
preview: ->
"https://img.youtube.com/vi/#{@}/0.jpg"
] ]

View File

@ -136,6 +136,11 @@ Config =
'Replace the link of a supported site with its actual title.' 'Replace the link of a supported site with its actual title.'
1 1
] ]
'Cover Preview': [
true
'Show preview of links on hover.'
1
]
'Embedding': [ 'Embedding': [
true true
'Embed supported services. Note: Some services don\'t work on HTTPS.' 'Embed supported services. Note: Some services don\'t work on HTTPS.'