index.html 6.63 KB
Newer Older
Kjetil Thuen's avatar
Kjetil Thuen committed
1 2
<!DOCTYPE html>
<html lang="en">
Kjetil Thuen's avatar
Kjetil Thuen committed
3 4
   <head>
       <meta charset="utf-8">
Kjetil Thuen's avatar
Kjetil Thuen committed
5

Kjetil Thuen's avatar
Kjetil Thuen committed
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
       <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">
       <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.css" rel="stylesheet">

       <style>
          body {
             background-color: #028e9b;
             color: #5ec4cd;
          }

          .hero-unit {
             color: #ff7800;
             background-color: #5ec4cd;
          }

          ul#studies_list li:first-child {
          }

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

          ul#studies_list li:last-child {
             margin-bottom: 20em;
          }

          ul#studies_list li {
             color: #5ec4cd;
             overflow: hidden;
             border-bottom: 1px solid #5ec4cd;
          }

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

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

          #target {
             top: 20%;
             height: 10%;
             width: 100%;
             min-height: 1em;
             z-index: -2;
             position: fixed;
             background: #5ec4cd;
          }

          #expansionzone {
             position: fixed;
             width: 70%;
             left: 15%;
             z-index: 2;
             display: none;
             max-height: 70%;
             background: #5ec4cd;
          }

          h2 {
             margin: 0px; 
             padding: 0.5em;
          }

          h2#target {
             padding: 0px;
          }

          #expansionzone div.metadata div.abstract { 
             max-height: 6em;
             margin-bottom: 0.5em;
             overflow: hidden;
             color: white;
             padding: 0em 1em 1em 1em;
          }

          #expansionzone button { 
             margin: 0 0 1em 1em ;
          }
       </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 target_top = 0;
          var scrollTimeout;
          var jsondata = {};
          var scrollVal;

          var build_list = function() {
             var source   = $('#study_list').html();
             var template = Handlebars.compile(source);
             var listhtml = template(jsondata);
             $('#content').html(listhtml);
             register_event_handlers();
          }

          var register_event_handlers = function() {
            $(document).scroll(find_and_select_element);
//            $(window).on("touchend", set_selected_element);
            $('#studies_list li').click(function() {
               set_selected_element($(this).get());
            });
          }

          var initialize_page = function() {
             target_top = $('#content').position().top;
             $('#target').css({top: target_top});
             horizontalCenter = Math.floor(window.innerWidth/2);
             centerOfHeadline = $('#target').offset().top - $(window).scrollTop() + ($('#target').height() / 2);
          }

          var load_data = function() {
             $.ajax({
               url: "https://nesstar-dev.nsd.uib.no/nesstardrop/study/list",
               datatype: "json",
               async: true,
               context: document.body
             }).done(function(data) {
               jsondata = data;
               build_list();
             });
          }
Kjetil Thuen's avatar
Kjetil Thuen committed
144

Kjetil Thuen's avatar
Kjetil Thuen committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
          var show_expanded_info = function() {
             $(document).scroll(function() {return false;});
             var listElem = $('#studies_list li.selected');
             $('html:not(:animated),body:not(:animated)').animate({scrollTop: scrollVal}, 'fast', function() {
                $('#target').animate({height: listElem.height()}, 'fast', function() {
                   details = listElem.find("div.abstract").html();
                   if (details != null) {
                      $('#expansionzone').css({top: target_top + $('#target').height()});
                      $('#expansionzone div.abstract').html(details);
                      $('#expansionzone').slideDown();
                      $(document).scroll(find_and_select_element);
                   }
                }); 
             });
          }

          var find_and_select_element = function() {
             window.clearTimeout(scrollTimeout);
             var focusedElement = document.elementFromPoint(horizontalCenter, centerOfHeadline);
             set_selected_element(focusedElement);
          }
Kjetil Thuen's avatar
Kjetil Thuen committed
166

Kjetil Thuen's avatar
Kjetil Thuen committed
167 168 169 170
          var set_selected_element = function (element) {
             window.clearTimeout(scrollTimeout);
             $('#expansionzone').fadeOut();
             $('ul#studies_list li').removeClass("selected");
Kjetil Thuen's avatar
Kjetil Thuen committed
171

Kjetil Thuen's avatar
Kjetil Thuen committed
172 173
             if (element) {
                var listElem = $(element).closest('li');
Kjetil Thuen's avatar
Kjetil Thuen committed
174

Kjetil Thuen's avatar
Kjetil Thuen committed
175 176 177 178 179 180 181
                if (listElem.is("LI")) {
                   listElem.addClass('selected');
                   scrollVal = listElem.offset().top - $('#studies_list').position().top;
                   scrollTimeout = window.setTimeout(show_expanded_info, 500);
                }
             } else {
                $('#expansionzone').hide();
Kjetil Thuen's avatar
Kjetil Thuen committed
182
             }
Kjetil Thuen's avatar
Kjetil Thuen committed
183 184 185 186 187 188 189 190 191
          }
       </script>
   </head>
   <body>
      <div class="hero-unit">
         <h1>Data fra Skolenesstar</h1>
         Finn interresante studier i listen under.
      </div>
      <div id="content">
Kjetil Thuen's avatar
Kjetil Thuen committed
192
      </div>
Kjetil Thuen's avatar
Kjetil Thuen committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
      <h2 id="target"></h2>
      <div id="expansionzone">
         <div class="metadata">
            <div class="abstract lead"></div>
            <div class="buttons">
               <button class="btn btn-info"><i class="icon-info-sign"></i> Mer metadata</button>
               <button class="btn btn-success"><i class="icon-ok-sign"></i> Velg studie</button>
            </div>
         </div>
      </div>
      <script>
         $('#expansionzone').fadeOut();
         initialize_page();
         load_data();
         $(window).resize(function() {
            initialize_page();
            build_list();
         });
      </script>
   </body>
Kjetil Thuen's avatar
Kjetil Thuen committed
213
</html>