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

Commit e25bd6e

Browse files
committed
Merge pull request #5 from wesleycho/master
Updated plugin for TinyMCE 3
2 parents 03db243 + b3cea18 commit e25bd6e

File tree

8 files changed

+101
-122
lines changed

8 files changed

+101
-122
lines changed

README.md

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,74 @@
1-
# ui-date directive [![Build Status](https://travis-ci.org/angular-ui/ui-tinymce.png)](https://travis-ci.org/angular-ui/ui-tinymce)
1+
# ui-tinymce directive [![Build Status](https://travis-ci.org/angular-ui/ui-tinymce.png)](https://travis-ci.org/angular-ui/ui-tinymce)
22

3-
This directive allows you to add a date-picker to your form elements.
3+
This directive allows you to add a TinyMCE editor to your form elements.
44

55
# Requirements
66

77
- AngularJS
8-
- JQuery
9-
- JQueryUI
10-
- [Date.toISOString()](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toISOString) (requires [polyfill](https://github.com/kriskowal/es5-shim/) for ≤IE8)
8+
- TinyMCE 3
119

1210
# Testing
1311

14-
We use testacular and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:
12+
We use karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:
1513

1614
npm install -g grunt-cli
1715
npm install
1816
bower install
1917
grunt
2018

21-
The testacular task will try to open Chrome as a browser in which to run the tests. Make sure this is available or change the configuration in `test\test.config.js`
19+
The karma task will try to open Chrome as a browser in which to run the tests. Make sure this is available or change the configuration in `test\test.config.js`
2220

2321
# Usage
2422

2523
We use [bower](http://twitter.github.com/bower/) for dependency management. Add
2624

2725
dependencies: {
28-
"angular-ui-date": "latest"
26+
"angular-ui-tinymce": "latest"
2927
}
3028

3129
To your `components.json` file. Then run
3230

3331
bower install
3432

35-
This will copy the ui-date files into your `components` folder, along with its dependencies. Load the script files in your application:
33+
This will copy the ui-tinymce files into your `components` folder, along with its dependencies. Load the script files in your application:
3634

37-
<script type="text/javascript" src="components/jquery/jquery.js"></script>
38-
<script type="text/javascript" src="components/jquery-ui\ui\jquery-ui.custom.js"></script>
35+
<script type="text/javascript" src="components/tinymce/tinymce.js"></script>
3936
<script type="text/javascript" src="components/angular/angular.js"></script>
40-
<script type="text/javascript" src="components/angular-ui-date/date.js"></script>
37+
<script type="text/javascript" src="components/angular-ui-tinymce/tinymce.js"></script>
4138

42-
Add the date module as a dependency to your application module:
39+
Add the tinymce module as a dependency to your application module:
4340

44-
var myAppModule = angular.module('MyApp', ['ui.date'])
41+
var myAppModule = angular.module('MyApp', ['ui.tinymce'])
4542

4643
Apply the directive to your form elements:
4744

48-
<input ui-date>
45+
<form method="post">
46+
<textarea id="tinymce" ui-tinymce ng-model="tinymceModel"></textarea>
47+
</form>
4948

5049
## Options
5150

52-
All the jQueryUI DatePicker options can be passed through the directive.
51+
All the TinyMCE options can be passed through the directive.
5352

5453
myAppModule.controller('MyController', function($scope) {
55-
$scope.dateOptions = {
56-
changeYear: true,
57-
changeMonth: true,
58-
yearRange: '1900:-0'
54+
$scope.tinymceOptions = {
55+
handle_event_callback: function (e) {
56+
// put logic here for keypress
57+
}
5958
};
6059
});
6160

62-
<input ui-date="dateOptions" name="DateOfBirth">
63-
64-
## Static Inline Picker
65-
66-
If you want a static picker then simply apply the directive to a div rather than an input element.
67-
68-
<div ui-date="dateOptions" name="DateOfBirth"></div>
61+
<form method="post">
62+
<textarea id="tinymce" ui-tinymce ng-model="tinymceModel"></textarea>
63+
</form>
6964

7065
## Working with ng-model
7166

72-
The ui-date directive plays nicely with ng-model and validation directives such as ng-required.
73-
74-
If you add the ng-model directive to same the element as ui-date then the picked date is automatically synchronized with the model value.
75-
76-
_The ui-date directive stores and expects the model value to be a standard javascript Date object._
77-
78-
## ui-date-format directive
79-
The ui-date directive only works with Date objects.
80-
If you want to pass date strings to and from the date directive via ng-model then you must use the ui-date-format directive.
81-
This directive specifies the format of the date string that will be expected in the ng-model.
82-
The format string syntax is that defined by the JQueryUI Date picker. For example
83-
84-
<input ui-date ui-date-format="DD, d MM, yy" ng-model="myDate">
85-
86-
Now you can set myDate in the controller.
87-
88-
$scope.myDate = "Thursday, 11 October, 2012";
89-
90-
## ng-required directive
91-
92-
If you apply the required directive to element then the form element is invalid until a date is picked.
67+
The ui-tinymce directive plays nicely with the ng-model directive such as ng-required.
9368

94-
Note: Remember that the ng-required directive must be explictly set, i.e. to "true". This is especially true on divs:
69+
If you add the ng-model directive to same the element as ui-tinymce then the text in the editor is automatically synchronized with the model value.
9570

96-
<div ui-date="dateOptions" name="DateOfBirth" ng-required="true"></div>
71+
_ng-model and the id are required_.
9772

73+
_The ui-tinymce directive stores and expects the model value to be a standard javascript tinymce object._
9874

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"dependencies": {
1919
"angular": "~1.x",
20-
"tinymce": "latest"
20+
"tinymce-release": "latest"
2121
},
2222
"devDependencies": {
2323
"angular-mocks": "~1.x"

demo/demo.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
<head>
77
<meta charset="utf-8">
88
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
9-
<title>AngularUI - Date Picker Demo</title>
9+
<title>AngularUI - TinyMCE Demo</title>
1010
<base href=".."></base>
11-
<link rel="stylesheet" href="components/jquery-ui/themes/smoothness/jquery-ui.css">
12-
<script type="text/javascript" src="components/jquery/jquery.js"></script>
13-
<script type="text/javascript" src="components/jquery-ui/ui/jquery-ui.custom.js"></script>
11+
<script type="text/javascript" src="components/tinymce-release/tiny_mce.js"></script>
1412
<script type="text/javascript" src="components/angular/angular.js"></script>
15-
<script type="text/javascript" src="src/date.js"></script>
13+
<script type="text/javascript" src="src/tinymce.js"></script>
1614
</head>
17-
<body ng-app="ui.date">
18-
<label>Select Date: <input type="text" ui-date ng-model="aDate"></label>
19-
<div>{{aDate}}</div>
15+
<body ng-app="ui.tinymce">
16+
<form method="post">
17+
<textarea id="tinymce" ui-tinymce ng-model="tinymce"></textarea>
18+
</form>
19+
<div>{{tinymce}}</div>
2020
</body>
2121
</html>

gruntFile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module.exports = function (grunt) {
22

3-
grunt.loadNpmTasks('grunt-testacular');
3+
grunt.loadNpmTasks('grunt-karma');
44
grunt.loadNpmTasks('grunt-contrib-jshint');
55

66
// Default task.
7-
grunt.registerTask('default', ['jshint', 'testacular']);
7+
grunt.registerTask('default', ['jshint', 'karma']);
88

9-
var testacularConfig = function(configFile, customOptions) {
9+
var karmaConfig = function(configFile, customOptions) {
1010
var options = { configFile: configFile, keepalive: true };
1111
var travisOptions = process.env.TRAVIS && { browsers: ['Firefox'], reporters: 'dots' };
1212
return grunt.util._.extend(options, customOptions, travisOptions);
1313
};
1414

1515
// Project configuration.
1616
grunt.initConfig({
17-
testacular: {
17+
karma: {
1818
unit: {
19-
options: testacularConfig('test/test.conf.js')
19+
options: karmaConfig('test/test.conf.js')
2020
}
2121
},
2222
jshint:{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"dependencies": {},
1010
"devDependencies": {
1111
"grunt": "~0.4.1",
12-
"grunt-testacular": "~0.3.0",
12+
"grunt-karma": "~0.4.4",
1313
"grunt-contrib-jshint": "~0.2.0"
1414
},
1515
"scripts": {},
1616
"repository": {
1717
"type": "git",
18-
"url": "git://github.com/angular-ui/ui-date.git"
18+
"url": "git://github.com/angular-ui/ui-tinymce.git"
1919
}
2020
}

src/tinymce.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
11
/**
22
* Binds a TinyMCE widget to <textarea> elements.
33
*/
4-
angular.module('ui.tinymce', []).directive('uiTinymce', ['uiTinymceConfig', function (uiTinymceConfig) {
5-
uiTinymceConfig = uiTinymceConfig || {};
6-
return {
7-
require: 'ngModel',
8-
link: function (scope, elm, attrs, ngModel) {
9-
var expression,
10-
options = {
11-
// Update model on button click
12-
onchange_callback: function (inst) {
13-
if (inst.isDirty()) {
14-
inst.save();
15-
ngModel.$setViewValue(elm.val());
16-
if (!scope.$$phase)
17-
scope.$apply();
18-
}
19-
},
20-
// Update model on keypress
21-
handle_event_callback: function (e) {
22-
if (this.isDirty()) {
23-
this.save();
24-
ngModel.$setViewValue(elm.val());
25-
if (!scope.$$phase)
26-
scope.$apply();
27-
}
28-
return true; // Continue handling
29-
},
30-
// Update model when calling setContent (such as from the source editor popup)
31-
setup: function (ed) {
32-
ed.onSetContent.add(function (ed, o) {
33-
if (ed.isDirty()) {
34-
ed.save();
4+
angular.module('ui.tinymce', [])
5+
.value('uiTinymceConfig', {})
6+
.directive('uiTinymce', ['uiTinymceConfig', function (uiTinymceConfig) {
7+
uiTinymceConfig = uiTinymceConfig || {};
8+
return {
9+
require: 'ngModel',
10+
link: function (scope, elm, attrs, ngModel) {
11+
var expression,
12+
options = {
13+
// Update model on button click
14+
onchange_callback: function (inst) {
15+
if (inst.isDirty()) {
16+
inst.save();
3517
ngModel.$setViewValue(elm.val());
3618
if (!scope.$$phase)
3719
scope.$apply();
3820
}
39-
});
40-
}
41-
};
42-
if (attrs.uiTinymce) {
43-
expression = scope.$eval(attrs.uiTinymce);
44-
} else {
45-
expression = {};
21+
},
22+
// Update model on keypress
23+
handle_event_callback: function (e) {
24+
if (this.isDirty()) {
25+
this.save();
26+
ngModel.$setViewValue(elm.val());
27+
if (!scope.$$phase)
28+
scope.$apply();
29+
}
30+
return true; // Continue handling
31+
},
32+
// Update model when calling setContent (such as from the source editor popup)
33+
setup: function (ed) {
34+
ed.onSetContent.add(function (ed, o) {
35+
if (ed.isDirty()) {
36+
ed.save();
37+
ngModel.$setViewValue(elm.val());
38+
if (!scope.$$phase)
39+
scope.$apply();
40+
}
41+
});
42+
},
43+
mode: 'exact',
44+
elements: attrs.id
45+
};
46+
if (attrs.uiTinymce) {
47+
expression = scope.$eval(attrs.uiTinymce);
48+
} else {
49+
expression = {};
50+
}
51+
angular.extend(options, uiTinymceConfig, expression);
52+
setTimeout(function () {
53+
tinymce.init(options);
54+
});
4655
}
47-
angular.extend(options, uiTinymceConfig, expression);
48-
setTimeout(function () {
49-
elm.tinymce(options);
50-
});
51-
}
52-
};
53-
}]);
56+
};
57+
}]);

test/test.conf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ basePath = '..';
22
files = [
33
JASMINE,
44
JASMINE_ADAPTER,
5-
'components/jquery/jquery.js',
6-
'components/jquery-ui/ui/jquery-ui.custom.js',
75
'components/angular/angular.js',
86
'components/angular-mocks/angular-mocks.js',
9-
'src/date.js',
7+
'components/tinymce-release/tiny_mce.js',
8+
'src/tinymce.js',
109
'test/*.spec.js'
1110
];
1211
singleRun = true;

test/tinymceSpec.js renamed to test/tinymce.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ describe('uiTinymce', function () {
33
'use strict';
44

55
var scope, $compile, element, text = '<p>Hello</p>';
6-
beforeEach(module('ui'));
6+
beforeEach(module('ui.tinymce'));
77
beforeEach(function () {
88
// throw some garbage in the tinymce cfg to be sure it's getting thru to the directive
99
angular.module('ui.tinymce').value('uiTinymceConfig', {tinymce: {bar: 'baz'}});
@@ -22,28 +22,28 @@ describe('uiTinymce', function () {
2222
*/
2323
function compile() {
2424
runs(function () {
25-
element = $compile('<form><textarea name="foo" ui-tinymce="{foo: \'bar\'}" ng-model="foo"></textarea></form>')(scope);
25+
element = $compile('<form><textarea id="foo" ui-tinymce="{foo: \'bar\'}" ng-model="foo"></textarea></form>')(scope);
2626
});
2727
waits(1);
2828
}
2929

3030
describe('compiling this directive', function () {
3131

3232
it('should include the passed options', function () {
33-
spyOn($.fn, 'tinymce');
33+
spyOn(tinymce, 'init');
3434
compile();
3535
runs(function () {
36-
expect($.fn.tinymce).toHaveBeenCalled();
37-
expect($.fn.tinymce.mostRecentCall.args[0].foo).toEqual('bar');
36+
expect(tinymce.init).toHaveBeenCalled();
37+
expect(tinymce.init.mostRecentCall.args[0].foo).toEqual('bar');
3838
});
3939
});
4040

4141
it('should include the default options', function () {
42-
spyOn($.fn, 'tinymce');
42+
spyOn(tinymce, 'init');
4343
compile();
4444
runs(function () {
45-
expect($.fn.tinymce).toHaveBeenCalled();
46-
expect($.fn.tinymce.mostRecentCall.args[0].bar).toEqual('baz');
45+
expect(tinymce.init).toHaveBeenCalled();
46+
expect(tinymce.init.mostRecentCall.args[0].bar).toEqual('baz');
4747
});
4848
});
4949
});

0 commit comments

Comments
 (0)