refactor(toggle): platform config toggle styles

This commit is contained in:
Adam Bradley
2015-01-21 12:55:11 -06:00
parent 65aa2af95d
commit 0e11a087a2
5 changed files with 97 additions and 67 deletions

View File

@@ -24,9 +24,9 @@
*/
IonicModule
.directive('ionToggle', [
'$ionicGesture',
'$timeout',
function($ionicGesture, $timeout) {
'$ionicConfig',
function($timeout, $ionicConfig) {
return {
restrict: 'E',
@@ -65,34 +65,32 @@ function($ionicGesture, $timeout) {
element[0].getElementsByTagName('label')[0].classList.add(attr.toggleClass);
}
return function($scope, $element, $attr) {
var el, checkbox, track, handle;
element.addClass('toggle-' + $ionicConfig.form.toggle());
el = $element[0].getElementsByTagName('label')[0];
checkbox = el.children[0];
track = el.children[1];
handle = track.children[0];
return function($scope, $element) {
var el = $element[0].getElementsByTagName('label')[0];
var checkbox = el.children[0];
var track = el.children[1];
var handle = track.children[0];
var ngModelController = jqLite(checkbox).controller('ngModel');
var ngModelController = jqLite(checkbox).controller('ngModel');
$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();
}
});
$scope.toggle = new ionic.views.Toggle({
el: el,
track: track,
checkbox: checkbox,
handle: handle,
onChange: function() {
if (ngModelController) {
ngModelController.$setViewValue(checkbox.checked);
$scope.$apply();
}
}
});
$scope.$on('$destroy', function() {
$scope.toggle.destroy();
});
$scope.$on('$destroy', function() {
$scope.toggle.destroy();
});
};
}

View File

@@ -113,6 +113,22 @@
* @returns {boolean}
*/
/**
* @ngdoc method
* @name $ionicConfigProvider#form.checkbox
* @description Checkbox style. Android defaults to `square` and iOS defaults to `circle`.
* @param {string} value
* @returns {string}
*/
/**
* @ngdoc method
* @name $ionicConfigProvider#form.toggle
* @description Toggle item style. Android defaults to `small` and iOS defaults to `large`.
* @param {string} value
* @returns {string}
*/
/**
* @ngdoc method
* @name $ionicConfigProvider#tabs.style
@@ -220,7 +236,8 @@ IonicModule
previousTitleText: PLATFORM
},
form: {
checkbox: PLATFORM
checkbox: PLATFORM,
toggle: PLATFORM
},
scrolling: {
jsScrolling: PLATFORM
@@ -262,7 +279,8 @@ IonicModule
},
form: {
checkbox: 'circle'
checkbox: 'circle',
toggle: 'large'
},
scrolling: {
@@ -309,7 +327,8 @@ IonicModule
},
form: {
checkbox: 'square'
checkbox: 'square',
toggle: 'small'
},
tabs: {