infopark_cloud_connector 6.8.3.2.153416031 → 6.8.3.67.110847540

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4451 @@
1
+ /*
2
+ Redactor v8.2.2
3
+ Updated: January 17, 2013
4
+
5
+ http://redactorjs.com/
6
+
7
+ Copyright (c) 2009-2013, Imperavi Inc.
8
+ License: http://redactorjs.com/license/
9
+
10
+ Usage: $('#content').redactor();
11
+ */
12
+
13
+
14
+ var rwindow, rdocument;
15
+
16
+ if (typeof RELANG === 'undefined')
17
+ {
18
+ var RELANG = {};
19
+ }
20
+
21
+ var RLANG = {
22
+ html: 'HTML',
23
+ video: 'Insert Video',
24
+ image: 'Insert Image',
25
+ table: 'Table',
26
+ link: 'Link',
27
+ link_insert: 'Insert link',
28
+ unlink: 'Unlink',
29
+ formatting: 'Formatting',
30
+ paragraph: 'Paragraph',
31
+ quote: 'Quote',
32
+ code: 'Code',
33
+ header1: 'Header 1',
34
+ header2: 'Header 2',
35
+ header3: 'Header 3',
36
+ header4: 'Header 4',
37
+ bold: 'Bold',
38
+ italic: 'Italic',
39
+ fontcolor: 'Font Color',
40
+ backcolor: 'Back Color',
41
+ unorderedlist: 'Unordered List',
42
+ orderedlist: 'Ordered List',
43
+ outdent: 'Outdent',
44
+ indent: 'Indent',
45
+ cancel: 'Cancel',
46
+ insert: 'Insert',
47
+ save: 'Save',
48
+ _delete: 'Delete',
49
+ insert_table: 'Insert Table',
50
+ insert_row_above: 'Add Row Above',
51
+ insert_row_below: 'Add Row Below',
52
+ insert_column_left: 'Add Column Left',
53
+ insert_column_right: 'Add Column Right',
54
+ delete_column: 'Delete Column',
55
+ delete_row: 'Delete Row',
56
+ delete_table: 'Delete Table',
57
+ rows: 'Rows',
58
+ columns: 'Columns',
59
+ add_head: 'Add Head',
60
+ delete_head: 'Delete Head',
61
+ title: 'Title',
62
+ image_position: 'Position',
63
+ none: 'None',
64
+ left: 'Left',
65
+ right: 'Right',
66
+ image_web_link: 'Image Web Link',
67
+ text: 'Text',
68
+ mailto: 'Email',
69
+ web: 'URL',
70
+ video_html_code: 'Video Embed Code',
71
+ file: 'Insert File',
72
+ upload: 'Upload',
73
+ download: 'Download',
74
+ choose: 'Choose',
75
+ or_choose: 'Or choose',
76
+ drop_file_here: 'Drop file here',
77
+ align_left: 'Align text to the left',
78
+ align_center: 'Center text',
79
+ align_right: 'Align text to the right',
80
+ align_justify: 'Justify text',
81
+ horizontalrule: 'Insert Horizontal Rule',
82
+ deleted: 'Deleted',
83
+ anchor: 'Anchor',
84
+ link_new_tab: 'Open link in new tab',
85
+ underline: 'Underline',
86
+ alignment: 'Alignment'
87
+ };
88
+
89
+ (function($){
90
+
91
+ // Plugin
92
+ jQuery.fn.redactor = function(option)
93
+ {
94
+ return this.each(function()
95
+ {
96
+ var $obj = $(this);
97
+
98
+ var data = $obj.data('redactor');
99
+ if (!data)
100
+ {
101
+ $obj.data('redactor', (data = new Redactor(this, option)));
102
+ }
103
+ });
104
+ };
105
+
106
+
107
+ // Initialization
108
+ var Redactor = function(element, options)
109
+ {
110
+ // Element
111
+ this.$el = $(element);
112
+
113
+ // Lang
114
+ if (typeof options !== 'undefined' && typeof options.lang !== 'undefined' && options.lang !== 'en' && typeof RELANG[options.lang] !== 'undefined')
115
+ {
116
+ RLANG = RELANG[options.lang];
117
+ }
118
+
119
+ // Options
120
+ this.opts = $.extend({
121
+
122
+ iframe: false,
123
+ css: false, // url
124
+
125
+ lang: 'en',
126
+ direction: 'ltr', // ltr or rtl
127
+
128
+ callback: false, // function
129
+ keyupCallback: false, // function
130
+ keydownCallback: false, // function
131
+ execCommandCallback: false, // function
132
+
133
+ plugins: false,
134
+ cleanup: true,
135
+
136
+ focus: false,
137
+ tabindex: false,
138
+ autoresize: true,
139
+ minHeight: false,
140
+ fixed: false,
141
+ fixedTop: 0, // pixels
142
+ fixedBox: false,
143
+ source: true,
144
+ shortcuts: true,
145
+
146
+ mobile: true,
147
+ air: false, // true or toolbar
148
+ wym: false,
149
+
150
+ convertLinks: true,
151
+ convertDivs: true,
152
+ protocol: 'http://', // for links http or https or ftp or false
153
+
154
+ autosave: false, // false or url
155
+ autosaveCallback: false, // function
156
+ interval: 60, // seconds
157
+
158
+ imageGetJson: false, // url (ex. /folder/images.json ) or false
159
+
160
+ imageUpload: false, // url
161
+ imageUploadCallback: false, // function
162
+ imageUploadErrorCallback: false, // function
163
+
164
+ fileUpload: false, // url
165
+ fileUploadCallback: false, // function
166
+ fileUploadErrorCallback: false, // function
167
+
168
+ uploadCrossDomain: false,
169
+ uploadFields: false,
170
+
171
+ observeImages: true,
172
+ overlay: true, // modal overlay
173
+
174
+ allowedTags: ["form", "input", "button", "select", "option", "datalist", "output", "textarea", "fieldset", "legend",
175
+ "section", "header", "hgroup", "aside", "footer", "article", "details", "nav", "progress", "time", "canvas",
176
+ "code", "span", "div", "label", "a", "br", "p", "b", "i", "del", "strike", "u",
177
+ "img", "video", "source", "track", "audio", "iframe", "object", "embed", "param", "blockquote",
178
+ "mark", "cite", "small", "ul", "ol", "li", "hr", "dl", "dt", "dd", "sup", "sub",
179
+ "big", "pre", "code", "figure", "figcaption", "strong", "em", "table", "tr", "td",
180
+ "th", "tbody", "thead", "tfoot", "h1", "h2", "h3", "h4", "h5", "h6"],
181
+
182
+ toolbarExternal: false, // ID selector
183
+
184
+ buttonsCustom: {},
185
+ buttonsAdd: [],
186
+ buttons: ['html', '|', 'formatting', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|',
187
+ 'image', 'video', 'file', 'table', 'link', '|',
188
+ 'fontcolor', 'backcolor', '|', 'alignment', '|', 'horizontalrule'], // 'underline', 'alignleft', 'aligncenter', 'alignright', 'justify'
189
+
190
+ airButtons: ['formatting', '|', 'bold', 'italic', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'fontcolor', 'backcolor'],
191
+
192
+ formattingTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4'],
193
+
194
+ activeButtons: ['deleted', 'italic', 'bold', 'underline', 'unorderedlist', 'orderedlist'], // 'alignleft', 'aligncenter', 'alignright', 'justify'
195
+ activeButtonsStates: {
196
+ b: 'bold',
197
+ strong: 'bold',
198
+ i: 'italic',
199
+ em: 'italic',
200
+ del: 'deleted',
201
+ strike: 'deleted',
202
+ ul: 'unorderedlist',
203
+ ol: 'orderedlist',
204
+ u: 'underline'
205
+ },
206
+
207
+ colors: [
208
+ '#ffffff', '#000000', '#eeece1', '#1f497d', '#4f81bd', '#c0504d', '#9bbb59', '#8064a2', '#4bacc6', '#f79646', '#ffff00',
209
+ '#f2f2f2', '#7f7f7f', '#ddd9c3', '#c6d9f0', '#dbe5f1', '#f2dcdb', '#ebf1dd', '#e5e0ec', '#dbeef3', '#fdeada', '#fff2ca',
210
+ '#d8d8d8', '#595959', '#c4bd97', '#8db3e2', '#b8cce4', '#e5b9b7', '#d7e3bc', '#ccc1d9', '#b7dde8', '#fbd5b5', '#ffe694',
211
+ '#bfbfbf', '#3f3f3f', '#938953', '#548dd4', '#95b3d7', '#d99694', '#c3d69b', '#b2a2c7', '#b7dde8', '#fac08f', '#f2c314',
212
+ '#a5a5a5', '#262626', '#494429', '#17365d', '#366092', '#953734', '#76923c', '#5f497a', '#92cddc', '#e36c09', '#c09100',
213
+ '#7f7f7f', '#0c0c0c', '#1d1b10', '#0f243e', '#244061', '#632423', '#4f6128', '#3f3151', '#31859b', '#974806', '#7f6000'],
214
+
215
+ // private
216
+ emptyHtml: '<p><br /></p>',
217
+ buffer: false,
218
+ visual: true,
219
+
220
+ // modal windows container
221
+ modal_file: String() +
222
+ '<div id="redactor_modal_content">' +
223
+ '<form id="redactorUploadFileForm" method="post" action="" enctype="multipart/form-data">' +
224
+ '<label>Name (optional)</label>' +
225
+ '<input type="text" id="redactor_filename" class="redactor_input" />' +
226
+ '<div style="margin-top: 7px;">' +
227
+ '<input type="file" id="redactor_file" name="file" />' +
228
+ '</div>' +
229
+ '</form><br>' +
230
+ '</div>',
231
+
232
+ modal_image_edit: String() +
233
+ '<div id="redactor_modal_content">' +
234
+ '<label>' + RLANG.title + '</label>' +
235
+ '<input id="redactor_file_alt" class="redactor_input" />' +
236
+ '<label>' + RLANG.link + '</label>' +
237
+ '<input id="redactor_file_link" class="redactor_input" />' +
238
+ '<label>' + RLANG.image_position + '</label>' +
239
+ '<select id="redactor_form_image_align">' +
240
+ '<option value="none">' + RLANG.none + '</option>' +
241
+ '<option value="left">' + RLANG.left + '</option>' +
242
+ '<option value="right">' + RLANG.right + '</option>' +
243
+ '</select>' +
244
+ '</div>' +
245
+ '<div id="redactor_modal_footer">' +
246
+ '<a href="javascript:void(null);" id="redactor_image_delete_btn" class="redactor_modal_btn">' + RLANG._delete + '</a>&nbsp;&nbsp;&nbsp;' +
247
+ '<a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">' + RLANG.cancel + '</a>' +
248
+ '<input type="button" name="save" class="redactor_modal_btn" id="redactorSaveBtn" value="' + RLANG.save + '" />' +
249
+ '</div>',
250
+
251
+ modal_image: String() +
252
+ '<div id="redactor_modal_content">' +
253
+ '<div id="redactor_tabs">' +
254
+ '<a href="javascript:void(null);" class="redactor_tabs_act">' + RLANG.upload + '</a>' +
255
+ '<a href="javascript:void(null);">' + RLANG.choose + '</a>' +
256
+ '<a href="javascript:void(null);">' + RLANG.link + '</a>' +
257
+ '</div>' +
258
+ '<form id="redactorInsertImageForm" method="post" action="" enctype="multipart/form-data">' +
259
+ '<div id="redactor_tab1" class="redactor_tab">' +
260
+ '<input type="file" id="redactor_file" name="file" />' +
261
+ '</div>' +
262
+ '<div id="redactor_tab2" class="redactor_tab" style="display: none;">' +
263
+ '<div id="redactor_image_box"></div>' +
264
+ '</div>' +
265
+ '</form>' +
266
+ '<div id="redactor_tab3" class="redactor_tab" style="display: none;">' +
267
+ '<label>' + RLANG.image_web_link + '</label>' +
268
+ '<input type="text" name="redactor_file_link" id="redactor_file_link" class="redactor_input" />' +
269
+ '</div>' +
270
+ '</div>' +
271
+ '<div id="redactor_modal_footer">' +
272
+ '<a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">' + RLANG.cancel + '</a>' +
273
+ '<input type="button" name="upload" class="redactor_modal_btn" id="redactor_upload_btn" value="' + RLANG.insert + '" />' +
274
+ '</div>',
275
+
276
+ modal_link: String() +
277
+ '<div id="redactor_modal_content">' +
278
+ '<form id="redactorInsertLinkForm" method="post" action="">' +
279
+ '<div id="redactor_tabs">' +
280
+ '<a href="javascript:void(null);" class="redactor_tabs_act">URL</a>' +
281
+ '<a href="javascript:void(null);">Email</a>' +
282
+ '<a href="javascript:void(null);">' + RLANG.anchor + '</a>' +
283
+ '</div>' +
284
+ '<input type="hidden" id="redactor_tab_selected" value="1" />' +
285
+ '<div class="redactor_tab" id="redactor_tab1">' +
286
+ '<label>URL</label><input type="text" id="redactor_link_url" class="redactor_input" />' +
287
+ '<label>' + RLANG.text + '</label><input type="text" class="redactor_input redactor_link_text" id="redactor_link_url_text" />' +
288
+ '<label><input type="checkbox" id="redactor_link_blank"> ' + RLANG.link_new_tab + '</label>' +
289
+ '</div>' +
290
+ '<div class="redactor_tab" id="redactor_tab2" style="display: none;">' +
291
+ '<label>Email</label><input type="text" id="redactor_link_mailto" class="redactor_input" />' +
292
+ '<label>' + RLANG.text + '</label><input type="text" class="redactor_input redactor_link_text" id="redactor_link_mailto_text" />' +
293
+ '</div>' +
294
+ '<div class="redactor_tab" id="redactor_tab3" style="display: none;">' +
295
+ '<label>' + RLANG.anchor + '</label><input type="text" class="redactor_input" id="redactor_link_anchor" />' +
296
+ '<label>' + RLANG.text + '</label><input type="text" class="redactor_input redactor_link_text" id="redactor_link_anchor_text" />' +
297
+ '</div>' +
298
+ '</form>' +
299
+ '</div>' +
300
+ '<div id="redactor_modal_footer">' +
301
+ '<a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">' + RLANG.cancel + '</a>' +
302
+ '<input type="button" class="redactor_modal_btn" id="redactor_insert_link_btn" value="' + RLANG.insert + '" />' +
303
+ '</div>',
304
+
305
+ modal_table: String() +
306
+ '<div id="redactor_modal_content">' +
307
+ '<label>' + RLANG.rows + '</label>' +
308
+ '<input type="text" size="5" value="2" id="redactor_table_rows" />' +
309
+ '<label>' + RLANG.columns + '</label>' +
310
+ '<input type="text" size="5" value="3" id="redactor_table_columns" />' +
311
+ '</div>' +
312
+ '<div id="redactor_modal_footer">' +
313
+ '<a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">' + RLANG.cancel + '</a>' +
314
+ '<input type="button" name="upload" class="redactor_modal_btn" id="redactor_insert_table_btn" value="' + RLANG.insert + '" />' +
315
+ '</div>',
316
+
317
+ modal_video: String() +
318
+ '<div id="redactor_modal_content">' +
319
+ '<form id="redactorInsertVideoForm">' +
320
+ '<label>' + RLANG.video_html_code + '</label>' +
321
+ '<textarea id="redactor_insert_video_area" style="width: 99%; height: 160px;"></textarea>' +
322
+ '</form>' +
323
+ '</div>'+
324
+ '<div id="redactor_modal_footer">' +
325
+ '<a href="javascript:void(null);" class="redactor_modal_btn redactor_btn_modal_close">' + RLANG.cancel + '</a>' +
326
+ '<input type="button" class="redactor_modal_btn" id="redactor_insert_video_btn" value="' + RLANG.insert + '" />' +
327
+ '</div>',
328
+
329
+ toolbar: {
330
+ html:
331
+ {
332
+ title: RLANG.html,
333
+ func: 'toggle'
334
+ },
335
+ formatting:
336
+ {
337
+ title: RLANG.formatting,
338
+ func: 'show',
339
+ dropdown:
340
+ {
341
+ p:
342
+ {
343
+ title: RLANG.paragraph,
344
+ exec: 'formatblock'
345
+ },
346
+ blockquote:
347
+ {
348
+ title: RLANG.quote,
349
+ exec: 'formatblock',
350
+ className: 'redactor_format_blockquote'
351
+ },
352
+ pre:
353
+ {
354
+ title: RLANG.code,
355
+ exec: 'formatblock',
356
+ className: 'redactor_format_pre'
357
+ },
358
+ h1:
359
+ {
360
+ title: RLANG.header1,
361
+ exec: 'formatblock',
362
+ className: 'redactor_format_h1'
363
+ },
364
+ h2:
365
+ {
366
+ title: RLANG.header2,
367
+ exec: 'formatblock',
368
+ className: 'redactor_format_h2'
369
+ },
370
+ h3:
371
+ {
372
+ title: RLANG.header3,
373
+ exec: 'formatblock',
374
+ className: 'redactor_format_h3'
375
+ },
376
+ h4:
377
+ {
378
+ title: RLANG.header4,
379
+ exec: 'formatblock',
380
+ className: 'redactor_format_h4'
381
+ }
382
+ }
383
+ },
384
+ bold:
385
+ {
386
+ title: RLANG.bold,
387
+ exec: 'bold'
388
+ },
389
+ italic:
390
+ {
391
+ title: RLANG.italic,
392
+ exec: 'italic'
393
+ },
394
+ deleted:
395
+ {
396
+ title: RLANG.deleted,
397
+ exec: 'strikethrough'
398
+ },
399
+ underline:
400
+ {
401
+ title: RLANG.underline,
402
+ exec: 'underline'
403
+ },
404
+ unorderedlist:
405
+ {
406
+ title: '&bull; ' + RLANG.unorderedlist,
407
+ exec: 'insertunorderedlist'
408
+ },
409
+ orderedlist:
410
+ {
411
+ title: '1. ' + RLANG.orderedlist,
412
+ exec: 'insertorderedlist'
413
+ },
414
+ outdent:
415
+ {
416
+ title: '< ' + RLANG.outdent,
417
+ exec: 'outdent'
418
+ },
419
+ indent:
420
+ {
421
+ title: '> ' + RLANG.indent,
422
+ exec: 'indent'
423
+ },
424
+ image:
425
+ {
426
+ title: RLANG.image,
427
+ func: 'showImage'
428
+ },
429
+ video:
430
+ {
431
+ title: RLANG.video,
432
+ func: 'showVideo'
433
+ },
434
+ file:
435
+ {
436
+ title: RLANG.file,
437
+ func: 'showFile'
438
+ },
439
+ table:
440
+ {
441
+ title: RLANG.table,
442
+ func: 'show',
443
+ dropdown:
444
+ {
445
+ insert_table:
446
+ {
447
+ title: RLANG.insert_table,
448
+ func: 'showTable'
449
+ },
450
+ separator_drop1:
451
+ {
452
+ name: 'separator'
453
+ },
454
+ insert_row_above:
455
+ {
456
+ title: RLANG.insert_row_above,
457
+ func: 'insertRowAbove'
458
+ },
459
+ insert_row_below:
460
+ {
461
+ title: RLANG.insert_row_below,
462
+ func: 'insertRowBelow'
463
+ },
464
+ insert_column_left:
465
+ {
466
+ title: RLANG.insert_column_left,
467
+ func: 'insertColumnLeft'
468
+ },
469
+ insert_column_right:
470
+ {
471
+ title: RLANG.insert_column_right,
472
+ func: 'insertColumnRight'
473
+ },
474
+ separator_drop2:
475
+ {
476
+ name: 'separator'
477
+ },
478
+ add_head:
479
+ {
480
+ title: RLANG.add_head,
481
+ func: 'addHead'
482
+ },
483
+ delete_head:
484
+ {
485
+ title: RLANG.delete_head,
486
+ func: 'deleteHead'
487
+ },
488
+ separator_drop3:
489
+ {
490
+ name: 'separator'
491
+ },
492
+ delete_column:
493
+ {
494
+ title: RLANG.delete_column,
495
+ func: 'deleteColumn'
496
+ },
497
+ delete_row:
498
+ {
499
+ title: RLANG.delete_row,
500
+ func: 'deleteRow'
501
+ },
502
+ delete_table:
503
+ {
504
+ title: RLANG.delete_table,
505
+ func: 'deleteTable'
506
+ }
507
+ }
508
+ },
509
+ link:
510
+ {
511
+ title: RLANG.link,
512
+ func: 'show',
513
+ dropdown:
514
+ {
515
+ link:
516
+ {
517
+ title: RLANG.link_insert,
518
+ func: 'showLink'
519
+ },
520
+ unlink:
521
+ {
522
+ title: RLANG.unlink,
523
+ exec: 'unlink'
524
+ }
525
+ }
526
+ },
527
+ fontcolor:
528
+ {
529
+ title: RLANG.fontcolor,
530
+ func: 'show'
531
+ },
532
+ backcolor:
533
+ {
534
+ title: RLANG.backcolor,
535
+ func: 'show'
536
+ },
537
+ alignment:
538
+ {
539
+ title: RLANG.alignment,
540
+ func: 'show',
541
+ dropdown:
542
+ {
543
+ alignleft:
544
+ {
545
+ title: RLANG.align_left,
546
+ exec: 'JustifyLeft'
547
+ },
548
+ aligncenter:
549
+ {
550
+ title: RLANG.align_center,
551
+ exec: 'JustifyCenter'
552
+ },
553
+ alignright:
554
+ {
555
+ title: RLANG.align_right,
556
+ exec: 'JustifyRight'
557
+ },
558
+ justify:
559
+ {
560
+ title: RLANG.align_justify,
561
+ exec: 'JustifyFull'
562
+ }
563
+ }
564
+ },
565
+ alignleft:
566
+ {
567
+ exec: 'JustifyLeft',
568
+ title: RLANG.align_left
569
+ },
570
+ aligncenter:
571
+ {
572
+ exec: 'JustifyCenter',
573
+ title: RLANG.align_center
574
+ },
575
+ alignright:
576
+ {
577
+ exec: 'JustifyRight',
578
+ title: RLANG.align_right
579
+ },
580
+ justify:
581
+ {
582
+ exec: 'JustifyFull',
583
+ title: RLANG.align_justify
584
+ },
585
+ horizontalrule:
586
+ {
587
+ exec: 'inserthorizontalrule',
588
+ title: RLANG.horizontalrule
589
+ }
590
+ }
591
+
592
+
593
+ }, options, this.$el.data());
594
+
595
+ this.dropdowns = [];
596
+
597
+ // Init
598
+ this.init();
599
+ };
600
+
601
+ // Functionality
602
+ Redactor.prototype = {
603
+
604
+
605
+ // Initialization
606
+ init: function()
607
+ {
608
+ // get dimensions
609
+ this.height = this.$el.css('height');
610
+ this.width = this.$el.css('width');
611
+
612
+ rdocument = this.document = document;
613
+ rwindow = this.window = window;
614
+
615
+ // mobile
616
+ if (this.opts.mobile === false && this.isMobile())
617
+ {
618
+ this.build(true);
619
+ return false;
620
+ }
621
+
622
+ // iframe
623
+ if (this.opts.iframe)
624
+ {
625
+ this.opts.autoresize = false;
626
+ }
627
+
628
+ // extend buttons
629
+ if (this.opts.air)
630
+ {
631
+ this.opts.buttons = this.opts.airButtons;
632
+ }
633
+ else if (this.opts.toolbar !== false)
634
+ {
635
+ if (this.opts.source === false)
636
+ {
637
+ var index = this.opts.buttons.indexOf('html');
638
+ var next = this.opts.buttons[index+1];
639
+ this.opts.buttons.splice(index, 1);
640
+ if (typeof next !== 'undefined' && next === '|')
641
+ {
642
+ this.opts.buttons.splice(index, 1);
643
+ }
644
+ }
645
+
646
+ $.extend(this.opts.toolbar, this.opts.buttonsCustom);
647
+ $.each(this.opts.buttonsAdd, $.proxy(function(i,s)
648
+ {
649
+ this.opts.buttons.push(s);
650
+
651
+ }, this));
652
+ }
653
+
654
+ // formatting tags
655
+ if (this.opts.toolbar !== false)
656
+ {
657
+ $.each(this.opts.toolbar.formatting.dropdown, $.proxy(function(i,s)
658
+ {
659
+ if ($.inArray(i, this.opts.formattingTags) == '-1')
660
+ {
661
+ delete this.opts.toolbar.formatting.dropdown[i];
662
+ }
663
+
664
+ }, this));
665
+ }
666
+
667
+ function afterBuild()
668
+ {
669
+ // air enable
670
+ this.enableAir();
671
+
672
+ // toolbar
673
+ this.buildToolbar();
674
+
675
+ // PLUGINS
676
+ if (typeof this.opts.plugins === 'object')
677
+ {
678
+ $.each(this.opts.plugins, $.proxy(function(i,s)
679
+ {
680
+ if (typeof RedactorPlugins[s] !== 'undefined')
681
+ {
682
+ $.extend(this, RedactorPlugins[s]);
683
+
684
+ if (typeof RedactorPlugins[s].init !== 'undefined')
685
+ {
686
+ this.init();
687
+ }
688
+ }
689
+
690
+ }, this));
691
+ }
692
+
693
+ // buttons response
694
+ if (this.opts.activeButtons !== false && this.opts.toolbar !== false)
695
+ {
696
+ var observeFormatting = $.proxy(function() { this.observeFormatting(); }, this);
697
+ this.$editor.click(observeFormatting).keyup(observeFormatting);
698
+ }
699
+
700
+ // paste
701
+ var oldsafari = false;
702
+ if (this.browser('webkit') && navigator.userAgent.indexOf('Chrome') === -1)
703
+ {
704
+ var arr = this.browser('version').split('.');
705
+ if (arr[0] < 536) oldsafari = true;
706
+ }
707
+
708
+ if (this.isMobile(true) === false && oldsafari === false)
709
+ {
710
+ this.$editor.bind('paste', $.proxy(function(e)
711
+ {
712
+ if (this.opts.cleanup === false)
713
+ {
714
+ return true;
715
+ }
716
+
717
+ this.pasteRunning = true;
718
+
719
+ this.setBuffer();
720
+
721
+ if (this.opts.autoresize === true)
722
+ {
723
+ this.saveScroll = this.document.body.scrollTop;
724
+ }
725
+ else
726
+ {
727
+ this.saveScroll = this.$editor.scrollTop();
728
+ }
729
+
730
+ var frag = this.extractContent();
731
+
732
+ setTimeout($.proxy(function()
733
+ {
734
+ var pastedFrag = this.extractContent();
735
+ this.$editor.append(frag);
736
+
737
+ this.restoreSelection();
738
+
739
+ var html = this.getFragmentHtml(pastedFrag);
740
+ this.pasteCleanUp(html);
741
+ this.pasteRunning = false;
742
+
743
+ }, this), 1);
744
+
745
+ }, this));
746
+ }
747
+
748
+ // key handlers
749
+ this.keyup();
750
+ this.keydown();
751
+
752
+ // autosave
753
+ if (this.opts.autosave !== false)
754
+ {
755
+ this.autoSave();
756
+ }
757
+
758
+ // observers
759
+ setTimeout($.proxy(function()
760
+ {
761
+ this.observeImages();
762
+ this.observeTables();
763
+
764
+ }, this), 1);
765
+
766
+ // FF fix
767
+ if (this.browser('mozilla'))
768
+ {
769
+ this.$editor.click($.proxy(function()
770
+ {
771
+ this.saveSelection();
772
+ }, this));
773
+
774
+ try
775
+ {
776
+ this.document.execCommand('enableObjectResizing', false, false);
777
+ this.document.execCommand('enableInlineTableEditing', false, false);
778
+ }
779
+ catch (e) {}
780
+ }
781
+
782
+ // focus
783
+ if (this.opts.focus)
784
+ {
785
+ setTimeout($.proxy(function(){
786
+ this.$editor.focus();
787
+ }, this), 1);
788
+ }
789
+
790
+ // fixed
791
+ if (this.opts.fixed)
792
+ {
793
+ this.observeScroll();
794
+ $(document).scroll($.proxy(this.observeScroll, this));
795
+ }
796
+
797
+ // callback
798
+ if (typeof this.opts.callback === 'function')
799
+ {
800
+ this.opts.callback(this);
801
+ }
802
+
803
+ if (this.opts.toolbar !== false)
804
+ {
805
+ this.$toolbar.find('a').attr('tabindex', '-1');
806
+ }
807
+ }
808
+
809
+ // construct editor
810
+ this.build(false, afterBuild);
811
+
812
+ },
813
+ shortcuts: function(e, cmd)
814
+ {
815
+ e.preventDefault();
816
+ this.execCommand(cmd, false);
817
+ },
818
+ keyup: function()
819
+ {
820
+ this.$editor.keyup($.proxy(function(e)
821
+ {
822
+ var key = e.keyCode || e.which;
823
+
824
+ if (this.browser('mozilla') && !this.pasteRunning)
825
+ {
826
+ this.saveSelection();
827
+ }
828
+
829
+ // callback as you type
830
+ if (typeof this.opts.keyupCallback === 'function')
831
+ {
832
+ this.opts.keyupCallback(this, e);
833
+ }
834
+
835
+ // if empty
836
+ if (key === 8 || key === 46)
837
+ {
838
+ this.observeImages();
839
+ return this.formatEmpty(e);
840
+ }
841
+
842
+ // new line p
843
+ if (key === 13 && !e.shiftKey && !e.ctrlKey && !e.metaKey)
844
+ {
845
+ if (this.browser('webkit'))
846
+ {
847
+ this.formatNewLine(e);
848
+ }
849
+
850
+ // convert links
851
+ if (this.opts.convertLinks)
852
+ {
853
+ this.$editor.linkify();
854
+ }
855
+ }
856
+
857
+ this.syncCode();
858
+
859
+ }, this));
860
+ },
861
+ keydown: function()
862
+ {
863
+ this.$editor.keydown($.proxy(function(e)
864
+ {
865
+ var key = e.keyCode || e.which;
866
+ var parent = this.getParentNode();
867
+ var current = this.getCurrentNode();
868
+ var pre = false;
869
+ var ctrl = e.ctrlKey || e.metaKey;
870
+
871
+ if ((parent || current) && ($(parent).get(0).tagName === 'PRE' || $(current).get(0).tagName === 'PRE'))
872
+ {
873
+ pre = true;
874
+ }
875
+
876
+ // callback keydown
877
+ if (typeof this.opts.keydownCallback === 'function')
878
+ {
879
+ this.opts.keydownCallback(this, e);
880
+ }
881
+
882
+ if (ctrl && this.opts.shortcuts)
883
+ {
884
+ if (key === 90)
885
+ {
886
+ if (this.opts.buffer !== false)
887
+ {
888
+ e.preventDefault();
889
+ this.getBuffer();
890
+ }
891
+ else if (e.shiftKey)
892
+ {
893
+ this.shortcuts(e, 'redo'); // Ctrl + Shift + z
894
+ }
895
+ else
896
+ {
897
+ this.shortcuts(e, 'undo'); // Ctrl + z
898
+ }
899
+ }
900
+ else if (key === 77)
901
+ {
902
+ this.shortcuts(e, 'removeFormat'); // Ctrl + m
903
+ }
904
+ else if (key === 66)
905
+ {
906
+ this.shortcuts(e, 'bold'); // Ctrl + b
907
+ }
908
+ else if (key === 73)
909
+ {
910
+ this.shortcuts(e, 'italic'); // Ctrl + i
911
+ }
912
+ else if (key === 74)
913
+ {
914
+ this.shortcuts(e, 'insertunorderedlist'); // Ctrl + j
915
+ }
916
+ else if (key === 75)
917
+ {
918
+ this.shortcuts(e, 'insertorderedlist'); // Ctrl + k
919
+ }
920
+ else if (key === 76)
921
+ {
922
+ this.shortcuts(e, 'superscript'); // Ctrl + l
923
+ }
924
+ else if (key === 72)
925
+ {
926
+ this.shortcuts(e, 'subscript'); // Ctrl + h
927
+ }
928
+ }
929
+
930
+ // clear undo buffer
931
+ if (!ctrl && key !== 90)
932
+ {
933
+ this.opts.buffer = false;
934
+ }
935
+
936
+ // enter
937
+ if (pre === true && key === 13)
938
+ {
939
+ e.preventDefault();
940
+
941
+ var html = $(current).parent().text();
942
+ this.insertNodeAtCaret(this.document.createTextNode('\r\n'));
943
+ if (html.search(/\s$/) == -1)
944
+ {
945
+ this.insertNodeAtCaret(this.document.createTextNode('\r\n'));
946
+ }
947
+ this.syncCode();
948
+
949
+ return false;
950
+ }
951
+
952
+ // tab
953
+ if (this.opts.shortcuts && !e.shiftKey && key === 9)
954
+ {
955
+ if (pre === false)
956
+ {
957
+ this.shortcuts(e, 'indent'); // Tab
958
+ }
959
+ else
960
+ {
961
+ e.preventDefault();
962
+ this.insertNodeAtCaret(this.document.createTextNode('\t'));
963
+ this.syncCode();
964
+ return false;
965
+ }
966
+ }
967
+ else if (this.opts.shortcuts && e.shiftKey && key === 9 )
968
+ {
969
+ this.shortcuts(e, 'outdent'); // Shift + tab
970
+ }
971
+
972
+ // safari shift key + enter
973
+ if (this.browser('webkit') && navigator.userAgent.indexOf('Chrome') === -1)
974
+ {
975
+ return this.safariShiftKeyEnter(e, key);
976
+ }
977
+ }, this));
978
+ },
979
+ build: function(mobile, whendone)
980
+ {
981
+ if (mobile !== true)
982
+ {
983
+ // container
984
+ this.$box = $('<div class="redactor_box"></div>');
985
+
986
+ // air box
987
+ if (this.opts.air)
988
+ {
989
+ this.air = $('<div class="redactor_air" style="display: none;"></div>');
990
+ }
991
+
992
+ this.$content = null;
993
+
994
+ function initFrame()
995
+ {
996
+ this.$editor = this.$content.contents().find("body").attr('contenteditable', true).attr('dir', this.opts.direction);
997
+
998
+ rdocument = this.document = this.$editor[0].ownerDocument;
999
+ rwindow = this.window = this.document.defaultView || window;
1000
+
1001
+ if (this.opts.css !== false)
1002
+ {
1003
+ this.$content.contents().find('head').append('<link rel="stylesheet" href="' + this.opts.css + '" />');
1004
+ }
1005
+
1006
+ this.$editor.html(html);
1007
+
1008
+ if (whendone)
1009
+ {
1010
+ whendone.call(this);
1011
+ whendone = null;
1012
+ }
1013
+ }
1014
+
1015
+ // editor
1016
+ this.textareamode = true;
1017
+ if (this.$el.get(0).tagName === 'TEXTAREA')
1018
+ {
1019
+ if(this.opts.iframe)
1020
+ {
1021
+ var me = this;
1022
+ this.$content = $('<iframe style="width: 100%;" frameborder="0"></iframe>').load(function()
1023
+ {
1024
+ initFrame.call(me);
1025
+ });
1026
+ }
1027
+ else
1028
+ {
1029
+ this.$content = this.$editor = $('<div></div>');
1030
+ }
1031
+
1032
+ var classlist = this.$el.get(0).className.split(/\s+/);
1033
+ $.each(classlist, $.proxy(function(i,s)
1034
+ {
1035
+ this.$content.addClass('redactor_' + s);
1036
+ }, this));
1037
+ }
1038
+ else
1039
+ {
1040
+ this.textareamode = false;
1041
+ this.$content = this.$editor = this.$el;
1042
+ this.$el = $('<textarea name="' + this.$editor.attr('id') + '"></textarea>').css('height', this.height);
1043
+ }
1044
+
1045
+ if (this.$editor)
1046
+ {
1047
+ this.$editor.addClass('redactor_editor').attr('contenteditable', true).attr('dir', this.opts.direction);
1048
+ }
1049
+
1050
+ if (this.opts.tabindex !== false)
1051
+ {
1052
+ this.$content.attr('tabindex', this.opts.tabindex);
1053
+ }
1054
+
1055
+ if (this.opts.minHeight !== false)
1056
+ {
1057
+ this.$content.css('min-height', this.opts.minHeight + 'px');
1058
+ }
1059
+
1060
+ if (this.opts.wym === true)
1061
+ {
1062
+ this.$content.addClass('redactor_editor_wym');
1063
+ }
1064
+
1065
+ if (this.opts.autoresize === false)
1066
+ {
1067
+ this.$content.css('height', this.height);
1068
+ }
1069
+
1070
+ // hide textarea
1071
+ this.$el.hide();
1072
+
1073
+ // append box and frame
1074
+ var html = '';
1075
+ if (this.textareamode)
1076
+ {
1077
+ // get html
1078
+ html = this.$el.val();
1079
+ html = this.savePreCode(html);
1080
+
1081
+ this.$box.insertAfter(this.$el).append(this.$content).append(this.$el);
1082
+ }
1083
+ else
1084
+ {
1085
+ // get html
1086
+ html = this.$editor.html();
1087
+ html = this.savePreCode(html);
1088
+
1089
+ this.$box.insertAfter(this.$content).append(this.$el).append(this.$editor);
1090
+
1091
+ }
1092
+
1093
+ // conver newlines to p
1094
+ html = this.paragraphy(html);
1095
+
1096
+ // enable
1097
+ if (this.$editor)
1098
+ {
1099
+ this.$editor.html(html);
1100
+ }
1101
+
1102
+ if (this.textareamode === false)
1103
+ {
1104
+ this.syncCode();
1105
+ }
1106
+ }
1107
+ else
1108
+ {
1109
+ if (this.$el.get(0).tagName !== 'TEXTAREA')
1110
+ {
1111
+ var html = this.$el.val();
1112
+ var textarea = $('<textarea name="' + this.$editor.attr('id') + '"></textarea>').css('height', this.height).val(html);
1113
+ this.$el.hide();
1114
+ this.$el.after(textarea);
1115
+ }
1116
+ }
1117
+
1118
+ if (whendone && this.$editor)
1119
+ {
1120
+ whendone.call(this);
1121
+ }
1122
+
1123
+ },
1124
+ enableAir: function()
1125
+ {
1126
+ if (this.opts.air === false)
1127
+ {
1128
+ return false;
1129
+ }
1130
+
1131
+ this.air.hide();
1132
+
1133
+ this.$editor.bind('textselect', $.proxy(function(e)
1134
+ {
1135
+ this.showAir(e);
1136
+
1137
+ }, this));
1138
+
1139
+ this.$editor.bind('textunselect', $.proxy(function()
1140
+ {
1141
+ this.air.hide();
1142
+
1143
+ }, this));
1144
+
1145
+ },
1146
+ showAir: function(e)
1147
+ {
1148
+ $('.redactor_air').hide();
1149
+
1150
+ var width = this.air.innerWidth();
1151
+ var left = e.clientX;
1152
+
1153
+ if ($(this.document).width() < (left + width))
1154
+ {
1155
+ left = left - width;
1156
+ }
1157
+
1158
+ var top = e.clientY + $(document).scrollTop() + 14;
1159
+ if (this.opts.iframe === true)
1160
+ {
1161
+ top = top + this.$box.position().top;
1162
+ left = left + this.$box.position().left;
1163
+ }
1164
+
1165
+ this.air.css({ left: left + 'px', top: top + 'px' }).show();
1166
+ },
1167
+ syncCode: function()
1168
+ {
1169
+ this.$el.val(this.$editor.html());
1170
+ },
1171
+
1172
+ // API functions
1173
+ setCode: function(html)
1174
+ {
1175
+ html = this.stripTags(html);
1176
+ this.$editor.html(html).focus();
1177
+
1178
+ this.syncCode();
1179
+ },
1180
+ getCode: function()
1181
+ {
1182
+ var html = '';
1183
+ if (this.opts.visual)
1184
+ {
1185
+ html = this.$editor.html()
1186
+ }
1187
+ else
1188
+ {
1189
+ html = this.$el.val();
1190
+ }
1191
+
1192
+ return this.stripTags(html);
1193
+ },
1194
+ insertHtml: function(html)
1195
+ {
1196
+ this.$editor.focus();
1197
+ this.pasteHtmlAtCaret(html);
1198
+ this.observeImages();
1199
+ this.syncCode();
1200
+ },
1201
+
1202
+ pasteHtmlAtCaret: function (html)
1203
+ {
1204
+ var sel, range;
1205
+ if (this.document.getSelection)
1206
+ {
1207
+ sel = this.window.getSelection();
1208
+ if (sel.getRangeAt && sel.rangeCount)
1209
+ {
1210
+ range = sel.getRangeAt(0);
1211
+ range.deleteContents();
1212
+ var el = this.document.createElement("div");
1213
+ el.innerHTML = html;
1214
+ var frag = this.document.createDocumentFragment(), node, lastNode;
1215
+ while (node = el.firstChild)
1216
+ {
1217
+ lastNode = frag.appendChild(node);
1218
+ }
1219
+ range.insertNode(frag);
1220
+
1221
+ if (lastNode)
1222
+ {
1223
+ range = range.cloneRange();
1224
+ range.setStartAfter(lastNode);
1225
+ range.collapse(true);
1226
+ sel.removeAllRanges();
1227
+ sel.addRange(range);
1228
+ }
1229
+ }
1230
+ }
1231
+ else if (this.document.selection && this.document.selection.type != "Control")
1232
+ {
1233
+ this.document.selection.createRange().pasteHTML(html);
1234
+ }
1235
+ },
1236
+
1237
+ destroy: function()
1238
+ {
1239
+ var html = this.getCode();
1240
+
1241
+ if (this.textareamode)
1242
+ {
1243
+ this.$box.after(this.$el);
1244
+ this.$box.remove();
1245
+ this.$el.height(this.height).val(html).show();
1246
+ }
1247
+ else
1248
+ {
1249
+ this.$box.after(this.$editor);
1250
+ this.$box.remove();
1251
+ this.$editor.removeClass('redactor_editor').removeClass('redactor_editor_wym').attr('contenteditable', false).html(html).show();
1252
+ }
1253
+
1254
+ if (this.opts.toolbarExternal)
1255
+ {
1256
+ $(this.opts.toolbarExternal).empty();
1257
+ }
1258
+
1259
+ $('.redactor_air').remove();
1260
+
1261
+ for (var i = 0; i < this.dropdowns.length; i++)
1262
+ {
1263
+ this.dropdowns[i].remove();
1264
+ delete(this.dropdowns[i]);
1265
+ }
1266
+
1267
+ if (this.opts.autosave !== false)
1268
+ {
1269
+ clearInterval(this.autosaveInterval);
1270
+ }
1271
+
1272
+ },
1273
+ // end API functions
1274
+
1275
+ // OBSERVERS
1276
+ observeFormatting: function()
1277
+ {
1278
+ var parent = this.getCurrentNode();
1279
+
1280
+ this.inactiveAllButtons();
1281
+
1282
+ $.each(this.opts.activeButtonsStates, $.proxy(function(i,s)
1283
+ {
1284
+ if ($(parent).closest(i,this.$editor.get()[0]).length != 0)
1285
+ {
1286
+ this.setBtnActive(s);
1287
+ }
1288
+
1289
+ }, this));
1290
+
1291
+ var tag = $(parent).closest(['p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'td']);
1292
+
1293
+ if (typeof tag[0] !== 'undefined' && typeof tag[0].elem !== 'undefined' && $(tag[0].elem).size() != 0)
1294
+ {
1295
+ var align = $(tag[0].elem).css('text-align');
1296
+
1297
+ switch (align)
1298
+ {
1299
+ case 'right':
1300
+ this.setBtnActive('alignright');
1301
+ break;
1302
+ case 'center':
1303
+ this.setBtnActive('aligncenter');
1304
+ break;
1305
+ case 'justify':
1306
+ this.setBtnActive('justify');
1307
+ break;
1308
+ default:
1309
+ this.setBtnActive('alignleft');
1310
+ break;
1311
+ }
1312
+ }
1313
+ },
1314
+ observeImages: function()
1315
+ {
1316
+ if (this.opts.observeImages === false)
1317
+ {
1318
+ return false;
1319
+ }
1320
+
1321
+ this.$editor.find('img').each($.proxy(function(i,s)
1322
+ {
1323
+ if (this.browser('msie'))
1324
+ {
1325
+ $(s).attr('unselectable', 'on');
1326
+ }
1327
+
1328
+ this.resizeImage(s);
1329
+
1330
+ }, this));
1331
+
1332
+ },
1333
+ observeTables: function()
1334
+ {
1335
+ this.$editor.find('table').click($.proxy(this.tableObserver, this));
1336
+ },
1337
+ observeScroll: function()
1338
+ {
1339
+ var scrolltop = $(this.document).scrollTop();
1340
+ var boxtop = this.$box.offset().top;
1341
+ var left = 0;
1342
+
1343
+ if (scrolltop > boxtop)
1344
+ {
1345
+ var width = '100%';
1346
+ if (this.opts.fixedBox)
1347
+ {
1348
+ left = this.$box.offset().left;
1349
+ width = this.$box.innerWidth();
1350
+ }
1351
+
1352
+ this.fixed = true;
1353
+ this.$toolbar.css({ position: 'fixed', width: width, zIndex: 1005, top: this.opts.fixedTop + 'px', left: left });
1354
+ }
1355
+ else
1356
+ {
1357
+ this.fixed = false;
1358
+ this.$toolbar.css({ position: 'relative', width: 'auto', zIndex: 1, top: 0, left: left });
1359
+ }
1360
+ },
1361
+
1362
+ // BUFFER
1363
+ setBuffer: function()
1364
+ {
1365
+ this.saveSelection();
1366
+ this.opts.buffer = this.$editor.html();
1367
+ },
1368
+ getBuffer: function()
1369
+ {
1370
+ if (this.opts.buffer === false)
1371
+ {
1372
+ return false;
1373
+ }
1374
+
1375
+ this.$editor.html(this.opts.buffer);
1376
+
1377
+ if (!this.browser('msie'))
1378
+ {
1379
+ this.restoreSelection();
1380
+ }
1381
+
1382
+ this.opts.buffer = false;
1383
+ },
1384
+
1385
+
1386
+
1387
+ // EXECCOMMAND
1388
+ execCommand: function(cmd, param)
1389
+ {
1390
+ if (this.opts.visual == false)
1391
+ {
1392
+ this.$el.focus();
1393
+ return false;
1394
+ }
1395
+
1396
+ try
1397
+ {
1398
+
1399
+ var parent;
1400
+
1401
+ if (cmd === 'inserthtml')
1402
+ {
1403
+ if (this.browser('msie'))
1404
+ {
1405
+ this.$editor.focus();
1406
+ this.document.selection.createRange().pasteHTML(param);
1407
+ }
1408
+ else
1409
+ {
1410
+ this.pasteHtmlAtCaret(param);
1411
+ //this.execRun(cmd, param);
1412
+ }
1413
+
1414
+ this.observeImages();
1415
+ }
1416
+ else if (cmd === 'unlink')
1417
+ {
1418
+ parent = this.getParentNode();
1419
+ if ($(parent).get(0).tagName === 'A')
1420
+ {
1421
+ $(parent).replaceWith($(parent).text());
1422
+ }
1423
+ else
1424
+ {
1425
+ this.execRun(cmd, param);
1426
+ }
1427
+ }
1428
+ else if (cmd === 'JustifyLeft' || cmd === 'JustifyCenter' || cmd === 'JustifyRight' || cmd === 'JustifyFull')
1429
+ {
1430
+ parent = this.getCurrentNode();
1431
+ var tag = $(parent).get(0).tagName;
1432
+
1433
+ if (this.opts.iframe === false && $(parent).parents('.redactor_editor').size() == 0)
1434
+ {
1435
+ return false;
1436
+ }
1437
+
1438
+ var tagsArray = ['P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'BLOCKQUOTE', 'TD'];
1439
+ if ($.inArray(tag, tagsArray) != -1)
1440
+ {
1441
+ var align = false;
1442
+
1443
+ if (cmd === 'JustifyCenter')
1444
+ {
1445
+ align = 'center';
1446
+ }
1447
+ else if (cmd === 'JustifyRight')
1448
+ {
1449
+ align = 'right';
1450
+ }
1451
+ else if (cmd === 'JustifyFull')
1452
+ {
1453
+ align = 'justify';
1454
+ }
1455
+
1456
+ if (align === false)
1457
+ {
1458
+ $(parent).css('text-align', '');
1459
+ }
1460
+ else
1461
+ {
1462
+ $(parent).css('text-align', align);
1463
+ }
1464
+ }
1465
+ else
1466
+ {
1467
+ this.execRun(cmd, param);
1468
+ }
1469
+ }
1470
+ else if (cmd === 'formatblock' && param === 'blockquote')
1471
+ {
1472
+ parent = this.getCurrentNode();
1473
+ if ($(parent).get(0).tagName === 'BLOCKQUOTE')
1474
+ {
1475
+ if (this.browser('msie'))
1476
+ {
1477
+ var node = $('<p>' + $(parent).html() + '</p>');
1478
+ $(parent).replaceWith(node);
1479
+ }
1480
+ else
1481
+ {
1482
+ this.execRun(cmd, 'p');
1483
+ }
1484
+ }
1485
+ else if ($(parent).get(0).tagName === 'P')
1486
+ {
1487
+ var parent2 = $(parent).parent();
1488
+ if ($(parent2).get(0).tagName === 'BLOCKQUOTE')
1489
+ {
1490
+ var node = $('<p>' + $(parent).html() + '</p>');
1491
+ $(parent2).replaceWith(node);
1492
+ this.setSelection(node[0], 0, node[0], 0);
1493
+ }
1494
+ else
1495
+ {
1496
+ if (this.browser('msie'))
1497
+ {
1498
+ var node = $('<blockquote>' + $(parent).html() + '</blockquote>');
1499
+ $(parent).replaceWith(node);
1500
+ }
1501
+ else
1502
+ {
1503
+ this.execRun(cmd, param);
1504
+ }
1505
+ }
1506
+ }
1507
+ else
1508
+ {
1509
+ this.execRun(cmd, param);
1510
+ }
1511
+ }
1512
+ else if (cmd === 'formatblock' && (param === 'pre' || param === 'p'))
1513
+ {
1514
+ parent = this.getParentNode();
1515
+
1516
+ if ($(parent).get(0).tagName === 'PRE')
1517
+ {
1518
+ $(parent).replaceWith('<p>' + this.encodeEntities($(parent).text()) + '</p>');
1519
+ }
1520
+ else
1521
+ {
1522
+ this.execRun(cmd, param);
1523
+ }
1524
+ }
1525
+ else
1526
+ {
1527
+ if (cmd === 'inserthorizontalrule' && this.browser('msie'))
1528
+ {
1529
+ this.$editor.focus();
1530
+ }
1531
+
1532
+ if (cmd === 'formatblock' && this.browser('mozilla'))
1533
+ {
1534
+ this.$editor.focus();
1535
+ }
1536
+
1537
+ this.execRun(cmd, param);
1538
+ }
1539
+
1540
+ if (cmd === 'inserthorizontalrule')
1541
+ {
1542
+ this.$editor.find('hr').removeAttr('id');
1543
+ }
1544
+
1545
+ this.syncCode();
1546
+
1547
+ if (this.oldIE())
1548
+ {
1549
+ this.$editor.focus();
1550
+ }
1551
+
1552
+ if (typeof this.opts.execCommandCallback === 'function')
1553
+ {
1554
+ this.opts.execCommandCallback(this, cmd);
1555
+ }
1556
+
1557
+ if (this.opts.air)
1558
+ {
1559
+ this.air.hide();
1560
+ }
1561
+ }
1562
+ catch (e) { }
1563
+ },
1564
+ execRun: function(cmd, param)
1565
+ {
1566
+ if (cmd === 'formatblock' && this.browser('msie'))
1567
+ {
1568
+ param = '<' + param + '>';
1569
+ }
1570
+
1571
+ this.document.execCommand(cmd, false, param);
1572
+ },
1573
+
1574
+ // FORMAT NEW LINE
1575
+ formatNewLine: function(e)
1576
+ {
1577
+ var parent = this.getParentNode();
1578
+
1579
+ if (parent.nodeName === 'DIV' && parent.className === 'redactor_editor')
1580
+ {
1581
+ var element = $(this.getCurrentNode());
1582
+
1583
+ if (element.get(0).tagName === 'DIV' && (element.html() === '' || element.html() === '<br>'))
1584
+ {
1585
+ var newElement = $('<p>').append(element.clone().get(0).childNodes);
1586
+ element.replaceWith(newElement);
1587
+ newElement.html('<br />');
1588
+ this.setSelection(newElement[0], 0, newElement[0], 0);
1589
+ }
1590
+ }
1591
+ },
1592
+
1593
+ // SAFARI SHIFT KEY + ENTER
1594
+ safariShiftKeyEnter: function(e, key)
1595
+ {
1596
+ if (e.shiftKey && key === 13)
1597
+ {
1598
+ e.preventDefault();
1599
+ this.insertNodeAtCaret($('<span><br /></span>').get(0));
1600
+ this.syncCode();
1601
+ return false;
1602
+ }
1603
+ else
1604
+ {
1605
+ return true;
1606
+ }
1607
+ },
1608
+
1609
+ // FORMAT EMPTY
1610
+ formatEmpty: function(e)
1611
+ {
1612
+ var html = $.trim(this.$editor.html());
1613
+
1614
+ if (this.browser('mozilla'))
1615
+ {
1616
+ html = html.replace(/<br>/i, '');
1617
+ }
1618
+
1619
+ var thtml = html.replace(/<(?:.|\n)*?>/gm, '');
1620
+
1621
+ if (html === '' || thtml === '')
1622
+ {
1623
+ e.preventDefault();
1624
+
1625
+ var node = $(this.opts.emptyHtml).get(0);
1626
+ this.$editor.html(node);
1627
+ this.setSelection(node, 0, node, 0);
1628
+
1629
+ this.syncCode();
1630
+ return false;
1631
+ }
1632
+ else
1633
+ {
1634
+ this.syncCode();
1635
+ }
1636
+ },
1637
+
1638
+ // PARAGRAPHY
1639
+ paragraphy: function (str)
1640
+ {
1641
+ str = $.trim(str);
1642
+ if (str === '' || str === '<p></p>')
1643
+ {
1644
+ return this.opts.emptyHtml;
1645
+ }
1646
+
1647
+ // convert div to p
1648
+ if (this.opts.convertDivs)
1649
+ {
1650
+ str = str.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi, '<p>$2</p>');
1651
+ }
1652
+
1653
+ // inner functions
1654
+ var X = function(x, a, b) { return x.replace(new RegExp(a, 'g'), b); };
1655
+ var R = function(a, b) { return X(str, a, b); };
1656
+
1657
+ // block elements
1658
+ var blocks = '(table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|style|script|object|input|param|p|h[1-6])';
1659
+
1660
+ //str = '<p>' + str;
1661
+ str += '\n';
1662
+
1663
+ R('<br />\\s*<br />', '\n\n');
1664
+ R('(<' + blocks + '[^>]*>)', '\n$1');
1665
+ R('(</' + blocks + '>)', '$1\n\n');
1666
+ R('\r\n|\r', '\n'); // newlines
1667
+ R('\n\n+', '\n\n'); // remove duplicates
1668
+ R('\n?((.|\n)+?)$', '<p>$1</p>\n'); // including one at the end
1669
+ R('<p>\\s*?</p>', ''); // remove empty p
1670
+ R('<p>(<div[^>]*>\\s*)', '$1<p>');
1671
+ R('<p>([^<]+)\\s*?(</(div|address|form)[^>]*>)', '<p>$1</p>$2');
1672
+ R('<p>\\s*(</?' + blocks + '[^>]*>)\\s*</p>', '$1');
1673
+ R('<p>(<li.+?)</p>', '$1');
1674
+ R('<p>\\s*(</?' + blocks + '[^>]*>)', '$1');
1675
+ R('(</?' + blocks + '[^>]*>)\\s*</p>', '$1');
1676
+ R('(</?' + blocks + '[^>]*>)\\s*<br />', '$1');
1677
+ R('<br />(\\s*</?(p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)', '$1');
1678
+
1679
+ // pre
1680
+ if (str.indexOf('<pre') != -1)
1681
+ {
1682
+ R('(<pre(.|\n)*?>)((.|\n)*?)</pre>', function(m0, m1, m2, m3)
1683
+ {
1684
+ return X(m1, '\\\\([\'\"\\\\])', '$1') + X(X(X(m3, '<p>', '\n'), '</p>|<br />', ''), '\\\\([\'\"\\\\])', '$1') + '</pre>';
1685
+ });
1686
+ }
1687
+
1688
+ return R('\n</p>$', '</p>');
1689
+ },
1690
+
1691
+ // REMOVE TAGS
1692
+ stripTags: function(html)
1693
+ {
1694
+ var allowed = this.opts.allowedTags;
1695
+ var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
1696
+ return html.replace(tags, function ($0, $1)
1697
+ {
1698
+ return $.inArray($1.toLowerCase(), allowed) > '-1' ? $0 : '';
1699
+ });
1700
+ },
1701
+
1702
+
1703
+ savePreCode: function(html)
1704
+ {
1705
+ var pre = html.match(/<pre(.*?)>([\w\W]*?)<\/pre>/gi);
1706
+ if (pre !== null)
1707
+ {
1708
+ $.each(pre, $.proxy(function(i,s)
1709
+ {
1710
+ var arr = s.match(/<pre(.*?)>([\w\W]*?)<\/pre>/i);
1711
+ arr[2] = this.encodeEntities(arr[2]);
1712
+ html = html.replace(s, '<pre' + arr[1] + '>' + arr[2] + '</pre>');
1713
+ }, this));
1714
+ }
1715
+
1716
+ return html;
1717
+ },
1718
+ encodeEntities: function(str)
1719
+ {
1720
+ str = String(str).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"');
1721
+ return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
1722
+ },
1723
+ cleanupPre: function(s)
1724
+ {
1725
+ s = s.replace(/<br>/gi, '\n');
1726
+ s = s.replace(/<\/p>/gi, '\n');
1727
+ s = s.replace(/<\/div>/gi, '\n');
1728
+
1729
+ var tmp = this.document.createElement("div");
1730
+ tmp.innerHTML = s;
1731
+ return tmp.textContent||tmp.innerText;
1732
+
1733
+ },
1734
+
1735
+
1736
+ // PASTE CLEANUP
1737
+ pasteCleanUp: function(html)
1738
+ {
1739
+ var parent = this.getParentNode();
1740
+
1741
+ // clean up pre
1742
+ if ($(parent).get(0).tagName === 'PRE')
1743
+ {
1744
+ html = this.cleanupPre(html);
1745
+ this.pasteCleanUpInsert(html);
1746
+ return true;
1747
+ }
1748
+
1749
+ // remove comments and php tags
1750
+ html = html.replace(/<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi, '');
1751
+
1752
+ // remove nbsp
1753
+ html = html.replace(/(&nbsp;){2,}/gi, '&nbsp;');
1754
+
1755
+ // remove google docs marker
1756
+ html = html.replace(/<b\sid="internal-source-marker(.*?)">([\w\W]*?)<\/b>/gi, "$2");
1757
+
1758
+ // strip tags
1759
+ html = this.stripTags(html);
1760
+
1761
+ // prevert
1762
+ html = html.replace(/<td><\/td>/gi, '[td]');
1763
+ html = html.replace(/<td>&nbsp;<\/td>/gi, '[td]');
1764
+ html = html.replace(/<td><br><\/td>/gi, '[td]');
1765
+ html = html.replace(/<a(.*?)href="(.*?)"(.*?)>([\w\W]*?)<\/a>/gi, '[a href="$2"]$4[/a]');
1766
+ html = html.replace(/<iframe(.*?)>([\w\W]*?)<\/iframe>/gi, '[iframe$1]$2[/iframe]');
1767
+ html = html.replace(/<video(.*?)>([\w\W]*?)<\/video>/gi, '[video$1]$2[/video]');
1768
+ html = html.replace(/<audio(.*?)>([\w\W]*?)<\/audio>/gi, '[audio$1]$2[/audio]');
1769
+ html = html.replace(/<embed(.*?)>([\w\W]*?)<\/embed>/gi, '[embed$1]$2[/embed]');
1770
+ html = html.replace(/<object(.*?)>([\w\W]*?)<\/object>/gi, '[object$1]$2[/object]');
1771
+ html = html.replace(/<param(.*?)>/gi, '[param$1]');
1772
+ html = html.replace(/<img(.*?)style="(.*?)"(.*?)>/gi, '[img$1$3]');
1773
+
1774
+ // remove attributes
1775
+ html = html.replace(/<(\w+)([\w\W]*?)>/gi, '<$1>');
1776
+
1777
+ // remove empty
1778
+ html = html.replace(/<[^\/>][^>]*>(\s*|\t*|\n*|&nbsp;|<br>)<\/[^>]+>/gi, '');
1779
+ html = html.replace(/<[^\/>][^>]*>(\s*|\t*|\n*|&nbsp;|<br>)<\/[^>]+>/gi, '');
1780
+
1781
+ // revert
1782
+ html = html.replace(/\[td\]/gi, '<td>&nbsp;</td>');
1783
+ html = html.replace(/\[a href="(.*?)"\]([\w\W]*?)\[\/a\]/gi, '<a href="$1">$2</a>');
1784
+ html = html.replace(/\[iframe(.*?)\]([\w\W]*?)\[\/iframe\]/gi, '<iframe$1>$2</iframe>');
1785
+ html = html.replace(/\[video(.*?)\]([\w\W]*?)\[\/video\]/gi, '<video$1>$2</video>');
1786
+ html = html.replace(/\[audio(.*?)\]([\w\W]*?)\[\/audio\]/gi, '<audio$1>$2</audio>');
1787
+ html = html.replace(/\[embed(.*?)\]([\w\W]*?)\[\/embed\]/gi, '<embed$1>$2</embed>');
1788
+ html = html.replace(/\[object(.*?)\]([\w\W]*?)\[\/object\]/gi, '<object$1>$2</object>');
1789
+ html = html.replace(/\[param(.*?)\]/gi, '<param$1>');
1790
+ html = html.replace(/\[img(.*?)\]/gi, '<img$1>');
1791
+
1792
+
1793
+ // convert div to p
1794
+ if (this.opts.convertDivs)
1795
+ {
1796
+ html = html.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi, '<p>$2</p>');
1797
+ }
1798
+
1799
+ // remove span
1800
+ html = html.replace(/<span>([\w\W]*?)<\/span>/gi, '$1');
1801
+
1802
+ html = html.replace(/\n{3,}/gi, '\n');
1803
+
1804
+ // remove dirty p
1805
+ html = html.replace(/<p><p>/gi, '<p>');
1806
+ html = html.replace(/<\/p><\/p>/gi, '</p>');
1807
+
1808
+ // FF fix
1809
+ if (this.browser('mozilla'))
1810
+ {
1811
+ html = html.replace(/<br>$/gi, '');
1812
+ }
1813
+
1814
+ this.pasteCleanUpInsert(html);
1815
+
1816
+ },
1817
+
1818
+ pasteCleanUpInsert: function(html)
1819
+ {
1820
+ this.execCommand('inserthtml', html);
1821
+
1822
+ if (this.opts.autoresize === true)
1823
+ {
1824
+ $(this.document.body).scrollTop(this.saveScroll);
1825
+ }
1826
+ else
1827
+ {
1828
+ this.$editor.scrollTop(this.saveScroll);
1829
+ }
1830
+ },
1831
+
1832
+
1833
+ // TEXTAREA CODE FORMATTING
1834
+ formattingRemove: function(html)
1835
+ {
1836
+ // save pre
1837
+ var prebuffer = [];
1838
+ var pre = html.match(/<pre(.*?)>([\w\W]*?)<\/pre>/gi);
1839
+ if (pre !== null)
1840
+ {
1841
+ $.each(pre, function(i,s)
1842
+ {
1843
+ html = html.replace(s, 'prebuffer_' + i);
1844
+ prebuffer.push(s);
1845
+ });
1846
+ }
1847
+
1848
+ html = html.replace(/\s{2,}/g, ' ');
1849
+ html = html.replace(/\n/g, ' ');
1850
+ html = html.replace(/[\t]*/g, '');
1851
+ html = html.replace(/\n\s*\n/g, "\n");
1852
+ html = html.replace(/^[\s\n]*/g, '');
1853
+ html = html.replace(/[\s\n]*$/g, '');
1854
+ html = html.replace(/>\s+</g, '><');
1855
+
1856
+ if (prebuffer)
1857
+ {
1858
+ $.each(prebuffer, function(i,s)
1859
+ {
1860
+ html = html.replace('prebuffer_' + i, s);
1861
+ });
1862
+
1863
+ prebuffer = [];
1864
+ }
1865
+
1866
+ return html;
1867
+ },
1868
+ formattingIndenting: function(html)
1869
+ {
1870
+ html = html.replace(/<li/g, "\t<li");
1871
+ html = html.replace(/<tr/g, "\t<tr");
1872
+ html = html.replace(/<td/g, "\t\t<td");
1873
+ html = html.replace(/<\/tr>/g, "\t</tr>");
1874
+
1875
+ return html;
1876
+ },
1877
+ formattingEmptyTags: function(html)
1878
+ {
1879
+ var etags = ["<pre></pre>","<blockquote>\\s*</blockquote>","<em>\\s*</em>","<ul></ul>","<ol></ol>","<li></li>","<table></table>","<tr></tr>","<span>\\s*<span>", "<span>&nbsp;<span>", "<b>\\s*</b>", "<b>&nbsp;</b>", "<p>\\s*</p>", "<p>&nbsp;</p>", "<p>\\s*<br>\\s*</p>", "<div>\\s*</div>", "<div>\\s*<br>\\s*</div>"];
1880
+ for (var i = 0; i < etags.length; ++i)
1881
+ {
1882
+ var bbb = etags[i];
1883
+ html = html.replace(new RegExp(bbb,'gi'), "");
1884
+ }
1885
+
1886
+ return html;
1887
+ },
1888
+ formattingAddBefore: function(html)
1889
+ {
1890
+ var lb = '\r\n';
1891
+ var btags = ["<p", "<form","</ul>", '</ol>', "<fieldset","<legend","<object","<embed","<select","<option","<input","<textarea","<pre","<blockquote","<ul","<ol","<li","<dl","<dt","<dd","<table", "<thead","<tbody","<caption","</caption>","<th","<tr","<td","<figure"];
1892
+ for (var i = 0; i < btags.length; ++i)
1893
+ {
1894
+ var eee = btags[i];
1895
+ html = html.replace(new RegExp(eee,'gi'),lb+eee);
1896
+ }
1897
+
1898
+ return html;
1899
+ },
1900
+ formattingAddAfter: function(html)
1901
+ {
1902
+ var lb = '\r\n';
1903
+ var atags = ['</p>', '</div>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>', '<br>', '<br />', '</dl>', '</dt>', '</dd>', '</form>', '</blockquote>', '</pre>', '</legend>', '</fieldset>', '</object>', '</embed>', '</textarea>', '</select>', '</option>', '</table>', '</thead>', '</tbody>', '</tr>', '</td>', '</th>', '</figure>'];
1904
+ for (var i = 0; i < atags.length; ++i)
1905
+ {
1906
+ var aaa = atags[i];
1907
+ html = html.replace(new RegExp(aaa,'gi'),aaa+lb);
1908
+ }
1909
+
1910
+ return html;
1911
+ },
1912
+ formatting: function(html)
1913
+ {
1914
+ html = this.formattingRemove(html);
1915
+
1916
+ // empty tags
1917
+ html = this.formattingEmptyTags(html);
1918
+
1919
+ // add formatting before
1920
+ html = this.formattingAddBefore(html);
1921
+
1922
+ // add formatting after
1923
+ html = this.formattingAddAfter(html);
1924
+
1925
+ // indenting
1926
+ html = this.formattingIndenting(html);
1927
+
1928
+ return html;
1929
+ },
1930
+
1931
+ // TOGGLE
1932
+ toggle: function()
1933
+ {
1934
+ var html;
1935
+
1936
+ if (this.opts.visual)
1937
+ {
1938
+ var height = this.$editor.innerHeight();
1939
+
1940
+ this.$editor.hide();
1941
+ this.$content.hide();
1942
+
1943
+ html = this.$editor.html();
1944
+ //html = $.trim(this.formatting(html));
1945
+
1946
+ this.$el.height(height).val(html).show().focus();
1947
+
1948
+ this.setBtnActive('html');
1949
+ this.opts.visual = false;
1950
+ }
1951
+ else
1952
+ {
1953
+ this.$el.hide();
1954
+ var html = this.$el.val();
1955
+
1956
+ //html = this.savePreCode(html);
1957
+
1958
+ // clean up
1959
+ //html = this.stripTags(html);
1960
+
1961
+ // set code
1962
+ this.$editor.html(html).show();
1963
+ this.$content.show();
1964
+
1965
+ if (this.$editor.html() === '')
1966
+ {
1967
+ this.setCode(this.opts.emptyHtml);
1968
+ }
1969
+
1970
+ this.$editor.focus();
1971
+
1972
+ this.setBtnInactive('html');
1973
+ this.opts.visual = true;
1974
+
1975
+ this.observeImages();
1976
+ this.observeTables();
1977
+ }
1978
+ },
1979
+
1980
+ // AUTOSAVE
1981
+ autoSave: function()
1982
+ {
1983
+ this.autosaveInterval = setInterval($.proxy(function()
1984
+ {
1985
+ $.ajax({
1986
+ url: this.opts.autosave,
1987
+ type: 'post',
1988
+ data: this.$el.attr('name') + '=' + escape(encodeURIComponent(this.getCode())),
1989
+ success: $.proxy(function(data)
1990
+ {
1991
+ // callback
1992
+ if (typeof this.opts.autosaveCallback === 'function')
1993
+ {
1994
+ this.opts.autosaveCallback(data, this);
1995
+ }
1996
+
1997
+ }, this)
1998
+ });
1999
+
2000
+
2001
+ }, this), this.opts.interval*1000);
2002
+ },
2003
+
2004
+ // TOOLBAR
2005
+ buildToolbar: function()
2006
+ {
2007
+ if (this.opts.toolbar === false)
2008
+ {
2009
+ return false;
2010
+ }
2011
+
2012
+ this.$toolbar = $('<ul>').addClass('redactor_toolbar');
2013
+
2014
+ if (this.opts.air)
2015
+ {
2016
+ $(this.air).append(this.$toolbar);
2017
+ $('body').append(this.air);
2018
+ }
2019
+ else
2020
+ {
2021
+ if (this.opts.toolbarExternal === false)
2022
+ {
2023
+ this.$box.prepend(this.$toolbar);
2024
+ }
2025
+ else
2026
+ {
2027
+ $(this.opts.toolbarExternal).html(this.$toolbar);
2028
+ }
2029
+ }
2030
+
2031
+ $.each(this.opts.buttons, $.proxy(function(i,key)
2032
+ {
2033
+
2034
+ if (key !== '|' && typeof this.opts.toolbar[key] !== 'undefined')
2035
+ {
2036
+ var s = this.opts.toolbar[key];
2037
+
2038
+ if (this.opts.fileUpload === false && key === 'file')
2039
+ {
2040
+ return true;
2041
+ }
2042
+
2043
+ this.$toolbar.append($('<li>').append(this.buildButton(key, s)));
2044
+ }
2045
+
2046
+
2047
+ if (key === '|')
2048
+ {
2049
+ this.$toolbar.append($('<li class="redactor_separator"></li>'));
2050
+ }
2051
+
2052
+ }, this));
2053
+
2054
+ },
2055
+ buildButton: function(key, s)
2056
+ {
2057
+ var button = $('<a href="javascript:void(null);" title="' + s.title + '" class="redactor_btn_' + key + '"></a>');
2058
+
2059
+ if (typeof s.func === 'undefined')
2060
+ {
2061
+ button.click($.proxy(function()
2062
+ {
2063
+ if ($.inArray(key, this.opts.activeButtons) != -1)
2064
+ {
2065
+ this.inactiveAllButtons();
2066
+ this.setBtnActive(key);
2067
+ }
2068
+
2069
+ if (this.browser('mozilla'))
2070
+ {
2071
+ this.$editor.focus();
2072
+ //this.restoreSelection();
2073
+ }
2074
+
2075
+ this.execCommand(s.exec, key);
2076
+
2077
+ }, this));
2078
+ }
2079
+ else if (s.func !== 'show')
2080
+ {
2081
+ button.click($.proxy(function(e) {
2082
+
2083
+ this[s.func](e);
2084
+
2085
+ }, this));
2086
+ }
2087
+
2088
+ if (typeof s.callback !== 'undefined' && s.callback !== false)
2089
+ {
2090
+ button.click($.proxy(function(e) { s.callback(this, e, key); }, this));
2091
+ }
2092
+
2093
+ // dropdown
2094
+ if (key === 'backcolor' || key === 'fontcolor' || typeof(s.dropdown) !== 'undefined')
2095
+ {
2096
+ var dropdown = $('<div class="redactor_dropdown" style="display: none;">');
2097
+
2098
+ if (key === 'backcolor' || key === 'fontcolor')
2099
+ {
2100
+ dropdown = this.buildColorPicker(dropdown, key);
2101
+ }
2102
+ else
2103
+ {
2104
+ dropdown = this.buildDropdown(dropdown, s.dropdown);
2105
+ }
2106
+
2107
+ this.dropdowns.push(dropdown.appendTo($(document.body)));
2108
+
2109
+ // observing dropdown
2110
+ this.hdlShowDropDown = $.proxy(function(e) { this.showDropDown(e, dropdown, key); }, this);
2111
+
2112
+ button.click(this.hdlShowDropDown);
2113
+ }
2114
+
2115
+ return button;
2116
+ },
2117
+ buildDropdown: function(dropdown, obj)
2118
+ {
2119
+ $.each(obj, $.proxy(
2120
+ function (x, d)
2121
+ {
2122
+ if (typeof(d.className) === 'undefined')
2123
+ {
2124
+ d.className = '';
2125
+ }
2126
+
2127
+ var drop_a;
2128
+ if (typeof d.name !== 'undefined' && d.name === 'separator')
2129
+ {
2130
+ drop_a = $('<a class="redactor_separator_drop">');
2131
+ }
2132
+ else
2133
+ {
2134
+ drop_a = $('<a href="javascript:void(null);" class="' + d.className + '">' + d.title + '</a>');
2135
+
2136
+ if (typeof(d.callback) === 'function')
2137
+ {
2138
+ $(drop_a).click($.proxy(function(e) { d.callback(this, e, x); }, this));
2139
+ }
2140
+ else if (typeof(d.func) === 'undefined')
2141
+ {
2142
+ $(drop_a).click($.proxy(function() { this.execCommand(d.exec, x); }, this));
2143
+ }
2144
+ else
2145
+ {
2146
+ $(drop_a).click($.proxy(function(e) { this[d.func](e); }, this));
2147
+ }
2148
+ }
2149
+
2150
+ $(dropdown).append(drop_a);
2151
+
2152
+ }, this)
2153
+ );
2154
+
2155
+ return dropdown;
2156
+
2157
+ },
2158
+ buildColorPicker: function(dropdown, key)
2159
+ {
2160
+ var mode;
2161
+ if (key === 'backcolor')
2162
+ {
2163
+ if (this.browser('msie'))
2164
+ {
2165
+ mode = 'BackColor';
2166
+ }
2167
+ else
2168
+ {
2169
+ mode = 'hilitecolor';
2170
+ }
2171
+ }
2172
+ else
2173
+ {
2174
+ mode = 'forecolor';
2175
+ }
2176
+
2177
+ $(dropdown).width(210);
2178
+
2179
+ var len = this.opts.colors.length;
2180
+ for (var i = 0; i < len; ++i)
2181
+ {
2182
+ var color = this.opts.colors[i];
2183
+
2184
+ var swatch = $('<a rel="' + color + '" href="javascript:void(null);" class="redactor_color_link"></a>').css({ 'backgroundColor': color });
2185
+ $(dropdown).append(swatch);
2186
+
2187
+ var _self = this;
2188
+ $(swatch).click(function()
2189
+ {
2190
+ _self.execCommand(mode, $(this).attr('rel'));
2191
+
2192
+ if (mode === 'forecolor')
2193
+ {
2194
+ _self.$editor.find('font').replaceWith(function() {
2195
+
2196
+ return $('<span style="color: ' + $(this).attr('color') + ';">' + $(this).html() + '</span>');
2197
+
2198
+ });
2199
+ }
2200
+
2201
+ if (_self.browser('msie') && mode === 'BackColor')
2202
+ {
2203
+ _self.$editor.find('font').replaceWith(function() {
2204
+
2205
+ return $('<span style="' + $(this).attr('style') + '">' + $(this).html() + '</span>');
2206
+
2207
+ });
2208
+ }
2209
+
2210
+ });
2211
+ }
2212
+
2213
+ var elnone = $('<a href="javascript:void(null);" class="redactor_color_none"></a>').html(RLANG.none);
2214
+
2215
+ if (key === 'backcolor')
2216
+ {
2217
+ elnone.click($.proxy(this.setBackgroundNone, this));
2218
+ }
2219
+ else
2220
+ {
2221
+ elnone.click($.proxy(this.setColorNone, this));
2222
+ }
2223
+
2224
+ $(dropdown).append(elnone);
2225
+
2226
+ return dropdown;
2227
+ },
2228
+ setBackgroundNone: function()
2229
+ {
2230
+ $(this.getParentNode()).css('background-color', 'transparent');
2231
+ this.syncCode();
2232
+ },
2233
+ setColorNone: function()
2234
+ {
2235
+ $(this.getParentNode()).attr('color', '').css('color', '');
2236
+ this.syncCode();
2237
+ },
2238
+
2239
+ // DROPDOWNS
2240
+ showDropDown: function(e, dropdown, key)
2241
+ {
2242
+ if (this.getBtn(key).hasClass('dropact'))
2243
+ {
2244
+ this.hideAllDropDown();
2245
+ }
2246
+ else
2247
+ {
2248
+ this.hideAllDropDown();
2249
+
2250
+ this.setBtnActive(key);
2251
+ this.getBtn(key).addClass('dropact');
2252
+
2253
+ var left = this.getBtn(key).offset().left;
2254
+
2255
+ if (this.opts.air)
2256
+ {
2257
+ var air_top = this.air.offset().top;
2258
+
2259
+ $(dropdown).css({ position: 'absolute', left: left + 'px', top: air_top+30 + 'px' }).show();
2260
+ }
2261
+ else if (this.opts.fixed && this.fixed)
2262
+ {
2263
+ $(dropdown).css({ position: 'fixed', left: left + 'px', top: '30px' }).show();
2264
+ }
2265
+ else
2266
+ {
2267
+ var top = this.$toolbar.offset().top + 30;
2268
+ $(dropdown).css({ position: 'absolute', left: left + 'px', top: top + 'px' }).show();
2269
+ }
2270
+ }
2271
+
2272
+ var hdlHideDropDown = $.proxy(function(e) { this.hideDropDown(e, dropdown, key); }, this);
2273
+
2274
+ $(document).one('click', hdlHideDropDown);
2275
+ this.$editor.one('click', hdlHideDropDown);
2276
+ this.$content.one('click', hdlHideDropDown);
2277
+
2278
+ e.stopPropagation();
2279
+
2280
+ },
2281
+ hideAllDropDown: function()
2282
+ {
2283
+ this.$toolbar.find('a.dropact').removeClass('redactor_act').removeClass('dropact');
2284
+ $('.redactor_dropdown').hide();
2285
+ },
2286
+ hideDropDown: function(e, dropdown, key)
2287
+ {
2288
+ if (!$(e.target).hasClass('dropact'))
2289
+ {
2290
+ $(dropdown).removeClass('dropact');
2291
+ this.showedDropDown = false;
2292
+ this.hideAllDropDown();
2293
+ }
2294
+ },
2295
+
2296
+ // BUTTONS MANIPULATIONS
2297
+ getBtn: function(key)
2298
+ {
2299
+ if (this.opts.toolbar === false)
2300
+ {
2301
+ return false;
2302
+ }
2303
+
2304
+ return $(this.$toolbar.find('a.redactor_btn_' + key));
2305
+ },
2306
+ setBtnActive: function(key)
2307
+ {
2308
+ this.getBtn(key).addClass('redactor_act');
2309
+ },
2310
+ setBtnInactive: function(key)
2311
+ {
2312
+ this.getBtn(key).removeClass('redactor_act');
2313
+ },
2314
+ inactiveAllButtons: function()
2315
+ {
2316
+ $.each(this.opts.activeButtons, $.proxy(function(i,s)
2317
+ {
2318
+ this.setBtnInactive(s);
2319
+
2320
+ }, this));
2321
+ },
2322
+ changeBtnIcon: function(key, classname)
2323
+ {
2324
+ this.getBtn(key).addClass('redactor_btn_' + classname);
2325
+ },
2326
+ removeBtnIcon: function(key, classname)
2327
+ {
2328
+ this.getBtn(key).removeClass('redactor_btn_' + classname);
2329
+ },
2330
+
2331
+ addBtnSeparator: function()
2332
+ {
2333
+ this.$toolbar.append($('<li class="redactor_separator"></li>'));
2334
+ },
2335
+ addBtnSeparatorAfter: function(key)
2336
+ {
2337
+ var $btn = this.getBtn(key);
2338
+ $btn.parent().after($('<li class="redactor_separator"></li>'));
2339
+ },
2340
+ addBtnSeparatorBefore: function(key)
2341
+ {
2342
+ var $btn = this.getBtn(key);
2343
+ $btn.parent().before($('<li class="redactor_separator"></li>'));
2344
+ },
2345
+ removeBtnSeparatorAfter: function(key)
2346
+ {
2347
+ var $btn = this.getBtn(key);
2348
+ $btn.parent().next().remove();
2349
+ },
2350
+ removeBtnSeparatorBefore: function(key)
2351
+ {
2352
+ var $btn = this.getBtn(key);
2353
+ $btn.parent().prev().remove();
2354
+ },
2355
+
2356
+ setBtnRight: function(key)
2357
+ {
2358
+ if (this.opts.toolbar === false)
2359
+ {
2360
+ return false;
2361
+ }
2362
+
2363
+ this.getBtn(key).parent().addClass('redactor_btn_right');
2364
+ },
2365
+ setBtnLeft: function(key)
2366
+ {
2367
+ if (this.opts.toolbar === false)
2368
+ {
2369
+ return false;
2370
+ }
2371
+
2372
+ this.getBtn(key).parent().removeClass('redactor_btn_right');
2373
+ },
2374
+ addBtn: function(key, title, callback, dropdown)
2375
+ {
2376
+ if (this.opts.toolbar === false)
2377
+ {
2378
+ return false;
2379
+ }
2380
+
2381
+ var btn = this.buildButton(key, { title: title, callback: callback, dropdown: dropdown });
2382
+ this.$toolbar.append($('<li>').append(btn));
2383
+ },
2384
+ addBtnFirst: function(key, title, callback, dropdown)
2385
+ {
2386
+ if (this.opts.toolbar === false)
2387
+ {
2388
+ return false;
2389
+ }
2390
+
2391
+ var btn = this.buildButton(key, { title: title, callback: callback, dropdown: dropdown });
2392
+ this.$toolbar.prepend($('<li>').append(btn));
2393
+ },
2394
+ addBtnAfter: function(afterkey, key, title, callback, dropdown)
2395
+ {
2396
+ if (this.opts.toolbar === false)
2397
+ {
2398
+ return false;
2399
+ }
2400
+
2401
+ var btn = this.buildButton(key, { title: title, callback: callback, dropdown: dropdown });
2402
+ var $btn = this.getBtn(afterkey);
2403
+ $btn.parent().after($('<li>').append(btn));
2404
+ },
2405
+ addBtnBefore: function(beforekey, key, title, callback, dropdown)
2406
+ {
2407
+ if (this.opts.toolbar === false)
2408
+ {
2409
+ return false;
2410
+ }
2411
+
2412
+ var btn = this.buildButton(key, { title: title, callback: callback, dropdown: dropdown });
2413
+ var $btn = this.getBtn(beforekey);
2414
+ $btn.parent().before($('<li>').append(btn));
2415
+ },
2416
+ removeBtn: function(key, separator)
2417
+ {
2418
+ var $btn = this.getBtn(key);
2419
+
2420
+ if (separator === true)
2421
+ {
2422
+ $btn.parent().next().remove();
2423
+ }
2424
+
2425
+ $btn.parent().removeClass('redactor_btn_right');
2426
+ $btn.remove();
2427
+ },
2428
+
2429
+
2430
+ // SELECTION AND NODE MANIPULATION
2431
+ getFragmentHtml: function (fragment)
2432
+ {
2433
+ var cloned = fragment.cloneNode(true);
2434
+ var div = this.document.createElement('div');
2435
+ div.appendChild(cloned);
2436
+ return div.innerHTML;
2437
+ },
2438
+ extractContent: function()
2439
+ {
2440
+ var node = this.$editor.get(0);
2441
+ var frag = this.document.createDocumentFragment(), child;
2442
+ while ((child = node.firstChild))
2443
+ {
2444
+ frag.appendChild(child);
2445
+ }
2446
+
2447
+ return frag;
2448
+ },
2449
+
2450
+ // Save and Restore Selection
2451
+ saveSelection: function()
2452
+ {
2453
+ this.$editor.focus();
2454
+
2455
+ this.savedSel = this.getOrigin();
2456
+ this.savedSelObj = this.getFocus();
2457
+ },
2458
+ restoreSelection: function()
2459
+ {
2460
+ if (typeof this.savedSel !== 'undefined' && this.savedSel !== null && this.savedSelObj !== null && this.savedSel[0].tagName !== 'BODY')
2461
+ {
2462
+ if (this.opts.iframe === false && $(this.savedSel[0]).closest('.redactor_editor').size() == 0)
2463
+ {
2464
+ this.$editor.focus();
2465
+ }
2466
+ else
2467
+ {
2468
+ if (this.browser('opera'))
2469
+ {
2470
+ this.$editor.focus();
2471
+ }
2472
+
2473
+ this.setSelection(this.savedSel[0], this.savedSel[1], this.savedSelObj[0], this.savedSelObj[1]);
2474
+
2475
+ if (this.browser('mozilla'))
2476
+ {
2477
+ this.$editor.focus();
2478
+ }
2479
+ }
2480
+ }
2481
+ else
2482
+ {
2483
+ this.$editor.focus();
2484
+ }
2485
+ },
2486
+
2487
+ // Selection
2488
+ getSelection: function()
2489
+ {
2490
+ var doc = this.document;
2491
+
2492
+ if (this.window.getSelection)
2493
+ {
2494
+ return this.window.getSelection();
2495
+ }
2496
+ else if (doc.getSelection)
2497
+ {
2498
+ return doc.getSelection();
2499
+ }
2500
+ else // IE
2501
+ {
2502
+ return doc.selection.createRange();
2503
+ }
2504
+
2505
+ return false;
2506
+ },
2507
+ hasSelection: function()
2508
+ {
2509
+ if (!this.oldIE())
2510
+ {
2511
+ var sel;
2512
+ return (sel = this.getSelection()) && (sel.focusNode != null) && (sel.anchorNode != null);
2513
+ }
2514
+ else // IE8
2515
+ {
2516
+ var node = this.$editor.get(0);
2517
+
2518
+ var range;
2519
+ node.focus();
2520
+ if (!node.document.selection)
2521
+ {
2522
+ return false;
2523
+ }
2524
+
2525
+ range = node.document.selection.createRange();
2526
+ return range && range.parentElement().document === node.document;
2527
+ }
2528
+ },
2529
+ getOrigin: function()
2530
+ {
2531
+ if (!this.oldIE())
2532
+ {
2533
+ var sel;
2534
+ if (!((sel = this.getSelection()) && (sel.anchorNode != null)))
2535
+ {
2536
+ return null;
2537
+ }
2538
+
2539
+ return [sel.anchorNode, sel.anchorOffset];
2540
+ }
2541
+ else
2542
+ {
2543
+ var node = this.$editor.get(0);
2544
+
2545
+ var range;
2546
+ node.focus();
2547
+ if (!this.hasSelection())
2548
+ {
2549
+ return null;
2550
+ }
2551
+
2552
+ range = node.document.selection.createRange();
2553
+ return this._getBoundary(node.document, range, true);
2554
+ }
2555
+ },
2556
+ getFocus: function()
2557
+ {
2558
+ if (!this.oldIE())
2559
+ {
2560
+ var sel;
2561
+ if (!((sel = this.getSelection()) && (sel.focusNode != null)))
2562
+ {
2563
+ return null;
2564
+ }
2565
+
2566
+ return [sel.focusNode, sel.focusOffset];
2567
+ }
2568
+ else
2569
+ {
2570
+ var node = this.$editor.get(0);
2571
+
2572
+ var range;
2573
+ node.focus();
2574
+ if (!this.hasSelection())
2575
+ {
2576
+ return null;
2577
+ }
2578
+
2579
+ range = node.document.selection.createRange();
2580
+ return this._getBoundary(node.document, range, false);
2581
+
2582
+ }
2583
+ },
2584
+ setSelection: function (orgn, orgo, focn, foco)
2585
+ {
2586
+ if (focn == null)
2587
+ {
2588
+ focn = orgn;
2589
+ }
2590
+
2591
+ if (foco == null)
2592
+ {
2593
+ foco = orgo;
2594
+ }
2595
+
2596
+ if (!this.oldIE())
2597
+ {
2598
+ var sel = this.getSelection();
2599
+ if (!sel)
2600
+ {
2601
+ return;
2602
+ }
2603
+
2604
+ if (sel.collapse && sel.extend)
2605
+ {
2606
+ sel.collapse(orgn, orgo);
2607
+ sel.extend(focn, foco);
2608
+ }
2609
+ else // IE9
2610
+ {
2611
+ r = this.document.createRange();
2612
+ r.setStart(orgn, orgo);
2613
+ r.setEnd(focn, foco);
2614
+
2615
+ try
2616
+ {
2617
+ sel.removeAllRanges();
2618
+ }
2619
+ catch (e) {}
2620
+
2621
+ sel.addRange(r);
2622
+ }
2623
+ }
2624
+ else
2625
+ {
2626
+ var node = this.$editor.get(0);
2627
+ var range = node.document.body.createTextRange();
2628
+
2629
+ this._moveBoundary(node.document, range, false, focn, foco);
2630
+ this._moveBoundary(node.document, range, true, orgn, orgo);
2631
+ return range.select();
2632
+ }
2633
+ },
2634
+
2635
+ // Get elements, html and text
2636
+ getCurrentNode: function()
2637
+ {
2638
+ if (typeof this.window.getSelection !== 'undefined')
2639
+ {
2640
+ return this.getSelectedNode().parentNode;
2641
+ }
2642
+ else if (typeof this.document.selection !== 'undefined')
2643
+ {
2644
+ return this.getSelection().parentElement();
2645
+ }
2646
+ },
2647
+ getParentNode: function()
2648
+ {
2649
+ return $(this.getCurrentNode()).parent()[0]
2650
+ },
2651
+ getSelectedNode: function()
2652
+ {
2653
+ if (this.oldIE())
2654
+ {
2655
+ return this.getSelection().parentElement();
2656
+ }
2657
+ else if (typeof this.window.getSelection !== 'undefined')
2658
+ {
2659
+ var s = this.window.getSelection();
2660
+ if (s.rangeCount > 0)
2661
+ {
2662
+ return this.getSelection().getRangeAt(0).commonAncestorContainer;
2663
+ }
2664
+ else
2665
+ {
2666
+ return false;
2667
+ }
2668
+ }
2669
+ else if (typeof this.document.selection !== 'undefined')
2670
+ {
2671
+ return this.getSelection();
2672
+ }
2673
+ },
2674
+
2675
+
2676
+ // IE8 specific selection
2677
+ _getBoundary: function(doc, textRange, bStart)
2678
+ {
2679
+ var cursor, cursorNode, node, offset, parent;
2680
+
2681
+ cursorNode = doc.createElement('a');
2682
+ cursor = textRange.duplicate();
2683
+ cursor.collapse(bStart);
2684
+ parent = cursor.parentElement();
2685
+ while (true)
2686
+ {
2687
+ parent.insertBefore(cursorNode, cursorNode.previousSibling);
2688
+ cursor.moveToElementText(cursorNode);
2689
+ if (!(cursor.compareEndPoints((bStart ? 'StartToStart' : 'StartToEnd'), textRange) > 0 && (cursorNode.previousSibling != null)))
2690
+ {
2691
+ break;
2692
+ }
2693
+ }
2694
+
2695
+ if (cursor.compareEndPoints((bStart ? 'StartToStart' : 'StartToEnd'), textRange) === -1 && cursorNode.nextSibling)
2696
+ {
2697
+ cursor.setEndPoint((bStart ? 'EndToStart' : 'EndToEnd'), textRange);
2698
+ node = cursorNode.nextSibling;
2699
+ offset = cursor.text.length;
2700
+ }
2701
+ else
2702
+ {
2703
+ node = cursorNode.parentNode;
2704
+ offset = this._getChildIndex(cursorNode);
2705
+ }
2706
+
2707
+ cursorNode.parentNode.removeChild(cursorNode);
2708
+ return [node, offset];
2709
+ },
2710
+ _moveBoundary: function(doc, textRange, bStart, node, offset)
2711
+ {
2712
+ var anchorNode, anchorParent, cursor, cursorNode, textOffset;
2713
+
2714
+ textOffset = 0;
2715
+ anchorNode = this._isText(node) ? node : node.childNodes[offset];
2716
+ anchorParent = this._isText(node) ? node.parentNode : node;
2717
+
2718
+ if (this._isText(node))
2719
+ {
2720
+ textOffset = offset;
2721
+ }
2722
+
2723
+ cursorNode = doc.createElement('a');
2724
+ anchorParent.insertBefore(cursorNode, anchorNode || null);
2725
+ cursor = doc.body.createTextRange();
2726
+ cursor.moveToElementText(cursorNode);
2727
+ cursorNode.parentNode.removeChild(cursorNode);
2728
+
2729
+ textRange.setEndPoint((bStart ? 'StartToStart' : 'EndToEnd'), cursor);
2730
+ return textRange[bStart ? 'moveStart' : 'moveEnd']('character', textOffset);
2731
+ },
2732
+ _isText: function (d)
2733
+ {
2734
+ return (d != null ? d.nodeType == 3 : false);
2735
+ },
2736
+ _getChildIndex: function (e)
2737
+ {
2738
+ var k = 0;
2739
+ while (e = e.previousSibling) {
2740
+ k++;
2741
+ }
2742
+ return k;
2743
+ },
2744
+
2745
+ insertNodeAfterCaret: function(node)
2746
+ {
2747
+ this.saveSelection();
2748
+ this.insertNodeAtCaret(node);
2749
+ this.restoreSelection();
2750
+ },
2751
+
2752
+ insertNodeAtCaret: function(node)
2753
+ {
2754
+ if (this.window.getSelection)
2755
+ {
2756
+ var sel = this.getSelection();
2757
+ if (sel.rangeCount)
2758
+ {
2759
+ var range = sel.getRangeAt(0);
2760
+ range.collapse(false);
2761
+ range.insertNode(node);
2762
+ range = range.cloneRange();
2763
+ range.selectNodeContents(node);
2764
+ range.collapse(false);
2765
+ sel.removeAllRanges();
2766
+ sel.addRange(range);
2767
+ }
2768
+ }
2769
+ else if (this.document.selection)
2770
+ {
2771
+ var html = (node.nodeType === 1) ? node.outerHTML : node.data;
2772
+ var id = "marker_" + ("" + Math.random()).slice(2);
2773
+ html += '<span id="' + id + '"></span>';
2774
+ var textRange = this.getSelection();
2775
+ textRange.collapse(false);
2776
+ textRange.pasteHTML(html);
2777
+ var markerSpan = this.document.getElementById(id);
2778
+ textRange.moveToElementText(markerSpan);
2779
+ textRange.select();
2780
+ markerSpan.parentNode.removeChild(markerSpan);
2781
+ }
2782
+ },
2783
+ getSelectedHtml: function()
2784
+ {
2785
+ var html = '';
2786
+ if (this.window.getSelection)
2787
+ {
2788
+ var sel = this.window.getSelection();
2789
+ if (sel.rangeCount)
2790
+ {
2791
+ var container = this.document.createElement("div");
2792
+ for (var i = 0, len = sel.rangeCount; i < len; ++i)
2793
+ {
2794
+ container.appendChild(sel.getRangeAt(i).cloneContents());
2795
+ }
2796
+
2797
+ html = container.innerHTML;
2798
+
2799
+ }
2800
+ }
2801
+ else if (this.document.selection)
2802
+ {
2803
+ if (this.document.selection.type === "Text")
2804
+ {
2805
+ html = this.document.selection.createRange().htmlText;
2806
+ }
2807
+ }
2808
+
2809
+ return html;
2810
+ },
2811
+
2812
+ // RESIZE IMAGES
2813
+ resizeImage: function(resize)
2814
+ {
2815
+ var clicked = false;
2816
+ var clicker = false;
2817
+ var start_x;
2818
+ var start_y;
2819
+ var ratio = $(resize).width()/$(resize).height();
2820
+ var min_w = 10;
2821
+ var min_h = 10;
2822
+
2823
+ $(resize).off('hover mousedown mouseup click mousemove');
2824
+ $(resize).hover(function() { $(resize).css('cursor', 'nw-resize'); }, function() { $(resize).css('cursor',''); clicked = false; });
2825
+
2826
+ $(resize).mousedown(function(e)
2827
+ {
2828
+ e.preventDefault();
2829
+
2830
+ ratio = $(resize).width()/$(resize).height();
2831
+
2832
+ clicked = true;
2833
+ clicker = true;
2834
+
2835
+ start_x = Math.round(e.pageX - $(resize).eq(0).offset().left);
2836
+ start_y = Math.round(e.pageY - $(resize).eq(0).offset().top);
2837
+ });
2838
+
2839
+ $(resize).mouseup($.proxy(function(e)
2840
+ {
2841
+ clicked = false;
2842
+ $(resize).css('cursor','');
2843
+ this.syncCode();
2844
+
2845
+ }, this));
2846
+
2847
+ $(resize).click($.proxy(function(e)
2848
+ {
2849
+ if (clicker)
2850
+ {
2851
+ this.imageEdit(e);
2852
+ }
2853
+
2854
+ }, this));
2855
+
2856
+ $(resize).mousemove(function(e)
2857
+ {
2858
+ if (clicked)
2859
+ {
2860
+ clicker = false;
2861
+
2862
+ var mouse_x = Math.round(e.pageX - $(this).eq(0).offset().left) - start_x;
2863
+ var mouse_y = Math.round(e.pageY - $(this).eq(0).offset().top) - start_y;
2864
+
2865
+ var div_h = $(resize).height();
2866
+
2867
+ var new_h = parseInt(div_h, 10) + mouse_y;
2868
+ var new_w = new_h*ratio;
2869
+
2870
+ if (new_w > min_w)
2871
+ {
2872
+ $(resize).width(new_w);
2873
+ }
2874
+
2875
+ if (new_h > min_h)
2876
+ {
2877
+ $(resize).height(new_h);
2878
+ }
2879
+
2880
+ start_x = Math.round(e.pageX - $(this).eq(0).offset().left);
2881
+ start_y = Math.round(e.pageY - $(this).eq(0).offset().top);
2882
+ }
2883
+ });
2884
+ },
2885
+
2886
+ // TABLE
2887
+ showTable: function()
2888
+ {
2889
+ this.saveSelection();
2890
+
2891
+ this.modalInit(RLANG.table, this.opts.modal_table, 300, $.proxy(function()
2892
+ {
2893
+ $('#redactor_insert_table_btn').click($.proxy(this.insertTable, this));
2894
+
2895
+ setTimeout(function()
2896
+ {
2897
+ $('#redactor_table_rows').focus();
2898
+ }, 200);
2899
+
2900
+ }, this)
2901
+ );
2902
+ },
2903
+ insertTable: function()
2904
+ {
2905
+ var rows = $('#redactor_table_rows').val();
2906
+ var columns = $('#redactor_table_columns').val();
2907
+
2908
+ var table_box = $('<div></div>');
2909
+
2910
+ var tableid = Math.floor(Math.random() * 99999);
2911
+ var table = $('<table id="table' + tableid + '"><tbody></tbody></table>');
2912
+
2913
+ for (var i = 0; i < rows; i++)
2914
+ {
2915
+ var row = $('<tr></tr>');
2916
+ for (var z = 0; z < columns; z++)
2917
+ {
2918
+ var column = $('<td><br></td>');
2919
+ $(row).append(column);
2920
+ }
2921
+ $(table).append(row);
2922
+ }
2923
+
2924
+ $(table_box).append(table);
2925
+ var html = $(table_box).html() + '<p></p>';
2926
+
2927
+ this.restoreSelection();
2928
+ this.execCommand('inserthtml', html);
2929
+ this.modalClose();
2930
+ this.observeTables();
2931
+
2932
+ },
2933
+ tableObserver: function(e)
2934
+ {
2935
+ this.$table = $(e.target).closest('table');
2936
+
2937
+ this.$table_tr = this.$table.find('tr');
2938
+ this.$table_td = this.$table.find('td');
2939
+
2940
+ this.$tbody = $(e.target).closest('tbody');
2941
+ this.$thead = $(this.$table).find('thead');
2942
+
2943
+ this.$current_td = $(e.target);
2944
+ this.$current_tr = $(e.target).closest('tr');
2945
+ },
2946
+ deleteTable: function()
2947
+ {
2948
+ $(this.$table).remove();
2949
+ this.$table = false;
2950
+ this.syncCode();
2951
+ },
2952
+ deleteRow: function()
2953
+ {
2954
+ $(this.$current_tr).remove();
2955
+ this.syncCode();
2956
+ },
2957
+ deleteColumn: function()
2958
+ {
2959
+ var index = $(this.$current_td).get(0).cellIndex;
2960
+
2961
+ $(this.$table).find('tr').each(function()
2962
+ {
2963
+ $(this).find('td').eq(index).remove();
2964
+ });
2965
+
2966
+ this.syncCode();
2967
+ },
2968
+ addHead: function()
2969
+ {
2970
+ if ($(this.$table).find('thead').size() !== 0)
2971
+ {
2972
+ this.deleteHead();
2973
+ }
2974
+ else
2975
+ {
2976
+ var tr = $(this.$table).find('tr').first().clone();
2977
+ tr.find('td').html('&nbsp;');
2978
+ this.$thead = $('<thead></thead>');
2979
+ this.$thead.append(tr);
2980
+ $(this.$table).prepend(this.$thead);
2981
+ this.syncCode();
2982
+ }
2983
+ },
2984
+ deleteHead: function()
2985
+ {
2986
+ $(this.$thead).remove();
2987
+ this.$thead = false;
2988
+ this.syncCode();
2989
+ },
2990
+ insertRowAbove: function()
2991
+ {
2992
+ this.insertRow('before');
2993
+ },
2994
+ insertRowBelow: function()
2995
+ {
2996
+ this.insertRow('after');
2997
+ },
2998
+ insertColumnLeft: function()
2999
+ {
3000
+ this.insertColumn('before');
3001
+ },
3002
+ insertColumnRight: function()
3003
+ {
3004
+ this.insertColumn('after');
3005
+ },
3006
+ insertRow: function(type)
3007
+ {
3008
+ var new_tr = $(this.$current_tr).clone();
3009
+ new_tr.find('td').html('&nbsp;');
3010
+ if (type === 'after')
3011
+ {
3012
+ $(this.$current_tr).after(new_tr);
3013
+ }
3014
+ else
3015
+ {
3016
+ $(this.$current_tr).before(new_tr);
3017
+ }
3018
+
3019
+ this.syncCode();
3020
+ },
3021
+ insertColumn: function(type)
3022
+ {
3023
+ var index = 0;
3024
+
3025
+ this.$current_tr.find('td').each($.proxy(function(i,s)
3026
+ {
3027
+ if ($(s)[0] === this.$current_td[0])
3028
+ {
3029
+ index = i;
3030
+ }
3031
+ }, this));
3032
+
3033
+ this.$table_tr.each(function(i,s)
3034
+ {
3035
+ var current = $(s).find('td').eq(index);
3036
+
3037
+ var td = current.clone();
3038
+ td.html('&nbsp;');
3039
+
3040
+ if (type === 'after')
3041
+ {
3042
+ $(current).after(td);
3043
+ }
3044
+ else
3045
+ {
3046
+ $(current).before(td);
3047
+ }
3048
+
3049
+ });
3050
+
3051
+ this.syncCode();
3052
+ },
3053
+
3054
+ // INSERT VIDEO
3055
+ showVideo: function()
3056
+ {
3057
+ this.saveSelection();
3058
+ this.modalInit(RLANG.video, this.opts.modal_video, 600, $.proxy(function()
3059
+ {
3060
+ $('#redactor_insert_video_btn').click($.proxy(this.insertVideo, this));
3061
+
3062
+ setTimeout(function()
3063
+ {
3064
+ $('#redactor_insert_video_area').focus();
3065
+ }, 200);
3066
+
3067
+ }, this)
3068
+ );
3069
+ },
3070
+ insertVideo: function()
3071
+ {
3072
+ var data = $('#redactor_insert_video_area').val();
3073
+ data = this.stripTags(data);
3074
+
3075
+ this.restoreSelection();
3076
+ this.execCommand('inserthtml', data);
3077
+ this.modalClose();
3078
+ },
3079
+
3080
+ // INSERT IMAGE
3081
+ imageEdit: function(e)
3082
+ {
3083
+ var $el = $(e.target);
3084
+ var parent = $el.parent();
3085
+
3086
+ var callback = $.proxy(function()
3087
+ {
3088
+ $('#redactor_file_alt').val($el.attr('alt'));
3089
+ $('#redactor_image_edit_src').attr('href', $el.attr('src'));
3090
+ $('#redactor_form_image_align').val($el.css('float'));
3091
+
3092
+ if ($(parent).get(0).tagName === 'A')
3093
+ {
3094
+ $('#redactor_file_link').val($(parent).attr('href'));
3095
+ }
3096
+
3097
+ $('#redactor_image_delete_btn').click($.proxy(function() { this.imageDelete($el); }, this));
3098
+ $('#redactorSaveBtn').click($.proxy(function() { this.imageSave($el); }, this));
3099
+
3100
+ }, this);
3101
+
3102
+ this.modalInit(RLANG.image, this.opts.modal_image_edit, 380, callback);
3103
+
3104
+ },
3105
+ imageDelete: function(el)
3106
+ {
3107
+ $(el).remove();
3108
+ this.modalClose();
3109
+ this.syncCode();
3110
+ },
3111
+ imageSave: function(el)
3112
+ {
3113
+ var parent = $(el).parent();
3114
+
3115
+ $(el).attr('alt', $('#redactor_file_alt').val());
3116
+
3117
+ var floating = $('#redactor_form_image_align').val();
3118
+
3119
+ if (floating === 'left')
3120
+ {
3121
+ $(el).css({ 'float': 'left', margin: '0 10px 10px 0' });
3122
+ }
3123
+ else if (floating === 'right')
3124
+ {
3125
+ $(el).css({ 'float': 'right', margin: '0 0 10px 10px' });
3126
+ }
3127
+ else
3128
+ {
3129
+ $(el).css({ 'float': 'none', margin: '0' });
3130
+ }
3131
+
3132
+ // as link
3133
+ var link = $.trim($('#redactor_file_link').val());
3134
+ if (link !== '')
3135
+ {
3136
+ if ($(parent).get(0).tagName !== 'A')
3137
+ {
3138
+ $(el).replaceWith('<a href="' + link + '">' + this.outerHTML(el) + '</a>');
3139
+ }
3140
+ else
3141
+ {
3142
+ $(parent).attr('href', link);
3143
+ }
3144
+ }
3145
+ else
3146
+ {
3147
+ if ($(parent).get(0).tagName === 'A')
3148
+ {
3149
+ $(parent).replaceWith(this.outerHTML(el));
3150
+ }
3151
+ }
3152
+
3153
+ this.modalClose();
3154
+ this.observeImages();
3155
+ this.syncCode();
3156
+
3157
+ },
3158
+ showImage: function()
3159
+ {
3160
+ this.saveSelection();
3161
+
3162
+ var callback = $.proxy(function()
3163
+ {
3164
+ // json
3165
+ if (this.opts.imageGetJson !== false)
3166
+ {
3167
+ $.getJSON(this.opts.imageGetJson, $.proxy(function(data) {
3168
+
3169
+ var folders = {};
3170
+ var z = 0;
3171
+
3172
+ // folders
3173
+ $.each(data, $.proxy(function(key, val)
3174
+ {
3175
+ if (typeof val.folder !== 'undefined')
3176
+ {
3177
+ z++;
3178
+ folders[val.folder] = z;
3179
+ }
3180
+
3181
+ }, this));
3182
+
3183
+ var folderclass = false;
3184
+ $.each(data, $.proxy(function(key, val)
3185
+ {
3186
+ // title
3187
+ var thumbtitle = '';
3188
+ if (typeof val.title !== 'undefined')
3189
+ {
3190
+ thumbtitle = val.title;
3191
+ }
3192
+
3193
+ var folderkey = 0;
3194
+ if (!$.isEmptyObject(folders) && typeof val.folder !== 'undefined')
3195
+ {
3196
+ folderkey = folders[val.folder];
3197
+ if (folderclass === false)
3198
+ {
3199
+ folderclass = '.redactorfolder' + folderkey;
3200
+ }
3201
+ }
3202
+
3203
+ var img = $('<img src="' + val.thumb + '" class="redactorfolder redactorfolder' + folderkey + '" rel="' + val.image + '" title="' + thumbtitle + '" />');
3204
+ $('#redactor_image_box').append(img);
3205
+ $(img).click($.proxy(this.imageSetThumb, this));
3206
+
3207
+
3208
+ }, this));
3209
+
3210
+ // folders
3211
+ if (!$.isEmptyObject(folders))
3212
+ {
3213
+ $('.redactorfolder').hide();
3214
+ $(folderclass).show();
3215
+
3216
+ var onchangeFunc = function(e)
3217
+ {
3218
+ $('.redactorfolder').hide();
3219
+ $('.redactorfolder' + $(e.target).val()).show();
3220
+ }
3221
+
3222
+ var select = $('<select id="redactor_image_box_select">');
3223
+ $.each(folders, function(k,v)
3224
+ {
3225
+ select.append($('<option value="' + v + '">' + k + '</option>'));
3226
+ });
3227
+
3228
+ $('#redactor_image_box').before(select);
3229
+ select.change(onchangeFunc);
3230
+ }
3231
+
3232
+ }, this));
3233
+ }
3234
+ else
3235
+ {
3236
+ $('#redactor_tabs a').eq(1).remove();
3237
+ }
3238
+
3239
+ if (this.opts.imageUpload !== false)
3240
+ {
3241
+
3242
+ // dragupload
3243
+ if (this.opts.uploadCrossDomain === false && this.isMobile() === false)
3244
+ {
3245
+
3246
+ if ($('#redactor_file').size() !== 0)
3247
+ {
3248
+ $('#redactor_file').dragupload(
3249
+ {
3250
+ url: this.opts.imageUpload,
3251
+ uploadFields: this.opts.uploadFields,
3252
+ success: $.proxy(this.imageUploadCallback, this),
3253
+ error: $.proxy(this.opts.imageUploadErrorCallback, this)
3254
+ });
3255
+ }
3256
+ }
3257
+
3258
+ // ajax upload
3259
+ this.uploadInit('redactor_file',
3260
+ {
3261
+ auto: true,
3262
+ url: this.opts.imageUpload,
3263
+ success: $.proxy(this.imageUploadCallback, this),
3264
+ error: $.proxy(this.opts.imageUploadErrorCallback, this)
3265
+ });
3266
+ }
3267
+ else
3268
+ {
3269
+ $('.redactor_tab').hide();
3270
+ if (this.opts.imageGetJson === false)
3271
+ {
3272
+ $('#redactor_tabs').remove();
3273
+ $('#redactor_tab3').show();
3274
+ }
3275
+ else
3276
+ {
3277
+ var tabs = $('#redactor_tabs a');
3278
+ tabs.eq(0).remove();
3279
+ tabs.eq(1).addClass('redactor_tabs_act');
3280
+ $('#redactor_tab2').show();
3281
+ }
3282
+ }
3283
+
3284
+ $('#redactor_upload_btn').click($.proxy(this.imageUploadCallbackLink, this));
3285
+
3286
+ if (this.opts.imageUpload === false && this.opts.imageGetJson === false)
3287
+ {
3288
+ setTimeout(function()
3289
+ {
3290
+ $('#redactor_file_link').focus();
3291
+ }, 200);
3292
+
3293
+ }
3294
+
3295
+ }, this);
3296
+
3297
+ this.modalInit(RLANG.image, this.opts.modal_image, 610, callback);
3298
+
3299
+ },
3300
+ imageSetThumb: function(e)
3301
+ {
3302
+ this._imageSet('<img src="' + $(e.target).attr('rel') + '" alt="' + $(e.target).attr('title') + '" />', true);
3303
+ },
3304
+ imageUploadCallbackLink: function()
3305
+ {
3306
+ if ($('#redactor_file_link').val() !== '')
3307
+ {
3308
+ var data = '<img src="' + $('#redactor_file_link').val() + '" />';
3309
+ this._imageSet(data, true);
3310
+ }
3311
+ else
3312
+ {
3313
+ this.modalClose();
3314
+ }
3315
+ },
3316
+ imageUploadCallback: function(data)
3317
+ {
3318
+ this._imageSet(data);
3319
+ },
3320
+ _imageSet: function(json, link)
3321
+ {
3322
+ this.restoreSelection();
3323
+
3324
+ if (json !== false)
3325
+ {
3326
+ var html = '';
3327
+ if (link !== true)
3328
+ {
3329
+ html = '<p><img src="' + json.filelink + '" /></p>';
3330
+ }
3331
+ else
3332
+ {
3333
+ html = json;
3334
+ }
3335
+
3336
+ this.execCommand('inserthtml', html);
3337
+
3338
+ // upload image callback
3339
+ if (link !== true && typeof this.opts.imageUploadCallback === 'function')
3340
+ {
3341
+ this.opts.imageUploadCallback(this, json);
3342
+ }
3343
+ }
3344
+
3345
+ this.modalClose();
3346
+ this.observeImages();
3347
+ },
3348
+
3349
+ // INSERT LINK
3350
+ showLink: function()
3351
+ {
3352
+ this.saveSelection();
3353
+
3354
+ var callback = $.proxy(function()
3355
+ {
3356
+ this.insert_link_node = false;
3357
+ var sel = this.getSelection();
3358
+ var url = '', text = '', target = '';
3359
+
3360
+ if (this.browser('msie'))
3361
+ {
3362
+ var parent = this.getParentNode();
3363
+ if (parent.nodeName === 'A')
3364
+ {
3365
+ this.insert_link_node = $(parent);
3366
+ text = this.insert_link_node.text();
3367
+ url = this.insert_link_node.attr('href');
3368
+ target = this.insert_link_node.attr('target');
3369
+ }
3370
+ else
3371
+ {
3372
+ if (this.oldIE())
3373
+ {
3374
+ text = sel.text;
3375
+ }
3376
+ else
3377
+ {
3378
+ text = sel.toString();
3379
+ }
3380
+ }
3381
+ }
3382
+ else
3383
+ {
3384
+ if (sel && sel.anchorNode && sel.anchorNode.parentNode.tagName === 'A')
3385
+ {
3386
+ url = sel.anchorNode.parentNode.href;
3387
+ text = sel.anchorNode.parentNode.text;
3388
+ target = sel.anchorNode.parentNode.target;
3389
+
3390
+ if (sel.toString() === '')
3391
+ {
3392
+ this.insert_link_node = sel.anchorNode.parentNode;
3393
+ }
3394
+ }
3395
+ else
3396
+ {
3397
+ text = sel.toString();
3398
+ }
3399
+ }
3400
+
3401
+ $('.redactor_link_text').val(text);
3402
+
3403
+ var thref = self.location.href.replace(/\/$/i, '');
3404
+ var turl = url.replace(thref, '');
3405
+
3406
+ if (url.search('mailto:') === 0)
3407
+ {
3408
+ this.setModalTab(2);
3409
+
3410
+ $('#redactor_tab_selected').val(2);
3411
+ $('#redactor_link_mailto').val(url.replace('mailto:', ''));
3412
+ }
3413
+ else if (turl.search(/^#/gi) === 0)
3414
+ {
3415
+ this.setModalTab(3);
3416
+
3417
+ $('#redactor_tab_selected').val(3);
3418
+ $('#redactor_link_anchor').val(turl.replace(/^#/gi, ''));
3419
+ }
3420
+ else
3421
+ {
3422
+ $('#redactor_link_url').val(turl);
3423
+ }
3424
+
3425
+ if (target === '_blank')
3426
+ {
3427
+ $('#redactor_link_blank').attr('checked', true);
3428
+ }
3429
+
3430
+ $('#redactor_insert_link_btn').click($.proxy(this.insertLink, this));
3431
+
3432
+ setTimeout(function()
3433
+ {
3434
+ $('#redactor_link_url').focus();
3435
+ }, 200);
3436
+
3437
+ }, this);
3438
+
3439
+ this.modalInit(RLANG.link, this.opts.modal_link, 460, callback);
3440
+
3441
+ },
3442
+ insertLink: function()
3443
+ {
3444
+ var tab_selected = $('#redactor_tab_selected').val();
3445
+ var link = '', text = '', target = '';
3446
+
3447
+ if (tab_selected === '1') // url
3448
+ {
3449
+ link = $('#redactor_link_url').val();
3450
+ text = $('#redactor_link_url_text').val();
3451
+
3452
+ if ($('#redactor_link_blank').attr('checked'))
3453
+ {
3454
+ target = ' target="_blank"';
3455
+ }
3456
+
3457
+ // test url
3458
+ var pattern = '/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/';
3459
+ //var pattern = '((xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}';
3460
+ var re = new RegExp('^(http|ftp|https)://' + pattern,'i');
3461
+ var re2 = new RegExp('^' + pattern,'i');
3462
+ if (link.search(re) == -1 && link.search(re2) == 0 && this.opts.protocol !== false)
3463
+ {
3464
+ link = this.opts.protocol + link;
3465
+ }
3466
+
3467
+ }
3468
+ else if (tab_selected === '2') // mailto
3469
+ {
3470
+ link = 'mailto:' + $('#redactor_link_mailto').val();
3471
+ text = $('#redactor_link_mailto_text').val();
3472
+ }
3473
+ else if (tab_selected === '3') // anchor
3474
+ {
3475
+ link = '#' + $('#redactor_link_anchor').val();
3476
+ text = $('#redactor_link_anchor_text').val();
3477
+ }
3478
+
3479
+ this._insertLink('<a href="' + link + '"' + target + '>' + text + '</a>', $.trim(text), link, target);
3480
+
3481
+ },
3482
+ _insertLink: function(a, text, link, target)
3483
+ {
3484
+ this.$editor.focus();
3485
+ this.restoreSelection();
3486
+
3487
+ if (text !== '')
3488
+ {
3489
+ if (this.insert_link_node)
3490
+ {
3491
+ $(this.insert_link_node).text(text);
3492
+ $(this.insert_link_node).attr('href', link);
3493
+ if (target !== '')
3494
+ {
3495
+ $(this.insert_link_node).attr('target', target);
3496
+ }
3497
+ else
3498
+ {
3499
+ $(this.insert_link_node).removeAttr('target');
3500
+ }
3501
+
3502
+ this.syncCode();
3503
+ }
3504
+ else
3505
+ {
3506
+ this.execCommand('inserthtml', a);
3507
+ }
3508
+ }
3509
+
3510
+ this.modalClose();
3511
+ },
3512
+
3513
+ // INSERT FILE
3514
+ showFile: function()
3515
+ {
3516
+ this.saveSelection();
3517
+
3518
+ var callback = $.proxy(function()
3519
+ {
3520
+ var sel = this.getSelection();
3521
+
3522
+ var text = '';
3523
+
3524
+ if (this.oldIE())
3525
+ {
3526
+ text = sel.text;
3527
+ }
3528
+ else
3529
+ {
3530
+ text = sel.toString();
3531
+ }
3532
+
3533
+ $('#redactor_filename').val(text);
3534
+
3535
+ // dragupload
3536
+ if (this.opts.uploadCrossDomain === false && this.isMobile() === false)
3537
+ {
3538
+ $('#redactor_file').dragupload(
3539
+ {
3540
+ url: this.opts.fileUpload,
3541
+ uploadFields: this.opts.uploadFields,
3542
+ success: $.proxy(this.fileUploadCallback, this),
3543
+ error: $.proxy(this.opts.fileUploadErrorCallback, this)
3544
+ });
3545
+ }
3546
+
3547
+ this.uploadInit('redactor_file',
3548
+ {
3549
+ auto: true,
3550
+ url: this.opts.fileUpload,
3551
+ success: $.proxy(this.fileUploadCallback, this),
3552
+ error: $.proxy(this.opts.fileUploadErrorCallback, this)
3553
+ });
3554
+
3555
+ }, this);
3556
+
3557
+ this.modalInit(RLANG.file, this.opts.modal_file, 500, callback);
3558
+ },
3559
+ fileUploadCallback: function(json)
3560
+ {
3561
+ this.restoreSelection();
3562
+
3563
+ if (json !== false)
3564
+ {
3565
+ var text = $('#redactor_filename').val();
3566
+
3567
+ if (text === '')
3568
+ {
3569
+ text = json.filename;
3570
+ }
3571
+
3572
+ var link = '<a href="' + json.filelink + '">' + text + '</a>';
3573
+
3574
+ // chrome fix
3575
+ if (this.browser('webkit') && !!this.window.chrome)
3576
+ {
3577
+ link = link + '&nbsp;';
3578
+ }
3579
+
3580
+ this.execCommand('inserthtml', link);
3581
+
3582
+ // file upload callback
3583
+ if (typeof this.opts.fileUploadCallback === 'function')
3584
+ {
3585
+ this.opts.fileUploadCallback(this, json);
3586
+ }
3587
+ }
3588
+
3589
+ this.modalClose();
3590
+ },
3591
+
3592
+
3593
+
3594
+ // MODAL
3595
+ modalInit: function(title, content, width, callback)
3596
+ {
3597
+ // modal overlay
3598
+ if ($('#redactor_modal_overlay').size() === 0)
3599
+ {
3600
+ this.overlay = $('<div id="redactor_modal_overlay" style="display: none;"></div>');
3601
+ $('body').prepend(this.overlay);
3602
+ }
3603
+
3604
+ if (this.opts.overlay)
3605
+ {
3606
+ $('#redactor_modal_overlay').show();
3607
+ $('#redactor_modal_overlay').click($.proxy(this.modalClose, this));
3608
+ }
3609
+
3610
+ if ($('#redactor_modal').size() === 0)
3611
+ {
3612
+ this.modal = $('<div id="redactor_modal" style="display: none;"><div id="redactor_modal_close">&times;</div><div id="redactor_modal_header"></div><div id="redactor_modal_inner"></div></div>');
3613
+ $('body').append(this.modal);
3614
+ }
3615
+
3616
+ $('#redactor_modal_close').click($.proxy(this.modalClose, this));
3617
+
3618
+ this.hdlModalClose = $.proxy(function(e) { if ( e.keyCode === 27) { this.modalClose(); return false; } }, this);
3619
+
3620
+ $(document).keyup(this.hdlModalClose);
3621
+ this.$editor.keyup(this.hdlModalClose);
3622
+
3623
+ // set content
3624
+ if (content.indexOf('#') == 0)
3625
+ {
3626
+ $('#redactor_modal_inner').empty().append($(content).html());
3627
+ }
3628
+ else
3629
+ {
3630
+ $('#redactor_modal_inner').empty().append(content);
3631
+ }
3632
+
3633
+
3634
+ $('#redactor_modal_header').html(title);
3635
+
3636
+ // draggable
3637
+ if (typeof $.fn.draggable !== 'undefined')
3638
+ {
3639
+ $('#redactor_modal').draggable({ handle: '#redactor_modal_header' });
3640
+ $('#redactor_modal_header').css('cursor', 'move');
3641
+ }
3642
+
3643
+ // tabs
3644
+ if ($('#redactor_tabs').size() !== 0)
3645
+ {
3646
+ var that = this;
3647
+ $('#redactor_tabs a').each(function(i,s)
3648
+ {
3649
+ i++;
3650
+ $(s).click(function()
3651
+ {
3652
+ $('#redactor_tabs a').removeClass('redactor_tabs_act');
3653
+ $(this).addClass('redactor_tabs_act');
3654
+ $('.redactor_tab').hide();
3655
+ $('#redactor_tab' + i).show();
3656
+ $('#redactor_tab_selected').val(i);
3657
+
3658
+ if (that.isMobile() === false)
3659
+ {
3660
+ var height = $('#redactor_modal').outerHeight();
3661
+ $('#redactor_modal').css('margin-top', '-' + (height+10)/2 + 'px');
3662
+ }
3663
+ });
3664
+ });
3665
+ }
3666
+
3667
+ $('#redactor_modal .redactor_btn_modal_close').click($.proxy(this.modalClose, this));
3668
+
3669
+ if (this.isMobile() === false)
3670
+ {
3671
+ $('#redactor_modal').css({ position: 'fixed', top: '-2000px', left: '50%', width: width + 'px', marginLeft: '-' + (width+60)/2 + 'px' }).show();
3672
+
3673
+ this.modalSaveBodyOveflow = $(document.body).css('overflow');
3674
+ $(document.body).css('overflow', 'hidden');
3675
+ }
3676
+ else
3677
+ {
3678
+ $('#redactor_modal').css({ position: 'fixed', width: '100%', height: '100%', top: '0', left: '0', margin: '0', minHeight: '300px' }).show();
3679
+ }
3680
+
3681
+ // callback
3682
+ if (typeof callback === 'function')
3683
+ {
3684
+ callback();
3685
+ }
3686
+
3687
+ if (this.isMobile() === false)
3688
+ {
3689
+ setTimeout(function()
3690
+ {
3691
+ var height = $('#redactor_modal').outerHeight();
3692
+ $('#redactor_modal').css({ top: '50%', height: 'auto', minHeight: 'auto', marginTop: '-' + (height+10)/2 + 'px' });
3693
+
3694
+ }, 20);
3695
+ }
3696
+
3697
+ },
3698
+ modalClose: function()
3699
+ {
3700
+ $('#redactor_modal_close').unbind('click', this.modalClose);
3701
+ $('#redactor_modal').fadeOut('fast', $.proxy(function()
3702
+ {
3703
+ $('#redactor_modal_inner').html('');
3704
+
3705
+ if (this.opts.overlay)
3706
+ {
3707
+ $('#redactor_modal_overlay').hide();
3708
+ $('#redactor_modal_overlay').unbind('click', this.modalClose);
3709
+ }
3710
+
3711
+ $(document).unbind('keyup', this.hdlModalClose);
3712
+ this.$editor.unbind('keyup', this.hdlModalClose);
3713
+
3714
+ }, this));
3715
+
3716
+
3717
+ if (this.isMobile() === false)
3718
+ {
3719
+ $(document.body).css('overflow', this.modalSaveBodyOveflow ? this.modalSaveBodyOveflow : 'visible');
3720
+ }
3721
+
3722
+ return false;
3723
+
3724
+ },
3725
+ setModalTab: function(num)
3726
+ {
3727
+ $('.redactor_tab').hide();
3728
+ var tabs = $('#redactor_tabs a');
3729
+ tabs.removeClass('redactor_tabs_act');
3730
+ tabs.eq(num-1).addClass('redactor_tabs_act');
3731
+ $('#redactor_tab' + num).show();
3732
+ },
3733
+
3734
+ // UPLOAD
3735
+ uploadInit: function(element, options)
3736
+ {
3737
+ // Upload Options
3738
+ this.uploadOptions = {
3739
+ url: false,
3740
+ success: false,
3741
+ error: false,
3742
+ start: false,
3743
+ trigger: false,
3744
+ auto: false,
3745
+ input: false
3746
+ };
3747
+
3748
+ $.extend(this.uploadOptions, options);
3749
+
3750
+ // Test input or form
3751
+ if ($('#' + element).size() !== 0 && $('#' + element).get(0).tagName === 'INPUT')
3752
+ {
3753
+ this.uploadOptions.input = $('#' + element);
3754
+ this.element = $($('#' + element).get(0).form);
3755
+ }
3756
+ else
3757
+ {
3758
+ this.element = $('#' + element);
3759
+ }
3760
+
3761
+ this.element_action = this.element.attr('action');
3762
+
3763
+ // Auto or trigger
3764
+ if (this.uploadOptions.auto)
3765
+ {
3766
+ $(this.uploadOptions.input).change($.proxy(function()
3767
+ {
3768
+ this.element.submit(function(e) { return false; });
3769
+ this.uploadSubmit();
3770
+ }, this));
3771
+
3772
+ }
3773
+ else if (this.uploadOptions.trigger)
3774
+ {
3775
+ $('#' + this.uploadOptions.trigger).click($.proxy(this.uploadSubmit, this));
3776
+ }
3777
+ },
3778
+ uploadSubmit : function()
3779
+ {
3780
+ this.uploadForm(this.element, this.uploadFrame());
3781
+ },
3782
+ uploadFrame : function()
3783
+ {
3784
+ this.id = 'f' + Math.floor(Math.random() * 99999);
3785
+
3786
+ var d = this.document.createElement('div');
3787
+ var iframe = '<iframe style="display:none" id="'+this.id+'" name="'+this.id+'"></iframe>';
3788
+ d.innerHTML = iframe;
3789
+ $(d).appendTo("body");
3790
+
3791
+ // Start
3792
+ if (this.uploadOptions.start)
3793
+ {
3794
+ this.uploadOptions.start();
3795
+ }
3796
+
3797
+ $('#' + this.id).load($.proxy(this.uploadLoaded, this));
3798
+
3799
+ return this.id;
3800
+ },
3801
+ uploadForm : function(f, name)
3802
+ {
3803
+ if (this.uploadOptions.input)
3804
+ {
3805
+ var formId = 'redactorUploadForm' + this.id;
3806
+ var fileId = 'redactorUploadFile' + this.id;
3807
+ this.form = $('<form action="' + this.uploadOptions.url + '" method="POST" target="' + name + '" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
3808
+
3809
+ // append hidden fields
3810
+ if (this.opts.uploadFields !== false && typeof this.opts.uploadFields === 'object')
3811
+ {
3812
+ $.each(this.opts.uploadFields, $.proxy(function(k,v)
3813
+ {
3814
+ if (v.toString().indexOf('#') === 0)
3815
+ {
3816
+ v = $(v).val();
3817
+ }
3818
+
3819
+ var hidden = $('<input/>', {'type': "hidden", 'name': k, 'value': v});
3820
+ $(this.form).append(hidden);
3821
+
3822
+ }, this));
3823
+ }
3824
+
3825
+ var oldElement = this.uploadOptions.input;
3826
+ var newElement = $(oldElement).clone();
3827
+ $(oldElement).attr('id', fileId);
3828
+ $(oldElement).before(newElement);
3829
+ $(oldElement).appendTo(this.form);
3830
+ $(this.form).css('position', 'absolute');
3831
+ $(this.form).css('top', '-2000px');
3832
+ $(this.form).css('left', '-2000px');
3833
+ $(this.form).appendTo('body');
3834
+
3835
+ this.form.submit();
3836
+ }
3837
+ else
3838
+ {
3839
+ f.attr('target', name);
3840
+ f.attr('method', 'POST');
3841
+ f.attr('enctype', 'multipart/form-data');
3842
+ f.attr('action', this.uploadOptions.url);
3843
+
3844
+ this.element.submit();
3845
+ }
3846
+
3847
+ },
3848
+ uploadLoaded : function()
3849
+ {
3850
+ var i = $('#' + this.id)[0];
3851
+ var d;
3852
+
3853
+ if (i.contentDocument)
3854
+ {
3855
+ d = i.contentDocument;
3856
+ }
3857
+ else if (i.contentWindow)
3858
+ {
3859
+ d = i.contentWindow.document;
3860
+ }
3861
+ else
3862
+ {
3863
+ d = window.frames[this.id].document;
3864
+ }
3865
+
3866
+ // Success
3867
+ if (this.uploadOptions.success)
3868
+ {
3869
+ if (typeof d !== 'undefined')
3870
+ {
3871
+ // Remove bizarre <pre> tag wrappers around our json data:
3872
+ var rawString = d.body.innerHTML;
3873
+ var jsonString = rawString.match(/\{(.|\n)*\}/)[0];
3874
+ var json = $.parseJSON(jsonString);
3875
+
3876
+ if (typeof json.error == 'undefined')
3877
+ {
3878
+ this.uploadOptions.success(json);
3879
+ }
3880
+ else
3881
+ {
3882
+ this.uploadOptions.error(this, json);
3883
+ this.modalClose();
3884
+ }
3885
+ }
3886
+ else
3887
+ {
3888
+ alert('Upload failed!');
3889
+ this.modalClose();
3890
+ }
3891
+ }
3892
+
3893
+ this.element.attr('action', this.element_action);
3894
+ this.element.attr('target', '');
3895
+
3896
+ },
3897
+
3898
+ // UTILITY
3899
+ browser: function(browser)
3900
+ {
3901
+ var ua = navigator.userAgent.toLowerCase();
3902
+ var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];
3903
+
3904
+ if (browser == 'version')
3905
+ {
3906
+ return match[2];
3907
+ }
3908
+
3909
+ if (browser == 'webkit')
3910
+ {
3911
+ return (match[1] == 'chrome' || match[1] == 'webkit');
3912
+ }
3913
+
3914
+ return match[1] == browser;
3915
+ },
3916
+ oldIE: function()
3917
+ {
3918
+ if (this.browser('msie') && parseInt(this.browser('version'), 10) < 9)
3919
+ {
3920
+ return true;
3921
+ }
3922
+
3923
+ return false;
3924
+ },
3925
+ outerHTML: function(s)
3926
+ {
3927
+ return $("<p>").append($(s).eq(0).clone()).html();
3928
+ },
3929
+ normalize: function(str)
3930
+ {
3931
+ return parseInt(str.replace('px',''), 10);
3932
+ },
3933
+ isMobile: function(ipad)
3934
+ {
3935
+ if (ipad === true && /(iPhone|iPod|iPad|BlackBerry|Android)/.test(navigator.userAgent))
3936
+ {
3937
+ return true;
3938
+ }
3939
+ else if (/(iPhone|iPod|BlackBerry|Android)/.test(navigator.userAgent))
3940
+ {
3941
+ return true;
3942
+ }
3943
+ else
3944
+ {
3945
+ return false;
3946
+ }
3947
+ }
3948
+
3949
+ };
3950
+
3951
+
3952
+ // API
3953
+ $.fn.getObject = function()
3954
+ {
3955
+ return this.data('redactor');
3956
+ };
3957
+
3958
+ $.fn.getEditor = function()
3959
+ {
3960
+ return this.data('redactor').$editor;
3961
+ };
3962
+
3963
+ $.fn.getCode = function()
3964
+ {
3965
+ return $.trim(this.data('redactor').getCode());
3966
+ };
3967
+
3968
+ $.fn.getText = function()
3969
+ {
3970
+ return this.data('redactor').$editor.text();
3971
+ };
3972
+
3973
+ $.fn.getSelected = function()
3974
+ {
3975
+ return this.data('redactor').getSelectedHtml();
3976
+ };
3977
+
3978
+ $.fn.setCode = function(html)
3979
+ {
3980
+ this.data('redactor').setCode(html);
3981
+ };
3982
+
3983
+ $.fn.insertHtml = function(html)
3984
+ {
3985
+ this.data('redactor').insertHtml(html);
3986
+ };
3987
+
3988
+ $.fn.destroyEditor = function()
3989
+ {
3990
+ this.each(function()
3991
+ {
3992
+ if (typeof $(this).data('redactor') != 'undefined')
3993
+ {
3994
+ $(this).data('redactor').destroy();
3995
+ $(this).removeData('redactor');
3996
+ }
3997
+ });
3998
+ };
3999
+
4000
+ $.fn.setFocus = function()
4001
+ {
4002
+ this.data('redactor').$editor.focus();
4003
+ };
4004
+
4005
+ $.fn.execCommand = function(cmd, param)
4006
+ {
4007
+ this.data('redactor').execCommand(cmd, param);
4008
+ };
4009
+
4010
+ })(jQuery);
4011
+
4012
+ /*
4013
+ Plugin Drag and drop Upload v1.0.2
4014
+ http://imperavi.com/
4015
+ Copyright 2012, Imperavi Inc.
4016
+ */
4017
+ (function($){
4018
+
4019
+ "use strict";
4020
+
4021
+ // Initialization
4022
+ $.fn.dragupload = function(options)
4023
+ {
4024
+ return this.each(function() {
4025
+ var obj = new Construct(this, options);
4026
+ obj.init();
4027
+ });
4028
+ };
4029
+
4030
+ // Options and variables
4031
+ function Construct(el, options) {
4032
+
4033
+ this.opts = $.extend({
4034
+
4035
+ url: false,
4036
+ success: false,
4037
+ error: false,
4038
+ preview: false,
4039
+ uploadFields: false,
4040
+
4041
+ text: RLANG.drop_file_here,
4042
+ atext: RLANG.or_choose
4043
+
4044
+ }, options);
4045
+
4046
+ this.$el = $(el);
4047
+ }
4048
+
4049
+ // Functionality
4050
+ Construct.prototype = {
4051
+ init: function()
4052
+ {
4053
+ if (navigator.userAgent.search("MSIE") === -1)
4054
+ {
4055
+ this.droparea = $('<div class="redactor_droparea"></div>');
4056
+ this.dropareabox = $('<div class="redactor_dropareabox">' + this.opts.text + '</div>');
4057
+ this.dropalternative = $('<div class="redactor_dropalternative">' + this.opts.atext + '</div>');
4058
+
4059
+ this.droparea.append(this.dropareabox);
4060
+
4061
+ this.$el.before(this.droparea);
4062
+ this.$el.before(this.dropalternative);
4063
+
4064
+ // drag over
4065
+ this.dropareabox.bind('dragover', $.proxy(function() { return this.ondrag(); }, this));
4066
+
4067
+ // drag leave
4068
+ this.dropareabox.bind('dragleave', $.proxy(function() { return this.ondragleave(); }, this));
4069
+
4070
+ var uploadProgress = $.proxy(function(e)
4071
+ {
4072
+ var percent = parseInt(e.loaded / e.total * 100, 10);
4073
+ this.dropareabox.text('Loading ' + percent + '%');
4074
+
4075
+ }, this);
4076
+
4077
+ var xhr = jQuery.ajaxSettings.xhr();
4078
+
4079
+ if (xhr.upload)
4080
+ {
4081
+ xhr.upload.addEventListener('progress', uploadProgress, false);
4082
+ }
4083
+
4084
+ var provider = function () { return xhr; };
4085
+
4086
+ // drop
4087
+ this.dropareabox.get(0).ondrop = $.proxy(function(event)
4088
+ {
4089
+ event.preventDefault();
4090
+
4091
+ this.dropareabox.removeClass('hover').addClass('drop');
4092
+
4093
+ var file = event.dataTransfer.files[0];
4094
+ var fd = new FormData();
4095
+
4096
+ // append hidden fields
4097
+ if (this.opts.uploadFields !== false && typeof this.opts.uploadFields === 'object')
4098
+ {
4099
+ $.each(this.opts.uploadFields, $.proxy(function(k,v)
4100
+ {
4101
+ if (v.toString().indexOf('#') === 0)
4102
+ {
4103
+ v = $(v).val();
4104
+ }
4105
+
4106
+ fd.append(k, v);
4107
+
4108
+ }, this));
4109
+ }
4110
+
4111
+ // append file data
4112
+ fd.append('file', file);
4113
+
4114
+ $.ajax({
4115
+ url: this.opts.url,
4116
+ dataType: 'html',
4117
+ data: fd,
4118
+ xhr: provider,
4119
+ cache: false,
4120
+ contentType: false,
4121
+ processData: false,
4122
+ type: 'POST',
4123
+ success: $.proxy(function(data)
4124
+ {
4125
+ var json = $.parseJSON(data);
4126
+
4127
+ if (typeof json.error == 'undefined')
4128
+ {
4129
+ this.opts.success(json);
4130
+ }
4131
+ else
4132
+ {
4133
+ this.opts.error(this, json);
4134
+ this.opts.success(false);
4135
+ }
4136
+
4137
+ }, this)
4138
+ });
4139
+
4140
+
4141
+ }, this);
4142
+ }
4143
+ },
4144
+ ondrag: function()
4145
+ {
4146
+ this.dropareabox.addClass('hover');
4147
+ return false;
4148
+ },
4149
+ ondragleave: function()
4150
+ {
4151
+ this.dropareabox.removeClass('hover');
4152
+ return false;
4153
+ }
4154
+ };
4155
+
4156
+ })(jQuery);
4157
+
4158
+
4159
+
4160
+ // Define: Linkify plugin from stackoverflow
4161
+ (function($){
4162
+
4163
+ "use strict";
4164
+
4165
+ var protocol = 'http://';
4166
+ var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
4167
+ url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,
4168
+
4169
+ linkifyThis = function ()
4170
+ {
4171
+ var childNodes = this.childNodes,
4172
+ i = childNodes.length;
4173
+ while(i--)
4174
+ {
4175
+ var n = childNodes[i];
4176
+ if (n.nodeType === 3)
4177
+ {
4178
+ var html = n.nodeValue;
4179
+ if (html)
4180
+ {
4181
+ html = html.replace(/&/g, '&amp;')
4182
+ .replace(/</g, '&lt;')
4183
+ .replace(/>/g, '&gt;')
4184
+ .replace(url1, '$1<a href="' + protocol + '$2">$2</a>$3')
4185
+ .replace(url2, '$1<a href="$2">$2</a>$5');
4186
+
4187
+ $(n).after(html).remove();
4188
+ }
4189
+ }
4190
+ else if (n.nodeType === 1 && !/^(a|button|textarea)$/i.test(n.tagName))
4191
+ {
4192
+ linkifyThis.call(n);
4193
+ }
4194
+ }
4195
+ };
4196
+
4197
+ $.fn.linkify = function ()
4198
+ {
4199
+ this.each(linkifyThis);
4200
+ };
4201
+
4202
+ })(jQuery);
4203
+
4204
+
4205
+ /* jQuery plugin textselect
4206
+ * version: 0.9
4207
+ * author: Josef Moravec, josef.moravec@gmail.com
4208
+ * updated: Imperavi Inc.
4209
+ *
4210
+ */
4211
+ eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(5($){$.1.4.7={t:5(0,v){$(2).0("8",c);$(2).0("r",0);$(2).l(\'g\',$.1.4.7.b)},u:5(0){$(2).w(\'g\',$.1.4.7.b)},b:5(1){9 0=$(2).0("r");9 3=$.1.4.7.f(0).h();6(3!=\'\'){$(2).0("8",x);1.j="7";1.3=3;$.1.i.m(2,k)}},f:5(0){9 3=\'\';6(q.e){3=q.e()}o 6(d.e){3=d.e()}o 6(d.p){3=d.p.B().3}A 3}};$.1.4.a={t:5(0,v){$(2).0("n",0);$(2).0("8",c);$(2).l(\'g\',$.1.4.a.b);$(2).l(\'D\',$.1.4.a.s)},u:5(0){$(2).w(\'g\',$.1.4.a.b)},b:5(1){6($(2).0("8")){9 0=$(2).0("n");9 3=$.1.4.7.f(0).h();6(3==\'\'){$(2).0("8",c);1.j="a";$.1.i.m(2,k)}}},s:5(1){6($(2).0("8")){9 0=$(2).0("n");9 3=$.1.4.7.f(0).h();6((1.y=z)&&(3==\'\')){$(2).0("8",c);1.j="a";$.1.i.m(2,k)}}}}})(C);',40,40,'data|event|this|text|special|function|if|textselect|textselected|var|textunselect|handler|false|rdocument|getSelection|getSelectedText|mouseup|toString|handle|type|arguments|bind|apply|rttt|else|selection|rwindow|ttt|handlerKey|setup|teardown|namespaces|unbind|true|keyCode|27|return|createRange|jQuery|keyup'.split('|'),0,{}))
4212
+ ;
4213
+ /*!
4214
+ * jQuery Cookie Plugin v1.3.1
4215
+ * https://github.com/carhartl/jquery-cookie
4216
+ *
4217
+ * Copyright 2013 Klaus Hartl
4218
+ * Released under the MIT license
4219
+ */
4220
+
4221
+ (function (factory) {
4222
+ if (typeof define === 'function' && define.amd && define.amd.jQuery) {
4223
+ // AMD. Register as anonymous module.
4224
+ define(['jquery'], factory);
4225
+ } else {
4226
+ // Browser globals.
4227
+ factory(jQuery);
4228
+ }
4229
+ }(function ($) {
4230
+
4231
+ var pluses = /\+/g;
4232
+
4233
+ function raw(s) {
4234
+ return s;
4235
+ }
4236
+
4237
+ function decoded(s) {
4238
+ return decodeURIComponent(s.replace(pluses, ' '));
4239
+ }
4240
+
4241
+ function converted(s) {
4242
+ if (s.indexOf('"') === 0) {
4243
+ // This is a quoted cookie as according to RFC2068, unescape
4244
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
4245
+ }
4246
+ try {
4247
+ return config.json ? JSON.parse(s) : s;
4248
+ } catch(er) {}
4249
+ }
4250
+
4251
+ var config = $.cookie = function (key, value, options) {
4252
+
4253
+ // write
4254
+ if (value !== undefined) {
4255
+ options = $.extend({}, config.defaults, options);
4256
+
4257
+ if (typeof options.expires === 'number') {
4258
+ var days = options.expires, t = options.expires = new Date();
4259
+ t.setDate(t.getDate() + days);
4260
+ }
4261
+
4262
+ value = config.json ? JSON.stringify(value) : String(value);
4263
+
4264
+ return (document.cookie = [
4265
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
4266
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
4267
+ options.path ? '; path=' + options.path : '',
4268
+ options.domain ? '; domain=' + options.domain : '',
4269
+ options.secure ? '; secure' : ''
4270
+ ].join(''));
4271
+ }
4272
+
4273
+ // read
4274
+ var decode = config.raw ? raw : decoded;
4275
+ var cookies = document.cookie.split('; ');
4276
+ var result = key ? undefined : {};
4277
+ for (var i = 0, l = cookies.length; i < l; i++) {
4278
+ var parts = cookies[i].split('=');
4279
+ var name = decode(parts.shift());
4280
+ var cookie = decode(parts.join('='));
4281
+
4282
+ if (key && key === name) {
4283
+ result = converted(cookie);
4284
+ break;
4285
+ }
4286
+
4287
+ if (!key) {
4288
+ result[name] = converted(cookie);
4289
+ }
4290
+ }
4291
+
4292
+ return result;
4293
+ };
4294
+
4295
+ config.defaults = {};
4296
+
4297
+ $.removeCookie = function (key, options) {
4298
+ if ($.cookie(key) !== undefined) {
4299
+ $.cookie(key, '', $.extend(options, { expires: -1 }));
4300
+ return true;
4301
+ }
4302
+ return false;
4303
+ };
4304
+
4305
+ }));
4306
+
4307
+ var infopark = (function(that) {
4308
+ var editing_active = false;
4309
+
4310
+ var save_obj_attribute = function(obj_id, attribute_name, content, success, error) {
4311
+ var url = window.location.protocol+"//"+window.location.host + "/__ipcms/objs/" + obj_id;
4312
+ var elements = {};
4313
+ elements[attribute_name] = content;
4314
+
4315
+ jQuery.ajax(url, {
4316
+ type: 'PUT',
4317
+ dataType: 'json',
4318
+ contentType: 'application/json; charset=utf-8',
4319
+ data: JSON.stringify({
4320
+ obj: elements
4321
+ }),
4322
+ success: function(data, textStatus, jqXHR) {
4323
+ success();
4324
+ },
4325
+ error: function(jqXHR, textStatus, errorThrown) {
4326
+ error(textStatus);
4327
+ }
4328
+ });
4329
+ };
4330
+
4331
+ var save_action = function(obj, event, key) {
4332
+ var obj_id = obj.$content.data('ip-field-id');
4333
+ var attribute_name = obj.$content.data('ip-field-name');
4334
+ var new_content = $.trim(obj.$editor.text());
4335
+
4336
+ obj.$box.addClass('ip_field_saving');
4337
+
4338
+ var success = function() {
4339
+ obj.$editor.destroyEditor();
4340
+ obj.$content.removeData('ip-field-original-content');
4341
+ };
4342
+ var error = function(error_message) {
4343
+ obj.$box.removeClass('ip_field_saving');
4344
+ infopark.alert(error_message);
4345
+ };
4346
+
4347
+ save_obj_attribute(obj_id, attribute_name, new_content, success, error);
4348
+ };
4349
+
4350
+ var cancel_action = function(obj, event, key) {
4351
+ // restore old content
4352
+ var item = obj.$content;
4353
+ item.html(item.data('ip-field-original-content'));
4354
+ item.removeData('ip-field-original-content');
4355
+
4356
+ obj.$editor.destroyEditor();
4357
+ };
4358
+
4359
+ var redactor_options_for_type = function(type) {
4360
+ var default_options = {
4361
+ focus: true,
4362
+ convertDivs: false,
4363
+ buttonsCustom: {
4364
+ saveButton: {
4365
+ title: "Save",
4366
+ callback: save_action
4367
+ },
4368
+ cancelButton: {
4369
+ title: "Cancel",
4370
+ callback: cancel_action
4371
+ }
4372
+ }
4373
+ };
4374
+ var special_options = {};
4375
+
4376
+ switch(type) {
4377
+ case 'string':
4378
+ special_options = {
4379
+ buttons: ['saveButton', 'cancelButton'],
4380
+ allowedTags: []
4381
+ };
4382
+ break;
4383
+
4384
+ default:
4385
+ return null;
4386
+ }
4387
+
4388
+ return $.extend(default_options, special_options);
4389
+ };
4390
+
4391
+ $.extend(that, {
4392
+ alert: function(message) {
4393
+ // this is a proxy method, so we can stub alert with ie8.
4394
+ alert(message);
4395
+ },
4396
+
4397
+ editing: {
4398
+ initialize: function() {
4399
+ if($.cookie('infopark_editing_active') === 'true') {
4400
+ infopark.editing.activate();
4401
+ }
4402
+ },
4403
+
4404
+ activate: function() {
4405
+ editing_active = true;
4406
+ $.cookie('infopark_editing_active', 'true', { path: '/' });
4407
+
4408
+ $('[data-ip-field-type]').each(function(index, dom_item) {
4409
+ var redactor_options = redactor_options_for_type($(dom_item).data('ip-field-type'));
4410
+ if (redactor_options !== null) {
4411
+ $(dom_item).addClass('ip_field_editable');
4412
+
4413
+ $(dom_item).on('click.ip-editing', function(e) {
4414
+ e.preventDefault();
4415
+
4416
+ $(dom_item).data('ip-field-original-content', $(dom_item).html());
4417
+ $(dom_item).redactor(redactor_options);
4418
+ });
4419
+ }
4420
+ });
4421
+ },
4422
+
4423
+ deactivate: function() {
4424
+ editing_active = false;
4425
+ $.removeCookie('infopark_editing_active');
4426
+
4427
+ $('[data-ip-field-type]').each(function(index, dom_item) {
4428
+ // remove editor (redactor)
4429
+ var redactor_editors = $(dom_item).data('redactor');
4430
+ if (redactor_editors) {
4431
+ redactor_editors.$editor.destroyEditor();
4432
+ }
4433
+
4434
+ // remove onclick handler
4435
+ $(dom_item).off('click.ip-editing');
4436
+
4437
+ // remove class ip_field_editable
4438
+ $(dom_item).removeClass('ip_field_editable');
4439
+ });
4440
+ },
4441
+
4442
+ is_active: function() {
4443
+ return editing_active;
4444
+ }
4445
+ }
4446
+ });
4447
+
4448
+ return that;
4449
+ }(infopark || {}));
4450
+
4451
+