Minified.js Beta 5: Features and Changes

I am still amazed how it is possible to optimize Minified even further and squeeze more and more features into Minified, while still staying under 4kB for the Web module and 8kB for the complete library. This release adds new 8 methods (while removing only 2), has vastly improved implementations for Promises and number formatting, and many smaller changes.
The focus on this release was to make Minified more comfortable to use. Minified original concept was to have only one way to do something, in order to keep its size down. As you can see below I have softened this rule somewhat and added a number of convenience functions. Enjoy!

Backward-incompatible Changes

  • defer() and delay() have been removed. Use the standard setTimeout() instead.
  • formatValue()'s handling of number group separators has been changed. It will now support all possible separators, but will not automatically add group separators anymore.
  • clone() will only remove ids of top-level elements, but not those of child elements.
  • The promise.state property has been removed. Invoke the promise function without arguments to obtain the current state.
  • Setting '$$slide' and '$$fade' in set() or in animations will not change '$display' anymore. Only the '$visibility' and opacity/height will be modified. If you need an element to be initially hidden, set '$visibility' to 'hidden' or use '$$show'.

New: Easier DOM traversal with up() and next()

up() and next() are two shortcuts for the most important usages of trav().

// get all form elements that contain a <select>
var selectForms = $('select').up('form');

// get all divs that follow an hr as siblings
var divAfterHr = $('hr').next('div', -1);

New: not() as inverse filter

not() returns a list of all elements that do not match a selector or function.

// selects all <table> elements that do not have the class 'simple'
var ts = $('table').not('.simple');

New: onClick() as alternative to .on('click', ...)

onClick() is a very thin helper function that does essentially the same as .on('click', ...).

$('#myButton').onClick(function() { alert('Clicked!'); });

New: show(), hide() and $$show to change the visibility of elements

show() and hide() are helper methods to manipulate the '$display' and 'style of elements. '$$show' can be used in get()/set() to find out whether an element is visible or to change its visibility.

$('#beautiful').show();
$('#ugly').hide();
var visibilityToggle = $('.hiddable').toggle({$$show: 1}, {$$show: 0});

New: isEmpty() checks for empty lists or strings

isEmpty() is a simple helper function that can check whether a list or string is either null or empty. When checking strings it can optionally ignore whitespace.

New: stop() to cancel chained animations

stop() now allows you to cancel even chained animations, if you are using the full distribution. All promises returned by Minified have a stop() function.

var div = $('#myMovingDiv').set({$left: '0px', $top: '0px'});
var prom = div.animate({$left: '200px', $top: '0px'}, 600, 0)
	.then(function() {
		return _.promise(div.animate({$left: '200px', $top: '200px'}, 800, 0), 
						 div.animate({$backgroundColor: '#f00'}, 200));
		}).then(function() {
			return div.animate({$left: '100px', $top: '100px'}, 400);
	});

$('#stopButton').onClick(prom.stop);

New: define() to define Minified modules

define() has been around for a long time, but only in beta 5 it becomes a part of the public API. define() is an extremely simplified AMD implementation sufficient to provide Minified-only modules. It is AMD-backward compatible, meaning that any module written for Minified should also work with a fully-blown AMD implementation. It is not enough to support a library written for AMD though.

define('makeGreen', function(require) {
    var MINI = require('minified'), $ = MINI.$; // private ref to Minified
    return function(list) {
        $(list).set({$color: '#0f0', $backgroundColor: '#050'});
    });
 });
 var makeGreen = require('makeGreen');
 makeGreen('.notGreenEnough');
 

Change: Promises/A+ updated to the latest spec

Minified's Promise implementation has been updated so that it passes the latest Promises/A+ compliance tests. The test suite has also been incorporated into Minified's test cases. Please note that the simplified Promises implementation in the Web module will not pass all tests.

Change: $.request uses only plain objects as form data

$.request() will only use plain objects as form data. Everything else is passed directly to the XHR. This allows you to use $.request() with FormData objects.

Change: $float will work as expected

$float will now work correctly in set() and all other methods. So far it didn't because in the DOM style object the property is called cssFloat. Beta 5 automatically translates the name.

Change: reverse() can also reverse strings

_.reverse() can now also be used to reverse strings, and not only lists.

Download

You can download beta 5 on the download page.