O jQuery UI é uma evolução do pattern de desenvolvimento de plugins para o jQuery. Com o Widget factory é possível ter plugins mais flexíveis para o jQuery e usando o Jasmine como ferramenta de BDD, é possível desenvolver melhores componentes jQuery com testes automatizados e ter uma aplicação web mais rica com menos bugs.
6. OUTROS PROJETOS...
Blog Webpoint
http://blog.alexadremagno.net eutro.co
http://eutro.co
Balloon3
http://balloon3.com
Salve a web por favo
http://salveaweb.com/
30. " >
sc ript
xt/ java JQUERY JFLOW
= "t e
type (){
ript ction ) .jfl
ow()
;
PATTERN DE PLUGIN BÁSICO
< s c fun nto'
leme
https://github.com/alexanmtz/jflow
$(
! (' # e
! ! $
! }); t>
p
</ scri
ao clicar aqui
Os elementos se mo
vem
e aqui
31. Ô NÓ, Eu quero usar o jflow em
meu projeto, mas a minha listagem
vai ser dinâmica, com possibilidade
de novos itens serem adicionados,
porém não está funcionando!
33. <scrip
t type
avasc r i p t" > ! $(fu = "t e x t
/javas
text/j nction
(){ c r i p t"
t type=" ! ! $
('#ele >
<scrip ction(){ flow({ mento2
$(fun .j ').jfl
! e nto1') items: ow({
( ' #elem s: 5 4
! ! $ item ! });
});
}); </scri
pt>
! });
t>
< /scrip
e aqui
ao clicar aqui
34. <scrip
t type
avasc r i p t" > ! $(fu = "t e x t
/javas
text/j nction
(){ c r i p t"
t type=" ! ! $
('#ele >
<scrip ction(){ flow({ mento2
$(fun .j ').jfl
! e nto1') items: ow({
( ' #elem s: 5 4
! ! $ item ! });
});
}); </scri
pt>
! });
t>
< /scrip
e aqui
ao clicar aqui
38. r">
<div i d = "c o n t a i n e
! ul>
<
Métodos de classe
li>
! <
! li> item 1</
i>
! <l i> item 2</l
!
> item 3</li
> Atributos data
! <li
!
/li>
!! <li> item 4<
! /ul>
<
</div> w({
$('#conta iner').jflo
! tens: 3,
i ,
ta i n e r u l l i'
i t e m : '# c o n Como chamar método
zon t a l' s?
! mode: ' hori
});
preciso executar u
ma ação
ow_metodo( ); //no!
$('#contai n e r' ) . j f l
$('#container
').jflow.meto
do(); //wtf
44. p t" >
java
s cri
;
COM O WIDGET FACTORY
t/ )
" tex ete(
ype= ){ c ompl
pt t ion( auto
< scri unct o').
( f e ment
! $ $(' # e l
! ! ;
)
! } ipt>
< /scr
... ) })
(
ete , {
toc ompl
$.u i.au p t" >
" , cri
se arch t/j avas
ui. auto " tex h();
" ype= ){ earc
get(
s
id pt t ion( auto
$.w < scri unct o').
(f e ment
! $ $('#el
! ! ;
TEMOS HERANÇA ! })
ipt>
< /scr
56. // widget factory
$.widget( “ui.sliding”, {
options: {
items: 5
// mais opcoes
},
pages: 0,
_create: function() {
this._enclose();
},
_enclose: function() {
// enclose envolve o elemento deslizante
// this.options são as opções
}
goToPage: function(page) {
// logica de ir para pagina
// this.element é o elemento
// this.options são as opções
}
});
73. SPEC
sliding / tests / spec / SlidingSpec.js
it("should get the currentPage and check if is last one", function(){
$(container).sliding('goToPage', 2);
var currPage = $(container).sliding.('getCurrentPage');
expect(currPage).toBe(2);
expect($(container).sliding(‘isLastPage’)).toBeTruthy();
});
78. MOCK DO DATA
VINDO DO AJAX
sliding / tests / spec / SlidingSpec.js
describe("remote sliding", function(){
var newData = '';
beforeEach(function(){
newData = createUnorderedList(30, true);
spyOn($, 'ajax').andCallFake(function(options){
options.success(newData);
});
});
79. E COM ISSO...
sliding / tests / spec / SlidingSpec.js
it("should make a ajax request for second page", function(){
$(container).sliding({
next: '.test-next',
prev: '.test-prev',
url: 'foo/test',
items: 15 // one page
});
$(container).sliding('setTotalPages', 3);
$('.test-next').trigger('click');
expect($(container).get(0)).beInRange(15,30); // Next
});
80. MATCHERS
sliding / tests / spec / SpecHelper.js
beforeEach(function() {
this.addMatchers({
beInRange: function(start, end) {
var isIn = 0;
var current_width = $(this.actual).width();
var container_pos = $(this.actual).position();
var final_pos = current_width + container_pos.left;
$(this.actual).find('li').slice(start,
end).each(function(i, el){
var el_pos = $(this).position();
if (el_pos.left < final_pos && el_pos.left >=
container_pos.left) {
isIn++;
}
});
return isIn == $(this.actual).sliding('option','items');
}
});
});