Skip to content

Instantly share code, notes, and snippets.

/icon.js Secret

Created August 14, 2015 00:41
Show Gist options
  • Save anonymous/9be8f111591b15fde9be to your computer and use it in GitHub Desktop.
Save anonymous/9be8f111591b15fde9be to your computer and use it in GitHub Desktop.
f@$king angular
var IconModule = angular.module('ssc.commons.icons', []);
IconModule.constant('ICON_COLORS', {
darkGray : 'hsl(0, 0, 23%)',
red: 'hsl(8, 58, 55%)'
});
IconModule.constant('ICON_TEMPLATE_MAP', {
lockIcon: '/app/commons/components/icons/templates/lock-icon.html'
// EXAMPLE: companyLogo: '/app/commons/components/icons/templates/company-logo.html'
});
IconModule.provider('iconConfiguration', ['ICON_COLORS', 'ICON_TEMPLATE_MAP', function IconConfigurationProvider(ICON_COLORS, ICON_TEMPLATE_MAP) {
this.height = '2em';
this.width = '2em';
this.fill = ICON_COLORS.darkGray;
this.iconName = null;
this.getTemplateUrl = function (name) {
return ICON_TEMPLATE_MAP[name];
if (!name) {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller Error, must provide iconName when using svgIcon directive!');
} else if (typeof name !== 'string') {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller TypeError, was expecting type String for icon name');
} else if (!ICON_TEMPLATE_MAP[name]) {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller Error, icon "' + name + '" doesn\'t exist');
} else {
return ICON_TEMPLATE_MAP[name];
}
};
this.setName = function (name) {
if (typeof name !== 'string') {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller TypeError, was expecting type String for icon name.');
} else {
return this.iconName = name;
}
};
this.setFill = function (fill) {
if (typeof fill !== 'string') {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller TypeError, was expecting type String for icon fill.');
} else {
return this.fill = fill;
}
};
this.setHeight = function (height) {
if (typeof height !== 'string') {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller TypeError, was expecting type String for icon height.');
} else {
return this.height = height;
}
};
this.setWidth = function (width) {
if (typeof width !== 'string') {
return $logFactory
.getLogger('ssc.commons.icons')
.error('Caller TypeError, was expecting type String for icon width.');
} else {
return this.width = width;
}
};
this.$get = ['providedName', function iconConfigurationFactory(providedName) {
var icon = new IconConfiguration();
icon.setName.call(providedName, this);
return icon;
}];
}]);
IconModule.config(['$compileProvider', 'iconConfigurationProvider', function ($compileProvider, iconConfigurationProvider) {
$compileProvider.directive('svgIcon', ['iconConfigurationProvider', function(iconConfigurationProvider) {
return {
templateNameSpace: 'svg',
replace: true,
templateUrl: iconConfigurationProvider.getTemplateUrl(iconConfigurationProvider.iconName)
};
}]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment