Changeset 668
- Timestamp:
- 06/14/10 21:06:06 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wymeditor/jquery.wymeditor.js
r655 r668 1215 1215 }; 1216 1216 1217 WYMeditor.editor.prototype.paste = function(sData) { 1218 1219 var sTmp; 1220 var container = this.selected(); 1221 1222 //split the data, using double newlines as the separator 1223 var aP = sData.split(this._newLine + this._newLine); 1224 var rExp = new RegExp(this._newLine, "g"); 1225 1226 //add a P for each item 1227 if(container && container.tagName.toLowerCase() != WYMeditor.BODY) { 1228 for(x = aP.length - 1; x >= 0; x--) { 1229 sTmp = aP[x]; 1230 //simple newlines are replaced by a break 1231 sTmp = sTmp.replace(rExp, "<br />"); 1232 jQuery(container).after("<p>" + sTmp + "</p>"); 1233 } 1234 } else { 1235 for(x = 0; x < aP.length; x++) { 1236 sTmp = aP[x]; 1237 //simple newlines are replaced by a break 1238 sTmp = sTmp.replace(rExp, "<br />"); 1239 jQuery(this._doc.body).append("<p>" + sTmp + "</p>"); 1240 } 1241 1242 } 1217 /* @name paste 1218 * @description Paste text into the editor below the carret, 1219 * used for "Paste from Word". 1220 * @param String str String to insert, two or more newlines separates 1221 * paragraphs. May contain inline HTML. 1222 */ 1223 WYMeditor.editor.prototype.paste = function(str) { 1224 var container = this.selected(), 1225 html = '', 1226 paragraphs, 1227 focusNode; 1228 1229 // Split string into paragraphs by two or more newlines 1230 paragraphs = str.split(new RegExp(this._newLine + '{2,}', 'g')); 1231 1232 // Build html 1233 for (var i=0, l=paragraphs.length; i < l; i++) { 1234 html += '<p>' + 1235 ( paragraphs[i].split(this._newLine).join('<br />') ) + 1236 '</p>'; 1237 } 1238 1239 // Insert where appropriate 1240 if (container && container.tagName.toLowerCase() != WYMeditor.BODY) { 1241 // No .last() pre jQuery 1.4 1242 //focusNode = jQuery(html).insertAfter(container).last()[0]; 1243 paragraphs = jQuery(html, this._doc).insertAfter(container); 1244 focusNode = paragraphs[paragraphs.length - 1]; 1245 } else { 1246 paragraphs = jQuery(html, this._doc).appendTo(this._doc.body); 1247 focusNode = paragraphs[paragraphs.length - 1]; 1248 } 1249 1250 // Do some minor cleanup (#131) 1251 if (jQuery(container).text() == '') { 1252 jQuery(container).remove(); 1253 } 1254 // And remove br (if editor was empty) 1255 jQuery('body > br', this._doc).remove(); 1256 1257 // Restore focus 1258 this.setFocusToNode(focusNode); 1243 1259 }; 1244 1260
Note: See TracChangeset
for help on using the changeset viewer.