Created
January 12, 2012 20:33
-
-
Save stepnem/1602929 to your computer and use it in GitHub Desktop.
Search keyword bookmarks trough the mouse context menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Almost all of this is courtesy Kris Maglione, I just made some adjustments | |
XML.prettyPrinting = false; | |
XML.ignoreWhitespace = true; | |
let objects = Class({ | |
get eventTarget() this, | |
fooEvents: { | |
popupshowing: function onPopupShowing(event) { | |
mow.contextEvents.popupshowing.call(mow, event); | |
} | |
}, | |
events: { | |
popupshowing: function onPopupShowing(event) { | |
let menu = DOM(this.menu); | |
menu.empty().append( | |
template.map(iter(bookmarks.searchEngines, | |
values(bookmarkcache.keywords) | |
.sort(function (a, b) String | |
.localeCompare(a.title, b.title))), | |
function ([keyword, item]) | |
<menuitem xmlns={XUL} xmlns:dactyl={NS} | |
dactyl:command="search.searchSelection" | |
label={item.title} | |
image={item.icon} | |
keyword={item.keyword}/>)); | |
} | |
} | |
})(); | |
overlay.overlayWindow(window, { | |
objects: objects, | |
after: <e4x xmlns={XUL} xmlns:dactyl={NS}> | |
<menuitem id="context-searchselect" style="visibility: collapse;"> | |
<menu id="dactyl-context-search" | |
label="Search Selection" | |
group="selection" | |
class="menu-iconic"> | |
<menupopup key="menu" highlight="Events"/> | |
</menu> | |
</menuitem> | |
</e4x>.elements() | |
}); | |
events.listen(document.getElementById("contentAreaContextMenu"), objects, | |
"fooEvents"); | |
dactyl.commands["search.searchSelection"] = function searchSelection(event) { | |
let elem = DOM(event.originalTarget); | |
dactyl.open(elem.attr("keyword") + " " + buffer.currentWord, | |
dactyl.NEW_TAB | |
// { from: "context-search" } | |
); | |
}; | |
// options.get("activate") | |
// .values["context-search"] = "Context menu search"; | |
// options.get("newtab") | |
// .values["context-search"] = "Context menu search"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment