angular-fullpage.js
angular-fullpage.js copied to clipboard
options.onLeave can't be set
I am using the current master.
In sanatizeOptions
the code is changing the option
objects.
Which calls for the options
watch, which calls for the rebuild
.
Also, when setting options.onLeave
the function save the onLeave in a local parameter, and create onAngularLeave
function instead of it. This line:
options.onLeave = onAngularLeave;
After a rebuild the origin onLeave function is lost.
Hmm, that's not what i intended.
I wrote it so that options.onLeave function would be saved to a variable, onLeave that would execute after the angular onLeave method. But your right, because of javascripts memory and variable management, i need to stringify and clone the function so that its a copy and not a reference.
Also having this problem. How do I solve?
I can confirm the bug still exist in the master. I will create a pull request with a fix in the weekend.
setting some options on the directive solves the issue.
<div full-page options="{'navigation': true}">...</div>
Sorry for my english. I can't speak better..
To fixe this issue you have to modify angular-fullpage.js to use fullpage default callback by commenting code from line 59 like this ` var sanatizeOptions = function(options) { //options.afterRender = afterAngularRender; //options.onLeave = onAngularLeave; options.onSlideLeave = onAngularSlideLeave;
/*function afterAngularRender() {
//We want to remove the HREF targets for navigation because they use hashbang
//They still work without the hash though, so its all good.
if (options && options.navigation) {
$('#fp-nav').find('a').removeAttr('href');
}
if (pageIndex) {
$timeout(function() {
$.fn.fullpage.silentMoveTo(pageIndex, slideIndex);
});
}
}*/
/*function onAngularLeave(page, next){
pageIndex = next;
if (typeof onLeave === 'function') {
onLeave();
}
}*/
`
I rewrote the sanitize function so that it still allows for user options to be executed. It takes the user's options and executes the users function after the directives own functions have been done.
var sanatizeOptions = function(options) {
const usrOptions = Object.assign({}, options);
options.onLeave = function(page, next){
pageIndex = next;
if (usrOptions.onLeave) {
usrOptions.onLeave(page, next);
}
};
options.onSlideLeave = function(anchorLink, page, slide, direction, next){
pageIndex = page;
slideIndex = next;
if (usrOptions.onSlideLeave) {
usrOptions.onSlideLeave(anchorLink, page, slide, direction, next);
}
};
options.afterRender = function(){
//We want to remove the HREF targets for navigation because they use hashbang
//They still work without the hash though, so its all good.
if (options && options.navigation) {
$('#fp-nav').find('a').removeAttr('href');
}
if (pageIndex) {
$timeout(function() {
$.fn.fullpage.silentMoveTo(pageIndex, slideIndex);
});
}
if (usrOptions.afterRender) {
usrOptions.afterRender();
}
};
//if we are using a ui-router, we need to be able to handle anchor clicks without 'href="#thing"'
$(document).on('click', '[data-menuanchor]', function () {
$.fn.fullpage.moveTo($(this).attr('data-menuanchor'));
});
return options;
};
@baffleinc Setting at least one option fixed the issue.
Still this needs to be patched.
Thans!