Skip to content

Commit

Permalink
Merge pull request #173 from fedwiki/ward/ipfs
Browse files Browse the repository at this point in the history
ipfs for image assets
  • Loading branch information
paul90 authored Sep 28, 2016
2 parents aa0f25c + adb111a commit 42eaa73
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ dialog = require './dialog'
editor = require './editor'
resolve = require './resolve'

ipfs = false
gateway = "http://localhost:8080"
$.ajax "#{gateway}/ipfs/Qmb1oS3TaS8vekxXqogoYsixe47sXcVxQ22kPWH8VSd7yQ",
timeout: 30000
success: (data) -> ipfs = data == "wiki\n"
complete: (xhr, status) -> console.log "ipfs gateway #{status}"

emit = ($item, item) ->
item.text ||= item.caption
$item.append "<img class=thumbnail src=\"#{item.url}\"> <p>#{resolve.resolveLinks(item.text)}</p>"

bind = ($item, item) ->
$item.dblclick -> editor.textEditor $item, item
$item.find('img').dblclick -> dialog.open item.text, this
$item.dblclick ->
editor.textEditor $item, item

$item.find('img').dblclick (event) ->
event.stopPropagation()
url = if ipfs and item.ipfs?
"#{gateway}/ipfs/#{item.ipfs}"
else
item.url
dialog.open item.text, """<img style="width:100%" src="#{url}">"""

module.exports = {emit, bind}

0 comments on commit 42eaa73

Please sign in to comment.