Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created April 16, 2014 20:55
Show Gist options
  • Save dhigginbotham/10932210 to your computer and use it in GitHub Desktop.
Save dhigginbotham/10932210 to your computer and use it in GitHub Desktop.
angular colorbox modal directive
var app = app || {};
/**
* angular xhr modal directive
* @param
*/
app.directive('xhrModal', ['$http','$compile',
function ($http, $compile) {
function compile (elem, cAtts) {
var template,
$element,
loader;
loader = $http.get(cAtts.template).success(function (resp) {
template = resp;
});
return function (scope, elem, lAtts) {
loader.then(function () {
$element = $compile(template)(scope);
});
scope.close = function() {
jQuery.colorbox.close();
};
scope.submit = function() {
var result = scope.formSubmit();
if (Object.isObject(result)) {
result.success(function() {
jQuery.colorbox.close();
});
} else if (result === false) {
//noop
} else {
jQuery.colorbox.close();
}
};
elem.on('click', function(e) {
e.preventDefault();
jQuery.colorbox({inline: true, href: $element});
});
}
}
return {
scope: {
formObject: '=',
formErrors: '=',
title: '@',
template: '@',
okButtonText: '@',
formSubmit: '&'
},
compile: compile
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment