User:wolfy87oc/Spark (JavaScript library)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Spark
SparkJavaScriptLogo.png
Original author(s) Oliver Caldwell
Developer(s) Oliver Caldwell
Initial release October 22, 2010 (2010-10-22)
Stable release
2.3.7 / March 9, 2011 (2011-03-09)
Development status Active
Written in JavaScript
Size 32.995kb (production mode) / 75.157kb (development mode)
Type Web application framework
License Dual license:
GPL or MIT
Website http://sparkjs.co.uk/

Spark is a cross browser JavaScript library that was written by Oliver Caldwell to assist with DOM (Document Object Model) traversal, AJAX (Asynchronous JavaScript and XML), the encoding or decoding of JSON (JavaScript object notation) and animation of HTML DOM (Document Object Model) elements.

Spark currently has little or no user base. Therefor documentation and tutorials are limited to the official documentation.

The Spark functions have been written in such a way that simply adding arguments to a function call will change it's functionality. For example, to make an AJAX call you would use something like this:

alert(Spark.ajax('post', 'mail.php', 'name=Oliver'));

If you wish to make it asynchronous, you simply add a callback function as an argument.

Spark.ajax('post', 'mail.php', 'name=Oliver', function(data) {
	alert(data);
});

This method of altering functionality depending on the arguments provided can help to save time and reduce the amount of JavaScript that is required.

Features[edit]

Spark contains the following features:

  • DOM element selections using the cross browser open source selector engine Sizzle as used in the jQuery JavaScript library.
  • DOM traversal and modification.
  • Events.
  • CSS manipulation.
  • Adding, removing or checking for the presence of a certain CSS class.
  • Animation of CSS properties of DOM elements.
  • Ajax.
  • Browser cookie management.
  • Extensibility through plug-ins.
  • Cross-browser support.
  • Retrieving information about the clients browser and operating system.
  • Loading of external JavaScript files.

Including the library[edit]

Spark is contained within a single JavaScript file. This can be downloaded from the temporary website or GitHub repository. An uncompressed, development version, is available from the [GitHub] repository. To include it simply insert this script tag into your HTML document after downloading. You may need to edit the 'src' accordingly.

<script type='text/javascript' src='spark.js'></script>

Examples[edit]

The library can either be accessed by dollar ($) notation or via the Spark function like so.

$('selector').function(arguments);

Or

Spark('selector').function(arguments);

Here is an example script that sets an on click listener and displays the clicked elements contents.

Spark('p').event('click', function(e) {
	// Target can be used in IE because Spark fixes this inconsistency.
	// Usually in IE you must use srcElement. And target in others.
	alert(Spark(e.target).html());
});

Compatibility[edit]

Spark can be ran in noConflict mode in which it can be run alongside other libraries such as Mootools or jQuery. This is achieved like so.

Spark.noConflict();

Spark plugins[edit]

Spark has Extensibility capabilities, therefor functions can be added to improve the functionality. These extra functions are also known as plugins. An example of a simple plugin can be found within the documentation.

See also[edit]

External links[edit]