<!DOCTYPE html>
<html ng-app="app">
  <head>
    <title>AngularJS Smooth Scroll</title>
    <link rel="stylesheet" href="style.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
    
    <script src="angular-smooth-scroll.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <h1>Go to 1!</h1>
    <section ng-controller="Main">
      <ul>
        <li ng-repeat="i in list" id="item{{i}}" ng-click="$parent._$.goTop()">{{ i }}</li>
      </ul>
      
    </section>
  </body>

</html>
/* Styles go here */

class MainController
  $inject = ["$scope", "$smoothScroll", "$log"]
  
  constructor: (@$scope, @$smoothScroll, @$log)->
    $scope._$ = @
    $scope.list = [1..100]
  
  goTop: ->
    @$smoothScroll.slow("#item1", null, @comp, @step)
    
  step: (args...)=>
    @$log.info("step")
    @$log.log(args)
    
  comp: (args...)=>
    @$log.info("comp")
    @$log.log(args)
    

app = angular.module("app", ["smooth-scroll"])

app.controller("Main", MainController)

###*
 * angular smooth-scroll
 * 
 * @author atomita
 * @license MIT
 * @version 0.0.3
###
class SmoothScroll
  @$inject = []
  
  constructor: ()->
    @duration = "normal"
    @easing = "swing"
    
  normal: (target, easing, complete, step)->
    @to(target, "normal", easing, complete, step)
    return
    
  slow: (target, easing, complete, step)->
    @to(target, "slow", easing, complete, step)
    return
    
  fast: (target, easing, complete, step)->
    @to(target, "fast", easing, complete, step)
    return
    
  to: (target, duration, easing, complete, step)->
    position = angular.element(target).offset().top
    
    opt =
      "duration": duration or @duration
      "easing": easing or @easing
    is_comepleted = false
    if angular.isFunction(complete)
      opt.complete = (args...)->
        complete.apply(null, args) if not is_comepleted
        is_comepleted = true
    opt.step = ((args...)-> step.apply(null, args) if not is_comepleted) if angular.isFunction(step)
    
    angular.element("html, body").animate({"scrollTop": position}, opt)
    return
    
angular.module("smooth-scroll", []).service("$smoothScroll", SmoothScroll)

var MainController, app,
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  __slice = [].slice;

MainController = (function() {
  var $inject;

  MainController.name = 'MainController';

  $inject = ["$scope", "$smoothScroll", "$log"];

  function MainController($scope, $smoothScroll, $log) {
    var _i, _results;
    this.$scope = $scope;
    this.$smoothScroll = $smoothScroll;
    this.$log = $log;
    this.comp = __bind(this.comp, this);

    this.step = __bind(this.step, this);

    $scope._$ = this;
    $scope.list = (function() {
      _results = [];
      for (_i = 1; _i <= 100; _i++){ _results.push(_i); }
      return _results;
    }).apply(this);
  }

  MainController.prototype.goTop = function() {
    return this.$smoothScroll.slow("#item1", null, this.comp, this.step);
  };

  MainController.prototype.step = function() {
    var args;
    args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
    this.$log.info("step");
    return this.$log.log(args);
  };

  MainController.prototype.comp = function() {
    var args;
    args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
    this.$log.info("comp");
    return this.$log.log(args);
  };

  return MainController;

})();

app = angular.module("app", ["smooth-scroll"]);

app.controller("Main", MainController);
/**
 * angular smooth-scroll
 * 
 * @author atomita
 * @license MIT
 * @version 0.0.3
*/

var SmoothScroll,
  __slice = [].slice;

SmoothScroll = (function() {

  SmoothScroll.name = 'SmoothScroll';

  SmoothScroll.$inject = [];

  function SmoothScroll() {
    this.duration = "normal";
    this.easing = "swing";
  }

  SmoothScroll.prototype.normal = function(target, easing, complete, step) {
    this.to(target, "normal", easing, complete, step);
  };

  SmoothScroll.prototype.slow = function(target, easing, complete, step) {
    this.to(target, "slow", easing, complete, step);
  };

  SmoothScroll.prototype.fast = function(target, easing, complete, step) {
    this.to(target, "fast", easing, complete, step);
  };

  SmoothScroll.prototype.to = function(target, duration, easing, complete, step) {
    var is_comepleted, opt, position;
    position = angular.element(target).offset().top;
    opt = {
      "duration": duration || this.duration,
      "easing": easing || this.easing
    };
    is_comepleted = false;
    if (angular.isFunction(complete)) {
      opt.complete = function() {
        var args;
        args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
        if (!is_comepleted) complete.apply(null, args);
        return is_comepleted = true;
      };
    }
    if (angular.isFunction(step)) {
      opt.step = (function() {
        var args;
        args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
        if (!is_comepleted) return step.apply(null, args);
      });
    }
    angular.element("html, body").animate({
      "scrollTop": position
    }, opt);
  };

  return SmoothScroll;

})();

angular.module("smooth-scroll", []).service("$smoothScroll", SmoothScroll);