Labs/Ubiquity/Writing A Search Command: Difference between revisions

 
(One intermediate revision by the same user not shown)
Line 140: Line 140:
Specifies the type of remote data to retrieve. (same as <code>[http://api.jquery.com/jQuery.ajax/ jQuery.ajax()]</code>'s <code>dataType</code> option). If <code>"json"</code> is passed, the parser switches to JSON mode.
Specifies the type of remote data to retrieve. (same as <code>[http://api.jquery.com/jQuery.ajax/ jQuery.ajax()]</code>'s <code>dataType</code> option). If <code>"json"</code> is passed, the parser switches to JSON mode.


==== url ====
==== url / postData ====
Alternative url used in case the preview uses a different service or API than the execute function. i.e.: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={QUERY}"
Alternative URL and/or POST Data used in case the preview uses a different service or API than the execute function. i.e.: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={QUERY}"


==== container ====
==== container ====
Line 171: Line 171:
==== baseUrl ====
==== baseUrl ====
String used as base URL if [[#href]] and/or [[#thumbnail]]'s src is found to be relative. If not provided, [[#url]] will be used instead.
String used as base URL if [[#href]] and/or [[#thumbnail]]'s src is found to be relative. If not provided, [[#url]] will be used instead.
==== plain ====
Array of strings naming selector properties (<code>"title", "body", "href", "thumbnail"</code>) that should be treated as plain text.
==== log ====
Function to which the command logs the reponse data and parsed results.


=== Other ===
=== Other ===
Line 211: Line 217:
</pre>
</pre>


=== Using functions in the parser ===
=== Parsing XML / Using functions in the parser ===
<pre>
<pre>
CmdUtils.makeSearchCommand({
CmdUtils.makeSearchCommand({
Line 220: Line 226:
     container: "simpleforecast > forecastday",
     container: "simpleforecast > forecastday",
     title: "pretty",
     title: "pretty",
     body: "conditions",
     body: function() $("<div>").append(
      $("conditions", this), "<br/>",
      $("<b>", {
        text: $("low > celsius", this).text() + "\u2103",
        style: "color:#66f",
      }),
      " \uFF5E ",
      $("<b>", {
        text: $("high > celsius", this).text() + "\u2103",
        style: "color:#f66",
      })),
     thumbnail: function() $("<img>", {
     thumbnail: function() $("<img>", {
       src: ("http://icons-pe.wxug.com/i/c/a/" +
       src: "http://icons-pe.wxug.com/i/c/a/" + $("icon", this).text() + ".gif",
            this.find("icon").text() + ".gif"),
     }),
     }),
   },
   },
73

edits