diff --git a/Gruntfile.js b/Gruntfile.js index 0622f65..679fc20 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -58,6 +58,7 @@ module.exports = function(grunt) { 'app/directives/archetypesubmitwatcher.js', 'app/directives/archetypecustomview.js', 'app/directives/archetypeLocalize.js', + 'app/directives/archetypeclickoutside.js', 'app/services/archetypeLocalizationService.js', 'app/helpers/sampleLabelHelpers.js', 'app/resources/archetypePropertyEditorResource.js', diff --git a/app/directives/archetypeclickoutside.js b/app/directives/archetypeclickoutside.js new file mode 100644 index 0000000..5370deb --- /dev/null +++ b/app/directives/archetypeclickoutside.js @@ -0,0 +1,29 @@ +angular.module("umbraco.directives") + .directive('archetypeClickOutside', function ($timeout, $parse) { + return { + restrict: 'A', + link: function (scope, element, attrs, ctrl) { + var fn = $parse(attrs.archetypeClickOutside); + + // add click event handler (delayed so we don't trigger the callback immediately if this directive itself was triggered by a mouse click) + $timeout(function () { + $(document).on("click", mouseClick); + }, 500); + + function mouseClick(event) { + if($(event.target).closest(element).length > 0) { + return; + } + var callback = function () { + fn(scope, { $event: event }); + }; + scope.$apply(callback); + } + + // unbind event + scope.$on('$destroy', function () { + $(document).off("click", mouseClick); + }); + } + }; + }); \ No newline at end of file diff --git a/app/views/archetype.default.html b/app/views/archetype.default.html index 0e2c209..2000b45 100644 --- a/app/views/archetype.default.html +++ b/app/views/archetype.default.html @@ -47,7 +47,7 @@
-
+
Add an item