Skip to content

Instantly share code, notes, and snippets.

@jarosan
Created June 17, 2014 12:14
Show Gist options
  • Save jarosan/5b5eba5f1719252d9ae3 to your computer and use it in GitHub Desktop.
Save jarosan/5b5eba5f1719252d9ae3 to your computer and use it in GitHub Desktop.
initArticleImages: ->
@element.find(".article__body img").each ->
self = $(@)
if alt = self.attr("alt")
wrapper_div = $('<div></div>').addClass(self.attr("class"))
self.attr("class", "")
wrapper_div.appendTo(self.parent("p"))
self.detach().appendTo(wrapper_div)
$("<span class='article__body__image-subtitle'></span>").text(alt).appendTo(wrapper_div)
@egze
Copy link

egze commented Jun 17, 2014

как-то так наверное

@element.find(".article__body img").each ->
  $img = $(@)
  if alt = $img.attr("alt")
    $img.wrap("<div class='#{$img.attr('class')}' />").removeClass()
    $img.after("<span class='article__body__image-subtitle'>#{alt}</span>")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment