Permalink
Browse files

Nodes can be searched in Chrome in omnibox with 'xv' prefix

  • Loading branch information...
1 parent e317aa1 commit 40354ba1caaf68091f19b9854b01f3d5a78b36e3 @sergeche committed Feb 9, 2011
View
36 extensions/chrome/background.html
@@ -1,3 +1,35 @@
-<html>
+<script>
+ function sendRequest(request, response) {
+ chrome.tabs.getSelected(null, function(tab) {
+ chrome.tabs.sendRequest(tab.id, request, function(r) {
+ if (response)
+ response(r);
+ });
+ });
+ }
+
+
+ chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
+ sendRequest({action: "xv.search", query: text}, suggest);
+ });
+
+ chrome.omnibox.onInputStarted.addListener(function() {
+
+ });
-</html>
+ chrome.omnibox.onInputCancelled.addListener(function() {
+ resetDefaultSuggestion();
+ });
+
+ chrome.omnibox.onInputEntered.addListener(function(text) {
+ sendRequest({action: "xv.search-apply", query: text});
+ });
+
+ function resetDefaultSuggestion() {
+ chrome.omnibox.setDefaultSuggestion({
+ description: '<url><match>xv:</match></url> Find node in current XML document'
+ });
+ }
+
+ resetDefaultSuggestion();
+</script>
View
35 extensions/chrome/controller.js
@@ -23,4 +23,37 @@ if (canTransform()) {
document.insertBefore(pi, document.firstChild);
document.replaceChild(html, document.documentElement);
-}
+
+ xv_controller.process(source_doc);
+}
+
+chrome.extension.onRequest.addListener(function(request, sender, sendResponse){
+ if (request.action == 'xv.search') {
+ var search_result = xv_search.search(request.query),
+ result = [];
+
+ if (search_result.results) {
+ result = _.map(search_result.results, function(n, i) {
+ /** @type {String} */
+ var label = n.label;
+ if (n.query_start != -1) {
+ label = label.substring(0, n.query_start) +
+ '<match>' + label.substring(n.query_start, n.query_end) + '</match>' +
+ label.substring(n.query_end)
+ }
+
+ return {
+ content: n.label + ' (id ' + i + ')',
+ description: '<url>' + label + '</url> <dim>' + n.xpath + '</dim>'
+ };
+ })
+ }
+
+ sendResponse(result);
+ } else if (request.action == 'xv.search-apply') {
+ try {
+ var id = request.query.match(/\(id\s+(\d+)\)$/i)[1];
+ xv_search.applyProposal(parseInt(id));
+ } catch(e) {}
+ }
+});
View
BIN extensions/chrome/icon-16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
6 extensions/chrome/manifest.json
@@ -8,6 +8,12 @@
"http://*/*",
"https://*/*"
],
+ "omnibox": {
+ "keyword" : "xv"
+ },
+ "icons": {
+ "16": "icon-16.png"
+ },
"content_scripts": [{
"js": ["xv.js", "controller.js"],
"matches": ["http://*/*", "https://*/*", "file://*/*"],
View
BIN icon-16.drawit/Data
Binary file not shown.
View
8 icon-16.drawit/Info.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>fileVersion</key>
+ <integer>2</integer>
+</dict>
+</plist>
View
BIN icon-16.drawit/QuickLook/Preview.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN icon-16.drawit/QuickLook/Thumbnail.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 40354ba

Please sign in to comment.