@ngal/ui
Version:
Addons for ui.bootstrap
44 lines (36 loc) • 1.32 kB
JavaScript
/* eslint-disable indent */
(function() {
"use strict";
angular
.module("ngal.ui")
.directive("ngalChangeThenLeave",
["ngal.ui.directiveUtil",
function(directiveUtil) {
function link(scope, elem, attrs, ngModelCtrl) {
var formElem;
var privateScope = scope.$root.$new(true);
function onLeave() {
if (privateScope.changed) {
privateScope.changed = false;
directiveUtil.callScriptFn(scope, attrs.ngalChangeThenLeave, ["model"]);
}
}
if (ngModelCtrl) {
ngModelCtrl.$viewChangeListeners.push(function() {
privateScope.changed = true;
});
formElem = directiveUtil.findParentElem("form", elem);
if (formElem) {
formElem.on("submit", function() { onLeave(); });
}
elem.on("blur mouseout", function() { onLeave();});
}
}
return {
link: link,
require: "?ngModel",
restrict: "A",
scope: false
};
}]);
})();