Skip to content

Instantly share code, notes, and snippets.

@sbeckeriv
Created February 22, 2012 08:05
Show Gist options
  • Save sbeckeriv/1883356 to your computer and use it in GitHub Desktop.
Save sbeckeriv/1883356 to your computer and use it in GitHub Desktop.
crow plugin
plugins = []
plugins.push(
description: "Creates an img tag for image urls so you can see the image inline"
text_only: true
match: [[
/http(s)?:\/\/.+/gi,
(captures)->
iframes = ""
for url in captures
try
logger.error(url)
logger.error("<div url='#{url}'>#{url}&nbsp;</div>")
iframes += "<div url='#{url}'>#{url}&nbsp;</div>"
url_callback = (data)->
logger.error(url)
logger.error(data.content)
logger.error $("div[url='#{url}'").text()
$("div[url='#{url}'").html(data.content)
$.getJSON("http://viewtext.org/api/text?url=" + url+ "&callback=?", url_callback)
catch e
logger.error e
logger.info(iframes)
@append_html iframes
]]
)
window.url_text = (url)->
url_callback = (data) ->
return $("div[url='" + url + "'").html(data.content)
$.getJSON("http://viewtext.org/api/text?url=" + url + "&callback=?", url_callback)
# plugin list
plugins = []
plugins.push(
description: "Creates an img tag for image urls so you can see the image inline"
text_only: true
match: [[
/http(s)?:\/\/.+/gi,
(captures)->
iframes = ""
for url in captures
try
iframes +="<div url='#{url}'>#{url}&nbsp;</div>"+'<'+'script>window.url_text("'+url+'")<'+'/script>'
catch e
logger.error e
logger.info(iframes)
@append_html iframes
]]
)
window.remove_url_text = (url)->
el = $("div[url='#{url}']")
el.html("")
window.url_text = (url)->
url_callback = (data) ->
el = $("div[url='#{url}']")
el.html("#{url}<br/><input type='button' onclick='window.remove_url_text(\"#{url}\")' value='Remove Text'>"+data.content+"<input type='button' onclick='window.remove_url_text(\"#{url}\")' value='Remove Text'>")
logger.error("url text url")
logger.error("http://viewtext.org/api/text?mld=.1&rl=false&url=" + url + "&callback=?")
$.getJSON("http://viewtext.org/api/text?mld=.1&rl=false&url=" + url + "&callback=?", url_callback)
# plugin list
plugins = []
plugins.push(
description: "Get url text"
text_only: true
match: [[
/http(s)?:\/\/.+/gi,
(captures)->
counter = 0
iframes = ""
for url in captures
try
iframes +="<div url='#{url}'>Loading Text for: #{url} &nbsp;<"+"script> window.url_text(\"#{url}\")</"+"script></div>"
counter+=1
catch e
logger.error e
logger.info(iframes)
@append_html iframes
]]
)
window.url_text = (url,el)->
url_callback = (data) ->
return el.html(data.content)
$.getJSON("http://viewtext.org/api/text?url=" + url + "&callback=?", url_callback)
# plugin list
plugins = []
plugins.push(
description: "Creates an img tag for image urls so you can see the image inline"
text_only: true
match: [[
/http(s)?:\/\/.+/gi,
(captures)->
iframes = ""
for url in captures
try
iframes +="<div url='#{url}'>#{url}&nbsp;</div>"+'<'+'script>window.url_text(\''+url+'\',$("div[url=\''+url + '\']"))<'+'/script>'
catch e
logger.error e
logger.info(iframes)
@append_html iframes
]]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment