I have an angular directive (below) that manages icon placement and icon states. The code is working as is, but I feel that adding ng-class in my markup variables would eliminate the need for the setMaskingIcon function. That function is basically jquery, and it feels like the perfect candidate for an ng-class argument based on the privacy variable.
(function() {
'use strict';
angular
.module('inputControls', [])
.directive('inputControls', function($log) {
var linkFunction = function(scope, element, attr) {
var privacy = false;
var setting = attr.inputControls;
var controlMarkup;
var baseMarkup = '<div class="icon-holder"></div>';
var infoControl = '<icon class="icon-info"></icon>';
var toggleControl = '<icon class="icon-show-hide icon-visible"></icon>';
if(setting === 'info') {
controlMarkup = infoControl;
}else if(setting === 'toggle') {
controlMarkup = toggleControl;
}else if(setting === 'both') {
controlMarkup = infoControl + toggleControl;
}
element.after(baseMarkup);
element.next().append(controlMarkup);
setMaskingIcon();
element.next().find('.icon-show-hide').click(function(){
privacy = !privacy;
setMaskingIcon();
});
element.next().find('.icon-info').click(function(){
$log.log('info click');
});
function setMaskingIcon() {
if(privacy === true) {
// these blocks are basically jquery. i tried using
// 'ng-class="{icon-visible:!privacy, icon-private:privacy}"'
// but that didn't seem to do the trick. any advice would be awesome
element.next().find('.icon-show-hide').removeClass('icon-visible');
element.next().find('.icon-show-hide').addClass('icon-private');
} else {
element.next().find('.icon-show-hide').addClass('icon-visible');
element.next().find('.icon-show-hide').removeClass('icon-private');
}
}
};
return {
restrict: 'A',
link: linkFunction
};
});
})();