;var monotype = monotype || (function(monotype){ monotype.range = function(n){ var R, s, t, n = n || 0, win = monotype.win || window, doc = win.document; if(!arguments.length) return doc.createRange(); if(!(win.Range && R instanceof Range)){ s = win.getSelection? win.getSelection() : {}; if(s.rangeCount){ R = s.getRangeAt(n); } else { if(doc.createRange){ R = doc.createRange(); R.setStart(doc.body, 0); } else if (doc.selection){ // '+n+'').contents():$(document.createTextNode(n)); } m.get = function(d){ if(u === d){ return $([m.R.startContainer, m.R.endContainer]) } return monotype.deep((d = (d && d > 0))? m.R.endContainer : m.R.startContainer , d? m.R.endOffset : m.R.startOffset).container; } m.remove = function(n,R){ R = m.R || m.range(); R.deleteContents(); monotype.restore(R); m = monotype(m,opt); return m; } m.insert = function(n,R){ n = jqtxt(n); R = m.R || m.range(); R.deleteContents(); $(n.get().reverse()).each(function(){ R.insertNode(this); }); R.selectNodeContents(n.last()[0]); monotype.restore(R); m = monotype(m,opt); return m; } m.wrap = function(n,R){ var jq; n = jqtxt(n); n = n[0]; R = m.R || m.range(); if(monotype.text(R.startContainer) || monotype.text(R.endContainer)){ var b = R.cloneContents(); R.deleteContents(); jq = $(n); jq.html(b); jq = jq[0]; R.insertNode(jq); }else{ R.surroundContents(n); } R.selectNodeContents(jq||n); monotype.restore(R); m = monotype(m,opt); return m; } m.select = function(n,i,e,j){ var R = m.R || m.range(), t = e; n = $(n); if($.isNumeric(e)){ e = j || n; j = t; } else { e = e || n; } j = $.isNumeric(j)? j : $.isNumeric(i)? i : Infinity; i = i || 0; if(i < 0){ t = n.contents().length || n.text().length; i = t + i; } if(j < 0){ t = n.contents().length || n.text().length; j = t + j; } if(j === Infinity){ R.selectNodeContents(n[0]); } else { R.setStart(n[0],i); R.setEnd(e[0],j); } monotype.restore(R); m = monotype(m,opt); return m; } return m; }