back to Overview

MINI.setter

Exposes a map of prefix handlers used by set.
Web module only.

Syntax

MINI.setter

Description

Exposes a map of prefix handlers used by set(). You can add support for a new prefix in set() by adding a function to this map. The prefix can be any string consisting solely of non-alphanumeric characters that's not already used by Minified.

You must not replace setters by a new map, but must always modify the existing map.

The function's signature is function(list, name, value) where

list
Is the Minified list to use.
name
The name of the property. That's the part AFTER the prefix.
value
Either the value to set, or a callback function to create the value that you must call for each value (see set() ).

If you provide complete get() and set() support for a prefix, you are also able to use it in other Minified function such as animate() and toggle().

Example

Adding a shortcut '||' for accessing border style properties. As it's just calling set() for an existing property, it is not required to extra code for the callback.

MINI.setter['||'] = function(list, name, value) {
	list.set('$border' + name.replace(/^[a-z]/, function(a) { return a.toUpperCase()}, value);
};

$('#box').set('||color', 'red');   // same as set('$borderColor', 'red')
$('#box').set('||leftRadius', 4);  // same as set('$borderLeftRadius', 4)

Example

Adding XLink attribute support to set(). This is useful if you work with SVG. The prefix is '>'.

MINI.setter['>'] = function(list, name, value) {
	list.each(function(obj, index) {
		var v;
		if (_.isFunction(value))
			v = value(obj.getAttributeNS('http://www.w3.org/1999/xlink', name), index, obj);
		else
			v = value;

	if (v == null)
		obj.removeAttributeNS('http://www.w3.org/1999/xlink', name);
	else
		obj.setAttributeNS('http://www.w3.org/1999/xlink', name, v);
});
};

$('#svgLink').set('>href', 'http://minifiedjs.com/');

Comments

comments powered by Disqus

back to Overview

Functions