Skip to content

Instantly share code, notes, and snippets.

@tlimpanont
Created August 14, 2014 13:08
Show Gist options
  • Save tlimpanont/122f2745e595935200df to your computer and use it in GitHub Desktop.
Save tlimpanont/122f2745e595935200df to your computer and use it in GitHub Desktop.
angular layout manager including jquery ui
/*================================================================
=> Directive = relativeLayoutContainer
==================================================================*/
/*global app*/
app.directive('relativeLayoutContainer', ['$rootScope',
function($rootScope) {
'use strict';
return {
restrict: 'AE',
replace: true,
transclude: true,
template: "<div ng-transclude />",
link: function(scope, element, attrs) {
jQuery(element).css({
"position": "absolute"
});
var ofElement = (jQuery(element).parent()[0].tagName.toLowerCase() == 'body') ? window : jQuery(element).parent()[0];
setTimeout(function() {
init();
jQuery(window).resize(init);
}, 0);
function init() {
jQuery(element)
.position({
of: ofElement,
at: attrs.at.toString(),
my: attrs.my.toString(),
collision: "none"
});
}
}
};
}
]);
/*----- End of Directive = relativeLayoutContainer ------*/
<relative-layout-container style="width: 500px; height: 500px; background: red;" data-my="center center" data-at="center center">
<relative-layout-container style="width: 200px; height: 200px; background: green;" data-my="center center" data-at="center center">
<relative-layout-container style="width: 20px; height: 20px; background: black;" data-my="center center" data-at="right center">
</relative-layout-container>
<relative-layout-container style="width: 20px; height: 20px; background: blue;" data-my="center center" data-at="left top">
</relative-layout-container>
</relative-layout-container>
<relative-layout-container style="width: 20px; height: 20px; background: black;" data-my="center center" data-at="right center">
</relative-layout-container>
</relative-layout-container>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment