-
4 Nov 2011 1:27 AM #1
Unanswered: AUTO SLIDING IN CAROUSEL while using MVC architecture
Unanswered: AUTO SLIDING IN CAROUSEL while using MVC architecture
Hi ,
I am trying to enable autoslide to my carousel.In my application,the carousel is a child of which viewport is a parent.I couldn't call/define any function in the 'listeners'.Whenever I refer the element using "this",I think the reference points to the parent viewport ,Also,my attempt to use the 'xtype' also failed.Can anyone help me?
-
4 Nov 2011 7:00 AM #2
Hi.
Can you post some code on how are you trying to do that just to understand your application architecture and find the scope issue?
Thank youSencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
6 Nov 2011 9:42 PM #3
Hi,
I have a tab panel as parent.Inside that I have two panels.In one of that panel,I have a carousel and a list.
I have to make that carousel to slide automatically in a specific interval.Let me show the code of my carousel. Hopefully awaiting your reply.
CODE:
Code:Code:Ext.define('Sencha.view.Article', { extend: 'Ext.Carousel', xtype: 'articlespage', layout: 'card', cardSwitchAnimation: 'fade', config: { title: 'Articles', iconCls: 'star', height: 400, items: [ { html:"some html text and image here", style: 'background-color:#110310;', ui:'light' }, { html:"some html text and image here", style: 'background-color:#110310;', ui:'light' } ], listeners: { // Here I couldn't get access to the object of carousel.I couldn't use "this" or "xtype" here.// } } });
How can I access the object of my carousel?...
Once again thanks.....
-
7 Nov 2011 11:03 AM #4
Do you also need listen for user interaction with the carousel and delay automation until the user stops interacting with the carousel?
-
7 Nov 2011 11:05 AM #5
oh… by object what are you referring to the carousel component, root level Ext.Element or items within the carousel?
-
7 Nov 2011 9:27 PM #6
Hi oddz,
Thanks.I meant exactly what you have asked.The carousel autosliding should be delayed while user interacts with it.So I have to listen for user interaction.
By object, I thought of referring the root level Ext. element,I mean the carousel itself.But it will be great if you can provide pieces of code for accessing both,items within the carousel, as well as root level element. Hopefully awaiting your reply...

-
17 Nov 2011 2:38 AM #7
For accessing a listener on a 'this', its default is do scope itself on the object that defines it - in your case 'Article'. However, there must exist an event before you can listen - check docs for these. In short, what happens is the same as the above override - the user functionality is run and then the corresponding general (if any) event handler runs. You could do like this:PHP Code:Ext.define("Article", {
xtype: 'articlespage',
layout: 'card',
cardSwitchAnimation: 'fade',
config: {
title: 'Articles',
iconCls: 'star',
height: 400,
items: [
{
html:"some html text and image here",
style: 'background-color:#110310;',
ui:'light'
},
{
html:"some html text and image here",
style: 'background-color:#110310;',
ui:'light'
}
],
/***********************************/
//@override
onDragStart : function() {
//// implement your code here
this.callParent(arguments); // note, UI updating only fires if 'callparent' runs
},
onDrag : function() {
this.callParent(arguments);
},
onDragEnd: function() {
this.callParent(arguments);
},
/***********************************/
listeners:
{
// Here I couldn't get access to the object of carousel.I couldn't use "this" or "xtype" here.//
}
}
PHP Code:...
listeners : {
show : this.myShow
},
myShow : function() {
// here you will have this == Ext.getCmp(Article)
}
...
-
20 Nov 2011 7:42 AM #8
-
20 Nov 2011 2:27 PM #9
This will likely become a mixin but the below method seems to work well.
Code:Ext.define('Exp.view.Carousel',{ extend: 'Ext.carousel.Carousel', xtype: 'expcarousel', config: { height: 200, items: [ {html: 'One'}, {html: 'Two'}, {html: 'Three'}, {html: 'Four'}, {html: 'Five'} ] }, automation: null, constructor: function() { this.callParent(arguments); this.startAutomate(); }, onDragStart: function() { this.stopAutomate(); this.callParent(arguments); }, onDragEnd: function() { this.callParent(arguments); this.startAutomate(); }, stopAutomate: function() { clearTimeout(this.automation); }, startAutomate: function() { this.automation = setTimeout((function(me) { return function() { me.onAutomateInterval(); }; })(this),5000); }, onAutomateInterval: function() { this.on('activeitemchange',this.startAutomate,this,{single:true}); this.next(); } });
-
20 Nov 2011 4:51 PM #10
Here is a mixin that also goes to the first card when the last is reached.
Code:Ext.define('Exp.mixin.Automated',{ extend: 'Ext.mixin.Mixin', automation: null, config: { delay: 5000 }, mixinConfig: { id: 'automated', beforeHooks: { stop: 'onDragStart' }, afterHooks: { doInitialize: 'doInitialize', start: 'onDragStart' } }, doInitialize: function() { this.start(); }, stop: function() { clearTimeout(this.automation); }, start: function() { this.automation = setTimeout((function(me) { return function() { me.interval(); }; })(this),this.getDelay()); }, interval: function() { var cards = this.getInnerItems(); this.on('activeitemchange',this.start,this,{single:true}); if((cards.length - 1) === this.getActiveIndex()) { this.setActiveItem(cards[0]); } else { this.next(); } } });


Reply With Quote