1 // https://civicrm.org/licensing
2 (function(angular
, $, _
) {
5 // Editable titles using ngModel & html5 contenteditable
6 // Cribbed from ContactLayoutEditor
7 angular
.module('afGuiEditor').directive("afGuiEditable", function() {
14 link: function(scope
, element
, attrs
, ngModel
) {
18 var htmlVal
= element
.html();
20 htmlVal
= scope
.defaultValue
;
21 element
.text(htmlVal
);
23 ngModel
.$setViewValue(htmlVal
);
26 ngModel
.$render = function() {
27 element
.text(ngModel
.$viewValue
|| scope
.defaultValue
);
30 // Special handling for enter and escape keys
31 element
.on('keydown', function(e
) {
32 // Enter: prevent line break and save
39 element
.html(ngModel
.$viewValue
|| scope
.defaultValue
);
44 element
.on("blur change", function() {
48 element
.attr('contenteditable', 'true').addClass('crm-editable-enabled');
53 })(angular
, CRM
.$, CRM
._
);