refactor responsive web design
authorWolfram Schneider <wosch@indexdata.dk>
Mon, 1 Jul 2013 13:29:53 +0000 (13:29 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Mon, 1 Jul 2013 13:29:53 +0000 (13:29 +0000)
experiments/spclient/index-mobile.html
experiments/spclient/mkws.js

index 201745a..b1821b7 100644 (file)
@@ -7,61 +7,25 @@
     <title>MKWS demo client</title>
 
     <script type="text/javascript">
-       var mkws_config = { 
+       var mkws_config = {
                lang: "da",
                debug: 1,
                use_service_proxy: true,
-               switch_menu: false, 
-               lang_menu: true, 
-               lang_display: ["da", "en"], 
+               switch_menu: false,
+               lang_menu: true,
+               lang_display: ["da", "en"],
                sort_default: "relevance",
                query_width: 50,
                responsive_design: true,
                facets: ["authors", "sources", "subjects"],
                perpage_default: 20
-        }; 
+        };
     </script>
 
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
     <script type="text/javascript" src="http://mkws.indexdata.com/libjs-pz2/pz2api.1.js"></script>
     <script type="text/javascript" src="mkws.js"></script>
     <link rel="stylesheet" href="mkwsStyle.css" />
-
-    <script type="text/javascript">
-       var timeout;
-
-       if (mkws_config.responsive_design) {
-           $(window).resize( function(e) { 
-               if (timeout)
-                   clearTimeout(timeout);
-               timeout = setTimeout(function () { mobile_resize() }, 100);
-            });
-           $(document).ready(function() { mobile_resize() });
-       }
-
-       function mobile_resize () {
-          debug("resize width: " + $(window).height() + ", width: " + $(window).width()); 
-          var list = ["mkwsSwitch"];
-          var obj;
-          // alert($(window).width());
-          if ($(window).width() <= 980) {
-               for(var i = 0; i < list.length; i++) {
-                   $("#" + list[i]).hide();
-               }
-               
-               $("#termlist").parent().hide(); 
-               obj = $("#termlist").parent().html();
-               $("#mkwsTermlist").html(obj);
-          } else {
-               for(var i = 0; i < list.length; i++) {
-                   $("#" + list[i]).show();
-               }
-               $("#termlist").parent().show(); 
-               $("#mkwsTermlist").html("");
-          }
-       };
-    </script>
   </head>
   <body>
     <!-- These six mkws <div>s are provided by MKWS -->
@@ -75,7 +39,7 @@
 
     <div id="footer">
       <div id="mkwsStat"></div>
-      <span>Powered by MKWS &copy; 2013 <a href="http://www.indexdata.com">Index Data</a></span> 
+      <span>Powered by MKWS &copy; 2013 <a href="http://www.indexdata.com">Index Data</a></span>
     </div>
   </body>
 </html>
index d168a34..5dfe32e 100644 (file)
@@ -560,15 +560,35 @@ function mkws_html_all(config) {
       </table>');
 
     mkws_html_switch(config);
+
     if (mkws_config.use_service_proxy)
        mkws_service_proxy_auth(config.service_proxy_auth);
 
+    if (mkws_config.responsive_design)
+       mkws_responsive_design();
+
     domReady();
 
     // on first page, hide the termlist
     $(document).ready(function() { $("#termlist").parent().hide(); } );
 }
 
+/* Responsive web design - change layout on the fly depending on
+ * the current screen size width/height. Required for mobile devices.
+ */
+function mkws_responsive_design () {
+    var timeout = null;
+
+    $(window).resize( function(e) {
+       if (timeout)
+           clearTimeout(timeout);
+       timeout = setTimeout(function () { mkws_mobile_resize() }, 100);
+    });
+
+    // initial check after page load
+    $(document).ready(function() { mkws_mobile_resize() });
+}
+
 function mkws_set_lang(mkws_config)  {
     var lang = jQuery.parseQuerystring().lang || mkws_config.lang || "";
     if (!lang || !mkws_locale_lang[lang]) {
@@ -713,6 +733,29 @@ function mkws_html_lang(mkws_config) {
     $("#mkwsLang").html(data);
 }
 
+function mkws_mobile_resize () {
+   debug("resize width: " + $(window).height() + ", width: " + $(window).width());
+   var list = ["mkwsSwitch"];
+   var obj;
+   // alert($(window).width());
+
+   if ($(window).width() <= 980) {
+       for(var i = 0; i < list.length; i++) {
+           $("#" + list[i]).hide();
+       }
+
+       $("#termlist").parent().hide();
+       obj = $("#termlist").parent().html();
+       $("#mkwsTermlist").html("<hr/>" + obj);
+   } else {
+       for(var i = 0; i < list.length; i++) {
+           $("#" + list[i]).show();
+       }
+       $("#termlist").parent().show();
+       $("#mkwsTermlist").html("");
+   }
+};
+
 /* locale */
 function M(word) {
     var lang = mkws_config.lang;