Zepto.JS

Fazendo "mais com menos"

Luiz Tiago

Zepto.JS

Target platforms

jQuery - $()

					
var match, elem, ret, doc;

// Handle $(""), $(null), $(undefined), $(false)
if ( !selector ) {
    return this;
}

// Handle $(DOMElement)
if ( selector.nodeType ) {
    this.context = this[0] = selector;
    this.length = 1;
    return this;
}

// Handle HTML strings
if ( typeof selector === "string" ) {
    if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
        // Assume that strings that start and end with <> are HTML and skip the regex check
        match = [ null, selector, null ];

    } else {
        match = rquickExpr.exec( selector );
    }

    // Match html or make sure no context is specified for #id
    if ( match && (match[1] || !context) ) {

        // HANDLE: $(html) -> $(array)
        if ( match[1] ) {
            context = context instanceof jQuery ? context[0] : context;
            doc = ( context && context.nodeType ? context.ownerDocument || context : document );

            // scripts is true for back-compat
            selector = jQuery.parseHTML( match[1], doc, true );
            if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
                this.attr.call( selector, context, true );
            }

            return jQuery.merge( this, selector );

        // HANDLE: $(#id)
        } else {
            elem = document.getElementById( match[2] );

            // Check parentNode to catch when Blackberry 4.6 returns
            // nodes that are no longer in the document #6963
            if ( elem && elem.parentNode ) {
                // Handle the case where IE and Opera return items
                // by name instead of ID
                if ( elem.id !== match[2] ) {
                    return rootjQuery.find( selector );
                }

                // Otherwise, we inject the element directly into the jQuery object
                this.length = 1;
                this[0] = elem;
            }

            this.context = document;
            this.selector = selector;
            return this;
        }

    // HANDLE: $(expr, $(...))
    } else if ( !context || context.jquery ) {
        return ( context || rootjQuery ).find( selector );

    // HANDLE: $(expr, context)
    // (which is just equivalent to: $(context).find(expr)
    } else {
        return this.constructor( context ).find( selector );
    }

// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
    return rootjQuery.ready( selector );
}

if ( selector.selector !== undefined ) {
    this.selector = selector.selector;
    this.context = selector.context;
}

return jQuery.makeArray( selector, this );

				

Zepto.JS - $()

return document.querySelectorAll(context)
				

Noooooossa,
é muito mais rápido!

Será?

http://jsperf.com/getelementbyid-vs-queryselector-vs-jquery

jQuery

jQuery - Um pouco sobre o futuro

Zepto.JS

Zepto.JS

Core

Zepto.JS

Events

Zepto.JS

Ajax

Zepto.JS

Effects

$.fadeOut()

Eu queria muito usar o fadeOut :(

fadeOut é muito legal :(

fadeOut parece Flash, po!

Do it! :)

;(function($){
    $.extend($.fn, {
        fadeOut: function(){
            return this.animate({
                opacity: 0
            }, 5000, 'linear');
        }
    })
})(Zepto)
					

$.fadeOut()

$.slideUp()

Ah o fade é fácil, eu queria slideUp :(

slideUp é muito legal :(

Do it! :)

;(function($){
    $.extend($.fn, {
        slideUp: function(){
            this.css('overflow','hidden');
            return this.animate({
                height: 0
            }, 5000, 'linear');
        }
    })
})(Zepto)
					

$.slideUp()

Leia o código!

replaceWith()

replaceWith: function(newContent){
    return this.before(newContent).remove()
}
				

indexOf()

index: function(element){
    return element ? this.indexOf($(element)[0]) : 
    this.parent().children().indexOf(this[0])
}
				

$.get()

$.get = function(url, success){ 
    return $.ajax({ url: url, success: success }) 
}
				

$.post()

$.post = function(url, data, success, dataType){
    if ($.isFunction(data)) {
    	dataType = dataType || success, 
    	success = data
    	data = null
    }
    return $.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType })
}
				

$.getJSON()

$.getJSON = function(url, success){
    return $.ajax({ url: url, success: success, dataType: 'json' })
}
				

Touch events

$.swipe() / $.swipeLeft()
$.swipeRight()

Zepto.JS - Documentation

Micro-libraries / Micro-frameworks

Micro.JS

Obrigado, Maceió!