-/* A very simple client that shows a basic usage of the pz2.js
-*/
+/*! MKWS, the MasterKey Widget Set. Copyright (C) 2013-2014, Index Data */
"use strict"; // HTML5: disable for debug_level >= 2
-// Set up namespace and some state.
-var mkws = {};
-
-/*
- * global config object: mkws_config
- *
- * Needs to be defined in the HTML header before including this JS file.
- * Define empty mkws_config for simple applications that don't define it.
- */
-if (!mkws_config)
- var mkws_config = {};
-
-// Wrapper for jQuery
-(function ($) {
+// Set up global mkws object. Contains a hash of session objects,
+// indexed by windowid.
+var mkws = {
+ authenticated: false,
+ sessions: {}
+};
mkws.locale_lang = {
"de": {
"Date": "Datum",
"Subject": "Schlagwort",
"Location": "Ort",
- // ### to add: Records, Targets
+ "Records": "Datensätze",
+ "Targets": "Datenbanken",
"dummy": "dummy"
},
"Date": "Dato",
"Subject": "Emneord",
"Location": "Lokation",
- // ### to add: Records, Targets
+ "Records": "Poster",
+ "Targets": "Baser",
"dummy": "dummy"
}
};
+// Define empty mkws_config for simple applications that don't define it.
+if (mkws_config == null || typeof mkws_config != 'object') {
+ var mkws_config = {};
+}
+
+// wrapper for jQuery lib
+function _make_mkws_team($, teamName) {
+ if (console && console.log)
+ console.log("run _make_mkws_team(" + (teamName ? teamName : "") + ")");
+
+ // call this function only once
+ if (mkws.init) {
+ alert("_make_mkws_team() called twice: how did that happen?!");
+ return;
+ }
+
+var m_sort = 'relevance';
+var m_filters = [];
+
// keep time state for debugging
-mkws.debug_time = {
+var m_debug_time = {
"start": $.now(),
"last": $.now()
};
}
var now = $.now();
- var timestamp = (now - mkws.debug_time.start)/1000 + " (+" + (now - mkws.debug_time.last)/1000 + ") "
- mkws.debug_time.last = now;
+ var timestamp = ((now - m_debug_time.start)/1000).toFixed(3) + " (+" + ((now - m_debug_time.last)/1000).toFixed(3) + ") "
+ m_debug_time.last = now;
// you need to disable use strict at the top of the file!!!
if (mkws.debug_level >= 3) {
console.log(timestamp + string);
}
var debug = mkws.debug_function; // local alias
+debug("start running MKWS");
+
+
+Handlebars.registerHelper('json', function(obj) {
+ return $.toJSON(obj);
+});
+
+
+Handlebars.registerHelper('translate', function(s) {
+ debug("translating '" + s + "'");
+ return M(s);
+});
+
+
+// We need {{attr '@name'}} because Handlebars can't parse {{@name}}
+Handlebars.registerHelper('attr', function(attrName) {
+ return this[attrName];
+});
+
+
+/*
+ * Use as follows: {{#if-any NAME1 having="NAME2"}}
+ * Applicable when NAME1 is the name of an array
+ * The guarded code runs only if at least one element of the NAME1
+ * array has a subelement called NAME2.
+ */
+Handlebars.registerHelper('if-any', function(items, options) {
+ var having = options.hash.having;
+ for (var i in items) {
+ var item = items[i]
+ if (!having || item[having]) {
+ return options.fn(this);
+ }
+ }
+ return "";
+});
+
+
+Handlebars.registerHelper('first', function(items, options) {
+ var having = options.hash.having;
+ for (var i in items) {
+ var item = items[i]
+ if (!having || item[having]) {
+ return options.fn(item);
+ }
+ }
+ return "";
+});
+
+
+Handlebars.registerHelper('commaList', function(items, options) {
+ var out = "";
+
+ for (var i in items) {
+ if (i > 0) out += ", ";
+ out += options.fn(items[i])
+ }
+
+ return out;
+});
+
{
+
/* default mkws config */
var config_default = {
use_service_proxy: true,
+ pazpar2_url: "http://mkws.indexdata.com/service-proxy/",
service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth",
lang: "",
sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
mkws.debug_level = config_default.debug_level;
}
+ // make sure the mkws_config is a valid hash
+ if (!$.isPlainObject(mkws_config)) {
+ debug("ERROR: mkws_config is not an JS object, ignore it....");
+ mkws_config = {};
+ }
+
/* override standard config values by function parameters */
for (var k in config_default) {
if (typeof mkws_config[k] === 'undefined')
}
}
+
+m_sort = mkws_config.sort_default;
+debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to m_sort");
+
if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
debug("Reset query width: " + mkws_config.query_width);
mkws_config.query_width = 50;
}
}
+// protocol independend link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
+if (mkws_config.pazpar2_url.match(/^\/\//)) {
+ mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url;
+ debug("adjust protocol independend links: " + mkws_config.pazpar2_url);
+}
+debug("Create main pz2 object");
// create a parameters array and pass it to the pz2's constructor
// then register the form submit event with the pz2.search function
// autoInit is set to true on default
var my_paz = new pz2( { "onshow": my_onshow,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
- "pazpar2path": mkws_config.pazpar2_url || "http://mkws.indexdata.com/service-proxy/",
+ "pazpar2path": mkws_config.pazpar2_url,
"oninit": my_oninit,
"onstat": my_onstat,
"onterm": my_onterm,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
- "usesessions" : mkws_config.use_service_proxy ? false : true,
+ "usesessions" : mkws_config.use_service_proxy ? false : true,
"showResponseType": '', // or "json" (for debugging?)
"onrecord": my_onrecord } );
-mkws.my_paz = my_paz; // export
-
// some state vars
var curPage = 1;
var recPerPage = 20;
var totalRec = 0;
var curDetRecId = '';
var curDetRecData = null;
-var curSort = 'relevance';
-var curFilter = null;
var submitted = false;
var SourceMax = 16;
var SubjectMax = 10;
var AuthorMax = 10;
+if (!isNaN(parseInt(mkws_config.perpage_default))) {
+ recPerPage = parseInt(mkws_config.perpage_default);
+}
+
//
// pz2.js event handlers:
//
var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- html.push('<div class="record" id="mkwsRecdiv_'+hit.recid+'" >'
- +'<a href="#" id="mkwsRec_'+hit.recid
- +'" onclick="mkws.showDetails(this.id);return false;"><b>'
- + hit["md-title"] +' </b></a>');
- if (hit["md-title-remainder"] !== undefined) {
- html.push('<span>' + hit["md-title-remainder"] + ' </span>');
- }
- if (hit["md-title-responsibility"] !== undefined) {
- html.push('<span><i>'+hit["md-title-responsibility"]+'</i></span>');
- }
- if (hit.recid == curDetRecId) {
+ html.push('<div class="record" id="mkwsRecdiv_' + hit.recid + '" >',
+ renderSummary(hit),
+ '</div>');
+ if (hit.recid == curDetRecId) {
html.push(renderDetails(curDetRecData));
- }
- html.push('</div>');
+ }
}
replaceHtml(results, html.join(''));
}
+
+function renderSummary(hit)
+{
+ if (mkws.templateSummary === undefined) {
+ loadTemplate("Summary");
+ }
+
+ hit._id = "mkwsRec_" + hit.recid;
+ hit._onclick = "mkws.showDetails(this.id);return false;"
+ return mkws.templateSummary(hit);
+}
+
+
function my_onstat(data) {
var stat = document.getElementById("mkwsStat");
if (stat == null)
if (facets[i] == "sources") {
add_single_facet(acc, "Sources", data.xtargets, SourceMax, null);
} else if (facets[i] == "subjects") {
- add_single_facet(acc, "Subjects", data.subject, SubjectMax, "su");
+ add_single_facet(acc, "Subjects", data.subject, SubjectMax, "subject");
} else if (facets[i] == "authors") {
- add_single_facet(acc, "Authors", data.author, AuthorMax, "au");
+ add_single_facet(acc, "Authors", data.author, AuthorMax, "author");
} else {
alert("bad facet configuration: '" + facets[i] + "'");
}
}
var termlist = document.getElementById("mkwsTermlists");
- replaceHtml(termlist, acc.join(''));
+ if (termlist)
+ replaceHtml(termlist, acc.join(''));
}
-function add_single_facet(acc, caption, data, max, cclIndex) {
+function add_single_facet(acc, caption, data, max, pzIndex) {
acc.push('<div class="facet" id="mkwsFacet' + caption + '">');
acc.push('<div class="termtitle">' + M(caption) + '</div>');
for (var i = 0; i < data.length && i < max; i++ ) {
acc.push('<div class="term">');
acc.push('<a href="#" ');
var action;
- if (!cclIndex) {
+ if (!pzIndex) {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
- action = 'mkws.limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
+ action = 'mkws.limitQuery(\'' + pzIndex + '\', this.firstChild.nodeValue)';
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ ' <span>' + data[i].freq + '</span>');
// when search button pressed
function onFormSubmitEventHandler()
{
- resetPage();
- loadSelect();
- triggerSearch();
+ newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ return false;
+}
+
+function newSearch(query, sort, targets, windowid)
+{
+ debug("newSearch: " + query);
+
+ if (mkws_config.use_service_proxy && !mkws.authenticated) {
+ alert("searching before authentication");
+ return;
+ }
+
+ m_filters = []
+ redraw_navi(); // ### should use windowid
+ resetPage(); // ### the globals it resents should be indexed by windowid
+ loadSelect(); // ### should use windowid
+ triggerSearch(query, sort, targets, windowid);
mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
- return false;
}
function onSelectDdChange()
if (!submitted) return false;
resetPage();
loadSelect();
- my_paz.show(0, recPerPage, curSort);
+ my_paz.show(0, recPerPage, m_sort);
return false;
}
totalRec = 0;
}
-function triggerSearch ()
+function triggerSearch (query, sort, targets, windowid)
{
- my_paz.search(document.mkwsSearchForm.mkwsQuery.value, recPerPage, curSort, curFilter);
+ var pp2filter = "";
+ var pp2limit = "";
+
+ // Re-use previous query/sort if new ones are not specified
+ if (query) {
+ mkws.query = query;
+ }
+ if (sort) {
+ m_sort = sort;
+ }
+ if (targets) {
+ // ### should support multiple |-separated targets
+ m_filters.push({ id: targets, name: targets });
+ }
+
+ for (var i in m_filters) {
+ var filter = m_filters[i];
+ if (filter.id) {
+ if (pp2filter)
+ pp2filter += ",";
+ if (filter.id.match(/^[a-z:]+[=~]/)) {
+ debug("filter '" + filter.id + "' already begins with SETTING OP");
+ } else {
+ filter.id = 'pz:id=' + filter.id;
+ }
+ pp2filter += filter.id;
+ } else {
+ if (pp2limit)
+ pp2limit += ",";
+ pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
+ }
+ }
+
+ var params = {};
+ if (pp2limit) {
+ params.limit = pp2limit;
+ }
+ if (windowid) {
+ params.windowid = windowid;
+ }
+ debug("triggerSearch(" + mkws.query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
+
+ my_paz.search(mkws.query, recPerPage, m_sort, pp2filter, undefined, params);
}
function loadSelect ()
{
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
- curSort = document.mkwsSelect.mkwsSort.value;
+ m_sort = document.mkwsSelect.mkwsSort.value;
if (document.mkwsSelect.mkwsPerpage)
recPerPage = document.mkwsSelect.mkwsPerpage.value;
}
// limit the query after clicking the facet
mkws.limitQuery = function (field, value)
{
- document.mkwsSearchForm.mkwsQuery.value += ' and ' + field + '="' + value + '"';
- onFormSubmitEventHandler();
+ debug("limitQuery(field=" + field + ", value=" + value + ")");
+ m_filters.push({ field: field, value: value });
+ redraw_navi();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
}
// limit by target functions
mkws.limitTarget = function (id, name)
{
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML =
- 'Source: <a class="crossout" href="#" onclick="mkws.delimitTarget();return false;">'
- + name + '</a>';
- curFilter = 'pz:id=' + id;
+ debug("limitTarget(id=" + id + ", name=" + name + ")");
+ m_filters.push({ id: id, name: name });
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
return false;
}
-mkws.delimitTarget = function ()
+mkws.delimitQuery = function (field, value)
{
- var navi = document.getElementById('mkwsNavi');
- navi.innerHTML = '';
- curFilter = null;
+ debug("delimitQuery(field=" + field + ", value=" + value + ")");
+ var newFilters = [];
+ for (var i in m_filters) {
+ var filter = m_filters[i];
+ if (filter.field &&
+ field == filter.field &&
+ value == filter.value) {
+ debug("delimitTarget() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
+ }
+ m_filters = newFilters;
+
+ redraw_navi();
+ resetPage();
+ loadSelect();
+ triggerSearch();
+ return false;
+}
+
+
+mkws.delimitTarget = function (id)
+{
+ debug("delimitTarget(id=" + id + ")");
+ var newFilters = [];
+ for (var i in m_filters) {
+ var filter = m_filters[i];
+ if (filter.id) {
+ debug("delimitTarget() removing filter " + $.toJSON(filter));
+ } else {
+ debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ newFilters.push(filter);
+ }
+ }
+ m_filters = newFilters;
+
+ redraw_navi();
resetPage();
loadSelect();
triggerSearch();
return false;
}
+
+function redraw_navi ()
+{
+ var navi = document.getElementById('mkwsNavi');
+ if (!navi) return;
+
+ var text = "";
+ for (var i in m_filters) {
+ if (text) {
+ text += " | ";
+ }
+ var filter = m_filters[i];
+ if (filter.id) {
+ text += 'Source: <a class="crossout" href="#" onclick="mkws.delimitTarget(' +
+ "'" + filter.id + "'" + ');return false;">' + filter.name + '</a>';
+ } else {
+ text += filter.field + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(' +
+ "'" + filter.field + "', '" + filter.value + "'" +
+ ');return false;">' + filter.value + '</a>';
+ }
+ }
+
+ navi.innerHTML = text;
+}
+
+
function drawPager (pagerDiv)
{
//client indexes pages from 1 but pz2 from 0
function renderDetails(data, marker)
{
- var details = '<div class="details" id="mkwsDet_'+data.recid+'"><table>';
- if (marker) details += '<tr><td colspan="2">'+ marker + '</td></tr>';
-
- var locations = [];
- for (var i in data.location) {
- locations.push(data.location[i]['@name']);
- }
-
- details += renderField("Title", data["md-title"], data["md-title-remainder"], data["md-title-responsibility"]);
- details += renderField("Date", data["md-date"]);
- details += renderField("Author", data["md-author"]);
- details += renderField("URL", data["md-electronic-url"]);
- details += renderField("Subject", data["location"][0]["md-subject"]);
- if (locations.length == 0) {
- details += '<tr><td colspan="2">No locations for record!</td></tr>';
- } else {
- details += renderField("Location" + (locations.length == 1 ? "" : "s"), locations);
+ if (mkws.templateRecord === undefined) {
+ loadTemplate("Record");
}
- details += '</table></div>';
- return details;
+ var template = mkws.templateRecord;
+ var details = template(data);
+ return '<div class="details" id="mkwsDet_' + data.recid + '">' + details + '</div>';
}
-function renderField(caption, data, data2, data3) {
- if (data === undefined) {
- return "";
- }
- var res = "";
- for (var i = 0; i < data.length; i++) {
- var s = data[i];
- if (i > 0)
- res += ", ";
-
- if (caption == "URL")
- s = '<a href="' + s + '" target="_blank">' + s + '</a>';
-
- res += s
+function loadTemplate(name)
+{
+ var source = $("#mkwsTemplate" + name).html();
+ if (!source) {
+ source = defaultTemplate(name);
}
- if (data2 != undefined) {
- res = res + " (" + data2 + ")";
- }
+ var template = Handlebars.compile(source);
+ debug("compiled template '" + name + "'");
+ mkws['template' + name] = template;
+}
+
- if (data3 != undefined) {
- res = res + " <i>" + data3 + "</i>";
+function defaultTemplate(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 "URL"}}</th>\
+ <td>\
+ {{#each md-electronic-url}}\
+ <a href="{{this}}">{{this}}</a><br/>\
+ {{/each}}\
+ </td>\
+ </tr>\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ <tr>\
+ <th>{{translate "Subject"}}</th>\
+ <td>\
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{md-subject}}\
+ {{/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}}\
+';
}
- return '<tr><th>' + M(caption) + '</th><td>' + res + '</td></tr>';
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
}
mkws_html_switch();
- if (mkws_config.use_service_proxy)
- mkws_service_proxy_auth(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain);
+ if (mkws_config.use_service_proxy) {
+ mkws_service_proxy_auth(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
+ } else {
+ // raw pp2
+ run_auto_searches();
+ }
if (mkws_config.responsive_design_width) {
// Responsive web design - change layout on the fly based on
}
}
+
+function run_auto_searches() {
+ debug("running auto searches");
+
+ $('[id^="mkwsRecords"]').each(function () {
+ var node = $(this);
+ var query = node.attr('autosearch');
+
+ if (query) {
+ var windowid = undefined;
+ var id = node.attr('id');
+ if (id.match(/^mkwsRecords_/, '')) {
+ windowid = id.replace(/^mkwsRecords_/, '');
+ }
+
+ var sort = node.attr('sort');
+ var targets = node.attr('targets');
+ var s = "running auto search: '" + query + "'";
+ if (windowid) s += " [windowid '" + windowid + "']";
+ if (sort) s += " sorted by '" + sort + "'";
+ if (targets) s += " in targets '" + targets + "'";
+ debug(s);
+ newSearch(query, sort, targets, windowid);
+ }
+ });
+}
+
+
+// implement $.parseQuerystring() for parsing URL parameters
+function parseQuerystring() {
+ var nvpair = {};
+ var qs = window.location.search.replace('?', '');
+ var pairs = qs.split('&');
+ $.each(pairs, function(i, v){
+ var pair = v.split('=');
+ nvpair[pair[0]] = pair[1];
+ });
+ return nvpair;
+}
+
function mkws_set_lang() {
- var lang = $.parseQuerystring().lang || mkws_config.lang;
+ var lang = parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
} else {
}
function mkws_html_sort() {
- debug("HTML sort");
+ debug("HTML sort, m_sort = '" + m_sort + "'");
var sort_html = '<select name="mkwsSort" id="mkwsSort">';
for(var i = 0; i < mkws_config.sort_options.length; i++) {
var val = opt.length == 1 ? opt[0] : opt[1];
sort_html += '<option value="' + key + '"';
- if (key == mkws_config.sort_default) {
+ if (m_sort == key || m_sort == val) {
sort_html += ' selected="selected"';
}
sort_html += '>' + M(val) + '</option>';
* The username/password is configured in the apache config file
* for the site.
*/
-function mkws_service_proxy_auth(auth_url, auth_domain) {
+function mkws_service_proxy_auth(auth_url, auth_domain, pp2_url) {
debug("Run service proxy auth URL: " + auth_url);
+ if (!auth_domain) {
+ auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
+ debug("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ }
+
var request = new pzHttpRequest(auth_url, function(err) {
alert("HTTP call for authentication failed: " + err)
return;
}
debug("Service proxy auth successfully done");
- mkws.service_proxy_auth = true;
+ mkws.authenticated = true;
+ run_auto_searches();
});
}
return mkws.locale_lang[lang][word] || word;
}
+// main
+(function() {
+ try {
+ mkws_html_all()
+ }
+
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
+ }
+})();
+
+ // done
+ mkws.init = true;
+};
+
+
/*
- * implement jQuery plugins
+ * implement jQuery plugin $.pazpar2({})
*/
-$.extend({
- // implement $.parseQuerystring() for parsing URL parameters
- parseQuerystring: function() {
- var nvpair = {};
- var qs = window.location.search.replace('?', '');
- var pairs = qs.split('&');
- $.each(pairs, function(i, v){
- var pair = v.split('=');
- nvpair[pair[0]] = pair[1];
+function _mkws_jquery_plugin ($) {
+ var debug_level = 1;
+
+ function debug (string) {
+ if (!debug_level)
+ return;
+
+ if (typeof console === "undefined" || typeof console.log === "undefined")
+ return;
+
+ console.log("jquery.pazpar2: " + string);
+ }
+
+ function init_popup(obj) {
+ var config = obj ? obj : {};
+
+ var height = config.height || 760;
+ var width = config.width || 880;
+ var id_button = config.id_button || "input#mkwsButton";
+ var id_popup = config.id_popup || "#mkwsPopup";
+
+ debug("popup height: " + height + ", width: " + width);
+
+ // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
+ // <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
+ if (!$.ui) {
+ debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
+ return;
+ }
+
+ $(id_popup).dialog({
+ closeOnEscape: true,
+ autoOpen: false,
+ height: height,
+ width: width,
+ modal: true,
+ resizable: true,
+ buttons: {
+ Cancel: function() {
+ $(this).dialog("close");
+ }
+ },
+ close: function() { }
});
- return nvpair;
- },
- debug2: function(string) { // delayed debug, internal variables are set after dom ready
- setTimeout(function() { debug(string); }, 500);
- },
+ $(id_button)
+ .button()
+ .click(function() {
+ $(id_popup).dialog("open");
+ });
+ };
+
+ $.extend({
// service-proxy or pazpar2
pazpar2: function(config) {
</div>'
if (config && config.layout == 'div') {
- this.debug2("jquery plugin layout: div");
+ debug("jquery plugin layout: div");
document.write(div);
} else if (config && config.layout == 'popup') {
- this.debug2("jquery plugin layout: popup with id: " + id_popup);
+ debug("jquery plugin layout: popup with id: " + id_popup);
document.write(popup);
$(document).ready( function() { init_popup(config); } );
} else {
- this.debug2("jquery plugin layout: table");
+ debug("jquery plugin layout: table");
document.write(table);
}
}
});
-
-function init_popup(obj) {
- var config = obj ? obj : {};
-
- var height = config.height || 760;
- var width = config.width || 880;
- var id_button = config.id_button || "input#mkwsButton";
- var id_popup = config.id_popup || "#mkwsPopup";
-
- debug("popup height: " + height + ", width: " + width);
-
- // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
- // <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
- if (!$.ui) {
- debug("Error: jquery-ui.js is missing, did you included it after jquery core in the HTML file?");
- return;
- }
-
- $(id_popup).dialog({
- closeOnEscape: true,
- autoOpen: false,
- height: height,
- width: width,
- modal: true,
- resizable: true,
- buttons: {
- Cancel: function() {
- $(this).dialog("close");
- }
- },
- close: function() { }
- });
-
- $(id_button)
- .button()
- .click(function() {
- $(id_popup).dialog("open");
- });
};
+// wrapper to call _make_mkws_team() after page load
+(function (j) {
+ // enable before page load, so we could call it before mkws() runs
+ _mkws_jquery_plugin(j);
-
-
-/* magic */
-$(document).ready(function() {
- try {
- mkws_html_all()
- }
-
- catch (e) {
- mkws_config.error = e.message;
- // alert(e.message);
- }
-});
-
+ $(document).ready(function() {
+ // if (console && console.log) console.log("on load ready");
+ _make_mkws_team(j, null);
+ });
})(jQuery);