Initial commit
authorJason Skomorowski <jason@indexdata.com>
Tue, 11 Jun 2013 18:34:41 +0000 (18:34 +0000)
committerJason Skomorowski <jason@indexdata.com>
Tue, 11 Jun 2013 18:34:41 +0000 (18:34 +0000)
css/customtheme.css [new file with mode: 0644]
customtheme.js [new file with mode: 0644]
images/search-button.png [new file with mode: 0644]
logo.png [new file with mode: 0644]
mkdrusampletheme.info [new file with mode: 0644]
pz2urlrecipe.js [new file with mode: 0644]
template.php [new file with mode: 0644]
templates/mkdru-block-facet.tpl.php [new file with mode: 0644]
templates/mkdru-block-search.tpl.php [new file with mode: 0644]
templates/mkdru-form.tpl.php [new file with mode: 0644]
templates/mkdru-results.tpl.php [new file with mode: 0644]

diff --git a/css/customtheme.css b/css/customtheme.css
new file mode 100644 (file)
index 0000000..9198573
--- /dev/null
@@ -0,0 +1,75 @@
+.mkdru-result-description {
+  font-size: 0.8em;
+}
+
+.mkdru-above-below {
+  font-size: 0.9em;
+  border: 0;
+  padding: 0.25em;
+  font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,sans-serif;
+}
+.mkdru-above {
+  border-bottom: 1px solid #D6D6D6;
+}
+.mkdru-below {
+  border-top: 1px solid #D6D6D6;
+  text-align: center;
+}
+
+
+.mkdru-result {
+  padding: .8em 1em 1em 1em !important;
+  border-bottom: 3px solid #FFFFFF;
+/*   margin-top: 0 !important; */
+/*   margin-bottom: 0 !important; */
+}
+.mkdru-result.odd {
+  background-color: #f6f6f2;
+}
+.mkdru-result.even {
+  background-color: #ebebe7;
+}
+.mkdru-result div {
+  margin-top: 0;
+  margin-bottom: .3em;
+}
+.mkdru-result-author {
+  margin-left: 1em !important;
+}
+.mkdru-result-description {
+  font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,sans-serif;
+}
+
+
+.mkdru-search {
+  text-align: left;
+}
+.mkdru-search input[type='text'] {
+  width: 100%;
+}
+.mkdru-search input[type='submit'] {
+  margin-left: 12px;
+}
+
+
+.mkdru-facet {
+  font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,sans-serif;
+}
+
+
+.mkdru-block-search input.form-text {
+  margin-right: 5px;
+  width: 9.5em;
+}
+.mkdru-block-search input.form-submit {
+    background: url("../images/search-button.png") no-repeat scroll center top transparent;
+    border-color: #E4E4E4 #D2D2D2 #B4B4B4;
+    cursor: pointer;
+    height: 25px;
+    margin-left: 0;
+    margin-right: 0;
+    overflow: hidden;
+    padding: 0;
+    text-indent: -9999px;
+    width: 34px;
+}
\ No newline at end of file
diff --git a/customtheme.js b/customtheme.js
new file mode 100644 (file)
index 0000000..9ba1f61
--- /dev/null
@@ -0,0 +1,88 @@
+Drupal.theme.mkdruCounts = function(first, last, available, total) {
+  if (last > 0)
+    return '<strong>' + first  + '</strong>' + Drupal.t(' to ') + '<strong>' + last + '</strong>' + Drupal.t(' of ') + '<strong>'
+      + available + '</strong>' + Drupal.t(' available');
+  else
+    return Drupal.t('No results');
+};
+
+Drupal.theme.mkdruResult = function(hit, num, detailLink) {
+  var resultclass = "mkdru-result ";
+  if (num%2)
+    resultclass += "odd";
+  else
+    resultclass += "even";
+  var html = "";
+  html += '<li class="' + resultclass + '" id="rec_' + hit.recid + '" >'
+          + '<div class="mkdru-result-title"><a href="' + detailLink + '">'
+          + hit["md-title"] + '</a>';
+  if (hit["md-title-remainder"] !== undefined) {
+    html += ' <span class="mkdru-result-title-remainder">'
+            + hit["md-title-remainder"] + ' </span>';
+  }
+  html += '</div>';
+  if (hit["md-title-responsibility"] !== undefined) {
+    html += '<div class="mkdru-result-author"><em>'
+            + hit["md-title-responsibility"]
+            + '</em> ';
+    if (hit["md-date"] !== undefined) {
+      html += hit["md-date"];
+    }
+    html += '</div>';
+  }
+  if (hit["md-description"] !== undefined) {
+    // limit description to 400 characters
+    html += '<div class="mkdru-result-description">'
+            + String(hit["md-description"]).substr(0, 400)
+            + ' </div>';
+  }
+
+  html += '</li>';
+  return html;
+};
+
+Drupal.theme.mkdruDetail = function(data, linkBack) {
+  var html = '<table id="det_' + data.recid +'">';
+  if (data["md-title"] != undefined) {
+    html += '<tr><th>' + Drupal.t("Title") + '</th><td>'
+            + data["md-title"];
+    if (data["md-title-remainder"] !== undefined) {
+      html += ' : <span>' + data["md-title-remainder"] + ' </span>';
+    }
+    if (data["md-title-responsibility"] !== undefined) {
+      html += ' <span><i>'+ data["md-title-responsibility"] +'</i></span>';
+    }
+    html += '</td></tr>';
+  }
+  if (data["md-date"] != undefined)
+    html += '<tr><th>' + Drupal.t("Date") + '</th><td>' + data["md-date"] + '</td></tr>';
+  if (data["md-author"] != undefined)
+    html += '<tr><th>' + Drupal.t("Author") + '</th><td>' + data["md-author"] + '</td></tr>';
+  if (data["md-electronic-url"] != undefined)
+    html += '<tr><th>URL</th><td><a href="'
+            + data["md-electronic-url"] + '" target="_blank">'
+            + data["md-electronic-url"] + '</a>' + '</td></tr>';
+  // test if there is an array of per-location data; process it
+  if (Object.prototype.toString.call(data['location']) === '[object Array]') { 
+    var subject = false;
+    var locations = ""; 
+    for (var i = 0; i < data['location'].length; i++) {
+      var locRec = data['location'][i];
+      // grab the first value we find for subject
+      if (!subject && locRec['md-subject']) subject = locRec['md-subject'];
+      // list named locations and link to the record there if url is available
+      var link = locRec["md-electronic-url"];
+      if (!link) link = pz2urlrecipe.getUrlFromRecipe(locRec);
+      var name = locRec["@name"]
+      if (link && name) locations += '<a href="' + link + '">' + name + '</a><br>';
+      else if (name) locations += name + '<br>';
+    }
+    if (subject)
+      html += '<tr><th>' + Drupal.t("Subject") + '</th><td>' + subject + '</td></tr>';
+    if (locations)
+      html += '<tr><th>' + Drupal.t("Location") + '</th><td>' + locations + '</td></tr>';
+  }
+  html += '</table>';
+  html += '<a href="' + linkBack + '">' + Drupal.t('Return to result list...') + '</a>';
+  return html;
+};
diff --git a/images/search-button.png b/images/search-button.png
new file mode 100644 (file)
index 0000000..c6e820a
Binary files /dev/null and b/images/search-button.png differ
diff --git a/logo.png b/logo.png
new file mode 100644 (file)
index 0000000..0ada453
Binary files /dev/null and b/logo.png differ
diff --git a/mkdrusampletheme.info b/mkdrusampletheme.info
new file mode 100644 (file)
index 0000000..f07939c
--- /dev/null
@@ -0,0 +1,27 @@
+name = MkDru Subtheme Example 
+description = A demonstration using Drupal theming to customise MkDru. 
+core = 7.x
+base theme = bartik
+
+stylesheets[all][] = css/customtheme.css
+
+regions[header] = Header
+regions[help] = Help
+regions[page_top] = Page top
+regions[page_bottom] = Page bottom
+regions[highlighted] = Highlighted
+
+regions[featured] = Featured
+regions[content] = Content
+regions[sidebar_first] = Sidebar first
+regions[sidebar_second] = Sidebar second
+
+regions[triptych_first] = Triptych first
+regions[triptych_middle] = Triptych middle
+regions[triptych_last] = Triptych last
+
+regions[footer_firstcolumn] = Footer first column
+regions[footer_secondcolumn] = Footer second column
+regions[footer_thirdcolumn] = Footer third column
+regions[footer_fourthcolumn] = Footer fourth column
+regions[footer] = Footer
diff --git a/pz2urlrecipe.js b/pz2urlrecipe.js
new file mode 100644 (file)
index 0000000..087edb5
--- /dev/null
@@ -0,0 +1,133 @@
+var pz2urlrecipe = (function() {
+  var choose_url = function (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;  
+  };
+
+  var has_recipe = function (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;
+  }
+
+  var getUrlFromRecipe = function (data) {
+    if (has_recipe(data)) {
+      return prepare_url(data["md-url_recipe"][0],data);
+    } else {
+      return null;
+    }  
+  }
+
+  var getElectronicUrls = function (data) {
+    var urls = [];
+    if (data["md-electronic-url"] !== undefined) {
+      for (var i=0; i<data["md-electronic-url"].length; i++) {
+        var linkUrl = data["md-electronic-url"][i];
+        var linkText = (data["md-electronic-text"]) ? data["md-electronic-text"][i] : "Web Link";
+        var ref = new XRef(linkUrl, (linkText.length==0 ? "Web Link" : linkText));
+        urls.push(ref);
+      }
+    }
+    return urls;
+  }
+
+
+  // Prepares urls from recipes with expressions in the form:
+  // ${variable-name[pattern/replacement/mode]}, [regex] is optional
+  // eg. http://sever.com?title=${md-title[\s+//]} will strip all whitespaces 
+  var prepare_url = function (url_recipe, meta_data) {
+    if (typeof url_recipe != "string" || url_recipe.length == 0)
+        return null;
+    if (typeof meta_data != "object")
+        return null;
+    try {
+        var result =  url_recipe.replace(/\${[^}]*}/g, function (match) { 
+          return get_var_value(match, meta_data);
+          }
+        );
+        //url encoding for %{} vars
+        result =  result.replace(/\%{[^}]*}/g, function (match) { 
+          return encodeURIComponent(get_var_value(match, meta_data));
+          }
+        );
+        return result;
+    } catch (e) {
+        return "Malformed URL recipe: " + e.message;
+    }
+  }
+
+  var get_var_value = function (expr_in, meta_data) {
+    //strip ${ and }
+    var expr = expr_in.substring(2, expr_in.length-1)
+    if (expr == "") return "";
+    //extract name
+    var var_name = expr.match(/^[^\[]+/)[0];
+    if (typeof meta_data[var_name] == "undefined") return "";
+    else var var_value = meta_data[var_name][0];
+    if (var_name.length < expr.length) { //possibly a regex
+       var_value = exec_sregex(
+          expr.substring(var_name.length+1, expr.length-1),
+          var_value);
+    }
+    return var_value;
+  }
+
+  // exec perl-like substitution regexes in the form: pattern/replacement/mode
+  var exec_sregex = function (regex_str, input_str) {   
+    var regex_parts = ["", "", ""];
+    var i = 0;
+    for (var j=0; j<regex_str.length && i<3; j++) {
+      if (j>0 && 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]);    
+  }
+
+  var test_url_recipe = function () {
+    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);
+  }
+
+  // expose public methods
+  return {
+    getUrlFromRecipe: getUrlFromRecipe,
+    getElectronicUrls: getElectronicUrls,
+  };
+})();
diff --git a/template.php b/template.php
new file mode 100644 (file)
index 0000000..7ad3a78
--- /dev/null
@@ -0,0 +1,11 @@
+<?php 
+function mkdrusampletheme_preprocess_page(&$vars, $hook) {
+  # only include theme functions on search nodes since, by default, mkdru
+  # will only load the client js there
+  if (isset($vars['node']) && ($vars['node']->type == 'mkdru')) {
+    # helper functions to apply URL recipes
+    drupal_add_js(drupal_get_path('theme', 'mkdrusampletheme') . '/pz2urlrecipe.js');
+    drupal_add_js(drupal_get_path('theme', 'mkdrusampletheme') . '/customtheme.js');
+  }
+}
+
diff --git a/templates/mkdru-block-facet.tpl.php b/templates/mkdru-block-facet.tpl.php
new file mode 100644 (file)
index 0000000..c32aed9
--- /dev/null
@@ -0,0 +1 @@
+<div class="mkdru-facet <?php print $class ?>"> </div>
diff --git a/templates/mkdru-block-search.tpl.php b/templates/mkdru-block-search.tpl.php
new file mode 100644 (file)
index 0000000..17ef61d
--- /dev/null
@@ -0,0 +1,4 @@
+<form class="mkdru-block-search" id="mkdru-block-search-<?php print $nid ?>" target="_blank" onsubmit="document.location.href = '<?php print $path ?>#query=' + jQuery('#mkdru-block-search-<?php print $nid ?> input:text').attr('value'); return false;">
+  <input class="form-text" type="text"/>
+  <input class="form-submit" type="submit" value="Search">
+</form>
diff --git a/templates/mkdru-form.tpl.php b/templates/mkdru-form.tpl.php
new file mode 100644 (file)
index 0000000..aaddba3
--- /dev/null
@@ -0,0 +1,19 @@
+<form class="mkdru-search">
+  <p><input class="form-text" type="text"/></p>
+  <p>Sort by
+  <select class="mkdru-sort form-select">
+    <option value="relevance" selected="selected">relevance</option>
+    <option value="title:1">title</option>
+    <option value="date:0">newest</option>
+    <option value="date:1">oldest</option>
+  </select>
+  and show 
+  <select class="mkdru-perpage form-select">
+    <option value="10">10</option>
+    <option value="20" selected="selected">20</option>
+    <option value="30">30</option>
+    <option value="50">50</option>
+  </select>
+  per page.
+  <input class="form-submit" type="submit" value="Search"/><p>
+</form>
\ No newline at end of file
diff --git a/templates/mkdru-results.tpl.php b/templates/mkdru-results.tpl.php
new file mode 100644 (file)
index 0000000..f187c59
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="mkdru-detail"></div>
+<div class="mkdru-results">
+  <div class="mkdru-above mkdru-above-below"><span class="mkdru-counts"></span><span class="mkdru-status"></span></div>
+  <ul class="mkdru-result-list"></ul>
+  <div class="mkdru-below mkdru-above-below"><span class="mkdru-pager"></span></div>
+</div>