|
1 | 1 | (function ($) { |
2 | | - $.fn.codemirror = function () { |
| 2 | + $.fn.codemirrorInit = function () { |
3 | 3 |
|
4 | 4 | $(this).init.prototype = $.extend({}, $(this).init.prototype, { |
5 | 5 |
|
6 | | - setValue: function (value) { |
7 | | - for (var i = 0; i < this.length; i++) { |
8 | | - $.data(this[i], 'codemirror').setValue(value); |
9 | | - } |
10 | | - }, |
11 | | - getValue: function () { |
12 | | - if (this.length > 1) { |
13 | | - throw new Error("Only one DOM element can be selected"); |
14 | | - } |
15 | | - return $.data(this[0], 'codemirror').getValue(); |
16 | | - }, |
17 | | - setOption: function (key, value) { |
18 | | - for (var i = 0; i < this.length; i++) { |
19 | | - $.data(this[i], 'codemirror').setOption(key, value); |
20 | | - } |
21 | | - }, |
22 | | - setOptions: function (optionsObject) { |
23 | | - for (var i = 0; i < this.length; i++) { |
24 | | - var $this = this[i]; |
25 | | - $.each(optionsObject, function (key, value) { |
26 | | - $.data($this, 'codemirror').setOption(key, value); |
27 | | - }); |
28 | | - } |
| 6 | + codemirror: function(){ |
| 7 | + var $this = this; |
| 8 | + return { |
| 9 | + setValue: function (value) { |
| 10 | + for (var i = 0; i < $this.length; i++) { |
| 11 | + $.data($this[i], 'codemirror').setValue(value); |
| 12 | + } |
| 13 | + }, |
| 14 | + getValue: function () { |
| 15 | + if (this.length > 1) { |
| 16 | + throw new Error("Only one DOM element can be selected"); |
| 17 | + } |
| 18 | + return $.data($this[0], 'codemirror').getValue(); |
| 19 | + }, |
| 20 | + setOption: function (key, value) { |
| 21 | + for (var i = 0; i < $this.length; i++) { |
| 22 | + $.data($this[i], 'codemirror').setOption(key, value); |
| 23 | + } |
| 24 | + }, |
| 25 | + setOptions: function (optionsObject) { |
| 26 | + for (var i = 0; i < this.length; i++) { |
| 27 | + var element = $this[i]; |
| 28 | + $.each(optionsObject, function (key, value) { |
| 29 | + $.data(element, 'codemirror').setOption(key, value); |
| 30 | + }); |
| 31 | + } |
| 32 | + } |
| 33 | + } |
29 | 34 | } |
30 | | - |
31 | 35 | }); |
32 | 36 |
|
33 | 37 | return this.each(function () { |
|
0 commit comments