markitup_rails3 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/.gitignore +3 -0
  2. data/README.md +89 -0
  3. data/lib/markitup_rails3.rb +9 -0
  4. data/lib/markitup_rails3/engine.rb +6 -0
  5. data/lib/markitup_rails3/railtie.rb +6 -0
  6. data/lib/markitup_rails3/version.rb +5 -0
  7. data/markitup_rails3.gemspec +21 -0
  8. data/vendor/assets/images/markitup/bg-container.png +0 -0
  9. data/vendor/assets/images/markitup/bg-editor-bbcode.png +0 -0
  10. data/vendor/assets/images/markitup/bg-editor-dotclear.png +0 -0
  11. data/vendor/assets/images/markitup/bg-editor-html.png +0 -0
  12. data/vendor/assets/images/markitup/bg-editor-json.png +0 -0
  13. data/vendor/assets/images/markitup/bg-editor-markdown.png +0 -0
  14. data/vendor/assets/images/markitup/bg-editor-textile.png +0 -0
  15. data/vendor/assets/images/markitup/bg-editor-wiki.png +0 -0
  16. data/vendor/assets/images/markitup/bg-editor-xml.png +0 -0
  17. data/vendor/assets/images/markitup/bg-editor.png +0 -0
  18. data/vendor/assets/images/markitup/bold.png +0 -0
  19. data/vendor/assets/images/markitup/clean.png +0 -0
  20. data/vendor/assets/images/markitup/code.png +0 -0
  21. data/vendor/assets/images/markitup/css.png +0 -0
  22. data/vendor/assets/images/markitup/disconnect.png +0 -0
  23. data/vendor/assets/images/markitup/h1.png +0 -0
  24. data/vendor/assets/images/markitup/h2.png +0 -0
  25. data/vendor/assets/images/markitup/h3.png +0 -0
  26. data/vendor/assets/images/markitup/h4.png +0 -0
  27. data/vendor/assets/images/markitup/h5.png +0 -0
  28. data/vendor/assets/images/markitup/h6.png +0 -0
  29. data/vendor/assets/images/markitup/handle.png +0 -0
  30. data/vendor/assets/images/markitup/image.png +0 -0
  31. data/vendor/assets/images/markitup/italic.png +0 -0
  32. data/vendor/assets/images/markitup/link.png +0 -0
  33. data/vendor/assets/images/markitup/list-bullet.png +0 -0
  34. data/vendor/assets/images/markitup/list-item.png +0 -0
  35. data/vendor/assets/images/markitup/list-numeric.png +0 -0
  36. data/vendor/assets/images/markitup/menu.png +0 -0
  37. data/vendor/assets/images/markitup/page_white_code.png +0 -0
  38. data/vendor/assets/images/markitup/paragraph.png +0 -0
  39. data/vendor/assets/images/markitup/picture.png +0 -0
  40. data/vendor/assets/images/markitup/preview.png +0 -0
  41. data/vendor/assets/images/markitup/quotes.png +0 -0
  42. data/vendor/assets/images/markitup/stroke.png +0 -0
  43. data/vendor/assets/images/markitup/submenu.png +0 -0
  44. data/vendor/assets/images/markitup/tag.png +0 -0
  45. data/vendor/assets/images/markitup/text_align_center.png +0 -0
  46. data/vendor/assets/images/markitup/text_align_justify.png +0 -0
  47. data/vendor/assets/images/markitup/text_align_left.png +0 -0
  48. data/vendor/assets/images/markitup/text_align_right.png +0 -0
  49. data/vendor/assets/images/markitup/text_indent.png +0 -0
  50. data/vendor/assets/images/markitup/text_letterspacing.png +0 -0
  51. data/vendor/assets/images/markitup/text_linespacing.png +0 -0
  52. data/vendor/assets/images/markitup/text_lowercase.png +0 -0
  53. data/vendor/assets/images/markitup/text_padding_bottom.png +0 -0
  54. data/vendor/assets/images/markitup/text_padding_left.png +0 -0
  55. data/vendor/assets/images/markitup/text_padding_right.png +0 -0
  56. data/vendor/assets/images/markitup/text_padding_top.png +0 -0
  57. data/vendor/assets/images/markitup/text_uppercase.png +0 -0
  58. data/vendor/assets/images/markitup/url.png +0 -0
  59. data/vendor/assets/javascripts/markitup-css.js +52 -0
  60. data/vendor/assets/javascripts/markitup-html.js +39 -0
  61. data/vendor/assets/javascripts/markitup-markdown.js +52 -0
  62. data/vendor/assets/javascripts/markitup-textile.js +40 -0
  63. data/vendor/assets/javascripts/markitup.js +596 -0
  64. data/vendor/assets/javascripts/marmarkitup-texy.js +51 -0
  65. data/vendor/assets/javascripts/marmarkitup-wiki.js +37 -0
  66. data/vendor/assets/stylesheets/markitup-css.css.erb +72 -0
  67. data/vendor/assets/stylesheets/markitup-html.css.erb +59 -0
  68. data/vendor/assets/stylesheets/markitup-markdown.css.erb +54 -0
  69. data/vendor/assets/stylesheets/markitup-textile.css.erb +61 -0
  70. data/vendor/assets/stylesheets/markitup.css.erb +184 -0
  71. data/vendor/assets/stylesheets/marmarkitup-texy.css.erb +51 -0
  72. data/vendor/assets/stylesheets/marmarkitup-wiki.css.erb +57 -0
  73. metadata +156 -0
