X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-main.js;h=a21fd42a9632b61339900fbe35bc591d89d3c215;hb=6c378665b37e896319bf50f7d4e3d71d686b794e;hp=2a68283a67afebb6b5d801cd9c5e15d569870718;hpb=fd831c63e414e24a0c596d93beb35f41c73762e5;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 2a68283..a21fd42 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -119,29 +119,79 @@ mkws.registerWidgetType('records', function() { if (op !== undefined) { that.node.fadeTo(500, op); } }); - this.team.queue("records").subscribe(function(data) { + var m_dataToRedraw = null; + function refreshRecordData() { that.node.css('opacity', 1); - for (var i = 0; i < data.hits.length; i++) { - var hit = data.hits[i]; - hit.detailLinkId = team.recordElementId(hit.recid[0]); - hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"; - hit.containerClass = "mkws-summary mkwsSummary mkws-team-" + team.name(); - hit.containerClass += " " + hit.detailLinkId; - // ### At some point, we may be able to move the - // m_currentRecordId and m_currentRecordData members - // from the team object into this widget. - if (hit.recid == team.currentRecordId()) { - if (team.currentRecordData()) { - hit.renderedDetails = team.renderDetails(team.currentRecordData()); - } + + if (m_dataToRedraw) { + for (var i = 0; i < m_dataToRedraw.hits.length; i++) { + var hit = m_dataToRedraw.hits[i]; + hit.detailLinkId = team.recordElementId(hit.recid[0]); + hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"; + hit.containerClass = "mkws-summary mkwsSummary mkws-team-" + team.name(); + hit.containerClass += " " + hit.detailLinkId; + // ### At some point, we may be able to move the + // m_currentRecordId and m_currentRecordData members + // from the team object into this widget. + if (hit.recid == team.currentRecordId()) { + if (team.currentRecordData()) { + hit.renderedDetails = team.renderDetails(team.currentRecordData()); + } + } + + var urls = hit['md-electronic-url']; + if (urls) { + var bestLink = null; + var otherLinks = []; + for (var j = 0; j < urls.length; j++) { + var url = urls[j]; + if (!url.match(/^(https?:)?\/\//)) { + that.warn("link '" + url + "' is not a valid URL"); + } else if (!bestLink) { + bestLink = url; + } else { + otherLinks.push(url); + } + } + hit.bestLink = bestLink; + hit.otherLinks = otherLinks; + } } + + var template = team.loadTemplate(that.config.template || "records"); + var summaryPartial = team.loadTemplate(that.config['summary-template'] || "summary"); + var tdata = $.extend({}, {"hits": m_dataToRedraw.hits}, that.config.template_vars); + that.node.html(template(tdata, {"partials":{"summary":summaryPartial}})); + } + + m_dataToRedraw = null; + } + + var m_frozen = false; + this.team.queue("records").subscribe(function(data) { + m_dataToRedraw = data; + if (!m_frozen) { + refreshRecordData(); } - var template = team.loadTemplate(that.config.template || "records"); - var summaryPartial = team.loadTemplate(that.config['summary-template'] || "summary"); - var tdata = $.extend({}, {"hits": data.hits}, that.config.template_vars); - that.node.html(template(tdata, {"partials":{"summary":summaryPartial}})); }); + var m_timer; + this.node.mousemove(function() { + var op = that.config.freeze_opacity; + if (op !== undefined) { that.node.css('opacity', op); } + m_frozen = true; + clearTimeout(m_timer); + m_timer = setTimeout(unfreezeRecordDisplay, 1000); + }); + + function unfreezeRecordDisplay() { + clearTimeout(m_timer); + that.node.css('opacity', 1); + m_frozen = false; + refreshRecordData(); + } + this.node.mouseleave(unfreezeRecordDisplay); + that.autosearch(); }); @@ -236,9 +286,10 @@ mkws.registerWidgetType('search', function() { mkws.registerWidgetType('search-form', function() { var team = this.team; + var that = this; this.node.submit(function() { var val = team.widget('query').value(); - team.newSearch(val); + team.newSearch(that, val); return false; }); }); @@ -388,8 +439,10 @@ mkws.registerWidgetType('waiting', function() { var that = this; this.node.css("visibility", "hidden"); - var src = this.config.src || "http://mkws.indexdata.com/progress.gif"; - this.node.html(''); + var template = that.team.loadTemplate(that.config.template || "waiting"); + this.node.html(template({ + src: this.config.src || "http://mkws.indexdata.com/progress.gif" + })); this.team.queue("searchtriggered").subscribe(function(data) { that.node.css("visibility", "visible");