index.html 4.99 KB
Newer Older
Kjetil Thuen's avatar
Kjetil Thuen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ScrollMagnifyer</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">

    <style>
       body {
          margin: 2em;
          font-size: 150%;
          background: #eee;
       }

       ul#studies_list li:first-child {
          margin-top: 50%;
       }

       ul#studies_list {
          width: 80%;
          margin: auto;
       }

       ul#studies_list li:last-child {
          margin-bottom: 50%;
       }

       ul#studies_list li {
          color: #888;
          max-height: 190px;
          overflow: hidden;
          text-align: center;
       }

       ul#studies_list li div.abstract {
          display: none;
       }

       ul#studies_list li.selected {
          color: black;
       }

       #targetwrapper {
          position: fixed;
          top: 30%;
          height: 40%;
          left: 12.5%;
          width: 75%;
       }

       #target {
          z-index: -2;
          border: 1px solid black;
          height: 1em;
          position: relative;
          border-radius: 5px;
       }

       #expansionzone {
          display: none;
          border: 1px solid black;
          position: relative;
          max-height: 70%;
          box-shadow: 5px 5px 5px rgba(100,100,100,0.8);
          border-radius:25px;
          background: rgba(255,255,255,0.8);
          padding: 1em;
       }

       #expansionzone h2 { 
          text-align: center;
       }

       #expansionzone div.metadata div.abstract { 
          max-height: 4em;
          margin-bottom: 0.5em;
          overflow: hidden;
       }

    </style>

    <script id="study_list" type="text/x-handlebars-template">
       <ul class="nav nav-list" id="studies_list">
          {{#each studies}}
          <li id="{{id}}">
             <h2>{{name}}</h2>
             <div class="abstract">{{abstractText}}</div>
          </li>
          {{/each}}
       </ul>
    </script>

    <script>
       var horizontalCenter = Math.floor(window.innerWidth/2);
       var centerOfHeadline =  0;
       var scrollTimeout;
       var focusedElement;
       var build_list = function(data) {
         var source   = $("#study_list").html();
         var template = Handlebars.compile(source);
         var listhtml = template(data);
         $("#content").html(listhtml);
       }

       var load_data = function() {
          horizontalCenter = Math.floor(window.innerWidth/2);
          centerOfHeadline = $('#target').offset().top - $(window).scrollTop() + ($('#target').height() / 2);
          $.ajax({
            url: "https://nesstar-dev.nsd.uib.no/nesstardrop/study/list",
            datatype: "json",
            async: true,
            context: document.body
          }).done(function(data) {
            build_list(data);
          });
       }

       var show_expanded_info = function() {
          var listElem = $(focusedElement).closest('li');
          if (listElem.is("LI")) {
             var listElemTop = listElem.offset().top; 
             var scrollVal =  listElemTop - centerOfHeadline + ($('#target').height() / 4);

             $(document).scroll(function() {return false;});
             $('html:not(:animated),body:not(:animated)').animate({scrollTop: scrollVal}, 'fast', function () {
                $(document).scroll(set_selected_element);

                $('#target').height(listElem.height());
                listElem.addClass('selected');
                details = listElem.find("div.abstract").html();
                if (details != null) {
                   $('#expansionzone div.abstract').html(details);
                   $('#expansionzone').fadeIn();
                } 
             });
          }
       }

       var set_selected_element = function () {
          $('#expansionzone').fadeOut();
          $('ul#studies_list li').removeClass("selected");

          $('#targetwrapper').hide();
          focusedElement = document.elementFromPoint(horizontalCenter, centerOfHeadline);

          if (focusedElement) {
             window.clearTimeout(scrollTimeout);
             scrollTimeout = window.setTimeout(show_expanded_info, 500);
          } else {
             $('#expansionzone').hide();
          }

          $('#targetwrapper').show();
       }
    </script>
</head>
<body>
   <div id="content">
   </div>
   <div id="targetwrapper">
      <h2 id="target"></h2>
      <div id="expansionzone">
         <div class="metadata">
            <div class="abstract lead"></div>
            <button class="btn btn-primary">Velg studie</button>
            <button class="btn btn-primary">Mer metadata</button>
         </div>
      </div>
   </div>
   <script>
      $('#expansionzone').fadeOut();
      load_data();
      $(document).scroll(set_selected_element);
   </script>
</body>
</html>