<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">

    <title>{% block title %}SWAN{% endblock %}</title>
    <link rel="shortcut icon" type="image/x-icon" href="{{hub_prefix}}static/swan/logos/favicon.ico">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="stylesheet" href="{{static_url('components/jquery-ui/themes/smoothness/jquery-ui.min.css') }}" type="text/css" />
    <link rel="stylesheet" href="{{static_url('components/jquery-typeahead/dist/jquery.typeahead.min.css') }}" type="text/css" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    {% block stylesheet %}
    <!-- Latest compiled and minified CSS -->

    <link rel="stylesheet" href="{{ static_url("components/codemirror/lib/codemirror.css") }}">

    <link rel="stylesheet" href="{{ static_url('style/style.min.css') }}" type="text/css"/>
    {%if hub_prefix %}
    <link rel="stylesheet" href="{{hub_prefix}}static/swan/css/style.css" type="text/css" />
    {% else %}
    <link rel="stylesheet" href="/custom/css/style.css" type="text/css"/> <!-- For Dev purposes-->
    {% endif %}
    {% endblock %}
    <script src="{{static_url('components/es6-promise/promise.min.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{static_url('components/react/react.production.min.js')}}" type="text/javascript"></script>
    <script src="{{static_url('components/react/react-dom.production.min.js')}}" type="text/javascript"></script>
    <script src="{{static_url('components/create-react-class/index.js')}}" type="text/javascript"></script>
    <script src="{{static_url('components/requirejs/require.js') }}" type="text/javascript" charset="utf-8"></script>
    <script>
      document.nbclassicPath = '{{nbclassic_path()}}';
      require.config({
          {% if version_hash %}
          urlArgs: "v={{version_hash}}",
          {% endif %}
          baseUrl: '{{static_url("", include_version=False)}}',
          paths: {
            'auth/js/main': 'auth/js/main.min',
            custom : '{{ base_url }}custom',
            'custom-preload' : '{{ base_url }}custom-preload',
            nbextensions : '{{ base_url }}nbextensions',
            kernelspecs : '{{ base_url }}kernelspecs',
            underscore : 'components/underscore/underscore-min',
            backbone : 'components/backbone/backbone-min',
            jed: 'components/jed/jed',
            jquery: 'components/jquery/jquery.min',
            json: 'components/requirejs-plugins/src/json',
            text: 'components/requirejs-text/text',
            bootstrap: 'components/bootstrap/dist/js/bootstrap.min',
            bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
            'jquery-ui': 'components/jquery-ui/jquery-ui.min',
            moment: 'components/moment/min/moment-with-locales',
            codemirror: 'components/codemirror',
            termjs: 'components/xterm.js/xterm',
            typeahead: 'components/jquery-typeahead/dist/jquery.typeahead.min',
          },
          map: { // for backward compatibility
              "*": {
                  "jqueryui": "jquery-ui",
                  'tree/js/notebooklist': 'swan/js/notebooklist',
                  'contents': 'swan/js/contents'
              },
              'swan/js/notebooklist': {
                  'tree/js/notebooklist': 'tree/js/notebooklist'
              },
              'swan/js/contents': {
                  'contents': '{{ contents_js_source }}'
              }
          },
          shim: {
            typeahead: {
              deps: ["jquery"],
              exports: "typeahead"
            },
            underscore: {
              exports: '_'
            },
            backbone: {
              deps: ["underscore", "jquery"],
              exports: "Backbone"
            },
            bootstrap: {
              deps: ["jquery"],
              exports: "bootstrap"
            },
            bootstraptour: {
              deps: ["bootstrap"],
              exports: "Tour"
            },
            "jquery-ui": {
              deps: ["jquery"],
              exports: "$"
            }
          },
          waitSeconds: 30,
      });

        // error-catching custom.js shim.
        define("custom", function (require, exports, module) {
            try {
                var custom = require('custom/custom');
                console.debug('loaded custom.js');
                return custom;
            } catch (e) {
                console.error("error loading custom.js", e);
                return {};
            }
        })

        // error-catching custom-preload.js shim.
        define("custom-preload", function (require, exports, module) {
            try {
                var custom = require('custom/custom-preload');
                console.debug('loaded custom-preload.js');
                return custom;
            } catch (e) {
                console.error("error loading custom-preload.js", e);
                return {};
            }
        })

      document.nbjs_translations = {{ nbjs_translations|safe }};
      document.documentElement.lang = navigator.language.toLowerCase();

    </script>

    {% block meta %}
    {% endblock %}

</head>

<body class="{% block bodyclasses %}{% endblock %}{% if not tree  and not extension%} full-width{% endif %}"
 {% block params %}
{% if logged_in and token %}
data-jupyter-api-token="{{token | urlencode}}"
{% endif %}
{% endblock params %}
page_type="{% if projects_page %}projects{% else %}cernbox{% endif %}"
dir="ltr">

<noscript>
    <div id='noscript'>
        {% trans %}Jupyter Notebook requires JavaScript.{% endtrans %}<br>
        {% trans %}Please enable it to proceed. {% endtrans %}
  </div>
</noscript>
<header role="navigation" aria-label="{% trans %}Top Menu{% endtrans %}">
  <div id="header-container" class="container">
      <div class="row">
          <div class="{% if tree %}col-md-3{% else %}col-md-1{% endif %} col-xs-6">
              <div id="ipython_notebook" class="nav navbar-brand"><a href="{{base_url}}projects" title='SWAN Projects'>{% block logo %}<img src='{% if hub_prefix %}{{hub_prefix}}logo{% else %}{{static_url("base/images/logo.png")}}{% endif %}' alt='SWAN'/>{% endblock %}</a></div>
          </div>

          <div class="col-md-3 {% if tree %}col-md-push-6{% else %}col-md-push-8{% endif %} col-xs-6 control">


              {% block header_buttons %}
              <div id="buttons-right-wrapper">
                  <div id="buttons-right">
                      <div id="options-buttons" class="btn-group">
                          {% block extra_buttons %}
                          {% endblock %}
                          <button id="help-button" role="presentation" class="btn btn-default btn-xs disabled" title="Help">
                            <i class="fa fa-question" aria-hidden="true"></i>
                          </button>
                          <button class="dropdown-toggle btn btn-default btn-xs" data-toggle="dropdown" title="Options">
                              <i class="icon-more" aria-hidden="true"></i>
                          </button>
                          <ul id="options-menu" class="dropdown-menu">
                              {% block extra_options %}
                              {% endblock %}
                              <li role="presentation">
                                  <a id="change-config" href="javascript:">Change configuration</a>
                              </li>
                          </ul>
                      </div>
                      <button class="btn btn-default btn-xs" onclick="javascript: window.location = '{{base_url}}logout'" title="Log out">
                          <i class="fa fa-sign-out" aria-hidden="true"></i>
                      </button>
                  </div>
              </div>
              {% endblock header_buttons %}
          </div>


          <div class="middle {% if tree %}col-md-6 col-md-pull-3{% else %}col-md-8 col-md-pull-3{% endif %} col-xs-12">

              {% block headercontainer %}
              {% endblock %}

              {% if menu %}
              <div id="menu">
                  <ul class="nav nav-tabs">
                      <li {%if projects_page%} class="active"{%endif%}><a href="{{base_url}}projects"><i class="fa fa-archive" aria-hidden="true"></i><span class="text">Projects</span></a></li>
                      <li {%if share_page%} class="active"{%endif%}><a href="{{base_url}}share"><i class="fa fa-share-alt" aria-hidden="true"></i><span class="text">Share</span></a></li>
                      <li {%if not projects_page and not share_page%} class="active"{%endif%}><a href="{{base_url}}cernbox"><i class="icon-cernbox-abstract" aria-hidden="true"></i><span class="text">CERNBox</span></a></li>
                  </ul>
              </div>
              {% endif %}
          </div>
      </div>
  </div>
  <div class="header-bar"></div>

  {% block header %}
  {% endblock %}
</header>

<div id="site">
{% block site %}
{% endblock %}
</div>

{% block after_site %}
{% endblock %}

<footer>
    <div class="container">
        <div class="row">
            <div class="col-xs-8 text">
                <span class="text-muted">SWAN &copy; Copyright CERN 2016-{{ current_year }}. All rights reserved.</span>
                <ul class="text-muted">
                    <li><a target="_blank" href="https://cern.ch/swan/">Home</a></li>
                    <li><a target="_blank" href="https://swan-community.web.cern.ch/">Community</a></li>
                    <li><a target="_blank" href="https://cern.service-now.com/service-portal/?id=functional_element&name=swan">Support</a></li>
                    <li><a target="_blank" href="https://github.com/swan-cern">Github</a></li>
                </ul>
            </div>
            <div class="col-xs-4 logo">
                <img src='{{hub_prefix}}static/swan/logos/logo_cern.png' alt='CERN'/>
            </div>
        </div>
    </div>
</footer>

{% block script %}
{% endblock %}

<script type='text/javascript'>
    define('template',[
        'jquery',
        'base/js/dialog'
    ], function ($, dialog) {

        $('#change-config').on('click', function () {
            dialog.modal({
                draggable: false,
                title: 'Change configuration',
                body: $("<p>You are going to shut down all your notebooks and remove your saved configuration.<br>Do you wish to continue?</p>"),
                buttons: {
                    'Cancel': {},
                    'Change': {
                        class: 'btn-warning',
                        click: function () {
                            window.location.replace('{{hub_prefix}}home?changeconfig');
                        }
                    }
                }
            }).modal('show');
        });
    });
    require(['template']);
    
    function _remove_token_from_url() {
        if (window.location.search.length <= 1) {
            return;
        }
        var search_parameters = window.location.search.slice(1).split('&');
        for (var i = 0; i < search_parameters.length; i++) {
        if (search_parameters[i].split('=')[0] === 'token') {
            // remote token from search parameters
            search_parameters.splice(i, 1);
            var new_search = '';
            if (search_parameters.length) {
            new_search = '?' + search_parameters.join('&');
            }
            var new_url = window.location.origin + 
                        window.location.pathname + 
                        new_search + 
                        window.location.hash;
            window.history.replaceState({}, "", new_url);
            return;
        }
        }
    }
    _remove_token_from_url();
</script>

</body>

</html>