@@ -0,0 +1,596 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // v 1.1.x
4
+ // Dual licensed under the MIT and GPL licenses.
5
+ // ----------------------------------------------------------------------------
6
+ // Copyright (C) 2007-2011 Jay Salvat
7
+ // http://markitup.jaysalvat.com/
8
+ // ----------------------------------------------------------------------------
9
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ // of this software and associated documentation files (the "Software"), to deal
11
+ // in the Software without restriction, including without limitation the rights
12
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the Software is
14
+ // furnished to do so, subject to the following conditions:
15
+ //
16
+ // The above copyright notice and this permission notice shall be included in
17
+ // all copies or substantial portions of the Software.
18
+ //
19
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ // THE SOFTWARE.
26
+ // ----------------------------------------------------------------------------
27
+ (function($) {
28
+ $.fn.markItUp = function(settings, extraSettings) {
29
+ var options, ctrlKey, shiftKey, altKey;
30
+ ctrlKey = shiftKey = altKey = false;
31
+
32
+ options = { id: '',
33
+ nameSpace: '',
34
+ root: '',
35
+ previewInWindow: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
36
+ previewAutoRefresh: true,
37
+ previewPosition: 'after',
38
+ previewTemplatePath: '~/templates/preview.html',
39
+ previewParser: function(content) {
40
+ converter = new Showdown.converter();
41
+ return converter.makeHtml(content);
42
+ }, //false,
43
+ previewParserPath: '',
44
+ previewParserVar: 'data',
45
+ resizeHandle: true,
46
+ beforeInsert: '',
47
+ afterInsert: '',
48
+ onEnter: {},
49
+ onShiftEnter: {},
50
+ onCtrlEnter: {},
51
+ onTab: {},
52
+ markupSet: [ { /* set */ } ]
53
+ };
54
+ $.extend(options, settings, extraSettings);
55
+
56
+ // compute markItUp! path
57
+ if (!options.root) {
58
+ $('script').each(function(a, tag) {
59
+ miuScript = $(tag).get(0).src.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
60
+ if (miuScript !== null) {
61
+ options.root = miuScript[1];
62
+ }
63
+ });
64
+ }
65
+
66
+ return this.each(function() {
67
+ var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
68
+ clicked, hash, header, footer, previewWindow, template, iFrame, abort;
69
+ $$ = $(this);
70
+ textarea = this;
71
+ levels = [];
72
+ abort = false;
73
+ scrollPosition = caretPosition = 0;
74
+ caretOffset = -1;
75
+
76
+ options.previewParserPath = localize(options.previewParserPath);
77
+ options.previewTemplatePath = localize(options.previewTemplatePath);
78
+
79
+ // apply the computed path to ~/
80
+ function localize(data, inText) {
81
+ if (inText) {
82
+ return data.replace(/("|')~\//g, "$1"+options.root);
83
+ }
84
+ return data.replace(/^~\//, options.root);
85
+ }
86
+
87
+ // init and build editor
88
+ function init() {
89
+ id = ''; nameSpace = '';
90
+ if (options.id) {
91
+ id = 'id="'+options.id+'"';
92
+ } else if ($$.attr("id")) {
93
+ id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
94
+
95
+ }
96
+ if (options.nameSpace) {
97
+ nameSpace = 'class="'+options.nameSpace+'"';
98
+ }
99
+ $$.wrap('<div '+nameSpace+'></div>');
100
+ $$.wrap('<div '+id+' class="markItUp"></div>');
101
+ $$.wrap('<div class="markItUpContainer"></div>');
102
+ $$.addClass("markItUpEditor");
103
+
104
+ // add the header before the textarea
105
+ header = $('<div class="markItUpHeader"></div>').insertBefore($$);
106
+ $(dropMenus(options.markupSet)).appendTo(header);
107
+
108
+ // add the footer after the textarea
109
+ footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
110
+
111
+ // add the resize handle after textarea
112
+ if (options.resizeHandle === true && $.browser.safari !== true) {
113
+ resizeHandle = $('<div class="markItUpResizeHandle"></div>')
114
+ .insertAfter($$)
115
+ .bind("mousedown", function(e) {
116
+ var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
117
+ mouseMove = function(e) {
118
+ $$.css("height", Math.max(20, e.clientY+h-y)+"px");
119
+ return false;
120
+ };
121
+ mouseUp = function(e) {
122
+ $("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp);
123
+ return false;
124
+ };
125
+ $("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp);
126
+ });
127
+ footer.append(resizeHandle);
128
+ }
129
+
130
+ // listen key events
131
+ $$.keydown(keyPressed).keyup(keyPressed);
132
+
133
+ // bind an event to catch external calls
134
+ $$.bind("insertion", function(e, settings) {
135
+ if (settings.target !== false) {
136
+ get();
137
+ }
138
+ if (textarea === $.markItUp.focused) {
139
+ markup(settings);
140
+ }
141
+ });
142
+
143
+ // remember the last focus
144
+ $$.focus(function() {
145
+ $.markItUp.focused = this;
146
+ });
147
+ }
148
+
149
+ // recursively build header with dropMenus from markupset
150
+ function dropMenus(markupSet) {
151
+ var ul = $('<ul></ul>'), i = 0;
152
+ $('li:hover > ul', ul).css('display', 'block');
153
+ $.each(markupSet, function() {
154
+ var button = this, t = '', title, li, j;
155
+ title = (button.key) ? (button.name||'')+' [Ctrl+'+button.key+']' : (button.name||'');
156
+ key = (button.key) ? 'accesskey="'+button.key+'"' : '';
157
+ if (button.separator) {
158
+ li = $('<li class="markItUpSeparator">'+(button.separator||'')+'</li>').appendTo(ul);
159
+ } else {
160
+ i++;
161
+ for (j = levels.length -1; j >= 0; j--) {
162
+ t += levels[j]+"-";
163
+ }
164
+ li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
165
+ .bind("contextmenu", function() { // prevent contextmenu on mac and allow ctrl+click
166
+ return false;
167
+ }).click(function() {
168
+ return false;
169
+ }).bind("focusin", function(){
170
+ $$.focus();
171
+ }).mouseup(function() {
172
+ if (button.call) {
173
+ eval(button.call)();
174
+ }
175
+ setTimeout(function() { markup(button) },1);
176
+ return false;
177
+ }).hover(function() {
178
+ $('> ul', this).show();
179
+ $(document).one('click', function() { // close dropmenu if click outside
180
+ $('ul ul', header).hide();
181
+ }
182
+ );
183
+ }, function() {
184
+ $('> ul', this).hide();
185
+ }
186
+ ).appendTo(ul);
187
+ if (button.dropMenu) {
188
+ levels.push(i);
189
+ $(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
190
+ }
191
+ }
192
+ });
193
+ levels.pop();
194
+ return ul;
195
+ }
196
+
197
+ // markItUp! markups
198
+ function magicMarkups(string) {
199
+ if (string) {
200
+ string = string.toString();
201
+ string = string.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
202
+ function(x, a) {
203
+ var b = a.split('|!|');
204
+ if (altKey === true) {
205
+ return (b[1] !== undefined) ? b[1] : b[0];
206
+ } else {
207
+ return (b[1] === undefined) ? "" : b[0];
208
+ }
209
+ }
210
+ );
211
+ // [![prompt]!], [![prompt:!:value]!]
212
+ string = string.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
213
+ function(x, a) {
214
+ var b = a.split(':!:');
215
+ if (abort === true) {
216
+ return false;
217
+ }
218
+ value = prompt(b[0], (b[1]) ? b[1] : '');
219
+ if (value === null) {
220
+ abort = true;
221
+ }
222
+ return value;
223
+ }
224
+ );
225
+ return string;
226
+ }
227
+ return "";
228
+ }
229
+
230
+ // prepare action
231
+ function prepare(action) {
232
+ if ($.isFunction(action)) {
233
+ action = action(hash);
234
+ }
235
+ return magicMarkups(action);
236
+ }
237
+
238
+ // build block to insert
239
+ function build(string) {
240
+ var openWith = prepare(clicked.openWith);
241
+ var placeHolder = prepare(clicked.placeHolder);
242
+ var replaceWith = prepare(clicked.replaceWith);
243
+ var closeWith = prepare(clicked.closeWith);
244
+ var openBlockWith = prepare(clicked.openBlockWith);
245
+ var closeBlockWith = prepare(clicked.closeBlockWith);
246
+ var multiline = clicked.multiline;
247
+
248
+ if (replaceWith !== "") {
249
+ block = openWith + replaceWith + closeWith;
250
+ } else if (selection === '' && placeHolder !== '') {
251
+ block = openWith + placeHolder + closeWith;
252
+ } else {
253
+ string = string || selection;
254
+
255
+ var lines = selection.split(/\r?\n/), blocks = [];
256
+
257
+ for (var l=0; l < lines.length; l++) {
258
+ line = lines[l];
259
+ var trailingSpaces;
260
+ if (trailingSpaces = line.match(/ *$/)) {
261
+ blocks.push(openWith + line.replace(/ *$/g, '') + closeWith + trailingSpaces);
262
+ } else {
263
+ blocks.push(openWith + line + closeWith);
264
+ }
265
+ }
266
+
267
+ block = blocks.join("\n");
268
+ }
269
+
270
+ block = openBlockWith + block + closeBlockWith;
271
+
272
+ return { block:block,
273
+ openWith:openWith,
274
+ replaceWith:replaceWith,
275
+ placeHolder:placeHolder,
276
+ closeWith:closeWith
277
+ };
278
+ }
279
+
280
+ // define markup to insert
281
+ function markup(button) {
282
+ var len, j, n, i;
283
+ hash = clicked = button;
284
+ get();
285
+ $.extend(hash, { line:"",
286
+ root:options.root,
287
+ textarea:textarea,
288
+ selection:(selection||''),
289
+ caretPosition:caretPosition,
290
+ ctrlKey:ctrlKey,
291
+ shiftKey:shiftKey,
292
+ altKey:altKey
293
+ }
294
+ );
295
+ // callbacks before insertion
296
+ prepare(options.beforeInsert);
297
+ prepare(clicked.beforeInsert);
298
+ if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
299
+ prepare(clicked.beforeMultiInsert);
300
+ }
301
+ $.extend(hash, { line:1 });
302
+
303
+ if ((ctrlKey === true && shiftKey === true)) {
304
+ lines = selection.split(/\r?\n/);
305
+ for (j = 0, n = lines.length, i = 0; i < n; i++) {
306
+ if ($.trim(lines[i]) !== '') {
307
+ $.extend(hash, { line:++j, selection:lines[i] } );
308
+ lines[i] = build(lines[i]).block;
309
+ } else {
310
+ lines[i] = "";
311
+ }
312
+ }
313
+ string = { block:lines.join('\n')};
314
+ start = caretPosition;
315
+ len = string.block.length + (($.browser.opera) ? n-1 : 0);
316
+ } else if (ctrlKey === true) {
317
+ string = build(selection);
318
+ start = caretPosition + string.openWith.length;
319
+ len = string.block.length - string.openWith.length - string.closeWith.length;
320
+ len = len - (string.block.match(/ $/) ? 1 : 0);
321
+ len -= fixIeBug(string.block);
322
+ } else if (shiftKey === true) {
323
+ string = build(selection);
324
+ start = caretPosition;
325
+ len = string.block.length;
326
+ len -= fixIeBug(string.block);
327
+ } else {
328
+ string = build(selection);
329
+ start = caretPosition + string.block.length ;
330
+ len = 0;
331
+ start -= fixIeBug(string.block);
332
+ }
333
+ if ((selection === '' && string.replaceWith === '')) {
334
+ caretOffset += fixOperaBug(string.block);
335
+
336
+ start = caretPosition + string.openWith.length;
337
+ len = string.block.length - string.openWith.length - string.closeWith.length;
338
+
339
+ caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
340
+ caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
341
+ }
342
+ $.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );
343
+
344
+ if (string.block !== selection && abort === false) {
345
+ insert(string.block);
346
+ set(start, len);
347
+ } else {
348
+ caretOffset = -1;
349
+ }
350
+ get();
351
+
352
+ $.extend(hash, { line:'', selection:selection });
353
+
354
+ // callbacks after insertion
355
+ if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
356
+ prepare(clicked.afterMultiInsert);
357
+ }
358
+ prepare(clicked.afterInsert);
359
+ prepare(options.afterInsert);
360
+
361
+ // refresh preview if opened
362
+ if (previewWindow && options.previewAutoRefresh) {
363
+ refreshPreview();
364
+ }
365
+
366
+ // reinit keyevent
367
+ shiftKey = altKey = ctrlKey = abort = false;
368
+ }
369
+
370
+ // Substract linefeed in Opera
371
+ function fixOperaBug(string) {
372
+ if ($.browser.opera) {
373
+ return string.length - string.replace(/\n*/g, '').length;
374
+ }
375
+ return 0;
376
+ }
377
+ // Substract linefeed in IE
378
+ function fixIeBug(string) {
379
+ if ($.browser.msie) {
380
+ return string.length - string.replace(/\r*/g, '').length;
381
+ }
382
+ return 0;
383
+ }
384
+
385
+ // add markup
386
+ function insert(block) {
387
+ if (document.selection) {
388
+ var newSelection = document.selection.createRange();
389
+ newSelection.text = block;
390
+ } else {
391
+ textarea.value = textarea.value.substring(0, caretPosition) + block + textarea.value.substring(caretPosition + selection.length, textarea.value.length);
392
+ }
393
+ }
394
+
395
+ // set a selection
396
+ function set(start, len) {
397
+ if (textarea.createTextRange){
398
+ // quick fix to make it work on Opera 9.5
399
+ if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
400
+ return false;
401
+ }
402
+ range = textarea.createTextRange();
403
+ range.collapse(true);
404
+ range.moveStart('character', start);
405
+ range.moveEnd('character', len);
406
+ range.select();
407
+ } else if (textarea.setSelectionRange ){
408
+ textarea.setSelectionRange(start, start + len);
409
+ }
410
+ textarea.scrollTop = scrollPosition;
411
+ textarea.focus();
412
+ }
413
+
414
+ // get the selection
415
+ function get() {
416
+ textarea.focus();
417
+
418
+ scrollPosition = textarea.scrollTop;
419
+ if (document.selection) {
420
+ selection = document.selection.createRange().text;
421
+ if ($.browser.msie) { // ie
422
+ var range = document.selection.createRange(), rangeCopy = range.duplicate();
423
+ rangeCopy.moveToElementText(textarea);
424
+ caretPosition = -1;
425
+ while(rangeCopy.inRange(range)) {
426
+ rangeCopy.moveStart('character');
427
+ caretPosition ++;
428
+ }
429
+ } else { // opera
430
+ caretPosition = textarea.selectionStart;
431
+ }
432
+ } else { // gecko & webkit
433
+ caretPosition = textarea.selectionStart;
434
+
435
+ selection = textarea.value.substring(caretPosition, textarea.selectionEnd);
436
+ }
437
+ return selection;
438
+ }
439
+
440
+ // open preview window
441
+ function preview() {
442
+ if (!previewWindow || previewWindow.closed) {
443
+ if (options.previewInWindow) {
444
+ previewWindow = window.open('', 'preview', options.previewInWindow);
445
+ $(window).unload(function() {
446
+ previewWindow.close();
447
+ });
448
+ } else {
449
+ iFrame = $('<iframe class="markItUpPreviewFrame"></iframe>');
450
+ if (options.previewPosition == 'after') {
451
+ iFrame.insertAfter(footer);
452
+ } else {
453
+ iFrame.insertBefore(header);
454
+ }
455
+ previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
456
+ }
457
+ } else if (altKey === true) {
458
+ if (iFrame) {
459
+ iFrame.remove();
460
+ } else {
461
+ previewWindow.close();
462
+ }
463
+ previewWindow = iFrame = false;
464
+ }
465
+ if (!options.previewAutoRefresh) {
466
+ refreshPreview();
467
+ }
468
+ if (options.previewInWindow) {
469
+ previewWindow.focus();
470
+ }
471
+ }
472
+
473
+ // refresh Preview window
474
+ function refreshPreview() {
475
+ renderPreview();
476
+ }
477
+
478
+ function renderPreview() {
479
+ var phtml;
480
+ if (options.previewParser && typeof options.previewParser === 'function') {
481
+ var data = options.previewParser( $$.val() );
482
+ writeInPreview( localize(data, 1) );
483
+ } else if (options.previewParserPath !== '') {
484
+ $.ajax({
485
+ type: 'POST',
486
+ dataType: 'text',
487
+ global: false,
488
+ url: options.previewParserPath,
489
+ data: options.previewParserVar+'='+encodeURIComponent($$.val()),
490
+ success: function(data) {
491
+ writeInPreview( localize(data, 1) );
492
+ }
493
+ });
494
+ } else {
495
+ if (!template) {
496
+ $.ajax({
497
+ url: options.previewTemplatePath,
498
+ dataType: 'text',
499
+ global: false,
500
+ success: function(data) {
501
+ writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
502
+ }
503
+ });
504
+ }
505
+ }
506
+ return false;
507
+ }
508
+
509
+ function writeInPreview(data) {
510
+ if (previewWindow.document) {
511
+ try {
512
+ sp = previewWindow.document.documentElement.scrollTop
513
+ } catch(e) {
514
+ sp = 0;
515
+ }
516
+ previewWindow.document.open();
517
+ previewWindow.document.write(data);
518
+ previewWindow.document.close();
519
+ previewWindow.document.documentElement.scrollTop = sp;
520
+ }
521
+ }
522
+
523
+ // set keys pressed
524
+ function keyPressed(e) {
525
+ shiftKey = e.shiftKey;
526
+ altKey = e.altKey;
527
+ ctrlKey = (!(e.altKey && e.ctrlKey)) ? (e.ctrlKey || e.metaKey) : false;
528
+
529
+ if (e.type === 'keydown') {
530
+ if (ctrlKey === true) {
531
+ li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li');
532
+ if (li.length !== 0) {
533
+ ctrlKey = false;
534
+ setTimeout(function() {
535
+ li.triggerHandler('mouseup');
536
+ },1);
537
+ return false;
538
+ }
539
+ }
540
+ if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
541
+ if (ctrlKey === true) { // Enter + Ctrl
542
+ ctrlKey = false;
543
+ markup(options.onCtrlEnter);
544
+ return options.onCtrlEnter.keepDefault;
545
+ } else if (shiftKey === true) { // Enter + Shift
546
+ shiftKey = false;
547
+ markup(options.onShiftEnter);
548
+ return options.onShiftEnter.keepDefault;
549
+ } else { // only Enter
550
+ markup(options.onEnter);
551
+ return options.onEnter.keepDefault;
552
+ }
553
+ }
554
+ if (e.keyCode === 9) { // Tab key
555
+ if (shiftKey == true || ctrlKey == true || altKey == true) {
556
+ return false;
557
+ }
558
+ if (caretOffset !== -1) {
559
+ get();
560
+ caretOffset = $$.val().length - caretOffset;
561
+ set(caretOffset, 0);
562
+ caretOffset = -1;
563
+ return false;
564
+ } else {
565
+ markup(options.onTab);
566
+ return options.onTab.keepDefault;
567
+ }
568
+ }
569
+ }
570
+ }
571
+
572
+ init();
573
+ });
574
+ };
575
+
576
+ $.fn.markItUpRemove = function() {
577
+ return this.each(function() {
578
+ var $$ = $(this).unbind().removeClass('markItUpEditor');
579
+ $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
580
+ }
581
+ );
582
+ };
583
+
584
+ $.markItUp = function(settings) {
585
+ var options = { target:false };
586
+ $.extend(options, settings);
587
+ if (options.target) {
588
+ return $(options.target).each(function() {
589
+ $(this).focus();
590
+ $(this).trigger('insertion', [options]);
591
+ });
592
+ } else {
593
+ $('textarea').trigger('insertion', [options]);
594
+ }
595
+ };
596
+ })(jQuery);