Skip to content

Commit

Permalink
Merge pull request #109 from nwpan/bug/activate_summernote_with_empty…
Browse files Browse the repository at this point in the history
…_model

Fix for an issue where initializing an (unintentional) empty model causes a push onto the Summernote History stack.
  • Loading branch information
outsideris committed Feb 1, 2016
2 parents e94e2fb + 8dae336 commit 88063d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/angular-summernote.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ angular.module('summernote', [])
removedMedia.attrs[attr.name] = attr.value;
});
$scope.mediaDelete({target: removedMedia});
}
};
}

this.activate = function(scope, element, ngModel) {
Expand Down Expand Up @@ -152,14 +152,22 @@ angular.module('summernote', [])
template: '<div class="summernote"></div>',
link: function(scope, element, attrs, ctrls, transclude) {
var summernoteController = ctrls[0],
ngModel = ctrls[1];

transclude(scope, function(clone, scope) {
// to prevent binding to angular scope (It require `tranclude: 'element'`)
element.append(clone.html());
});
ngModel = ctrls[1];

summernoteController.activate(scope, element, ngModel);
if (!ngModel) {
transclude(scope, function(clone, scope) {
// to prevent binding to angular scope (It require `tranclude: 'element'`)
element.append(clone.html());
});
summernoteController.activate(scope, element, ngModel);
} else {
scope.$watch(function() {
return ngModel.$viewValue;
}, function(value) {
element.append(value);
summernoteController.activate(scope, element, ngModel);
}, true);
}
}
};
}]);
12 changes: 12 additions & 0 deletions test/angular-summernote.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ describe('Summernote directive', function() {
el.remove();
});

it('element text should be blank in outer scope before digesting', function() {
// given
var blankText = '', helloText = 'Hello World';
var element = $compile('<summernote ng-model="text"></summernote>')(scope);
scope.text = helloText;
expect(element.html()).to.be.equal(blankText);
// when
scope.$digest();
// then
expect(element.html()).to.be.equal(helloText);
});

it('text should be synchronized when text is changed using toolbar', function() {
var selectText = function(element){
var doc = document,
Expand Down

0 comments on commit 88063d1

Please sign in to comment.