markitup-rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Markitup
2
2
  module Rails
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -12,10 +12,10 @@
12
12
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
13
  // copies of the Software, and to permit persons to whom the Software is
14
14
  // furnished to do so, subject to the following conditions:
15
- //
15
+ //
16
16
  // The above copyright notice and this permission notice shall be included in
17
17
  // all copies or substantial portions of the Software.
18
- //
18
+ //
19
19
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
20
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
21
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -31,7 +31,7 @@
31
31
  if (typeof settings == 'string') {
32
32
  method = settings;
33
33
  params = extraSettings;
34
- }
34
+ }
35
35
 
36
36
  options = { id: '',
37
37
  nameSpace: '',
@@ -66,6 +66,35 @@
66
66
  });
67
67
  }
68
68
 
69
+ // Quick patch to keep compatibility with jQuery 1.9
70
+ var uaMatch = function(ua) {
71
+ ua = ua.toLowerCase();
72
+
73
+ var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
74
+ /(webkit)[ \/]([\w.]+)/.exec(ua) ||
75
+ /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
76
+ /(msie) ([\w.]+)/.exec(ua) ||
77
+ ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
78
+ [];
79
+
80
+ return {
81
+ browser: match[ 1 ] || "",
82
+ version: match[ 2 ] || "0"
83
+ };
84
+ };
85
+ var matched = uaMatch( navigator.userAgent );
86
+ var browser = {};
87
+
88
+ if (matched.browser) {
89
+ browser[matched.browser] = true;
90
+ browser.version = matched.version;
91
+ }
92
+ if (browser.chrome) {
93
+ browser.webkit = true;
94
+ } else if (browser.webkit) {
95
+ browser.safari = true;
96
+ }
97
+
69
98
  return this.each(function() {
70
99
  var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
71
100
  clicked, hash, header, footer, previewWindow, template, iFrame, abort;
@@ -87,7 +116,7 @@
87
116
  case 'insert':
88
117
  markup(params);
89
118
  break;
90
- default:
119
+ default:
91
120
  $.error('Method ' + method + ' does not exist on jQuery.markItUp');
92
121
  }
93
122
  return;
@@ -126,7 +155,7 @@
126
155
  footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
127
156
 
128
157
  // add the resize handle after textarea
129
- if (options.resizeHandle === true && $.browser.safari !== true) {
158
+ if (options.resizeHandle === true && browser.safari !== true) {
130
159
  resizeHandle = $('<div class="markItUpResizeHandle"></div>')
131
160
  .insertAfter($$)
132
161
  .bind("mousedown.markItUp", function(e) {
@@ -146,7 +175,7 @@
146
175
 
147
176
  // listen key events
148
177
  $$.bind('keydown.markItUp', keyPressed).bind('keyup', keyPressed);
149
-
178
+
150
179
  // bind an event to catch external calls
151
180
  $$.bind("insertion.markItUp", function(e, settings) {
152
181
  if (settings.target !== false) {
@@ -185,8 +214,8 @@
185
214
  li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
186
215
  .bind("contextmenu.markItUp", function() { // prevent contextmenu on mac and allow ctrl+click
187
216
  return false;
188
- }).bind('click.markItUp', function() {
189
- return false;
217
+ }).bind('click.markItUp', function(e) {
218
+ e.preventDefault();
190
219
  }).bind("focusin.markItUp", function(){
191
220
  $$.focus();
192
221
  }).bind('mouseup', function() {
@@ -209,7 +238,7 @@
209
238
  $(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
210
239
  }
211
240
  }
212
- });
241
+ });
213
242
  levels.pop();
214
243
  return ul;
215
244
  }
@@ -264,7 +293,7 @@
264
293
  var openBlockWith = prepare(clicked.openBlockWith);
265
294
  var closeBlockWith = prepare(clicked.closeBlockWith);
266
295
  var multiline = clicked.multiline;
267
-
296
+
268
297
  if (replaceWith !== "") {
269
298
  block = openWith + replaceWith + closeWith;
270
299
  } else if (selection === '' && placeHolder !== '') {
@@ -273,11 +302,11 @@
273
302
  string = string || selection;
274
303
 
275
304
  var lines = [string], blocks = [];
276
-
305
+
277
306
  if (multiline === true) {
278
307
  lines = string.split(/\r?\n/);
279
308
  }
280
-
309
+
281
310
  for (var l = 0; l < lines.length; l++) {
282
311
  line = lines[l];
283
312
  var trailingSpaces;
@@ -287,17 +316,19 @@
287
316
  blocks.push(openWith + line + closeWith);
288
317
  }
289
318
  }
290
-
319
+
291
320
  block = blocks.join("\n");
292
321
  }
293
322
 
294
323
  block = openBlockWith + block + closeBlockWith;
295
324
 
296
- return { block:block,
297
- openWith:openWith,
298
- replaceWith:replaceWith,
325
+ return { block:block,
326
+ openBlockWith:openBlockWith,
327
+ openWith:openWith,
328
+ replaceWith:replaceWith,
299
329
  placeHolder:placeHolder,
300
- closeWith:closeWith
330
+ closeWith:closeWith,
331
+ closeBlockWith:closeBlockWith
301
332
  };
302
333
  }
303
334
 
@@ -306,13 +337,13 @@
306
337
  var len, j, n, i;
307
338
  hash = clicked = button;
308
339
  get();
309
- $.extend(hash, { line:"",
340
+ $.extend(hash, { line:"",
310
341
  root:options.root,
311
- textarea:textarea,
312
- selection:(selection||''),
342
+ textarea:textarea,
343
+ selection:(selection||''),
313
344
  caretPosition:caretPosition,
314
- ctrlKey:ctrlKey,
315
- shiftKey:shiftKey,
345
+ ctrlKey:ctrlKey,
346
+ shiftKey:shiftKey,
316
347
  altKey:altKey
317
348
  }
318
349
  );
@@ -321,7 +352,7 @@
321
352
  prepare(clicked.beforeInsert);
322
353
  if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
323
354
  prepare(clicked.beforeMultiInsert);
324
- }
355
+ }
325
356
  $.extend(hash, { line:1 });
326
357
 
327
358
  if ((ctrlKey === true && shiftKey === true)) {
@@ -337,7 +368,7 @@
337
368
 
338
369
  string = { block:lines.join('\n')};
339
370
  start = caretPosition;
340
- len = string.block.length + (($.browser.opera) ? n-1 : 0);
371
+ len = string.block.length + ((browser.opera) ? n-1 : 0);
341
372
  } else if (ctrlKey === true) {
342
373
  string = build(selection);
343
374
  start = caretPosition + string.openWith.length;
@@ -357,9 +388,9 @@
357
388
  }
358
389
  if ((selection === '' && string.replaceWith === '')) {
359
390
  caretOffset += fixOperaBug(string.block);
360
-
361
- start = caretPosition + string.openWith.length;
362
- len = string.block.length - string.openWith.length - string.closeWith.length;
391
+
392
+ start = caretPosition + string.openBlockWith.length + string.openWith.length;
393
+ len = string.block.length - string.openBlockWith.length - string.openWith.length - string.closeWith.length - string.closeBlockWith.length;
363
394
 
364
395
  caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
365
396
  caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
@@ -385,30 +416,30 @@
385
416
 
386
417
  // refresh preview if opened
387
418
  if (previewWindow && options.previewAutoRefresh) {
388
- refreshPreview();
419
+ refreshPreview();
389
420
  }
390
-
421
+
391
422
  // reinit keyevent
392
423
  shiftKey = altKey = ctrlKey = abort = false;
393
424
  }
394
425
 
395
426
  // Substract linefeed in Opera
396
427
  function fixOperaBug(string) {
397
- if ($.browser.opera) {
428
+ if (browser.opera) {
398
429
  return string.length - string.replace(/\n*/g, '').length;
399
430
  }
400
431
  return 0;
401
432
  }
402
433
  // Substract linefeed in IE
403
434
  function fixIeBug(string) {
404
- if ($.browser.msie) {
435
+ if (browser.msie) {
405
436
  return string.length - string.replace(/\r*/g, '').length;
406
437
  }
407
438
  return 0;
408
439
  }
409
-
440
+
410
441
  // add markup
411
- function insert(block) {
442
+ function insert(block) {
412
443
  if (document.selection) {
413
444
  var newSelection = document.selection.createRange();
414
445
  newSelection.text = block;
@@ -421,13 +452,13 @@
421
452
  function set(start, len) {
422
453
  if (textarea.createTextRange){
423
454
  // quick fix to make it work on Opera 9.5
424
- if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
455
+ if (browser.opera && browser.version >= 9.5 && len == 0) {
425
456
  return false;
426
457
  }
427
458
  range = textarea.createTextRange();
428
459
  range.collapse(true);
429
- range.moveStart('character', start);
430
- range.moveEnd('character', len);
460
+ range.moveStart('character', start);
461
+ range.moveEnd('character', len);
431
462
  range.select();
432
463
  } else if (textarea.setSelectionRange ){
433
464
  textarea.setSelectionRange(start, start + len);
@@ -443,7 +474,7 @@
443
474
  scrollPosition = textarea.scrollTop;
444
475
  if (document.selection) {
445
476
  selection = document.selection.createRange().text;
446
- if ($.browser.msie) { // ie
477
+ if (browser.msie) { // ie
447
478
  var range = document.selection.createRange(), rangeCopy = range.duplicate();
448
479
  rangeCopy.moveToElementText(textarea);
449
480
  caretPosition = -1;
@@ -458,7 +489,7 @@
458
489
  caretPosition = textarea.selectionStart;
459
490
 
460
491
  selection = textarea.value.substring(caretPosition, textarea.selectionEnd);
461
- }
492
+ }
462
493
  return selection;
463
494
  }
464
495
 
@@ -480,7 +511,7 @@
480
511
  iFrame.insertAfter(footer);
481
512
  } else {
482
513
  iFrame.insertBefore(header);
483
- }
514
+ }
484
515
  previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
485
516
  }
486
517
  } else if (altKey === true) {
@@ -492,7 +523,7 @@
492
523
  previewWindow = iFrame = false;
493
524
  }
494
525
  if (!options.previewAutoRefresh) {
495
- refreshPreview();
526
+ refreshPreview();
496
527
  }
497
528
  if (options.previewInWindow) {
498
529
  previewWindow.focus();
@@ -510,7 +541,7 @@
510
541
  options.previewHandler( $$.val() );
511
542
  } else if (options.previewParser && typeof options.previewParser === 'function') {
512
543
  var data = options.previewParser( $$.val() );
513
- writeInPreview(localize(data, 1) );
544
+ writeInPreview(localize(data, 1) );
514
545
  } else if (options.previewParserPath !== '') {
515
546
  $.ajax({
516
547
  type: 'POST',
@@ -519,7 +550,7 @@
519
550
  url: options.previewParserPath,
520
551
  data: options.previewParserVar+'='+encodeURIComponent($$.val()),
521
552
  success: function(data) {
522
- writeInPreview( localize(data, 1) );
553
+ writeInPreview( localize(data, 1) );
523
554
  }
524
555
  });
525
556
  } else {
@@ -536,25 +567,25 @@
536
567
  }
537
568
  return false;
538
569
  }
539
-
570
+
540
571
  function writeInPreview(data) {
541
572
  if (options.previewInElement) {
542
573
  $(options.previewInElement).html(data);
543
- } else if (previewWindow && previewWindow.document) {
574
+ } else if (previewWindow && previewWindow.document) {
544
575
  try {
545
576
  sp = previewWindow.document.documentElement.scrollTop
546
577
  } catch(e) {
547
578
  sp = 0;
548
- }
579
+ }
549
580
  previewWindow.document.open();
550
581
  previewWindow.document.write(data);
551
582
  previewWindow.document.close();
552
583
  previewWindow.document.documentElement.scrollTop = sp;
553
584
  }
554
585
  }
555
-
586
+
556
587
  // set keys pressed
557
- function keyPressed(e) {
588
+ function keyPressed(e) {
558
589
  shiftKey = e.shiftKey;
559
590
  altKey = e.altKey;
560
591
  ctrlKey = (!(e.altKey && e.ctrlKey)) ? (e.ctrlKey || e.metaKey) : false;
@@ -586,7 +617,7 @@
586
617
  }
587
618
  if (e.keyCode === 9) { // Tab key
588
619
  if (shiftKey == true || ctrlKey == true || altKey == true) {
589
- return false;
620
+ return false;
590
621
  }
591
622
  if (caretOffset !== -1) {
592
623
  get();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markitup-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-19 00:00:00.000000000 Z
13
+ date: 2013-03-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails