Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Enabled attaching of the editor (for direct access) to any part of the scope hierarchy #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ describe('uiAce', function () {
}
expect(compile).not.toThrow();
});

it('should be wrapped with .ace_editor_wrapper', function () {
var element = $compile('<div ui-ace>')(scope);
expect(element.parent().hasClass('ace_editor_wrapper')).toBeTruthy();
});


it('should watch the uiAce attribute', function () {
spyOn(scope, '$watch');
$compile('<div ui-ace ng-model="foo">')(scope);
expect(scope.$watch).toHaveBeenCalled();
});

});

describe('instance', function () {
Expand Down Expand Up @@ -132,6 +132,8 @@ describe('uiAce', function () {
it('should access to this instance in the scope', function () {
$compile('<div ui-ace scope-instance="foo">')(scope);
expect(scope.foo).toBe(_ace);
$compile('<div ui-ace scope-instance="bar.baz.qux">')(scope);
expect(scope.bar.baz.qux).toBe(_ace);
});
});
});
Expand All @@ -155,5 +157,5 @@ describe('uiAce', function () {
});
});


});
12 changes: 9 additions & 3 deletions ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ angular.module('ui.ace', [])
// EVENTS
session.on('change', onChange(opts.onChange));

// Direct instance access
// Allow the editor to be directly accessed via the location in the scope specified by the scope-instance attribute
if (attrs.scopeInstance && "" !== attrs.scopeInstance) {
scope[attrs.scopeInstance] = acee;
var parts, last_part, loc, i;
parts = attrs.scopeInstance.split(".");
last_part = parts.pop();
loc = scope;
for (i = 0; i < parts.length; i++) {
loc = loc[parts[i]] = (loc[parts[i]] || {});
}
loc[last_part] = acee;
}

}
};
}]);