Hi All,
I'm using Bill Scott's YUI carousel v5.6, and I've run into a crazy looping javascript for some reason, and I can't seem to get around it.
The carousel loads a bunch of items, 7 of which are visible, and then via ajax it loads more and ads them to them on to the list as it goes.
If a user selects one of the items, that item scrolls to the middle and is highlighted.
I've got all this working, except that when a user clicks, the item scrolls and is highlighted, and then it loops through that same script and scrolls to another item (sometimes 3 or 4 times). Nothing in here tells it to loop, so I am at a total loss as to why it would do this.
I've included an alert, and it does get called after each scroll, and when a loop occurs, the alert is called multiple times and displays the proper index+start value, so that all works, but nothing is being clicked.
As an example of the error, I was on #7,
- I clicked on #5
- alert showed 5
-carousel scrolled to 5
-alert showed 8
-carousel scrolled to 8
-alert showed 11
-carousel scrolled to 11
- that for some reason ended the loop.
That was all from ONE click. It should have just gone to 5 and stopped.
I've only included the code which I think is affecting this rather than having somebody look through ALL of my code. I don't think I've missed anything. -
---- the ajax response which adds the items to the carousel-----
-
var handleSuccess = function(callbackResponse)
-
{
-
var start = callbackResponse.argument[0];
-
var numResults = callbackResponse.argument[1];
-
var carousel = callbackResponse.argument[2];
-
-
if(callbackResponse.responseText !== undefined) {
-
theList = eval( '(' + callbackResponse.responseText + ')' );
-
for(var i=0; i< theList.ResultSet.totalResultsReturned; i++) {
-
result = theList.ResultSet.Result[i];
-
carousel.addItem(start+i, fmtInnerHTML(result, i, seed));
-
-
// Image click will scroll to the corresponding carousel item.
-
YAHOO.util.Event.addListener('goto-'+i, 'click', function(evt) { alert(this.index+start)
-
carousel.scrollTo(this.index+start);
-
}, {carousel:carousel,index:i}, true);
-
}
-
showButtons();
-
}
-
};
-
-
---- the scrollTo function ----
-
scrollTo: function(newStart) {
-
this._position(newStart, true);
-
},
-
-
---- the _position function called from ScrollTo ----
-
_position: function(newStart, showAnimation) {
-
// do we bypass the isAnimated check?
-
if(newStart > this.firstVisible) {
-
var inc = newStart - this.firstVisible;
-
this._scrollNextInc(this, inc, showAnimation);
-
}
-
else if(newStart < this.firstVisible) {
-
var dec = this.firstVisible - newStart;
-
this._scrollPrevInc(this, dec, showAnimation);
-
}
-
else if(newStart = this.firstVisible) {
-
alert('you are already here!');
-
}
-
},
-
----- the scrollTo function -----
-
-
ABSOLUTELY ANY advise on this would be great. I'm at a total loss.
2 1668
Digging into this issue further, I realized the following code might be useful as well. -
-
-
_scrollPrevInc: function(carousel, dec, showAnimation) {
-
-
var currLastVisible = carousel.lastVisible;
-
var newStart = carousel.firstVisible - dec;
-
newStart = (newStart <= 1) ? 1 : (newStart);
-
var newDec = carousel.firstVisible - newStart;
-
carousel.priorFirstVisible = carousel.firstVisible;
-
carousel.firstVisible = newStart;
-
-
// if prev is enabled && we are now at position 1, then disable
-
if((carousel.prevEnabled === true) && (carousel.firstVisible == 1)) {
-
carousel._disablePrev();
-
}
-
// if the next button is disabled and end is < size, then enable it
-
if((carousel.nextEnabled === false) &&
-
((carousel.firstVisible + carousel.numVisible - 1) < carousel.size)) {
-
carousel._enableNext();
-
}
-
-
// if we are decrementing
-
if(newDec > 0) {
-
if(carousel._isValidObj(carousel.loadPrevHandler)) {
-
carousel.lastVisible = carousel.firstVisible + carousel.numVisible - 1;
-
-
carousel.currSize = (carousel.lastVisible > carousel.currSize) ?
-
carousel.lastVisible : carousel.currSize;
-
-
var alreadyCached = carousel._areAllItemsLoaded(carousel.firstVisible,
-
currLastVisible);
-
-
var revealOffset = (this.revealAmount > 0) ? 1:0;
-
carousel.loadPrevHandlerEvt.fire(carousel.firstVisible+revealOffset,
-
carousel.lastVisible, alreadyCached);
-
}
-
-
if(showAnimation) {
-
var prevParams = { points: { by: [carousel.scrollAmountPerInc*newDec, 0] } };
-
if(carousel.isVertical()) {
-
prevParams = { points: { by: [0, carousel.scrollAmountPerInc*newDec] } };
-
}
-
-
carousel.scrollPrevAnim = new YAHOO.util.Motion(carousel.carouselList,
-
prevParams,
-
carousel.cfg.getProperty("animationSpeed"), carousel.animationMethod);
-
if(carousel._isValidObj(carousel.animationCompleteHandler)) {
-
carousel.scrollPrevAnim.onComplete.subscribe(this._handleAnimationComplete, [carousel, "prev"]);
-
}
-
carousel.scrollPrevAnim.animate();
-
} else {
-
if(carousel.isVertical()) {
-
var currY = YAHOO.util.Dom.getY(carousel.carouselList);
-
YAHOO.util.Dom.setY(carousel.carouselList, currY +
-
carousel.scrollAmountPerInc*newDec);
-
} else {
-
var currX = YAHOO.util.Dom.getX(carousel.carouselList);
-
YAHOO.util.Dom.setX(carousel.carouselList, currX +
-
carousel.scrollAmountPerInc*newDec);
-
}
-
}
-
}
-
-
return false;
-
},
-
-
_scrollNextInc: function(carousel, inc, showAnimation) {
-
-
var currFirstVisible = carousel.firstVisible;
-
-
var newEnd = carousel.firstVisible + inc + carousel.numVisible - 1;
-
newEnd = (newEnd > carousel.size) ? carousel.size : newEnd;
-
var newStart = newEnd - carousel.numVisible + 1;
-
inc = newStart - carousel.firstVisible;
-
carousel.priorFirstVisible = carousel.firstVisible;
-
carousel.firstVisible = newStart;
-
-
// if the prev button is disabled and start is now past 1, then enable it
-
if((carousel.prevEnabled === false) && (carousel.firstVisible > 1)) {
-
carousel._enablePrev();
-
}
-
// if next is enabled && we are now at the end, then disable
-
if((carousel.nextEnabled === true) && (newEnd == carousel.size)) {
-
carousel._disableNext();
-
}
-
-
if(inc > 0) {
-
if(carousel._isValidObj(carousel.loadNextHandler)) {
-
carousel.lastVisible = carousel.firstVisible + carousel.numVisible - 1;
-
-
carousel.currSize = (carousel.lastVisible > carousel.currSize) ?
-
carousel.lastVisible : carousel.currSize;
-
-
var alreadyCached = carousel._areAllItemsLoaded(currFirstVisible,
-
carousel.lastVisible);
-
var revealOffset = (this.revealAmount > 0) ? 1:0;
-
carousel.loadNextHandlerEvt.fire(carousel.firstVisible,
-
carousel.lastVisible+revealOffset, alreadyCached);
-
}
-
-
if(showAnimation) {
-
var nextParams = { points: { by: [-carousel.scrollAmountPerInc*inc, 0] } };
-
if(carousel.isVertical()) {
-
nextParams = { points: { by: [0, -carousel.scrollAmountPerInc*inc] } };
-
}
-
-
carousel.scrollNextAnim = new YAHOO.util.Motion(carousel.carouselList,
-
nextParams,
-
carousel.cfg.getProperty("animationSpeed"), carousel.animationMethod);
-
if(carousel._isValidObj(carousel.animationCompleteHandler)) {
-
carousel.scrollNextAnim.onComplete.subscribe(this._handleAnimationComplete, [carousel, "next"]);
-
}
-
carousel.scrollNextAnim.animate();
-
} else {
-
if(carousel.isVertical()) {
-
var currY = YAHOO.util.Dom.getY(carousel.carouselList);
-
-
YAHOO.util.Dom.setY(carousel.carouselList,
-
currY - carousel.scrollAmountPerInc*inc);
-
} else {
-
var currX = YAHOO.util.Dom.getX(carousel.carouselList);
-
YAHOO.util.Dom.setX(carousel.carouselList,
-
currX - carousel.scrollAmountPerInc*inc);
-
}
-
}
-
-
}
-
-
return false;
-
},
-
the simplest route is always the best. there seemed to be a problem with the YUI event listener.
I changed to a simple onClick event and the problem seems to be fixed.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: doltharz |
last post by:
Please Help me
i'm doing something i though was to be REALLY EASY but it drives me
crazy
The complete code is at the end of the email
(i mean newsgroup article),
i always use Option...
|
by: Trevor Best |
last post by:
I did a test once using a looping variable, first dimmed as Integer,
then as Long. I found the Integer was quicker at looping. I knew this to
be true back in the 16 bit days where the CPU's (80286)...
|
by: masood.iqbal |
last post by:
My simplistic mind tells me that having local variables within looping
constructs is a bad idea. The reason is that these variables are
created during the beginning of an iteration and deleted at...
|
by: Diva |
last post by:
Hi,
I have a data grid in my application. It has 20 rows and I
have set the page size as 5. I have a Submit button on my
form and when I click on Submit, I need to loop through
the rows in the...
|
by: squash |
last post by:
I have spent two hours trying to make sense of this script, called
crazy.php. The output should be nothing because $cookie_password is
nowhere defined in this script, correct? But it actually...
|
by: AshuPd |
last post by:
Hi all !!!
I am fighting with a very interesting issue...
What i need is to link a javasript with a imagebutton control which is already on a datalist. the problem is, if i place the control out...
|
by: anthon |
last post by:
Hi all - first post!
anywho;
I need to create a function for speeding up and down a looping clip.
imagine a rotating object, triggered by an action, and slowly decreasing in speed, till it...
|
by: Ifoel |
last post by:
Hi all,
Sorry im beginer in vb.
I want making programm looping character or number.
Just say i have numbers from 100 to 10000.
just sample:
Private Sub Timer1_Timer()
if check1.value= 1...
|
by: Davaa |
last post by:
Dear all,
I am a student making a MS Form application in C++. I would ask a question about "Timer". Sample code which I am developing is below.
private: System::Void...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |