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

Commit 161cc7d

Browse files
committed
Merge pull request #10 from choxi/master
add onLoad option
2 parents c0f94f5 + 4da836f commit 161cc7d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,31 @@ Although, _ui-ace_ automatically handles some handy options :
7474
+ _useWrapMode_ : to set whether or not line wrapping is enabled.
7575
+ _theme_ : to set the thme to use.
7676
+ _mode_ : to set the mode to use.
77+
+ _onLoad_ : callback when the editor has finished loading
7778

7879
```html
7980
<div ui-ace="{
8081
useWrapMode : true,
8182
showGutter: false,
8283
theme:'twilight',
83-
mode: 'xml'
84+
mode: 'xml',
85+
onLoad: aceLoaded
8486
}"></div>
8587
```
8688

89+
You'll want to define the onLoad callback on your scope:
90+
91+
```javascript
92+
myAppModule.controller('MyController', [ '$scope', function($scope) {
93+
94+
$scope.aceLoaded = function(editor) {
95+
// Options
96+
_editor.setReadOnly(true);
97+
};
98+
99+
}]);
100+
```
101+
87102
To handle other options you'll have to use a direct access to the Ace created instance (see [below](#ace-instance-direct-access)).
88103

89104
## Working with ng-model

test/ace.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ describe('uiAce', function () {
7373
expect(_ace.renderer.getShowGutter()).toBeFalsy();
7474
});
7575
});
76+
describe('onLoad', function() {
77+
it("runs the onLoad callback", function() {
78+
scope.aceLoaded = function() {};
79+
spyOn(scope, "aceLoaded");
80+
$compile('<div ui-ace="{onLoad: aceLoaded}">')(scope);
81+
expect(scope.aceLoaded).toHaveBeenCalled();
82+
});
83+
});
7684
});
7785

7886
describe('when the model changes', function () {

ui-ace.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ angular.module('ui.ace', [])
5959
session.setUseWrapMode(opts.useWrapMode);
6060
}
6161

62+
// onLoad callback
63+
if (angular.isFunction(opts.onLoad)) {
64+
opts.onLoad(acee);
65+
}
66+
6267
// Basic options
6368
if (angular.isString(opts.theme)) {
6469
acee.setTheme("ace/theme/" + opts.theme);

0 commit comments

Comments
 (0)