On cleanup remove also id and data- attributes.

This commit is contained in:
Martin Edenhofer 2016-05-12 15:22:34 +02:00
parent 5e7468e8a8
commit bee011d030
3 changed files with 25 additions and 3 deletions

View file

@ -205,13 +205,16 @@ class App.Utils
.removeAttr('title')
.removeAttr('lang')
.removeAttr('type')
.removeAttr('id')
.removeAttrs(/data-/)
html
.removeAttr('style')
.removeAttr('class')
.removeAttr('title')
.removeAttr('lang')
.removeAttr('type')
.removeAttr('id')
.removeAttrs(/data-/)
html
@_removeComments: (html) ->

View file

@ -174,13 +174,27 @@ jQuery.event.special.remove = {
// native checkbox focus behaviour is the following:
// tab to checkbox: :focus state and focus outline
// click on checkbox: :focus state but no focus outline
$('body').on('click', '.checkbox-replacement, .radio-replacement', function(event){
$('body').on('click', '.checkbox-replacement, .radio-replacement', function(event){
$(event.currentTarget).find('input').addClass('is-active')
});
$('body').on('blur', '.checkbox-replacement input, .radio-replacement input', function(){
$('body').on('blur', '.checkbox-replacement input, .radio-replacement input', function(){
$(this).removeClass('is-active')
});
// remove attributes by regex
// http://stackoverflow.com/questions/8968767/remove-multiple-html5-data-attributes-with-jquery
jQuery.fn.removeAttrs = function(regex) {
return this.each(function() {
var $this = $(this),
names = [];
$.each(this.attributes, function(i, attr) {
if (attr && attr.specified && regex.test(attr.name)) {
$this.removeAttr(attr.name);
}
});
});
};
// start application
jQuery(function(){
new App.Run();

View file

@ -432,6 +432,11 @@ test("htmlCleanup", function() {
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "<div><p id=\"123\" data-id=\"abc\">some link to somewhere</p></div>"
should = "<p>some link to somewhere</p>"
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "<div><small>some link to somewhere</small></a>"
//should = "<div>some link to somewhere</div>"
should = "some link to somewhere"