<commit_before>/*
  nr is the prefix for this function space.
  
  There's probably a way to do it in YUI that's not so awful, but I only know jQuery...
*/
function ddg_spice_zanran(zanran_results) {
  /* IE6 cannot be supported due to lack of max-width / min-width without rewriting everything */
  if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
    return;
  }
  if(!zanran_results || !zanran_results.results || !zanran_results.results.length) {
    return;
  }

  var results = zanran_results.results;
  
  var out = "";

  for(var i=0; i<results.length; i++) {
    if(i==3) break; // 3 results max
    var div = d.createElement("div");
    YAHOO.util.Dom.addClass(div, 'highlight_zero_click1 highlight_zero_click_wrapper');
    YAHOO.util.Dom.setStyle(div, 'clear', 'both');
    YAHOO.util.Dom.setStyle(div, 'border-bottom', '1px solid #BFBFBF');
    YAHOO.util.Dom.setStyle(div, 'width', '620px');
    YAHOO.util.Dom.setStyle(div, '-moz-border-radius', '6px');
    YAHOO.util.Dom.setStyle(div, '-webkit-border-radius', '6px');
    YAHOO.util.Dom.setStyle(div, 'border-radius', '6px');

    var img_link = d.createElement("a");
    img_link.href = results[i].preview_url;
    img_link.title = results[i].title;
    var img = d.createElement('img');
    img.src = results[i].preview_image;
    img_link.appendChild(img);
    YAHOO.util.Dom.setStyle(img, 'max-width', '43px');
    YAHOO.util.Dom.setStyle(img, 'max-height', '60px'); // A4 ratio
    YAHOO.util.Dom.setStyle(img, 'border', '1px solid black');
    YAHOO.util.Dom.setStyle(img_link, 'float', 'right');
    YAHOO.util.Dom.setStyle(img_link, 'margin-left', '10px');
    
    div.appendChild(img_link);

    var title = results[i].title;
    if(title.length > 140) {
      var words = title.split(/\s+/);
      title = "";
      while(words.length && title.length + 1 + words[0].length < 140) {
        title = title + " " + words.shift();
      }
      title += "\u2026";
    }

    var p1 = d.createElement('div');
    p1.appendChild(d.createTextNode(title));
    div.appendChild(p1);

    YAHOO.util.Dom.setStyle(p1, 'max-width', '575px');

    var p2 = d.createElement('div');

    var link1 = d.createElement("a");
    link1.href = results[i].final_url;
    link1.title = results[i].title;
    link1.appendChild(d.createTextNode("Link"));

    var link2 = d.createElement("a");
    link2.href = results[i].preview_url;
    link2.title = results[i].title;
    link2.appendChild(d.createTextNode("Preview"));

    p2.appendChild(link1);
    p2.appendChild(d.createTextNode(" | "));
    p2.appendChild(link2);
    p2.appendChild(d.createTextNode(" | "));

    var source = d.createElement('i');
    p2.appendChild(source);
    source.appendChild(d.createTextNode("Source: "));

    p2.appendChild(d.createTextNode(results[i].site_name));

    YAHOO.util.Dom.setStyle(p2, "overflow", "hidden");
    YAHOO.util.Dom.setStyle(p2, "white-space", "nowrap");
    YAHOO.util.Dom.setStyle(p2, "text-overflow", "ellipsis");

    
    div.appendChild(p2);

    var container_div = d.createElement("div");
    container_div.appendChild(div);
    out += container_div.innerHTML;
  }
  out += '<div class="clear"></div>';
  
  items = [[]];
  items[0]['a'] = out;
  items[0]['h'] = "Data & Statistics from Zanran (" + DDG.get_query() + ")";
  items[0]['s'] = 'Zanran';
  items[0]['u'] = zanran_results.more;
  items[0]['f'] = 1;
  items[0]['force_big_header'] = 1;
  // items[0]['i'] = 'http://zanran.com/favicon.ico';

  nra(items,1,1);
};<commit_msg>New layout with 1 result + 3 extra under "More results"<commit_after>/*
  nr is the prefix for this function space.
*/
function ddg_spice_zanran(zanran_results) {
  var outer_html = function(element){
    var container_div = d.createElement("div");
    container_div.appendChild(element);
    return container_div.innerHTML;
  };
  
  var create_link = function(result){
    var link = d.createElement("a");
    link.href = result.preview_url;
    link.title = result.title;
    return link;
  };
  
  var shorten_title = function(title, max_len){
    if(title.length > max_len) {
      var words = title.split(/\s+/);
      title = "";
      while(words.length && title.length + 1 + words[0].length < max_len) {
        title = title + " " + words.shift();
      }
      title += "\u2026";
    }
    return title;
  }
  
  var create_dom_for_primary_result = function(result){
    var img_link = create_link(result);
    var img = d.createElement('img');
    img.src = result.preview_image;
    img_link.appendChild(img);
    YAHOO.util.Dom.setStyle(img, 'max-width', '71px');
    YAHOO.util.Dom.setStyle(img, 'max-height', '100px'); // A4 ratio
    YAHOO.util.Dom.setStyle(img, 'border', '1px solid black');
    YAHOO.util.Dom.setStyle(img_link, 'float', 'right');
    YAHOO.util.Dom.setStyle(img_link, 'margin-left', '10px');

    var p1 = d.createElement("div");
    var source = d.createElement('i');
    p1.appendChild(source);
    source.appendChild(d.createTextNode("Source: "));
    p1.appendChild(d.createTextNode(result.site_name));
    
    var p2 = d.createElement("div");
    p2.appendChild(d.createTextNode(result.title));

    var link2 = create_link(result);
    link2.appendChild(d.createTextNode("Link"));
    
    var div = d.createElement("div");
    div.appendChild(img_link);
    div.appendChild(p1);
    div.appendChild(p2);
    div.appendChild(link2);

    return div;
  };
  
  var create_dom_for_secondary_result = function(result){
    var source = d.createElement('i');
    source.appendChild(d.createTextNode("Source: "));
    source.appendChild(d.createTextNode(result.site_name));
    
    var title = shorten_title(result.title, 140);

    var link = create_link(result);
    link.appendChild(d.createTextNode("Link"));
  
    var div = d.createElement("li");
    div.appendChild(d.createTextNode(title));
    div.appendChild(link);
    div.appendChild(d.createTextNode(" | "));
    div.appendChild(source);
    
    return div;
  };

  if(YAHOO.env.ua.ie && YAHOO.env.ua.ie < 7) {
    return;
  }
  if(!zanran_results || !zanran_results.results || !zanran_results.results.length) {
    return;
  }

  var results = zanran_results.results;

  var div = create_dom_for_primary_result(results[0]);

  if(results.length > 1) {
    var hr = d.createElement("hr");
    var more = d.createElement("a");
    more.id = "zanran_show_extra_results";
    more.appendChild(d.createTextNode("More results..."));
    
    var list = d.createElement("ul");
    
    div.appendChild(hr);
    div.appendChild(more);

    var extra_results = d.createElement("div");
    extra_results.id = "zanran_extra_results_list";
    div.appendChild(extra_results);
    
    extra_results.appendChild(list);
    var show_extra_results = false;
    YAHOO.util.Dom.setStyle(extra_results, 'display', 'none');

    YAHOO.util.Event.addListener("zanran_show_extra_results", "click", function(){
      show_extra_results = !show_extra_results;
      if(show_extra_results){
        YAHOO.util.Dom.setStyle(document.getElementById("zanran_extra_results_list"), 'display', 'block');
      } else {
        YAHOO.util.Dom.setStyle(document.getElementById("zanran_extra_results_list"), 'display', 'none');
      }
    });

    for(var i=1; i<results.length && i<5; i++) {
      var div2 = create_dom_for_secondary_result(results[i]);
      list.appendChild(div2);
    }
  }

  var out = outer_html(div);
  out += '<div class="clear"></div>';
  
  items = [{
    a: out,
    h: "Data & Statistics from Zanran (" + DDG.get_query() + ")",
    s: 'Zanran',
    u: zanran_results.more,
    f: 1,
    force_big_header: 1    
  }];
  nra(items,1,1);
}
{'fraction_non_alphanumeric': 0.1679759099240639, 'fraction_numerical': 0.014794448808588635, 'mean_word_length': 3.4284057971014494, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715585', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2661, 'n_words': 454}