imperavi-rails 0.0.2.beta → 0.0.3.beta

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.
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,1834 @@
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
+ {
30
+ return ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1));
31
+ }
32
+
33
+ function detectAndroid()
34
+ {
35
+ if (uagent.search(deviceAndroid) > -1) return true;
36
+ else return false;
37
+ }
38
+
39
+ function detectAndroidWebKit()
40
+ {
41
+ if (detectAndroid())
42
+ {
43
+ if (uagent.search('webkit') > -1) return true;
44
+ else return false;
45
+ }
46
+ else return false;
47
+ }
48
+
49
+ // redactor
50
+ (function($){
51
+
52
+ // Initialization
53
+ $.fn.redactor = function(options)
54
+ {
55
+ if (isiOS() || detectAndroid() || detectAndroidWebKit()) return false;
56
+
57
+ var obj = new Construct(this, options);
58
+
59
+ obj.init();
60
+
61
+ return obj;
62
+ };
63
+
64
+ // Options and variables
65
+ function Construct(el, options) {
66
+ this.opts = $.extend({
67
+ air : false,
68
+ autosave : false, // false or url
69
+ interval : 20, // seconds
70
+ resize : true,
71
+ visual : true,
72
+ focus : false,
73
+ autoclear : true,
74
+ removeClasses : false,
75
+ removeStyles : true,
76
+ convertLinks : true,
77
+ autoformat : true,
78
+ clearOnInit : false,
79
+ overlay : true, // modal overlay
80
+ fileUploadCallback : false, // callback function
81
+ imageUploadCallback : false, // callback function
82
+
83
+ // Paths to various handlers
84
+ paths : {
85
+ // Editor css
86
+ stylesheets : ['/assets/imperavi-rails/imperavi/wym.css'],
87
+
88
+ // Toolbar
89
+ toolbar : '/imperavi/toolbar.js',
90
+
91
+ // Interface translations
92
+ language : '/imperavi/language.js',
93
+
94
+ // Typograf
95
+ typograf : '/imperavi/typograf',
96
+
97
+ // Dialogs
98
+ // TODO Add dialogs sizes
99
+ dialogs : {
100
+ file : '/imperavi/file?r',
101
+ fileEdit : '/imperavi/file_edit',
102
+ image : '/imperavi/image?r',
103
+ imageEdit : '/imperavi/image_edit',
104
+ link : '/imperavi/link',
105
+ table : '/imperavi/table',
106
+ video : '/imperavi/video'
107
+ },
108
+
109
+ // Images
110
+ images : {
111
+ upload : '/imperavi/images',
112
+ download : '/imperavi/images/777',
113
+ list : '/imperavi/images.json'
114
+ },
115
+
116
+ // Files
117
+ files : {
118
+ upload : '/imperavi/files',
119
+ download : '/imperavi/files/777', // /tests/file_download.php?file=
120
+ remove : '/imperavi/files/777' // /tests/file_delete.php?delete=
121
+ }
122
+ }
123
+ }, options);
124
+
125
+ this.$el = $(el);
126
+ };
127
+
128
+ // Functionality
129
+ Construct.prototype = {
130
+
131
+ init: function()
132
+ {
133
+ if (this.opts.air) this.opts.toolbar = 'air';
134
+
135
+ // include lang and toolbar
136
+ this.include();
137
+
138
+ // sizes and id
139
+ this.frameID = this.$el.attr('id');
140
+ this.width = this.$el.css('width');
141
+ this.height = this.$el.css('height');
142
+
143
+
144
+ // modal overlay
145
+ if ($('#redactor_imp_modal_overlay').size() == 0)
146
+ {
147
+ this.overlay = $('<div id="redactor_imp_modal_overlay" style="display: none;"></div>');
148
+ $('body').prepend(this.overlay);
149
+ }
150
+
151
+ // create container
152
+ this.box = $('<div id="imp_redactor_box_' + this.frameID + '" style="width: ' + this.width + ';" class="imp_redactor_box imp_redactor_box"></div>');
153
+
154
+ // air box
155
+ if (this.opts.air)
156
+ {
157
+ this.air = $('<div id="imp_redactor_air_' + this.frameID + '" class="redactor_air" style="display: none;"></div>');
158
+ }
159
+
160
+ // create iframe
161
+ 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>');
162
+
163
+ this.$el.hide();
164
+
165
+ // append box and frame
166
+ $(this.box).insertAfter(this.$el).append(this.frame).append(this.$el);
167
+
168
+ // toolbar
169
+ if (this.opts.toolbar !== false) this.buildToolbar();
170
+
171
+ // resizer
172
+ if (this.opts.resize)
173
+ {
174
+ this.resizer = $('<div id="imp_redactor_resize' + this.frameID + '" class="imp_redactor_resize"><div></div></div>');
175
+ $(this.box).append(this.resizer);
176
+
177
+ $(this.resizer).mousedown(function(e) { this.initResize(e) }.bind2(this));
178
+ }
179
+
180
+ // enable
181
+ this.enable(this.$el.val());
182
+
183
+ $(this.doc).click(function() { this.hideAllDropDown() }.bind2(this));
184
+
185
+ if (this.opts.autoclear)
186
+ {
187
+ $(this.doc).bind('paste', function(e)
188
+ {
189
+ setTimeout(function () { this.clean(); }.bind2(this), 200);
190
+ }.bind2(this));
191
+ }
192
+
193
+ // air enable
194
+ this.enableAir();
195
+
196
+ // doc events
197
+ $(this.doc).keydown(function(e)
198
+ {
199
+ if (e.ctrlKey || e.metaKey) isCtrl = true;
200
+
201
+ if (e.keyCode == 9) { this.execCommand('indent', false); return false; }
202
+ if (e.keyCode == 66 && isCtrl) { this.execCommand('bold', 'bold'); return false; }
203
+ if (e.keyCode == 73 && isCtrl) { this.execCommand('italic', 'italic'); return false; }
204
+
205
+ }.bind2(this)).keyup(function(e)
206
+ {
207
+ isCtrl = false;
208
+
209
+ if (e.keyCode == 13)
210
+ {
211
+ $(this.doc).linkify();
212
+ return true;
213
+ }
214
+
215
+ this.syncCode();
216
+
217
+ }.bind2(this));
218
+
219
+
220
+ // autosave
221
+ if (this.opts.autosave)
222
+ {
223
+ setInterval(function()
224
+ {
225
+ var html = this.getHtml();
226
+ $.post(this.opts.autosave, { data: html });
227
+
228
+ }.bind2(this), this.opts.interval*1000);
229
+
230
+ }
231
+
232
+ this.formSets();
233
+
234
+ // focus
235
+ if (this.opts.focus) this.focus();
236
+ },
237
+
238
+ /*
239
+ API
240
+ */
241
+ setHtml: function(html)
242
+ {
243
+ this.doc.body.innerHTML = html;
244
+ this.docObserve();
245
+ },
246
+ getHtml: function()
247
+ {
248
+ return this.doc.body.innerHTML;
249
+ },
250
+ getCode: function(clear)
251
+ {
252
+ return this.$el.val();
253
+ },
254
+ focus: function()
255
+ {
256
+ if ($.browser.msie) $(this.frame).load(function() { $(this).get(0).contentWindow.focus(); });
257
+ else this.frame.get(0).contentWindow.focus();
258
+ },
259
+ typo: function()
260
+ {
261
+ var html = this.getHtml();
262
+ $.ajax({
263
+ url: this.opts.paths.typograf,
264
+ type: 'post',
265
+ data: 'redactor=' + escape(encodeURIComponent(html)),
266
+ success: function(data)
267
+ {
268
+ this.setHtml(data);
269
+ }.bind2(this)
270
+ });
271
+ },
272
+ syncCode: function()
273
+ {
274
+ var html = this.getHtml();
275
+
276
+ html = this.tidyUp(html);
277
+
278
+ html = html.replace(/\%7B/gi, '{');
279
+ html = html.replace(/\%7D/gi, '}');
280
+
281
+ html = html.replace(/<hr class="redactor_cut">/gi, '<!--more-->');
282
+ html = html.replace(/<hr class=redactor_cut>/gi, '<!--more-->');
283
+
284
+ this.$el.val(html);
285
+ },
286
+ destroy: function()
287
+ {
288
+ var html = this.getCode();
289
+ $(this.box).after(this.$el)
290
+ this.box.remove();
291
+ this.$el.val(html).show();
292
+ },
293
+
294
+ /*
295
+ Include
296
+ */
297
+ include: function()
298
+ {
299
+ // lang
300
+ $('head').append(
301
+ $('<script src="' + this.opts.paths.language + '"></script>')
302
+ );
303
+
304
+ // toolbar
305
+ // @tanraya
306
+ if (this.opts.toolbar !== false) {
307
+ $('head').append($('<script src="' + this.opts.paths.toolbar + '"></script>'));
308
+ }
309
+ },
310
+
311
+ /*
312
+ Enable
313
+ */
314
+ enable: function(html)
315
+ {
316
+ this.doc = this.contentDocumentFrame(this.frame);
317
+
318
+ // flash replace
319
+ html = html.replace(/\<object([\w\W]*?)\<\/object\>/gi, '<p class="redactor_video_box"><object$1</object></p>');
320
+
321
+ if (html == '')
322
+ {
323
+ if (this.opts.autoformat === true)
324
+ {
325
+ if ($.browser.msie) html = "<p></p>";
326
+ else html = "<p>&nbsp;</p>";
327
+ }
328
+ }
329
+
330
+ this.redactorWrite(this.getRedactorDoc(html));
331
+
332
+ if (this.opts.clearOnInit) this.clean();
333
+
334
+
335
+ this.designMode();
336
+ },
337
+ enableAir: function()
338
+ {
339
+ if (this.opts.air)
340
+ {
341
+ $('#imp_redactor_air_' + this.frameID).hide();
342
+
343
+ $(this.doc).bind('textselect', this.frameID, function(e)
344
+ {
345
+ var width = $('#imp_redactor_air_' + this.frameID).width();
346
+ var width_area = $(this.frame).width();
347
+
348
+ var diff = width_area - e.clientX;
349
+ if (diff < width) e.clientX = e.clientX - width;
350
+
351
+ $('#imp_redactor_air_' + this.frameID).css({ left: e.clientX + 'px', top: (e.clientY + 8) + 'px' }).show();
352
+
353
+ }.bind2(this));
354
+
355
+ $(this.doc).bind('textunselect', this.frameID, function()
356
+ {
357
+ $('#imp_redactor_air_' + this.frameID).hide();
358
+
359
+ }.bind2(this));
360
+ }
361
+ },
362
+ redactorWrite: function(html)
363
+ {
364
+ this.doc.open();
365
+ this.doc.write(html);
366
+ this.doc.close();
367
+ },
368
+ getRedactorDoc: function(html)
369
+ {
370
+ css = '';
371
+ for (stylesheet in this.opts.paths.stylesheets)
372
+ {
373
+ css += '<link media="all" href="' + this.opts.paths.stylesheets[stylesheet] + '" rel="stylesheet">';
374
+ }
375
+
376
+ var frameHtml = '<!DOCTYPE html>\n';
377
+ frameHtml += '<html><head>' + css + '</head><body>';
378
+ frameHtml += html;
379
+ frameHtml += '</body></html>';
380
+ return frameHtml;
381
+ },
382
+ contentDocumentFrame: function(frame)
383
+ {
384
+ frame = frame.get(0);
385
+
386
+ if (frame.contentDocument) return frame.contentDocument;
387
+ else if (frame.contentWindow && frame.contentWindow.document) return frame.contentWindow.document;
388
+ else if (frame.document) return frame.document;
389
+ else return null;
390
+ },
391
+ designMode: function()
392
+ {
393
+ if (this.doc)
394
+ {
395
+ this.doc.designMode = 'on';
396
+ this.frame.load(function()
397
+ {
398
+ this.enableObjects();
399
+ this.docObserve();
400
+ this.doc.designMode = 'on';
401
+ }.bind2(this));
402
+ }
403
+ },
404
+ enableObjects: function()
405
+ {
406
+ if ($.browser.mozilla)
407
+ {
408
+ this.doc.execCommand("enableObjectResizing", false, "false");
409
+ this.doc.execCommand("enableInlineTableEditing", false, "false");
410
+ }
411
+ },
412
+
413
+
414
+ /*
415
+ Observers
416
+ */
417
+ docObserve: function()
418
+ {
419
+ var body = $(this.doc).find('body');
420
+
421
+ body.find('img').click(function(e) { this.imageEdit(e); }.bind2(this));
422
+ body.find('table').click(function(e) { this.tableObserver(e); }.bind2(this));
423
+ body.find('.redactor_file_link').click(function(e) { this.fileEdit(e); }.bind2(this));
424
+
425
+ },
426
+
427
+ /*
428
+ Format on submit form
429
+ */
430
+ formSets: function()
431
+ {
432
+ var oldOnsubmit = null;
433
+
434
+ var theForm = $(this.box).parents('form');
435
+ if (theForm.length == 0) return false;
436
+
437
+ oldOnsubmit = theForm.get(0).onsubmit;
438
+
439
+ if (typeof theForm.get(0).onsubmit != "function")
440
+ {
441
+ theForm.get(0).onsubmit = function()
442
+ {
443
+ if (this.opts.visual)
444
+ {
445
+ this.syncCode();
446
+
447
+ return true;
448
+ }
449
+ }.bind2(this)
450
+ }
451
+ else
452
+ {
453
+ theForm.get(0).onsubmit = function()
454
+ {
455
+ if (this.opts.visual)
456
+ {
457
+ this.syncCode();
458
+
459
+ return oldOnsubmit();
460
+ }
461
+ }.bind2(this)
462
+ }
463
+
464
+ return true;
465
+ },
466
+
467
+ /*
468
+ Exec
469
+ */
470
+ execCommand: function(cmd, param)
471
+ {
472
+ if (this.opts.visual && this.doc)
473
+ {
474
+ try
475
+ {
476
+ this.frame.get(0).contentWindow.focus();
477
+
478
+ if (cmd == 'inserthtml' && $.browser.msie) this.doc.selection.createRange().pasteHTML(param);
479
+ else
480
+ {
481
+ this.doc.execCommand(cmd, false, param);
482
+
483
+ if (param == "blockquote" || param == 'pre') this.doc.body.appendChild(this.doc.createElement("BR"));
484
+ }
485
+ }
486
+ catch (e) { }
487
+
488
+ this.syncCode();
489
+
490
+ if (this.opts.air) $('#imp_redactor_air_' + this.frameID).hide();
491
+
492
+ }
493
+ },
494
+
495
+ /*
496
+ Format and clean
497
+ */
498
+
499
+ clean: function()
500
+ {
501
+ var html = this.getHtml();
502
+
503
+ if ($.browser.mozilla) html = this.convertSpan(html);
504
+
505
+ // strip tags
506
+ html = html.replace(/<(?!\s*\/?(a|br|p|b|i|strong|em|table|tr|td|th|tbody|thead|tfoot|h2|h3|h4)\b)[^>]+>/ig,"");
507
+
508
+ if (this.opts.removeStyles) html = html.replace(/ style=".*?"/g, '');
509
+ if (this.opts.removeClasses) html = html.replace(/ class=".*?"/g, '');
510
+
511
+ html = this.tidyUp(html);
512
+
513
+ this.setHtml(html);
514
+
515
+ this.paragraphise();
516
+
517
+ return html;
518
+ },
519
+
520
+ tidyUp: function (html)
521
+ {
522
+ // lowercase
523
+ if ($.browser.msie)
524
+ {
525
+ html = html.replace(/< *(\/ *)?(\w+)/g,function(w){return w.toLowerCase()});
526
+ html = html.replace(/ jQuery(.*?)=\"(.*?)\"/gi, '');
527
+ }
528
+
529
+ if (this.opts.convertLinks) html = this.convertLinks(html);
530
+
531
+ html = html.replace(/[\t]*/g, '');
532
+ html = html.replace(/[\r\n]*/g, '');
533
+ html = html.replace(/\n\s*\n/g, "\n");
534
+ html = html.replace(/^[\s\n]*/, '');
535
+ html = html.replace(/[\s\n]*$/, '');
536
+
537
+ var lb = '\r\n';
538
+ 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>"];
539
+ for (i = 0; i < btags.length; ++i)
540
+ {
541
+ var bbb = btags[i];
542
+ html = html.replace(new RegExp(bbb,'gi'),lb+bbb);
543
+ }
544
+
545
+ // indenting
546
+ html = html.replace(/<li/g, "\t<li");
547
+ html = html.replace(/<tr/g, "\t<tr");
548
+ html = html.replace(/<td/g, "\t\t<td");
549
+ html = html.replace(/<\/tr>/g, "\t</tr>");
550
+
551
+ // empty tags
552
+ 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>"];
553
+ for (i = 0; i < btags.length; ++i)
554
+ {
555
+ var bbb = btags[i];
556
+ html = html.replace(new RegExp(bbb,'gi'), "");
557
+ }
558
+
559
+ return html;
560
+ },
561
+
562
+ convertLinks: function(html)
563
+ {
564
+ html = html.replace(/\<a(.*?)href="http:\/\/(.*?)"(.*?)>([\w\W]*?)\<\/a\>/gi, "<a$1href=\"rttp://$2\"$3>$4</a>");
565
+ html = html.replace(/\<a(.*?)href="rttp:\/\/(.*?)"(.*?)>http:\/\/([\w\W]*?)\<\/a\>/gi, "<a$1href=\"rttp://$2\"$3>rttp:\/\/$4</a>");
566
+
567
+ //var url1 = /(^|>|\s)(www\..+?\..+?)(\s|<|$)/g;
568
+ var url2 = /(^|>|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|<|$)/g;
569
+
570
+ //html = html.replace(url1, '$1<a href="http://$2">$2</a>$3')
571
+ html = html.replace(url2, '$1<a href="$2">$2</a>$5');
572
+
573
+ html = html.replace(/\<a(.*?)href="rttp:\/\/(.*?)"(.*?)>([\w\W]*?)\<\/a\>/gi, "<a$1href=\"http://$2\"$3>$4</a>");
574
+ html = html.replace(/\<a(.*?)href="http:\/\/(.*?)"(.*?)>rttp:\/\/([\w\W]*?)\<\/a\>/gi, "<a$1href=\"http://$2\"$3>http://$4</a>");
575
+
576
+ return html;
577
+ },
578
+
579
+ convertSpan: function(html)
580
+ {
581
+ html = html.replace(/\<span(.*?)style="font-weight: bold;"\>([\w\W]*?)\<\/span\>/gi, "<strong>$2</strong>");
582
+ html = html.replace(/\<span(.*?)style="font-style: italic;"\>([\w\W]*?)\<\/span\>/gi, "<em>$2</em>");
583
+ html = html.replace(/\<span(.*?)style="font-weight: bold; font-style: italic;"\>([\w\W]*?)\<\/span\>/gi, "<em><strong>$2</strong></em>");
584
+ html = html.replace(/\<span(.*?)style="font-style: italic; font-weight: bold;"\>([\w\W]*?)\<\/span\>/gi, "<strong><em>$2</em></strong>");
585
+
586
+ return html;
587
+ },
588
+
589
+ /*
590
+ Paragraphise
591
+ */
592
+ paragraphise: function()
593
+ {
594
+
595
+ if (this.opts.autoformat === false) return true;
596
+ if (this.opts.visual)
597
+ {
598
+ var theBody = this.doc.body;
599
+
600
+ /* Remove all text nodes containing just whitespace */
601
+ for (var i = 0; i < theBody.childNodes.length; i++)
602
+ {
603
+ if (theBody.childNodes[i].nodeName.toLowerCase() == "#text" && theBody.childNodes[i].data.search(/^\s*$/) != -1)
604
+ {
605
+ theBody.removeChild(theBody.childNodes[i]);
606
+ i--;
607
+ }
608
+ }
609
+
610
+ var removedElements = new Array();
611
+ for (var i = 0; i < theBody.childNodes.length; i++)
612
+ {
613
+ if (theBody.childNodes[i].nodeName.isInlineName())
614
+ {
615
+ removedElements.push(theBody.childNodes[i].cloneNode(true));
616
+ theBody.removeChild(theBody.childNodes[i]);
617
+ i--;
618
+ }
619
+ else if (theBody.childNodes[i].nodeName.toLowerCase() == "br")
620
+ {
621
+ if (i + 1 < theBody.childNodes.length)
622
+ {
623
+ if (theBody.childNodes[i + 1].nodeName.toLowerCase() == "br")
624
+ {
625
+ while (i < theBody.childNodes.length && theBody.childNodes[i].nodeName.toLowerCase() == "br")
626
+ {
627
+ theBody.removeChild(theBody.childNodes[i]);
628
+ }
629
+
630
+ if (removedElements.length > 0)
631
+ {
632
+ this.insertNewParagraph(removedElements, theBody.childNodes[i]);
633
+ removedElements = new Array();
634
+ }
635
+ }
636
+ else if (!theBody.childNodes[i + 1].nodeName.isInlineName()) theBody.removeChild(theBody.childNodes[i]);
637
+ else if (removedElements.length > 0)
638
+ {
639
+ removedElements.push(theBody.childNodes[i].cloneNode(true));
640
+ theBody.removeChild(theBody.childNodes[i]);
641
+ }
642
+ else theBody.removeChild(theBody.childNodes[i]);
643
+ i--;
644
+ }
645
+ else theBody.removeChild(theBody.childNodes[i]);
646
+ }
647
+ else if (removedElements.length > 0)
648
+ {
649
+ this.insertNewParagraph(removedElements, theBody.childNodes[i]);
650
+ removedElements = new Array();
651
+ }
652
+ }
653
+
654
+ if (removedElements.length > 0) this.insertNewParagraph(removedElements);
655
+ }
656
+
657
+ return true;
658
+ },
659
+ insertNewParagraph: function(elementArray, succeedingElement)
660
+ {
661
+ var theBody = this.doc.getElementsByTagName("body")[0];
662
+ var theParagraph = this.doc.createElement("p");
663
+
664
+ for (var i = 0; i < elementArray.length; i++) theParagraph.appendChild(elementArray[i]);
665
+
666
+ if (typeof(succeedingElement) != "undefined") theBody.insertBefore(theParagraph, succeedingElement);
667
+ else theBody.appendChild(theParagraph);
668
+
669
+ return true;
670
+ },
671
+
672
+ /*
673
+ Selection
674
+ */
675
+ get_selection: function ()
676
+ {
677
+ if (this.frame.get(0).contentWindow.getSelection) return this.frame.get(0).contentWindow.getSelection();
678
+ else if (this.frame.get(0).contentWindow.document.selection) return this.frame.contentWindow.get(0).document.selection.createRange();
679
+ },
680
+
681
+ setCut: function()
682
+ {
683
+ this.execCommand('inserthtml', '<hr class="redactor_cut" />');
684
+ },
685
+
686
+ /*
687
+ Toggle
688
+ */
689
+ toggle: function()
690
+ {
691
+ if (this.opts.visual)
692
+ {
693
+ this.addSelButton('html');
694
+
695
+ var html = this.getHtml();
696
+
697
+ html = this.tidyUp(html);
698
+
699
+ html = html.replace(/\%7B/gi, '{');
700
+ html = html.replace(/\%7D/gi, '}');
701
+
702
+ // flash replace
703
+ html = html.replace(/<p(.*?)class="redactor_video_box"(.*?)>([\w\W]*?)\<\/p>/gi, "$3");
704
+
705
+ // files replace
706
+ 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>");
707
+
708
+ // cut replace
709
+ html = html.replace(/<hr class="redactor_cut"\/>/gi, '<!--more-->');
710
+ html = html.replace(/<hr class=redactor_cut>/gi, '<!--more-->');
711
+
712
+
713
+ this.frame.hide();
714
+ this.$el.val(html);
715
+ this.$el.show().focus();
716
+
717
+ var height = this.$el.height();
718
+
719
+ this.opts.visual = false;
720
+ }
721
+ else
722
+ {
723
+ this.removeSelButton('html');
724
+ this.$el.hide();
725
+
726
+ var html = this.$el.val();
727
+
728
+ // cut replace
729
+ html = html.replace(/<!--more-->/gi, '<hr class="redactor_cut"/>');
730
+
731
+ // flash replace
732
+ html = html.replace(/\<object([\w\W]*?)\<\/object\>/gi, '<p class="redactor_video_box"><object$1</object></p>');
733
+
734
+ // files replace
735
+ 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>");
736
+
737
+
738
+ this.opts.visual = true;
739
+
740
+ this.setHtml(html);
741
+
742
+ this.frame.show();
743
+ this.focus();
744
+ }
745
+ },
746
+
747
+
748
+ /*
749
+ Video
750
+ */
751
+ showVideo: function()
752
+ {
753
+ redactorActive = this;
754
+ this.modalInit(RLANG.video, this.opts.paths.dialogs.video, 600, 360, function()
755
+ {
756
+ $('#redactor_insert_video_area').focus();
757
+ });
758
+ },
759
+ insertVideo: function()
760
+ {
761
+ var data = $('#redactor_insert_video_area').val();
762
+ if (redactorActive.opts.visual)
763
+ {
764
+ // iframe video
765
+ if (data.search('iframe')) {}
766
+ // flash
767
+ else data = '<p class="redactor_video_box">' + data + '</p>';
768
+ }
769
+
770
+ redactorActive.execCommand('inserthtml', data);
771
+ this.modalClose();
772
+
773
+ },
774
+
775
+
776
+
777
+ /*
778
+ File
779
+ */
780
+ showFile: function()
781
+ {
782
+ redactorActive = this;
783
+
784
+ var handler = function()
785
+ {
786
+ // upload params
787
+ var params = '';
788
+ if (this.opts.fileUploadCallback) params = this.opts.fileUploadCallback();
789
+
790
+ $('#redactor_file').dragupload(
791
+ {
792
+ url: this.opts.paths.files.upload + params,
793
+ success: function(data)
794
+ {
795
+ this.fileUploadCallback(data);
796
+
797
+ }.bind2(this)
798
+ });
799
+
800
+ this.uploadInit('redactor_file', { auto: true, url: this.opts.paths.files.upload + params, success: function(data) {
801
+
802
+ this.fileUploadCallback(data);
803
+
804
+ }.bind2(this) });
805
+
806
+
807
+ }.bind2(this);
808
+
809
+
810
+ redactorActive = this;
811
+ this.modalInit(RLANG.file, this.opts.paths.dialogs.file, 500, 400, handler);
812
+ },
813
+ fileUploadCallback: function(data)
814
+ {
815
+ redactorActive.frame.get(0).contentWindow.focus();
816
+ redactorActive.execCommand('inserthtml', data);
817
+ this.modalClose();
818
+ this.docObserve();
819
+ },
820
+ fileEdit: function(e)
821
+ {
822
+ var el = e.target;
823
+ var file_id = $(el).attr('rel');
824
+
825
+ var handler = function()
826
+ {
827
+ $('#file').val($(el).text());
828
+ $('#redactorFileDeleteBtn').click(function()
829
+ {
830
+ this.fileDelete(el, file_id);
831
+ }.bind2(this));
832
+
833
+ $('#redactorFileDownloadBtn').click(function()
834
+ {
835
+ this.fileDownload(el, file_id);
836
+ }.bind2(this));
837
+
838
+ }.bind2(this);
839
+
840
+ redactorActive = this;
841
+ this.modalInit(RLANG.file, this.opts.paths.dialogs.fileEdit, 400, 200, handler);
842
+ },
843
+ fileDelete: function(el, file_id)
844
+ {
845
+ $(el).remove();
846
+ $.get(this.opts.paths.files.remove + file_id);
847
+ redactorActive.frame.get(0).contentWindow.focus();
848
+ this.modalClose();
849
+ },
850
+ fileDownload: function(el, file_id)
851
+ {
852
+ top.location.href = this.opts.paths.files.download + file_id;
853
+ },
854
+
855
+ /*
856
+ Table
857
+ */
858
+ showTable: function()
859
+ {
860
+ redactorActive = this;
861
+ this.modalInit(RLANG.table, this.opts.paths.dialogs.table, 360, 200);
862
+ },
863
+ insertTable: function()
864
+ {
865
+ var rows = $('#redactor_table_rows').val();
866
+ var columns = $('#redactor_table_columns').val();
867
+
868
+ var table_box = $('<div></div>');
869
+
870
+ var tableid = Math.floor(Math.random() * 99999);
871
+ var table = $('<table id="table' + tableid + '"><tbody></tbody></table>');
872
+
873
+ for (i = 0; i < rows; i++)
874
+ {
875
+ var row = $('<tr></tr>')
876
+ for (z = 0; z < columns; z++)
877
+ {
878
+ var column = $('<td>&nbsp;</td>');
879
+ $(row).append(column);
880
+ }
881
+ $(table).append(row);
882
+ }
883
+
884
+ $(table_box).append(table);
885
+ var html = $(table_box).html();
886
+ if ($.browser.msie) html += '<p></p>';
887
+ else html += '<p>&nbsp;</p>';
888
+
889
+ redactorActive.execCommand('inserthtml', html);
890
+ this.enableObjects();
891
+ this.docObserve();
892
+ this.modalClose();
893
+
894
+ $table = $(this.doc).find('body').find('#table' + tableid);
895
+
896
+
897
+ },
898
+ tableObserver: function(e)
899
+ {
900
+ $table = $(e.target).parents('table');
901
+
902
+ $tbody = $(e.target).parents('tbody');
903
+ $thead = $($table).find('thead');
904
+
905
+ $current_td = $(e.target);
906
+ $current_tr = $(e.target).parents('tr');
907
+ },
908
+ deleteTable: function()
909
+ {
910
+ $($table).remove();
911
+ $table = false;
912
+ },
913
+ deleteRow: function()
914
+ {
915
+ $($current_tr).remove();
916
+ },
917
+ deleteColumn: function()
918
+ {
919
+ var index = $($current_td).attr('cellIndex');
920
+
921
+ $($table).find('tr').each(function()
922
+ {
923
+ $(this).find('td').eq(index).remove();
924
+ });
925
+ },
926
+ addHead: function()
927
+ {
928
+ if ($($table).find('thead').size() != 0) this.deleteHead();
929
+ else
930
+ {
931
+ var tr = $($table).find('tr').first().clone();
932
+ tr.find('td').html('&nbsp;');
933
+ $thead = $('<thead></thead>');
934
+ $thead.append(tr);
935
+ $($table).prepend($thead);
936
+ }
937
+ },
938
+ deleteHead: function()
939
+ {
940
+ $($thead).remove();
941
+ $thead = false;
942
+ },
943
+ insertRowAbove: function()
944
+ {
945
+ this.insertRow('before');
946
+ },
947
+ insertRowBelow: function()
948
+ {
949
+ this.insertRow('after');
950
+ },
951
+ insertColumnLeft: function()
952
+ {
953
+ this.insertColumn('before');
954
+ },
955
+ insertColumnRight: function()
956
+ {
957
+ this.insertColumn('after');
958
+ },
959
+ insertRow: function(type)
960
+ {
961
+ var new_tr = $($current_tr).clone();
962
+ new_tr.find('td').html('&nbsp;');
963
+ if (type == 'after') $($current_tr).after(new_tr);
964
+ else $($current_tr).before(new_tr);
965
+ },
966
+ insertColumn: function(type)
967
+ {
968
+ var index = $($current_td).attr('cellIndex');
969
+
970
+ $($table).find('tr').each(function(i,s)
971
+ {
972
+ var current = $(s).find('td').eq(index);
973
+ var td = current.clone();
974
+ td.html('&nbsp;');
975
+ if (type == 'after') $(current).after(td);
976
+ else $(current).before(td);
977
+ });
978
+ },
979
+
980
+ /*
981
+ Image
982
+ */
983
+ imageEdit: function(e)
984
+ {
985
+ var handler = function()
986
+ {
987
+ var $el = $(e.target);
988
+ var src = $el.attr('src');
989
+ $('#redactor_image_edit_src').attr('href', src);
990
+ $('#redactor_image_edit_delete').click(function() { this.deleteImage(e.target); }.bind2(this));
991
+ $('#redactorSaveBtn').click(function() { this.imageSave(e.target); }.bind2(this));
992
+
993
+ $('#redactor_file_alt').val($el.attr('alt'));
994
+
995
+ var float = $el.css('float');
996
+ if (float == 'none') float = 0;
997
+
998
+ $('#redactor_form_image_align').val(float);
999
+
1000
+ }.bind2(this);
1001
+
1002
+ redactorActive = this;
1003
+ this.modalInit(RLANG.image, this.opts.paths.dialogs.imageEdit, 380, 290, handler);
1004
+ },
1005
+ imageSave: function(el)
1006
+ {
1007
+ $(el).attr('alt', $('#redactor_file_alt').val());
1008
+
1009
+ var style = '';
1010
+ if ($('#redactor_form_image_align') != 0)
1011
+ {
1012
+ var float = $('#redactor_form_image_align').val();
1013
+
1014
+ // @tanraya AddedClasses
1015
+ $(el).removeClass('img_left').removeClass('img_right')
1016
+
1017
+ if (float == 'left')
1018
+ $(el).addClass('img_left');
1019
+ else if (float == 'right')
1020
+ $(el).addClass('img_right')
1021
+ }
1022
+ else $(el).css({ float: 'none', margin: '0' });
1023
+
1024
+ this.modalClose();
1025
+ },
1026
+ deleteImage: function(el)
1027
+ {
1028
+ $(el).remove();
1029
+ this.modalClose();
1030
+ },
1031
+ showImage: function()
1032
+ {
1033
+ this.spanid = Math.floor(Math.random() * 99999);
1034
+ if (jQuery.browser.msie)
1035
+ {
1036
+ this.execCommand('inserthtml', '<span id="span' + this.spanid + '"></span>');
1037
+ }
1038
+
1039
+ var handler = function() {
1040
+ if (this.opts.paths.images.list !== false) {
1041
+ $.getJSON(this.opts.paths.images.list, function(data) {
1042
+ $.each(data, function(key, val) {
1043
+ var img = $('<img src="' + val.thumb + '" rel="' + val.image + '">');
1044
+ img.click(function() { redactorActive.imageSetThumb($(this).attr('rel')); });
1045
+ $('#redactor_image_box').append(img);
1046
+ });
1047
+ });
1048
+ } else {
1049
+ $('#redactor_tabs li').eq(0).remove();
1050
+ $('#redactor_tabs a').eq(1).addClass('redactor_tabs_act');
1051
+ $('#redactor_tabs1').hide();
1052
+ $('#redactor_tabs2').show();
1053
+ }
1054
+
1055
+ // upload params
1056
+ var params = '';
1057
+ if (this.opts.imageUploadCallback) var params = this.opts.imageUploadCallback();
1058
+
1059
+ $('#redactor_file').dragupload({
1060
+ url : this.opts.paths.images.upload + params,
1061
+ success : function(data) {
1062
+ this.imageUploadCallback(data);
1063
+ }.bind2(this)
1064
+ });
1065
+
1066
+ this.uploadInit('redactor_file', {
1067
+ auto : true,
1068
+ url : this.opts.paths.images.upload + params,
1069
+ trigger : 'redactorUploadBtn',
1070
+ success : function(data) {
1071
+ this.imageUploadCallback(data);
1072
+ }.bind2(this)});
1073
+ }.bind2(this);
1074
+
1075
+ redactorActive = this;
1076
+ this.modalInit(RLANG.image, this.opts.paths.dialogs.image, 570, 450, handler);
1077
+
1078
+ },
1079
+ imageSetThumb: function(data)
1080
+ {
1081
+ this._imageSet('<img alt="" src="' + data + '" />');
1082
+ },
1083
+ imageUploadCallback: function(data)
1084
+ {
1085
+ if ($('#redactor_file_link').val() != '') data = $('#redactor_file_link').val();
1086
+
1087
+ this._imageSet(data);
1088
+
1089
+ },
1090
+ _imageSet: function(html)
1091
+ {
1092
+ redactorActive.frame.get(0).contentWindow.focus();
1093
+
1094
+ if ($.browser.msie)
1095
+ {
1096
+ $(redactorActive.doc.getElementById('span' + redactorActive.spanid)).after(html);
1097
+ $(redactorActive.doc.getElementById('span' + redactorActive.spanid)).remove();
1098
+ }
1099
+ else
1100
+ {
1101
+ redactorActive.execCommand('inserthtml', html);
1102
+ }
1103
+
1104
+ this.modalClose();
1105
+ this.docObserve();
1106
+ },
1107
+
1108
+
1109
+ /*
1110
+ Link
1111
+ */
1112
+ showLink: function()
1113
+ {
1114
+ redactorActive = this;
1115
+
1116
+ var handler = function()
1117
+ {
1118
+ var sel = this.get_selection();
1119
+ if ($.browser.msie)
1120
+ {
1121
+ var temp = sel.htmlText.match(/href="(.*?)"/gi);
1122
+ if (temp != null)
1123
+ {
1124
+ temp = new String(temp);
1125
+ temp = temp.replace(/href="(.*?)"/gi, '$1');
1126
+ }
1127
+
1128
+ var text = sel.text;
1129
+ if (temp != null) var url = temp;
1130
+ else var url = '';
1131
+ var title = '';
1132
+ }
1133
+ else
1134
+ {
1135
+ if (sel.anchorNode.parentNode.tagName == 'A')
1136
+ {
1137
+ var url = sel.anchorNode.parentNode.href;
1138
+ var text = sel.anchorNode.parentNode.text;
1139
+ var title = sel.anchorNode.parentNode.title;
1140
+ if (sel.toString() == '') this.insert_link_node = sel.anchorNode.parentNode
1141
+
1142
+ }
1143
+ else
1144
+ {
1145
+ var text = sel.toString();
1146
+ var url = '';
1147
+ var title = '';
1148
+ }
1149
+ }
1150
+
1151
+ $('#redactor_link_url').val(url).focus();
1152
+ $('#redactor_link_text').val(text);
1153
+ $('#redactor_link_title').val(title);
1154
+
1155
+ }.bind2(this);
1156
+
1157
+ this.modalInit(RLANG.link, this.opts.paths.dialogs.link, 400, 300, handler);
1158
+
1159
+ },
1160
+ insertLink: function()
1161
+ {
1162
+ var value = $('#redactor_link_text').val();
1163
+ if (value == '') return true;
1164
+
1165
+ var title = $('#redactor_link_title').val();
1166
+ if (title != '') title = ' title="' + $('#redactor_link_title').val() + '"';
1167
+
1168
+ if ($('#redactor_link_id_url').get(0).checked) var mailto = '';
1169
+ else var mailto = 'mailto:';
1170
+
1171
+ var a = '<a href="' + mailto + $('#redactor_link_url').val() + '"' + title +'>' + value + '</a> ';
1172
+
1173
+ if (a)
1174
+ {
1175
+ if (this.insert_link_node)
1176
+ {
1177
+ $(this.insert_link_node).text(value);
1178
+ $(this.insert_link_node).attr('href', $('#redactor_link_url').val());
1179
+
1180
+ var title = $('#redactor_link_title').val();
1181
+ if (title != '') $(this.insert_link_node).attr('title', title);
1182
+
1183
+ this.modalClose();
1184
+ }
1185
+ else
1186
+ {
1187
+ redactorActive.frame.get(0).contentWindow.focus();
1188
+ redactorActive.execCommand('inserthtml', a);
1189
+ }
1190
+ }
1191
+
1192
+ this.modalClose();
1193
+ },
1194
+
1195
+
1196
+ /*
1197
+ Modal
1198
+ */
1199
+ modalInit: function(title, url, width, height, handler, scroll)
1200
+ {
1201
+ if (this.opts.overlay)
1202
+ {
1203
+ $('#redactor_imp_modal_overlay').show();
1204
+ $('#redactor_imp_modal_overlay').click(function() { this.modalClose(); }.bind2(this));
1205
+ }
1206
+
1207
+ if ($('#redactor_imp_modal').size() == 0)
1208
+ {
1209
+ 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>');
1210
+ $('body').append(this.modal);
1211
+ }
1212
+
1213
+ $('#redactor_imp_modal_close').click(function() { this.modalClose(); }.bind2(this));
1214
+ $(document).keyup(function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1215
+ $(this.doc).keyup(function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1216
+
1217
+ $.ajax({
1218
+ url: url,
1219
+ success: function(data)
1220
+ {
1221
+ // parse lang
1222
+ $.each(RLANG, function(i,s)
1223
+ {
1224
+ var re = new RegExp("%RLANG\." + i + "%","gi");
1225
+ data = data.replace(re, s);
1226
+ });
1227
+
1228
+ $('#redactor_imp_modal_inner').html(data);
1229
+ $('#redactor_imp_modal_header').html(title);
1230
+
1231
+ if (height === false) theight = 'auto';
1232
+ else theight = height + 'px';
1233
+
1234
+ $('#redactor_imp_modal').css({ width: width + 'px', height: theight, marginTop: '-' + height/2 + 'px', marginLeft: '-' + width/2 + 'px' }).fadeIn('fast');
1235
+
1236
+ if (scroll === true)
1237
+ {
1238
+ $('#imp_redactor_table_box').height(height-$('#redactor_imp_modal_header').outerHeight()-130).css('overflow', 'auto');
1239
+ }
1240
+
1241
+ if (typeof(handler) == 'function') handler();
1242
+
1243
+
1244
+ }.bind2(this)
1245
+ });
1246
+ },
1247
+ modalClose: function()
1248
+ {
1249
+
1250
+ $('#redactor_imp_modal_close').unbind('click', function() { this.modalClose(); }.bind2(this));
1251
+ $('#redactor_imp_modal').fadeOut('fast', function()
1252
+ {
1253
+ $('#redactor_imp_modal_inner').html('');
1254
+
1255
+ if (this.opts.overlay)
1256
+ {
1257
+ $('#redactor_imp_modal_overlay').hide();
1258
+ $('#redactor_imp_modal_overlay').unbind('click', function() { this.modalClose(); }.bind2(this));
1259
+ }
1260
+
1261
+ $(document).unbind('keyup', function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1262
+ $(this.doc).unbind('keyup', function(e) { if( e.keyCode == 27) this.modalClose(); }.bind2(this));
1263
+
1264
+ }.bind2(this));
1265
+
1266
+ },
1267
+
1268
+ /*
1269
+ Upload
1270
+ */
1271
+ uploadInit: function(element, options)
1272
+ {
1273
+ /*
1274
+ Options
1275
+ */
1276
+ this.uploadOptions = {
1277
+ url: false,
1278
+ success: false,
1279
+ start: false,
1280
+ trigger: false,
1281
+ auto: false,
1282
+ input: false
1283
+ };
1284
+
1285
+ $.extend(this.uploadOptions, options);
1286
+
1287
+
1288
+ // Test input or form
1289
+ if ($('#' + element).get(0).tagName == 'INPUT')
1290
+ {
1291
+ this.uploadOptions.input = $('#' + element);
1292
+ this.element = $($('#' + element).get(0).form);
1293
+ }
1294
+ else
1295
+ {
1296
+ this.element = $('#' + element);
1297
+ }
1298
+
1299
+
1300
+ this.element_action = this.element.attr('action');
1301
+
1302
+ // Auto or trigger
1303
+ if (this.uploadOptions.auto)
1304
+ {
1305
+ $(this.uploadOptions.input).change(function()
1306
+ {
1307
+ this.element.submit(function(e) { return false; });
1308
+ this.uploadSubmit();
1309
+ }.bind2(this));
1310
+
1311
+ }
1312
+ else if (this.uploadOptions.trigger)
1313
+ {
1314
+ $('#' + this.uploadOptions.trigger).click(function() { this.uploadSubmit(); }.bind2(this));
1315
+ }
1316
+ },
1317
+ uploadSubmit : function()
1318
+ {
1319
+ this.uploadForm(this.element, this.uploadFrame());
1320
+ },
1321
+ uploadFrame : function()
1322
+ {
1323
+ this.id = 'f' + Math.floor(Math.random() * 99999);
1324
+
1325
+ var d = document.createElement('div');
1326
+ var iframe = '<iframe style="display:none" src="about:blank" id="'+this.id+'" name="'+this.id+'"></iframe>';
1327
+ d.innerHTML = iframe;
1328
+ document.body.appendChild(d);
1329
+
1330
+ // Start
1331
+ if (this.uploadOptions.start) this.uploadOptions.start();
1332
+
1333
+ $('#' + this.id).load(function () { this.uploadLoaded() }.bind2(this));
1334
+
1335
+ return this.id;
1336
+ },
1337
+ uploadForm : function(f, name)
1338
+ {
1339
+ if (this.uploadOptions.input)
1340
+ {
1341
+ var formId = 'redactorUploadForm' + this.id;
1342
+ var fileId = 'redactorUploadFile' + this.id;
1343
+ this.form = $('<form action="' + this.uploadOptions.url + '" method="POST" target="' + name + '" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
1344
+
1345
+ var oldElement = this.uploadOptions.input;
1346
+ var newElement = $(oldElement).clone();
1347
+ $(oldElement).attr('id', fileId);
1348
+ $(oldElement).before(newElement);
1349
+ $(oldElement).appendTo(this.form);
1350
+ $(this.form).css('position', 'absolute');
1351
+ $(this.form).css('top', '-2000px');
1352
+ $(this.form).css('left', '-2000px');
1353
+ $(this.form).appendTo('body');
1354
+
1355
+ this.form.submit();
1356
+ }
1357
+ else
1358
+ {
1359
+ f.attr('target', name);
1360
+ f.attr('method', 'POST');
1361
+ f.attr('enctype', 'multipart/form-data');
1362
+ f.attr('action', this.uploadOptions.url);
1363
+
1364
+ this.element.submit();
1365
+ }
1366
+
1367
+ },
1368
+ uploadLoaded : function()
1369
+ {
1370
+ var i = $('#' + this.id);
1371
+
1372
+ if (i.contentDocument) var d = i.contentDocument;
1373
+ else if (i.contentWindow) var d = i.contentWindow.document;
1374
+ else var d = window.frames[this.id].document;
1375
+
1376
+ if (d.location.href == "about:blank") return true;
1377
+
1378
+ // Success
1379
+ if (this.uploadOptions.success) this.uploadOptions.success(d.body.innerHTML);
1380
+
1381
+ this.element.attr('action', this.element_action);
1382
+ this.element.attr('target', '');
1383
+ //this.element.unbind('submit');
1384
+ //if (this.uploadOptions.input) $(this.form).remove();
1385
+ },
1386
+
1387
+ /*
1388
+ Toolbar
1389
+ */
1390
+ buildToolbar: function()
1391
+ {
1392
+ this.toolbar = $('<ul id="imp_redactor_toolbar_' + this.frameID + '" class="imp_redactor_toolbar"></ul>');
1393
+
1394
+ if (this.opts.air)
1395
+ {
1396
+ $(this.air).append(this.toolbar);
1397
+ this.box.prepend(this.air);
1398
+ }
1399
+ else $(this.box).prepend(this.toolbar);
1400
+
1401
+
1402
+ $.each(RTOOLBAR,
1403
+ function (i, s)
1404
+ {
1405
+ if (s.name == 'separator')
1406
+ {
1407
+ var li = $('<li class="separator"></li>');
1408
+ $(this.toolbar).append(li);
1409
+ }
1410
+ else
1411
+ {
1412
+
1413
+ var a = $('<a href="javascript:void(null);" class="imp_btn imp_btn_' + s.name + '" title="' + s.title + '"></a>');
1414
+
1415
+ if (typeof(s.func) == 'undefined') a.click(function() { this.execCommand(s.exec, s.name); }.bind2(this));
1416
+ else if (s.func != 'show') a.click(function(e) { this[s.func](e); }.bind2(this));
1417
+
1418
+ var li = $('<li class="imp_li_btn imp_li_btn_' + s.name + '"></li>');
1419
+ $(li).append(a);
1420
+ $(this.toolbar).append(li);
1421
+
1422
+ // build dropdown box
1423
+ if (s.name == 'backcolor' || s.name == 'fontcolor' || typeof(s.dropdown) != 'undefined')
1424
+ {
1425
+ 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>');
1426
+ if ($.browser.msie) ul.css({ borderLeft: '1px solid #ddd', borderRight: '1px solid #ddd', borderBottom: '1px solid #ddd' });
1427
+ }
1428
+
1429
+ // build dropdown
1430
+ if (typeof(s.dropdown) != 'undefined')
1431
+ {
1432
+
1433
+ $.each(s.dropdown,
1434
+ function (x, d)
1435
+ {
1436
+ if (typeof(d.style) == 'undefined') d.style = '';
1437
+
1438
+ if (d.name == 'separator')
1439
+ {
1440
+ var ul_li = $('<li class="separator_drop"></li>');
1441
+ $(ul).append(ul_li);
1442
+ }
1443
+ else
1444
+ {
1445
+
1446
+ var ul_li = $('<li></li>');
1447
+ var ul_li_a = $('<a href="javascript:void(null);" style="' + d.style + '">' + d.title + '</a>');
1448
+ $(ul_li).append(ul_li_a);
1449
+ $(ul).append(ul_li);
1450
+
1451
+ if (typeof(d.func) == 'undefined') $(ul_li_a).click(function() { this.execCommand(d.exec, d.name); }.bind2(this));
1452
+ else $(ul_li_a).click(function(e) { this[d.func](e); }.bind2(this));
1453
+ }
1454
+
1455
+
1456
+
1457
+ }.bind2(this)
1458
+ );
1459
+ }
1460
+ else a.mouseover(function() { this.hideAllDropDown() }.bind2(this));
1461
+
1462
+ // observing dropdown
1463
+ if (s.name == 'backcolor' || s.name == 'fontcolor' || typeof(s.dropdown) != 'undefined')
1464
+ {
1465
+ $('#imp_redactor_toolbar_' + this.frameID).after(ul);
1466
+
1467
+ this.hdlHideDropDown = function(e) { this.hideDropDown(e, ul, s.name) }.bind2(this);
1468
+ this.hdlShowDropDown = function(e) { this.showDropDown(e, ul, s.name) }.bind2(this);
1469
+ this.hdlShowerDropDown = function(e) { this.showerDropDown(e, ul, s.name) }.bind2(this);
1470
+
1471
+ a.click(this.hdlShowDropDown).mouseover(this.hdlShowerDropDown);
1472
+
1473
+ $(document).click(this.hdlHideDropDown);
1474
+ }
1475
+
1476
+
1477
+ }
1478
+ }.bind2(this)
1479
+ );
1480
+ },
1481
+
1482
+ /*
1483
+ DropDown
1484
+ */
1485
+ showedDropDown: false,
1486
+ showDropDown: function(e, ul, name)
1487
+ {
1488
+
1489
+ if (this.showedDropDown) this.hideAllDropDown();
1490
+ else
1491
+ {
1492
+ this.showedDropDown = true;
1493
+ this.showingDropDown(e, ul, name);
1494
+ }
1495
+
1496
+ },
1497
+ showingDropDown: function(e, ul, name)
1498
+ {
1499
+ this.hideAllDropDown();
1500
+ this.addSelButton(name);
1501
+
1502
+ var left = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name).position().left;
1503
+ $(ul).css('left', left + 'px').show();
1504
+ },
1505
+ showerDropDown: function(e, ul, name)
1506
+ {
1507
+ if (this.showedDropDown) this.showingDropDown(e, ul, name);
1508
+ },
1509
+ hideAllDropDown: function()
1510
+ {
1511
+ $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn').removeClass('act');
1512
+ $('ul.imp_redactor_drop_down' + this.frameID).hide();
1513
+ },
1514
+ hideDropDown: function(e, ul, name)
1515
+ {
1516
+ if (!$(e.target).parent().hasClass('act'))
1517
+ {
1518
+ this.showedDropDown = false;
1519
+ this.hideAllDropDown();
1520
+ }
1521
+
1522
+ $(document).unbind('click', this.hdlHideDropDown);
1523
+ $(this.doc).unbind('click', this.hdlHideDropDown);
1524
+
1525
+ },
1526
+ addSelButton: function(name)
1527
+ {
1528
+ var element = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name);
1529
+ element.addClass('act');
1530
+ },
1531
+ removeSelButton: function(name)
1532
+ {
1533
+ var element = $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name);
1534
+ element.removeClass('act');
1535
+ },
1536
+ toggleSelButton: function(name)
1537
+ {
1538
+ $('#imp_redactor_toolbar_' + this.frameID + ' li.imp_li_btn_' + name).toggleClass('act');
1539
+ },
1540
+
1541
+
1542
+ /*
1543
+ Resizer
1544
+ */
1545
+ initResize: function(e)
1546
+ {
1547
+ if (e.preventDefault) e.preventDefault();
1548
+ else e.returnValue = false;
1549
+
1550
+ this.splitter = e.target;
1551
+
1552
+ if (this.opts.visual)
1553
+ {
1554
+ this.element_resize = this.frame;
1555
+ this.element_resize.get(0).style.visibility = 'hidden';
1556
+ this.element_resize_parent = this.$el;
1557
+ }
1558
+ else
1559
+ {
1560
+ this.element_resize = this.$el;
1561
+ this.element_resize_parent = this.frame;
1562
+ }
1563
+
1564
+ this.stopResizeHdl = function (e) { this.stopResize(e) }.bind2(this);
1565
+ this.startResizeHdl = function (e) { this.startResize(e) }.bind2(this);
1566
+ this.resizeHdl = function (e) { this.resize(e) }.bind2(this);
1567
+
1568
+ $(document).mousedown(this.startResizeHdl);
1569
+ $(document).mouseup(this.stopResizeHdl);
1570
+ $(this.splitter).mouseup(this.stopResizeHdl);
1571
+
1572
+ this.null_point = false;
1573
+ this.h_new = false;
1574
+ this.h = this.element_resize.height();
1575
+ },
1576
+ startResize: function()
1577
+ {
1578
+ $(document).mousemove(this.resizeHdl);
1579
+ },
1580
+ resize: function(e)
1581
+ {
1582
+ if (e.preventDefault) e.preventDefault();
1583
+ else e.returnValue = false;
1584
+
1585
+ var y = e.pageY;
1586
+ if (this.null_point == false) this.null_point = y;
1587
+ if (this.h_new == false) this.h_new = this.element_resize.height();
1588
+
1589
+ var s_new = (this.h_new + y - this.null_point) - 10;
1590
+
1591
+ if (s_new <= 30) return true;
1592
+
1593
+ if (s_new >= 0)
1594
+ {
1595
+ this.element_resize.get(0).style.height = s_new + 'px';
1596
+ this.element_resize_parent.get(0).style.height = s_new + 'px';
1597
+ }
1598
+ },
1599
+ stopResize: function(e)
1600
+ {
1601
+ $(document).unbind('mousemove', this.resizeHdl);
1602
+ $(document).unbind('mousedown', this.startResizeHdl);
1603
+ $(document).unbind('mouseup', this.stopResizeHdl);
1604
+ $(this.splitter).unbind('mouseup', this.stopResizeHdl);
1605
+
1606
+ this.element_resize.get(0).style.visibility = 'visible';
1607
+ }
1608
+
1609
+ };
1610
+
1611
+
1612
+ String.prototype.isInlineName = function()
1613
+ {
1614
+ var inlineList = new Array("#text", "a", "em", "font", "span", "strong", "u");
1615
+ var theName = this.toLowerCase();
1616
+
1617
+ for (var i = 0; i < inlineList.length; i++)
1618
+ {
1619
+ if (theName == inlineList[i])
1620
+ {
1621
+ return true;
1622
+ }
1623
+ }
1624
+
1625
+ return false;
1626
+ };
1627
+
1628
+
1629
+ // bind2
1630
+ Function.prototype.bind2 = function(object)
1631
+ {
1632
+ var method = this; var oldArguments = $.makeArray(arguments).slice(1);
1633
+ return function (argument)
1634
+ {
1635
+ if (argument == new Object) { method = null; oldArguments = null; }
1636
+ else if (method == null) throw "Attempt to invoke destructed method reference.";
1637
+ else { var newArguments = $.makeArray(arguments); return method.apply(object, oldArguments.concat(newArguments)); }
1638
+ };
1639
+ };
1640
+
1641
+
1642
+ })(jQuery);
1643
+
1644
+ // redactor_tabs
1645
+ function showRedactorTabs(el, index)
1646
+ {
1647
+ $('#redactor_tabs a').removeClass('redactor_tabs_act');
1648
+ $(el).addClass('redactor_tabs_act');
1649
+
1650
+ $('.redactor_tabs').hide();
1651
+ $('#redactor_tabs' + index).show();
1652
+ }
1653
+
1654
+
1655
+ // Define: Linkify plugin from stackoverflow
1656
+ (function($){
1657
+ var url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g;
1658
+
1659
+ linkifyThis = function ()
1660
+ {
1661
+ var childNodes = this.childNodes,
1662
+ i = childNodes.length;
1663
+ while(i--)
1664
+ {
1665
+ var n = childNodes[i];
1666
+ if (n.nodeType == 3)
1667
+ {
1668
+ var html = n.nodeValue;
1669
+ if (html)
1670
+ {
1671
+ html = html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(url2, '$1<a href="$2">$2</a>$5');
1672
+ $(n).after(html).remove();
1673
+ }
1674
+ }
1675
+ else if (n.nodeType == 1 && !/^(a|button|textarea)$/i.test(n.tagName)) linkifyThis.call(n);
1676
+ }
1677
+ };
1678
+
1679
+ $.fn.linkify = function ()
1680
+ {
1681
+ this.each(linkifyThis);
1682
+ };
1683
+
1684
+ })(jQuery);
1685
+
1686
+
1687
+ /* jQuery plugin textselect
1688
+ * version: 0.9
1689
+ * author: Josef Moravec, josef.moravec@gmail.com
1690
+ * updated: Imperavi
1691
+ *
1692
+ */
1693
+ (function($){$.event.special.textselect={setup:function(data,namespaces)
1694
+ {$(this).data("textselected",false);$(this).data("ttt",data);$(this).bind('mouseup',$.event.special.textselect.handler);},teardown:function(data)
1695
+ {$(this).unbind('mouseup',$.event.special.textselect.handler);},handler:function(event)
1696
+ {var data=$(this).data("ttt");var text=$.event.special.textselect.getSelectedText(data).toString();if(text!='')
1697
+ {$(this).data("textselected",true);event.type="textselect";event.text=text;$.event.handle.apply(this,arguments);}},getSelectedText:function(data)
1698
+ {var text='';var frame=$('#imp_redactor_frame_'+data).get(0);if(frame.contentWindow.getSelection)text=frame.contentWindow.getSelection();else if(frame.contentWindow.document.getSelection) text=frame.contentWindow.document.getSelection();else if(frame.contentWindow.document.selection)text=frame.contentWindow.document.selection.createRange().text;return text;}}
1699
+ $.event.special.textunselect={setup:function(data,namespaces){$(this).data("rttt",data);$(this).data("textselected",false);$(this).bind('mouseup',$.event.special.textunselect.handler);$(this).bind('keyup',$.event.special.textunselect.handlerKey)},teardown:function(data){$(this).unbind('mouseup',$.event.special.textunselect.handler);},handler:function(event){if($(this).data("textselected")){var data=$(this).data("rttt");var text=$.event.special.textselect.getSelectedText(data).toString();if(text==''){$(this).data("textselected",false);event.type="textunselect";$.event.handle.apply(this,arguments);}}},handlerKey:function(event){if($(this).data("textselected")){var data=$(this).data("rttt");var text=$.event.special.textselect.getSelectedText(data).toString();if((event.keyCode=27)&&(text=='')){$(this).data("textselected",false);event.type="textunselect";$.event.handle.apply(this,arguments);}}}}})(jQuery);
1700
+
1701
+
1702
+ /*
1703
+ Plugin Drag and drop Upload v1.0.0
1704
+ http://imperavi.com/
1705
+ Copyright 2011, Imperavi Ltd.
1706
+ */
1707
+ (function($){
1708
+
1709
+ // Initialization
1710
+ $.fn.dragupload = function(options)
1711
+ {
1712
+ return this.each(function() {
1713
+ var obj = new Construct(this, options);
1714
+ obj.init();
1715
+ });
1716
+ };
1717
+
1718
+ // Options and variables
1719
+ function Construct(el, options) {
1720
+
1721
+ this.opts = $.extend({
1722
+
1723
+ url: false,
1724
+ success: false,
1725
+ maxfilesize: 10485760, // 10MB
1726
+ preview: false,
1727
+
1728
+ text: RLANG.drop_file_here,
1729
+ atext: RLANG.or_choose
1730
+
1731
+ /*
1732
+ success_text: 'Загрузка успешно завершена',
1733
+ progress_text: 'Загрузка',
1734
+ maxsize_error: 'Файл слишком большой'
1735
+ */
1736
+
1737
+
1738
+ }, options);
1739
+
1740
+ this.$el = $(el);
1741
+ };
1742
+
1743
+ // Functionality
1744
+ Construct.prototype = {
1745
+ init: function()
1746
+ {
1747
+ if (!$.browser.opera && !$.browser.msie)
1748
+ {
1749
+ this.droparea = $('<div class="redactor_droparea"></div>');
1750
+ this.dropareabox = $('<div class="redactor_dropareabox">' + this.opts.text + '</div>');
1751
+ this.dropalternative = $('<div class="redactor_dropalternative">' + this.opts.atext + '</div>');
1752
+
1753
+ this.droparea.append(this.dropareabox);
1754
+
1755
+ this.$el.before(this.droparea);
1756
+ this.$el.before(this.dropalternative);
1757
+
1758
+
1759
+ // drag over
1760
+ this.dropareabox.bind('dragover', function() { return this.ondrag(); }.bind2(this));
1761
+
1762
+ // drag leave
1763
+ this.dropareabox.bind('dragleave', function() { return this.ondragleave(); }.bind2(this));
1764
+
1765
+
1766
+ // drop
1767
+ this.dropareabox.get(0).ondrop = function(event) {
1768
+
1769
+ event.preventDefault();
1770
+
1771
+ this.dropareabox.removeClass('hover').addClass('drop');
1772
+
1773
+ var file = event.dataTransfer.files[0];
1774
+
1775
+
1776
+ /*
1777
+ if (file.size > this.opts.maxfilesize)
1778
+ {
1779
+ this.dropareabox.text(this.opts.maxsize_error).addClass('error');
1780
+ return false;
1781
+ }
1782
+
1783
+ var uploadProgress = function(e)
1784
+ {
1785
+ var percent = parseInt(e.loaded / e.total * 100);
1786
+ this.dropareabox.text(this.opts.progress_text + ': ' + percent + '%');
1787
+
1788
+ }.bind2(this);
1789
+
1790
+
1791
+ var xhr = jQuery.ajaxSettings.xhr();
1792
+ if (xhr.upload) xhr.upload.addEventListener('progress', uploadProgress, false);
1793
+ var provider = function () { return xhr; };
1794
+ */
1795
+
1796
+ var fd = new FormData();
1797
+ fd.append('file', file);
1798
+
1799
+ $.ajax({
1800
+ url: this.opts.url,
1801
+ data: fd,
1802
+ //xhr: provider,
1803
+ cache: false,
1804
+ contentType: false,
1805
+ processData: false,
1806
+ type: 'POST',
1807
+ success: function(data)
1808
+ {
1809
+ if (this.opts.success !== false) this.opts.success(data);
1810
+
1811
+ if (this.opts.preview === true) this.dropareabox.html(data);
1812
+ //else this.dropareabox.text(this.opts.success_text);
1813
+
1814
+ }.bind2(this)
1815
+ });
1816
+
1817
+
1818
+ }.bind2(this);
1819
+ }
1820
+ },
1821
+ ondrag: function()
1822
+ {
1823
+ this.dropareabox.addClass('hover');
1824
+ return false;
1825
+ },
1826
+ ondragleave: function()
1827
+ {
1828
+ this.dropareabox.removeClass('hover');
1829
+ return false;
1830
+ }
1831
+ };
1832
+
1833
+
1834
+ })(jQuery);