2017-07-15 17:48:46 +02:00
|
|
|
( function () {
|
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.sanitize
|
|
|
|
*
|
|
|
|
* Helper functions to sanitize strings.
|
|
|
|
*/
|
|
|
|
wp.sanitize = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip HTML tags.
|
|
|
|
*
|
|
|
|
* @param {string} text Text to have the HTML tags striped out of.
|
|
|
|
*
|
|
|
|
* @return Stripped text.
|
|
|
|
*/
|
|
|
|
stripTags: function( text ) {
|
|
|
|
text = text || '';
|
|
|
|
|
|
|
|
return text
|
|
|
|
.replace( /<!--[\s\S]*?(-->|$)/g, '' )
|
|
|
|
.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
|
|
|
|
.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip HTML tags and convert HTML entities.
|
|
|
|
*
|
|
|
|
* @param {string} text Text to strip tags and convert HTML entities.
|
|
|
|
*
|
|
|
|
* @return Sanitized text. False on failure.
|
|
|
|
*/
|
2017-10-04 20:58:47 +02:00
|
|
|
stripTagsAndEncodeText: function( text ) {
|
2017-09-14 21:29:44 +02:00
|
|
|
var _text = wp.sanitize.stripTags( text ),
|
2017-07-15 17:48:46 +02:00
|
|
|
textarea = document.createElement( 'textarea' );
|
|
|
|
|
|
|
|
try {
|
|
|
|
textarea.innerHTML = _text;
|
2017-09-14 21:29:44 +02:00
|
|
|
_text = wp.sanitize.stripTags( textarea.value );
|
2017-07-15 17:48:46 +02:00
|
|
|
} catch ( er ) {}
|
|
|
|
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}() );
|