Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (73 sloc) 2.29 KB
<!DOCTYPE html>
<title>Delicious</title>
<script type="text/javascript">
Delicious = new Object; // I'm not sure, do we need to namespace work?
Delicious.itemURL = '';
Delicious.itemTitle = '';
Delicious.itemDescription = '';
/*
* seems like eventually it'd be nice to have a toggle between using the inline or popup
*/
Delicious.openDeliciousWindow = function() {
/* as a heads up, the itemDescription is already URI encoded when
* passed back from the message event listener
*/
var deliciousTab = safari.application.activeBrowserWindow.openTab();
var url = 'http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(Delicious.itemURL)+'&title='+encodeURIComponent(Delicious.itemTitle) +'&notes='+Delicious.itemDescription;
deliciousTab.url = url;
};
Delicious.performCommand = function(event)
{
if (event.command === 'DeliciousToolbarItem')
{
// Get the current tab's URL
var itemUrl = event.target.browserWindow.activeTab.url;
// There's nothing to do if there's no URL
if (itemUrl)
{
Delicious.itemURL = safari.application.activeBrowserWindow.activeTab.url;
Delicious.itemTitle = safari.application.activeBrowserWindow.activeTab.title;
/*
* dispatch a message to the current page where an injected script is listening
*/
event.target.browserWindow.activeTab.page.dispatchMessage("getSelection","");
}
}
else
{
// unknown command
return;
}
}
Delicious.validateCommand = function(event)
{
if (event.command === 'DeliciousToolbarItem') {
event.target.disabled = !event.target.browserWindow.activeTab.url;
}
else
{
// unknown command
return;
}
}
Delicious.respondToMessage = function(messageEvent)
{
if(messageEvent.name === "getSelection")
{
/*
* receives a message from the current page where the injected text selection script is listening
*/
Delicious.itemDescription = String(messageEvent.message);
Delicious.openDeliciousWindow();
return;
}
else
{
//unknown messageEvent
return
}
}
safari.application.addEventListener("message",Delicious.respondToMessage,false);
safari.application.addEventListener('command',Delicious.performCommand, false);
safari.application.addEventListener('validate',Delicious.validateCommand, false);
</script>