<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
  <title>Ubiquity Web Search Commands</title>
</head>
<body>

<div id="google-search" style="display: none;">

{for result in results}
<div class="gresult">
  <div>
    ${result.key}: <a href="${result.unescapedUrl}" accesskey="${result.key}">${result.title}</a>
  </div>
  <xul:description class="gresult-content">${result.content}</xul:description>
  <div class="gresult-url">${result.visibleUrl}</div>
</div>

{forelse}
  <b>${noResultsMessage}</b>
{/for}
<small>${tipsMessage}</small>
</div>

<script class="commands"><![CDATA[


CmdUtils.makeSearchCommand({
    names: ["googlede", "gde", "dge"],
    url: "http://www.google.de/search?q={QUERY}",
    icon: "chrome://ubiquity/skin/icons/google.ico",
    description: "Searches with Google Germany. I used the Ubiquity Google Command and enhanced it.",
    help: "googlede OR gde OR dge [search item]",
    author: {name: "Digioso", email: "webmaster@digioso.org"},
    homepage: "http://www.digioso.org",
    license: "GPL",
  preview: function(pblock, {object}) {
    var searchTerm = object.text;
    // Don't even display any text before fetching search results,
    // since the results come back nearly instantaneously. In the
    // future, we can display a throbber.
    if(searchTerm.length < 1) {
      pblock.innerHTML = _("Searches Google for your words.");
      return;
    }

    var url = "http://ajax.googleapis.com/ajax/services/search/web";
    var params = { v: "1.0", q: searchTerm };

    CmdUtils.previewGet( pblock, url, params, function(data) {
      var numToDisplay = 3;
      var results = data.responseData.results.splice( 0, numToDisplay );
      
      //for access keys
      for(var i=0;i<results.length;i++){
        var result = results[i];
        result.key = i+1;
      }
      
      var noResultsMessage = _("Your search - ${searchTerm} - did not match any documents.",
                              {searchTerm:searchTerm});
      var tipsMessage = _("Tip: You can go to any result in this preview by pressing control, alt, and the result number at the same time.");
      
      pblock.innerHTML = CmdUtils.renderTemplate(
        jQuery("#google-search", feed.dom).html(),
          { results:results,
            searchTerm:searchTerm,
            noResultsMessage:noResultsMessage,
            tipsMessage:tipsMessage
          });
      }, "json");
  }
});

]]></script>
</body>

</html>
