forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
|
|
// usage: <partials-renderer partial-id="partial-1"></partials-renderer>
|
|
|
|
evoapp.directive('partialsRenderer', function($rootScope, $compile) {
|
|
|
|
return {
|
|
restrict: 'AE',
|
|
link: function (scope, elem, attrs) {
|
|
|
|
scope.partialId = attrs.partialId || null;
|
|
|
|
if(scope.partialId != null){
|
|
|
|
var partialEL = $rootScope.viewCache.find('[id=' + scope.partialId + ']');
|
|
|
|
if(partialEL.length == 0){
|
|
throw Error('partial ' + scope.partialId + ' not found!');
|
|
}else{
|
|
|
|
if(partialEL.length > 1){
|
|
throw Error('more than one partial ' + scope.partialId + ' was found!');
|
|
}else{
|
|
|
|
var finalEl = $.parseHTML(partialEL.html());
|
|
|
|
$(finalEl).insertAfter(elem);
|
|
|
|
elem.remove();
|
|
|
|
$compile(finalEl)(scope);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}); |