Skip to content

Commit

Permalink
Support for selection in conjunction with the keybinding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Grimaldi committed Jun 19, 2010
1 parent ec81f96 commit 1730e67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions OpenInPapers.safariextension/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function performCommand(event)
}
else if (event.command === "openInPapersMenu")
{
url = event.target.contextMenu.tab.browserWindow.url;
title = event.target.contextMenu.tab.browserWindow.title;
url = safari.application.activeBrowserWindow.activeTab.url;
title = safari.application.activeBrowserWindow.activeTab.title;
if (event.userInfo)
{
title = event.userInfo.selection;
Expand All @@ -31,7 +31,8 @@ function performCommand(event)

function openURLinPapers(url, title)
{
safari.application.activeBrowserWindow.activeTab.url = 'papers://url/'+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
papersURL = 'papers://url/' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
safari.application.activeBrowserWindow.activeTab.url = papersURL;
}


Expand All @@ -56,7 +57,14 @@ function handleMessage(event)
{
if (event.name == 'openInPapersViaKeyboardShortcut')
{
openURLinPapers(safari.application.activeBrowserWindow.activeTab.url,
safari.application.activeBrowserWindow.activeTab.title);
url = event.target.browserWindow.activeTab.url;
title = event.target.browserWindow.activeTab.title;

if (event.message)
{
title = event.message;
}

openURLinPapers(url, title);
}
}
3 changes: 2 additions & 1 deletion OpenInPapers.safariextension/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if (window == window.top)
// <CTRL>+p
if (event.ctrlKey && event.keyCode == 80)
{
safari.self.tab.dispatchMessage("openInPapersViaKeyboardShortcut");
selection = event.view.document.getSelection().toString().trim();
safari.self.tab.dispatchMessage("openInPapersViaKeyboardShortcut", selection);
}
}

Expand Down

0 comments on commit 1730e67

Please sign in to comment.