5. Na minha visão, aplicações JavaScript
de larga escala são aplicações não-
triviais que requerem um esforço
significante de manutenção por parte do
desenvolvedor, onde a maior parte do
trabalho de manipulação de dados e
visualização é atribuída ao navegador.
Addy Osmani
Developer Programs Engineer @ Google
6. Aplicações com front-end de larga
escala são aplicações não-triviais que
requerem um esforço significante de
manutenção por parte do
desenvolvedor, onde organização,
modularização, otimização e reutilização
de código são cruciais.
Eduardo Shiota Yasuda
Loves cat videos on Youtube
9. O CSS de um blog é geralmente simples, com algumas centenas de linhas de código,
concentrado em um único arquivo. Não é tão difícil de manter.
10. Mesma coisa para o JS: geralmente um arquivo e alguns plugins, e tudo sendo chamado em
uma única função auto-executável.
11. O tema Twenty Ten do Wordpress mostra uma estrutura básica de blog: alguns templates,
um CSS. Provavelmente terá um único arquivo de JavaScript também.
44. /**
Loader constructor
@params {Function} placement Function that determines the loader's placement
@constructor
**/
ns("EDEN.ui.Loader", function (placement) {
if (!(this instanceof EDEN.ui.Loader)) {
return new EDEN.ui.Loader(placement);
}
this.frame = 1;
this.framesQty = 8;
this.stack = [];
this.animating = false;
this.$loader = $("<div class='loader'><b> </b></div>");
this.$renderer = this.$loader.find("b");
this.placement = placement;
this.init();
});
45. /**
Animation speed (in frames per second)
@property fps
@type Number
@default 20
**/
EDEN.ui.Loader.prototype.fps = 20;
/**
Fading speed
@property fadeSpeed
@type Number
@default 150
**/
EDEN.ui.Loader.prototype.fadeSpeed = 150;
46. /**
Inits the loader by inserting it into the DOM. If a placement argument
wasn't passed to the constructor, uses a generic placement.
@method init
**/
EDEN.ui.Loader.prototype.init = function () {
if (!this.placement) {
this.placement = function ($loader) {
$loader.appendTo($("body"));
};
}
this.placement.call(this, this.$loader);
};
47. /**
Starts the loader by fading in and starting the animation.
If there are multiple processes, stacks the requests.
@method start
**/
EDEN.ui.Loader.prototype.start = function () {
this.stack.push((new Date()).getTime());
if (this.stack.length === 1) {
this._startAnimation();
}
};
/**
Stops the loader by fading out and stoping the animation
If there are any processes pending, pops the requests
until it can actually stop.
@method stop
**/
EDEN.ui.Loader.prototype.stop = function () {
this.stack.pop();
if (!this.stack.length) {
this._stopAnimation();
}
};
48. /**
Starts the loader animation
@private
**/
EDEN.ui.Loader.prototype._startAnimation = function () {
this.animating = true;
this._renderAnimation();
};
/**
Stops the loader animation
@private
**/
EDEN.ui.Loader.prototype._stopAnimation = function () {
this.animating = false;
};
49. /**
Loops the animation, calling itself according to the fps
@private
**/
EDEN.ui.Loader.prototype._renderAnimation = function () {
if (!this.animating) { return true; }
this._draw();
setTimeout(this._renderAnimation.bind(this), 1000 / this.fps);
};
/**
Draws the animation
@private
**/
EDEN.ui.Loader.prototype._draw = function () {
this.$renderer.removeClass().addClass("f" + this.frame);
this.frame = this.frame + 1 > this.framesQty ? 1 : this.frame + 1;
};
/**
Returns the animation stack.
@return Array
@private
**/
EDEN.ui.Loader.prototype._getAnimationStack = function () {
return this.stack;
};
51. it("appends the loader to body as a default", function () {
var loader = new Loader();
expect($("body").find(".loader").length).toEqual(1);
});
it("appends the loader through an argument function", function () {
var loader = new Loader(function ($loader) {
$("#loader-placeholder").append($loader);
});
expect($("#loader-placeholder").find(".loader").length).toEqual(1);
});
it("stops the animation if stack is empty", function () {
loader.start();
loader.stop();
expect($(".loader").data("spinning")).not.toBeTruthy();
});
57. //my/shirt.js now has some dependencies, a cart and inventory
//module in the same directory as shirt.js
define(["./cart", "./inventory"], function(cart, inventory) {
//return an object to define the "my/shirt" module.
return {
color: "blue",
size: "large",
addToCart: function() {
inventory.decrement(this);
cart.add(this);
}
};
}
);