mapping
7 years ago
angular-chosen.directive.js
7 years ago
attributes.service.js
7 years ago
autodetect.directive.js
7 years ago
cascade.directive.js
7 years ago
contenteditable.directive.js
7 years ago
currency.service.js
7 years ago
droppable.directive.js
7 years ago
export.service.js
7 years ago
focusMeWhenEnabled.directive.js
7 years ago
googleCategoriesService.js
7 years ago
main.controller.js
7 years ago
styledInput.directive.js
7 years ago
template.service.js
7 years ago
tipsy.directive.js
7 years ago
wpHttp.service.js
7 years ago
contenteditable.directive.js
32 lines
| 1 | GoogleMerchants.directive('contenteditable', ['$sce', function($sce) { |
| 2 | return { |
| 3 | restrict: 'A', // only activate on element attribute |
| 4 | require: '?ngModel', // get a hold of NgModelController |
| 5 | link: function(scope, element, attrs, ngModel) { |
| 6 | if (!ngModel) return; // do nothing if no ng-model |
| 7 | |
| 8 | // Specify how UI should be updated |
| 9 | ngModel.$render = function() { |
| 10 | element.html($sce.getTrustedHtml(ngModel.$viewValue || '')); |
| 11 | }; |
| 12 | |
| 13 | // Listen for change events to enable binding |
| 14 | element.on('blur keyup change', function() { |
| 15 | scope.$evalAsync(read); |
| 16 | }); |
| 17 | read(); // initialize |
| 18 | |
| 19 | // Write data to the model |
| 20 | function read() { |
| 21 | var html = element.html(); |
| 22 | // When we clear the content editable the browser leaves a <br> behind |
| 23 | // If strip-br attribute is provided then we strip this out |
| 24 | if (attrs.stripBr && html === '<br>') { |
| 25 | html = ''; |
| 26 | } |
| 27 | ngModel.$setViewValue(html); |
| 28 | } |
| 29 | } |
| 30 | }; |
| 31 | }]); |
| 32 |