diff --git a/README.md b/README.md index e6a8330..f2bb72c 100644 --- a/README.md +++ b/README.md @@ -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
``` +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 diff --git a/test/ace.spec.js b/test/ace.spec.js index 35203cb..5400c92 100644 --- a/test/ace.spec.js +++ b/test/ace.spec.js @@ -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('
')(scope); + expect(scope.aceLoaded).toHaveBeenCalled(); + }); + }); }); describe('when the model changes', function () { diff --git a/ui-ace.js b/ui-ace.js index 25f3c80..74b3580 100644 --- a/ui-ace.js +++ b/ui-ace.js @@ -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);