<commit_before>require 'shortcodes/handler'

module Shortcodes
  class QuienManda < Handler

    def url
      shortcode.attributes.fetch('url')
    end

    def width
      attributes.fetch('width', 500)
    end

    def render
      # See http://stackoverflow.com/a/15558627
      template = <<TEMPLATE
<div class="quienmanda-embed-wrapper">
<script>
  // Create IE + others compatible event handler
  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var eventer = window[eventMethod];
  var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

  // Listen to message from child window
  eventer(messageEvent, function(event) {
    if ('#{url}'.indexOf(event.origin) == 0) {
      document.getElementById('quienmanda-embed').height = event.data + 'px';
    }
  },false);
</script>
<iframe class="quienmanda-embed" id="quienmanda-embed" frameborder="0" width="#{width}"
  style="display: block; border-style: solid; border-color: #FAFAFA; border-radius: 4px 4px 4px 4px; border-right: 1px solid #FAFAFA; border-width: 2px 1px 1px; margin: 10px auto; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 1px rgba(0, 0, 0, 0.05);"
  height="0" scrolling="no" src="#{url}?widget=1">
</iframe><commit_msg>Allow multiple photo embeds in the same post. Fixes #150<commit_after>require 'shortcodes/handler'

module Shortcodes
  class QuienManda < Handler

    def url
      shortcode.attributes.fetch('url')
    end

    def width
      attributes.fetch('width', 500)
    end

    def render
      # Get photo id to uniquely identify each embed
      url =~ /photos\/(\d+)/
      photo_id = $1

      # See http://stackoverflow.com/a/15558627
      template = <<TEMPLATE
<div class="quienmanda-embed-wrapper">
<script>
  // Create IE + others compatible event handler
  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var eventer = window[eventMethod];
  var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

  // Listen to message from child window
  eventer(messageEvent, function(event) {
    if ('#{url}'.indexOf(event.origin) == 0) {
      document.getElementById("quienmanda-embed-#{photo_id}").height = event.data + 'px';
    }
  },false);
</script>
<iframe class="quienmanda-embed" id="quienmanda-embed-#{photo_id}" frameborder="0" width="#{width}"
  style="display: block; border-style: solid; border-color: #FAFAFA; border-radius: 4px 4px 4px 4px; border-right: 1px solid #FAFAFA; border-width: 2px 1px 1px; margin: 10px auto; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 2px 1px rgba(0, 0, 0, 0.1), 0 3px 1px rgba(0, 0, 0, 0.05);"
  height="0" scrolling="no" src="#{url}?widget=1">
</iframe>
{'fraction_non_alphanumeric': 0.14835164835164835, 'fraction_numerical': 0.03882783882783883, 'mean_word_length': 3.9296028880866425, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5689269', 'n_tokens_mistral': 1008, 'n_tokens_neox': 900, 'n_words': 248}