jhtmlarea 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e1279607fe08d4f1a29b6e29818f5a03adfc98f
4
- data.tar.gz: e2e68165f32c2c997979383b72fa1bc002bf533c
3
+ metadata.gz: 536e0c99eec093a2cccfddf5c0d13dacfc4be81e
4
+ data.tar.gz: 417d430346ffa49a2dd1cf4f1aca797b62df079c
5
5
  SHA512:
6
- metadata.gz: 67079ac2e2cfec53ca73d61006978aaa54a5d97fe3050253a7205e7e95e4872f5d4317af60ca39aa8ac72701a772a2a2ddc90fe6ab7f8ba8fa81ce3d1fe79f0f
7
- data.tar.gz: 318d4e146276601a989a2e03c142e76badc6ca631f9082b4840c3490304edce5f3d8ee6e921e7b2f043464764234dad14bbb953aa949d100916c6326ca9f7a97
6
+ metadata.gz: f0a8259070d831c0163f3c4cfd037c17d67387902d9f5c9aceafc7ee47a2dd8d4d1beaedc422ed79467646a69231b3d56eb4d9ed7c1f5ab4809e21eb13239d5d
7
+ data.tar.gz: c5451dbe2efc2b1bbf01458f15f353710e007fd2d0cc8161737a38a9452875fed5373189c0ab902e7f5d27e890348c38631b70f057a4bef1b17032cdc76a3064
data/README.md CHANGED
@@ -20,7 +20,6 @@ Or install it yourself as:
20
20
 
21
21
  Add the following to app/assets/javascripts/application.js:
22
22
 
23
- //= require browserDetect
24
23
  //= require jHtmlArea-0.7.5
25
24
  //= require jHtmlArea.ColorPickerMenu-0.7.0
26
25
 
@@ -61,10 +60,6 @@ Then add this code to the view with your form (you can edit out any buttons you
61
60
  </script>
62
61
  ~~~
63
62
 
64
- ## Notes
65
-
66
- The original jHtmlArea 0.7.5 source caused errors in Rails 4 since it calls the `$.browser` function which is [no longer supported in jQuery 1.9](http://stackoverflow.com/questions/14524289/browser-is-undefined-error). [jQuery recommends](http://jquery.com/upgrade-guide/1.9/#jquery-browser-removed) using a library such as [Modernizer](http://modernizr.com/) for feature detection, but I have not been able to use modernizer to address the browser incompatibilities handled with $.browser() in the original javascript. These issues could be dealt with by including jquery-migrate, but instead I have included a simple browser detection script and modified the original javascript accordingly.
67
-
68
63
  ## Contributing
69
64
 
70
65
  1. Fork it
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- # borrowed from jquery-datatables-rails
3
+ # borrowed and adapted from jquery-datatables-rails
4
4
  desc "Fixes css image paths in scss files."
5
5
  task :fix_css do
6
- Dir.glob(File.join("vendor/assets/stylesheets/dataTables", "*.css.scss")).each do |filename|
6
+ Dir.glob(File.join("vendor/assets/stylesheets/", "*.css.scss")).each do |filename|
7
7
  content = File.read(filename)
8
- content.gsub!(/url\('\.\.\/images\/([A-Za-z0-9_]*\.png)'\)/) do
9
- "image-url('dataTables/#{$1}')"
8
+ content.gsub!(/url\(([A-Za-z0-9_]*\.png)\)/) do
9
+ "image-url('#{$1}')"
10
10
  end
11
11
  File.open(filename, 'w') { |f| f << content }
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Jhtmlarea
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,455 +1,443 @@
1
- /*
2
- * jHtmlArea 0.7.5 - WYSIWYG Html Editor jQuery Plugin
3
- * Copyright (c) 2012 Chris Pietschmann
4
- * http://jhtmlarea.codeplex.com
5
- * Licensed under the Microsoft Reciprocal License (Ms-RL)
6
- * http://jhtmlarea.codeplex.com/license
7
-
8
- * Modified by Dow Drake to use browserDetect.js for jQuery 1.9+ compatibility
9
- */
10
- (function ($) {
11
- $.fn.htmlarea = function (opts) {
12
- if (opts && typeof (opts) === "string") {
13
- var args = [];
14
- for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); }
15
- var htmlarea = jHtmlArea(this[0]);
16
- var f = htmlarea[opts];
17
- if (f) { return f.apply(htmlarea, args); }
18
- }
19
- return this.each(function () { jHtmlArea(this, opts); });
20
- };
21
- var jHtmlArea = window.jHtmlArea = function (elem, options) {
22
- if (elem.jquery) {
23
- return jHtmlArea(elem[0]);
24
- }
25
- if (elem.jhtmlareaObject) {
26
- return elem.jhtmlareaObject;
27
- } else {
28
- return new jHtmlArea.fn.init(elem, options);
29
- }
30
- };
31
- jHtmlArea.fn = jHtmlArea.prototype = {
32
-
33
- // The current version of jHtmlArea being used
34
- jhtmlarea: "0.7.5",
35
-
36
- init: function (elem, options) {
37
- if (elem.nodeName.toLowerCase() === "textarea") {
38
- var opts = $.extend({}, jHtmlArea.defaultOptions, options);
39
- elem.jhtmlareaObject = this;
40
-
41
- var textarea = this.textarea = $(elem);
42
- var container = this.container = $("<div/>").addClass("jHtmlArea").width(textarea.width()).insertAfter(textarea);
43
-
44
- var toolbar = this.toolbar = $("<div/>").addClass("ToolBar").appendTo(container);
45
- priv.initToolBar.call(this, opts);
46
-
47
- var iframe = this.iframe = $("<iframe/>").height(textarea.height());
48
- // jQuery.browser is deprecated
49
- //iframe.width(textarea.width() - ($.browser.msie ? 0 : 4));
50
- iframe.width(textarea.width() - (BrowserDetect.browser === "Explorer" ? 0 : 4));
51
- var htmlarea = this.htmlarea = $("<div/>").append(iframe);
52
-
53
- container.append(htmlarea).append(textarea.hide());
54
-
55
- priv.initEditor.call(this, opts);
56
- priv.attachEditorEvents.call(this);
57
-
58
- // Fix total height to match TextArea
59
- iframe.height(iframe.height() - toolbar.height());
60
- toolbar.width(textarea.width() - 2);
61
-
62
- if (opts.loaded) { opts.loaded.call(this); }
63
- }
64
- },
65
- dispose: function () {
66
- this.textarea.show().insertAfter(this.container);
67
- this.container.remove();
68
- this.textarea[0].jhtmlareaObject = null;
69
- },
70
- execCommand: function (a, b, c) {
71
- this.iframe[0].contentWindow.focus();
72
- this.editor.execCommand(a, b || false, c || null);
73
- this.updateTextArea();
74
- },
75
- ec: function (a, b, c) {
76
- this.execCommand(a, b, c);
77
- },
78
- queryCommandValue: function (a) {
79
- this.iframe[0].contentWindow.focus();
80
- return this.editor.queryCommandValue(a);
81
- },
82
- qc: function (a) {
83
- return this.queryCommandValue(a);
84
- },
85
- getSelectedHTML: function () {
86
- // if ($.browser.msie) {
87
- // return this.getRange().htmlText;
88
- // } else {
89
- // var elem = this.getRange().cloneContents();
90
- // return $("<p/>").append($(elem)).html();
91
- // }
92
- if (BrowserDetect.browser === "Explorer") {
93
- return this.getRange().htmlText;
94
- } else {
95
- var elem = this.getRange().cloneContents();
96
- return $("<p/>").append($(elem)).html();
97
- }
98
-
99
- },
100
- getSelection: function () {
101
- // if ($.browser.msie) {
102
- // //return (this.editor.parentWindow.getSelection) ? this.editor.parentWindow.getSelection() : this.editor.selection;
103
- // return this.editor.selection;
104
- // } else {
105
- // return this.iframe[0].contentDocument.defaultView.getSelection();
106
- // }
107
- if (BrowserDetect.browser === "Explorer") {
108
- //return (this.editor.parentWindow.getSelection) ? this.editor.parentWindow.getSelection() : this.editor.selection;
109
- return this.editor.selection;
110
- } else {
111
- return this.iframe[0].contentDocument.defaultView.getSelection();
112
- }
113
- },
114
- getRange: function () {
115
- var s = this.getSelection();
116
- if (!s) { return null; }
117
- //return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange();
118
- return (s.getRangeAt) ? s.getRangeAt(0) : s.createRange();
119
- },
120
- html: function (v) {
121
- if (v) {
122
- this.textarea.val(v);
123
- this.updateHtmlArea();
124
- } else {
125
- return this.toHtmlString();
126
- }
127
- },
128
- pasteHTML: function (html) {
129
- this.iframe[0].contentWindow.focus();
130
- var r = this.getRange();
131
- // if ($.browser.msie) {
132
- // r.pasteHTML(html);
133
- // } else if ($.browser.mozilla) {
134
- // r.deleteContents();
135
- // r.insertNode($((html.indexOf("<") != 0) ? $("<span/>").append(html) : html)[0]);
136
- // } else { // Safari
137
- // r.deleteContents();
138
- // r.insertNode($(this.iframe[0].contentWindow.document.createElement("span")).append($((html.indexOf("<") != 0) ? "<span>" + html + "</span>" : html))[0]);
139
- // }
140
- if (BrowserDetect.browser === "Explorer") {
141
- r.pasteHTML(html);
142
- } else if (BrowserDetect.browser === "Firefox" || BrowserDetect.browser === "Mozilla") {
143
- r.deleteContents();
144
- r.insertNode($((html.indexOf("<") != 0) ? $("<span/>").append(html) : html)[0]);
145
- } else { // Safari
146
- r.deleteContents();
147
- r.insertNode($(this.iframe[0].contentWindow.document.createElement("span")).append($((html.indexOf("<") != 0) ? "<span>" + html + "</span>" : html))[0]);
148
- }
149
- r.collapse(false);
150
- r.select();
151
- },
152
- cut: function () {
153
- this.ec("cut");
154
- },
155
- copy: function () {
156
- this.ec("copy");
157
- },
158
- paste: function () {
159
- this.ec("paste");
160
- },
161
- bold: function () { this.ec("bold"); },
162
- italic: function () { this.ec("italic"); },
163
- underline: function () { this.ec("underline"); },
164
- strikeThrough: function () { this.ec("strikethrough"); },
165
- image: function (url) {
166
- // if ($.browser.msie && !url) {
167
- // this.ec("insertImage", true);
168
- // } else {
169
- // this.ec("insertImage", false, (url || prompt("Image URL:", "http://")));
170
- // }
171
- if (BrowserDetect.browser === "Explorer" && !url) {
172
- this.ec("insertImage", true);
173
- } else {
174
- this.ec("insertImage", false, (url || prompt("Image URL:", "http://")));
175
- }
176
- },
177
- removeFormat: function () {
178
- this.ec("removeFormat", false, []);
179
- this.unlink();
180
- },
181
- link: function () {
182
- // if ($.browser.msie) {
183
- // this.ec("createLink", true);
184
- // } else {
185
- // this.ec("createLink", false, prompt("Link URL:", "http://"));
186
- // }
187
- if (BrowserDetect.browser === "Explorer") {
188
- this.ec("createLink", true);
189
- } else {
190
- this.ec("createLink", false, prompt("Link URL:", "http://"));
191
- }
192
- },
193
- unlink: function () { this.ec("unlink", false, []); },
194
- orderedList: function () { this.ec("insertorderedlist"); },
195
- unorderedList: function () { this.ec("insertunorderedlist"); },
196
- superscript: function () { this.ec("superscript"); },
197
- subscript: function () { this.ec("subscript"); },
198
-
199
- p: function () {
200
- this.formatBlock("<p>");
201
- },
202
- h1: function () {
203
- this.heading(1);
204
- },
205
- h2: function () {
206
- this.heading(2);
207
- },
208
- h3: function () {
209
- this.heading(3);
210
- },
211
- h4: function () {
212
- this.heading(4);
213
- },
214
- h5: function () {
215
- this.heading(5);
216
- },
217
- h6: function () {
218
- this.heading(6);
219
- },
220
- heading: function (h) {
221
- // this.formatBlock($.browser.msie ? "Heading " + h : "h" + h);
222
- this.formatBlock(BrowserDetect.browser === "Explorer" ? "Heading " + h : "h" + h);
223
- },
224
-
225
- indent: function () {
226
- this.ec("indent");
227
- },
228
- outdent: function () {
229
- this.ec("outdent");
230
- },
231
-
232
- insertHorizontalRule: function () {
233
- this.ec("insertHorizontalRule", false, "ht");
234
- },
235
-
236
- justifyLeft: function () {
237
- this.ec("justifyLeft");
238
- },
239
- justifyCenter: function () {
240
- this.ec("justifyCenter");
241
- },
242
- justifyRight: function () {
243
- this.ec("justifyRight");
244
- },
245
-
246
- increaseFontSize: function () {
247
- // if ($.browser.msie) {
248
- // this.ec("fontSize", false, this.qc("fontSize") + 1);
249
- // } else if ($.browser.safari) {
250
- // this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "larger")[0]);
251
- // } else {
252
- // this.ec("increaseFontSize", false, "big");
253
- // }
254
- if (BrowserDetect.browser === "Explorer") {
255
- this.ec("fontSize", false, this.qc("fontSize") + 1);
256
- } else if (BrowserDetect.browser === "Safari") {
257
- this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "larger")[0]);
258
- } else {
259
- this.ec("increaseFontSize", false, "big");
260
- }
261
- },
262
- decreaseFontSize: function () {
263
- // if ($.browser.msie) {
264
- // this.ec("fontSize", false, this.qc("fontSize") - 1);
265
- // } else if ($.browser.safari) {
266
- // this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "smaller")[0]);
267
- // } else {
268
- // this.ec("decreaseFontSize", false, "small");
269
- // }
270
- if (BrowserDetect.browser === "Explorer") {
271
- this.ec("fontSize", false, this.qc("fontSize") - 1);
272
- } else if (BrowserDetect.browser === "Safari") {
273
- this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "smaller")[0]);
274
- } else {
275
- this.ec("decreaseFontSize", false, "small");
276
- }
277
- },
278
-
279
- forecolor: function (c) {
280
- this.ec("foreColor", false, c || prompt("Enter HTML Color:", "#"));
281
- },
282
-
283
- formatBlock: function (v) {
284
- this.ec("formatblock", false, v || null);
285
- },
286
-
287
- showHTMLView: function () {
288
- this.updateTextArea();
289
- this.textarea.show();
290
- this.htmlarea.hide();
291
- $("ul li:not(li:has(a.html))", this.toolbar).hide();
292
- $("ul:not(:has(:visible))", this.toolbar).hide();
293
- $("ul li a.html", this.toolbar).addClass("highlighted");
294
- },
295
- hideHTMLView: function () {
296
- this.updateHtmlArea();
297
- this.textarea.hide();
298
- this.htmlarea.show();
299
- $("ul", this.toolbar).show();
300
- $("ul li", this.toolbar).show().find("a.html").removeClass("highlighted");
301
- },
302
- toggleHTMLView: function () {
303
- (this.textarea.is(":hidden")) ? this.showHTMLView() : this.hideHTMLView();
304
- },
305
-
306
- toHtmlString: function () {
307
- return this.editor.body.innerHTML;
308
- },
309
- toString: function () {
310
- return this.editor.body.innerText;
311
- },
312
-
313
- updateTextArea: function () {
314
- this.textarea.val(this.toHtmlString());
315
- },
316
- updateHtmlArea: function () {
317
- this.editor.body.innerHTML = this.textarea.val();
318
- }
319
- };
320
- jHtmlArea.fn.init.prototype = jHtmlArea.fn;
321
-
322
- jHtmlArea.defaultOptions = {
323
- toolbar: [
324
- ["html"], ["bold", "italic", "underline", "strikethrough", "|", "subscript", "superscript"],
325
- ["increasefontsize", "decreasefontsize"],
326
- ["orderedlist", "unorderedlist"],
327
- ["indent", "outdent"],
328
- ["justifyleft", "justifycenter", "justifyright"],
329
- ["link", "unlink", "image", "horizontalrule"],
330
- ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
331
- ["cut", "copy", "paste"]
332
- ],
333
- css: null,
334
- toolbarText: {
335
- bold: "Bold", italic: "Italic", underline: "Underline", strikethrough: "Strike-Through",
336
- cut: "Cut", copy: "Copy", paste: "Paste",
337
- h1: "Heading 1", h2: "Heading 2", h3: "Heading 3", h4: "Heading 4", h5: "Heading 5", h6: "Heading 6", p: "Paragraph",
338
- indent: "Indent", outdent: "Outdent", horizontalrule: "Insert Horizontal Rule",
339
- justifyleft: "Left Justify", justifycenter: "Center Justify", justifyright: "Right Justify",
340
- increasefontsize: "Increase Font Size", decreasefontsize: "Decrease Font Size", forecolor: "Text Color",
341
- link: "Insert Link", unlink: "Remove Link", image: "Insert Image",
342
- orderedlist: "Insert Ordered List", unorderedlist: "Insert Unordered List",
343
- subscript: "Subscript", superscript: "Superscript",
344
- html: "Show/Hide HTML Source View"
345
- }
346
- };
347
- var priv = {
348
- toolbarButtons: {
349
- strikethrough: "strikeThrough", orderedlist: "orderedList", unorderedlist: "unorderedList",
350
- horizontalrule: "insertHorizontalRule",
351
- justifyleft: "justifyLeft", justifycenter: "justifyCenter", justifyright: "justifyRight",
352
- increasefontsize: "increaseFontSize", decreasefontsize: "decreaseFontSize",
353
- html: function (btn) {
354
- this.toggleHTMLView();
355
- }
356
- },
357
- initEditor: function (options) {
358
- var edit = this.editor = this.iframe[0].contentWindow.document;
359
- edit.designMode = 'on';
360
- edit.open();
361
- edit.write(this.textarea.val());
362
- edit.close();
363
- if (options.css) {
364
- var e = edit.createElement('link'); e.rel = 'stylesheet'; e.type = 'text/css'; e.href = options.css; edit.getElementsByTagName('head')[0].appendChild(e);
365
- }
366
- },
367
- initToolBar: function (options) {
368
- var that = this;
369
-
370
- var menuItem = function (className, altText, action) {
371
- return $("<li/>").append($("<a href='javascript:void(0);'/>").addClass(className).attr("title", altText).click(function () { action.call(that, $(this)); }));
372
- };
373
-
374
- function addButtons(arr) {
375
- var ul = $("<ul/>").appendTo(that.toolbar);
376
- for (var i = 0; i < arr.length; i++) {
377
- var e = arr[i];
378
- if ((typeof (e)).toLowerCase() === "string") {
379
- if (e === "|") {
380
- ul.append($('<li class="separator"/>'));
381
- } else {
382
- var f = (function (e) {
383
- // If button name exists in priv.toolbarButtons then call the "method" defined there, otherwise call the method with the same name
384
- var m = priv.toolbarButtons[e] || e;
385
- if ((typeof (m)).toLowerCase() === "function") {
386
- return function (btn) { m.call(this, btn); };
387
- } else {
388
- return function () { this[m](); this.editor.body.focus(); };
389
- }
390
- })(e.toLowerCase());
391
- var t = options.toolbarText[e.toLowerCase()];
392
- ul.append(menuItem(e.toLowerCase(), t || e, f));
393
- }
394
- } else {
395
- ul.append(menuItem(e.css, e.text, e.action));
396
- }
397
- }
398
- };
399
- if (options.toolbar.length !== 0 && priv.isArray(options.toolbar[0])) {
400
- for (var i = 0; i < options.toolbar.length; i++) {
401
- addButtons(options.toolbar[i]);
402
- }
403
- } else {
404
- addButtons(options.toolbar);
405
- }
406
- },
407
- attachEditorEvents: function () {
408
- var t = this;
409
-
410
- var fnHA = function () {
411
- t.updateHtmlArea();
412
- };
413
-
414
- this.textarea.click(fnHA).
415
- keyup(fnHA).
416
- keydown(fnHA).
417
- mousedown(fnHA).
418
- blur(fnHA);
419
-
420
-
421
-
422
- var fnTA = function () {
423
- t.updateTextArea();
424
- };
425
-
426
- $(this.editor.body).click(fnTA).
427
- keyup(fnTA).
428
- keydown(fnTA).
429
- mousedown(fnTA).
430
- blur(fnTA);
431
-
432
- $('form').submit(function () { t.toggleHTMLView(); t.toggleHTMLView(); });
433
- //$(this.textarea[0].form).submit(function() { //this.textarea.closest("form").submit(function() {
434
-
435
-
436
- // Fix for ASP.NET Postback Model
437
- if (window.__doPostBack) {
438
- var old__doPostBack = __doPostBack;
439
- window.__doPostBack = function () {
440
- if (t) {
441
- if (t.toggleHTMLView) {
442
- t.toggleHTMLView();
443
- t.toggleHTMLView();
444
- }
445
- }
446
- return old__doPostBack.apply(window, arguments);
447
- };
448
- }
449
-
450
- },
451
- isArray: function (v) {
452
- return v && typeof v === 'object' && typeof v.length === 'number' && typeof v.splice === 'function' && !(v.propertyIsEnumerable('length'));
453
- }
454
- };
455
- })(jQuery);
1
+ /*
2
+ * jHtmlArea 0.8 - WYSIWYG Html Editor jQuery Plugin
3
+ * Copyright (c) 2013 Chris Pietschmann
4
+ * http://jhtmlarea.codeplex.com
5
+ * Licensed under the Microsoft Reciprocal License (Ms-RL)
6
+ * http://jhtmlarea.codeplex.com/license
7
+ */
8
+ (function ($, window) {
9
+
10
+ var $jhtmlarea = window.$jhtmlarea = {};
11
+ var $browser = $jhtmlarea.browser = {};
12
+ (function () {
13
+ $browser.msie = false;
14
+ $browser.mozilla = false;
15
+ $browser.safari = false;
16
+ $browser.version = 0;
17
+
18
+ if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
19
+ $browser.msie = true;
20
+ $browser.version = parseFloat(RegExp.$1);
21
+ } else if (navigator.userAgent.match(/Trident\/([0-9]+)\./)) {
22
+ $browser.msie = true;
23
+ $browser.version = RegExp.$1;
24
+ if (navigator.userAgent.match(/rv:([0-9]+)\./)) {
25
+ $browser.version = parseFloat(RegExp.$1);
26
+ }
27
+ }
28
+ if (navigator.userAgent.match(/Mozilla\/([0-9]+)\./)) {
29
+ $browser.mozilla = true;
30
+ if ($browser.version === 0) {
31
+ $browser.version = parseFloat(RegExp.$1);
32
+ }
33
+ }
34
+ if (navigator.userAgent.match(/Safari ([0-9]+)\./)) {
35
+ $browser.safari = true;
36
+ $browser.version = RegExp.$1;
37
+ if (navigator.userAgent.match(/Version\/([0-9]+)\./)) {
38
+ if ($browser.version === 0) {
39
+ $browser.version = parseFloat(RegExp.$1);
40
+ }
41
+ }
42
+ }
43
+ })();
44
+
45
+ $.fn.htmlarea = function (opts) {
46
+ if (opts && typeof (opts) === "string") {
47
+ var args = [];
48
+ for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); }
49
+ var htmlarea = jHtmlArea(this[0]);
50
+ var f = htmlarea[opts];
51
+ if (f) { return f.apply(htmlarea, args); }
52
+ }
53
+ return this.each(function () { jHtmlArea(this, opts); });
54
+ };
55
+ var jHtmlArea = window.jHtmlArea = function (elem, options) {
56
+ if (elem.jquery) {
57
+ return jHtmlArea(elem[0]);
58
+ }
59
+ if (elem.jhtmlareaObject) {
60
+ return elem.jhtmlareaObject;
61
+ } else {
62
+ return new jHtmlArea.fn.init(elem, options);
63
+ }
64
+ };
65
+ jHtmlArea.fn = jHtmlArea.prototype = {
66
+
67
+ // The current version of jHtmlArea being used
68
+ jhtmlarea: "0.8",
69
+
70
+ init: function (elem, options) {
71
+ if (elem.nodeName.toLowerCase() === "textarea") {
72
+ var opts = $.extend({}, jHtmlArea.defaultOptions, options);
73
+ elem.jhtmlareaObject = this;
74
+
75
+ var textarea = this.textarea = $(elem);
76
+ var container = this.container = $("<div/>").addClass("jHtmlArea").width(textarea.width()).insertAfter(textarea);
77
+
78
+ var toolbar = this.toolbar = $("<div/>").addClass("ToolBar").appendTo(container);
79
+ priv.initToolBar.call(this, opts);
80
+
81
+ var iframe = this.iframe = $("<iframe/>").height(textarea.height());
82
+ iframe.width(textarea.width());
83
+
84
+ var htmlarea = this.htmlarea = $("<div/>").append(iframe);
85
+
86
+ container.append(htmlarea).append(textarea.hide());
87
+
88
+ priv.initEditor.call(this, opts);
89
+ priv.attachEditorEvents.call(this);
90
+
91
+ // Fix total height to match TextArea
92
+ iframe.height(iframe.height() - toolbar.height());
93
+ toolbar.width(textarea.width());
94
+
95
+
96
+ if (opts.loaded) { opts.loaded.call(this); }
97
+ }
98
+ },
99
+ dispose: function () {
100
+ this.textarea.show().insertAfter(this.container);
101
+ this.container.remove();
102
+ this.textarea[0].jhtmlareaObject = null;
103
+ },
104
+ execCommand: function (a, b, c) {
105
+ this.iframe[0].contentWindow.focus();
106
+ this.editor.execCommand(a, b || false, c || null);
107
+ this.updateTextArea();
108
+ },
109
+ ec: function (a, b, c) {
110
+ this.execCommand(a, b, c);
111
+ },
112
+ queryCommandValue: function (a) {
113
+ this.iframe[0].contentWindow.focus();
114
+ return this.editor.queryCommandValue(a);
115
+ },
116
+ qc: function (a) {
117
+ return this.queryCommandValue(a);
118
+ },
119
+ getSelectedHTML: function () {
120
+ if ($browser.msie) {
121
+ return this.getRange().htmlText;
122
+ } else {
123
+ var elem = this.getRange().cloneContents();
124
+ return $("<p/>").append($(elem)).html();
125
+ }
126
+ },
127
+ getSelection: function () {
128
+ if ($browser.msie === true && $browser.version < 11) {
129
+ //return (this.editor.parentWindow.getSelection) ? this.editor.parentWindow.getSelection() : this.editor.selection;
130
+ return this.editor.selection;
131
+ } else {
132
+ return this.iframe[0].contentDocument.defaultView.getSelection();
133
+ }
134
+ },
135
+ getRange: function () {
136
+ var s = this.getSelection();
137
+ if (!s) { return null; }
138
+ //return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange();
139
+ return (s.getRangeAt) ? s.getRangeAt(0) : s.createRange();
140
+ },
141
+ html: function (v) {
142
+ if (v !== undefined) {
143
+ this.textarea.val(v);
144
+ this.updateHtmlArea();
145
+ } else {
146
+ return this.toHtmlString();
147
+ }
148
+ },
149
+ pasteHTML: function (html) {
150
+ this.iframe[0].contentWindow.focus();
151
+ var r = this.getRange();
152
+ if ($browser.msie) {
153
+ r.pasteHTML(html);
154
+ } else if ($browser.mozilla) {
155
+ r.deleteContents();
156
+ r.insertNode($((html.indexOf("<") != 0) ? $("<span/>").append(html) : html)[0]);
157
+ } else { // Safari
158
+ r.deleteContents();
159
+ r.insertNode($(this.iframe[0].contentWindow.document.createElement("span")).append($((html.indexOf("<") != 0) ? "<span>" + html + "</span>" : html))[0]);
160
+ }
161
+ r.collapse(false);
162
+ r.select();
163
+ },
164
+ cut: function () {
165
+ this.ec("cut");
166
+ },
167
+ copy: function () {
168
+ this.ec("copy");
169
+ },
170
+ paste: function () {
171
+ this.ec("paste");
172
+ },
173
+ bold: function () { this.ec("bold"); },
174
+ italic: function () { this.ec("italic"); },
175
+ underline: function () { this.ec("underline"); },
176
+ strikeThrough: function () { this.ec("strikethrough"); },
177
+ image: function (url) {
178
+ if ($browser.msie === true && !url) {
179
+ this.ec("insertImage", true);
180
+ } else {
181
+ this.ec("insertImage", false, (url || prompt("Image URL:", "http://")));
182
+ }
183
+ },
184
+ removeFormat: function () {
185
+ this.ec("removeFormat", false, []);
186
+ this.unlink();
187
+ },
188
+ link: function () {
189
+ if ($browser.msie === true) {
190
+ this.ec("createLink", true);
191
+ } else {
192
+ this.ec("createLink", false, prompt("Link URL:", "http://"));
193
+ }
194
+ },
195
+ unlink: function () { this.ec("unlink", false, []); },
196
+ orderedList: function () { this.ec("insertorderedlist"); },
197
+ unorderedList: function () { this.ec("insertunorderedlist"); },
198
+ superscript: function () { this.ec("superscript"); },
199
+ subscript: function () { this.ec("subscript"); },
200
+
201
+ p: function () {
202
+ this.formatBlock("<p>");
203
+ },
204
+ h1: function () {
205
+ this.heading(1);
206
+ },
207
+ h2: function () {
208
+ this.heading(2);
209
+ },
210
+ h3: function () {
211
+ this.heading(3);
212
+ },
213
+ h4: function () {
214
+ this.heading(4);
215
+ },
216
+ h5: function () {
217
+ this.heading(5);
218
+ },
219
+ h6: function () {
220
+ this.heading(6);
221
+ },
222
+ heading: function (h) {
223
+ this.formatBlock($browser.msie === true ? "Heading " + h : "h" + h);
224
+ },
225
+
226
+ indent: function () {
227
+ this.ec("indent");
228
+ },
229
+ outdent: function () {
230
+ this.ec("outdent");
231
+ },
232
+
233
+ insertHorizontalRule: function () {
234
+ this.ec("insertHorizontalRule", false, "ht");
235
+ },
236
+
237
+ justifyLeft: function () {
238
+ this.ec("justifyLeft");
239
+ },
240
+ justifyCenter: function () {
241
+ this.ec("justifyCenter");
242
+ },
243
+ justifyRight: function () {
244
+ this.ec("justifyRight");
245
+ },
246
+
247
+ increaseFontSize: function () {
248
+ if ($browser.msie === true) {
249
+ this.ec("fontSize", false, this.qc("fontSize") + 1);
250
+ } else if ($browser.safari) {
251
+ this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "larger")[0]);
252
+ } else {
253
+ this.ec("increaseFontSize", false, "big");
254
+ }
255
+ },
256
+ decreaseFontSize: function () {
257
+ if ($browser.msie === true) {
258
+ this.ec("fontSize", false, this.qc("fontSize") - 1);
259
+ } else if ($browser.safari) {
260
+ this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "smaller")[0]);
261
+ } else {
262
+ this.ec("decreaseFontSize", false, "small");
263
+ }
264
+ },
265
+
266
+ forecolor: function (c) {
267
+ this.ec("foreColor", false, c !== undefined ? c : prompt("Enter HTML Color:", "#"));
268
+ },
269
+
270
+ formatBlock: function (v) {
271
+ this.ec("formatblock", false, v || null);
272
+ },
273
+
274
+ showHTMLView: function () {
275
+ this.updateTextArea();
276
+ this.textarea.show();
277
+ this.htmlarea.hide();
278
+ $("ul li:not(li:has(a.html))", this.toolbar).hide();
279
+ $("ul:not(:has(:visible))", this.toolbar).hide();
280
+ $("ul li a.html", this.toolbar).addClass("highlighted");
281
+ },
282
+ hideHTMLView: function () {
283
+ this.updateHtmlArea();
284
+ this.textarea.hide();
285
+ this.htmlarea.show();
286
+ $("ul", this.toolbar).show();
287
+ $("ul li", this.toolbar).show().find("a.html").removeClass("highlighted");
288
+ },
289
+ toggleHTMLView: function () {
290
+ (this.textarea.is(":hidden")) ? this.showHTMLView() : this.hideHTMLView();
291
+ },
292
+
293
+ toHtmlString: function () {
294
+ return this.editor.body.innerHTML;
295
+ },
296
+ toString: function () {
297
+ return this.editor.body.innerText;
298
+ },
299
+
300
+ updateTextArea: function () {
301
+ this.textarea.val(this.toHtmlString());
302
+ },
303
+ updateHtmlArea: function () {
304
+ this.editor.body.innerHTML = this.textarea.val();
305
+ }
306
+ };
307
+ jHtmlArea.fn.init.prototype = jHtmlArea.fn;
308
+
309
+ jHtmlArea.defaultOptions = {
310
+ toolbar: [
311
+ ["html"], ["bold", "italic", "underline", "strikethrough", "|", "subscript", "superscript"],
312
+ ["increasefontsize", "decreasefontsize"],
313
+ ["orderedlist", "unorderedlist"],
314
+ ["indent", "outdent"],
315
+ ["justifyleft", "justifycenter", "justifyright"],
316
+ ["link", "unlink", "image", "horizontalrule"],
317
+ ["p", "h1", "h2", "h3", "h4", "h5", "h6"],
318
+ ["cut", "copy", "paste"]
319
+ ],
320
+ css: null,
321
+ toolbarText: {
322
+ bold: "Bold", italic: "Italic", underline: "Underline", strikethrough: "Strike-Through",
323
+ cut: "Cut", copy: "Copy", paste: "Paste",
324
+ h1: "Heading 1", h2: "Heading 2", h3: "Heading 3", h4: "Heading 4", h5: "Heading 5", h6: "Heading 6", p: "Paragraph",
325
+ indent: "Indent", outdent: "Outdent", horizontalrule: "Insert Horizontal Rule",
326
+ justifyleft: "Left Justify", justifycenter: "Center Justify", justifyright: "Right Justify",
327
+ increasefontsize: "Increase Font Size", decreasefontsize: "Decrease Font Size", forecolor: "Text Color",
328
+ link: "Insert Link", unlink: "Remove Link", image: "Insert Image",
329
+ orderedlist: "Insert Ordered List", unorderedlist: "Insert Unordered List",
330
+ subscript: "Subscript", superscript: "Superscript",
331
+ html: "Show/Hide HTML Source View"
332
+ }
333
+ };
334
+ var priv = {
335
+ toolbarButtons: {
336
+ strikethrough: "strikeThrough", orderedlist: "orderedList", unorderedlist: "unorderedList",
337
+ horizontalrule: "insertHorizontalRule",
338
+ justifyleft: "justifyLeft", justifycenter: "justifyCenter", justifyright: "justifyRight",
339
+ increasefontsize: "increaseFontSize", decreasefontsize: "decreaseFontSize",
340
+ html: function (btn) {
341
+ this.toggleHTMLView();
342
+ }
343
+ },
344
+ initEditor: function (options) {
345
+ var edit = this.editor = this.iframe[0].contentWindow.document;
346
+ edit.designMode = 'on';
347
+ edit.open();
348
+ edit.write(this.textarea.val());
349
+ edit.close();
350
+ if (options.css) {
351
+ var e = edit.createElement('link'); e.rel = 'stylesheet'; e.type = 'text/css'; e.href = options.css; edit.getElementsByTagName('head')[0].appendChild(e);
352
+ }
353
+ },
354
+ initToolBar: function (options) {
355
+ var that = this;
356
+
357
+ var menuItem = function (className, altText, action) {
358
+ return $("<li/>").append($("<a href='javascript:void(0);'/>").addClass(className).attr("title", altText).click(function () { action.call(that, $(this)); }));
359
+ };
360
+
361
+ function addButtons(arr) {
362
+ var ul = $("<ul/>").appendTo(that.toolbar);
363
+ for (var i = 0; i < arr.length; i++) {
364
+ var e = arr[i];
365
+ if ((typeof (e)).toLowerCase() === "string") {
366
+ if (e === "|") {
367
+ ul.append($('<li class="separator"/>'));
368
+ } else {
369
+ var f = (function (e) {
370
+ // If button name exists in priv.toolbarButtons then call the "method" defined there, otherwise call the method with the same name
371
+ var m = priv.toolbarButtons[e] || e;
372
+ if ((typeof (m)).toLowerCase() === "function") {
373
+ return function (btn) { m.call(this, btn); };
374
+ } else {
375
+ return function () { this[m](); this.editor.body.focus(); };
376
+ }
377
+ })(e.toLowerCase());
378
+ var t = options.toolbarText[e.toLowerCase()];
379
+ ul.append(menuItem(e.toLowerCase(), t || e, f));
380
+ }
381
+ } else {
382
+ ul.append(menuItem(e.css, e.text, e.action));
383
+ }
384
+ }
385
+ };
386
+ if (options.toolbar.length !== 0 && priv.isArray(options.toolbar[0])) {
387
+ for (var i = 0; i < options.toolbar.length; i++) {
388
+ addButtons(options.toolbar[i]);
389
+ }
390
+ } else {
391
+ addButtons(options.toolbar);
392
+ }
393
+ },
394
+ attachEditorEvents: function () {
395
+ var t = this;
396
+
397
+ var fnHA = function () {
398
+ t.updateHtmlArea();
399
+ };
400
+
401
+ this.textarea.click(fnHA).
402
+ keyup(fnHA).
403
+ keydown(fnHA).
404
+ mousedown(fnHA).
405
+ blur(fnHA);
406
+
407
+
408
+
409
+ var fnTA = function () {
410
+ t.updateTextArea();
411
+ };
412
+
413
+ $(this.editor.body).click(fnTA).
414
+ keyup(fnTA).
415
+ keydown(fnTA).
416
+ mousedown(fnTA).
417
+ blur(fnTA);
418
+
419
+ $('form').submit(function () { t.toggleHTMLView(); t.toggleHTMLView(); });
420
+ //$(this.textarea[0].form).submit(function() { //this.textarea.closest("form").submit(function() {
421
+
422
+
423
+ // Fix for ASP.NET Postback Model
424
+ if (window.__doPostBack) {
425
+ var old__doPostBack = __doPostBack;
426
+ window.__doPostBack = function () {
427
+ if (t) {
428
+ if (t.toggleHTMLView) {
429
+ t.toggleHTMLView();
430
+ t.toggleHTMLView();
431
+ }
432
+ }
433
+ return old__doPostBack.apply(window, arguments);
434
+ };
435
+ }
436
+
437
+ },
438
+ isArray: function (v) {
439
+ return v && typeof v === 'object' && typeof v.length === 'number' && typeof v.splice === 'function' && !(v.propertyIsEnumerable('length'));
440
+ }
441
+ };
442
+ })(jQuery, window);
443
+