index.html 5.62 KB
Newer Older
Kjetil Thuen's avatar
Kjetil Thuen committed
1 2 3 4 5 6 7 8
<!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">
Kjetil Thuen's avatar
Kjetil Thuen committed
9
    <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.css" rel="stylesheet">
Kjetil Thuen's avatar
Kjetil Thuen committed
10 11 12 13

    <style>
       body {
          font-size: 150%;
Kjetil Thuen's avatar
Kjetil Thuen committed
14
          background: url(http://subtlepatterns.com/patterns/light_toast.png);
Kjetil Thuen's avatar
Kjetil Thuen committed
15 16 17 18 19 20 21 22 23 24 25
       }

       ul#studies_list li:first-child {
       }

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

       ul#studies_list li:last-child {
Kjetil Thuen's avatar
Kjetil Thuen committed
26
          margin-bottom: 20em;
Kjetil Thuen's avatar
Kjetil Thuen committed
27 28 29 30 31 32
       }

       ul#studies_list li {
          color: #888;
          overflow: hidden;
          text-align: center;
Kjetil Thuen's avatar
Kjetil Thuen committed
33
          border-bottom: 1px solid #bbb;
Kjetil Thuen's avatar
Kjetil Thuen committed
34 35 36 37 38 39 40 41 42 43 44
       }

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

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

       #target {
Kjetil Thuen's avatar
Kjetil Thuen committed
45 46 47 48
          top: 20%;
          height: 10%;
          width: 100%;
          min-height: 1em;
Kjetil Thuen's avatar
Kjetil Thuen committed
49
          z-index: -2;
Kjetil Thuen's avatar
Kjetil Thuen committed
50 51
          position: fixed;
          background: rgba(200,237,200,0.8);
Kjetil Thuen's avatar
Kjetil Thuen committed
52 53 54
       }

       #expansionzone {
Kjetil Thuen's avatar
Kjetil Thuen committed
55 56 57 58
          position: fixed;
          left: 12.5%;
          width: 75%;
          z-index: 2;
Kjetil Thuen's avatar
Kjetil Thuen committed
59 60
          display: none;
          max-height: 70%;
Kjetil Thuen's avatar
Kjetil Thuen committed
61
          background: rgba(200,237,200,0.8);
Kjetil Thuen's avatar
Kjetil Thuen committed
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
          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);
Kjetil Thuen's avatar
Kjetil Thuen committed
90 91
       var centerOfHeadline = 0;
       var target_top = 0;
Kjetil Thuen's avatar
Kjetil Thuen committed
92 93
       var scrollTimeout;
       var focusedElement;
Kjetil Thuen's avatar
Kjetil Thuen committed
94 95 96 97 98
       var jsondata = {};
       var scrollVal;

       var build_list = function() {
         var source   = $('#study_list').html();
Kjetil Thuen's avatar
Kjetil Thuen committed
99
         var template = Handlebars.compile(source);
Kjetil Thuen's avatar
Kjetil Thuen committed
100 101
         var listhtml = template(jsondata);
         $('#content').html(listhtml);
Kjetil Thuen's avatar
Kjetil Thuen committed
102 103
       }

