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