From: Mike Taylor Date: Fri, 17 Oct 2014 14:25:58 +0000 (+0100) Subject: Towards MKWS-294 (Change names of MKWS classes to be case-insensitive) X-Git-Tag: 1.0.0~155^2~16 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=f944d2112f977ffe31545ceaee8a1ebeb1e128d8;p=mkws-moved-to-github.git Towards MKWS-294 (Change names of MKWS classes to be case-insensitive) The code now runs with the new-style classes. But there is lots more to do. Running applications are as ugly as sin because the CSS styles don't yet apply; use of teams has yet to be tested; backwards compatibility is only partly implemented; many examples need testing under the compatibility rules, then upgrading --- diff --git a/src/mkws-core.js b/src/mkws-core.js index 3a4fa5b..df7382f 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -286,6 +286,16 @@ mkws.log("Using window.name '" + window.name + "'"); // wrapper to provide local copy of the jQuery object. (function($) { var log = mkws.log; + var _old2new = { // Maps old-style widget names to new-style + 'Authname': 'auth-name', + 'ConsoleBuilder': 'console-builder', + 'Coverart': 'cover-art', + 'GoogleImage': 'google-image', + 'MOTD': 'motd', + 'MOTDContainer': 'motd-container', + 'Perpage': 'per-page', + 'SearchForm': 'search-form', + }; function handleNodeWithTeam(node, callback) { // First branch for DOM objects; second branch for jQuery objects @@ -303,10 +313,15 @@ mkws.log("Using window.name '" + window.name + "'"); for (var i = 0; i < list.length; i++) { var cname = list[i]; - if (cname.match(/^mkwsTeam_/)) { - teamName = cname.replace(/^mkwsTeam_/, ''); + if (cname.match(/^mkws-team-/)) { + teamName = cname.replace(/^mkws-team-/, ''); + } else if (cname.match(/^mkws-/)) { + // New-style names of the form mkws-foo-bar + type = cname.replace(/^mkws-/, ''); } else if (cname.match(/^mkws/)) { - type = cname.replace(/^mkws/, ''); + // Old-style names of the form mkwsFooBar + var tmp = cname.replace(/^mkws/, ''); + type = _old2new[tmp] || tmp; } } @@ -353,8 +368,8 @@ mkws.log("Using window.name '" + window.name + "'"); for (var tname in mkws.teams) { var team = mkws.teams[tname]; team.visitWidgets(function(t, w) { - var w1 = team.widget(t + "-Container-" + from); - var w2 = team.widget(t + "-Container-" + to); + var w1 = team.widget(t + "-container-" + from); + var w2 = team.widget(t + "-container-" + to); if (w1) { w1.node.hide(); } @@ -443,9 +458,10 @@ mkws.log("Using window.name '" + window.name + "'"); var s = ""; for (var type in mkws.widgetType2function) { if (s) s += ','; - s += '.mkws' + type; - s += ',.mkws' + type + "-Container-wide"; - s += ',.mkws' + type + "-Container-narrow"; + s += '.mkws-' + type; + s += ',.mkws-' + type + "-container-wide"; + s += ',.mkws-' + type + "-container-narrow"; + // ### Do we need to do something about old-style names? } return s; } diff --git a/src/mkws-popup.js b/src/mkws-popup.js index 7496a07..ee26049 100644 --- a/src/mkws-popup.js +++ b/src/mkws-popup.js @@ -4,13 +4,13 @@ //"use strict"; // $(document).ready(function () { -mkws.registerWidgetType('Popup', function() { +mkws.registerWidgetType('popup', function() { var $ = mkws.$; var debug = mkws.log; debug("init popup window"); var popup_window = $(this.node); - // var popup_window = $(".mkwsPopup"); // $(document).ready() + // var popup_window = $(".mkws-popup"); // $(document).ready() if (!popup_window) { debug("no popup found, skip..."); return; @@ -49,7 +49,7 @@ mkws.registerWidgetType('Popup', function() { close: function() {} }); - // open at search query submit: "input.mkwsButton" + // open at search query submit: "input.mkws-button" var id_botton = that.attr("popup_button"); if (id_botton) { $(id_botton).button().click(function() { diff --git a/src/mkws-team.js b/src/mkws-team.js index 0879add..0825553 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -191,13 +191,13 @@ mkws.makeTeam = function($, teamName) { // Used by the Records widget and onRecord() function recordElementId(s) { - return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_'); + return 'mkws-rec_' + s.replace(/[^a-z0-9]/ig, '_'); } that.recordElementId = recordElementId; // Used by onRecord(), showDetails() and renderDetails() function recordDetailsId(s) { - return 'mkwsDet_' + s.replace(/[^a-z0-9]/ig, '_'); + return 'mkws-det_' + s.replace(/[^a-z0-9]/ig, '_'); } @@ -390,10 +390,10 @@ mkws.makeTeam = function($, teamName) { teamName = teamName || m_teamName; if (teamName === 'AUTO') { - selector = (selector + '.mkwsTeam_' + teamName + ',' + - selector + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"])'); + selector = (selector + '.mkws-team-' + teamName + ',' + + selector + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"],[class^="mkws-team-"],[class*=" mkws-team-"])'); } else { - selector = selector + '.mkwsTeam_' + teamName; + selector = selector + '.mkws-team-' + teamName; } var node = $(selector); @@ -410,7 +410,7 @@ mkws.makeTeam = function($, teamName) { function renderDetails(data, marker) { var template = loadTemplate("Record"); var details = template(data); - return '
' + details + '
'; } that.renderDetails = renderDetails; @@ -425,9 +425,9 @@ mkws.makeTeam = function($, teamName) { var template = m_template[name]; if (template === undefined && Handlebars.compile) { var source; - var node = $(".mkwsTemplate_" + name + " .mkwsTeam_" + that.name()); + var node = $(".mkws-template_" + name + " .mkws-team-" + that.name()); if (node && node.length < 1) { - node = $(".mkwsTemplate_" + name); + node = $(".mkws-template_" + name); } if (node) source = node.html(); if (!source) source = m_templateText[name]; diff --git a/src/mkws-widget-authname.js b/src/mkws-widget-authname.js index b1e0b1f..b96dad2 100644 --- a/src/mkws-widget-authname.js +++ b/src/mkws-widget-authname.js @@ -1,4 +1,4 @@ -mkws.registerWidgetType('Authname', function() { +mkws.registerWidgetType('auth-name', function() { var that = this; this.team.queue("authenticated").subscribe(function(authName) { diff --git a/src/mkws-widget-builder.js b/src/mkws-widget-builder.js index 6468e86..dac54ab 100644 --- a/src/mkws-widget-builder.js +++ b/src/mkws-widget-builder.js @@ -1,4 +1,4 @@ -mkws.registerWidgetType('Builder', function() { +mkws.registerWidgetType('builder', function() { var that = this; var team = this.team; @@ -8,11 +8,11 @@ mkws.registerWidgetType('Builder', function() { }); this.node.append(button); button.click(function() { - var query = team.widget('Query').value(); - var sort = team.widget('Sort').value(); - var perpage = team.widget('Perpage').value(); + var query = team.widget('query').value(); + var sort = team.widget('sort').value(); + var perpage = team.widget('per-page').value(); - var html = ('
'); @@ -21,8 +21,8 @@ mkws.registerWidgetType('Builder', function() { }); }); -mkws.registerWidgetType('ConsoleBuilder', function() { - mkws.promotionFunction('Builder').call(this); +mkws.registerWidgetType('console-builder', function() { + mkws.promotionFunction('builder').call(this); this.callback = function(s) { console.log("generated widget: " + s); } diff --git a/src/mkws-widget-categories.js b/src/mkws-widget-categories.js index 6982db8..754e68b 100644 --- a/src/mkws-widget-categories.js +++ b/src/mkws-widget-categories.js @@ -1,4 +1,4 @@ -mkws.registerWidgetType('Categories', function() { +mkws.registerWidgetType('categories', function() { var that = this; if (!mkws.authenticated) { @@ -20,7 +20,7 @@ mkws.registerWidgetType('Categories', function() { var text = []; text.push("Select category: "); - text.push(" + + - +
+ +
diff --git a/src/mkws.templates/Stat.handlebars b/src/mkws.templates/Stat.handlebars index d8ae997..c912c22 100644 --- a/src/mkws.templates/Stat.handlebars +++ b/src/mkws.templates/Stat.handlebars @@ -6,4 +6,4 @@ clients - total targets for this search records - number of records returned and available hits - number of hits across all targets }} - -- {{{mkws-translate "Active clients"}}} : {{activeclients}}/{{clients}} -- {{{mkws-translate "Retrieved records"}}} : {{records}}/{{hits}} + -- {{{mkws-translate "Active clients"}}} : {{activeclients}}/{{clients}} -- {{{mkws-translate "Retrieved records"}}} : {{records}}/{{hits}} diff --git a/src/mkws.templates/Termlists.handlebars b/src/mkws.templates/Termlists.handlebars index 7c6f3b8..5ee6f6b 100644 --- a/src/mkws.templates/Termlists.handlebars +++ b/src/mkws.templates/Termlists.handlebars @@ -5,7 +5,7 @@ team - the current team facets - array of facet names }} -
Termlists
+
Termlists
{{#each facets}} -
+
{{/each}}