Thank you for your interest in developing for XKit!
Developing for XKit is really simple if you are efficient with HTML + CSS and JavaScript. XKit includes jQuery on all installations, so writing for XKit is not only simple, but also fast, too. And not only that, when you submit your extension to the Extension Gallery, you can reach new users, quick and easy.
In this page..
This page describes the concepts of an XKit extension, how XKit works, how to set and read global variables and functions, and how to append CSS styles. In
page two, all global functions are listed, and a sample extension is provided, as well as submission guidelines, and how to submit your extension.
If you are interested in theme development, please check the
Themes Documentation instead.
How does XKit work?
Every part of XKit (except the Framework part) is actually a XKit extension. On first install (or on resetting XKit), it downloads the Bootstrap code, which contains jQuery, and necessary code required to install or "boot" XKit.
Framework is responsible for interacting with the browser, doing stuff like saving and retrieving settings, logging debug messages, and running functions, as well as providing information about installed extensions ("packages").
Every part of XKit can be updated remotely, except the Framework part, which must be updated by the user.
When installing XKit for the first time, or resetting it, after downloading Bootstrap, "xkit_installer" package is downloaded, which installs and configures XKit, and then deletes itself.
Upon opening a page, XKit does the following:
- Framework: Check installation, then call Bootstrap.
- Bootstrap: Call the package xkit_main.
- xkit_main: Fetch information about installed extensions, and tell Framework to boot them.
There are six "internal packages", packages that are installed with every XKit installation, and can't be removed.
- xkit_main: Responsible for starting up extensions.
- xkit_extendedkernel: Used to 'patch' functions without updating Framework. (seldom used)
- xkit_required: CSS and Base64 encoded images used by XKit
- xkit_preferences: Responsible for user interaction. Displays the "X" icon on dashboard, and used to configure XKit.
- xkit_update_manager: Checks updates for packages, and downloads and applies them.
- xkit_pfm: Not used anymore.
Packages
Internally, each extension is called a "package." Packages are stores along with configuration data, and each package have two 'files': the extension data itself, and the icon data. For example, if a package's JavaScript file on server is called "xfollowers.js", it would be stored internally as "xfollowers", and it's icon would be saved as "xfollowers_icon."
When installing XKit, "xkit_installer" package is responsible for downloading and saving packages. When using the Extension Gallery, "xkit_preferences" is responsible for it.
Each package has it's "information section", which looks like this:
//* VERSION 1.0 REV C **//
//* INTERVAL 0 **//
//* TITLE Fix and Tweaks **//
//* DEVELOPER STUDIOXENIX **//
//* PREFMENU Fix and Tweaks **//
//* PREFFUNC xpatches_options **//
//* DESCRIPTION Various fixes to make your Tumblr experience even better. **//
//* ADVANCED false **//
Note that the bold lines are required. The others are optional.
So what does all these stuff mean?
- VERSION: Version of the extension. Used in preference panels, and to update the extension.
- INTERVAL: Used to "attach" an extension to the page, to be run in the interval specified here. (in milliseconds) If set to 0, it will be ignored.
- TITLE: User-viewable title of the extension
- DEVELOPER: Your name.
- PREFMENU: On XKit 4.x, it sets the tabs caption on control panel. Not used in XKit 5.x, but must be specified anyway, if your extension has a control panel.
- PREFFUNC: The function to be called when the user tries to open the extension control panel.
- DESCRIPTION: A short description about your extension. Used on the control panel, as well as the Extension Gallery.
- ADVANCED: If set to "true", the extension will only appear on the Extension Gallery if the user has "Advanced Packages" enabled under the Advanced Settings menu.
Storage and Variables
There are three types of storing data:
- Normal, JS declaration: used to store temp. data "private" to extension. Gets lost when the user refreshes the page, or reloads the extension.
- Shared Temporary Storage: used to store temporary data that can be used by other extensions. Remains on memory until the user refreshes the page.
- Shared Persistent Storage: used to store data such as configuration and settings. Saved even after the user closes down the browser.
Normal JS declaration: Works just as it does in any JavaScript function.
var myname = "Atesh";
alert("Hi, my name is " + myname);
Shared Temporary Storage: Also called a "XVar."
xvar_set("myname","Atesh");
alert("Hi, my name is " + xvar_get("myname"));
Shared Persistent Storage: Used to store configuration data.
xset("myname","Atesh");
alert("Hi, my name is " + xget("myname"));
IMPORTANT:
When using shared storage options, always append an "identifier" before your variable name, since that name could be also used by another extension. (ex: "xfollowers_myname")
Functions
There are three types of functions:
Framework functions: There are included in every XKit environment. More on these later.
Normal JS declaration: Works just as it does in any JavaScript function. You can only call these from within your extension.
function say_hi() {
alert("hi!");
}
// call it:
say_hi();
Global Functions (globalf): Any extension can call these.
// create a function:
function say_hi() {
alert("hi!");
}
// attach it to page:
globalf_add("my_global_function",say_hi);
// call it:
globalf_run("my_global_function");
CSS
If you are going to use styles, please append them using
xcss_append, which adds it to the header of the page. Using xcss_append is easy: (you can, of course, also use multi-line strings.)
xcss_append(" .my_div { padding: 10px; border: 2px solid red; } ");
xcss_append also supports adding Shared Temporary Storage variables (xvars):
xvar_set('mycolor', 'red');
xcss_append(" .my_div { padding: 10px; border: 2px solid %var mycolor%; } ");
IMPORTANT:
When appending styles, always append an "identifier" to your names: use "xmyapplication_mydiv", not "mydiv", as that can cause problems in the future.
IMPORTANT:
xcss_append does not check for duplicate entries. Use with caution, and if your application has an interval, set a variable (like "xmyapp_added_css_to_page") to not re-add styles again.
Framework Variables
XKit framework does have some variables that can give information about the framework, and the page it is running on.
- xframework_version_major: 'Major' version of the framework (string, "4", "5"...)
- xframework_version_minor: 'Minor' version of the framework (string, "0", "1"...)
- xframework_version: 'Full' version (string, "4.3", "5.1"...)
- xframework_debug_mode: If true, xlog will also print to browser console (boolean)
- xframework_panic: A function called 'xpanic' (boolean)
- xbootstrap_fetch_urls: URLs used to fetch bootstrap (array)
- xbootstrap_page_url: The current page URL (string)
- xkit_is_chrome: True if running on Google Chrome (boolean)
IMPORTANT:
Never, ever change the preceding variables. Doing so might confuse other extensions, and extensions that change these variables won't be allowed in the Extension Gallery.
Next: Global functions, and writing your first extension ·
Next Page >