redde 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitignore +20 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +24 -0
  5. data/LICENSE +22 -0
  6. data/README.md +57 -0
  7. data/Rakefile +2 -0
  8. data/lib/generators/redde/deploy/deploy_generator.rb +34 -0
  9. data/lib/generators/redde/deploy/templates/Capfile +4 -0
  10. data/lib/generators/redde/deploy/templates/deploy.rb +33 -0
  11. data/lib/generators/redde/deploy/templates/recipes/base.rb +16 -0
  12. data/lib/generators/redde/deploy/templates/recipes/check.rb +13 -0
  13. data/lib/generators/redde/deploy/templates/recipes/database.rb +66 -0
  14. data/lib/generators/redde/deploy/templates/recipes/imagemagick.rb +8 -0
  15. data/lib/generators/redde/deploy/templates/recipes/memcached.rb +10 -0
  16. data/lib/generators/redde/deploy/templates/recipes/monit.rb +35 -0
  17. data/lib/generators/redde/deploy/templates/recipes/nginx.rb +26 -0
  18. data/lib/generators/redde/deploy/templates/recipes/nodejs.rb +10 -0
  19. data/lib/generators/redde/deploy/templates/recipes/postfix.rb +37 -0
  20. data/lib/generators/redde/deploy/templates/recipes/rbenv.rb +17 -0
  21. data/lib/generators/redde/deploy/templates/recipes/templates/database.yml.erb +8 -0
  22. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.conf.erb +57 -0
  23. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.defaults.erb +11 -0
  24. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-keys.conf.erb +2 -0
  25. data/lib/generators/redde/deploy/templates/recipes/templates/gemrc.erb +1 -0
  26. data/lib/generators/redde/deploy/templates/recipes/templates/main.cf.erb +43 -0
  27. data/lib/generators/redde/deploy/templates/recipes/templates/memcached.erb +47 -0
  28. data/lib/generators/redde/deploy/templates/recipes/templates/monit_monitrc.erb +21 -0
  29. data/lib/generators/redde/deploy/templates/recipes/templates/monit_nginx.erb +5 -0
  30. data/lib/generators/redde/deploy/templates/recipes/templates/monit_unicorn.erb +14 -0
  31. data/lib/generators/redde/deploy/templates/recipes/templates/nginx_unicorn.erb +28 -0
  32. data/lib/generators/redde/deploy/templates/recipes/templates/unicorn.rb.erb +36 -0
  33. data/lib/generators/redde/deploy/templates/recipes/templates/unicorn_init.erb +84 -0
  34. data/lib/generators/redde/deploy/templates/recipes/unicorn.rb +27 -0
  35. data/lib/generators/redde/layout/layout_generator.rb +57 -0
  36. data/lib/generators/redde/layout/templates/assets/images/admin/addphoto.png +0 -0
  37. data/lib/generators/redde/layout/templates/assets/images/admin/ajaxloader2.gif +0 -0
  38. data/lib/generators/redde/layout/templates/assets/images/admin/arrow_down.png +0 -0
  39. data/lib/generators/redde/layout/templates/assets/images/admin/arrow_enter.png +0 -0
  40. data/lib/generators/redde/layout/templates/assets/images/admin/arrow_right.png +0 -0
  41. data/lib/generators/redde/layout/templates/assets/images/admin/coins.png +0 -0
  42. data/lib/generators/redde/layout/templates/assets/images/admin/confirm.png +0 -0
  43. data/lib/generators/redde/layout/templates/assets/images/admin/del.png +0 -0
  44. data/lib/generators/redde/layout/templates/assets/images/admin/delete.png +0 -0
  45. data/lib/generators/redde/layout/templates/assets/images/admin/email.png +0 -0
  46. data/lib/generators/redde/layout/templates/assets/images/admin/error.png +0 -0
  47. data/lib/generators/redde/layout/templates/assets/images/admin/fio.png +0 -0
  48. data/lib/generators/redde/layout/templates/assets/images/admin/folder.png +0 -0
  49. data/lib/generators/redde/layout/templates/assets/images/admin/folder_.png +0 -0
  50. data/lib/generators/redde/layout/templates/assets/images/admin/icon_eye.gif +0 -0
  51. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/css/jquery.lightbox-0.5.css +101 -0
  52. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-blank.gif +0 -0
  53. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-close.gif +0 -0
  54. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-next.gif +0 -0
  55. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-btn-prev.gif +0 -0
  56. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/images/lightbox-ico-loading.gif +0 -0
  57. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.js +32 -0
  58. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.js +477 -0
  59. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.min.js +42 -0
  60. data/lib/generators/redde/layout/templates/assets/images/admin/lightbox/js/jquery.lightbox-0.5.pack.js +14 -0
  61. data/lib/generators/redde/layout/templates/assets/images/admin/logo.png +0 -0
  62. data/lib/generators/redde/layout/templates/assets/images/admin/logo_reddeshop.png +0 -0
  63. data/lib/generators/redde/layout/templates/assets/images/admin/move_handler.png +0 -0
  64. data/lib/generators/redde/layout/templates/assets/images/admin/phone.png +0 -0
  65. data/lib/generators/redde/layout/templates/assets/images/admin/photo_ico.png +0 -0
  66. data/lib/generators/redde/layout/templates/assets/images/admin/print.png +0 -0
  67. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/docstyle.css +123 -0
  68. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/redactor.css +369 -0
  69. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/style.css +119 -0
  70. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/css/wym.css +136 -0
  71. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/img/icons.png +0 -0
  72. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/by.js +72 -0
  73. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/de.js +75 -0
  74. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/en.js +76 -0
  75. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/es.js +76 -0
  76. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/fr.js +74 -0
  77. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/hu.js +76 -0
  78. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/it.js +76 -0
  79. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ja.js +76 -0
  80. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/lv.js +74 -0
  81. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/nl.js +76 -0
  82. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pl.js +75 -0
  83. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/pt_br.js +81 -0
  84. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ru.js +75 -0
  85. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/sq.js +76 -0
  86. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/tr.js +76 -0
  87. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/ua.js +75 -0
  88. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/langs/zh_cn.js +77 -0
  89. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/file.html +3 -0
  90. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/image.html +39 -0
  91. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/image_edit.html +35 -0
  92. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/link.html +74 -0
  93. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/table.html +25 -0
  94. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/plugins/video.html +15 -0
  95. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/redactor.js.erb +2260 -0
  96. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/redactor.min.js +1 -0
  97. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/toolbars/default.js +219 -0
  98. data/lib/generators/redde/layout/templates/assets/images/admin/redactor/toolbars/mini.js +103 -0
  99. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/_jquery.reddebox.js.erb +214 -0
  100. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/close.png +0 -0
  101. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.js.erb +246 -0
  102. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/jquery.reddebox.scss +31 -0
  103. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/next.png +0 -0
  104. data/lib/generators/redde/layout/templates/assets/images/admin/reddebox/prev.png +0 -0
  105. data/lib/generators/redde/layout/templates/assets/images/admin/refresh.png +0 -0
  106. data/lib/generators/redde/layout/templates/assets/images/admin/submit.png +0 -0
  107. data/lib/generators/redde/layout/templates/assets/images/admin/submit_hover.png +0 -0
  108. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/change-log.txt +19 -0
  109. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/check-exists.php +15 -0
  110. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/index.php +50 -0
  111. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.js +888 -0
  112. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/jquery.uploadifive.min.js +6 -0
  113. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/license-standard.txt +71 -0
  114. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-cancel.png +0 -0
  115. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive-image-only.php +66 -0
  116. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.css +100 -0
  117. data/lib/generators/redde/layout/templates/assets/images/admin/uploadifive/uploadifive.php +33 -0
  118. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/#swfobject.js +4 -0
  119. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/cancel.png +0 -0
  120. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/jquery.uploadify.min.js +315 -0
  121. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify-cancel.png +0 -0
  122. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.css +66 -0
  123. data/lib/generators/redde/layout/templates/assets/images/admin/uploadify/uploadify.swf +0 -0
  124. data/lib/generators/redde/layout/templates/assets/images/admin/view.png +0 -0
  125. data/lib/generators/redde/layout/templates/assets/images/admin/view_mk.png +0 -0
  126. data/lib/generators/redde/layout/templates/assets/javascripts/admin/jquery.ui.nestedSortable.js +390 -0
  127. data/lib/generators/redde/layout/templates/assets/javascripts/admin/swfobject.js +4 -0
  128. data/lib/generators/redde/layout/templates/assets/javascripts/admin/zen_textarea.min.js +17 -0
  129. data/lib/generators/redde/layout/templates/assets/javascripts/admin.js +88 -0
  130. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/_reset.scss +32 -0
  131. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_list.scss +22 -0
  132. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_notice.scss +39 -0
  133. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_orders.scss +22 -0
  134. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_partners.scss +15 -0
  135. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_photos.scss +31 -0
  136. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/blocks/_sortable.scss +17 -0
  137. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/default.scss +127 -0
  138. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/_input.scss +43 -0
  139. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/defaults/_table.scss +24 -0
  140. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_header.scss +57 -0
  141. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_launchbar.scss +35 -0
  142. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_login.scss +10 -0
  143. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_main.scss +59 -0
  144. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/_sidebar.scss +35 -0
  145. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_filter.scss +16 -0
  146. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_order-sh.scss +59 -0
  147. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/shop/_pe.scss +43 -0
  148. data/lib/generators/redde/layout/templates/assets/stylesheets/admin.scss +12 -0
  149. data/lib/generators/redde/layout/templates/controllers/base_controller.rb +6 -0
  150. data/lib/generators/redde/layout/templates/helpers/admin_helper.rb +37 -0
  151. data/lib/generators/redde/layout/templates/layouts/admin.html.haml +30 -0
  152. data/lib/generators/redde/layout/templates/layouts/login.html.haml +32 -0
  153. data/lib/generators/redde/layout/templates/shared/_header.html.haml +13 -0
  154. data/lib/generators/redde/layout/templates/shared/_launchbar.html.haml +9 -0
  155. data/lib/generators/redde/layout/templates/shared/_sidebar.html.haml +23 -0
  156. data/lib/generators/redde/scaffold/scaffold_generator.rb +114 -0
  157. data/lib/generators/redde/scaffold/templates/controllers/controller.rb +55 -0
  158. data/lib/generators/redde/scaffold/templates/edit.html.haml +36 -0
  159. data/lib/generators/redde/scaffold/templates/index.html.haml +37 -0
  160. data/lib/redde/version.rb +3 -0
  161. data/lib/redde.rb +4 -0
  162. data/redde.gemspec +26 -0
  163. data/spec/deploy_generator_spec.rb +29 -0
  164. data/spec/layout_generator_spec.rb +41 -0
  165. data/spec/scaffold_generator_spec.rb +25 -0
  166. data/spec/spec_helper.rb +10 -0
  167. metadata +327 -0
@@ -0,0 +1,2260 @@
1
+ /*
2
+ Redactor v7.6.3
3
+ Updated 31.05.2012
4
+
5
+ http://redactorjs.com/
6
+
7
+ Copyright (c) 2009-2012, Imperavi Ltd.
8
+ Licensed under Creative Commons Attribution-NonCommercial 3.0 license.
9
+
10
+ Usage: $('#content').redactor();
11
+ */
12
+
13
+ var RTOOLBAR = {};
14
+
15
+ (function($){
16
+
17
+ // Plugin
18
+ jQuery.fn.redactor = function(option)
19
+ {
20
+ return this.each(function()
21
+ {
22
+ var $this = $(this);
23
+
24
+ var data = $this.data('redactor');
25
+ if (!data) $this.data('redactor', (data = new Redactor(this, option)));
26
+ });
27
+ };
28
+
29
+
30
+ // Initialization
31
+ var Redactor = function(element, options)
32
+ {
33
+ // Element
34
+ this.$el = $(element);
35
+
36
+ // Options
37
+ this.opts = $.extend({
38
+
39
+ lang: 'en',
40
+ toolbar: 'default',
41
+
42
+ load: true,
43
+
44
+ path: false,
45
+ css: '<%= asset_path("redactor/css/wym.css") %>',
46
+ focus: true,
47
+ resize: true,
48
+ autoresize: false,
49
+ fixed: false,
50
+
51
+ autoformat: true,
52
+ cleanUp: true,
53
+ convertDivs: true,
54
+ removeClasses: true,
55
+ removeStyles: false,
56
+ convertLinks: true,
57
+
58
+ handler: false, // false or url
59
+
60
+ autosave: false, // false or url
61
+ interval: 60, // seconds
62
+
63
+ imageGetJson: false, // url (ex. /folder/images.json ) or false
64
+
65
+ imageUpload: false, // url
66
+ linkFileUpload: false, // url
67
+ fileUpload: false, // url
68
+
69
+ visual: true,
70
+ fullscreen: false,
71
+ overlay: true, // modal overlay
72
+
73
+ colors: Array(
74
+ '#ffffff', '#000000', '#eeece1', '#1f497d', '#4f81bd', '#c0504d', '#9bbb59', '#8064a2', '#4bacc6', '#f79646', '#ffff00',
75
+ '#f2f2f2', '#7f7f7f', '#ddd9c3', '#c6d9f0', '#dbe5f1', '#f2dcdb', '#ebf1dd', '#e5e0ec', '#dbeef3', '#fdeada', '#fff2ca',
76
+ '#d8d8d8', '#595959', '#c4bd97', '#8db3e2', '#b8cce4', '#e5b9b7', '#d7e3bc', '#ccc1d9', '#b7dde8', '#fbd5b5', '#ffe694',
77
+ '#bfbfbf', '#3f3f3f', '#938953', '#548dd4', '#95b3d7', '#d99694', '#c3d69b', '#b2a2c7', '#b7dde8', '#fac08f', '#f2c314',
78
+ '#a5a5a5', '#262626', '#494429', '#17365d', '#366092', '#953734', '#76923c', '#5f497a', '#92cddc', '#e36c09', '#c09100',
79
+ '#7f7f7f', '#0c0c0c', '#1d1b10', '#0f243e', '#244061', '#632423', '#4f6128', '#3f3151', '#31859b', '#974806', '#7f6000'),
80
+
81
+ // private
82
+ allEmptyHtml: '<p><br /></p>',
83
+ mozillaEmptyHtml: '<p>&nbsp;</p>'
84
+
85
+
86
+ }, options, this.$el.data());
87
+
88
+ this.dropdowns = [];
89
+
90
+ // Init
91
+ this.init();
92
+ };
93
+
94
+ // Functionality
95
+ Redactor.prototype = {
96
+
97
+ // DYNAMICALLY LOAD
98
+ _loadFile: function(file, array)
99
+ {
100
+ var item = array[0];
101
+ array.splice(0, 1);
102
+
103
+ var callback;
104
+ if (typeof(item) == 'function') callback = item;
105
+ else callback = $.proxy(function() { this._loadFile(item, array); }, this);
106
+
107
+ this.dynamicallyLoad(file, callback);
108
+ },
109
+ loadFiles: function(array)
110
+ {
111
+ var item = array[0];
112
+ array.splice(0, 1);
113
+
114
+ this._loadFile(item, array);
115
+ },
116
+ dynamicallyLoad: function (url, callback)
117
+ {
118
+ var head = document.getElementsByTagName("head")[0];
119
+ var script = document.createElement("script");
120
+ script.src = url;
121
+
122
+ var done = false;
123
+
124
+ script.onload = script.onreadystatechange = function()
125
+ {
126
+ if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete"))
127
+ {
128
+ done = true;
129
+ if (callback) callback();
130
+ script.onload = script.onreadystatechange = null;
131
+ }
132
+ };
133
+
134
+ head.appendChild(script);
135
+
136
+ },
137
+
138
+ // Initialization
139
+ init: function()
140
+ {
141
+ // get path to styles
142
+ this.getPath();
143
+
144
+ if (this.opts.load)
145
+ {
146
+ // load files
147
+ var files = [];
148
+
149
+ files.push(this.opts.path + '/langs/' + this.opts.lang + '.js');
150
+ if (this.opts.toolbar !== false) files.push(this.opts.path + '/toolbars/' + this.opts.toolbar + '.js');
151
+ files.push($.proxy(this.start, this));
152
+
153
+ this.loadFiles(files);
154
+ }
155
+ else this.start();
156
+
157
+
158
+ },
159
+ start: function()
160
+ {
161
+
162
+ // get dimensions
163
+ this.height = this.$el.css('height');
164
+ this.width = this.$el.css('width');
165
+
166
+ // construct editor
167
+ this.build();
168
+
169
+ // get html
170
+ var html = this.$el.val();
171
+
172
+ // preformatter
173
+ html = this.preformater(html);
174
+
175
+ // conver newlines to p
176
+ if (this.opts.autoformat) html = this.paragraphy(html);
177
+
178
+ // enable
179
+ this.$editor = this.enable(html);
180
+
181
+ // focus always on page
182
+ $(this.doc).click($.proxy(function(e) { this.$editor.focus(); }, this));
183
+
184
+ // cleanup
185
+ $(this.doc).bind('paste', $.proxy(function(e)
186
+ {
187
+ setTimeout($.proxy(function ()
188
+ {
189
+ var node = $('<span id="pastemarkerend">&nbsp;</span>');
190
+ this.insertNodeAtCaret(node.get(0));
191
+
192
+ this.pasteCleanUp();
193
+
194
+ }, this), 200);
195
+
196
+
197
+
198
+ }, this));
199
+
200
+ // keypress
201
+ $(this.doc).keypress($.proxy(function(e)
202
+ {
203
+ var key = e.keyCode || e.which;
204
+
205
+ // safari shift key + enter
206
+ if (navigator.userAgent.indexOf('AppleWebKit') != -1) return this.safariShiftKeyEnter(e, key);
207
+
208
+ }, this))
209
+
210
+ // keyup
211
+ .keyup($.proxy(function(e)
212
+ {
213
+ var key = e.keyCode || e.which;
214
+
215
+ if (this.opts.autoformat)
216
+ {
217
+ // if empty
218
+ if (key == 8 || key == 46) return this.formatEmpty(e);
219
+
220
+ // new line p
221
+ if (key == 13 && !e.shiftKey && !e.ctrlKey && !e.metaKey) return this.formatNewLine(e);
222
+ }
223
+ //console.log(e);
224
+ this.syncCode();
225
+
226
+ }, this));
227
+
228
+ // toolbar
229
+ this.buildToolbar();
230
+
231
+ // resizer
232
+ if (this.opts.autoresize === false) this.buildResizer();
233
+ else this.observeAutoResize();
234
+
235
+ // shortcuts
236
+ this.shortcuts();
237
+
238
+ // autosave
239
+ this.autoSave();
240
+
241
+ // observers
242
+ this.observeImages();
243
+
244
+ // fullscreen on start
245
+ if (this.opts.fullscreen)
246
+ {
247
+ this.opts.fullscreen = false;
248
+ this.fullscreen();
249
+ }
250
+
251
+ // focus
252
+ if (this.opts.focus) this.focus();
253
+
254
+ // fixed
255
+ if (this.opts.fixed)
256
+ {
257
+ this.observeScroll();
258
+ $(document).scroll($.proxy(this.observeScroll, this));
259
+ }
260
+ },
261
+ shortcuts: function()
262
+ {
263
+ $(this.doc).keydown($.proxy(function(e)
264
+ {
265
+ var key = e.keyCode || e.which;
266
+
267
+ if (e.ctrlKey)
268
+ {
269
+ if (key == 90) this._shortcuts(e, 'undo'); // Ctrl + z
270
+ else if (key == 90 && e.shiftKey) this._shortcuts(e, 'redo'); // Ctrl + Shift + z
271
+ else if (key == 77) this._shortcuts(e, 'removeFormat'); // Ctrl + m
272
+ else if (key == 66) this._shortcuts(e, 'bold'); // Ctrl + b
273
+ else if (key == 73) this._shortcuts(e, 'italic'); // Ctrl + i
274
+ else if (key == 74) this._shortcuts(e, 'insertunorderedlist'); // Ctrl + j
275
+ else if (key == 75) this._shortcuts(e, 'insertorderedlist'); // Ctrl + k
276
+ else if (key == 76) this._shortcuts(e, 'superscript'); // Ctrl + l
277
+ }
278
+
279
+ if (!e.shiftKey && key == 9) this._shortcuts(e, 'indent'); // Tab
280
+ else if (e.shiftKey && key == 9 ) this._shortcuts(e, 'outdent'); // Shift + tab
281
+
282
+ }, this));
283
+
284
+ },
285
+ _shortcuts: function(e, cmd)
286
+ {
287
+ if (e.preventDefault) e.preventDefault();
288
+ this.execCommand(cmd, null);
289
+ },
290
+ getPath: function()
291
+ {
292
+ if (this.opts.path !== false) return this.opts.path;
293
+
294
+ $('script').each($.proxy(function(i,s)
295
+ {
296
+ if (s.src)
297
+ {
298
+
299
+ // Match redactor.js or redactor.min.js, followed by an optional querystring (often used for cache purposes)
300
+ var regexp = new RegExp(/\/redactor(\.min)?\.js(\?.*)?/);
301
+ if (s.src.match(regexp)) this.opts.path = s.src.replace(regexp, '');
302
+ }
303
+ }, this));
304
+
305
+ },
306
+ build: function()
307
+ {
308
+ // container
309
+ this.$box = $('<div class="redactor_box"></div>');
310
+
311
+ // frame
312
+ this.$frame = $('<iframe frameborder="0" scrolling="auto" style="height: ' + this.height + ';" class="redactor_frame"></iframe>');
313
+
314
+ // hide textarea
315
+ this.$el.css('width', '100%').hide();
316
+
317
+ // append box and frame
318
+ this.$box.insertAfter(this.$el).append(this.$frame).append(this.$el);
319
+
320
+ },
321
+ write: function(html)
322
+ {
323
+ this.doc.open();
324
+ this.doc.write(html);
325
+ this.doc.close();
326
+ },
327
+ enable: function(html)
328
+ {
329
+ this.doc = this.getDoc(this.$frame.get(0));
330
+
331
+ if (this.doc !== null)
332
+ {
333
+ this.write(this.setDoc(html));
334
+ if ($.browser.mozilla) this.doc.execCommand("useCSS", false, true);
335
+ return $(this.doc).find('#page');
336
+ }
337
+ else return false;
338
+ },
339
+ setDoc: function(html)
340
+ {
341
+ var frameHtml = '<!DOCTYPE html>\n';
342
+ frameHtml += '<html><head><link media="all" type="text/css" href="' + this.opts.css + '" rel="stylesheet"></head>';
343
+ frameHtml += '<body><div id="page" contenteditable="true">';
344
+ frameHtml += html;
345
+ frameHtml += '</div></body></html>';
346
+ return frameHtml;
347
+ },
348
+ getDoc: function(frame)
349
+ {
350
+ if (frame.contentDocument) return frame.contentDocument;
351
+ else if (frame.contentWindow && frame.contentWindow.document) return frame.contentWindow.document;
352
+ else if (frame.document) return frame.document;
353
+ else return null;
354
+ },
355
+ focus: function()
356
+ {
357
+ this.$editor.focus();
358
+ },
359
+ syncCode: function()
360
+ {
361
+ var html = this.formating(this.$editor.html());
362
+ this.$el.val(html);
363
+ },
364
+
365
+ // API functions
366
+ setCode: function(html)
367
+ {
368
+ html = this.preformater(html);
369
+
370
+ this.$editor.html(html).focus();
371
+
372
+ this.syncCode();
373
+ },
374
+ getCode: function()
375
+ {
376
+ var html = this.$editor ? this.$editor.html() : this.$el.val();
377
+ html = this.reformater(html);
378
+
379
+ return html;
380
+ },
381
+ insertHtml: function(html)
382
+ {
383
+ this.execCommand('inserthtml', html);
384
+ },
385
+ destroy: function()
386
+ {
387
+ var html = this.getCode();
388
+
389
+ this.$box.after(this.$el);
390
+ this.$box.remove();
391
+ this.$el.val(html).show();
392
+
393
+ this.dropdowns.forEach(function(dropdown, i)
394
+ {
395
+ dropdown.remove();
396
+ delete(this.dropdowns[i]);
397
+ }, this);
398
+ },
399
+ handler: function()
400
+ {
401
+ $.ajax({
402
+ url: this.opts.handler,
403
+ type: 'post',
404
+ data: 'redactor=' + escape(encodeURIComponent(this.getCode())),
405
+ success: $.proxy(function(data)
406
+ {
407
+ this.setCode(data);
408
+ this.syncCode();
409
+
410
+ }, this)
411
+ });
412
+
413
+ },
414
+ // end API functions
415
+
416
+ // OBSERVERS
417
+ observeImages: function()
418
+ {
419
+ if ($.browser.mozilla) this.doc.execCommand("enableObjectResizing", false, "false");
420
+
421
+ $(this.doc).find('img').attr('unselectable', 'on').each($.proxy(function(i,s)
422
+ {
423
+ this.resizeImage(s);
424
+
425
+ }, this));
426
+
427
+ },
428
+ observeScroll: function()
429
+ {
430
+ var scrolltop = $(document).scrollTop();
431
+ var boxtop = this.$box.offset().top;
432
+
433
+ if (scrolltop > boxtop)
434
+ {
435
+ this.fixed = true;
436
+ this.$toolbar.css({position: 'fixed', width: '100%'});
437
+ }
438
+ else
439
+ {
440
+ this.fixed = false;
441
+ this.$toolbar.css({position: 'relative', width: 'auto'});
442
+ }
443
+ },
444
+ observeAutoResize: function()
445
+ {
446
+ this.$editor.css({ 'min-height':this.$el.height()+'px' });
447
+ this.$frame.css({ 'overflow-x':'auto', 'overflow-y':'hidden' });
448
+ this.$frame.load($.proxy(this.setAutoSize, this));
449
+ $(this.doc).keyup($.proxy(this.setAutoSize, this));
450
+ },
451
+ setAutoSize: function()
452
+ {
453
+ this.$frame.height(this.$editor.outerHeight(true)+30);
454
+ },
455
+
456
+
457
+ // EXECCOMMAND
458
+ execCommand: function(cmd, param)
459
+ {
460
+ if (this.opts.visual && this.doc)
461
+ {
462
+ try
463
+ {
464
+ if ($.browser.msie) this.focus();
465
+
466
+ if (cmd == 'inserthtml' && $.browser.msie) this.doc.selection.createRange().pasteHTML(param);
467
+ else if (cmd == 'formatblock' && $.browser.msie) this.doc.execCommand(cmd, false, '<' +param + '>');
468
+ else
469
+ {
470
+ this.doc.execCommand(cmd, false, param);
471
+ }
472
+
473
+ this.syncCode();
474
+ this.focus();
475
+ }
476
+ catch (e) { }
477
+
478
+ }
479
+ },
480
+
481
+ // FORMAT NEW LINE
482
+ formatNewLine: function(e)
483
+ {
484
+ var parent = this.getParentNode();
485
+ if (parent.nodeName == 'DIV' && parent.id == 'page')
486
+ {
487
+ if (e.preventDefault) e.preventDefault();
488
+
489
+ element = $(this.getCurrentNode());
490
+ if (element.get(0).tagName == 'DIV' && (element.html() == '' || element.html() == '<br>'))
491
+ {
492
+ newElement = $('<p>').append(element.clone().get(0).childNodes);
493
+ element.replaceWith(newElement);
494
+ newElement.html('<br />');
495
+ this.setFocusNode(newElement.get(0));
496
+
497
+ this.syncCode();
498
+ return false;
499
+ }
500
+ else this.syncCode();
501
+
502
+ // convert links
503
+ if (this.opts.convertLinks) this.$editor.linkify();
504
+ }
505
+ else
506
+ {
507
+ this.syncCode();
508
+ return true;
509
+ }
510
+ },
511
+
512
+ // SAFARI SHIFT KEY + ENTER
513
+ safariShiftKeyEnter: function(e, key)
514
+ {
515
+ if (e.shiftKey && key == 13)
516
+ {
517
+ if (e.preventDefault) e.preventDefault();
518
+
519
+ var node1 = $('<span><br /></span>');
520
+ this.insertNodeAtCaret(node1.get(0));
521
+ this.setFocusNode(node1.get(0));
522
+
523
+ this.syncCode();
524
+ return false;
525
+ }
526
+ },
527
+
528
+ // FORMAT EMPTY
529
+ formatEmpty: function(e)
530
+ {
531
+ var html = $.trim(this.$editor.html());
532
+
533
+ if ($.browser.mozilla) html = html.replace(/<br>/gi, '');
534
+
535
+ if (html === '')
536
+ {
537
+ if (e.preventDefault) e.preventDefault();
538
+
539
+ var nodehtml = this.opts.allEmptyHtml;
540
+ if ($.browser.mozilla) nodehtml = this.opts.mozillaEmptyHtml;
541
+
542
+ var node = $(nodehtml).get(0);
543
+ this.$editor.html(node);
544
+ this.setFocusNode(node);
545
+
546
+ this.syncCode();
547
+ return false;
548
+ }
549
+ else this.syncCode();
550
+ },
551
+
552
+ // PARAGRAPHY
553
+ paragraphy: function (str)
554
+ {
555
+ str = $.trim(str);
556
+ if (str === '')
557
+ {
558
+ if (!$.browser.mozilla) return this.opts.allEmptyHtml;
559
+ else return this.opts.mozillaEmptyHtml;
560
+ }
561
+
562
+ // convert div to p
563
+ if (this.opts.convertDivs) str = str.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi, '<p>$2</p>');
564
+
565
+ // inner functions
566
+ var X = function(x, a, b) { return x.replace(new RegExp(a, 'g'), b); };
567
+ var R = function(a, b) { return X(str, a, b); };
568
+
569
+ // block elements
570
+ 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])';
571
+
572
+ str += '\n';
573
+
574
+ R('<br />\\s*<br />', '\n\n');
575
+ R('(<' + blocks + '[^>]*>)', '\n$1');
576
+ R('(</' + blocks + '>)', '$1\n\n');
577
+ R('\r\n|\r', '\n'); // newlines
578
+ R('\n\n+', '\n\n'); // remove duplicates
579
+ R('\n?((.|\n)+?)$', '<p>$1</p>\n'); // including one at the end
580
+ R('<p>\\s*?</p>', ''); // remove empty p
581
+ R('<p>(<div[^>]*>\\s*)', '$1<p>');
582
+ R('<p>([^<]+)\\s*?(</(div|address|form)[^>]*>)', '<p>$1</p>$2');
583
+ R('<p>\\s*(</?' + blocks + '[^>]*>)\\s*</p>', '$1');
584
+ R('<p>(<li.+?)</p>', '$1');
585
+ R('<p>\\s*(</?' + blocks + '[^>]*>)', '$1');
586
+ R('(</?' + blocks + '[^>]*>)\\s*</p>', '$1');
587
+ R('(</?' + blocks + '[^>]*>)\\s*<br />', '$1');
588
+ R('<br />(\\s*</?(p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)', '$1');
589
+
590
+ // pre
591
+ if (str.indexOf('<pre') != -1)
592
+ {
593
+ R('(<pre(.|\n)*?>)((.|\n)*?)</pre>', function(m0, m1, m2, m3)
594
+ {
595
+ return X(m1, '\\\\([\'\"\\\\])', '$1') + X(X(X(m3, '<p>', '\n'), '</p>|<br />', ''), '\\\\([\'\"\\\\])', '$1') + '</pre>';
596
+ });
597
+ }
598
+
599
+ return R('\n</p>$', '</p>');
600
+ },
601
+
602
+ // PREPARE FORMATER
603
+ preformater: function(html)
604
+ {
605
+ html = html.replace(/<br>/gi,'<br />');
606
+
607
+ html = html.replace(/<blockquote\b[^>]*>([\w\W]*?)<p>([\w\W]*?)<\/p>([\w\W]*?)<\/blockquote[^>]*>/gi,'<blockquote>$1$2<br />$3</blockquote>');
608
+
609
+ html = html.replace(/<strong\b[^>]*>([\w\W]*?)<\/strong[^>]*>/gi,'<b>$1</b>');
610
+ html = html.replace(/<em\b[^>]*>([\w\W]*?)<\/em[^>]*>/gi,'<i>$1</i>');
611
+ html = html.replace(/<del\b[^>]*>([\w\W]*?)<\/del[^>]*>/gi,'<strike>$1</strike>');
612
+
613
+ return html;
614
+ },
615
+
616
+ // REVERT FORMATER
617
+ reformater: function(html)
618
+ {
619
+ html = html.replace(/<br>/gi,'<br />');
620
+
621
+ html = html.replace(/<b\b[^>]*>([\w\W]*?)<\/b[^>]*>/gi,'<strong>$1</strong>');
622
+ html = html.replace(/<i\b[^>]*>([\w\W]*?)<\/i[^>]*>/gi,'<em>$1</em>');
623
+ html = html.replace(/<strike\b[^>]*>([\w\W]*?)<\/strike[^>]*>/gi,'<del>$1</del>');
624
+ html = html.replace(/<span(.*?)style="font-weight: bold;">([\w\W]*?)<\/span>/gi, "<strong>$2</strong>");
625
+ html = html.replace(/<span(.*?)style="font-style: italic;">([\w\W]*?)<\/span>/gi, "<em>$2</em>");
626
+ html = html.replace(/<span(.*?)style="font-weight: bold; font-style: italic;">([\w\W]*?)<\/span>/gi, "<em><strong>$2</strong></em>");
627
+ html = html.replace(/<span(.*?)style="font-style: italic; font-weight: bold;">([\w\W]*?)<\/span>/gi, "<strong><em>$2</em></strong>");
628
+
629
+ return html;
630
+ },
631
+
632
+ // REMOVE CLASSES AND STYLES
633
+ cleanUpClasses: function(html)
634
+ {
635
+ html = html.replace(/\s*class="TOC(.*?)"/gi, "" );
636
+ html = html.replace(/\s*class="Heading(.*?)"/gi, "" );
637
+ html = html.replace(/\s*class="Body(.*?)"/gi, "" );
638
+
639
+ return html;
640
+ },
641
+ cleanUpStyles: function(html)
642
+ {
643
+
644
+ html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" );
645
+ html = html.replace( /\s*margin(.*?)pt\s*;/gi, "" );
646
+ html = html.replace( /\s*margin(.*?)cm\s*;/gi, "" );
647
+ html = html.replace( /\s*text-indent:(.*?)\s*;/gi, "" );
648
+ html = html.replace( /\s*line-height:(.*?)\s*;/gi, "" );
649
+ html = html.replace( /\s*page-break-before: [^\s;]+;?"/gi, "\"" );
650
+ html = html.replace( /\s*font-variant: [^\s;]+;?"/gi, "\"" );
651
+ html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" );
652
+ html = html.replace( /\s*tab-stops:[^"]*/gi, "" );
653
+ html = html.replace( /\s*face="[^"]*"/gi, "" );
654
+ html = html.replace( /\s*face=[^ >]*/gi, "" );
655
+ html = html.replace( /\s*font:(.*?);/gi, "" );
656
+ html = html.replace( /\s*font-size:(.*?);/gi, "" );
657
+ html = html.replace( /\s*font-weight:(.*?);/gi, "" );
658
+ html = html.replace( /\s*font-family:[^;"]*;?/gi, "" );
659
+ html = html.replace(/<span style="Times New Roman&quot;">\s\n<\/span>/gi, '');
660
+
661
+ return html;
662
+
663
+ },
664
+ cleanUp: function(html)
665
+ {
666
+ // clean comments
667
+ html = html.replace(/(<\!\-\-([\w\W]*?)\-\->)/ig, "");
668
+
669
+ if (this.opts.convertDivs)
670
+ {
671
+ html = html.replace(/<div(.*?)>([\w\W]*?)<\/div>/gi, '<p$1>$2</p>');
672
+ }
673
+
674
+ // clean dirty
675
+ html = html.replace(/ lang="([\w\W]*?)"/gi, '');
676
+ html = html.replace(/<a name="(.*?)">([\w\W]*?)<\/a>/gi, '');
677
+ html = html.replace(/\&nbsp;\&nbsp;\&nbsp;/gi, ' ');
678
+ html = html.replace(/\&nbsp;\&nbsp;/gi, ' ');
679
+ html = html.replace(/<o:p>(.*?)<\/o:p>/gi, '');
680
+
681
+
682
+ // empty style
683
+ html = html.replace( /\s*style="\s*"/gi, '' );
684
+
685
+ // spans
686
+ html = html.replace(/<span>&nbsp;<\/span>/gi, '');
687
+ html = html.replace(/<span>([\w\W]*?)<\/span>/gi, '$1');
688
+
689
+ return html;
690
+ },
691
+ removeTags: function(html)
692
+ {
693
+ return html.replace(/<(?!\s*\/?(code|span|div|label|a|br|p|b|i|del|strike|img|video|audio|iframe|object|embed|param|blockquote|mark|cite|small|ul|ol|li|hr|dl|dt|dd|sup|sub|big|pre|code|figure|figcaption|strong|em|table|tr|td|th|tbody|thead|tfoot|h1|h2|h3|h4|h5|h6)\b)[^>]+>/gi,"");
694
+ },
695
+
696
+ // PASTE CLEANUP
697
+ pasteCleanUp: function()
698
+ {
699
+ var html = this.$editor.html();
700
+
701
+ html = html.replace(/<span id="pastemarkerend">&nbsp;<\/span>/, '#marker#');
702
+
703
+ html = this.formating(html);
704
+ html = this.cleanUp(html);
705
+
706
+ if (this.opts.removeClasses) html = html.replace(/ class="([\w\W]*?)"/gi, '');
707
+ else html = this.cleanUpClasses(html);
708
+
709
+ if (this.opts.removeStyles) html = html.replace(/ style="([\w\W]*?)"/gi, '');
710
+ else html = this.cleanUpStyles(html);
711
+
712
+ html = this.cleanUp(html);
713
+ html = this.formating(html);
714
+
715
+ html = html.replace(/<b(.*?)id="internal-source-marker(.*?)">([\w\W]*?)<\/b>/gi, "$3");
716
+
717
+ html = html.replace(/#marker#/, '<span id="pastemarkerend">&nbsp;</span>');
718
+
719
+ this.$editor.html(html);
720
+
721
+ var node = $(this.doc.body).find('#pastemarkerend').get(0);
722
+ this.setFocusNode(node);
723
+
724
+ this.syncCode();
725
+ this.observeImages();
726
+ },
727
+
728
+ // TEXTAREA CODE FORMATTING
729
+ formating: function (html)
730
+ {
731
+ // lowercase
732
+ if ($.browser.msie)
733
+ {
734
+ html = html.replace(/<*(\/ *)?(\w+)/g, function(w) { return w.toLowerCase(); });
735
+ html = html.replace(/style="(.*?)"/g, function(w) { return w.toLowerCase(); });
736
+ html = html.replace(/ jQuery(.*?)=\"(.*?)\"/gi, '');
737
+ }
738
+
739
+ html = html.replace(/<font([\w\W]*?)color="(.*?)">([\w\W]*?)<\/font\>/gi, '<span style="color: $2;">$3</span>');
740
+ html = html.replace(/<font([\w\W]*?)>([\w\W]*?)<\/font\>/gi, "<span$1>$2</span>");
741
+ html = html.replace(/<span>([\w\W]*?)<\/span>/gi, '$1');
742
+
743
+ // mini clean
744
+ html = html.replace(/ class="Apple-style-span"/gi, '');
745
+ html = html.replace(/ class="Apple-tab-span"/gi, '');
746
+ html = html.replace(/<p><p>/g, '<p>');
747
+ html = html.replace(/<\/p><\/p>/g, '</p>');
748
+ html = html.replace(/<hr(.*?)>/g, '<hr />');
749
+ html = html.replace(/<p>&nbsp;/g, '<p>');
750
+ html = html.replace(/<p><ul>/g, '<ul>');
751
+ html = html.replace(/<p><ol>/g, '<ol>');
752
+ html = html.replace(/<\/ul><\/p>/g, '</ul>');
753
+ html = html.replace(/<\/ol><\/p>/g, '</ol>');
754
+ html = html.replace( /<p(.*?)>&nbsp;<\/p>/gi, '');
755
+
756
+ // remove formatting
757
+ html = html.replace(/[\t]*/g, '');
758
+ html = html.replace(/\n\s*\n/g, "\n");
759
+ html = html.replace(/^[\s\n]*/, '');
760
+ html = html.replace(/[\s\n]*$/, '');
761
+
762
+ // empty tags
763
+ var etags = ["<pre></pre>","<blockquote>\\s*</blockquote>","<em>\\s*</em>","<b>\\s*</b>","<ul></ul>","<ol></ol>","<li></li>","<table></table>","<tr></tr>","<span>\\s*<span>", "<span>&nbsp;<span>", "<p>\\s*</p>", "<p>&nbsp;</p>", "<p>\\s*<br>\\s*</p>", "<div>\\s*</div>", "<div>\\s*<br>\\s*</div>"];
764
+ for (var i = 0; i < etags.length; ++i)
765
+ {
766
+ var bbb = etags[i];
767
+ html = html.replace(new RegExp(bbb,'gi'), "");
768
+ }
769
+
770
+
771
+ // add formatting before
772
+ var lb = '\r\n';
773
+ var btags = ["<form","<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"];
774
+ for (var i = 0; i < btags.length; ++i)
775
+ {
776
+ var eee = btags[i];
777
+ html = html.replace(new RegExp(eee,'gi'),lb+eee);
778
+ }
779
+
780
+ // add formatting after
781
+ var atags = ['</p>', '</div>', '</ul>', '</ol>', '</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>'];
782
+ for (var i = 0; i < atags.length; ++i)
783
+ {
784
+ var aaa = atags[i];
785
+ html = html.replace(new RegExp(aaa,'gi'),aaa+lb);
786
+ }
787
+
788
+ // indenting
789
+ html = html.replace(/<li/g, "\t<li");
790
+ html = html.replace(/<tr/g, "\t<tr");
791
+ html = html.replace(/<td/g, "\t\t<td");
792
+ html = html.replace(/<\/tr>/g, "\t</tr>");
793
+
794
+ return html;
795
+ },
796
+
797
+ // TOGGLE
798
+ toggle: function()
799
+ {
800
+ var html;
801
+
802
+ if (this.opts.visual)
803
+ {
804
+ this.$frame.hide();
805
+
806
+ html = this.$editor.html();
807
+ html = $.trim(this.formating(html));
808
+
809
+ this.$el.val(html).show().focus();
810
+
811
+ this.setBtnActive('html');
812
+ this.opts.visual = false;
813
+ }
814
+ else
815
+ {
816
+ this.$el.hide();
817
+
818
+ this.$editor.html(this.$el.val());
819
+
820
+ this.$frame.show();
821
+
822
+ if (this.$editor.html() === '')
823
+ {
824
+ if (!$.browser.mozilla) html = this.opts.allEmptyHtml;
825
+ else html = this.opts.mozillaEmptyHtml;
826
+
827
+ this.setCode(html);
828
+ }
829
+
830
+ this.focus();
831
+
832
+ this.setBtnInactive('html');
833
+ this.opts.visual = true;
834
+ this.observeImages();
835
+ }
836
+ },
837
+
838
+ // AUTOSAVE
839
+ autoSave: function()
840
+ {
841
+ if (this.opts.autosave === false) return false;
842
+
843
+ setInterval($.proxy(function()
844
+ {
845
+ $.post(this.opts.autosave, { data: this.getCode() });
846
+
847
+ }, this), this.opts.interval*1000);
848
+ },
849
+
850
+ // TOOLBAR
851
+ buildToolbar: function()
852
+ {
853
+ if (this.opts.toolbar === false) return false;
854
+
855
+ this.$toolbar = $('<ul>').addClass('redactor_toolbar');
856
+ this.$box.prepend(this.$toolbar);
857
+
858
+ $.each(RTOOLBAR[this.opts.toolbar], $.proxy(function(key,s)
859
+ {
860
+ if (this.opts.fileUpload === false && key == 'file') return true;
861
+
862
+ var li = $('<li>');
863
+
864
+ if (key == 'fullscreen') $(li).addClass('redactor_toolbar_right');
865
+
866
+ var a = this.buildButton(key, s);
867
+
868
+ // dropdown
869
+ if (key == 'backcolor' || key == 'fontcolor' || typeof(s.dropdown) != 'undefined')
870
+ {
871
+ var dropdown = $('<div class="redactor_dropdown" style="display: none;">');
872
+
873
+ if (key == 'backcolor' || key == 'fontcolor') dropdown = this.buildColorPicker(dropdown, key);
874
+ else dropdown = this.buildDropdown(dropdown, s.dropdown);
875
+
876
+ this.dropdowns.push(dropdown.appendTo($(document.body)));
877
+
878
+ // observing dropdown
879
+ this.hdlHideDropDown = $.proxy(function(e) { this.hideDropDown(e, dropdown, key); }, this);
880
+ this.hdlShowDropDown = $.proxy(function(e) { this.showDropDown(e, dropdown, key); }, this);
881
+
882
+ a.click(this.hdlShowDropDown);
883
+ }
884
+
885
+ this.$toolbar.append($(li).append(a));
886
+ if (typeof(s.separator) != 'undefined') this.$toolbar.append($('<li class="redactor_separator"></li>'));
887
+
888
+ }, this));
889
+
890
+ $(document).click(this.hdlHideDropDown);
891
+ $(this.doc).click(this.hdlHideDropDown);
892
+
893
+ },
894
+ buildButton: function(key, s)
895
+ {
896
+ var button = $('<a href="javascript:void(null);" title="' + s.title + '" class="redactor_btn_' + key + '"><span>&nbsp;</span></a>');
897
+ if (typeof(s.func) == 'undefined') button.click($.proxy(function() { this.execCommand(s.exec, key); }, this));
898
+ else if (s.func != 'show') button.click($.proxy(function(e) { this[s.func](e); }, this));
899
+
900
+ return button;
901
+ },
902
+ buildDropdown: function(dropdown, obj)
903
+ {
904
+ $.each(obj, $.proxy(
905
+ function (x, d)
906
+ {
907
+ if (typeof(d.style) == 'undefined') d.style = '';
908
+
909
+ var drop_a;
910
+ if (d.name == 'separator') drop_a = $('<a class="redactor_separator_drop">');
911
+ else
912
+ {
913
+ drop_a = $('<a href="javascript:void(null);" style="' + d.style + '">' + d.title + '</a>');
914
+
915
+ if (typeof(d.func) == 'undefined') $(drop_a).click($.proxy(function() { this.execCommand(d.exec, x); }, this));
916
+ else $(drop_a).click($.proxy(function(e) { this[d.func](e); }, this));
917
+ }
918
+
919
+ $(dropdown).append(drop_a);
920
+
921
+ }, this)
922
+ );
923
+
924
+ return dropdown;
925
+
926
+ },
927
+ buildColorPicker: function(dropdown, key)
928
+ {
929
+ var mode;
930
+ if (key == 'backcolor')
931
+ {
932
+ if ($.browser.msie) mode = 'BackColor';
933
+ else mode = 'hilitecolor';
934
+ }
935
+ else mode = 'forecolor';
936
+
937
+ $(dropdown).width(210);
938
+
939
+ var len = this.opts.colors.length;
940
+ for (var i = 0; i < len; ++i)
941
+ {
942
+ var color = this.opts.colors[i];
943
+
944
+ var swatch = $('<a rel="' + color + '" href="javascript:void(null);" class="redactor_color_link"></a>').css({ 'backgroundColor': color });
945
+ $(dropdown).append(swatch);
946
+
947
+ var _self = this;
948
+ $(swatch).click(function() { _self.execCommand(mode, $(this).attr('rel')); });
949
+ }
950
+
951
+ var elnone = $('<a href="javascript:void(null);" class="redactor_color_none"></a>').html(RLANG.none);
952
+
953
+ if (key == 'backcolor') elnone.click($.proxy(this.setBackgroundNone, this));
954
+ else elnone.click($.proxy(this.setColorNone, this));
955
+
956
+ $(dropdown).append(elnone);
957
+
958
+ return dropdown;
959
+ },
960
+ setBackgroundNone: function()
961
+ {
962
+ $(this.getParentNode()).css('background-color', 'transparent');
963
+ this.syncCode();
964
+ },
965
+ setColorNone: function()
966
+ {
967
+ $(this.getParentNode()).attr('color', '').css('color', '');
968
+ this.syncCode();
969
+ },
970
+
971
+ // DROPDOWNS
972
+ showDropDown: function(e, dropdown, key)
973
+ {
974
+ this.hideAllDropDown();
975
+
976
+ this.setBtnActive(key);
977
+ this.getBtn(key).addClass('dropact');
978
+
979
+ var left = this.getBtn(key).offset().left;
980
+
981
+
982
+ if (this.opts.fixed && this.fixed)
983
+ {
984
+ $(dropdown).css({ position: 'fixed', left: left + 'px', top: '30px' }).show();
985
+ }
986
+ else
987
+ {
988
+ var top = this.$toolbar.offset().top + 30;
989
+ $(dropdown).css({ position: 'absolute', left: left + 'px', top: top + 'px' }).show();
990
+ }
991
+
992
+ },
993
+ hideAllDropDown: function()
994
+ {
995
+ this.$toolbar.find('a.dropact').removeClass('act').removeClass('dropact');
996
+ $('.redactor_dropdown').hide();
997
+ },
998
+ hideDropDown: function(e, dropdown, key)
999
+ {
1000
+ if (!$(e.target).parent().hasClass('dropact'))
1001
+ {
1002
+ $(dropdown).removeClass('act');
1003
+ this.showedDropDown = false;
1004
+ this.hideAllDropDown();
1005
+ }
1006
+ },
1007
+
1008
+ // SELECTION AND NODE MANIPULATION
1009
+ getSelection: function ()
1010
+ {
1011
+ if (this.$frame.get(0).contentWindow.getSelection) return this.$frame.get(0).contentWindow.getSelection();
1012
+ else if (this.$frame.get(0).contentWindow.document.selection) return this.$frame.get(0).contentWindow.document.selection.createRange();
1013
+ },
1014
+ getParentNode: function()
1015
+ {
1016
+ if (window.getSelection) return this.getSelection().getRangeAt(0).startContainer.parentNode;
1017
+ else if (document.selection) return this.getSelection().parentElement();
1018
+ },
1019
+ getCurrentNode: function()
1020
+ {
1021
+ if (window.getSelection) return this.getSelection().getRangeAt(0).startContainer;
1022
+ else if (document.selection) return this.getSelection();
1023
+ },
1024
+ setFocusNode: function(node, toStart)
1025
+ {
1026
+ var range = this.doc.createRange();
1027
+
1028
+ var selection = this.getSelection();
1029
+ toStart = toStart ? 0 : 1;
1030
+
1031
+ if (selection !== null)
1032
+ {
1033
+ range.selectNodeContents(node);
1034
+ selection.addRange(range);
1035
+ selection.collapse(node, toStart);
1036
+ }
1037
+
1038
+ this.focus();
1039
+ },
1040
+ insertNodeAtCaret: function (node)
1041
+ {
1042
+ if (typeof window.getSelection != "undefined")
1043
+ {
1044
+ var sel = this.getSelection();
1045
+ if (sel.rangeCount)
1046
+ {
1047
+ var range = sel.getRangeAt(0);
1048
+ range.collapse(false);
1049
+ range.insertNode(node);
1050
+ range = range.cloneRange();
1051
+ range.selectNodeContents(node);
1052
+ range.collapse(false);
1053
+ sel.removeAllRanges();
1054
+ sel.addRange(range);
1055
+ }
1056
+ }
1057
+ else if (typeof document.selection != "undefined" && document.selection.type != "Control")
1058
+ {
1059
+ var html = (node.nodeType == 1) ? node.outerHTML : node.data;
1060
+ var id = "marker_" + ("" + Math.random()).slice(2);
1061
+ html += '<span id="' + id + '"></span>';
1062
+ var textRange = this.getSelection();
1063
+ textRange.collapse(false);
1064
+ textRange.pasteHTML(html);
1065
+ var markerSpan = document.getElementById(id);
1066
+ textRange.moveToElementText(markerSpan);
1067
+ textRange.select();
1068
+ markerSpan.parentNode.removeChild(markerSpan);
1069
+ }
1070
+ },
1071
+
1072
+ // BUTTONS MANIPULATIONS
1073
+ getBtn: function(key)
1074
+ {
1075
+ return $(this.$toolbar.find('a.redactor_btn_' + key));
1076
+ },
1077
+ setBtnActive: function(key)
1078
+ {
1079
+ this.getBtn(key).addClass('act');
1080
+ },
1081
+ setBtnInactive: function(key)
1082
+ {
1083
+ this.getBtn(key).removeClass('act');
1084
+ },
1085
+ changeBtnIcon: function(key, classname)
1086
+ {
1087
+ this.getBtn(key).addClass('redactor_btn_' + classname);
1088
+ },
1089
+ removeBtnIcon: function(key, classname)
1090
+ {
1091
+ this.getBtn(key).removeClass('redactor_btn_' + classname);
1092
+ },
1093
+ removeBtn: function(key)
1094
+ {
1095
+ this.getBtn(key).remove();
1096
+ },
1097
+ addBtn: function(key, obj)
1098
+ {
1099
+ this.$toolbar.append($('<li>').append(this.buildButton(key, obj)));
1100
+ },
1101
+
1102
+ // FULLSCREEN
1103
+ fullscreen: function()
1104
+ {
1105
+ var html;
1106
+
1107
+ if (this.opts.fullscreen === false)
1108
+ {
1109
+ this.changeBtnIcon('fullscreen', 'normalscreen');
1110
+ this.setBtnActive('fullscreen');
1111
+ this.opts.fullscreen = true;
1112
+
1113
+ this.height = this.$frame.css('height');
1114
+ this.width = (this.$box.width() - 2) + 'px';
1115
+
1116
+ html = this.getCode();
1117
+
1118
+ this.tmpspan = $('<span></span>');
1119
+ this.$box.addClass('redactor_box_fullscreen').after(this.tmpspan);
1120
+
1121
+ $(document.body).prepend(this.$box).css('overflow', 'hidden');
1122
+
1123
+ this.$editor = this.enable(html);
1124
+
1125
+ $(this.doc).click($.proxy(this.hideAllDropDown, this));
1126
+ // focus always on page
1127
+ $(this.doc).click($.proxy(function(e) { this.$editor.focus(); }, this));
1128
+
1129
+ this.observeImages();
1130
+ this.$box.find('.redactor_resizer').hide();
1131
+
1132
+ this.fullScreenResize();
1133
+ $(window).resize($.proxy(this.fullScreenResize, this));
1134
+ $(document).scrollTop(0,0);
1135
+ this.focus();
1136
+
1137
+ }
1138
+ else
1139
+ {
1140
+ this.removeBtnIcon('fullscreen', 'normalscreen');
1141
+ this.setBtnInactive('fullscreen');
1142
+ this.opts.fullscreen = false;
1143
+
1144
+ $(window).unbind('resize', $.proxy(this.fullScreenResize, this));
1145
+ $(document.body).css('overflow', '');
1146
+
1147
+ html = this.getCode();
1148
+
1149
+ this.$box.removeClass('redactor_box_fullscreen').css('width', 'auto');
1150
+
1151
+ this.tmpspan.after(this.$box).remove();
1152
+
1153
+ this.$editor = this.enable(html);
1154
+
1155
+ this.observeImages();
1156
+ this.observeAutoResize();
1157
+ this.$box.find('.redactor_resizer').show();
1158
+
1159
+ $(this.doc).click($.proxy(this.hideAllDropDown, this));
1160
+ // focus always on page
1161
+ $(this.doc).click($.proxy(function(e) { this.$editor.focus(); }, this));
1162
+
1163
+ this.syncCode();
1164
+
1165
+ this.$frame.css('height', this.height);
1166
+ this.$el.css('height', this.height);
1167
+ this.focus();
1168
+ }
1169
+ },
1170
+ fullScreenResize: function()
1171
+ {
1172
+ if (this.opts.fullscreen === false) return;
1173
+
1174
+ var hfix = 42;
1175
+ if (this.opts.air) hfix = 2;
1176
+
1177
+ var height = $(window).height() - hfix;
1178
+
1179
+ this.$box.width($(window).width() - 2);
1180
+ this.$frame.height(height);
1181
+ this.$el.height(height);
1182
+ },
1183
+
1184
+ // RESIZE
1185
+ buildResizer: function()
1186
+ {
1187
+ if (this.opts.resize === false) return false;
1188
+
1189
+ this.$resizer = $('<div class="redactor_resizer">&mdash;</div>');
1190
+ this.$box.append(this.$resizer);
1191
+
1192
+ this.$resizer.mousedown($.proxy(this.initResize, this));
1193
+
1194
+ },
1195
+ initResize: function(e)
1196
+ {
1197
+ if (e.preventDefault) e.preventDefault();
1198
+
1199
+ this.splitter = e.target;
1200
+
1201
+ if (this.opts.visual)
1202
+ {
1203
+ this.element_resize = this.$frame;
1204
+ this.element_resize.get(0).style.visibility = 'hidden';
1205
+ this.element_resize_parent = this.$el;
1206
+ }
1207
+ else
1208
+ {
1209
+ this.element_resize = this.$el;
1210
+ this.element_resize_parent = this.$frame;
1211
+ }
1212
+
1213
+ this.stopResizeHdl = $.proxy(this.stopResize, this);
1214
+ this.startResizeHdl = $.proxy(this.startResize, this);
1215
+ this.resizeHdl = $.proxy(this.resize, this);
1216
+
1217
+ $(document).mousedown(this.startResizeHdl);
1218
+ $(document).mouseup(this.stopResizeHdl);
1219
+ $(this.splitter).mouseup(this.stopResizeHdl);
1220
+
1221
+ this.null_point = false;
1222
+ this.h_new = false;
1223
+ this.h = this.element_resize.height();
1224
+ },
1225
+ startResize: function()
1226
+ {
1227
+ $(document).mousemove(this.resizeHdl);
1228
+ },
1229
+ resize: function(e)
1230
+ {
1231
+ if (e.preventDefault) e.preventDefault();
1232
+
1233
+ var y = e.pageY;
1234
+ if (this.null_point === false) this.null_point = y;
1235
+ if (this.h_new === false) this.h_new = this.element_resize.height();
1236
+
1237
+ var s_new = (this.h_new + y - this.null_point) - 10;
1238
+
1239
+ if (s_new <= 30) return true;
1240
+
1241
+ if (s_new >= 0)
1242
+ {
1243
+ this.element_resize.get(0).style.height = s_new + 'px';
1244
+ this.element_resize_parent.get(0).style.height = s_new + 'px';
1245
+ }
1246
+ },
1247
+ stopResize: function(e)
1248
+ {
1249
+ $(document).unbind('mousemove', this.resizeHdl);
1250
+ $(document).unbind('mousedown', this.startResizeHdl);
1251
+ $(document).unbind('mouseup', this.stopResizeHdl);
1252
+ $(this.splitter).unbind('mouseup', this.stopResizeHdl);
1253
+
1254
+ this.element_resize.get(0).style.visibility = 'visible';
1255
+ },
1256
+
1257
+ // RESIZE IMAGES
1258
+ resizeImage: function(resize)
1259
+ {
1260
+ var clicked = false;
1261
+ var clicker = false;
1262
+ var start_x;
1263
+ var start_y;
1264
+ var ratio = $(resize).width()/$(resize).height();
1265
+
1266
+ var y = 1;
1267
+ var x = 1;
1268
+ var min_w = 1;
1269
+ var min_h = 1;
1270
+
1271
+ $(resize).hover(function(){$(resize).css('cursor', 'nw-resize');}, function(){$(resize).css('cursor','default');clicked=false;});
1272
+
1273
+ $(resize).mousedown(function(e)
1274
+ {
1275
+ if (e.preventDefault) e.preventDefault();
1276
+
1277
+ clicked = true;
1278
+ clicker = true;
1279
+
1280
+ start_x = Math.round(e.pageX - $(resize).eq(0).offset().left);
1281
+ start_y = Math.round(e.pageY - $(resize).eq(0).offset().top);
1282
+ });
1283
+
1284
+ $(resize).mouseup($.proxy(function(e)
1285
+ {
1286
+ clicked = false;
1287
+ this.syncCode();
1288
+ }, this));
1289
+
1290
+ $(resize).click($.proxy(function(e)
1291
+ {
1292
+ if (clicker) this.imageEdit(e);
1293
+
1294
+ }, this));
1295
+
1296
+ $(resize).mousemove(function(e)
1297
+ {
1298
+ if (clicked)
1299
+ {
1300
+ clicker = false;
1301
+
1302
+ var mouse_x = Math.round(e.pageX - $(this).eq(0).offset().left) - start_x;
1303
+ var mouse_y = Math.round(e.pageY - $(this).eq(0).offset().top) - start_y;
1304
+
1305
+ var div_h = $(resize).height();
1306
+
1307
+ var new_h = parseInt(div_h)+mouse_y;
1308
+ var new_w = new_h*ratio;
1309
+
1310
+
1311
+
1312
+ if(x==1 || (typeof(x) == "number" && new_w < x && new_w > min_w) ){ $(resize).width(new_w); }
1313
+ if(y==1 || (typeof(y) == "number" && new_h < y && new_h > min_h) ){ $(resize).height(new_h); }
1314
+ start_x = Math.round(e.pageX - $(this).eq(0).offset().left);
1315
+ start_y = Math.round(e.pageY - $(this).eq(0).offset().top);
1316
+ }
1317
+ });
1318
+ },
1319
+
1320
+ // TABLE
1321
+ showTable: function()
1322
+ {
1323
+ this.modalInit(RLANG.table, this.opts.path + '/plugins/table.html', 300, $.proxy(function()
1324
+ {
1325
+ $('#redactor_table_rows').focus();
1326
+ $('#redactor_insert_table_btn').click($.proxy(this.insertTable, this));
1327
+
1328
+ }, this));
1329
+ },
1330
+ insertTable: function()
1331
+ {
1332
+ var rows = $('#redactor_table_rows').val();
1333
+ var columns = $('#redactor_table_columns').val();
1334
+
1335
+ var table_box = $('<div></div>');
1336
+
1337
+ var tableid = Math.floor(Math.random() * 99999);
1338
+ var table = $('<table id="table' + tableid + '"><tbody></tbody></table>');
1339
+
1340
+ for (var i = 0; i < rows; i++)
1341
+ {
1342
+ var row = $('<tr></tr>');
1343
+ for (var z = 0; z < columns; z++)
1344
+ {
1345
+ var column = $('<td>&nbsp;</td>');
1346
+ $(row).append(column);
1347
+ }
1348
+ $(table).append(row);
1349
+ }
1350
+
1351
+ $(table_box).append(table);
1352
+ var html = $(table_box).html();
1353
+
1354
+ if ($.browser.msie) html += '<p></p>';
1355
+ else html += '<p>&nbsp;</p>';
1356
+
1357
+ this.execCommand('inserthtml', html);
1358
+ this.modalClose();
1359
+
1360
+ this.$table = $(this.doc).find('body').find('#table' + tableid);
1361
+ this.$table.click($.proxy(this.tableObserver, this));
1362
+ },
1363
+ tableObserver: function(e)
1364
+ {
1365
+ this.$table = $(e.target).parents('table');
1366
+
1367
+ this.$table_tr = this.$table.find('tr');
1368
+ this.$table_td = this.$table.find('td');
1369
+
1370
+ this.$table_td.removeClass('current');
1371
+
1372
+ this.$tbody = $(e.target).parents('tbody');
1373
+ this.$thead = $(this.$table).find('thead');
1374
+
1375
+ this.$current_td = $(e.target);
1376
+ this.$current_td.addClass('current');
1377
+
1378
+ this.$current_tr = $(e.target).parents('tr');
1379
+ },
1380
+ deleteTable: function()
1381
+ {
1382
+ $(this.$table).remove();
1383
+ this.$table = false;
1384
+ this.syncCode();
1385
+ },
1386
+ deleteRow: function()
1387
+ {
1388
+ $(this.$current_tr).remove();
1389
+ this.syncCode();
1390
+ },
1391
+ deleteColumn: function()
1392
+ {
1393
+ var index = $(this.$current_td).get(0).cellIndex;
1394
+
1395
+ $(this.$table).find('tr').each(function()
1396
+ {
1397
+ $(this).find('td').eq(index).remove();
1398
+ });
1399
+
1400
+ this.syncCode();
1401
+ },
1402
+ addHead: function()
1403
+ {
1404
+ if ($(this.$table).find('thead').size() !== 0) this.deleteHead();
1405
+ else
1406
+ {
1407
+ var tr = $(this.$table).find('tr').first().clone();
1408
+ tr.find('td').html('&nbsp;');
1409
+ this.$thead = $('<thead></thead>');
1410
+ this.$thead.append(tr);
1411
+ $(this.$table).prepend(this.$thead);
1412
+ this.syncCode();
1413
+ }
1414
+ },
1415
+ deleteHead: function()
1416
+ {
1417
+ $(this.$thead).remove();
1418
+ this.$thead = false;
1419
+ this.syncCode();
1420
+ },
1421
+ insertRowAbove: function()
1422
+ {
1423
+ this.insertRow('before');
1424
+ },
1425
+ insertRowBelow: function()
1426
+ {
1427
+ this.insertRow('after');
1428
+ },
1429
+ insertColumnLeft: function()
1430
+ {
1431
+ this.insertColumn('before');
1432
+ },
1433
+ insertColumnRight: function()
1434
+ {
1435
+ this.insertColumn('after');
1436
+ },
1437
+ insertRow: function(type)
1438
+ {
1439
+ var new_tr = $(this.$current_tr).clone();
1440
+ new_tr.find('td').html('&nbsp;');
1441
+ if (type == 'after') $(this.$current_tr).after(new_tr);
1442
+ else $(this.$current_tr).before(new_tr);
1443
+
1444
+ this.syncCode();
1445
+ },
1446
+ insertColumn: function(type)
1447
+ {
1448
+ var index = 0;
1449
+
1450
+ this.$current_td.addClass('current');
1451
+
1452
+ this.$current_tr.find('td').each(function(i,s)
1453
+ {
1454
+ if ($(s).hasClass('current')) index = i;
1455
+ });
1456
+
1457
+ this.$table_tr.each(function(i,s)
1458
+ {
1459
+ var current = $(s).find('td').eq(index);
1460
+
1461
+ var td = current.clone();
1462
+ td.html('&nbsp;');
1463
+
1464
+ if (type == 'after') $(current).after(td);
1465
+ else $(current).before(td);
1466
+
1467
+ });
1468
+
1469
+ this.syncCode();
1470
+ },
1471
+
1472
+ // INSERT VIDEO
1473
+ showVideo: function()
1474
+ {
1475
+ if ($.browser.msie) this.markerIE();
1476
+
1477
+ this.modalInit(RLANG.video, this.opts.path + '/plugins/video.html', 600, $.proxy(function()
1478
+ {
1479
+ $('#redactor_insert_video_area').focus();
1480
+ $('#redactor_insert_video_btn').click($.proxy(this.insertVideo, this));
1481
+
1482
+ }, this));
1483
+ },
1484
+ insertVideo: function()
1485
+ {
1486
+ var data = $('#redactor_insert_video_area').val();
1487
+
1488
+ if ($.browser.msie)
1489
+ {
1490
+ $(this.doc.getElementById('span' + this.spanid)).after(data).remove();
1491
+ this.syncCode();
1492
+ }
1493
+ else this.execCommand('inserthtml', data);
1494
+
1495
+ this.modalClose();
1496
+ },
1497
+
1498
+ // INSERT IMAGE
1499
+ imageEdit: function(e)
1500
+ {
1501
+ var $el = $(e.target);
1502
+ var parent = $el.parent();
1503
+
1504
+ var handler = $.proxy(function()
1505
+ {
1506
+ $('#redactor_file_alt').val($el.attr('alt'));
1507
+ $('#redactor_image_edit_src').attr('href', $el.attr('src'));
1508
+ $('#redactor_form_image_align').val($el.css('float'));
1509
+
1510
+ if ($(parent).get(0).tagName == 'A') $('#redactor_file_link').val($(parent).attr('href'));
1511
+
1512
+ $('#redactor_image_delete_btn').click($.proxy(function() { this.imageDelete($el); }, this));
1513
+ $('#redactorSaveBtn').click($.proxy(function() { this.imageSave($el); }, this));
1514
+
1515
+ }, this);
1516
+
1517
+ this.modalInit(RLANG.image, this.opts.path + '/plugins/image_edit.html', 380, handler);
1518
+
1519
+ },
1520
+ imageDelete: function(el)
1521
+ {
1522
+ $(el).remove();
1523
+ this.modalClose();
1524
+ this.syncCode();
1525
+ },
1526
+ imageSave: function(el)
1527
+ {
1528
+ var parent = $(el).parent();
1529
+
1530
+ $(el).attr('alt', $('#redactor_file_alt').val());
1531
+
1532
+ var floating = $('#redactor_form_image_align').val();
1533
+
1534
+ if (floating == 'left') $(el).css({ 'float': 'left', margin: '0 10px 10px 0' });
1535
+ else if (floating == 'right') $(el).css({ 'float': 'right', margin: '0 0 10px 10px' });
1536
+ else $(el).css({ 'float': 'none', margin: '0' });
1537
+
1538
+ // as link
1539
+ var link = $.trim($('#redactor_file_link').val());
1540
+ if (link !== '')
1541
+ {
1542
+ if ($(parent).get(0).tagName != 'A')
1543
+ {
1544
+ $(el).replaceWith('<a href="' + link + '">' + this.outerHTML(el) + '</a>');
1545
+ }
1546
+ else
1547
+ {
1548
+ $(parent).attr('href', link);
1549
+ }
1550
+ }
1551
+
1552
+ this.modalClose();
1553
+ this.observeImages();
1554
+ this.syncCode();
1555
+
1556
+ },
1557
+ showImage: function()
1558
+ {
1559
+ if ($.browser.msie) this.markerIE();
1560
+
1561
+ var handler = $.proxy(function()
1562
+ {
1563
+ // json
1564
+ if (this.opts.imageGetJson !== false)
1565
+ {
1566
+ $.getJSON(this.opts.imageGetJson, $.proxy(function(data) {
1567
+
1568
+ $.each(data, $.proxy(function(key, val)
1569
+ {
1570
+ var img = $('<img src="' + val.thumb + '" rel="' + val.image + '" />');
1571
+ $('#redactor_image_box').append(img);
1572
+ $(img).click($.proxy(this.imageSetThumb, this));
1573
+
1574
+ }, this));
1575
+
1576
+ }, this));
1577
+ }
1578
+ else
1579
+ {
1580
+ $('#redactor_tabs a').eq(1).remove();
1581
+ }
1582
+
1583
+ if (this.opts.imageUpload !== false)
1584
+ {
1585
+ // dragupload
1586
+ if ($('#redactor_file').size() !== 0)
1587
+ {
1588
+ $('#redactor_file').dragupload(
1589
+ {
1590
+ url: this.opts.imageUpload,
1591
+ success: $.proxy(this.imageUploadCallback, this)
1592
+ });
1593
+ }
1594
+
1595
+ // ajax upload
1596
+ this.uploadInit('redactor_file', { auto: true, url: this.opts.imageUpload, success: $.proxy(this.imageUploadCallback, this) });
1597
+ }
1598
+ else
1599
+ {
1600
+ $('.redactor_tab').hide();
1601
+ if (this.opts.imageGetJson === false)
1602
+ {
1603
+ $('#redactor_tabs').remove();
1604
+ $('#redactor_tab3').show();
1605
+ }
1606
+ else
1607
+ {
1608
+ var tabs = $('#redactor_tabs a');
1609
+ tabs.eq(0).remove();
1610
+ tabs.eq(1).addClass('redactor_tabs_act');
1611
+ $('#redactor_tab2').show();
1612
+ }
1613
+ }
1614
+
1615
+ $('#redactor_upload_btn').click($.proxy(this.imageUploadCallbackLink, this));
1616
+
1617
+ }, this);
1618
+
1619
+ this.modalInit(RLANG.image, this.opts.path + '/plugins/image.html', 570, handler, true);
1620
+
1621
+ },
1622
+ imageSetThumb: function(e)
1623
+ {
1624
+ this._imageSet('<img alt="" src="' + $(e.target).attr('rel') + '" />');
1625
+ },
1626
+ imageUploadCallbackLink: function()
1627
+ {
1628
+ if ($('#redactor_file_link').val() !== '')
1629
+ {
1630
+ var data = '<img src="' + $('#redactor_file_link').val() + '" />';
1631
+
1632
+ this._imageSet(data);
1633
+ }
1634
+ else this.modalClose();
1635
+ },
1636
+ imageUploadCallback: function(data)
1637
+ {
1638
+ this._imageSet(data);
1639
+ },
1640
+ _imageSet: function(html)
1641
+ {
1642
+ html = '<p>' + html + '</p>';
1643
+
1644
+ this.focus();
1645
+
1646
+ if ($.browser.msie)
1647
+ {
1648
+ $(this.doc.getElementById('span' + this.spanid)).after(html).remove();
1649
+ this.syncCode();
1650
+ }
1651
+ else
1652
+ {
1653
+ this.execCommand('inserthtml', html);
1654
+ }
1655
+
1656
+ this.modalClose();
1657
+ this.observeImages();
1658
+ },
1659
+
1660
+ // INSERT LINK
1661
+ showLink: function()
1662
+ {
1663
+ var handler = $.proxy(function()
1664
+ {
1665
+ var sel = this.getSelection();
1666
+
1667
+ if ($.browser.msie)
1668
+ {
1669
+ var parent = this.getParentNode();
1670
+ if (parent.nodeName == 'A')
1671
+ {
1672
+ this.insert_link_node = $(parent);
1673
+ var text = this.insert_link_node.text();
1674
+ var url = this.insert_link_node.attr('href');
1675
+ }
1676
+ else
1677
+ {
1678
+ if (this.oldIE()) var text = sel.text;
1679
+ else var text = sel.toString();
1680
+
1681
+ var url = '';
1682
+
1683
+ this.spanid = Math.floor(Math.random() * 99999);
1684
+
1685
+ var html = '<span id="span' + this.spanid + '">' + text + '</span>';
1686
+ if (text != '') html = '<span id="span' + this.spanid + '">' + text + '</span>';
1687
+ this.execCommand('inserthtml', html);
1688
+ }
1689
+ }
1690
+ else
1691
+ {
1692
+ if (sel && sel.anchorNode.parentNode.tagName == 'A')
1693
+ {
1694
+ var url = sel.anchorNode.parentNode.href;
1695
+ var text = sel.anchorNode.parentNode.text;
1696
+ if (sel.toString() === '') this.insert_link_node = sel.anchorNode.parentNode;
1697
+ }
1698
+ else
1699
+ {
1700
+ var text = sel.toString();
1701
+ var url = '';
1702
+ }
1703
+ }
1704
+
1705
+ $('.redactor_link_text').val(text);
1706
+ $('#redactor_link_url').val(url).focus();
1707
+
1708
+ $('#redactor_insert_link_btn').click($.proxy(this.insertLink, this));
1709
+
1710
+ if (this.opts.linkFileUpload === false)
1711
+ {
1712
+ $('#redactor_tabs a').eq(3).remove();
1713
+ }
1714
+ else
1715
+ {
1716
+ // dragupload
1717
+ if ($('#redactor_file').size() != 0)
1718
+ {
1719
+ $('#redactor_file').dragupload(
1720
+ {
1721
+ url: this.opts.linkFileUpload,
1722
+ success: $.proxy(this.insertLinkFile, this)
1723
+ });
1724
+ }
1725
+
1726
+ // ajax upload
1727
+ this.uploadInit('redactor_file', { auto: true, url: this.opts.linkFileUpload, success: $.proxy(this.insertLinkFile, this) });
1728
+ }
1729
+
1730
+ }, this);
1731
+
1732
+ this.modalInit(RLANG.link, this.opts.path + '/plugins/link.html', 460, handler);
1733
+
1734
+ },
1735
+ insertLink: function()
1736
+ {
1737
+ var tab_selected = $('#redactor_tab_selected').val();
1738
+
1739
+ var link = '', text = '';
1740
+
1741
+ if (tab_selected == 1) // url
1742
+ {
1743
+ link = $('#redactor_link_url').val();
1744
+ text = $('#redactor_link_url_text').val();
1745
+ }
1746
+ else if (tab_selected == 2) // mailto
1747
+ {
1748
+ link = 'mailto:' + $('#redactor_link_mailto').val();
1749
+ text = $('#redactor_link_mailto_text').val();
1750
+ }
1751
+ else if (tab_selected == 3) // anchor
1752
+ {
1753
+ link = '#' + $('#redactor_link_anchor').val();
1754
+ text = $('#redactor_link_anchor_text').val();
1755
+ }
1756
+
1757
+ this._insertLink('<a href="' + link + '">' + text + '</a> ', $.trim(text), link);
1758
+
1759
+ },
1760
+ insertLinkFile: function(data)
1761
+ {
1762
+ text = $('#redactor_link_file_text').val();
1763
+
1764
+ this._insertLink('<a href="' + data + '">' + text + '</a> ', $.trim(text), data);
1765
+ },
1766
+ _insertLink: function(a, text, link)
1767
+ {
1768
+ if (text != '')
1769
+ {
1770
+ if (this.insert_link_node)
1771
+ {
1772
+ $(this.insert_link_node).text(text);
1773
+ $(this.insert_link_node).attr('href', link);
1774
+ this.syncCode();
1775
+ }
1776
+ else
1777
+ {
1778
+ if ($.browser.msie)
1779
+ {
1780
+ $(this.doc.getElementById('span' + this.spanid)).replaceWith(a);
1781
+ this.syncCode();
1782
+ }
1783
+ else this.execCommand('inserthtml', a);
1784
+ }
1785
+ }
1786
+
1787
+ this.modalClose();
1788
+ },
1789
+
1790
+ // INSERT FILE
1791
+ showFile: function()
1792
+ {
1793
+ if ($.browser.msie) this.markerIE();
1794
+
1795
+ var handler = $.proxy(function()
1796
+ {
1797
+ $('#redactor_file').dragupload(
1798
+ {
1799
+ url: this.opts.fileUpload,
1800
+ success: $.proxy(function(data)
1801
+ {
1802
+ this.fileUploadCallback(data);
1803
+ }, this)
1804
+ });
1805
+
1806
+ this.uploadInit('redactor_file', { auto: true, url: this.opts.fileUpload, success: $.proxy(function(data) {
1807
+
1808
+ this.fileUploadCallback(data);
1809
+
1810
+ }, this)});
1811
+ }, this);
1812
+
1813
+ this.modalInit(RLANG.file, this.opts.path + '/plugins/file.html', 500, handler);
1814
+ },
1815
+ fileUploadCallback: function(data)
1816
+ {
1817
+ // chrome fix
1818
+ if ($.browser.webkit && !!window.chrome) data = data + '&nbsp;';
1819
+
1820
+ if ($.browser.msie)
1821
+ {
1822
+ $(this.doc.getElementById('span' + this.spanid)).after(data).remove();
1823
+ this.syncCode();
1824
+ }
1825
+ else this.execCommand('inserthtml', data);
1826
+
1827
+ this.modalClose();
1828
+ },
1829
+
1830
+
1831
+
1832
+ // MODAL
1833
+ modalInit: function(title, url, width, handler, scroll)
1834
+ {
1835
+ // modal overlay
1836
+ if ($('#redactor_modal_overlay').size() == 0)
1837
+ {
1838
+ this.overlay = $('<div id="redactor_modal_overlay" style="display: none;"></div>');
1839
+ $('body').prepend(this.overlay);
1840
+ }
1841
+
1842
+ if (this.opts.overlay)
1843
+ {
1844
+ $('#redactor_modal_overlay').show();
1845
+ $('#redactor_modal_overlay').click($.proxy(this.modalClose, this));
1846
+ }
1847
+
1848
+ if ($('#redactor_modal').size() == 0)
1849
+ {
1850
+ 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>');
1851
+ $('body').append(this.modal);
1852
+ }
1853
+
1854
+ $('#redactor_modal_close').click($.proxy(this.modalClose, this));
1855
+
1856
+ this.hdlModalClose = $.proxy(function(e) { if( e.keyCode == 27) this.modalClose(); }, this);
1857
+
1858
+ $(document).keyup(this.hdlModalClose);
1859
+ $(this.doc).keyup(this.hdlModalClose);
1860
+
1861
+ $.ajax({
1862
+ dataType: 'html',
1863
+ type: 'get',
1864
+ url: url,
1865
+ success: $.proxy(function(data)
1866
+ {
1867
+ // parse lang
1868
+ $.each(RLANG, function(i,s)
1869
+ {
1870
+ var re = new RegExp("%RLANG\." + i + "%","gi");
1871
+ data = data.replace(re, s);
1872
+ });
1873
+
1874
+ $('#redactor_modal_inner').html(data);
1875
+ $('#redactor_modal_header').html(title);
1876
+
1877
+ // tabs
1878
+ if ($('#redactor_tabs').size() != 0)
1879
+ {
1880
+ $('#redactor_tabs a').each(function(i,s)
1881
+ {
1882
+ i++;
1883
+ $(s).click(function()
1884
+ {
1885
+ $('#redactor_tabs a').removeClass('redactor_tabs_act');
1886
+ $(this).addClass('redactor_tabs_act');
1887
+ $('.redactor_tab').hide();
1888
+ $('#redactor_tab' + i).show();
1889
+ $('#redactor_tab_selected').val(i);
1890
+
1891
+ var height = $('#redactor_modal').outerHeight();
1892
+ $('#redactor_modal').css('margin-top', '-' + (height+10)/2 + 'px');
1893
+ });
1894
+ });
1895
+ }
1896
+
1897
+ $('#redactor_btn_modal_close').click($.proxy(this.modalClose, this));
1898
+
1899
+ // callback
1900
+ if (typeof(handler) == 'function') handler();
1901
+
1902
+ // setup
1903
+ var height = $('#redactor_modal').outerHeight();
1904
+
1905
+ $('#redactor_modal').css({ width: width + 'px', height: 'auto', marginTop: '-' + (height+10)/2 + 'px', marginLeft: '-' + (width+60)/2 + 'px' }).fadeIn('fast');
1906
+
1907
+ if (scroll === true)
1908
+ {
1909
+ $('#redactor_image_box').height(300).css('overflow', 'auto');
1910
+ }
1911
+
1912
+ }, this)
1913
+ });
1914
+ },
1915
+ modalClose: function()
1916
+ {
1917
+
1918
+ $('#redactor_modal_close').unbind('click', this.modalClose);
1919
+ $('#redactor_modal').fadeOut('fast', $.proxy(function()
1920
+ {
1921
+ $('#redactor_modal_inner').html('');
1922
+
1923
+ if (this.opts.overlay)
1924
+ {
1925
+ $('#redactor_modal_overlay').hide();
1926
+ $('#redactor_modal_overlay').unbind('click', this.modalClose);
1927
+ }
1928
+
1929
+ $(document).unbind('keyup', this.hdlModalClose);
1930
+ $(this.doc).unbind('keyup', this.hdlModalClose);
1931
+
1932
+ }, this));
1933
+
1934
+ },
1935
+
1936
+ // UPLOAD
1937
+ uploadInit: function(element, options)
1938
+ {
1939
+ // Upload Options
1940
+ this.uploadOptions = {
1941
+ url: false,
1942
+ success: false,
1943
+ start: false,
1944
+ trigger: false,
1945
+ auto: false,
1946
+ input: false
1947
+ };
1948
+
1949
+ $.extend(this.uploadOptions, options);
1950
+
1951
+ // Test input or form
1952
+ if ($('#' + element).size() != 0 && $('#' + element).get(0).tagName == 'INPUT')
1953
+ {
1954
+ this.uploadOptions.input = $('#' + element);
1955
+ this.element = $($('#' + element).get(0).form);
1956
+ }
1957
+ else
1958
+ {
1959
+ this.element = $('#' + element);
1960
+ }
1961
+
1962
+ this.element_action = this.element.attr('action');
1963
+
1964
+ // Auto or trigger
1965
+ if (this.uploadOptions.auto)
1966
+ {
1967
+ $(this.uploadOptions.input).change($.proxy(function()
1968
+ {
1969
+ this.element.submit(function(e) { return false; });
1970
+ this.uploadSubmit();
1971
+ }, this));
1972
+
1973
+ }
1974
+ else if (this.uploadOptions.trigger)
1975
+ {
1976
+ $('#' + this.uploadOptions.trigger).click($.proxy(this.uploadSubmit, this));
1977
+ }
1978
+ },
1979
+ uploadSubmit : function()
1980
+ {
1981
+ this.uploadForm(this.element, this.uploadFrame());
1982
+ },
1983
+ uploadFrame : function()
1984
+ {
1985
+ this.id = 'f' + Math.floor(Math.random() * 99999);
1986
+
1987
+ var d = document.createElement('div');
1988
+ var iframe = '<iframe style="display:none" src="about:blank" id="'+this.id+'" name="'+this.id+'"></iframe>';
1989
+ d.innerHTML = iframe;
1990
+ document.body.appendChild(d);
1991
+
1992
+ // Start
1993
+ if (this.uploadOptions.start) this.uploadOptions.start();
1994
+
1995
+ $('#' + this.id).load($.proxy(this.uploadLoaded, this));
1996
+
1997
+ return this.id;
1998
+ },
1999
+ uploadForm : function(f, name)
2000
+ {
2001
+ if (this.uploadOptions.input)
2002
+ {
2003
+ var formId = 'redactorUploadForm' + this.id;
2004
+ var fileId = 'redactorUploadFile' + this.id;
2005
+ this.form = $('<form action="' + this.uploadOptions.url + '" method="POST" target="' + name + '" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
2006
+
2007
+ var oldElement = this.uploadOptions.input;
2008
+ var newElement = $(oldElement).clone();
2009
+ $(oldElement).attr('id', fileId);
2010
+ $(oldElement).before(newElement);
2011
+ $(oldElement).appendTo(this.form);
2012
+ $(this.form).css('position', 'absolute');
2013
+ $(this.form).css('top', '-2000px');
2014
+ $(this.form).css('left', '-2000px');
2015
+ $(this.form).appendTo('body');
2016
+
2017
+ this.form.submit();
2018
+ }
2019
+ else
2020
+ {
2021
+ f.attr('target', name);
2022
+ f.attr('method', 'POST');
2023
+ f.attr('enctype', 'multipart/form-data');
2024
+ f.attr('action', this.uploadOptions.url);
2025
+
2026
+ this.element.submit();
2027
+ }
2028
+
2029
+ },
2030
+ uploadLoaded : function()
2031
+ {
2032
+ var i = $('#' + this.id);
2033
+
2034
+ if (i.contentDocument) var d = i.contentDocument;
2035
+ else if (i.contentWindow) var d = i.contentWindow.document;
2036
+ else var d = window.frames[this.id].document;
2037
+
2038
+ if (d.location.href == "about:blank") return true;
2039
+
2040
+ // Success
2041
+ if (this.uploadOptions.success) this.uploadOptions.success(d.body.innerHTML);
2042
+
2043
+ this.element.attr('action', this.element_action);
2044
+ this.element.attr('target', '');
2045
+
2046
+ },
2047
+
2048
+ // UTILITY
2049
+ markerIE: function()
2050
+ {
2051
+ this.spanid = Math.floor(Math.random() * 99999);
2052
+ this.execCommand('inserthtml', '<span id="span' + this.spanid + '"></span>');
2053
+ },
2054
+ oldIE: function()
2055
+ {
2056
+ if ($.browser.msie && parseInt($.browser.version, 10) < 9) return true;
2057
+ return false;
2058
+ },
2059
+ outerHTML: function(s)
2060
+ {
2061
+ return $("<p>").append($(s).eq(0).clone()).html();
2062
+ },
2063
+ normalize: function(str)
2064
+ {
2065
+ return parseInt(str.replace('px',''));
2066
+ }
2067
+
2068
+ };
2069
+
2070
+
2071
+ // API
2072
+ $.fn.getDoc = function()
2073
+ {
2074
+ return $(this.data('redactor').doc);
2075
+ };
2076
+
2077
+ $.fn.getFrame = function()
2078
+ {
2079
+ return this.data('redactor').$frame;
2080
+ };
2081
+
2082
+ $.fn.getEditor = function()
2083
+ {
2084
+ return this.data('redactor').$editor;
2085
+ };
2086
+
2087
+ $.fn.getCode = function()
2088
+ {
2089
+ return this.data('redactor').getCode();
2090
+ };
2091
+
2092
+ $.fn.setCode = function(html)
2093
+ {
2094
+ this.data('redactor').setCode(html);
2095
+ };
2096
+
2097
+ $.fn.insertHtml = function(html)
2098
+ {
2099
+ this.data('redactor').insertHtml(html);
2100
+ };
2101
+
2102
+ $.fn.destroyEditor = function()
2103
+ {
2104
+ this.data('redactor').destroy();
2105
+ this.removeData('redactor');
2106
+ };
2107
+
2108
+ $.fn.setFocus = function()
2109
+ {
2110
+ this.data('redactor').focus();
2111
+ };
2112
+
2113
+ $.fn.execCommand = function(cmd, param)
2114
+ {
2115
+ this.data('redactor').execCommand(cmd, param);
2116
+ };
2117
+
2118
+ })(jQuery);
2119
+
2120
+ /*
2121
+ Plugin Drag and drop Upload v1.0.1
2122
+ http://imperavi.com/
2123
+ Copyright 2012, Imperavi Ltd.
2124
+ */
2125
+ (function($){
2126
+
2127
+ // Initialization
2128
+ $.fn.dragupload = function(options)
2129
+ {
2130
+ return this.each(function() {
2131
+ var obj = new Construct(this, options);
2132
+ obj.init();
2133
+ });
2134
+ };
2135
+
2136
+ // Options and variables
2137
+ function Construct(el, options) {
2138
+
2139
+ this.opts = $.extend({
2140
+
2141
+ url: false,
2142
+ success: false,
2143
+ preview: false,
2144
+
2145
+ text: RLANG.drop_file_here,
2146
+ atext: RLANG.or_choose
2147
+
2148
+ }, options);
2149
+
2150
+ this.$el = $(el);
2151
+ }
2152
+
2153
+ // Functionality
2154
+ Construct.prototype = {
2155
+ init: function()
2156
+ {
2157
+ if (!$.browser.opera && !$.browser.msie)
2158
+ {
2159
+
2160
+ this.droparea = $('<div class="redactor_droparea"></div>');
2161
+ this.dropareabox = $('<div class="redactor_dropareabox">' + this.opts.text + '</div>');
2162
+ this.dropalternative = $('<div class="redactor_dropalternative">' + this.opts.atext + '</div>');
2163
+
2164
+ this.droparea.append(this.dropareabox);
2165
+
2166
+ this.$el.before(this.droparea);
2167
+ this.$el.before(this.dropalternative);
2168
+
2169
+ // drag over
2170
+ this.dropareabox.bind('dragover', $.proxy(function() { return this.ondrag(); }, this));
2171
+
2172
+ // drag leave
2173
+ this.dropareabox.bind('dragleave', $.proxy(function() { return this.ondragleave(); }, this));
2174
+
2175
+ // drop
2176
+ this.dropareabox.get(0).ondrop = $.proxy(function(event)
2177
+ {
2178
+ event.preventDefault();
2179
+
2180
+ this.dropareabox.removeClass('hover').addClass('drop');
2181
+
2182
+ var file = event.dataTransfer.files[0];
2183
+
2184
+ var fd = new FormData();
2185
+ fd.append('file', file);
2186
+
2187
+ $.ajax({
2188
+ dataType: 'html',
2189
+ url: this.opts.url,
2190
+ data: fd,
2191
+ //xhr: provider,
2192
+ cache: false,
2193
+ contentType: false,
2194
+ processData: false,
2195
+ type: 'POST',
2196
+ success: $.proxy(function(data)
2197
+ {
2198
+ if (this.opts.success !== false) this.opts.success(data);
2199
+ if (this.opts.preview === true) this.dropareabox.html(data);
2200
+ }, this)
2201
+ });
2202
+
2203
+ }, this);
2204
+ }
2205
+ },
2206
+ ondrag: function()
2207
+ {
2208
+ this.dropareabox.addClass('hover');
2209
+ return false;
2210
+ },
2211
+ ondragleave: function()
2212
+ {
2213
+ this.dropareabox.removeClass('hover');
2214
+ return false;
2215
+ }
2216
+ };
2217
+
2218
+ })(jQuery);
2219
+
2220
+
2221
+ // Define: Linkify plugin from stackoverflow
2222
+ (function($){
2223
+
2224
+ var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
2225
+ url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,
2226
+
2227
+ linkifyThis = function ()
2228
+ {
2229
+ var childNodes = this.childNodes,
2230
+ i = childNodes.length;
2231
+ while(i--)
2232
+ {
2233
+ var n = childNodes[i];
2234
+ if (n.nodeType == 3)
2235
+ {
2236
+ var html = n.nodeValue;
2237
+ if (html)
2238
+ {
2239
+ html = html.replace(/&/g, '&amp;')
2240
+ .replace(/</g, '&lt;')
2241
+ .replace(/>/g, '&gt;')
2242
+ .replace(url1, '$1<a href="http://$2">$2</a>$3')
2243
+ .replace(url2, '$1<a href="$2">$2</a>$5');
2244
+
2245
+ $(n).after(html).remove();
2246
+ }
2247
+ }
2248
+ else if (n.nodeType == 1 && !/^(a|button|textarea)$/i.test(n.tagName))
2249
+ {
2250
+ linkifyThis.call(n);
2251
+ }
2252
+ }
2253
+ };
2254
+
2255
+ $.fn.linkify = function ()
2256
+ {
2257
+ this.each(linkifyThis);
2258
+ };
2259
+
2260
+ })(jQuery);