Minified.js Beta 4: Features and Changes
Beta 4 is a relatively small release. Notable changes include the new functions per() and onFocus(), a reorganization of request()'s advanced options as well as a new value for this in all event handlers.
Main reason to release it so early and with so few features is that I wanted to release some backward-incompatible changes as soon as possible. After beta 4 I intend to keep further backward-incompatible changes to a minimum, as Minified steers slowly towards its first stable release.
Backward-incompatible Changes
- on(), onOver() and onChange() will set this to a Minified list containing the event target, and not the event target itself.
- $.request() headers, username and password arguments have been moved into a new settings argument.
New: Iteration over sub-lists with per()
per() is an iteration function like each(), but with one key difference: it invokes the callback with the elements wrapped in a single-item Minified list. This can simplify your code in some cases.
$('.withHoverEffect').per(function(el) {
el.onOver(el.toggle('hoverEffect'));
});
per() also supports sub-selects. That can make it easier to create events when you use iteration in templates:
$('#list').add(HTML('{{each}}<li>{{this.name}} <a class="del" href="#">Delete</a></li>{{each}}', items)
.per('.del', function(el, index) {
el.on('click', deleteItemByName, [items[index].name]);
}));
New: onFocus() for toggling when an element gets focussed
per() is an iteration function like each(), but with one difference: it invokes the callback with the elements wrapped in a single-item Minified list. This can simplify your code in some cases.
$('input').per(function(el) {
el.onFocus(el.toggle('isFocussed'));
});
New: reduce() for Minified lists
Beta 4 (re-)adds a simple reduce() version to the Util module.
var sum = _(1, 2, 3, 4, 5).reduce(function(memo, value, index) {
return memo + value;
}, 0);
Change: on(), onOver() and onChange() return target wrapped in a list
Before beta 3, on() would call its handler with this set to the event source. Starting with beta 4, it passes a Minified list containing the event source as its only element.
onOver() and onChange() have also been modified accordingly.
Change: request() uses settings object, support for setting XHR properties
$.request()'s headers, username and password arguments have been moved into an object as 4th argument. You can now also set XMLHttpRequest properties.
Change: HTML() and ht() support templates stored in script tags
HTML() and ht() can now automatically get the template from a HTML <script> tag. This is mostly useful when you have large scripts that can not be conveniently stored in a JavaScript string, or when you need to store the string on the HTML page for internationalization purposes.
First create a <script> tag with a type not supported by the browser and put your template in there, like this:
<script id="myTimeTpl" type="minified-template">The time is {{HH:mm:ss}}.</script>
Then you can specify the tag's id directly to access it:
$('#timeDisplay').ht('#myTimeTpl', new Date());
Site: Comments in API docs (Disqus)
Minified's API documentation supports comments now. It uses Disqus as its backend.
Download
You can download beta 4 on the download page.