From ac3d47c986ab5db1d6597b5125b34a50bb6ae57b Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Thu, 3 Mar 2011 14:09:55 +0100 Subject: [PATCH] Add link/recipe logic --- mkdru.module | 2 + recipe.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 recipe.js diff --git a/mkdru.module b/mkdru.module index e477eab..0e4daf1 100644 --- a/mkdru.module +++ b/mkdru.module @@ -61,6 +61,8 @@ function mkdru_search_execute($keys = NULL, $conditions = NULL) { drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_library('overlay', 'jquery-bbq'); + drupal_add_js($path . '/recipe.js', + array('type' => 'file', 'scope' => 'footer')); drupal_add_js($path . '/mkdru.theme.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_js($path . '/mkdru.client.js', diff --git a/recipe.js b/recipe.js new file mode 100644 index 0000000..5f380e9 --- /dev/null +++ b/recipe.js @@ -0,0 +1,119 @@ + +function choose_url (data, proxyPattern) { + //first try to prepare local_url from recipe + var local_url = data["md-url_recipe"] !== undefined + ? prepare_url(data["md-url_recipe"][0], data) : null; + + var use_url_proxy = data["md-use_url_proxy"] !== undefined + ? data["md-use_url_proxy"] : "0"; + + //use the proxyPattern + if (proxyPattern && use_url_proxy == "1") { + if (local_url) { + data["md-local-url"] = []; + data["md-local-url"].push(local_url); + } + var ref_local_url = prepare_url(proxyPattern, data); + if (ref_local_url) return ref_local_url; + } + + // proxyPattern failed, go for local + if (local_url) + return local_url; + + //local failed, go for resource + return data["md-electronic-url"] !== undefined + ? data["md-electronic-url"][0] : null; +} + +var XRef = function (url, text) { + this.url = url; + this.text = text; +}; + +function has_recipe (data) { + var has = false; + if (data["md-url_recipe"] !== undefined) { + var recipe = data["md-url_recipe"][0]; + if (typeof recipe == "string" && recipe.length>0) { + has = true; + } + } + return has; +} + +function getUrlFromRecipe (data) { + if (has_recipe(data)) { + return prepare_url(data["md-url_recipe"][0],data); + } else { + return null; + } +} + +function getElectronicUrls (data) { + var urls = []; + if (data["md-electronic-url"] !== undefined) { + for (var i=0; i0 && regex_str.charAt(j) == '/' && regex_str.charAt(j-1) != '\\') + i++; + else + regex_parts[i] += regex_str.charAt(j); + } + var regex_obj = new RegExp(regex_parts[0], regex_parts[2]); + return input_str.replace(regex_obj, regex_parts[1]); +} + +function test_url_recipe() { + var url_recipe = "http://www.indexdata.com/?title=${md-title[\\s+/+/g]}&author=${md-author}"; + var meta_data = { "md-title" : ["Art of Computer Programming"], "md-author" : ["Knuth"]} + var final_url = prepare_url(url_recipe, meta_data); + alert(final_url); +} \ No newline at end of file -- 1.7.10.4