Permalink
Browse files

Add directive for yuri

  • Loading branch information...
1 parent acd2586 commit 40661135bc98ae875c93c7e391290d36e8558a37 Penn Su committed Jul 10, 2014
Showing with 32 additions and 1 deletion.
  1. +1 −0 www/index.html
  2. +1 −1 www/js/app.js
  3. +30 −0 www/js/directives.js
View
1 www/index.html
@@ -29,6 +29,7 @@
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/filters.js"></script>
+ <script src="js/directives.js"></script>
</head>
<body ng-app="starter">
View
2 www/js/app.js
@@ -4,7 +4,7 @@
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
-angular.module('starter', ['ionic', 'starter.filters', 'starter.services', 'starter.controllers', 'firebase'])
+angular.module('starter', ['ionic', 'starter.filters', 'starter.services', 'starter.directives', 'starter.controllers', 'firebase'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
View
30 www/js/directives.js
@@ -0,0 +1,30 @@
+angular.module('starter.directives', [])
+ .directive('myDraggable', ['$document', function($document) {
+ return function(scope, element, attr) {
+ var startX = 0, startY = 0, x = 0, y = 0;
+
+ element.on('mousedown', function(event) {
+ // Prevent default dragging of selected content
+ event.preventDefault();
+ startX = event.pageX - x;
+ startY = event.pageY - y;
+ $document.on('mousemove', mousemove);
+ $document.on('mouseup', mouseup);
+ });
+
+ function mousemove(event) {
+ y = event.pageY - startY;
+ // commenting line below to make it only Y axis
+ //x = event.pageX - startX;
+ element.css({
+ top: y + 'px',
+ left: x + 'px'
+ });
+ }
+
+ function mouseup() {
+ $document.off('mousemove', mousemove);
+ $document.off('mouseup', mouseup);
+ }
+ };
+ }]);

0 comments on commit 4066113

Please sign in to comment.