Skip to content

Commit 5af76dd

Browse files
Merge pull request #202 from dheerajaccolite/v.3
Angular Changes to make it work with Non Jquery froala v.3
2 parents 4c2fbab + 96fb737 commit 5af76dd

File tree

8 files changed

+32
-44
lines changed

8 files changed

+32
-44
lines changed

.jshintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"browser": true,
2121
"devel": true,
2222
"jasmine": true,
23-
"jquery": true,
2423
// Custom Globals
2524
"globals": {
2625
"module": true,

Gruntfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module.exports = function(grunt) {
2929
browsers: ['PhantomJS'],
3030
files: [
3131
'node_modules/sinon/pkg/sinon.js',
32-
'bower_components/jquery/dist/jquery.js',
3332
'bower_components/angular/angular.js',
3433
'bower_components/angular-mocks/angular-mocks.js',
3534
'src/**/*.js',

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ This repository contains bindings for the latest version of the Froala Editor (v
1414

1515
1. Clone this repo or download the zip.
1616

17-
2. Run `bower install` or Download the editor from [https://www.froala.com/wysiwyg-editor/](https://www.froala.com/wysiwyg-editor/) and jQuery
17+
2. Run `bower install` or Download the editor from [https://www.froala.com/wysiwyg-editor/](https://www.froala.com/wysiwyg-editor/)
1818

19-
3. Load Froala WYSIWYG editor (and all desired plugins), jQuery and the angular-froala files into your project.
19+
3. Load Froala WYSIWYG editor (and all desired plugins) and the angular-froala files into your project.
2020
- src/angular-froala.js
2121

22-
***NB***: You must ensure jQuery is included *before* angular, otherwise Angular will use it's own jqLite which doesn't provide the necessary functions.
23-
2422
## Update editor
2523

2624
With npm:

bower.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
"text",
1414
"editor",
1515
"wysiwyg",
16-
"jquery-plugin",
1716
"rich editor",
1817
"rich text editor",
1918
"rte",
2019
"javascript",
21-
"jquery"
2220
],
2321
"license": "MIT",
2422
"ignore": [

demo/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
charCounterCount: false,
1414
toolbarInline: true,
1515
events: {
16-
'froalaEditor.initialized': function() {
16+
'initialized': function() {
1717
console.log('initialized');
1818
}
1919
}
@@ -22,7 +22,7 @@
2222
$scope.initialize = function(initControls) {
2323
$scope.initControls = initControls;
2424
$scope.deleteAll = function() {
25-
initControls.getEditor()('html.set', '');
25+
initControls.getEditor().html.set('');
2626
};
2727
};
2828

demo/index.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
<head>
77
<meta charset="utf-8">
88
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0"/>
9-
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
109

11-
<!-- Include Font Awesome. -->
12-
<link href="../node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
13-
14-
<!-- Include Froala Editor styles -->
10+
<!-- Include Froala Editor styles -->
1511
<link rel="stylesheet" href="../bower_components/froala-wysiwyg-editor/css/froala_editor.min.css" />
1612
<link rel="stylesheet" href="../bower_components/froala-wysiwyg-editor/css/froala_style.min.css" />
1713

@@ -29,7 +25,7 @@
2925
<link rel="stylesheet" href="../bower_components/froala-wysiwyg-editor/css/plugins/video.css">
3026

3127
<!-- Include Froala Editor -->
32-
<script src="../bower_components/froala-wysiwyg-editor/js/froala_editor.min.js"></script>
28+
<script src="../bower_components/froala-wysiwyg-editor/js/froala_editor.pkgd.min.js"></script>
3329

3430
<!-- Include Froala Editor Plugins -->
3531
<script src="../bower_components/froala-wysiwyg-editor/js/plugins/align.min.js"></script>
@@ -58,7 +54,6 @@
5854
<!-- End Froala -->
5955

6056
<script src="../bower_components/angular/angular.min.js"></script>
61-
6257
<script src="../src/angular-froala.js"></script>
6358
<script src="app.js"></script>
6459
<link rel="stylesheet" href="app.css">

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
"text",
1818
"editor",
1919
"wysisyg",
20-
"jquery-plugin",
2120
"rich editor",
2221
"rich text editor",
2322
"rte",
2423
"javascript",
25-
"jquery"
2624
],
2725
"contributors": [
2826
"Cameron Gallarno <[email protected]>",

src/angular-froala.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(window, angular, jQuery, undefined) {
1+
(function(window, angular, undefined) {
22
'use strict';
33

44
angular.module('froala', [])
@@ -17,7 +17,7 @@
1717
froalaOptions: '=froala',
1818
initFunction: '&froalaInit'
1919
};
20-
20+
2121
froalaConfig = froalaConfig || {};
2222

2323
// Constants
@@ -30,8 +30,12 @@
3030
require: 'ngModel',
3131
scope: scope,
3232
link: function(scope, element, attrs, ngModel) {
33-
if (jQuery) element = jQuery(element);
34-
33+
// Create a blur event to update the data of ngModel
34+
element.on('blur', function () {
35+
ngModel.$setViewValue(element.innerHTML.text())
36+
});
37+
38+
3539
var specialTag = false;
3640
if (SPECIAL_TAGS.indexOf(element.prop("tagName").toLowerCase()) != -1) {
3741
specialTag = true;
@@ -77,11 +81,10 @@
7781
else {
7882
if (ctrl.editorInitialized) {
7983
// Set HTML.
80-
element.froalaEditor('html.set', ngModel.$viewValue || '', true);
81-
84+
element.froalaEditor.html.set(ngModel.$viewValue || '')
8285
//This will reset the undo stack everytime the model changes externally. Can we fix this?
83-
element.froalaEditor('undo.reset');
84-
element.froalaEditor('undo.saveStep');
86+
element.froalaEditor.undo.reset();
87+
element.froalaEditor.undo.saveStep();
8588
}
8689
}
8790
};
@@ -91,10 +94,6 @@
9194
return true;
9295
}
9396

94-
if (ctrl.editorInitialized) {
95-
return element.froalaEditor('node.isEmpty', jQuery('<div>' + value + '</div>').get(0));
96-
}
97-
9897
return true;
9998
};
10099
};
@@ -105,11 +104,11 @@
105104
froalaInitOptions = (froalaInitOptions || {});
106105
ctrl.options = angular.extend({}, defaultConfig, froalaConfig, scope.froalaOptions, froalaInitOptions);
107106

108-
ctrl.registerEventsWithCallbacks('froalaEditor.initializationDelayed', function() {
107+
ctrl.registerEventsWithCallbacks('initializationDelayed', function() {
109108
ngModel.$render()
110109
});
111110

112-
ctrl.registerEventsWithCallbacks('froalaEditor.initialized', function () {
111+
ctrl.registerEventsWithCallbacks('initialized', function () {
113112
ctrl.editorInitialized = true;
114113
ngModel.$render()
115114
})
@@ -122,10 +121,9 @@
122121
}
123122
}
124123

125-
element.innerHTML =
126-
ctrl.froalaElement = element.froalaEditor(ctrl.options).data('froala.editor').$el;
127-
ctrl.froalaEditor = angular.bind(element, element.froalaEditor);
128-
ctrl.initListeners();
124+
ctrl.froalaEditor = element.froalaEditor = new FroalaEditor('#'+element.attr('id'),ctrl.options);
125+
element.innerHTML = ctrl.froalaElement = ctrl.froalaEditor.$el[0];
126+
ctrl.initListeners();
129127

130128
//assign the froala instance to the options object to make methods available in parent scope
131129
if (scope.froalaOptions) {
@@ -136,18 +134,18 @@
136134

137135
ctrl.initListeners = function() {
138136
if (ctrl.options.immediateAngularModelUpdate) {
139-
ctrl.froalaElement.on('froalaEditor.keyup', function() {
137+
ctrl.registerEventsWithCallbacks('keyup', function() {
140138
scope.$evalAsync(ctrl.updateModelView);
141139
});
142140
}
143141

144-
element.on('froalaEditor.contentChanged', function() {
142+
ctrl.registerEventsWithCallbacks('contentChanged', function() {
145143
scope.$evalAsync(ctrl.updateModelView);
146144
});
147145

148146
element.bind('$destroy', function() {
149147
if (element) {
150-
element.froalaEditor('destroy');
148+
element.froalaEditor.destroy();
151149
element = null;
152150
}
153151
});
@@ -176,7 +174,7 @@
176174
}
177175
modelContent = attrs;
178176
} else {
179-
var returnedHtml = element.froalaEditor('html.get');
177+
var returnedHtml = element.froalaEditor.html.get();
180178
if (angular.isString(returnedHtml)) {
181179
modelContent = returnedHtml;
182180
}
@@ -191,7 +189,10 @@
191189
ctrl.registerEventsWithCallbacks = function(eventName, callback) {
192190
if (eventName && callback) {
193191
ctrl.listeningEvents.push(eventName);
194-
element.on(eventName, callback);
192+
if(!ctrl.options.events){
193+
ctrl.options.events = {};
194+
}
195+
ctrl.options.events[eventName] = callback;
195196
}
196197
};
197198

@@ -201,7 +202,7 @@
201202
initialize: ctrl.createEditor,
202203
destroy: function() {
203204
if (_ctrl.froalaEditor) {
204-
_ctrl.froalaEditor('destroy');
205+
_ctrl.froalaEditor.destroy();
205206
_ctrl.editorInitialized = false;
206207
}
207208
},
@@ -232,4 +233,4 @@
232233
}
233234
};
234235
}]);
235-
})(window, window.angular, window.jQuery);
236+
})(window, window.angular);

0 commit comments

Comments
 (0)