hellsan631/angular-pagepiling.js

View on GitHub
sample/app/directives/angular-pagepiling.min.js

Summary

Maintainability
D
2 days
Test Coverage
;(function() {
  'use strict';

  angular
    .module('pagePiling.js', [])
    .directive('pagePiling', pagePiling);

  pagePiling.$inject = ['$timeout'];

  function pagePiling($timeout) {
    var directive = {
      restrict: 'A',
      scope: {options: '='},
      link: link
    };

    return directive;

    function link(scope, element) {
      var pageIndex;
      var slideIndex;

      angular.element(element).pagepiling(sanatizeOptions(scope.options));

      function destroyFullPage() {
        var pageElement = angular.element(element);

        pageElement.attr({
            style: '',
        });

        pageElement.find('.section').removeClass('pp-section active pp-table pp-easing');

        pageElement.find('li').css({
            zIndex: '',
            transform: '',
            '-webkit-transform': '',
            '-moz-transform': '',
            '-ms-transform': ''
        });

        pageElement.find('.pp-tableCell').remove();

        $('#pp-nav').remove();
      }

      function sanatizeOptions(options) {

        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.
          $('#pp-nav').find('a').removeAttr('href');
        };

        //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.pagepiling.moveTo($(this).attr('data-menuanchor'));
        });

        return options;
      }

      element.on('$destroy', destroyFullPage);
    }
  }

})();