X consists of symbols. A symbol is a variable, function or object prototype.
Previously, X was defined as a set of symbols where each identifier began with a lower-case 'x'. XC 1.0 frees us from that limitation. Now X symbols can be any legal Javascript identifier. X is now defined by a set of x_symbol
XML elements. The id
attribute of x_symbol
specifies the identifier for the symbol. The only requirement is that each symbol's id
be unique within the library.
Each symbol is completely defined by two files: an XML file and a Javascript source file.
For every X symbol there must be an XML file with an x_symbol
root element. For convenience the name of the XML file is the symbol identifier in all lower-case.
The XML file provides the symbol's actual identifier, the location of the Javascript source file, a list of dependencies, complete usage documentation, revision history, author copyright, license statement, and more. In /templates/
you will find an _x_symbol_template.xml file.
With the release of XC 1.0 there is now no requirement for the name of the Javascript source file. It can be any legal filename. For convenience the filenames are all lower-case. Also, multiple symbols (multiple XML files) can have their sources in the same Javascript file (but XC will include the entire source file in the ouput even if only one of the symbols is used in the application code).
The Javascript source file should begin with the following, standard header. If you are the author you should use your own copyright info. I do not require copyright assignment for code contributions to X. For "[your URL]" please provide the URL to your web-site. I never make your email addresses publically available.
// [symbol identifier], Copyright [your date] [your name] ([your URL]) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
Please only use 'text' files with no special characters.
Please don't use tabs - use spaces for indentation.
Since XC's compression option removes newlines, you cannot use implicit statement termination. For example in the following the ';' is required because this is an assignment expression.
myObject.prototype.method = function() { // statements... }; // <- this semicolon is required to support compression
Here is another example where a semicolon is required because it is an assignment statement.
function myObjectPrototype(id) { var img = document.getElementById(id); img.onmouseover = function() { this.src = urlOver; }; // <- this semicolon is required to support compression function foo() { } // <- a semicolon is not required here }
XC v1.02+ (released 30Jan07) supports JScript conditional compilation statements - that is, it will not remove them when compressing. I have found only one situation where XC does not properly handle this and that is when there is no @if statement beginning the block. For example:
/*@cc_on var _x = null; // xml element for IE @*/
For the above XC will generate this: /*@cc_onvar _x=null;@*/, and IE will not recognize "@cc_onvar". A solution is to format the above as follows:
/*@cc_on var _x = null; @*/ // xml element for IE
I am proud to include your contribution in the official X distribution - but it is your responsibility to document, test and maintain your function or object.
X Index - X Library Index.
X Quick-Start - Getting Started with the X Library.
XC Reference - X Library Compiler Reference.
Get your questions answered faster by posting at one of the following forums.