summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/tinymce
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-ui/modules/directives/tinymce')
-rw-r--r--js/vendor/angular-ui/modules/directives/tinymce/dependencies.json8
-rw-r--r--js/vendor/angular-ui/modules/directives/tinymce/test/tinymceSpec.js90
-rw-r--r--js/vendor/angular-ui/modules/directives/tinymce/tinymce.js53
3 files changed, 151 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/directives/tinymce/dependencies.json b/js/vendor/angular-ui/modules/directives/tinymce/dependencies.json
new file mode 100644
index 000000000..ebaa430e6
--- /dev/null
+++ b/js/vendor/angular-ui/modules/directives/tinymce/dependencies.json
@@ -0,0 +1,8 @@
+{
+ "core": [ "jquery" ],
+ "internal": [],
+ "external": [
+ "http://fiddle.tinymce.com/tinymce/3.5.8/tiny_mce_jquery_src.js",
+ "http://fiddle.tinymce.com/tinymce/3.5.8/jquery.tinymce.js",
+ ]
+} \ No newline at end of file
diff --git a/js/vendor/angular-ui/modules/directives/tinymce/test/tinymceSpec.js b/js/vendor/angular-ui/modules/directives/tinymce/test/tinymceSpec.js
new file mode 100644
index 000000000..d7c72921e
--- /dev/null
+++ b/js/vendor/angular-ui/modules/directives/tinymce/test/tinymceSpec.js
@@ -0,0 +1,90 @@
+/*global describe, beforeEach, module, inject, it, spyOn, expect, $, angular, afterEach, runs, waits */
+describe('uiTinymce', function () {
+ 'use strict';
+
+ var scope, $compile, element, text = '<p>Hello</p>';
+ beforeEach(module('ui'));
+ beforeEach(function () {
+ // throw some garbage in the tinymce cfg to be sure it's getting thru to the directive
+ angular.module('ui.config').value('ui.config', {tinymce: {bar: 'baz'}});
+ });
+ beforeEach(inject(function (_$rootScope_, _$compile_) {
+ scope = _$rootScope_.$new();
+ $compile = _$compile_;
+ }));
+
+ afterEach(function () {
+ angular.module('ui.config').value('ui.config', {}); // cleanup
+ });
+
+ /**
+ * Asynchronously runs the compilation.
+ */
+ function compile() {
+ runs(function () {
+ element = $compile('<form><textarea name="foo" ui-tinymce="{foo: \'bar\'}" ng-model="foo"></textarea></form>')(scope);
+ });
+ waits(1);
+ }
+
+ describe('compiling this directive', function () {
+
+ it('should include the passed options', function () {
+ spyOn($.fn, 'tinymce');
+ compile();
+ runs(function () {
+ expect($.fn.tinymce).toHaveBeenCalled();
+ expect($.fn.tinymce.mostRecentCall.args[0].foo).toEqual('bar');
+ });
+ });
+
+ it('should include the default options', function () {
+ spyOn($.fn, 'tinymce');
+ compile();
+ runs(function () {
+ expect($.fn.tinymce).toHaveBeenCalled();
+ expect($.fn.tinymce.mostRecentCall.args[0].bar).toEqual('baz');
+ });
+ });
+ });
+ /*
+ describe('setting a value to the model', function () {
+ it('should update the editor', function() {
+ compile();
+ runs(function () {
+ scope.$apply(function() {
+ scope.foo = text;
+ });
+ expect(element.find('textarea').tinymce().getContent()).toEqual(text);
+ });
+ });
+ it('should handle undefined gracefully', function() {
+ compile();
+ runs(function () {
+ scope.$apply(function() {
+ scope.foo = undefined;
+ });
+ expect(element.find('textarea').tinymce().getContent()).toEqual('');
+ });
+ });
+ it('should handle null gracefully', function() {
+ compile();
+ runs(function () {
+ scope.$apply(function() {
+ scope.foo = null;
+ });
+ expect(element.find('textarea').tinymce().getContent()).toEqual('');
+ });
+ });
+ });
+ describe('using the editor', function () {
+ it('should update the model', function() {
+ compile();
+ runs(function () {
+ element.find('textarea').tinymce().setContent(text);
+ expect($rootScope.x).toEqual(text);
+ });
+ });
+ });
+ */
+}); \ No newline at end of file
diff --git a/js/vendor/angular-ui/modules/directives/tinymce/tinymce.js b/js/vendor/angular-ui/modules/directives/tinymce/tinymce.js
new file mode 100644
index 000000000..a91f1ad34
--- /dev/null
+++ b/js/vendor/angular-ui/modules/directives/tinymce/tinymce.js
@@ -0,0 +1,53 @@
+/**
+ * Binds a TinyMCE widget to <textarea> elements.
+ */
+angular.module('ui.directives').directive('uiTinymce', ['ui.config', function (uiConfig) {
+ uiConfig.tinymce = uiConfig.tinymce || {};
+ return {
+ require: 'ngModel',
+ link: function (scope, elm, attrs, ngModel) {
+ var expression,
+ options = {
+ // Update model on button click
+ onchange_callback: function (inst) {
+ if (inst.isDirty()) {
+ inst.save();
+ ngModel.$setViewValue(elm.val());
+ if (!scope.$$phase)
+ scope.$apply();
+ }
+ },
+ // Update model on keypress
+ handle_event_callback: function (e) {
+ if (this.isDirty()) {
+ this.save();
+ ngModel.$setViewValue(elm.val());
+ if (!scope.$$phase)
+ scope.$apply();
+ }
+ return true; // Continue handling
+ },
+ // Update model when calling setContent (such as from the source editor popup)
+ setup: function (ed) {
+ ed.onSetContent.add(function (ed, o) {
+ if (ed.isDirty()) {
+ ed.save();
+ ngModel.$setViewValue(elm.val());
+ if (!scope.$$phase)
+ scope.$apply();
+ }
+ });
+ }
+ };
+ if (attrs.uiTinymce) {
+ expression = scope.$eval(attrs.uiTinymce);
+ } else {
+ expression = {};
+ }
+ angular.extend(options, uiConfig.tinymce, expression);
+ setTimeout(function () {
+ elm.tinymce(options);
+ });
+ }
+ };
+}]);