imperavi-rails 0.0.2.beta → 0.0.3.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/README.md +16 -4
  2. data/app/assets/javascripts/imperavi-rails/imperavi/dd_upload.js +100 -0
  3. data/app/assets/javascripts/imperavi-rails/imperavi/linkify.js +30 -0
  4. data/app/assets/javascripts/imperavi-rails/imperavi/redactor.js +104 -364
  5. data/app/assets/javascripts/imperavi-rails/imperavi/textselect.js +14 -0
  6. data/app/assets/javascripts/imperavi-rails/imperavi.js +4 -0
  7. data/app/helpers/imperavi_rails/imperavi_helper.rb +2 -2
  8. data/lib/imperavi-rails/version.rb +1 -1
  9. data/spec/dummy/app/assets/stylesheets/application.css.scss +1 -9
  10. data/spec/dummy/app/views/pages/index.html.erb +7 -17
  11. data/spec/dummy/db/development.sqlite3 +0 -0
  12. data/spec/dummy/log/development.log +1197 -0
  13. data/spec/dummy/public/system/dragonfly/development/2012/02/03/10_10_05_126_6.jpg +0 -0
  14. data/spec/dummy/public/system/dragonfly/development/2012/02/03/10_10_05_126_6.jpg.meta +4 -0
  15. data/spec/dummy/tmp/cache/assets/C41/5B0/sprockets%2F095415e1141a435237aa9464752d21fd +242 -0
  16. data/spec/dummy/tmp/cache/assets/CBE/FC0/sprockets%2Ff5431a64e341b062b7530132a5c1ea5a +1726 -0
  17. data/spec/dummy/tmp/cache/assets/CC0/310/sprockets%2Fb372e5f868e8a8801e126262f66c9c08 +16 -0
  18. data/spec/dummy/tmp/cache/assets/CC5/C10/sprockets%2F7c81f5c40dc9b87819488e127f487a04 +513 -0
  19. data/spec/dummy/tmp/cache/assets/CE5/650/sprockets%2F8ab512c9b33ac90e699b73469d71f061 +269 -0
  20. data/spec/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +81 -0
  21. data/spec/dummy/tmp/cache/assets/D02/F90/sprockets%2Ff029f33d65d53d13d3c0fd29e0c08133 +10 -0
  22. data/spec/dummy/tmp/cache/assets/D06/850/sprockets%2F9027c767fa3c09c1a605eae10b43d549 +9272 -0
  23. data/spec/dummy/tmp/cache/assets/D0C/0C0/sprockets%2F106b7f622fb804e4248c862abe73a4c8 +16 -0
  24. data/spec/dummy/{app/assets/stylesheets/scaffold.css → tmp/cache/assets/D11/D20/sprockets%2Fcac21eac42152981882bf9e489316af4} +6 -1
  25. data/spec/dummy/tmp/cache/assets/D24/8E0/sprockets%2F47f976dc55ebc7889e349067c9ba01b2 +16 -0
  26. data/spec/dummy/tmp/cache/assets/D2A/450/sprockets%2F58e369b37e5157ea746a485eea17e9f7 +28 -0
  27. data/spec/dummy/tmp/cache/assets/D34/D90/sprockets%2Fac3fb880b6bb140d16d5b4a6916e5067 +52 -0
  28. data/spec/dummy/tmp/cache/assets/D38/C80/sprockets%2Fb7152c93aa41253e9ed17d71a5c0eb88 +16 -0
  29. data/spec/dummy/tmp/cache/assets/D58/6D0/sprockets%2Fd2a3ab2b5401861dcd2e343ca6e4923e +37 -0
  30. data/spec/dummy/tmp/cache/assets/D59/260/sprockets%2Fd513a46ce8d83f003a733cb306dfe01a +1598 -0
  31. data/spec/dummy/tmp/cache/assets/D64/190/sprockets%2Ffdfa1bbf71247a2b9ef0b97732603e02 +0 -0
  32. data/spec/dummy/tmp/cache/assets/D6D/7C0/sprockets%2Fa4b9caa51f636e2b2db868c480e2a487 +8 -0
  33. data/spec/dummy/tmp/cache/assets/D73/170/sprockets%2Ffe70d93b5d3398dd8d0c6a3d701290ef +123 -0
  34. data/spec/dummy/tmp/cache/assets/D76/B30/sprockets%2Fce979145545abbfd4ca50fea3489554c +395 -0
  35. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +9655 -0
  36. data/spec/dummy/tmp/cache/assets/D9B/E30/sprockets%2Fd87c8ca46743542cace533cfe91ae1d0 +495 -0
  37. data/spec/dummy/tmp/cache/assets/DA2/EA0/sprockets%2F9e95d2e1a4da7fafb60b9b782a53b753 +378 -0
  38. data/spec/dummy/tmp/cache/assets/DA8/F60/sprockets%2Fbb2cd57d63160c94d622ef9d91ccef68 +16 -0
  39. data/spec/dummy/tmp/cache/assets/DAC/DC0/sprockets%2Fe8cdb03f780ff87851dd459dc844ad1b +246 -0
  40. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +61 -0
  41. data/spec/dummy/tmp/cache/assets/E05/F10/sprockets%2Fb3d9b0e88cdded276ebdce333e338a85 +30 -0
  42. data/spec/dummy/tmp/cache/assets/E22/CE0/sprockets%2F6fe70d27fda81ea53c8bdaeb1b112dd7 +9289 -0
  43. data/spec/dummy/tmp/cache/assets/E26/210/sprockets%2Fbb3accabff7037e93dc9a3373f4a5b7a +1580 -0
  44. data/spec/dummy/tmp/cache/assets/E66/AE0/sprockets%2Ffcb98ed9ac3e15f6d9e59fd00cbb2d3d +16 -0
  45. data/spec/dummy/tmp/cache/sass/9bd7199bacdbfc23c47b913698aa7195d1e0f382/application.css.scssc +0 -0
  46. data/spec/dummy/tmp/cache/sass/bc54e898614d486bf9338d646e8cd056915d4779/imperavi-base.css.scssc +0 -0
  47. data/spec/dummy/tmp/cache/sass/bc54e898614d486bf9338d646e8cd056915d4779/redactor.css.scssc +0 -0
  48. data/spec/dummy/tmp/cache/sass/bc54e898614d486bf9338d646e8cd056915d4779/wym.css.scssc +0 -0
  49. data/spec/dummy/tmp/dragonfly/cache/body/00/4aecc0c59254723e83737f8928702ffd7bb98b +373 -0
  50. data/spec/dummy/tmp/dragonfly/cache/body/16/c5ea89574eb557096b3fefd758954e84a34381 +0 -0
  51. data/spec/dummy/tmp/dragonfly/cache/body/21/199c9bdb6c7f65200a15ca0934612bcae4204c +242 -0
  52. data/spec/dummy/tmp/dragonfly/cache/body/42/bb515c02767a37104eca97f75df3b4a49e1759 +242 -0
  53. data/spec/dummy/tmp/dragonfly/cache/body/48/cf4eb3ec838cdab2af24f4603e7954ab5012ee +0 -0
  54. data/spec/dummy/tmp/dragonfly/cache/body/4a/72b5c050f6e3702f880e19fcf37793c135cd3d +0 -0
  55. data/spec/dummy/tmp/dragonfly/cache/body/61/e9711fd55eccdf62882cb8d127b22664f7023f +3 -0
  56. data/spec/dummy/tmp/dragonfly/cache/body/74/98c8a3bb6ee03af2b6952e797e632938d84649 +237 -0
  57. data/spec/dummy/tmp/dragonfly/cache/body/77/78d2df49ed1274a18f2c479b5747a91417458f +490 -0
  58. data/spec/dummy/tmp/dragonfly/cache/body/8e/46450213e0599dab4f0033c16b21731ca5e19c +242 -0
  59. data/spec/dummy/tmp/dragonfly/cache/body/a4/2e62d48de5370a8402707dd02fcf64039923b4 +0 -0
  60. data/spec/dummy/tmp/dragonfly/cache/body/a8/85ba08a1465f458ec2e999aecc73ba6b885520 +1575 -0
  61. data/spec/dummy/tmp/dragonfly/cache/body/ab/c30526420462e4081de3dcbc7598a7930bbc51 +0 -0
  62. data/spec/dummy/tmp/dragonfly/cache/body/b2/f1d81a83ca37d428780d1d9deb87cf0312cb62 +0 -0
  63. data/spec/dummy/tmp/dragonfly/cache/body/bb/cf048304dee182fc21ba43f408d8623c2f65b1 +1721 -0
  64. data/{app/assets/javascripts/imperavi-rails/application.js → spec/dummy/tmp/dragonfly/cache/body/c2/d1fe276d6e527c155855e99dc19d239b6d71f3} +1 -3
  65. data/spec/dummy/tmp/dragonfly/cache/body/d6/1d64e39570cd647cee3d3a62efa17ab2290d1e +0 -0
  66. data/spec/dummy/tmp/dragonfly/cache/body/ef/f130cc312268f0864d651bb53d4f83189b925a +9267 -0
  67. data/spec/dummy/tmp/dragonfly/cache/body/fb/54a1604f6c72b35d8b9c3da9f3899d77db70dd +1834 -0
  68. data/spec/dummy/tmp/dragonfly/cache/meta/1d/f723c27427056dd58a506f1e4f15020442098e +0 -0
  69. data/spec/dummy/tmp/dragonfly/cache/meta/23/4f7740cb6118c7c530ce379339a99828a75ef3 +0 -0
  70. data/spec/dummy/tmp/dragonfly/cache/meta/2d/fe381b58b48b16278672bd61db736e4e920955 +0 -0
  71. data/spec/dummy/tmp/dragonfly/cache/meta/39/b52b68255f54efe8cb853fd153088f94a7661a +0 -0
  72. data/spec/dummy/tmp/dragonfly/cache/meta/55/32c60f25996b8e8a9fdf7125956c5204fa8792 +0 -0
  73. data/spec/dummy/tmp/dragonfly/cache/meta/66/b6e26427e56a9f9ade00d4cf5d615679f0f7a7 +0 -0
  74. data/spec/dummy/tmp/dragonfly/cache/meta/66/f44aba1428593600ff0e47ea6aa54362e39a59 +0 -0
  75. data/spec/dummy/tmp/dragonfly/cache/meta/78/d74c0cd05a77c0c06acb622761d30c9ea00bb3 +0 -0
  76. data/spec/dummy/tmp/dragonfly/cache/meta/80/5841ac20acdd8dd41460c8346294abc5c4dd8f +0 -0
  77. data/spec/dummy/tmp/dragonfly/cache/meta/e7/6d1dc2d45d19440e781f6c5d00f39d8aeb4da1 +0 -0
  78. data/spec/dummy/tmp/dragonfly/cache/meta/ee/fe74949a8c2a0bbc077385a12944d9f98a12e0 +0 -0
  79. data/spec/dummy/tmp/dragonfly/cache/meta/ef/d71b44567b90c7f85e9bd0576e4b7e55bd3565 +0 -0
  80. data/spec/dummy/tmp/dragonfly/cache/meta/f4/2f71b4755920b57e574c91123765511a8f0b25 +0 -0
  81. data/spec/dummy/tmp/dragonfly/cache/meta/f5/b1288f6769945a2de532e359e061896e1197df +0 -0
  82. data/spec/dummy/tmp/dragonfly/cache/meta/f9/67ac04386c59253bd80f4034d18af166cc5691 +0 -0
  83. data/spec/dummy/tmp/pids/server.pid +1 -0
  84. metadata +260 -122
  85. data/app/assets/stylesheets/imperavi-rails/imperavi/imperavi.css.scss +0 -150
  86. data/spec/dummy/app/assets/stylesheets/pages.css +0 -4
  87. data/spec/dummy/db/test.sqlite3 +0 -0
@@ -0,0 +1,1575 @@
1
+ /*
2
+ Redactor v7.2.0
3
+ Updated 20.11.2011
4
+
5
+ In English http://imperavi.com/
6
+ In Russian http://imperavi.ru/
7
+
8
+ Copyright (c) 2009-2012, Imperavi Ltd.
9
+ Dual licensed under the MIT or GPL Version 2 licenses.
10
+
11
+ Usage: $('#content').redactor();
12
+ */
13
+
14
+
15
+ var isCtrl = false;
16
+ var redactorActive = false;
17
+
18
+ var $table = false;
19
+ var $tbody = false;
20
+ var $thead = false;
21
+ var $current_tr = false;
22
+ var $current_td = false;
23
+
24
+ var deviceAndroid = "android";
25
+ var uagent = navigator.userAgent.toLowerCase();
26
+
27
+ // detect iOS and Android
28
+ function isiOS() {
29
+ return ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1));
30
+ }
31
+
32
+ function detectAndroid() {
33
+ return uagent.search(deviceAndroid) > -1
34
+ }
35
+
36
+ function detectAndroidWebKit() {
37
+ if (detectAndroid()) {
38
+ return uagent.search('webkit') > -1
39
+ }
40
+
41
+ return false;
42
+ }
43
+
44
+ // redactor
45
+ (function($){
46
+ // Initialization
47
+ $.fn.redactor = function(options) {
48
+ if (isiOS() || detectAndroid() || detectAndroidWebKit()) return false;
49
+ var obj = new Construct(this, options);
50
+ obj.init();
51
+ return obj;
52
+ };
53
+
54
+ // Options and variables
55
+ function Construct(el, options) {
56
+ this.opts = $.extend({
57
+ air : false,
58
+ autosave : false, // false or url
59
+ interval : 20, // seconds
60
+ resize : true,
61
+ visual : true,
62
+ focus : false,
63
+ autoclear : true,
64
+ removeClasses : false,
65
+ removeStyles : true,
66
+ convertLinks : true,
67
+ autoformat : true,
68
+ clearOnInit : false,
69
+ overlay : true, // modal overlay
70
+ fileUploadCallback : false, // callback function
71
+ imageUploadCallback : false, // callback function
72
+
73
+ // Paths to various handlers
74
+ paths : {
75
+ // Editor css
76
+ stylesheets : ['/assets/imperavi-rails/imperavi/wym.css'],
77
+
78
+ // Toolbar
79
+ toolbar : '/imperavi/toolbar.js',
80
+
81
+ // Interface translations
82
+ language : '/imperavi/language.js',
83
+
84
+ // Typograf
85
+ typograf : '/imperavi/typograf',
86
+
87
+ // Dialogs
88
+ // TODO Add dialogs sizes
89
+ dialogs : {
90
+ file : '/imperavi/file?r',
91
+ fileEdit : '/imperavi/file_edit',
92
+ image : '/imperavi/image?r',
93
+ imageEdit : '/imperavi/image_edit',
94
+ link : '/imperavi/link',
95
+ table : '/imperavi/table',
96
+ video : '/imperavi/video'
97
+ },
98
+
99
+ // Images
100
+ images : {
101
+ upload : '/imperavi/images',
102
+ download : '/imperavi/images/777',
103
+ list : '/imperavi/images.json'
104
+ },
105
+
106
+ // Files
107
+ files : {
108
+ upload : '/imperavi/files',
109
+ download : '/imperavi/files/777', // /tests/file_download.php?file=
110
+ remove : '/imperavi/files/777' // /tests/file_delete.php?delete=
111
+ }
112
+ }
113
+ }, options);
114
+
115
+ this.$el = $(el);
116
+ };
117
+
118
+ // Functionality
119
+ Construct.prototype = {
120
+ init: function() {
121
+ if (this.opts.air) this.opts.toolbar = 'air';
122
+
123
+ // include lang and toolbar
124
+ this.include();
125
+
126
+ // sizes and id
127
+ this.frameID = this.$el.attr('id');
128
+ this.width = this.$el.css('width');
129
+ this.height = this.$el.css('height');
130
+
131
+ // modal overlay
132
+ if ($('#redactor_imp_modal_overlay').size() == 0) {
133
+ this.overlay = $('<div id="redactor_imp_modal_overlay" style="display: none;"></div>');
134
+ $('body').prepend(this.overlay);
135
+ }
136
+
137
+ // create container
138
+ this.box = $('<div id="imp_redactor_box_' + this.frameID + '" style="width: ' + this.width + ';" class="imp_redactor_box imp_redactor_box"></div>');
139
+
140
+ // air box
141
+ if (this.opts.air) {
142
+ this.air = $('<div id="imp_redactor_air_' + this.frameID + '" class="redactor_air" style="display: none;"></div>');
143
+ }
144
+
145
+ // create iframe
146
+ this.frame = $('<iframe frameborder="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" scrolling="auto" id="imp_redactor_frame_' + this.frameID + '" style="height: ' + this.height + ';" class="imp_redactor_frame"></iframe>');
147
+
148
+ this.$el.hide();
149
+
150
+ // append box and frame
151
+ $(this.box).insertAfter(this.$el).append(this.frame).append(this.$el);
152
+
153
+ // toolbar
154
+ if (this.opts.toolbar !== false) this.buildToolbar();
155
+
156
+ // resizer
157
+ if (this.opts.resize) {
158
+ this.resizer = $('<div id="imp_redactor_resize' + this.frameID + '" class="imp_redactor_resize"><div></div></div>');
159
+ $(this.box).append(this.resizer);
160
+
161
+ $(this.resizer).mousedown(function(e) { this.initResize(e) }.bind2(this));
162
+ }
163
+
164
+ // enable
165
+ this.enable(this.$el.val());
166
+
167
+ $(this.doc).click(function() { this.hideAllDropDown() }.bind2(this));
168
+
169
+ if (this.opts.autoclear) {
170
+ $(this.doc).bind('paste', function(e) {
171
+ setTimeout(function () { this.clean(); }.bind2(this), 200);
172
+ }.bind2(this));
173
+ }
174
+
175
+ // air enable
176
+ this.enableAir();
177
+
178
+ // doc events
179
+ $(this.doc).keydown(function(e) {
180
+ if (e.ctrlKey || e.metaKey) isCtrl = true;
181
+ if (e.keyCode == 9) { this.execCommand('indent', false); return false; }
182
+ if (e.keyCode == 66 && isCtrl) { this.execCommand('bold', 'bold'); return false; }
183
+ if (e.keyCode == 73 && isCtrl) { this.execCommand('italic', 'italic'); return false; }
184
+
185
+ }.bind2(this)).keyup(function(e) {
186
+ isCtrl = false;
187
+
188
+ if (e.keyCode == 13) {
189
+ $(this.doc).linkify();
190
+ return true;
191
+ }
192
+
193
+ this.syncCode();
194
+ }.bind2(this));
195
+
196
+ // autosave
197
+ if (this.opts.autosave) {
198
+ setInterval(function() {
199
+ var html = this.getHtml();
200
+ $.post(this.opts.autosave, { data: html });
201
+ }.bind2(this), this.opts.interval*1000);
202
+ }
203
+
204
+ this.formSets();
205
+
206
+ // focus
207
+ if (this.opts.focus) this.focus();
208
+ },
209
+
210
+ /*
211
+ API
212
+ */
213
+ setHtml: function(html) {
214
+ this.doc.body.innerHTML = html;
215
+ this.docObserve();
216
+ },
217
+
218
+ getHtml: function() {
219
+ return this.doc.body.innerHTML;
220
+ },
221
+
222
+ getCode: function(clear) {
223
+ return this.$el.val();
224
+ },
225
+
226
+ focus: function() {
227
+ if ($.browser.msie) $(this.frame).load(function() { $(this).get(0).contentWindow.focus(); });
228
+ else this.frame.get(0).contentWindow.focus();
229
+ },
230
+
231
+ typo: function() {
232
+ var html = this.getHtml();
233
+
234
+ $.ajax({
235
+ url : this.opts.paths.typograf,
236
+ type : 'post',
237
+ data : 'redactor=' + escape(encodeURIComponent(html)),
238
+ success: function(data) {
239
+ this.setHtml(data);
240
+ }.bind2(this)
241
+ });
242
+ },
243
+
244
+ syncCode: function() {
245
+ var html = this.getHtml();
246
+
247
+ html = this.tidyUp(html);
248
+ html = html.replace(/\%7B/gi, '{');
249
+ html = html.replace(/\%7D/gi, '}');
250
+ html = html.replace(/<hr class="redactor_cut">/gi, '<!--more-->');
251
+ html = html.replace(/<hr class=redactor_cut>/gi, '<!--more-->');
252
+ this.$el.val(html);
253
+ },
254
+
255
+ destroy: function() {
256
+ var html = this.getCode();
257
+ $(this.box).after(this.$el)
258
+ this.box.remove();
259
+ this.$el.val(html).show();
260
+ },
261
+
262
+ // Include
263
+ include: function() {
264
+ // lang
265
+ $('head').append(
266
+ $('<script src="' + this.opts.paths.language + '"></script>')
267
+ );
268
+
269
+ // toolbar
270
+ // @tanraya
271
+ if (this.opts.toolbar !== false) {
272
+ $('head').append($('<script src="' + this.opts.paths.toolbar + '"></script>'));
273
+ }
274
+ },
275
+
276
+ // Enable
277
+ enable: function(html) {
278
+ this.doc = this.contentDocumentFrame(this.frame);
279
+
280
+ // flash replace
281
+ html = html.replace(/\<object([\w\W]*?)\<\/object\>/gi, '<p class="redactor_video_box"><object$1</object></p>');
282
+
283
+ if (html == '') {
284
+ if (this.opts.autoformat === true) {
285
+ html = $.browser.msie ? "<p></p>" : "<p>&nbsp;</p>";
286
+ }
287
+ }
288
+
289
+ this.redactorWrite(this.getRedactorDoc(html));
290
+ if (this.opts.clearOnInit) this.clean();
291
+ this.designMode();
292
+ },
293
+
294
+ enableAir: function() {
295
+ if (this.opts.air) {
296
+ $('#imp_redactor_air_' + this.frameID).hide();
297
+
298
+ $(this.doc).bind('textselect', this.frameID, function(e) {
299
+ var width = $('#imp_redactor_air_' + this.frameID).width();
300
+ var width_area = $(this.frame).width();
301
+ var diff = width_area - e.clientX;
302
+
303
+ if (diff < width) e.clientX = e.clientX - width;
304
+
305
+ $('#imp_redactor_air_' + this.frameID).css({ left: e.clientX + 'px', top: (e.clientY + 8) + 'px' }).show();
306
+
307
+ }.bind2(this));
308
+
309
+ $(this.doc).bind('textunselect', this.frameID, function() {
310
+ $('#imp_redactor_air_' + this.frameID).hide();
311
+ }.bind2(this));
312
+ }
313
+ },
314
+
315
+ redactorWrite: function(html) {
316
+ this.doc.open();
317
+ this.doc.write(html);
318
+ this.doc.close();
319
+ },
320
+
321
+ getRedactorDoc: function(html) {
322
+ css = '';
323
+
324
+ for (stylesheet in this.opts.paths.stylesheets) {
325
+ css += '<link media="all" href="' + this.opts.paths.stylesheets[stylesheet] + '" rel="stylesheet">';
326
+ }
327
+
328
+ var frameHtml = '<!DOCTYPE html>\n';
329
+ frameHtml += '<html><head>' + css + '</head><body>';
330
+ frameHtml += html;
331
+ frameHtml += '</body></html>';
332
+
333
+ return frameHtml;
334
+ },
335
+
336
+ contentDocumentFrame: function(frame) {
337
+ frame = frame.get(0);
338
+
339
+ if (frame.contentDocument) return frame.contentDocument;
340
+ else if (frame.contentWindow && frame.contentWindow.document) return frame.contentWindow.document;
341
+ else if (frame.document) return frame.document;
342
+ else return null;
343
+ },
344
+
345
+ designMode: function() {
346
+ if (this.doc) {
347
+ this.doc.designMode = 'on';
348
+ this.frame.load(function() {
349
+ this.enableObjects();
350
+ this.docObserve();
351
+ this.doc.designMode = 'on';
352
+ }.bind2(this));
353
+ }
354
+ },
355
+
356
+ enableObjects: function() {
357
+ if ($.browser.mozilla) {
358
+ this.doc.execCommand("enableObjectResizing", false, "false");
359
+ this.doc.execCommand("enableInlineTableEditing", false, "false");
360
+ }
361
+ },
362
+
363
+
364
+ // Observers
365
+ docObserve: function() {
366
+ var body = $(this.doc).find('body');
367
+
368
+ body.find('img').click(function(e) { this.imageEdit(e); }.bind2(this));
369
+ body.find('table').click(function(e) { this.tableObserver(e); }.bind2(this));
370
+ body.find('.redactor_file_link').click(function(e) { this.fileEdit(e); }.bind2(this));
371
+
372
+ },
373
+
374
+ // Format on submit form
375
+ formSets: function() {
376
+ var oldOnsubmit = null;
377
+ var theForm = $(this.box).parents('form');
378
+
379
+ if (theForm.length == 0) return false;
380
+
381
+ oldOnsubmit = theForm.get(0).onsubmit;
382
+
383
+ if (typeof theForm.get(0).onsubmit != "function") {
384
+ theForm.get(0).onsubmit = function() {
385
+ if (this.opts.visual) {
386
+ this.syncCode();
387
+ return true;
388
+ }
389
+ }.bind2(this)
390
+ } else {
391
+ theForm.get(0).onsubmit = function() {
392
+ if (this.opts.visual) {
393
+ this.syncCode();
394
+ return oldOnsubmit();
395
+ }
396
+ }.bind2(this)
397
+ }
398
+
399
+ return true;
400
+ },
401
+
402
+ // Exec
403
+ execCommand: function(cmd, param) {
404
+ if (this.opts.visual && this.doc) {
405
+ try {
406
+ this.frame.get(0).contentWindow.focus();
407
+
408
+ if (cmd == 'inserthtml' && $.browser.msie) {
409
+ this.doc.selection.createRange().pasteHTML(param);
410
+ } else {
411
+ this.doc.execCommand(cmd, false, param);
412
+
413
+ if (param == "blockquote" || param == 'pre')
414
+ this.doc.body.appendChild(this.doc.createElement("BR"));
415
+ }
416
+ } catch (e) { }
417
+
418
+ this.syncCode();
419
+ if (this.opts.air) $('#imp_redactor_air_' + this.frameID).hide();
420
+ }
421
+ },
422
+
423
+ // Format and clean
424
+ clean: function() {
425
+ var html = this.getHtml();
426
+
427
+ if ($.browser.mozilla) html = this.convertSpan(html);
428
+
429
+ // strip tags
430
+ html = html.replace(/<(?!\s*\/?(a|br|p|b|i|strong|em|table|tr|td|th|tbody|thead|tfoot|h2|h3|h4)\b)[^>]+>/ig,"");
431
+
432
+ if (this.opts.removeStyles) html = html.replace(/ style=".*?"/g, '');
433
+ if (this.opts.removeClasses) html = html.replace(/ class=".*?"/g, '');
434
+
435
+ html = this.tidyUp(html);
436
+
437
+ this.setHtml(html);
438
+ this.paragraphise();
439
+
440
+ return html;
441
+ },
442
+
443
+ tidyUp: function (html) {
444
+ // lowercase
445
+ if ($.browser.msie)
446
+ {
447
+ html = html.replace(/< *(\/ *)?(\w+)/g,function(w){return w.toLowerCase()});
448
+ html = html.replace(/ jQuery(.*?)=\"(.*?)\"/gi, '');
449
+ }
450
+
451
+ if (this.opts.convertLinks) html = this.convertLinks(html);
452
+
453
+ html = html.replace(/[\t]*/g, '');
454
+ html = html.replace(/[\r\n]*/g, '');
455
+ html = html.replace(/\n\s*\n/g, "\n");
456
+ html = html.replace(/^[\s\n]*/, '');
457
+ html = html.replace(/[\s\n]*$/, '');
458
+
459
+ var lb = '\r\n';
460
+ var btags = ["<html","</html>","</head>","<title","</title>","<meta","<link","<style","</style>","</body>","<body","<head","<div","<p","<form","<fieldset","<label","</label>","<legend","</legend>","<object","</object>","<embed","</embed>","<select","</select>","<option","<option","<input","<textarea","</textarea>","</form>","</fieldset>","<br>","<br />","<hr","<pre","</pre>","<blockquote","</blockquote>","<ul","</ul>","<ol","</ol>","<li","<dl","</dl>","<dt","</dt>","<dd","</dd>","<\!--","<table","</table>","</thead>","<tbody","</tbody>","<caption","</caption>","<th","</th>","<tr","</tr>","<td","<script","</script>","<noscript","</noscript>"];
461
+ for (i = 0; i < btags.length; ++i)
462
+ {
463
+ var bbb = btags[i];
464
+ html = html.replace(new RegExp(bbb,'gi'),lb+bbb);
465
+ }
466
+
467
+ // indenting
468
+ html = html.replace(/<li/g, "\t<li");
469
+ html = html.replace(/<tr/g, "\t<tr");
470
+ html = html.replace(/<td/g, "\t\t<td");
471
+ html = html.replace(/<\/tr>/g, "\t</tr>");
472
+
473
+ // empty tags
474
+ var btags = ["<pre></pre>","<blockquote></blockquote>","<ul></ul>","<ol></ol>","<li></li>","<table></table>","<tr></tr>","<span><span>", "<p>&nbsp;</p>", "<p></p>", "<p><br></p>", "<div></div>"];
475
+ for (i = 0; i < btags.length; ++i)
476
+ {
477
+ var bbb = btags[i];
478
+ html = html.replace(new RegExp(bbb,'gi'), "");
479
+ }
480
+
481
+ return html;
482
+ },
483
+
484
+ convertLinks: function(html)
485
+ {
486
+ html = html.replace(/\<a(.*?)href="http:\/\/(.*?)"(.*?)>([\w\W]*?)\<\/a\>/gi, "<a$1href=\"rttp://$2\"$3>$4</a>");
487
+ html = html.replace(/\<a(.*?)href="rttp:\/\/(.*?)"(.*?)>http:\/\/([\w\W]*?)\<\/a\>/gi, "<a$1href=\"rttp://$2\"$3>rttp:\/\/$4</a>");
488
+
489
+ //var url1 = /(^|>|\s)(www\..+?\..+?)(\s|<|$)/g;
490
+ var url2 = /(^|>|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|<|$)/g;
491
+
492
+ //html = html.replace(url1, '$1<a href="http://$2">$2</a>$3')
493
+ html = html.replace(url2, '$1<a href="$2">$2</a>$5');
494
+
495
+ html = html.replace(/\<a(.*?)href="rttp:\/\/(.*?)"(.*?)>([\w\W]*?)\<\/a\>/gi, "<a$1href=\"http://$2\"$3>$4</a>");
496
+ html = html.replace(/\<a(.*?)href="http:\/\/(.*?)"(.*?)>rttp:\/\/([\w\W]*?)\<\/a\>/gi, "<a$1href=\"http://$2\"$3>http://$4</a>");
497
+
498
+ return html;
499
+ },
500
+
501
+ convertSpan: function(html)
502
+ {
503
+ html = html.replace(/\<span(.*?)style="font-weight: bold;"\>([\w\W]*?)\<\/span\>/gi, "<strong>$2</strong>");
504
+ html = html.replace(/\<span(.*?)style="font-style: italic;"\>([\w\W]*?)\<\/span\>/gi, "<em>$2</em>");
505
+ html = html.replace(/\<span(.*?)style="font-weight: bold; font-style: italic;"\>([\w\W]*?)\<\/span\>/gi, "<em><strong>$2</strong></em>");
506
+ html = html.replace(/\<span(.*?)style="font-style: italic; font-weight: bold;"\>([\w\W]*?)\<\/span\>/gi, "<strong><em>$2</em></strong>");
507
+
508
+ return html;
509
+ },
510
+
511
+ /*
512
+ Paragraphise
513
+ */
514
+ paragraphise: function()
515
+ {
516
+
517
+ if (this.opts.autoformat === false) return true;
518
+ if (this.opts.visual)
519
+ {
520
+ var theBody = this.doc.body;
521
+
522
+ /* Remove all text nodes containing just whitespace */
523
+ for (var i = 0; i < theBody.childNodes.length; i++)
524
+ {
525
+ if (theBody.childNodes[i].nodeName.toLowerCase() == "#text" && theBody.childNodes[i].data.search(/^\s*$/) != -1)
526
+ {
527
+ theBody.removeChild(theBody.childNodes[i]);
528
+ i--;
529
+ }
530
+ }
531
+
532
+ var removedElements = new Array();
533
+ for (var i = 0; i < theBody.childNodes.length; i++)
534
+ {
535
+ if (theBody.childNodes[i].nodeName.isInlineName())
536
+ {
537
+ removedElements.push(theBody.childNodes[i].cloneNode(true));
538
+ theBody.removeChild(theBody.childNodes[i]);
539
+ i--;
540
+ }
541
+ else if (theBody.childNodes[i].nodeName.toLowerCase() == "br")
542
+ {
543
+ if (i + 1 < theBody.childNodes.length)
544
+ {
545
+ if (theBody.childNodes[i + 1].nodeName.toLowerCase() == "br")
546
+ {
547
+ while (i < theBody.childNodes.length && theBody.childNodes[i].nodeName.toLowerCase() == "br")
548
+ {
549
+ theBody.removeChild(theBody.childNodes[i]);
550
+ }
551
+
552
+ if (removedElements.length > 0)
553
+ {
554
+ this.insertNewParagraph(removedElements, theBody.childNodes[i]);
555
+ removedElements = new Array();
556
+ }
557
+ }
558
+ else if (!theBody.childNodes[i + 1].nodeName.isInlineName()) theBody.removeChild(theBody.childNodes[i]);
559
+ else if (removedElements.length > 0)
560
+ {
561
+ removedElements.push(theBody.childNodes[i].cloneNode(true));
562
+ theBody.removeChild(theBody.childNodes[i]);
563
+ }
564
+ else theBody.removeChild(theBody.childNodes[i]);
565
+ i--;
566
+ }
567
+ else theBody.removeChild(theBody.childNodes[i]);
568
+ }
569
+ else if (removedElements.length > 0)
570
+ {
571
+ this.insertNewParagraph(removedElements, theBody.childNodes[i]);
572
+ removedElements = new Array();
573
+ }
574
+ }
575
+
576
+ if (removedElements.length > 0) this.insertNewParagraph(removedElements);
577
+ }
578
+
579
+ return true;
580
+ },
581
+ insertNewParagraph: function(elementArray, succeedingElement)
582
+ {
583
+ var theBody = this.doc.getElementsByTagName("body")[0];
584
+ var theParagraph = this.doc.createElement("p");
585
+
586
+ for (var i = 0; i < elementArray.length; i++) theParagraph.appendChild(elementArray[i]);
587
+
588
+ if (typeof(succeedingElement) != "undefined") theBody.insertBefore(theParagraph, succeedingElement);
589
+ else theBody.appendChild(theParagraph);
590
+
591
+ return true;
592
+ },
593
+
594
+ /*
595
+ Selection
596
+ */
597
+ get_selection: function ()
598
+ {
599
+ if (this.frame.get(0).contentWindow.getSelection) return this.frame.get(0).contentWindow.getSelection();
600
+ else if (this.frame.get(0).contentWindow.document.selection) return this.frame.contentWindow.get(0).document.selection.createRange();
601
+ },
602
+
603
+ setCut: function()
604
+ {
605
+ this.execCommand('inserthtml', '<hr class="redactor_cut" />');
606
+ },
607
+
608
+ /*
609
+ Toggle
610
+ */
611
+ toggle: function()
612
+ {
613
+ if (this.opts.visual)
614
+ {
615
+ this.addSelButton('html');
616
+
617
+ var html = this.getHtml();
618
+
619
+ html = this.tidyUp(html);
620
+
621
+ html = html.replace(/\%7B/gi, '{');
622
+ html = html.replace(/\%7D/gi, '}');
623
+
624
+ // flash replace
625
+ html = html.replace(/<p(.*?)class="redactor_video_box"(.*?)>([\w\W]*?)\<\/p>/gi, "$3");
626
+
627
+ // files replace
628
+ html = html.replace(/<a(.*?)rel="(.*?)"(.*?)class="redactor_file_link(.*?)"(.*?)>([\w\W]*?)\<\/a>/gi, "<a href=\"" + this.opts.paths.files.download + "$2\" rel=\"$2\" class=\"redactor_file_link$4\">$6</a>");
629
+
630
+ // cut replace
631
+ html = html.replace(/<hr class="redactor_cut"\/>/gi, '<!--more-->');
632
+ html = html.replace(/<hr class=redactor_cut>/gi, '<!--more-->');
633
+
634
+
635
+ this.frame.hide();
636
+ this.$el.val(html);
637
+ this.$el.show().focus();
638
+
639
+ var height = this.$el.height();
640
+
641
+ this.opts.visual = false;
642
+ }
643
+ else
644
+ {
645
+ this.removeSelButton('html');
646
+ this.$el.hide();
647
+
648
+ var html = this.$el.val();
649
+
650
+ // cut replace
651
+ html = html.replace(/<!--more-->/gi, '<hr class="redactor_cut"/>');
652
+
653
+ // flash replace
654
+ html = html.replace(/\<object([\w\W]*?)\<\/object\>/gi, '<p class="redactor_video_box"><object$1</object></p>');
655
+
656
+ // files replace
657
+ html = html.replace(/<a(.*?)href="(.*?)"(.*?)rel="(.*?)"(.*?)class="redactor_file_link(.*?)">(.*?)<\/a>/gi, "<a href=\"javascript:void(null);\" rel=\"$4\" class=\"redactor_file_link$6\">$7</a>");
658
+
659
+
660
+ this.opts.visual = true;
661
+
662
+ this.setHtml(html);
663
+
664
+ this.frame.show();
665
+ this.focus();
666
+ }
667
+ },
668
+
669
+
670
+ /*
671
+ Video
672
+ */
673
+ showVideo: function()
674
+ {
675
+ redactorActive = this;
676
+ this.modalInit(RLANG.video, this.opts.paths.dialogs.video, 600, 360, function()
677
+ {
678
+ $('#redactor_insert_video_area').focus();
679
+ });
680
+ },
681
+ insertVideo: function()
682
+ {
683
+ var data = $('#redactor_insert_video_area').val();
684
+ if (redactorActive.opts.visual)
685
+ {
686
+ // iframe video
687
+ if (data.search('iframe')) {}
688
+ // flash
689
+ else data = '<p class="redactor_video_box">' + data + '</p>';
690
+ }
691
+
692
+ redactorActive.execCommand('inserthtml', data);
693
+ this.modalClose();
694
+
695
+ },
696
+
697
+
698
+
699
+ /*
700
+ File
701
+ */
702
+ showFile: function()
703
+ {
704
+ redactorActive = this;
705
+
706
+ var handler = function()
707
+ {
708
+ // upload params
709
+ var params = '';
710
+ if (this.opts.fileUploadCallback) params = this.opts.fileUploadCallback();
711
+
712
+ $('#redactor_file').dragupload(
713
+ {
714
+ url: this.opts.paths.files.upload + params,
715
+ success: function(data)
716
+ {
717
+ this.fileUploadCallback(data);
718
+
719
+ }.bind2(this)
720
+ });
721
+
722
+ this.uploadInit('redactor_file', { auto: true, url: this.opts.paths.files.upload + params, success: function(data) {
723
+
724
+ this.fileUploadCallback(data);
725
+
726
+ }.bind2(this) });
727
+
728
+
729
+ }.bind2(this);
730
+
731
+
732
+ redactorActive = this;
733
+ this.modalInit(RLANG.file, this.opts.paths.dialogs.file, 500, 400, handler);
734
+ },
735
+ fileUploadCallback: function(data)
736
+ {
737
+ redactorActive.frame.get(0).contentWindow.focus();
738
+ redactorActive.execCommand('inserthtml', data);
739
+ this.modalClose();
740
+ this.docObserve();
741
+ },
742
+ fileEdit: function(e)
743
+ {
744
+ var el = e.target;
745
+ var file_id = $(el).attr('rel');
746
+
747
+ var handler = function()
748
+ {
749
+ $('#file').val($(el).text());
750
+ $('#redactorFileDeleteBtn').click(function()
751
+ {
752
+ this.fileDelete(el, file_id);
753
+ }.bind2(this));
754
+
755
+ $('#redactorFileDownloadBtn').click(function()
756
+ {
757
+ this.fileDownload(el, file_id);
758
+ }.bind2(this));
759
+
760
+ }.bind2(this);
761
+
762
+ redactorActive = this;
763
+ this.modalInit(RLANG.file, this.opts.paths.dialogs.fileEdit, 400, 200, handler);
764
+ },
765
+ fileDelete: function(el, file_id)
766
+ {
767
+ $(el).remove();
768
+ $.get(this.opts.paths.files.remove + file_id);
769
+ redactorActive.frame.get(0).contentWindow.focus();
770
+ this.modalClose();
771
+ },
772
+ fileDownload: function(el, file_id)
773
+ {
774
+ top.location.href = this.opts.paths.files.download + file_id;
775
+ },
776
+
777
+ /*
778
+ Table
779
+ */
780
+ showTable: function()
781
+ {
782
+ redactorActive = this;
783
+ this.modalInit(RLANG.table, this.opts.paths.dialogs.table, 360, 200);
784
+ },
785
+ insertTable: function()
786
+ {
787
+ var rows = $('#redactor_table_rows').val();
788
+ var columns = $('#redactor_table_columns').val();
789
+
790
+ var table_box = $('<div></div>');
791
+
792
+ var tableid = Math.floor(Math.random() * 99999);
793
+ var table = $('<table id="table' + tableid + '"><tbody></tbody></table>');
794
+
795
+ for (i = 0; i < rows; i++)
796
+ {
797
+ var row = $('<tr></tr>')
798
+ for (z = 0; z < columns; z++)
799
+ {
800
+ var column = $('<td>&nbsp;</td>');
801
+ $(row).append(column);
802
+ }
803
+ $(table).append(row);
804
+ }
805
+
806
+ $(table_box).append(table);
807
+ var html = $(table_box).html();
808
+ if ($.browser.msie) html += '<p></p>';
809
+ else html += '<p>&nbsp;</p>';
810
+
811
+ redactorActive.execCommand('inserthtml', html);
812
+ this.enableObjects();
813
+ this.docObserve();
814
+ this.modalClose();
815
+
816
+ $table = $(this.doc).find('body').find('#table' + tableid);
817
+
818
+
819
+ },
820
+ tableObserver: function(e)
821
+ {
822
+ $table = $(e.target).parents('table');
823
+
824
+ $tbody = $(e.target).parents('tbody');
825
+ $thead = $($table).find('thead');
826
+
827
+ $current_td = $(e.target);
828
+ $current_tr = $(e.target).parents('tr');
829
+ },
830
+ deleteTable: function()
831
+ {
832
+ $($table).remove();
833
+ $table = false;
834
+ },
835
+ deleteRow: function()
836
+ {
837
+ $($current_tr).remove();
838
+ },
839
+ deleteColumn: function()
840
+ {
841
+ var index = $($current_td).attr('cellIndex');
842
+
843
+ $($table).find('tr').each(function()
844
+ {
845
+ $(this).find('td').eq(index).remove();
846
+ });
847
+ },
848
+ addHead: function()
849
+ {
850
+ if ($($table).find('thead').size() != 0) this.deleteHead();
851
+ else
852
+ {
853
+ var tr = $($table).find('tr').first().clone();
854
+ tr.find('td').html('&nbsp;');
855
+ $thead = $('<thead></thead>');
856
+ $thead.append(tr);
857
+ $($table).prepend($thead);
858
+ }
859
+ },
860
+ deleteHead: function()
861
+ {
862
+ $($thead).remove();
863
+ $thead = false;
864
+ },
865
+ insertRowAbove: function()
866
+ {
867
+ this.insertRow('before');
868
+ },
869
+ insertRowBelow: function()
870
+ {
871
+ this.insertRow('after');
872
+ },
873
+ insertColumnLeft: function()
874
+ {
875
+ this.insertColumn('before');
876
+ },
877
+ insertColumnRight: function()
878
+ {
879
+ this.insertColumn('after');
880
+ },
881
+ insertRow: function(type)
882
+ {
883
+ var new_tr = $($current_tr).clone();
884
+ new_tr.find('td').html('&nbsp;');
885
+ if (type == 'after') $($current_tr).after(new_tr);
886
+ else $($current_tr).before(new_tr);
887
+ },
888
+ insertColumn: function(type)
889
+ {
890
+ var index = $($current_td).attr('cellIndex');
891
+
892
+ $($table).find('tr').each(function(i,s)
893
+ {
894
+ var current = $(s).find('td').eq(index);
895
+ var td = current.clone();
896
+ td.html('&nbsp;');
897
+ if (type == 'after') $(current).after(td);
898
+ else $(current).before(td);
899
+ });
900
+ },
901
+
902
+ /*
903
+ Image
904
+ */
905
+ imageEdit: function(e)
906
+ {
907
+ var handler = function()
908
+ {
909
+ var $el = $(e.target);
910
+ var src = $el.attr('src');
911
+ $('#redactor_image_edit_src').attr('href', src);
912
+ $('#redactor_image_edit_delete').click(function() { this.deleteImage(e.target); }.bind2(this));
913
+ $('#redactorSaveBtn').click(function() { this.imageSave(e.target); }.bind2(this));
914
+
915
+ $('#redactor_file_alt').val($el.attr('alt'));
916
+
917
+ var float = $el.css('float');
918
+ if (float == 'none') float = 0;
919
+
920
+ $('#redactor_form_image_align').val(float);
921
+
922
+ }.bind2(this);
923
+
924
+ redactorActive = this;
925
+ this.modalInit(RLANG.image, this.opts.paths.dialogs.imageEdit, 380, 290, handler);
926
+ },
927
+ imageSave: function(el)
928
+ {
929
+ $(el).attr('alt', $('#redactor_file_alt').val());
930
+
931
+ var style = '';
932
+ if ($('#redactor_form_image_align') != 0)
933
+ {
934
+ var float = $('#redactor_form_image_align').val();
935
+
936
+ // @tanraya AddedClasses
937
+ $(el).removeClass('img_left').removeClass('img_right')
938
+
939
+ if (float == 'left')
940
+ $(el).addClass('img_left');
941
+ else if (float == 'right')
942
+ $(el).addClass('img_right')
943
+ }
944
+ else $(el).css({ float: 'none', margin: '0' });
945
+
946
+ this.modalClose();
947
+ },
948
+ deleteImage: function(el)
949
+ {
950
+ $(el).remove();
951
+ this.modalClose();
952
+ },
953
+ showImage: function()
954
+ {
955
+ this.spanid = Math.floor(Math.random() * 99999);
956
+ if (jQuery.browser.msie)
957
+ {
958
+ this.execCommand('inserthtml', '<span id="span' + this.spanid + '"></span>');
959
+ }
960
+
961
+ var handler = function() {
962
+ if (this.opts.paths.images.list !== false) {
963
+ $.getJSON(this.opts.paths.images.list, function(data) {
964
+ $.each(data, function(key, val) {
965
+ var img = $('<img src="' + val.thumb + '" rel="' + val.image + '">');
966
+ img.click(function() { redactorActive.imageSetThumb($(this).attr('rel')); });
967
+ $('#redactor_image_box').append(img);
968
+ });
969
+ });
970
+ } else {
971
+ $('#redactor_tabs li').eq(0).remove();
972
+ $('#redactor_tabs a').eq(1).addClass('redactor_tabs_act');
973
+ $('#redactor_tabs1').hide();
974
+ $('#redactor_tabs2').show();
975
+ }
976
+
977
+ // upload params
978
+ var params = '';
979
+ if (this.opts.imageUploadCallback) var params = this.opts.imageUploadCallback();
980
+
981
+ $('#redactor_file').dragupload({
982
+ url : this.opts.paths.images.upload + params,
983
+ success : function(data) {
984
+ this.imageUploadCallback(data);
985
+ }.bind2(this)
986
+ });
987
+
988
+ this.uploadInit('redactor_file', {
989
+ auto : true,
990
+ url : this.opts.paths.images.upload + params,
991
+ trigger : 'redactorUploadBtn',
992
+ success : function(data) {
993
+ this.imageUploadCallback(data);
994
+ }.bind2(this)});
995
+ }.bind2(this);
996
+
997
+ redactorActive = this;
998
+ this.modalInit(RLANG.image, this.opts.paths.dialogs.image, 570, 450, handler);
999
+
1000
+ },
1001
+ imageSetThumb: function(data)
1002
+ {
1003
+ this._imageSet('<img alt="" src="' + data + '" />');
1004
+ },
1005
+ imageUploadCallback: function(data)
1006
+ {
1007
+ if ($('#redactor_file_link').val() != '') data = $('#redactor_file_link').val();
1008
+
1009
+ this._imageSet(data);
1010
+
1011
+ },
1012
+ _imageSet: function(html)
1013
+ {
1014
+ redactorActive.frame.get(0).contentWindow.focus();
1015
+
1016
+ if ($.browser.msie)
1017
+ {
1018
+ $(redactorActive.doc.getElementById('span' + redactorActive.spanid)).after(html);
1019
+ $(redactorActive.doc.getElementById('span' + redactorActive.spanid)).remove();
1020
+ }
1021
+ else
1022
+ {
1023
+ redactorActive.execCommand('inserthtml', html);
1024
+ }
1025
+
1026
+ this.modalClose();
1027
+ this.docObserve();
1028
+ },
1029
+
1030
+
1031
+ /*
1032
+ Link
1033
+ */
1034
+ showLink: function()
1035
+ {
1036
+ redactorActive = this;
1037
+
1038
+ var handler = function()
1039
+ {
1040
+ var sel = this.get_selection();
1041
+ if ($.browser.msie)
1042
+ {
1043
+ var temp = sel.htmlText.match(/href="(.*?)"/gi);
1044
+ if (temp != null)
1045
+ {
1046
+ temp = new String(temp);
1047
+ temp = temp.replace(/href="(.*?)"/gi, '$1');
1048
+ }
1049
+
1050
+ var text = sel.text;
1051
+ if (temp != null) var url = temp;
1052
+ else var url = '';
1053
+ var title = '';
1054
+ }
1055
+ else
1056
+ {
1057
+ if (sel.anchorNode.parentNode.tagName == 'A')
1058
+ {
1059
+ var url = sel.anchorNode.parentNode.href;
1060
+ var text = sel.anchorNode.parentNode.text;
1061
+ var title = sel.anchorNode.parentNode.title;
1062
+ if (sel.toString() == '') this.insert_link_node = sel.anchorNode.parentNode
1063
+
1064
+ }
1065
+ else
1066
+ {
1067
+ var text = sel.toString();
1068
+ var url = '';
1069
+ var title = '';
1070
+ }
1071
+ }
1072
+
1073
+ $('#redactor_link_url').val(url).focus();
1074
+ $('#redactor_link_text').val(text);
1075
+ $('#redactor_link_title').val(title);
1076
+
1077
+ }.bind2(this);
1078
+
1079
+ this.modalInit(RLANG.link, this.opts.paths.dialogs.link, 400, 300, handler);
1080
+
1081
+ },
1082
+ insertLink: function()
1083
+ {
1084
+ var value = $('#redactor_link_text').val();
1085
+ if (value == '') return true;
1086
+
1087
+ var title = $('#redactor_link_title').val();
1088
+ if (title != '') title = ' title="' + $('#redactor_link_title').val() + '"';
1089
+
1090
+ if ($('#redactor_link_id_url').get(0).checked) var mailto = '';
1091
+ else var mailto = 'mailto:';
1092
+
1093
+ var a = '<a href="' + mailto + $('#redactor_link_url').val() + '"' + title +'>' + value + '</a> ';
1094
+
1095
+ if (a)
1096
+ {
1097
+ if (this.insert_link_node)
1098
+ {
1099
+ $(this.insert_link_node).text(value);
1100
+ $(this.insert_link_node).attr('href', $('#redactor_link_url').val());
1101
+
1102
+ var title = $('#redactor_link_title').val();
1103
+ if (title != '') $(this.insert_link_node).attr('title', title);
1104
+
1105
+ this.modalClose();
1106
+ }
1107
+ else
1108
+ {
1109
+ redactorActive.frame.get(0).contentWindow.focus();
1110
+ redactorActive.execCommand('inserthtml', a);
1111
+ }
1112
+ }
1113
+
1114
+ this.modalClose();
1115
+ },
1116
+
1117
+
1118
+ /*
1119
+ Modal
1120
+ */
1121
+ modalInit: function(title, url, width, height, handler, scroll)
1122
+ {
1123
+ if (this.opts.overlay)
1124
+ {
1125
+ $('#redactor_imp_modal_overlay').show();
1126
+ $('#redactor_imp_modal_overlay').click(function() { this.modalClose(); }.bind2(this));
1127
+ }
1128
+
1129
+ if ($('#redactor_imp_modal').size() == 0)
1130
+ {
1131
+ this.modal = $('<div id="redactor_imp_modal" style="display: none;"><div id="redactor_imp_modal_close"></div><div id="redactor_imp_modal_header"></div><div id="redactor_imp_modal_inner"></div></div>');
1132
+ $('body').append(this.modal);
1133
+ }
1134
+
1135
+ $('#redactor_imp_modal_close').click(function() { this.modalClose(); }.bind2(this));
1136
+ $(document).keyup(function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1137
+ $(this.doc).keyup(function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1138
+
1139
+ $.ajax({
1140
+ url: url,
1141
+ success: function(data)
1142
+ {
1143
+ // parse lang
1144
+ $.each(RLANG, function(i,s)
1145
+ {
1146
+ var re = new RegExp("%RLANG\." + i + "%","gi");
1147
+ data = data.replace(re, s);
1148
+ });
1149
+
1150
+ $('#redactor_imp_modal_inner').html(data);
1151
+ $('#redactor_imp_modal_header').html(title);
1152
+
1153
+ if (height === false) theight = 'auto';
1154
+ else theight = height + 'px';
1155
+
1156
+ $('#redactor_imp_modal').css({ width: width + 'px', height: theight, marginTop: '-' + height/2 + 'px', marginLeft: '-' + width/2 + 'px' }).fadeIn('fast');
1157
+
1158
+ if (scroll === true)
1159
+ {
1160
+ $('#imp_redactor_table_box').height(height-$('#redactor_imp_modal_header').outerHeight()-130).css('overflow', 'auto');
1161
+ }
1162
+
1163
+ if (typeof(handler) == 'function') handler();
1164
+
1165
+
1166
+ }.bind2(this)
1167
+ });
1168
+ },
1169
+ modalClose: function()
1170
+ {
1171
+
1172
+ $('#redactor_imp_modal_close').unbind('click', function() { this.modalClose(); }.bind2(this));
1173
+ $('#redactor_imp_modal').fadeOut('fast', function()
1174
+ {
1175
+ $('#redactor_imp_modal_inner').html('');
1176
+
1177
+ if (this.opts.overlay)
1178
+ {
1179
+ $('#redactor_imp_modal_overlay').hide();
1180
+ $('#redactor_imp_modal_overlay').unbind('click', function() { this.modalClose(); }.bind2(this));
1181
+ }
1182
+
1183
+ $(document).unbind('keyup', function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1184
+ $(this.doc).unbind('keyup', function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1185
+
1186
+ }.bind2(this));
1187
+
1188
+ },
1189
+
1190
+ /*
1191
+ Upload
1192
+ */
1193
+ uploadInit: function(element, options)
1194
+ {
1195
+ /*
1196
+ Options
1197
+ */
1198
+ this.uploadOptions = {
1199
+ url: false,
1200
+ success: false,
1201
+ start: false,
1202
+ trigger: false,
1203
+ auto: false,
1204
+ input: false
1205
+ };
1206
+
1207
+ $.extend(this.uploadOptions, options);
1208
+
1209
+
1210
+ // Test input or form
1211
+ if ($('#' + element).get(0).tagName == 'INPUT')
1212
+ {
1213
+ this.uploadOptions.input = $('#' + element);
1214
+ this.element = $($('#' + element).get(0).form);
1215
+ }
1216
+ else
1217
+ {
1218
+ this.element = $('#' + element);
1219
+ }
1220
+
1221
+
1222
+ this.element_action = this.element.attr('action');
1223
+
1224
+ // Auto or trigger
1225
+ if (this.uploadOptions.auto)
1226
+ {
1227
+ $(this.uploadOptions.input).change(function()
1228
+ {
1229
+ this.element.submit(function(e) { return false; });
1230
+ this.uploadSubmit();
1231
+ }.bind2(this));
1232
+
1233
+ }
1234
+ else if (this.uploadOptions.trigger)
1235
+ {
1236
+ $('#' + this.uploadOptions.trigger).click(function() { this.uploadSubmit(); }.bind2(this));
1237
+ }
1238
+ },
1239
+ uploadSubmit : function()
1240
+ {
1241
+ this.uploadForm(this.element, this.uploadFrame());
1242
+ },
1243
+ uploadFrame : function()
1244
+ {
1245
+ this.id = 'f' + Math.floor(Math.random() * 99999);
1246
+
1247
+ var d = document.createElement('div');
1248
+ var iframe = '<iframe style="display:none" src="about:blank" id="'+this.id+'" name="'+this.id+'"></iframe>';
1249
+ d.innerHTML = iframe;
1250
+ document.body.appendChild(d);
1251
+
1252
+ // Start
1253
+ if (this.uploadOptions.start) this.uploadOptions.start();
1254
+
1255
+ $('#' + this.id).load(function () { this.uploadLoaded() }.bind2(this));
1256
+
1257
+ return this.id;
1258
+ },
1259
+ uploadForm : function(f, name)
1260
+ {
1261
+ if (this.uploadOptions.input)
1262
+ {
1263
+ var formId = 'redactorUploadForm' + this.id;
1264
+ var fileId = 'redactorUploadFile' + this.id;
1265
+ this.form = $('<form action="' + this.uploadOptions.url + '" method="POST" target="' + name + '" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
1266
+
1267
+ var oldElement = this.uploadOptions.input;
1268
+ var newElement = $(oldElement).clone();
1269
+ $(oldElement).attr('id', fileId);
1270
+ $(oldElement).before(newElement);
1271
+ $(oldElement).appendTo(this.form);
1272
+ $(this.form).css('position', 'absolute');
1273
+ $(this.form).css('top', '-2000px');
1274
+ $(this.form).css('left', '-2000px');
1275
+ $(this.form).appendTo('body');
1276
+
1277
+ this.form.submit();
1278
+ }
1279
+ else
1280
+ {
1281
+ f.attr('target', name);
1282
+ f.attr('method', 'POST');
1283
+ f.attr('enctype', 'multipart/form-data');
1284
+ f.attr('action', this.uploadOptions.url);
1285
+
1286
+ this.element.submit();
1287
+ }
1288
+
1289
+ },
1290
+ uploadLoaded : function()
1291
+ {
1292
+ var i = $('#' + this.id);
1293
+
1294
+ if (i.contentDocument) var d = i.contentDocument;
1295
+ else if (i.contentWindow) var d = i.contentWindow.document;
1296
+ else var d = window.frames[this.id].document;
1297
+
1298
+ if (d.location.href == "about:blank") return true;
1299
+
1300
+ // Success
1301
+ if (this.uploadOptions.success) this.uploadOptions.success(d.body.innerHTML);
1302
+
1303
+ this.element.attr('action', this.element_action);
1304
+ this.element.attr('target', '');
1305
+ //this.element.unbind('submit');
1306
+ //if (this.uploadOptions.input) $(this.form).remove();
1307
+ },
1308
+
1309
+ /*
1310
+ Toolbar
1311
+ */
1312
+ buildToolbar: function()
1313
+ {
1314
+ this.toolbar = $('<ul id="imp_redactor_toolbar_' + this.frameID + '" class="imp_redactor_toolbar"></ul>');
1315
+
1316
+ if (this.opts.air)
1317
+ {
1318
+ $(this.air).append(this.toolbar);
1319
+ this.box.prepend(this.air);
1320
+ }
1321
+ else $(this.box).prepend(this.toolbar);
1322
+
1323
+
1324
+ $.each(RTOOLBAR,
1325
+ function (i, s)
1326
+ {
1327
+ if (s.name == 'separator')
1328
+ {
1329
+ var li = $('<li class="separator"></li>');
1330
+ $(this.toolbar).append(li);
1331
+ }
1332
+ else
1333
+ {
1334
+
1335
+ var a = $('<a href="javascript:void(null);" class="imp_btn imp_btn_' + s.name + '" title="' + s.title + '"></a>');
1336
+
1337
+ if (typeof(s.func) == 'undefined') a.click(function() { this.execCommand(s.exec, s.name); }.bind2(this));
1338
+ else if (s.func != 'show') a.click(function(e) { this[s.func](e); }.bind2(this));
1339
+
1340
+ var li = $('<li class="imp_li_btn imp_li_btn_' + s.name + '"></li>');
1341
+ $(li).append(a);
1342
+ $(this.toolbar).append(li);
1343
+
1344
+ // build dropdown box
1345
+ if (s.name == 'backcolor' || s.name == 'fontcolor' || typeof(s.dropdown) != 'undefined')
1346
+ {
1347
+ var ul = $('<ul class="imp_redactor_drop_down imp_redactor_drop_down' + this.frameID + '" id="imp_redactor_drop_down' + this.frameID + '_' + s.name + '" style="display: none;"></ul>');
1348
+ if ($.browser.msie) ul.css({ borderLeft: '1px solid #ddd', borderRight: '1px solid #ddd', borderBottom: '1px solid #ddd' });
1349
+ }
1350
+
1351
+ // build dropdown
1352
+ if (typeof(s.dropdown) != 'undefined')
1353
+ {
1354
+
1355
+ $.each(s.dropdown,
1356
+ function (x, d)
1357
+ {
1358
+ if (typeof(d.style) == 'undefined') d.style = '';
1359
+
1360
+ if (d.name == 'separator')
1361
+ {
1362
+ var ul_li = $('<li class="separator_drop"></li>');
1363
+ $(ul).append(ul_li);
1364
+ }
1365
+ else
1366
+ {
1367
+
1368
+ var ul_li = $('<li></li>');
1369
+ var ul_li_a = $('<a href="javascript:void(null);" style="' + d.style + '">' + d.title + '</a>');
1370
+ $(ul_li).append(ul_li_a);
1371
+ $(ul).append(ul_li);
1372
+
1373
+ if (typeof(d.func) == 'undefined') $(ul_li_a).click(function() { this.execCommand(d.exec, d.name); }.bind2(this));
1374
+ else $(ul_li_a).click(function(e) { this[d.func](e); }.bind2(this));
1375
+ }
1376
+
1377
+
1378
+
1379
+ }.bind2(this)
1380
+ );
1381
+ }
1382
+ else a.mouseover(function() { this.hideAllDropDown() }.bind2(this));
1383
+
1384
+ // observing dropdown
1385
+ if (s.name == 'backcolor' || s.name == 'fontcolor' || typeof(s.dropdown) != 'undefined')
1386
+ {
1387
+ $('#imp_redactor_toolbar_' + this.frameID).after(ul);
1388
+
1389
+ this.hdlHideDropDown = function(e) { this.hideDropDown(e, ul, s.name) }.bind2(this);
1390
+ this.hdlShowDropDown = function(e) { this.showDropDown(e, ul, s.name) }.bind2(this);
1391
+ this.hdlShowerDropDown = function(e) { this.showerDropDown(e, ul, s.name) }.bind2(this);
1392
+
1393
+ a.click(this.hdlShowDropDown).mouseover(this.hdlShowerDropDown);
1394
+
1395
+ $(document).click(this.hdlHideDropDown);
1396
+ }
1397
+
1398
+
1399
+ }
1400
+ }.bind2(this)
1401
+ );
1402
+ },
1403
+
1404
+ /*
1405
+ DropDown
1406
+ */
1407
+ showedDropDown: false,
1408
+ showDropDown: function(e, ul, name)
1409
+ {
1410
+
1411
+ if (this.showedDropDown) this.hideAllDropDown();
1412
+ else
1413
+ {
1414
+ this.showedDropDown = true;
1415
+ this.showingDropDown(e, ul, name);
1416
+ }
1417
+
1418
+ },
1419
+ showingDropDown: function(e, ul, name)
1420
+ {
1421
+ this.hideAllDropDown();
1422
+ this.addSelButton(name);
1423
+
1424
+ var left = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name).position().left;
1425
+ $(ul).css('left', left + 'px').show();
1426
+ },
1427
+ showerDropDown: function(e, ul, name)
1428
+ {
1429
+ if (this.showedDropDown) this.showingDropDown(e, ul, name);
1430
+ },
1431
+ hideAllDropDown: function()
1432
+ {
1433
+ $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn').removeClass('act');
1434
+ $('ul.imp_redactor_drop_down' + this.frameID).hide();
1435
+ },
1436
+ hideDropDown: function(e, ul, name)
1437
+ {
1438
+ if (!$(e.target).parent().hasClass('act'))
1439
+ {
1440
+ this.showedDropDown = false;
1441
+ this.hideAllDropDown();
1442
+ }
1443
+
1444
+ $(document).unbind('click', this.hdlHideDropDown);
1445
+ $(this.doc).unbind('click', this.hdlHideDropDown);
1446
+
1447
+ },
1448
+ addSelButton: function(name)
1449
+ {
1450
+ var element = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name);
1451
+ element.addClass('act');
1452
+ },
1453
+ removeSelButton: function(name)
1454
+ {
1455
+ var element = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name);
1456
+ element.removeClass('act');
1457
+ },
1458
+ toggleSelButton: function(name)
1459
+ {
1460
+ $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name).toggleClass('act');
1461
+ },
1462
+
1463
+
1464
+ /*
1465
+ Resizer
1466
+ */
1467
+ initResize: function(e)
1468
+ {
1469
+ if (e.preventDefault) e.preventDefault();
1470
+ else e.returnValue = false;
1471
+
1472
+ this.splitter = e.target;
1473
+
1474
+ if (this.opts.visual)
1475
+ {
1476
+ this.element_resize = this.frame;
1477
+ this.element_resize.get(0).style.visibility = 'hidden';
1478
+ this.element_resize_parent = this.$el;
1479
+ }
1480
+ else
1481
+ {
1482
+ this.element_resize = this.$el;
1483
+ this.element_resize_parent = this.frame;
1484
+ }
1485
+
1486
+ this.stopResizeHdl = function (e) { this.stopResize(e) }.bind2(this);
1487
+ this.startResizeHdl = function (e) { this.startResize(e) }.bind2(this);
1488
+ this.resizeHdl = function (e) { this.resize(e) }.bind2(this);
1489
+
1490
+ $(document).mousedown(this.startResizeHdl);
1491
+ $(document).mouseup(this.stopResizeHdl);
1492
+ $(this.splitter).mouseup(this.stopResizeHdl);
1493
+
1494
+ this.null_point = false;
1495
+ this.h_new = false;
1496
+ this.h = this.element_resize.height();
1497
+ },
1498
+ startResize: function()
1499
+ {
1500
+ $(document).mousemove(this.resizeHdl);
1501
+ },
1502
+ resize: function(e)
1503
+ {
1504
+ if (e.preventDefault) e.preventDefault();
1505
+ else e.returnValue = false;
1506
+
1507
+ var y = e.pageY;
1508
+ if (this.null_point == false) this.null_point = y;
1509
+ if (this.h_new == false) this.h_new = this.element_resize.height();
1510
+
1511
+ var s_new = (this.h_new + y - this.null_point) - 10;
1512
+
1513
+ if (s_new <= 30) return true;
1514
+
1515
+ if (s_new >= 0)
1516
+ {
1517
+ this.element_resize.get(0).style.height = s_new + 'px';
1518
+ this.element_resize_parent.get(0).style.height = s_new + 'px';
1519
+ }
1520
+ },
1521
+ stopResize: function(e)
1522
+ {
1523
+ $(document).unbind('mousemove', this.resizeHdl);
1524
+ $(document).unbind('mousedown', this.startResizeHdl);
1525
+ $(document).unbind('mouseup', this.stopResizeHdl);
1526
+ $(this.splitter).unbind('mouseup', this.stopResizeHdl);
1527
+
1528
+ this.element_resize.get(0).style.visibility = 'visible';
1529
+ }
1530
+
1531
+ };
1532
+
1533
+
1534
+ String.prototype.isInlineName = function()
1535
+ {
1536
+ var inlineList = new Array("#text", "a", "em", "font", "span", "strong", "u");
1537
+ var theName = this.toLowerCase();
1538
+
1539
+ for (var i = 0; i < inlineList.length; i++)
1540
+ {
1541
+ if (theName == inlineList[i])
1542
+ {
1543
+ return true;
1544
+ }
1545
+ }
1546
+
1547
+ return false;
1548
+ };
1549
+
1550
+
1551
+ // bind2
1552
+ Function.prototype.bind2 = function(object)
1553
+ {
1554
+ var method = this; var oldArguments = $.makeArray(arguments).slice(1);
1555
+ return function (argument)
1556
+ {
1557
+ if (argument == new Object) { method = null; oldArguments = null; }
1558
+ else if (method == null) throw "Attempt to invoke destructed method reference.";
1559
+ else { var newArguments = $.makeArray(arguments); return method.apply(object, oldArguments.concat(newArguments)); }
1560
+ };
1561
+ };
1562
+
1563
+
1564
+ })(jQuery);
1565
+
1566
+ // redactor_tabs
1567
+ function showRedactorTabs(el, index)
1568
+ {
1569
+ $('#redactor_tabs a').removeClass('redactor_tabs_act');
1570
+ $(el).addClass('redactor_tabs_act');
1571
+
1572
+ $('.redactor_tabs').hide();
1573
+ $('#redactor_tabs' + index).show();
1574
+ }
1575
+ ;