From: Jakub Skoczen Date: Thu, 2 Dec 2010 14:12:16 +0000 (+0100) Subject: Rough implementation of 'ting_search_show' X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=92f23f8e3751e247fea54584fb84fb9266bb4ec9;p=mkdru-moved-to-drupal.org.git Rough implementation of 'ting_search_show' We spill out the basic result-set theme when the hook is invoked, pass the query as the JS Drupal var and autosearch in the client if the query is detected. --- diff --git a/mkdru.client.js b/mkdru.client.js index 5b0ce75..95c9bf5 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -21,8 +21,9 @@ var mkdru = { // pz2.js event handlers: mkdru.pz2Init = function () { - mkdru.pz2.stat(); - mkdru.pz2.bytarget(); + if (mkdru.query) mkdru.triggerSearch(); + //mkdru.pz2.stat(); + //mkdru.pz2.bytarget(); }; mkdru.pz2Show = function (data) { @@ -97,6 +98,7 @@ mkdru.pz2ByTarget = function (data) { // UI functions: mkdru.submitQuery = function () { + mkdru.query = $('.mkdru-search input:text').attr('value'); mkdru.resetPage(); mkdru.pollDropDowns(); mkdru.search(); @@ -104,9 +106,14 @@ mkdru.submitQuery = function () { return false; }; +mkdru.triggerSearch = function () { + mkdru.search(); + mkdru.submitted = true; +}; + mkdru.search = function () { - mkdru.pz2.search($('.mkdru-search input:text').attr('value'), - mkdru.recPerPage, mkdru.curSort, mkdru.curFilter); + mkdru.pz2.search(mkdru.query, mkdru.recPerPage, mkdru.curSort, + mkdru.curFilter); }; mkdru.pollDropDowns = function () { @@ -179,5 +186,12 @@ $(document).ready(function () { "onbytarget": mkdru.pz2ByTarget, "usesessions" : mkdru.usesessions, "showResponseType": mkdru.showResponseType, - "onrecord": mkdru.pz2Record } ); -}); \ No newline at end of file + "onrecord": mkdru.pz2Record, + "autoInit": false } ); + mkdru.query = Drupal.settings.mkdru.query; + if (mkdru.usesessions) { + mkdru.pz2.init(); + } else if (mkdru.query) { + mkdru.triggerSearch(); + } +}); diff --git a/mkdru.module b/mkdru.module index b5718cc..51df633 100644 --- a/mkdru.module +++ b/mkdru.module @@ -18,7 +18,17 @@ function mkdru_node_info() { } function mkdru_ting_search_show($params) { - return array("content" => "You have searched for '".$params['keys']."'."); + $path = drupal_get_path('module', 'mkdru'); + // Include client library. + drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') + . '/pz2.js', 'module', 'footer'); + drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer'); + drupal_add_js($path . '/mkdru.client.js', 'module', 'footer'); + $html = theme('mkdru_results'); + drupal_add_js(array('mkdru' => + array('use_sessions' => '1', 'query' => $params['keys'] + )), 'setting'); + return array("content" => $html); } /**