{#  -*- coding: utf-8 -*- #}
{% macro comment_form(url, title, identifier) %}
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '{{ comment_system_id }}',
      status     : true,
      xfbml      : true
    });

  };

  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

<div class="fb-comments" data-href="{{ url }}" data-width="470"></div>
{% endmacro %}

{% macro comment_link(link, identifier) %}
<span class="fb-comments-count" data-url="{{ link }}">
{% endmacro %}

{% macro comment_link_script() %}
<div id="fb-root"></div>
<script>
    // thank lxml for this
    $('.fb-comments-count').each(function(i, obj) {
        var url = obj.attributes['data-url'].value;
        // change here if you dislike the default way of displaying
        // this
        obj.innerHTML = '<fb:comments-count href="' + url + '"></fb:comments-count> comments';
    });

  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '{{ comment_system_id }}',
      status     : true,
      xfbml      : true
    });

  };

  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>
{% endmacro %}
