mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 23:16:52 +08:00
Toggle with unit test
This commit is contained in:
38
dist/js/ionic-angular.js
vendored
38
dist/js/ionic-angular.js
vendored
@ -6,8 +6,10 @@ angular.module('ionic.ui', ['ionic.ui.content',
|
||||
'ionic.ui.tabs',
|
||||
'ionic.ui.nav',
|
||||
'ionic.ui.sideMenu',
|
||||
'ionic.ui.list'
|
||||
'ionic.ui.list',
|
||||
'ionic.ui.toggle'
|
||||
]);
|
||||
|
||||
;
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service', 'ionic.ui.actionSheet'])
|
||||
|
||||
@ -572,7 +574,7 @@ angular.module('ionic.ui.tabs', [])
|
||||
}
|
||||
});
|
||||
;
|
||||
angular.module('ionic.ui.content', [])
|
||||
angular.module('ionic.ui.toggle', [])
|
||||
|
||||
// The content directive is a core scrollable content area
|
||||
// that is part of many View hierarchies
|
||||
@ -580,30 +582,42 @@ angular.module('ionic.ui.content', [])
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
scope: {},
|
||||
require: '?ngModel',
|
||||
template: '<div class="toggle">' +
|
||||
' <input type="checkbox">'+
|
||||
' <div class="track">' +
|
||||
' <div class="handle"></div>' +
|
||||
' <div class="handle"></div>' +
|
||||
' </div>' +
|
||||
'</div>',
|
||||
|
||||
link: function($scope, $element, $attr, ngModel) {
|
||||
var checkbox;
|
||||
|
||||
$scope.toggle = new ionic.views.Toggle({ el: $element[0] });
|
||||
var checkbox, track, handle;
|
||||
|
||||
if(!ngModel) { return; }
|
||||
|
||||
checkbox = $element.children()[0];
|
||||
checkbox = $element.children().eq(0);
|
||||
track = $element.children().eq(1);
|
||||
handle = track.children().eq(0);
|
||||
|
||||
if(!checkbox) { return; }
|
||||
if(!checkbox.length || !track.length || !handle.length) { return; }
|
||||
|
||||
$scope.toggle = new ionic.views.Toggle({
|
||||
el: $element[0],
|
||||
checkbox: checkbox[0],
|
||||
track: track[0],
|
||||
handle: handle[0]
|
||||
});
|
||||
|
||||
$element.bind('click', function(e) {
|
||||
$scope.toggle.tap(e);
|
||||
$scope.$apply(function() {
|
||||
ngModel.$setViewValue(checkbox[0].checked);
|
||||
});
|
||||
});
|
||||
|
||||
ngModel.$render = function() {
|
||||
checkbox.checked = ngModel.$viewValue;
|
||||
$scope.toggle.val(ngModel.$viewValue);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user