web/embedscript.php
changeset 620 953c68b4da79
child 621 44f90de0016f
equal deleted inserted replaced
619:170f46b3b318 620:953c68b4da79
       
     1 <?php
       
     2 header("Content-type: text/javascript; charset=utf-8");
       
     3 $rep = $_REQUEST['rep'];
       
     4 include_once dirname(__FILE__).'/'.$rep.'/config.php';
       
     5 include_once 'common.php';
       
     6 
       
     7 if (is_array($config['metadata']) && array_key_exists("metadata",$_GET) && array_key_exists($_GET['metadata'], $config['metadata'])) {
       
     8     $media_title = $config['metadata'][$_GET['metadata']]['display'];
       
     9 } else {
       
    10     $media_title = $config['title'];
       
    11 }
       
    12 
       
    13 ?>
       
    14 (function(_containerId, _iframeUrl, _mediaUrl, _platformUrl, _mediaTitle, _platformTitle, _width, _height) {
       
    15     
       
    16     var _messages = {
       
    17             en: {
       
    18                 watch: "Watch",
       
    19                 on: "on"
       
    20             },
       
    21             fr: {
       
    22                 watch: "Regarder",
       
    23                 on: "sur"
       
    24             }
       
    25         },
       
    26         _lang = ( navigator.language ? navigator.language : ( navigator.userLanguage ? navigator.userLanguage : "en" ) ).substr(0,2).toLowerCase();
       
    27     _lang = (_messages[_lang] ? _lang : "en");
       
    28     
       
    29     var _container = document.getElementById(_containerId),
       
    30         _frame = document.createElement("iframe");
       
    31     
       
    32     _frame.width = _width;
       
    33     _frame.height = _height;
       
    34     _frame.frameBorder = 0;
       
    35     _frame.src = _iframeUrl;
       
    36     
       
    37     _container.appendChild(_frame);
       
    38     
       
    39     var _p = document.createElement("p");
       
    40     _p.innerHTML = _messages[_lang].watch
       
    41         + ' <a href="'
       
    42         + _mediaUrl
       
    43         + '" target="_blank">'
       
    44         + _mediaTitle
       
    45         + '</a> '
       
    46         + _messages[_lang].on
       
    47         + ' <a href="'
       
    48         + _platformUrl
       
    49         + '" target="_blank">'
       
    50         + _platformTitle
       
    51         + '</a>';
       
    52     _container.appendChild(_p);
       
    53     
       
    54     var _blocked = false,
       
    55         _updater = function() {
       
    56             _blocked = true;
       
    57             window.setTimeout(function() {
       
    58                 _blocked = false;
       
    59             }, 1000);
       
    60             _frame.contentWindow.postMessage({type: "hashchange", hash: document.location.hash}, "*");
       
    61         };
       
    62     
       
    63     window.onhashchange = _updater;
       
    64     
       
    65     window.addEventListener('message', function(_e) {
       
    66         if (_e.data.type === "hashchange" && !_blocked) {
       
    67             document.location.hash = _e.data.hash;
       
    68         }
       
    69     });
       
    70     
       
    71     window.setTimeout(_updater, 2000);
       
    72     
       
    73 })(
       
    74     'metadataplayer_embed',
       
    75     '<?php echo(URL_ROOT.$rep); ?>/player_embed.php<?php echo(array_key_exists("metadata",$_GET)?"?metadata=".$_GET["metadata"]:""); ?>',
       
    76     '<?php echo(URL_ROOT.$rep); ?>/polemicaltimeline.php<?php echo(array_key_exists("metadata",$_GET)?"#metadata=".$_GET["metadata"]:""); ?>',
       
    77     '<?php echo URL_ROOT; ?>',
       
    78     '<?php echo $media_title; ?>',
       
    79     'Polemic Tweet',
       
    80     650,
       
    81     500
       
    82 );