src/content_editable.js
function (value, strategy, e) {
      var pre = this.getTextFromHeadToCaret();
      // use ownerDocument instead of window to support iframes
      var sel = this.el.ownerDocument.getSelection();
      
      var range = sel.getRangeAt(0);
      var selection = range.cloneRange();
      selection.selectNodeContents(range.startContainer);
      var content = selection.toString();
      var post = content.substring(range.startOffset);
      var newSubstr = strategy.replace(value, e);
      var regExp;
      if (typeof newSubstr !== 'undefined') {
        if ($.isArray(newSubstr)) {
          post = newSubstr[1] + post;
          newSubstr = newSubstr[0];
        }
        regExp = $.isFunction(strategy.match) ? strategy.match(pre) : strategy.match;
        pre = pre.replace(regExp, newSubstr)
            .replace(/ $/, "&nbsp"); // &nbsp necessary at least for CKeditor to not eat spaces
        range.selectNodeContents(range.startContainer);
        range.deleteContents();
        
        // create temporary elements
        var preWrapper = this.el.ownerDocument.createElement("div");
        preWrapper.innerHTML = pre;
        var postWrapper = this.el.ownerDocument.createElement("div");
        postWrapper.innerHTML = post;
        
        // create the fragment thats inserted
        var fragment = this.el.ownerDocument.createDocumentFragment();
        var childNode;
        var lastOfPre;
        while (childNode = preWrapper.firstChild) {
        	lastOfPre = fragment.appendChild(childNode);
        }
        while (childNode = postWrapper.firstChild) {
        	fragment.appendChild(childNode);
        }
        
        // insert the fragment & jump behind the last node in "pre"
        range.insertNode(fragment);
        range.setStartAfter(lastOfPre);
        
        range.collapse(true);
        sel.removeAllRanges();
        sel.addRange(range);
      }
    }
function (value, strategy, e) {
      var pre = this.getTextFromHeadToCaret();
      // use ownerDocument instead of window to support iframes
      var sel = this.el.ownerDocument.getSelection();
      
      var range = sel.getRangeAt(0);
      var selection = range.cloneRange();
      selection.selectNodeContents(range.startContainer);
      var content = selection.toString();
      var post = content.substring(range.startOffset);
      var newSubstr = strategy.replace(value, e);
      var regExp;
      if (typeof newSubstr !== 'undefined') {
        if ($.isArray(newSubstr)) {
          post = newSubstr[1] + post;
          newSubstr = newSubstr[0];
        }
        regExp = $.isFunction(strategy.match) ? strategy.match(pre) : strategy.match;
        pre = pre.replace(regExp, newSubstr)
            .replace(/ $/, "&nbsp"); // &nbsp necessary at least for CKeditor to not eat spaces
        range.selectNodeContents(range.startContainer);
        range.deleteContents();
        
        // create temporary elements
        var preWrapper = this.el.ownerDocument.createElement("div");
        preWrapper.innerHTML = pre;
        var postWrapper = this.el.ownerDocument.createElement("div");
        postWrapper.innerHTML = post;
        
        // create the fragment thats inserted
        var fragment = this.el.ownerDocument.createDocumentFragment();
        var childNode;
        var lastOfPre;
        while (childNode = preWrapper.firstChild) {
        	lastOfPre = fragment.appendChild(childNode);
        }
        while (childNode = postWrapper.firstChild) {
        	fragment.appendChild(childNode);
        }
        
        // insert the fragment & jump behind the last node in "pre"
        range.insertNode(fragment);
        range.setStartAfter(lastOfPre);
        
        range.collapse(true);
        sel.removeAllRanges();
        sel.addRange(range);
      }
    }
function ( value , strategy , e ) { var pre = this . getTextFromHeadToCaret ( ) ; // use ownerDocument instead of window to support iframes var sel = this . el . ownerDocument . getSelection ( ) ; var range = sel . getRangeAt ( 0 ) ; var selection = range . cloneRange ( ) ; selection . selectNodeContents ( range . startContainer ) ; var content = selection . toString ( ) ; var post = content . substring ( range . startOffset ) ; var newSubstr = strategy . replace ( value , e ) ; var regExp ; if ( typeof newSubstr !== 'undefined' ) { if ( $ . isArray ( newSubstr ) ) { post = newSubstr [ 1 ] + post ; newSubstr = newSubstr [ 0 ] ; } regExp = $ . isFunction ( strategy . match ) ? strategy . match ( pre ) : strategy . match ; pre = pre . replace ( regExp , newSubstr ) . replace ( /  $ / , "&nbsp" ) ; // &nbsp necessary at least for CKeditor to not eat spaces range . selectNodeContents ( range . startContainer ) ; range . deleteContents ( ) ; // create temporary elements var preWrapper = this . el . ownerDocument . createElement ( "div" ) ; preWrapper . innerHTML = pre ; var postWrapper = this . el . ownerDocument . createElement ( "div" ) ; postWrapper . innerHTML = post ; // create the fragment thats inserted var fragment = this . el . ownerDocument . createDocumentFragment ( ) ; var childNode ; var lastOfPre ; while ( childNode = preWrapper . firstChild ) { lastOfPre = fragment . appendChild ( childNode ) ; } while ( childNode = postWrapper . firstChild ) { fragment . appendChild ( childNode ) ; } // insert the fragment & jump behind the last node in "pre" range . insertNode ( fragment ) ; range . setStartAfter ( lastOfPre ) ; range . collapse ( true ) ; sel . removeAllRanges ( ) ; sel . addRange ( range ) ; } }
Update the content with the given value and strategy. When an dropdown item is selected, it is executed.
Update the content with the given value and strategy . When an dropdown item is selected it is executed .