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

Commit

Permalink
feat(ui-ace): Make the readonly option use double-curly expressions. C…
Browse files Browse the repository at this point in the history
…lose #3.
  • Loading branch information
douglasduteil committed Dec 14, 2013
1 parent 5da05ab commit 2115d61
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ The ng-model will be watched for to set the Ace EditSession value (by [setValue]

_The ui-ace directive stores and expects the model value to be a standard javascript String._

### Can be read only

Simple demo
```html
<div ui-ace readonly="true"></div>
or
Check me to make Ace readonly: <input type="checkbox" ng-model="checked" ><br/>
<div ui-ace readonly="{{checked}}"></div>
```

### Ace instance direct access

For more interaction with the Ace instance in the directive, we provide a direct access to it.
Expand Down
18 changes: 15 additions & 3 deletions test/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,25 @@ describe('uiAce', function () {

describe('readOnly', function () {
it('should read only option true', function () {
$compile('<div ui-ace="{readOnly:true}">')(scope);
expect(_ace).toBeDefined();
$compile('<div ui-ace readonly="true">')(scope);
scope.$apply();
expect(_ace.getReadOnly()).toBeTruthy();
$compile('<div ui-ace readonly="{{foo}}">')(scope);
scope.$apply("foo = true");
expect(_ace.getReadOnly()).toBeTruthy();
});
it('should read only option false', function () {
$compile('<div ui-ace>')(scope);
expect(_ace).toBeDefined();
scope.$apply();
expect(_ace.getReadOnly()).toBeFalsy();
$compile('<div ui-ace readonly="false">')(scope);
scope.$apply();
expect(_ace.getReadOnly()).toBeFalsy();
$compile('<div ui-ace readonly="{{foo}}">')(scope);
expect(_ace.getReadOnly()).toBeFalsy();
scope.$apply("foo = true");
expect(_ace.getReadOnly()).toBeTruthy();
scope.$apply("foo = false");
expect(_ace.getReadOnly()).toBeFalsy();
});
});
Expand Down
6 changes: 3 additions & 3 deletions ui-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ angular.module('ui.ace', [])
session.setMode("ace/mode/" + opts.mode);
}

if (angular.isDefined(opts.readOnly)) {
acee.setReadOnly(opts.readOnly);
}
attrs.$observe('readonly', function (value) {
acee.setReadOnly(value === 'true');
});

// Value Blind
if (angular.isDefined(ngModel)) {
Expand Down

0 comments on commit 2115d61

Please sign in to comment.