Draggable slider working

This commit is contained in:
Max Lynch
2014-03-01 15:52:47 -06:00
parent a0d60d5228
commit e538fa77c9
5 changed files with 141 additions and 33 deletions

View File

@@ -5,7 +5,7 @@ angular.module('ionic.ui.toggle', [])
// The Toggle directive is a toggle switch that can be tapped to change
// its value
.directive('ionToggle', function() {
.directive('ionToggle', ['$ionicGesture', '$timeout', function($ionicGesture, $timeout) {
return {
restrict: 'E',
@@ -36,30 +36,38 @@ angular.module('ionic.ui.toggle', [])
if(attr.ngTrueValue) input.attr('ng-true-value', attr.ngTrueValue);
if(attr.ngFalseValue) input.attr('ng-false-value', attr.ngFalseValue);
// return function link($scope, $element, $attr, ngModel) {
// var el, checkbox, track, handle;
return function($scope, $element, $attr) {
var el, checkbox, track, handle;
// el = $element[0].getElementsByTagName('label')[0];
// checkbox = el.children[0];
// track = el.children[1];
// handle = track.children[0];
el = $element[0].getElementsByTagName('label')[0];
checkbox = el.children[0];
track = el.children[1];
handle = track.children[0];
var ngModelController = angular.element(checkbox).controller('ngModel');
// $scope.toggle = new ionic.views.Toggle({
// el: el,
// track: track,
// checkbox: checkbox,
// handle: handle
// });
$scope.toggle = new ionic.views.Toggle({
el: el,
track: track,
checkbox: checkbox,
handle: handle,
onChange: function() {
if(checkbox.checked) {
ngModelController.$setViewValue(true);
} else {
ngModelController.$setViewValue(false);
}
$scope.$apply();
}
});
// ionic.on('drag', function(e) {
// console.log('drag');
// $scope.toggle.drag(e);
// }, handle);
// }
$scope.$on('$destroy', function() {
$scope.toggle.destroy();
});
};
}
};
});
}]);
})(window.ionic);