mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
yay
This commit is contained in:
54
js/ext/angular/src/directive/ionicRadio.js
vendored
54
js/ext/angular/src/directive/ionicRadio.js
vendored
@@ -73,37 +73,55 @@ angular.module('ionic.ui.radio', [])
|
||||
link: function($scope, $element, $attr, ngModel) {
|
||||
var radio;
|
||||
|
||||
if(!ngModel) { return; }
|
||||
|
||||
radio = $element.children().eq(0);
|
||||
|
||||
if(!radio.length) { return; }
|
||||
|
||||
$scope.tapHandler = function(e) {
|
||||
radio[0].checked = true;
|
||||
ngModel.$setViewValue($scope.$eval($attr.ngValue));
|
||||
e.alreadyHandled = true;
|
||||
};
|
||||
|
||||
var clickHandler = function(e) {
|
||||
ngModel.$setViewValue($scope.$eval($attr.ngValue));
|
||||
};
|
||||
|
||||
if(ngModel) {
|
||||
//$element.bind('tap', tapHandler);
|
||||
$element.bind('click', clickHandler);
|
||||
|
||||
ngModel.$render = function() {
|
||||
var val = $scope.$eval($attr.ngValue);
|
||||
if(val === ngModel.$viewValue) {
|
||||
radio.attr('checked', 'checked');
|
||||
} else {
|
||||
radio.removeAttr('checked');
|
||||
}
|
||||
};
|
||||
$scope.$parent.$on('button.toggled', function(e, element) {
|
||||
var c, children = $element.children();
|
||||
for(var i = 0; i < children.length; i++) {
|
||||
c = children[i];
|
||||
if(c != element[0]) {
|
||||
c.classList.remove('active');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
.directive('button', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
require: '?^ngModel',
|
||||
link: function($scope, $element, $attr, ngModel) {
|
||||
if(!ngModel) { return; }
|
||||
|
||||
var setIt = function() {
|
||||
$element.addClass('active');
|
||||
ngModel.$setViewValue($scope.$eval($attr.ngValue));
|
||||
$scope.$emit('button.toggled', $element);
|
||||
};
|
||||
|
||||
$scope.tapHandler = function(e) {
|
||||
setIt();
|
||||
e.alreadyHandled = true;
|
||||
};
|
||||
|
||||
var clickHandler = function(e) {
|
||||
setIt();
|
||||
};
|
||||
|
||||
$element.bind('click', clickHandler);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(window.ionic);
|
||||
|
||||
Reference in New Issue
Block a user