Pokki API - blakemachado/Pokki GitHub Wiki
Pokki API Reference
Methods
-
pokki.addContextMenuItem(str
text, stridentifier)Dynamically add an item to the context menu.
pokki.addContextMenuItem("Log this!", "log"); pokki.addEventListener("context_menu", function(identifier) { if (identifier == "log") { console.log(identifier); } }); -
[pokki.addEventListener] (http://developers.pokki.com/docs/reference.php#pokki.addEventListener)(str
event, funcfunction)Add a listener for a Pokki event.
pokki.addEventListener("shown", function() { console.log("Popup was shown."); });Events:
- showing - Fires when the user clicks on the Pokki's icon in the taskbar and the popup animates in
- shown - Fires after the
showingevent once the popup window is done animating in - hiding - Fires as the popup hides due to a user action,
pokki.hidebeing called or the platform exiting - hidden - Fires after
hidingonce the popup window is hidden. - unload - Fires when the popup page is being unloaded by the platform; you have four seconds to save state
- context_menu - Fires when the user selects a developer defined context menu item; passes the identifier associated with that item
-
[pokki.clearWebSheetCookies] (http://developers.pokki.com/docs/reference.php#pokki.clearWebSheetCookies)()
Clears the cookies and localStorage of the web sheet.
-
[pokki.hide] (http://developers.pokki.com/docs/reference.php#pokki.hide)()
Minimizes the window.
-
[pokki.descramble] (http://developers.pokki.com/docs/reference.php#pokki.descramble)(str
scrambled_data)Descrambles scrambled data.
var scrambled_data = pokki.scramble("Eggs"); console.log(scrambled_data); var data = pokki.descramble(scrambled_data); console.log(data); -
[pokki.getScrambled] (http://developers.pokki.com/docs/reference.php#pokki.getScrambled)(str
scrambled_key)Retrieves and descrambles scrambled_data from the manifest.
manifest.json:
{ ... scrambled_data: [{ "key": "breakfast", "value": "eggs" }] }popup or background_page:
var breakfast = pokki.getScrambled("breakfast"); console.log(breakfast); -
[pokki.hideWebSheet] (http://developers.pokki.com/docs/reference.php#pokki.hideWebSheet)()
Hides the web sheet.
-
[pokki.isShown] (http://developers.pokki.com/docs/reference.php#pokki.isShown)()
Returns true if the popup is currently being shown, otherwise returns false.
if (pokki.isShown()) { console.log("Popup is shown."); } else { console.log("Popup is not shown."); } -
[pokki.show] (http://developers.pokki.com/docs/reference.php#pokki.show)()
Opens the popup page. This function may only be called within 5 seconds of a context_menu event being fired.
pokki.addContextMenuItem("Open me!", "open"); pokki.addEventListener("context_menu", function(identifier) { if (identifier == "open") { pokki.show(); } }); -
[pokki.openURLInDefaultBrowser] (http://developers.pokki.com/docs/reference.php#pokki.openURLInDefaultBrowser)(str
url)Opens the specified URL in the user's default browser.
<a href="#" onclick="pokki.openURLInDefaultBrowser('http://pokki.com');pokki.hide();">Pokki.com</a> -
[pokki.removeIconBadge] (http://developers.pokki.com/docs/reference.php#pokki.removeIconBadge)()
Removes the icon badge.
-
[pokki.resetContextMenu] (http://developers.pokki.com/docs/reference.php#pokki.resetContextMenu)()
Clears all dynamically defined context menu items.
-
[pokki.rpc] (http://developers.pokki.com/docs/reference.php#pokki.rpc)(str
javascript)Runs the specified Javascript in the opposing page's context. Returns primitive data types (number, boolean, string, null, undefined), cannot return complex data types such as objects.
background_page:
function add_two(n) { return n + 2; }window_page:
var sum = pokki.rpc("add_two(4);"); console.log(sum); -
[pokki.scramble] (http://developers.pokki.com/docs/reference.php#pokki.scramble)(str
to_scramble)Scrambles a string.
var scrambled_data = pokki.scramble("Eggs"); console.log(scrambled_data); var data = pokki.descramble(scrambled_data); console.log(data); -
[pokki.setIconBadge] (http://developers.pokki.com/docs/reference.php#pokki.setIconBadge)(int
number)Sets the number to display in the icon's badge.
-
[pokki.showWebSheet] (http://developers.pokki.com/docs/reference.php#pokki.showWebSheet)(str
url, intwidth, intheight, funcloading_callback, funcerror_callback)Opens a web sheet to the specified URL and sets the appropriate callbacks. A web sheet is an embedded browser which is used for things like OAuth.
// The URL that will contain the access token we're looking for var token_url = 'http://apps.facebook.com/frontierville/tracks.php'; // The initial URL for the WebSheet var url = 'https://www.facebook.com/login.php?api_key=201278444497' + '&next=' + token_url; // Display the WebSheet pokki.showWebSheet( url, 512, 400, function(_url) { // If the URL being loaded is the one we're looking for... if (_url.startsWith(token_url)) { // Extract access token // Close the web sheet pokki.hideWebSheet(); } else { // This is not the URL we're looking for, let the page be shown return true; } }, function(error) { // An error occurred! } );