MooTools 1.4.4 Released

Written By Olmo Maldonado, on Tuesday, February 7th 2012, 11:30am

Today we release MooTools Core 1.4.4 which is a critical maintenance release. 1.4.3 release introduced a bug as a result of fixing another bug. Specifically, 1.4.3 did not allow custom attributes (e.g. data- or non-standard attributes). See this issue for a full explanation and solution.

We recommend that all users upgrade to 1.4.4 as soon as possible.

Fixes

  • #2160: Fx.Tween/Fx.Morph problem with ‘%’ unit
  • #2175: IE Leak: Array.flatten
  • #2178: IE doesn’t set value when creating element if css attributes are used
  • #2241: Slick.finder index selector
  • #2247: Element.get not reading custom attributes in IE7/8
  • #2248: contains causes “Out of Stack Space” in IE
  • #2252: Element.getParents doc clarification
  • #2262: SVGAnimatedString causes Slick error
  • #2266: Calling setOpacity with null does not remove the style
  • #2275: Update Slick to 1.1.7

Known Issues

  • #2184: IE9 on Windows Server throws exception; can’t continue
  • #2194: Function#bind ES5 bug when bound function is called as part of a new expression
  • #2199: Browser.version always returns the same for Android 2-4
  • #2207: Fx.cancel() should clear animation so Fx.resume() will not continue it
  • #2214: IE8 - Cannot inject into window.opener
  • #2225: IE in-page memory leak when using removeChild
  • #2236: IE8 tween/morph clip:rect breaks
  • #2243: Memory leak with request class
  • #2245: Element.getOffsets() is broken in iOS 4.3 if using -webkit-transform
  • #2265: new Element(‘style’, {text: ”}) throws IE exception
  • and more

These issues will be fixed subsequently prior to release of the next maintenance release, 1.4.5.

Contribute

These fixes and improvements would not have happened if you didn’t submit an issue (ticket) to the MooTools Core Issues, or reporting your problems in the MooTools User Group. Send us your (MooTools) issues (or feature requests) so that your favorite JavaScript framework keeps getting better.

Get it!

MooTools 1.4.3 Released

Written By Olmo Maldonado, on Saturday, January 21st 2012, 12:59pm

Today we release MooTools Core 1.4.3 which is a small maintenance release. Upgrading from 1.4.2 should not cause any backward incompatibilities. We recommend that all users upgrade to 1.4.3 as soon as possible.

Fixes

  • #2109: IE7/8 getProperty returns functions
  • #2110: Documentation: Request.JSON’s behaviour of onFailure
  • #2117: Document conflicts between Array and Elements methods
  • #2121: Missing Fx.options.frameSkip documentation.
  • #2126: Re-add undocumented from argument to Element.fade
  • #2127: Element.js memory leaks
  • #2146: Add Element.NativeEvents to docs
  • #2150: Add Fx.isPaused() method
  • #2152: Packaging issue. Build header and Core.js yml header collide
  • #2155: Add special note to Element.empty
  • #2163: IE7 Crash with Mootools Core 1.4.2
  • #2164: Cannot set numerical 0 values to form fields.
  • #2169: Array#filter should store this[i] in a variable before calling the callback.
  • #2170: propertychange on an input[type=radio] with this.checked fires standard onChange
  • #2176: uid remnant which prevented proper cleaning of elements and their storage
  • #2182: element.erase( ‘html’ ) sets content to text ‘undefined’

Known Issues

  • #2129: < IE9 sets width/height attribute once, and doesn’t update on other loads
  • #2130: Object.each doesn’t address IE DontEnum bugs like Object.extend and others
  • #2160: Fx.Tween/Fx.Morph problem with ‘%’ unit
  • #2168: Fixes 2129.
  • #2175: IE Leak: Array.flatten
  • #2178: IE doesn’t set value when creating element if css attributes are used
  • #2183: Incorrect event.key from some keypress events in Firefox
  • #2184: IE9 on Windows Server throws exception; can’t continue
  • #2185: Fix #2184: IE9 on Windows Server throws exception; can’t continue
  • #2188: Fixes #2178 - A input field should keep its value even when the type property is changed (in IE)
  • #2189: Uncaught TypeError: Property ‘id’ of object # is not a function
  • #2193: Element clone storage again
  • #2194: Function#bind ES5 bug when bound function is called as part of a new expression
  • #2196: it’s better for getStyle method always returns style value with px unit
  • #2199: Browser.version always returns the same for Android 2-4
  • and more

These issues will be fixed subsequently prior to release of the next maintenance release, 1.4.4.

Contribute

These fixes and improvements would not have happened if you didn’t submit an issue (ticket) to the MooTools Core Issues, or reporting your problems in the MooTools User Group. Send us your (MooTools) issues (or feature requests) so that your favorite JavaScript framework keeps getting better.

Get it!

JxLib: An Introduction

Written By Aaron Newton, on Monday, December 26th 2011, 3:02pm

Jon Bomgardner is a contributor to the jxlib.org project. After recently joining the MooTools Developer mailing list and sharing his experience in upgrading jxlib to MooTools 1.4.2 we asked him to share his work here on the blog.

What is JxLib

JxLib is a JavaScript UI framework built on MooTools. It allows web developers and designers to quickly build user interfaces for their applications. JxLib is based on some sweet HMTL markup and strives to be fully CSS compliant. It is also a modular library allowing you to pick and choose from the available components as well as giving you the ability to override default behaviors and extend core classes.

All of this flexibility is, in large part, due to being built on MooTools. The library is heavily object-oriented with a huge number of classes inheriting from a single base. If you know how to use the MooTools class system you will quickly get up to speed on JxLib. In addition to being based on HTML and CSS, which provides an amazing amount of flexibility itself, the library’s architecture is based on a plugin system that allows additional functionality to be added to each component at the developer’s discretion.

A couple of quick examples

So, I wanted to show a couple of easy examples of what you can do with JxLib. There’s a ton of functionality built in and for more complete examples you can check out the examples page at jxlib.org. Here are 3 quick jsfiddles that you can play around with to get a feel of some of the functionality.

Example 1: Drop Down Menu Toolbar

This example shows a simple menu toolbar with cascading menus

Example 2 : Jx.Form and Form fields

This example shows off Jx.Form and a lot of the bundled fields you get out of the box.

Example 3: The New Jx.Container and Jx.LayoutManager classes

This one shows off some of the new work in JxLib 3.1.1. It creates the entire layout using a single javascript object. Check out the center panel’s tabs for a look at Jx.Editor and other components.

Experiences achieving compatibility with Core 1.4.2

I am happy to report that the conversion to Core 1.4.2 went relatively easily. The biggest conversion headache was when I originally worked on getting compatibility with 1.3.2 - that was a ton of work. We used many of the $ global methods ($defined, $H, $A were some of the big ones) and they were littered about the code base quite liberally. I really didn’t want to use the compatibility layer that the folks here at MooTools so graciously provided everyone because the download was big enough as it was. Hunting down all of those changes took the most time. In the process of doing so however I learned a few interesting tidbits:

First, it was best to replace $defined() with a check for undefined and null. for example:

