Last active
December 16, 2015 19:39
-
-
Save divanvisagie/5486987 to your computer and use it in GitHub Desktop.
An example of how touch angular should be handled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html ng-app="test"> | |
| <head> | |
| <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
| <link href="http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" /> | |
| <script src="http://twitter.github.io/bootstrap/assets/js/bootstrap.js"></script> | |
| <meta charset=utf-8 /> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <div> | |
| <label>Name:</label> | |
| <input type="text" ng-model="yourName" placeholder="Enter Your name here"> | |
| <hr> | |
| <h1>Hello {{yourName}}!</h1> | |
| </div> | |
| <div ng-controller="thingsControl"> | |
| Things: | |
| <ul> | |
| <li ng-repeat="thing in things" ng-click="doit( $event )"> | |
| <input type="text" ng-model="thing.type" /> | |
| </li> | |
| </ul> | |
| <button id="saveButton" on-touch="save" class='btn'>Save</button> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = angular.module( 'test', [] ); | |
| app.directive( 'onTouch' , function(){ | |
| return { | |
| restrict: 'A', | |
| replace : true, | |
| link : function( scope , element , attribs ){ | |
| var ontouchFn = scope.$eval( attribs.onTouch ); | |
| element.bind( 'touchstart' , function( e ){ | |
| if ( e ) e.preventDefault(); | |
| scope.$apply(function() { | |
| ontouchFn.call(scope, e.which); | |
| }); | |
| } ); | |
| element.bind( 'click' , function( e ){ | |
| if ( e ) e.preventDefault(); | |
| scope.$apply(function() { | |
| ontouchFn.call(scope, e.which); | |
| }); | |
| } ); | |
| } | |
| }; | |
| } ); | |
| app.controller( 'thingsControl', function ( $scope ){ | |
| $scope.things = [ | |
| { type : 'animal' }, | |
| { type : 'tree' }, | |
| { type : 'human' } | |
| ]; | |
| $scope.doit = function( e ){ | |
| if ( e ){ | |
| e.preventDefault(); | |
| console.log( 'theres an e!!!' , e ); | |
| } | |
| console.log( 'was clicked' , $scope ); | |
| }; | |
| $scope.save = function( item ){ | |
| //alert( 'aa' ); | |
| console.log( 'this is a test' , $scope.things ); | |
| }; | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment