Skip to content

Instantly share code, notes, and snippets.

@mklickman
Forked from anonymous/controller.js
Last active October 19, 2016 16:41
Show Gist options
  • Save mklickman/4dbf624bed2a5434d1c63dcad1bb427a to your computer and use it in GitHub Desktop.
Save mklickman/4dbf624bed2a5434d1c63dcad1bb427a to your computer and use it in GitHub Desktop.

Revisions

  1. mklickman revised this gist Oct 19, 2016. 3 changed files with 9 additions and 6 deletions.
    1 change: 1 addition & 0 deletions 01-template.html
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,7 @@
    -->
    <div class="slide"
    swipe-handler-directive
    click-handler="clickHandler(slide, $index)"
    ng-repeat="slide in slides track by $index"
    ></div>

    4 changes: 2 additions & 2 deletions 02-controller.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    angular.module('myApp')
    .controller('rootController', function($scope) {
    $scope.clickHandler = function(item) {
    // do something with 'item'
    $scope.clickHandler = function(slide, $index) {
    // do something with 'item' and $index
    };
    })
    ;
    10 changes: 6 additions & 4 deletions 03-swipe-handler-directive.js
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,13 @@ angular.module('myApp')
    .directive('swipe-handler-directive', function() {
    return {
    restrict: "A",
    scope: {},
    scope: {
    clickHandler: '&'
    },
    link: function($scope, $element, $attrs) {
    // do all the mousedown/mousemove event handler stuff
    // here, and call the parent scope's click handler
    // from here, but only if a swipe hasn't occurred
    $element.on('click', function() {
    $scope.clickHandler(slide, $index);
    }
    }
    }
    })
  2. mklickman revised this gist Oct 19, 2016. 1 changed file with 12 additions and 8 deletions.
    20 changes: 12 additions & 8 deletions 01-template.html
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,18 @@

    <div class="carousel">
    <!--
    Each slide needs to be both clickable and swipeable, with a mouse
    (this problem does not happen on mobile). The problem I'm having
    is that when you swipe with a mouse click, letting the mouse up at
    the end of the swipe will trigger the click (which opens a modal).
    I need the click to only be called if there no swipe happens. That
    is what the swipe handler directive is there for, but I need to
    trigger the parent scope's click handler from the directive's link
    function. How do I do that?
    I have a UI Bootstrap carousel with some slides in it. Each slide
    needs to be both clickable and swipeable, with a mouse (this problem
    is not an issue on mobile).
    The problem I'm having is that when you swipe with a mouse click,
    letting the mouse up at the end of the swipe will trigger the click
    (which opens a modal). I need the click to only be called if no swipe
    happens. That is what the swipe handler directive is there for, but I
    need to trigger the parent scope's click handler from the directive's
    link function.
    How do I do that?
    -->
    <div class="slide"
    swipe-handler-directive
  3. mklickman revised this gist Oct 19, 2016. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  4. @invalid-email-address Anonymous created this gist Oct 19, 2016.
    7 changes: 7 additions & 0 deletions controller.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    angular.module('myApp')
    .controller('rootController', function($scope) {
    $scope.clickHandler = function(item) {
    // do something with 'item'
    };
    })
    ;
    13 changes: 13 additions & 0 deletions swipe-handler-directive.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    angular.module('myApp')
    .directive('swipe-handler-directive', function() {
    return {
    restrict: "A",
    scope: {},
    link: function($scope, $element, $attrs) {
    // do all the mousedown/mousemove event handler stuff
    // here, and call the parent scope's click handler
    // from here, but only if a swipe hasn't occurred
    }
    }
    })
    ;
    20 changes: 20 additions & 0 deletions template.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <div class="app-root" ng-controller="rootController">

    <div class="carousel">
    <!--
    Each slide needs to be both clickable and swipeable, with a mouse
    (this problem does not happen on mobile). The problem I'm having
    is that when you swipe with a mouse click, letting the mouse up at
    the end of the swipe will trigger the click (which opens a modal).
    I need the click to only be called if there no swipe happens. That
    is what the swipe handler directive is there for, but I need to
    trigger the parent scope's click handler from the directive's link
    function. How do I do that?
    -->
    <div class="slide"
    swipe-handler-directive
    ng-repeat="slide in slides track by $index"
    ></div>

    </div><!-- .carousel -->
    </div><!-- .app-root -->