Add logging of size state-changes.
[mkws-moved-to-github.git] / src / mkws-core.js
index 0bfc174..8d19f3a 100644 (file)
@@ -88,7 +88,8 @@ mkws.log = function(string) {
 
     // you need to disable use strict at the top of the file!!!
     if (mkws.log_level >= 3) {
-       console.log(arguments.callee.caller);
+        // Works in Chrome; not sure about elsewhere
+       console.trace();
     } else if (mkws.log_level >= 2) {
        console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
     }
@@ -163,6 +164,95 @@ mkws.objectInheritingFrom = function(o) {
 }
 
 
+mkws.defaultTemplate = function(name) {
+    if (name === 'Record') {
+       return '\
+<table>\
+  <tr>\
+    <th>{{translate "Title"}}</th>\
+    <td>\
+      {{md-title}}\
+      {{#if md-title-remainder}}\
+       ({{md-title-remainder}})\
+      {{/if}}\
+      {{#if md-title-responsibility}}\
+       <i>{{md-title-responsibility}}</i>\
+      {{/if}}\
+    </td>\
+  </tr>\
+  {{#if md-date}}\
+  <tr>\
+    <th>{{translate "Date"}}</th>\
+    <td>{{md-date}}</td>\
+  </tr>\
+  {{/if}}\
+  {{#if md-author}}\
+  <tr>\
+    <th>{{translate "Author"}}</th>\
+    <td>{{md-author}}</td>\
+  </tr>\
+  {{/if}}\
+  {{#if md-electronic-url}}\
+  <tr>\
+    <th>{{translate "Links"}}</th>\
+    <td>\
+      {{#each md-electronic-url}}\
+       <a href="{{this}}">Link{{index1}}</a>\
+      {{/each}}\
+    </td>\
+  </tr>\
+  {{/if}}\
+  {{#if-any location having="md-subject"}}\
+  <tr>\
+    <th>{{translate "Subject"}}</th>\
+    <td>\
+      {{#first location having="md-subject"}}\
+       {{#if md-subject}}\
+         {{#commaList md-subject}}\
+           {{this}}{{/commaList}}\
+       {{/if}}\
+      {{/first}}\
+    </td>\
+  </tr>\
+  {{/if-any}}\
+  <tr>\
+    <th>{{translate "Locations"}}</th>\
+    <td>\
+      {{#commaList location}}\
+       {{attr "@name"}}{{/commaList}}\
+    </td>\
+  </tr>\
+</table>\
+';
+    } else if (name === "Summary") {
+       return '\
+<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
+  <b>{{md-title}}</b>\
+</a>\
+{{#if md-title-remainder}}\
+  <span>{{md-title-remainder}}</span>\
+{{/if}}\
+{{#if md-title-responsibility}}\
+  <span><i>{{md-title-responsibility}}</i></span>\
+{{/if}}\
+';
+    } else if (name === "Image") {
+       return '\
+      <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
+        {{#first md-thumburl}}\
+         <img src="{{this}}" alt="{{../md-title}}"/>\
+        {{/first}}\
+       <br/>\
+      </a>\
+';
+    }
+
+    var s = "There is no default '" + name +"' template!";
+    alert(s);
+    return s;
+};
+
+
 // The following functions are dispatchers for team methods that
 // are called from the UI using a team-name rather than implicit
 // context.
@@ -242,27 +332,43 @@ mkws.pagerNext = function(tname) {
     function resizePage() {
        var list = ["mkwsSwitch", "mkwsLang"];
 
-       var width = mkws.config.responsive_design_width;
        var parent = $(".mkwsTermlists").parent();
-
-       if ($(window).width() <= width &&
-           parent.hasClass("mkwsTermlistContainer1")) {
-           log("changing from wide to narrow: " + $(window).width());
-           $(".mkwsTermlistContainer1").hide();
-           $(".mkwsTermlistContainer2").show();
+       var targetWidth = mkws.config.responsive_design_width;
+        var width = $(window).width();
+
+        if (mkws.width === undefined) {
+            // No state change, since we have no previous state
+        } else if (mkws.width <= targetWidth && width > targetWidth) {
+            log("narrow -> wide");
+        } else if (mkws.width > targetWidth && width <= targetWidth) {
+            log("wide -> narrow");
+        } else if (width > targetWidth) {
+            log("already wide");
+        } else {
+            log("already narrow");
+        }
+        mkws.width = width;
+
+       if (width <= targetWidth &&
+           parent.hasClass("mkwsTermlist-Container-wide")) {
+           log("changing from wide to narrow: " + width);
+           $(".mkwsTermlist-Container-wide").hide();
+           $(".mkwsTermlist-Container-narrow").show();
            for (var tname in mkws.teams) {
-               $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer2.mkwsTeam_" + tname));
+                mkws.teams[tname].queue("resize-narrow").publish();
+               $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlist-Container-narrow.mkwsTeam_" + tname));
                for(var i = 0; i < list.length; i++) {
                    $("." + list[i] + ".mkwsTeam_" + tname).hide();
                }
            }
-       } else if ($(window).width() > width &&
-                  parent.hasClass("mkwsTermlistContainer2")) {
-           log("changing from narrow to wide: " + $(window).width());
-           $(".mkwsTermlistContainer1").show();
-           $(".mkwsTermlistContainer2").hide();
+       } else if (width > targetWidth &&
+                  parent.hasClass("mkwsTermlist-Container-narrow")) {
+           log("changing from narrow to wide: " + width);
+           $(".mkwsTermlist-Container-wide").show();
+           $(".mkwsTermlist-Container-narrow").hide();
            for (var tname in mkws.teams) {
-               $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer1.mkwsTeam_" + tname));
+                mkws.teams[tname].queue("resize-wide").publish();
+               $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlist-Container-wide.mkwsTeam_" + tname));
                for(var i = 0; i < list.length; i++) {
                    $("." + list[i] + ".mkwsTeam_" + tname).show();
                }