Advertisement
Guest User

Untitled

a guest
Feb 1st, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // chrome fix
  2.         // when creating a new line after the link,
  3.         // the first letter of new line is appended to link
  4.         if (jQuery.browser.webkit) {
  5.             editor.on('contentDom', function() {
  6.                 this.document.on('keydown', function(event) {
  7.                     if (event.data.getKey() === 13 /* enter */) {
  8.                         var selection = editor.getSelection(),
  9.                             range,
  10.                             parent;
  11.  
  12.                         if (!selection) {
  13.                             return;
  14.                         }
  15.  
  16.                         // insert <span>&nbsp;</span> right after the link
  17.                         // cursor moves to next line
  18.                         // remove span element
  19.  
  20.                         range = selection.getRanges()[0];
  21.                         parent = range.endContainer.getParent();
  22.  
  23.                         var before = range.checkStartOfBlock(),
  24.                             after = range.checkEndOfBlock();
  25.  
  26.                         if ((parent.is('a') && range.collapsed) ||
  27.                             (range.endContainer.type === 1 && range.endContainer.is('a'))) {
  28.  
  29.                             if (isInside(range.endContainer, 'li')) {
  30.                                 return;
  31.                             }
  32.  
  33.                             editor.insertHtml('<span>&nbsp;</span>');
  34.                             setTimeout(function() {
  35.                                 if (after && parent && parent.getNext()) {
  36.                                     parent.getNext().remove();
  37.                                 }
  38.                             }, 100);
  39.                         }
  40.                     }
  41.                 });
  42.             });
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement