X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmkws-core.js;h=07a4b2d3f2da9d4cfe15cab77966deb10414d23b;hb=48a4e4a82714887fbcb8121b24cf96adb2b93e97;hp=4ea36ef38d3eaf5ab69641b5d19cf25c7a555de8;hpb=0f1feb1a81659f046de02035e127d61b99e96a09;p=mkws-moved-to-github.git diff --git a/src/mkws-core.js b/src/mkws-core.js index 4ea36ef..07a4b2d 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -96,14 +96,14 @@ mkws.log = function(string) { }; -mkws.objectWithParent = function(parent) { - function thing() {} // Must be function so `prototype' works - - thing.prototype = parent; - var res = new thing(); - thing.prototype = null; - return res; -}; +// This function is taken from a StackOverflow answer +// http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144 +mkws.getParameterByName = function(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); +} mkws.registerWidgetType = function(name, fn) { @@ -144,13 +144,25 @@ mkws.setMkwsConfig = function(overrides) { dummy: "dummy" }; - mkws.config = Object.create(config_default); + mkws.config = mkws.objectInheritingFrom(config_default); for (var k in overrides) { mkws.config[k] = overrides[k]; } }; +// This code is from Douglas Crockford's article "Prototypal Inheritance in JavaScript" +// http://javascript.crockford.com/prototypal.html +// mkws.objectInheritingFrom behaves the same as Object.create, +// but since the latter is not available in IE8 we can't use it. +// +mkws.objectInheritingFrom = function(o) { + function F() {} + F.prototype = o; + return new F(); +} + + // The following functions are dispatchers for team methods that // are called from the UI using a team-name rather than implicit // context. @@ -217,6 +229,8 @@ mkws.pagerNext = function(tname) { type = cname.replace(/^mkws/, ''); } } + + if (!teamName) teamName = "AUTO"; callback.call(node, teamName, type); } @@ -298,25 +312,19 @@ mkws.pagerNext = function(tname) { log("running auto searches"); for (var teamName in mkws.teams) { - mkws.teams[teamName].runAutoSearch(); + mkws.teams[teamName].queue("ready").publish(); } } - - // I don't understand why I need this copy, but I do: mkws_config - // is not visible inside the document.ready function, but the - // saved copy is. - var saved_config; - if (typeof mkws_config === 'undefined') { - log("setting empty config"); - saved_config = {}; - } else { - log("using config: " + $.toJSON(mkws_config)); - saved_config = mkws_config; - } - - $(document).ready(function() { + var saved_config; + if (typeof mkws_config === 'undefined') { + log("setting empty config"); + saved_config = {}; + } else { + log("using config: " + $.toJSON(mkws_config)); + saved_config = mkws_config; + } mkws.setMkwsConfig(saved_config); for (var key in mkws.config) { @@ -363,15 +371,6 @@ mkws.pagerNext = function(tname) { } } - // For all MKWS-classed nodes that don't have a team - // specified, set the team to AUTO. - $('[class^="mkws"],[class*=" mkws"]').each(function() { - if (!this.className.match(/mkwsTeam_/)) { - log("adding AUTO team to node with class '" + this.className + "'"); - $(this).addClass('mkwsTeam_AUTO'); - } - }); - // Find all nodes with an MKWS class, and determine their team from // the mkwsTeam_* class. Make all team objects. var then = $.now(); @@ -391,11 +390,22 @@ mkws.pagerNext = function(tname) { handleNodeWithTeam(this, function(tname, type) { var myTeam = mkws.teams[tname]; var myWidget = widget(j, myTeam, type, this); + myTeam.addWidget(myWidget); }); }); var now = $.now(); log("Walking MKWS nodes took " + (now-then) + " ms"); +// for (var tName in mkws.teams) { +// var myTeam = mkws.teams[tName] +// var types = myTeam.widgetTypes(); +// log("TEAM '" + tName + "' = " + myTeam + " has widget types " + types); +// for (var i = 0; i < types.length; i++) { +// var type = types[i]; +// log(" has widget of type '" + type + "': " + myTeam.widget(type)); +// } +// } + if (mkws.config.use_service_proxy) { authenticateSession(mkws.config.service_proxy_auth, mkws.config.service_proxy_auth_domain,