Skip to content

Instantly share code, notes, and snippets.

@sbosell
Created February 18, 2014 01:24
Show Gist options
  • Save sbosell/9062798 to your computer and use it in GitHub Desktop.
Save sbosell/9062798 to your computer and use it in GitHub Desktop.
Umbraco Angular Directives
app.directive('cycle', function($parse) {
return {
restrict: 'A',
priority: 400,
link: function (scope, element, attr) {
scope.$watch('isLoaded', function (newVal) {
if (!newVal) return;
var opts = $parse(attr.cycle);
$(element).cycle(opts());
});
}
}
})
.directive('umbChildren', function (contentService, $compile) {
return {
restrict: 'A',
priority: 1100, // higher than ng-repeat
controller: function($scope) {
$scope.children = [];
$scope.isLoaded = false;
$scope.safeApply = function (fn) {
var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof (fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$scope.$watch('content.Id', function (newVal) {
if (!newVal) return;
contentService.getChildrenById(newVal).then(function (data) {
$scope.children = data;
$scope.isLoaded = true;
$scope.safeApply();
});
});
},
link: function (scope, element, attr) {
}
}
}).directive('umbMedia', function (contentService) {
return {
restrict: 'A',
scope: {
umbMedia: '='
},
link: function (scope, element, attr) {
scope.$watch('umbMedia', function (newVal) {
if (!newVal) return;
contentService.getMediaById(newVal).then(function (data) {
$(element).attr('src', data.Url);
});
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment