Created
April 16, 2014 20:55
-
-
Save dhigginbotham/10932210 to your computer and use it in GitHub Desktop.
angular colorbox modal directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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