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