Kjetil Thuen's avatar
Kjetil Thuen committed
104 105 106
       var initialize_page = function() {
          target_top = $('#content').position().top;
          $('#target').css({top: target_top});
Kjetil Thuen's avatar
Kjetil Thuen committed
107 108
          horizontalCenter = Math.floor(window.innerWidth/2);
          centerOfHeadline = $('#target').offset().top - $(window).scrollTop() + ($('#target').height() / 2);
Kjetil Thuen's avatar
Kjetil Thuen committed
109 110 111
       }

       var load_data = function() {
Kjetil Thuen's avatar
Kjetil Thuen committed
112 113 114 115 116 117
          $.ajax({
            url: "https://nesstar-dev.nsd.uib.no/nesstardrop/study/list",
            datatype: "json",
            async: true,
            context: document.body
          }).done(function(data) {
Kjetil Thuen's avatar
Kjetil Thuen committed
118 119
            jsondata = data;
            build_list();
Kjetil Thuen's avatar
Kjetil Thuen committed
120 121 122 123
          });
       }

       var show_expanded_info = function() {
Kjetil Thuen's avatar
Kjetil Thuen committed
124 125 126 127 128 129
          console.log("triggered");
          var listElem = $('#studies_list li.selected');
          $(document).scroll(function() {return false;});
          console.log("disabled");
          $('html:not(:animated),body:not(:animated)').animate({scrollTop: scrollVal}, 'fast', function() {
             $('#target').animate({height: listElem.height()}, 'fast', function() {
Kjetil Thuen's avatar
Kjetil Thuen committed
130 131
                details = listElem.find("div.abstract").html();
                if (details != null) {
Kjetil Thuen's avatar
Kjetil Thuen committed
132
                   $('#expansionzone').css({top: target_top + $('#target').height()});
Kjetil Thuen's avatar
Kjetil Thuen committed
133
                   $('#expansionzone div.abstract').html(details);
Kjetil Thuen's avatar
Kjetil Thuen committed
134 135 136 137 138 139 140
                   $('#expansionzone').slideDown();
                   console.log("enabling");
                   window.clearTimeout(scrollTimeout);
                   $(document).scroll(set_selected_element);
                }
             }); 
          });
Kjetil Thuen's avatar
Kjetil Thuen committed
141 142
       }

Kjetil Thuen's avatar
Kjetil Thuen committed
143 144
       var set_selected_element = function() {
          window.clearTimeout(scrollTimeout);
Kjetil Thuen's avatar
Kjetil Thuen committed
145 146 147 148 149 150
          $('#expansionzone').fadeOut();
          $('ul#studies_list li').removeClass("selected");

          focusedElement = document.elementFromPoint(horizontalCenter, centerOfHeadline);

          if (focusedElement) {
Kjetil Thuen's avatar
Kjetil Thuen committed
151 152 153 154 155 156 157
             var listElem = $(focusedElement).closest('li');

             if (listElem.is("LI")) {
                listElem.addClass('selected');
                scrollVal = listElem.offset().top - $('#studies_list').position().top;
                scrollTimeout = window.setTimeout(show_expanded_info, 500);
             }
Kjetil Thuen's avatar
Kjetil Thuen committed
158 159 160 161 162 163 164
          } else {
             $('#expansionzone').hide();
          }
       }
    </script>
</head>
<body>
Kjetil Thuen's avatar
Kjetil Thuen committed
165 166 167 168
   <div class="hero-unit">
      <h1>Data fra Skolenesstar</h1>
      Finn interresante studier i listen under.
   </div>
Kjetil Thuen's avatar
Kjetil Thuen committed
169 170
   <div id="content">
   </div>
Kjetil Thuen's avatar
Kjetil Thuen committed
171 172 173 174 175 176
   <h2 id="target"></h2>
   <div id="expansionzone">
      <div class="metadata">
         <div class="abstract lead"></div>
         <button class="btn btn-primary"><i class="icon-ok-sign"></i> Velg studie</button>
         <button class="btn"><i class="icon-info-sign"></i> Mer metadata</button>
Kjetil Thuen's avatar
Kjetil Thuen committed
177 178 179 180
      </div>
   </div>
   <script>
      $('#expansionzone').fadeOut();
Kjetil Thuen's avatar
Kjetil Thuen committed
181
      initialize_page();
Kjetil Thuen's avatar
Kjetil Thuen committed
182 183
      load_data();
      $(document).scroll(set_selected_element);
Kjetil Thuen's avatar
Kjetil Thuen committed
184
      $(window).resize(function() {initialize_page();build_list();});
Kjetil Thuen's avatar
Kjetil Thuen committed
185 186 187
   </script>
</body>
</html>