acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
55 lines • 1.81 kB
JavaScript
(function ($, angular, underscore, window, document, undefined) {
'use strict';
angular.module('frontend.directives').directive('switch', [function () {
return {
restrict: 'E',
replace: true,
scope: {
tag: '<?',
disabled: '=?',
visible: '=?',
cssClass: '=?',
model: '=?'
},
templateUrl: '/templates/framework/directives/switch/template.html',
link: function (scope, element, attr) {
scope.vm = { initialized: false };
scope.vm.init = function () {
if (angular.isUndefined(scope.disabled)) {
scope.disabled = false;
}
if (angular.isUndefined(scope.visible)) {
scope.visible = true;
}
if (angular.isUndefined(scope.cssClass)) {
scope.cssClass = '';
}
if (angular.isUndefined(scope.readonly)) {
scope.readonly = false;
}
scope.vm.bind();
};
scope.vm.toggle = function ($event) {
$event.stopPropagation();
$event.preventDefault();
if (scope.disabled)
return;
scope.model = !scope.model;
};
scope.vm.bind = function () {
scope.$watch('model', function (val, old) {
if (!scope.vm.initialized) {
scope.vm.initialized = true;
if (!scope.triggerOnInit)
return;
}
if (scope.vm.initialized && angular.isFunction(scope.onChange)) {
scope.onChange(scope.model, scope.tag);
}
});
};
scope.vm.init();
}
};
}]);
}(jQuery, angular, _, window, document));