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

add onLoad option #10

Merged
merged 1 commit into from
Aug 7, 2013
Merged
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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,31 @@ Although, _ui-ace_ automatically handles some handy options :
+ _useWrapMode_ : to set whether or not line wrapping is enabled.
+ _theme_ : to set the thme to use.
+ _mode_ : to set the mode to use.
+ _onLoad_ : callback when the editor has finished loading

```html
<div ui-ace="{
useWrapMode : true,
showGutter: false,
theme:'twilight',
mode: 'xml'
mode: 'xml',
onLoad: aceLoaded
}"></div>
```

You'll want to define the onLoad callback on your scope:

```javascript
myAppModule.controller('MyController', [ '$scope', function($scope) {

$scope.aceLoaded = function(editor) {
// Options
_editor.setReadOnly(true);
};

}]);
```

To handle other options you'll have to use a direct access to the Ace created instance (see [below](#ace-instance-direct-access)).

## Working with ng-model
Expand Down
8 changes: 8 additions & 0 deletions test/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ describe('uiAce', function () {
expect(_ace.renderer.getShowGutter()).toBeFalsy();
});
});
describe('onLoad', function() {
it("runs the onLoad callback", function() {
scope.aceLoaded = function() {};
spyOn(scope, "aceLoaded");
$compile('<div ui-ace="{onLoad: aceLoaded}">')(scope);
expect(scope.aceLoaded).toHaveBeenCalled();
});
});
});

describe('when the model changes', function () {
Expand Down
5 changes: 5 additions & 0 deletions ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ angular.module('ui.ace', [])
session.setUseWrapMode(opts.useWrapMode);
}

// onLoad callback
if (angular.isFunction(opts.onLoad)) {
opts.onLoad(acee);
}

// Basic options
if (angular.isString(opts.theme)) {
acee.setTheme("ace/theme/" + opts.theme);
Expand Down