angular-fullpage.js icon indicating copy to clipboard operation
angular-fullpage.js copied to clipboard

options.onLeave can't be set

Open nivm opened this issue 8 years ago • 7 comments

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.

nivm avatar Apr 07 '16 09:04 nivm

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.

hellsan631 avatar Apr 07 '16 20:04 hellsan631

Also having this problem. How do I solve?

baffleinc avatar May 23 '16 05:05 baffleinc

I can confirm the bug still exist in the master. I will create a pull request with a fix in the weekend.

nivm avatar May 23 '16 06:05 nivm

setting some options on the directive solves the issue.

<div full-page options="{'navigation': true}">...</div>

baffleinc avatar May 23 '16 06:05 baffleinc

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();
      }
    }*/

`

MaxwellADN avatar Jun 29 '16 16:06 MaxwellADN

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;
      };

blaiseyuri avatar Jul 29 '16 15:07 blaiseyuri

@baffleinc Setting at least one option fixed the issue.

Still this needs to be patched.

Thans!

santiagovdk avatar Dec 07 '16 17:12 santiagovdk