Skip to content

Commit

Permalink
fixed ta-default-tag-attribute attribute handling to extend the existing
Browse files Browse the repository at this point in the history
taOptions.defaultTagAttributes property. I also added a TODO statement to update this
to use angular.merge as soon as textAngular requires angular 1.4 or higher
  • Loading branch information
Ken Severn committed Apr 28, 2015
1 parent f633b59 commit 2c8c2c9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/textAngular.min.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions lib/main.js
Expand Up @@ -134,19 +134,20 @@ textAngular.directive("textAngular", [
if(attrs.taFocussedClass) scope.classes.focussed = attrs.taFocussedClass;
if(attrs.taTextEditorClass) scope.classes.textEditor = attrs.taTextEditorClass;
if(attrs.taHtmlEditorClass) scope.classes.htmlEditor = attrs.taHtmlEditorClass;
// optional setup functions
if(attrs.taTextEditorSetup) scope.setup.textEditorSetup = scope.$parent.$eval(attrs.taTextEditorSetup);
if(attrs.taHtmlEditorSetup) scope.setup.htmlEditorSetup = scope.$parent.$eval(attrs.taHtmlEditorSetup);
// optional fileDropHandler function
if(attrs.taFileDrop) scope.fileDropHandler = scope.$parent.$eval(attrs.taFileDrop);
else scope.fileDropHandler = scope.defaultFileDropHandler;
if(attrs.taDefaultTagAttributes){
try {
scope.defaultTagAttributes = angular.fromJson(attrs.taDefaultTagAttributes);
// TODO: This should use angular.merge to enhance functionality once angular 1.4 is required
angular.extend(scope.defaultTagAttributes, angular.fromJson(attrs.taDefaultTagAttributes));
} catch (error) {
$log.error(error);
}
}
// optional setup functions
if(attrs.taTextEditorSetup) scope.setup.textEditorSetup = scope.$parent.$eval(attrs.taTextEditorSetup);
if(attrs.taHtmlEditorSetup) scope.setup.htmlEditorSetup = scope.$parent.$eval(attrs.taHtmlEditorSetup);
// optional fileDropHandler function
if(attrs.taFileDrop) scope.fileDropHandler = scope.$parent.$eval(attrs.taFileDrop);
else scope.fileDropHandler = scope.defaultFileDropHandler;

_originalContents = element[0].innerHTML;
// clear the original content
Expand Down
15 changes: 8 additions & 7 deletions src/textAngular.js
Expand Up @@ -1926,19 +1926,20 @@ textAngular.directive("textAngular", [
if(attrs.taFocussedClass) scope.classes.focussed = attrs.taFocussedClass;
if(attrs.taTextEditorClass) scope.classes.textEditor = attrs.taTextEditorClass;
if(attrs.taHtmlEditorClass) scope.classes.htmlEditor = attrs.taHtmlEditorClass;
// optional setup functions
if(attrs.taTextEditorSetup) scope.setup.textEditorSetup = scope.$parent.$eval(attrs.taTextEditorSetup);
if(attrs.taHtmlEditorSetup) scope.setup.htmlEditorSetup = scope.$parent.$eval(attrs.taHtmlEditorSetup);
// optional fileDropHandler function
if(attrs.taFileDrop) scope.fileDropHandler = scope.$parent.$eval(attrs.taFileDrop);
else scope.fileDropHandler = scope.defaultFileDropHandler;
if(attrs.taDefaultTagAttributes){
try {
scope.defaultTagAttributes = angular.fromJson(attrs.taDefaultTagAttributes);
// TODO: This should use angular.merge to enhance functionality when angular 1.4 is required
angular.extend(scope.defaultTagAttributes, angular.fromJson(attrs.taDefaultTagAttributes));
} catch (error) {
$log.error(error);
}
}
// optional setup functions
if(attrs.taTextEditorSetup) scope.setup.textEditorSetup = scope.$parent.$eval(attrs.taTextEditorSetup);
if(attrs.taHtmlEditorSetup) scope.setup.htmlEditorSetup = scope.$parent.$eval(attrs.taHtmlEditorSetup);
// optional fileDropHandler function
if(attrs.taFileDrop) scope.fileDropHandler = scope.$parent.$eval(attrs.taFileDrop);
else scope.fileDropHandler = scope.defaultFileDropHandler;

_originalContents = element[0].innerHTML;
// clear the original content
Expand Down
4 changes: 2 additions & 2 deletions test/textAngular.spec.js
Expand Up @@ -198,7 +198,7 @@ describe('textAngular', function(){
}));

it('respects the taDefaultTagAttributes attribute',inject(function ($compile, $rootScope, $document, textAngularManager) {
$rootScope.taTestDefaultTagAttributes = {a:{target:"_blank"}};
$rootScope.taTestDefaultTagAttributes = {a:{target:"_blank"}, li:{test:"testing"}};
element = $compile('<text-angular name="test" ta-default-tag-attributes="{{taTestDefaultTagAttributes}}"></text-angular>')($rootScope);
$document.find('body').append(element);
editorScope = textAngularManager.retrieveEditor('test').scope;
Expand All @@ -207,7 +207,7 @@ describe('textAngular', function(){
element.remove();
}));

it('uses the default defaultTagAttributes when the taDefaultTabAttributes attribute throws a JSON parse error',inject(function ($compile, $rootScope, $document, textAngularManager) {
it('uses the default defaultTagAttributes when the taDefaultTagAttributes attribute throws a JSON parse error',inject(function ($compile, $rootScope, $document, textAngularManager) {
var taTestDefaultTagAttributes = {a:{target:""}};
element = $compile('<text-angular name="test" ta-default-tag-attributes="invalidJSON"></text-angular>')($rootScope);
$document.find('body').append(element);
Expand Down

0 comments on commit 2c8c2c9

Please sign in to comment.