Remove newlines (contenteditable experiment)

From CODECS Dev
Draft/446099

Remove newlines (contenteditable experiment)

Relies on Gadgets extension. See also old Common.js?

On blur method

Source: https://stackoverflow.com/questions/425274/prevent-line-paragraph-breaks-in-contenteditable

Removes newlines when the input loses focus (blur event). The advantage is that it will also cater for newlines that have been copied and pasted.

{{#tag:html
|<span onblur="handle_blur(event)" class="form-control form-control-contenteditable" contenteditable>editable text here</span>
}}

function handle_blur(evt){
  var elt=evt.target; elt.innerText=elt.innerText.replace(/\n/g,' ');
}
keypress + copy/paste method

https://jsfiddle.net/b8bb8rwv/3/ Gadget:Contenteditable-flow-sans-newlines.js

Removes newlines when the input loses focus (blur event). The advantage is that it will also cater for newlines that have been copied and pasted.

$('[contenteditable]').on('paste', function(e) {
	var $self = $(this);
	setTimeout(function() {
		$self.html($self.text());
	}, 0);
}).on('keypress', function(e) {
	return e.which != 13;
});

(currently in a gadget)