gizzmo
21 May 2008, 12:40 PM
Hi,
I was writing a image slideshow extension for one of my projects.
Ext.ux.ImageSlideshow = Ext.extend(Ext.Container, {
start: 0,
duration: 1,
easing: 'easeNone',
pause: 5000,
// private
initComponent : function(){
Ext.ux.ImageSlideshow.superclass.initComponent.call(this);
this.tpl = new Ext.Template('<img src="{url}">');
this.tpl.compile();
if(this.ds) {
this.store = this.ds;
delete this.ds;
} else {
this.store = new Ext.data.JsonStore({
autoLoad: this.autoLoad,
baseParams: this.params,
url: this.url,
root: 'data',
fields: [
{name: 'url', type: 'string'}
]
});
}
this.store = Ext.StoreMgr.lookup(this.store);
this.store.on('load', this.loop, this);
},
// private
onRender: function(ct, position) {
this.el = ct.createChild({
id: this.id,
cls: this.baseCls
}, position);
this.el.setWidth(this.width);
this.el.setHeight(this.height);
},
load: function() {
this.store.load();
},
//private
loop: function() {
if(this.store.getCount()>0) {
var r = this.store.getAt(this.start++);
this.el.fadeOut({
duration: this.duration,
easing: this.easing,
scope: this,
useDisplay: true,
callback: function() {
this.tpl.overwrite(this.el.dom, r.data);
this.el.fadeIn({
duration: this.duration,
easing: this.easing,
scope: this,
callback: function() {
if( this.start == this.store.getCount() ) {
this.start = 0;
}
setTimeout( this.loop.createDelegate(this), this.pause );
}
});
}
});
}
}
});
Ext.reg('image-slideshow', Ext.ux.ImageSlideshow);
and implementation:
var slideshow = new Ext.ux.ImageSlideshow({
autoLoad: true,
renderTo: 'commercial',
width: 1000,
height: 225,
url: basePath+'/action/image/getImageSlideshow',
params: {tournamentId: tournamentId, type: 'COMMERCIAL_1000x225'}
});
and data:
{
"success" : true,
"totals" : 3,
"data" :[{
"height" : 225,
"url" : "/action/image/get?id=10048",
"width" : 1000
},{
"height" : 225,
"url" : "/action/image/get?id=10049",
"width" : 1000
},{
"height" : 225,
"url" : "/action/image/get?id=10047",
"width" : 1000
}]
}
Thanks
I was writing a image slideshow extension for one of my projects.
Ext.ux.ImageSlideshow = Ext.extend(Ext.Container, {
start: 0,
duration: 1,
easing: 'easeNone',
pause: 5000,
// private
initComponent : function(){
Ext.ux.ImageSlideshow.superclass.initComponent.call(this);
this.tpl = new Ext.Template('<img src="{url}">');
this.tpl.compile();
if(this.ds) {
this.store = this.ds;
delete this.ds;
} else {
this.store = new Ext.data.JsonStore({
autoLoad: this.autoLoad,
baseParams: this.params,
url: this.url,
root: 'data',
fields: [
{name: 'url', type: 'string'}
]
});
}
this.store = Ext.StoreMgr.lookup(this.store);
this.store.on('load', this.loop, this);
},
// private
onRender: function(ct, position) {
this.el = ct.createChild({
id: this.id,
cls: this.baseCls
}, position);
this.el.setWidth(this.width);
this.el.setHeight(this.height);
},
load: function() {
this.store.load();
},
//private
loop: function() {
if(this.store.getCount()>0) {
var r = this.store.getAt(this.start++);
this.el.fadeOut({
duration: this.duration,
easing: this.easing,
scope: this,
useDisplay: true,
callback: function() {
this.tpl.overwrite(this.el.dom, r.data);
this.el.fadeIn({
duration: this.duration,
easing: this.easing,
scope: this,
callback: function() {
if( this.start == this.store.getCount() ) {
this.start = 0;
}
setTimeout( this.loop.createDelegate(this), this.pause );
}
});
}
});
}
}
});
Ext.reg('image-slideshow', Ext.ux.ImageSlideshow);
and implementation:
var slideshow = new Ext.ux.ImageSlideshow({
autoLoad: true,
renderTo: 'commercial',
width: 1000,
height: 225,
url: basePath+'/action/image/getImageSlideshow',
params: {tournamentId: tournamentId, type: 'COMMERCIAL_1000x225'}
});
and data:
{
"success" : true,
"totals" : 3,
"data" :[{
"height" : 225,
"url" : "/action/image/get?id=10048",
"width" : 1000
},{
"height" : 225,
"url" : "/action/image/get?id=10049",
"width" : 1000
},{
"height" : 225,
"url" : "/action/image/get?id=10047",
"width" : 1000
}]
}
Thanks