Skip to content

Commit 895b45a

Browse files
committed
Added froala-view directive to support displaying all froala features
1 parent 27f13c7 commit 895b45a

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This repository contains bindings for the latest version of the Froala Editor (v
1313

1414
3. Load Froala WYSIWYG editor (and all desired plugins), jQuery and the angular-froala files into your project
1515
- src/angular-froala.js
16-
- src/froala-sanitize.js
1716

1817
## Usage
1918

@@ -105,9 +104,17 @@ The object received by the function will contain the following methods:
105104
106105
Checkout the demo file to see a working example.
107106
108-
###Displaying Html
107+
<!-- ### Displaying Html -->
109108
110-
Using `ng-bind-html` will render your html on the page but the default angular-sanitize.js will strip out all style tags. Remedy this by including `froala-sanitize.js` instead. example: `<div class="fr-view" ng-bind-html="myHtml"></div>`
109+
![screenshot 2016-02-25 16 47 15](https://cloud.githubusercontent.com/assets/597735/13335505/774c0a76-dbdf-11e5-94c5-b0eb9c5b4923.png)
110+
111+
To display content created with the froala editor use the froala-view directive.
112+
if `myHtml` is your model, then the following will render your content.
113+
```html
114+
<div froala-view="myHtml"></div>
115+
```
116+
117+
If you are using the old `ng-bind-html` that will continue to work however it still requires froala-sanitize.js to be use and not all of froala is supported with it. The update directive does __not__ require froala-sanitize.
111118
112119
Congrats all is done!
113120

demo/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// add the module with global defaults for froala
2-
var myApp = angular.module('myApp', ['ngSanitize', 'froala']).
2+
var myApp = angular.module('myApp', ['froala']).
33
value('froalaConfig', {
44
toolbarInline: false,
55
placeholderText: 'Edit Your Content Here!'
@@ -14,7 +14,7 @@
1414
toolbarInline: true,
1515
events: {
1616
'froalaEditor.initialized': function() {
17-
console.log('initialized')
17+
console.log('initialized');
1818
}
1919
}
2020
};

demo/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
<script src="../bower_components/angular/angular.min.js"></script>
6161

6262
<script src="../src/froala-sanitize.js"></script>
63-
<script src="../src/angular-froala.js"></script>
6463
<script src="app.js"></script>
6564
<link rel="stylesheet" href="app.css">
6665
</head>
@@ -77,7 +76,7 @@ <h2>Sample 1: Inline Edit</h2>
7776
<h2>Sample 2: Full Editor</h2>
7877
<textarea id="froala-sample-2" froala ng-model="sample2Text"></textarea>
7978
<h4>Rendered Content:</h4>
80-
<div class="fr-view" ng-bind-html="sample2Text"></div>
79+
<div froala-view="sample2Text"></div>
8180
</div>
8281

8382
<div class="sample">

src/angular-froala.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module('froala', []).
2-
value('froalaConfig', {}).
3-
directive('froala', ['froalaConfig', function (froalaConfig) {
2+
value('froalaConfig', {})
3+
.directive('froala', ['froalaConfig', function (froalaConfig) {
44
"use strict"; //Scope strict mode to only this directive
55
var generatedIds = 0;
66
var defaultConfig = { immediateAngularModelUpdate: false};
@@ -132,4 +132,21 @@ directive('froala', ['froalaConfig', function (froalaConfig) {
132132
ctrl.init();
133133
}
134134
};
135+
}])
136+
.directive('froalaView', ['$sce', function ($sce) {
137+
return {
138+
restrict: 'ACM',
139+
scope: {
140+
content: '=froalaView'
141+
},
142+
link: function (scope, element) {
143+
element.addClass('fr-view');
144+
scope.$watch('content', function (nv) {
145+
if (nv || nv === ''){
146+
var explicitlyTrustedValue = $sce.trustAsHtml(nv);
147+
element.html(explicitlyTrustedValue.toString());
148+
}
149+
});
150+
}
151+
};
135152
}]);

test/angular-froala.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ describe("froala", function () {
33
var $compile;
44
var $rootScope;
55
var element = null;
6+
var view = null;
67
var elementHtml = null;
8+
var viewHtml = null;
79
var froalaEditorStub = null;
810
var froalaEditorOnStub = null;
911
var froalaEditorOffStub = null;
@@ -19,6 +21,7 @@ describe("froala", function () {
1921

2022
froalaConfig.placeholderText = 'Placeholder';
2123
elementHtml = "<div froala='froalaOptions' ng-model='content'></div>";
24+
viewHtml = "<div froala-view='content'></div>";
2225
}));
2326

2427
var compileElement = function (extraSetup) {
@@ -31,6 +34,10 @@ describe("froala", function () {
3134
element = $compile(elementHtml)($rootScope);
3235
};
3336

37+
var compileViewElement = function () {
38+
view = $compile(viewHtml)($rootScope);
39+
};
40+
3441
var setupFroalaEditorStub = function () {
3542
froalaEditorStub = sinon.stub();
3643
froalaEditorOnStub = sinon.stub();
@@ -289,4 +296,13 @@ describe("froala", function () {
289296
//
290297

291298
});
299+
300+
it('Sets the view to the value of the model', function () {
301+
$rootScope.content = '<i>New Text</i>';
302+
303+
compileViewElement();
304+
$rootScope.$digest();
305+
306+
expect(view.html()).toEqual("<i>New Text</i>");
307+
});
292308
});

0 commit comments

Comments
 (0)