templates/homepage/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Homepage{% endblock %}
  3. {% block stylesheets %}
  4.     {{ parent() }}
  5.     <style>
  6.         #fb-root {
  7.             text-align: center;
  8.         }
  9.         .fb-form-wrapper {
  10.             display: none;
  11.         }
  12.     </style>
  13. {% endblock %}
  14. {% block body %}
  15.     <div class="login-wrapper">
  16.         <div id="fb-root">
  17.             <div class="fb-login-button" data-width="" data-scope="manage_pages, pages_show_list" data-size="large"
  18.                  data-button-type="continue_with" data-auto-logout-link="true" data-use-continue-as="true"></div>
  19.         </div>
  20.     </div>
  21.     <div class="fb-form-wrapper">
  22.         <h4>Choose page</h4>
  23.         <form id="fb-form" action="{{ path("choose_fb_page") }}" method="post">
  24.             <input type="hidden" name="at">
  25.             <input type="hidden" name="uid">
  26.             <select name="page"></select>
  27.         <button type="submit">Save</button>
  28.         </form>
  29.     </div>
  30. {% endblock %}
  31. {% block javascripts %}
  32.     {{ parent() }}
  33.     <script>
  34.         $(document).ready(function () {
  35.             window.fbAsyncInit = function () {
  36.                 FB.init({
  37.                     appId: {{ fb.app_id }},
  38.                     cookie: true,
  39.                     xfbml: true,
  40.                     version: 'v3.3'
  41.                 });
  42.                 FB.AppEvents.logPageView();
  43.                 FB.getLoginStatus(function (response) {
  44.                     statusChangeCallback(response);
  45.                 });
  46.                 function checkLoginState() {
  47.                     FB.getLoginStatus(function (response) {
  48.                         statusChangeCallback(response);
  49.                     });
  50.                 }
  51.             };
  52.             (function (d, s, id) {
  53.                 var js, fjs = d.getElementsByTagName(s)[0];
  54.                 if (d.getElementById(id)) {
  55.                     return;
  56.                 }
  57.                 js = d.createElement(s);
  58.                 js.id = id;
  59.                 js.src = "https://connect.facebook.net/en_US/sdk.js";
  60.                 fjs.parentNode.insertBefore(js, fjs);
  61.             }(document, 'script', 'facebook-jssdk'));
  62.         });
  63.         function statusChangeCallback(response) {
  64.             if (response.status === 'connected') {
  65.                 $('#fb-form input[name="at"]').val(response.authResponse.accessToken);
  66.                 $('#fb-form input[name="uid"]').val(response.authResponse.userID);
  67.                 $('.fb-form-wrapper').show();
  68.                 FB.api(
  69.                     "/" + response.authResponse.userID + "/accounts",
  70.                     function (response) {
  71.                         if (response && !response.error) {
  72.                             html = "";
  73.                             $('#fb-form select[name="page"]').html(html);
  74.                             $.each(response.data, function (index, value) {
  75.                                 html += "<option value=" + value.id + ">" + value.name + "</option>";
  76.                             });
  77.                             $('#fb-form select[name="page"]').html(html);
  78.                         }
  79.                     }
  80.                 );
  81.             }
  82.         }
  83.     </script>
  84. {% endblock %}