diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbGenerateAlias.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbGenerateAlias.directive.js new file mode 100644 index 0000000000..b37855b33e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/editors/umbGenerateAlias.directive.js @@ -0,0 +1,61 @@ +angular.module("umbraco.directives") + .directive('umbGenerateAlias', function ($timeout) { + return { + restrict: 'E', + templateUrl: 'views/components/umb-generate-alias.html', + replace: true, + scope: { + alias: '=', + aliasFrom: '=', + enableLock: '=?' + }, + link: function (scope, element, attrs, ctrl) { + + var unbindWatcher = function(){}; + + scope.locked = true; + + function init() { + + if(scope.alias === undefined || scope.alias === "" || scope.alias === null) { + + unbindWatcher = scope.$watch('aliasFrom', function (newValue, oldValue) { + + if(newValue !== undefined && newValue !== null) { + generateAlias(newValue); + } + + }); + + } + + } + + function generateAlias(value) { + + var str = value; + + // capitalize all words + str = str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); + + // remove spaces + str = str.replace(/\s/g, ''); + + scope.alias = str; + + } + + + scope.$watch('locked', function(newValue, oldValue){ + + if(newValue === false) { + unbindWatcher(); + } + + }); + + init(); + + } + }; + }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/components/umb-generate-alias.html b/src/Umbraco.Web.UI.Client/src/views/components/umb-generate-alias.html new file mode 100644 index 0000000000..5156d3f240 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/components/umb-generate-alias.html @@ -0,0 +1,4 @@ +
+ {{ alias }} + +
\ No newline at end of file