From 44cc9ee7a954f70175e91e0493e7ba64d219ea6d Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Tue, 16 Jun 2015 13:52:15 +0300 Subject: [PATCH] LIVIJUKU-253 Scopeton transcludaaminen komponentteihin jotka ei tarvi omaa scopea. https://github.com/angular/angular.js/issues/5489 --- app/scripts/components/form/index.js | 13 ++++++------- app/scripts/components/formRow/index.js | 13 ++++++------- app/scripts/components/formSection/index.js | 13 ++++++------- app/scripts/utils/transclude.js | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 app/scripts/utils/transclude.js diff --git a/app/scripts/components/form/index.js b/app/scripts/components/form/index.js index ee55bee4..38b0448b 100644 --- a/app/scripts/components/form/index.js +++ b/app/scripts/components/form/index.js @@ -1,10 +1,9 @@ 'use strict'; -module.exports = function () { - return { - transclude: true, - replace: true, - template: ` -
` - }; +var transclude = require('utils/transclude'); + +module.exports = function() { + return transclude({ + template: `
` + }); }; diff --git a/app/scripts/components/formRow/index.js b/app/scripts/components/formRow/index.js index c228e6c5..2386c5d5 100644 --- a/app/scripts/components/formRow/index.js +++ b/app/scripts/components/formRow/index.js @@ -1,10 +1,9 @@ 'use strict'; -module.exports = function () { - return { - transclude: true, - replace: true, - template: ` -
` - }; +var transclude = require('utils/transclude'); + +module.exports = function() { + return transclude({ + template: `
` + }); }; diff --git a/app/scripts/components/formSection/index.js b/app/scripts/components/formSection/index.js index 63e7e32d..2643ff4d 100644 --- a/app/scripts/components/formSection/index.js +++ b/app/scripts/components/formSection/index.js @@ -1,10 +1,9 @@ 'use strict'; -module.exports = function () { - return { - transclude: true, - replace: true, - template: ` -
` - }; +var transclude = require('utils/transclude'); + +module.exports = function() { + return transclude({ + template: `
` + }); }; diff --git a/app/scripts/utils/transclude.js b/app/scripts/utils/transclude.js new file mode 100644 index 00000000..2f9c060f --- /dev/null +++ b/app/scripts/utils/transclude.js @@ -0,0 +1,15 @@ +'use strict'; + +var _ = require('lodash'); + +module.exports = function transclude(options) { + return _.extend({ + transclude: true, + replace: true, + link(scope, element, attr, controller, transcludeFn) { + transcludeFn(scope, function (clone) { + element.empty().append(clone); + }); + } + }, options); +};