From: Jason Skomorowski Date: Fri, 16 May 2014 05:00:11 +0000 (-0400) Subject: Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkws X-Git-Tag: 1.0.0~666 X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=commitdiff_plain;h=82b78674032447e08477c34258c999fea92cbadc;hp=16708a6aebe10acd3b72bcb20b03c54d1195a1b9 Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkws --- diff --git a/examples/htdocs/mkws-widget-ru.css b/examples/htdocs/mkws-widget-ru.css new file mode 100644 index 0000000..39765ff --- /dev/null +++ b/examples/htdocs/mkws-widget-ru.css @@ -0,0 +1,31 @@ +.mkwsReferenceUniverse { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + background: #FCFBFA; + padding: 0.5em 1em 0.25em; + box-shadow: 0 0 2px 0 #7F8F93; + border-radius: 0 0 1.5em; + -moz-border-radius: 0 0 1.5em; + -webkit-border-radius: 0 0 1.5em; + line-height: 1.4; + color: #86979B; + background: radial-gradient(ellipse at center, #ffffff 0%,#f8f8f8 100%); +} + +h2 { + font-size: 100%; + color: #4A5456; + padding-bottom: .5em; +} + +.record, .mkwsSummary { + margin: .95em .25em; + padding-top: .75em; + border-top: 1px dotted #BEC8CC; + font-size: 90%; +} + +a { + text-decoration: none; + font-weight:normal; + color: #2B77AF; +} diff --git a/examples/htdocs/mkws-widget-ru.html b/examples/htdocs/mkws-widget-ru.html new file mode 100644 index 0000000..64ef386 --- /dev/null +++ b/examples/htdocs/mkws-widget-ru.html @@ -0,0 +1,8 @@ + +
+ + + +
+
+ diff --git a/examples/htdocs/mkws-widget-ru.js b/examples/htdocs/mkws-widget-ru.js new file mode 100644 index 0000000..e38d957 --- /dev/null +++ b/examples/htdocs/mkws-widget-ru.js @@ -0,0 +1,11 @@ +mkws.registerWidgetType('ReferenceUniverse', function() { + //this.team.config.service_proxy_auth = "http://mkws.indexdata.com/service-proxy/?command=auth&action=login&username=paratext&password=paratext_mkc"; + // this.team.config.perpage_default = 5; + // this.team.config.sort_default = "position"; + var teamClass = 'mkwsTeam_' + this.team.name(); + var html = "

Reference Universe results:

\n"; + html += '
'; + $(this.node).html(html); +}); diff --git a/examples/htdocs/mkws-widget-ru.readme b/examples/htdocs/mkws-widget-ru.readme new file mode 100644 index 0000000..c55272e --- /dev/null +++ b/examples/htdocs/mkws-widget-ru.readme @@ -0,0 +1,34 @@ +# Embedding Reference Universe with MKWS + +## Quick start +Simply paste this inline with the markup on any page: + + + + +
+ +## A bit more detail + +The MasterKey Widget Set ([MKWS](http://mkws.indexdata.com/)) lets you easily embed search-enabled widgets which run in the client browser and display results from a web service. In this case, it searches Reference Universe. + +You need to include two scripts: one for MKWS and one for the Reference Universe widget. This can be inline as above or you can include them in the header or aggregate them with your application's scripts. + + + + +The provided stylesheet is generic and you're encouraged to replace it entirely by styling the new elements to fit seamlessly with your content. + + + +Any element you give the class `mkwsReferenceUniverse` will have is contents replaced by the top results from a search against the Reference Universe service for the current query. + +
+ +### Finding the query + +The `autosearch` attribute of the widget container lets it know where to find the query. There are three places it might look to find that you're searching for *water*: + +* `!param!foo` indicates a GET parameter and would match `http://site.tld/search?foo=water` +* `!path!2` will take the 2nd path component from the end of the url and would find the query in `http://site.tld/apps/search/water/mobile` +* `!var!foo` will look for the query in a JavaScript variable named `foo` in the `window` context (ie. a top level variable) diff --git a/src/mkws-core.js b/src/mkws-core.js index 6341087..0af84a9 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -430,7 +430,7 @@ mkws.pagerNext = function(tname) { function selectorForAllWidgets() { - if (mkws.config.scan_all_nodes) { + if (mkws.config && mkws.config.scan_all_nodes) { // This is the old version, which works by telling jQuery to // find every node that has a class beginning with "mkws". In // theory it should be slower than the class-based selector; but @@ -479,7 +479,8 @@ mkws.pagerNext = function(tname) { } - $(document).ready(function() { + function init(rootsel) { + if (!rootsel) var rootsel = ':root'; var saved_config; if (typeof mkws_config === 'undefined') { log("setting empty config"); @@ -544,7 +545,7 @@ mkws.pagerNext = function(tname) { } var then = $.now(); - makeWidgetsWithin(1, $(':root')); + makeWidgetsWithin(1, $(rootsel)); var now = $.now(); log("walking MKWS nodes took " + (now-then) + " ms"); @@ -567,5 +568,9 @@ mkws.pagerNext = function(tname) { // raw pp2 runAutoSearches(); } + }; + $(document).ready(function() { + var widgetSelector = selectorForAllWidgets(); + if (widgetSelector && $(widgetSelector).length !== 0) init(); }); })(jQuery);