if ($defined(some_variable)) {

became

if (some_variable !== undefined && some_variable !== null) {

I realize that the conversion docs state that checking undefined should be enough but when I tried that at first I got a LOT of weird errors. This change fixed them.

The other thing I discovered is that Object.each and Object.keys weren’t all that useful when the object you’re using them with was actually on the prototype of the class they were in. For example, in JxLib 2.0 we had this code:

processElements: function(template, classes) { 
    var keys = classes.getValues(); 
    elements = this.processTemplate(template, keys); 
    classes.each(function(value, key) { 
        if (key != 'elements' && elements.get(value)) { 
            this[key] = elements.get(value); 
        } 
    }, this); 
    return elements; 
}

It seems that those two functions use hasOwnProperty() which was causing the loop above to have 0 iterations because the classes variable was actually this.classes which was found on the prototype of the class. When converting to Core 1.3.2 (and subsequently 1.4.2) we had to use this:

processElements: function(template, classes) { 
    var keys = [], 
        values = []; 
    for (var key in classes){ 
        if (key !== undefined) { 
            values.push(classes[key]); 
            keys.push(key); 
        } 
    } 
    elements = this.processTemplate(template, values); 
    keys.each(function(key){ 
        if (key != 'elements' && elements[classes[key]] !== undefined && elements[classes[key]] !== null) { 
            this[key] =  elements[classes[key]]; 
        } 
    },this); 
    return elements; 
}

Once those were figured out, and we had full compatibility with 1.3.2, moving up to 1.4.x was pretty painless. For more info on what I learned during the conversion (some of it not MooTools or even javascript related) check out my blog post.

Get More information

You can get more information on JxLib at the following places:

If you have any questions or comments feel free to leave those below or in the Google group (linked above). Also, if you like what you’ve seen and read here please consider pitching in and helping to make JxLib even better. We have many plans for future releases but could always use a few extra hands.

MooTools Behavior

Written By Aaron Newton, on Tuesday, December 20th 2011, 7:51pm

Those of you who follow my work over on Clientcide may already be familiar with it, but for the rest of you I wanted to write a blog posts here on MooTools.net about the work I’ve been doing on a library called Behavior - a throwback to the behavior.js library released way back in 2005 which one might consider to be philosophically an ancestor of sorts.

Purpose

All well-written web sites / apps that are interactive have the same basic pattern:

Web app layers

Each page of a site or app you build is esoteric. It may have any combination of interactive elements, some of which interact with each other (for example, a form validation controller might interact with an ajax controller to prevent it sending a form that isn’t valid). Typically this “glue” code exists in a DOMReady statement. It says, get this form and instantiate that class with these options. This code is brittle; if you change either the DOM or the code the state breaks easily. It’s not reusable, it only works for a specific page state. It can easily get out of hand.

Behavior attempts to abstract that DOMReady code into something you only write once and use often. It’s fast and easily customized and extended. Instead of having a DOMReady block that, say, finds all the images on a page and turns them into a gallery, and another block that searches the page for all the links on the page and turns them into tool tips, Behavior does a single search for all the elements you’ve marked. Each element is passed through the filter it names, where a filter is a function (and perhaps some configuration) that you’ve named. Each of these functions takes that element, reads properties defined on it in a prescribed manner and invokes the appropriate UI component.

Why?

The nutshell is that instead of having a DOMReady function that finds the stuff in your DOM and sets up instances of classes and whatnot, you put the configuration in the HTML itself and write the code that calls new Foo(...) only once. Example:

So instead of this:

$$('form').each(function(form){
  new FormValidator(form, someOptions);
  new Form.Request(form, someOptions);
});
new Tips($$('.tip'));
$$('.accordion').each(function(container){
  new Accordion(container.getElements('.toggler'), container.getElements('.section'), someOptions);
});
//etc

You do this:

<form data-behavior="FormValidator FormRequest" data-formvalidator-options="{someOptions}">...</form>
<a data-behavior="Tip" title="I'm a tip!">blah</a>
<div data-behavior="Accordion" data-accordion-options="{someOptions}">...</div>

Think of it as delegation (as in event delegation) for class invocation. If you use DOMReady to do your setup and you want to swap out some HTML with AJAX, you need to reapply that startup selectively to only your components that you’re updating, which is often painful. Not with Behavior, you just apply the filters to the response and call it a day.

You do a lot less DOM selection; you only ever run $$('[data-behavior]') once (though some filters may run more selectors on themselves - like Accordion finding its togglers and sections).

DOMReady setup is always closely bound to the DOM anyway, but it’s also separated from it. If you change the DOM, you might break the JS that sets it up and you always have to keep it in sync. You almost can’t do that here because the DOM and its configuration is closely bound and in the same place.

Developers who maybe aren’t interested in writing components don’t need to wade into the JS to use it. This is a big deal if you’re working with a team you must support.

Behavior is designed for apps that are constantly updating the UI with new data from the server. It’s not an MVC replacement though. It’s designed for web development that uses HTML fragments not JSON APIs (though it can play nicely with them). If you destroy a node that has a widget initialized it’s easy to make sure that widget cleans itself up. The library also allows you to create enforcement to prevent misconfiguration and an API that makes it easy to read the values of the configuration. (More on that in a bit).

There are some other nifty things you get out of it; you get essentially free specs tests and benchmarks because the code to create both of them is in the Behavior filter. Here’s an example of what it takes to write a spec for a widget and ALSO the benchmark for it’s instantiation (this uses Behavior.SpecsHelpers.js).

Behavior.addFilterTest({
  filterName: 'OverText',
  desc: 'Creates an instance of OverText',
  content:  '<input data-behavior="OverText" title="test"/>',
  returns: OverText
});

This code above can be used to validate that the HTML fragment passed in does, in fact, create an OverText instance and it can also be used with Benchmark.js to see which of your filters are the most expensive.

Delegator

Included in the library is also a file called Delegator which is essentially the same thing except for events. For example, let’s say you have a predictable UI pattern of having a link that, when clicked, it hides a parent element. Rather than writing that code each time:

document.body.addEvent("click:a.hideParent", function(e, link){
  e.preventDefault();
  link.getParent().hide();
});

You register this pattern with Delegator and now you just do:

<a data-trigger="hideParent" data-hideparent-options ="{'target': '.someSelector'}">Hide Me!</a>

It provides essentially the same value as Behavior, but at event time. The above example is pretty straight forward so, you know, why bother, right? But consider how many of these little things you write to make a web app function. If you can create them once and configure them inline, you save yourself a lot of code.

BehaviorAPI

This stand-alone library facilitates reading values from element data- properties. Examples of the HTML expressions evaluated are as follows (all of the following produce the same output):

<tag data-behavior="Filter1 Filter2" data-filter1-options="{'opt1': 'foo', 'opt2': 'bar', 'selector': '.selector'}"> //prefered
<tag data-behavior="Filter1 Filter2" data-filter1-options="'opt1': 'foo', 'opt2': 'bar', 'selector': '.selector'"> //no braces on JSON
<tag data-behavior="Filter1 Filter2" data-filter1-options="{'opt1': 'foo', 'opt2': 'bar'}" data-filter1-selector=".selector">
<tag data-behavior="Filter1 Filter2" data-filter1-opt1='foo' data-filter1-opt2='false' data-filter1-selector=".selector">

The -options value is parsed as JSON first (it’s slightly more permissive in that you don’t have to wrap it in {} just for convenience). Values defined here are read as defined allowing you to express arrays, numbers, booleans, etc. Functions / callbacks are generally not used by Behavior.

If you attempt to read a value that isn’t defined in this options object, the property name is attempted to be read from the property directly (e.g. data-behaviorname-prop). This value is always a string unless you specify a type. If a type is specified the value is run through the JSON parser and validated against that type.

Even if you don’t want to use the whole Behavior suite, this library may be of use if you like the idea of including configuration inline. There’s a lot more in BehaviorAPI so it’s worth perusing the docs for it.

Documentation

Stock Behaviors

Check out these resources of available Behavior Filters provided by the author:

Demos

Notes

Below are some notes regarding the implementation. The documentation should probably be read first as it gives usage examples.

  • Only one selector is ever run; adding 1,000 filters doesn’t affect performance.
  • Nodes can have numerous filters.
  • Nodes can have an arbitrary number of supported options for each filter (data-behaviorname-foo="bar").
  • Nodes can define options as JSON (this is actually the preferred implementation - data-behaviorname-options="<your JSON>").
  • Elements can be retired w/ custom destruction; cleaning up an element also cleans up all the children of that element that have had behaviors applied.
  • Behaviors are only ever applied once to an element; if you call myBehavior.apply(document.body) a dozen times, the elements with filters will only have those filters applied once (can be forced to override and re-apply).
  • Filters are instances of classes that are applied to any number of elements. They are named uniquely.
  • Filters can be namespaced. Declare a filter called Foo.Bar and reference its options as data-foo-bar-options="...".
  • There are “global” filters that are registered for all instances of behavior.
  • Instance filters get precedence. This allows for libraries to provide filters (like http://github.com/anutron/more-behaviors) but for a specific instance to overwrite it without affecting the global state. (This pattern is in MooTools’ Form.Validator and works pretty well).

Limitations:

  • Due to the DOM-searching for both creation and destruction, you can’t have behavior instances inside each other.

Downloading

You can find Behavior on github and also on Clientcide where you’ll also find a builder. That builder will also let you get the stock behaviors from Clientcide and the ones I’ve authored for MooTools More. If you want to get to the bootstrap builder, be sure to select “MooTools Bootstrap” in the top menu (or just clicketh hereth).

MooTools 1.4.2 Released

Written By Olmo Maldonado, on Friday, December 2nd 2011, 4:03pm

Today we release MooTools Core 1.4.2 which is a small maintenance release. Upgrading from 1.4.1 should not cause any backward incompatibilities. We recommend all users upgrade to 1.4.2 as soon as possible.

Fixes

  • #2073: Reduced redundant call to onTimeout if async option is true.
  • #2083: Fixes Element.clone in IE.
  • #2085: All specs are green across.
  • #2110: Element.erase('class') did not clear the class.
  • #2113: button.set('type', 'button') is now fixed for webkit bug.
  • #2116: Fixes Element.fade chain.
  • #2118: $uid method is no longer exposed

Improvements

  • #2089: Added support for native mouseenter and mouseleave.
  • #2134: Deprecates the MooTools Core Specs repository in favor of including the specs in the Core repo. Due to ease of development.
  • Series of new specs and refactoring of old specs. Specs are all passing and much faster.
  • #2138: Native Element.fireEvent in IE is now accessible in via Element._fireEvent.

Known Issues

  • Documentation fixes/additions for Element.NativeEvents, Fx, Request.JSON, and conflicts between Array and Elements methods.
  • Object.each enumeration
  • Possible leak with Element.adopt
  • IE returns methods for some Element attributes.
  • Element.Delegation problem with non-elements.

These issues will be fixed subsequently prior to release of the next maintenance release.

Get it!

Contribute

These fixes and improvements would not have happened if you didn’t submit an issue (ticket) to the MooTools Core Issues, or reporting your problems in the MooTools User Group. Send us your (MooTools) issues (or feature requests) so that your favorite JavaScript framework keeps getting better.