Skip to content

Commit

Permalink
fix(taSanitize): copy code to lib/factories.js (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
marbug committed Dec 12, 2014
1 parent e3c9cf6 commit e61f69c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,58 @@ angular.module('textAngular.factories', [])
};
return taFixChrome;
}).factory('taSanitize', ['$sanitize', function taSanitizeFactory($sanitize){

var convert_info = {
'font-weight': {
values: [ 'bold' ],
tag: 'b'
},
'font-style': {
values: [ 'italic' ],
tag: 'i'
}
};

function fixChildren( jq_elm ) {
var children = jq_elm.children();
if ( !children.length ) {
return;
}
angular.forEach( children, function( child ) {
var jq_child = angular.element(child);
fixElement( jq_child );
fixChildren( jq_child );
});
}

function fixElement( jq_elm ) {
var styleString = jq_elm.attr('style');
if ( !styleString ) {
return;
}
angular.forEach( convert_info, function( css_info, css_key ) {
var css_value = jq_elm.css(css_key);
if ( css_info.values.indexOf(css_value) >= 0 && styleString.indexOf(css_key) >= 0 ) {
jq_elm.css( css_key, '' );
var inner_html = jq_elm.html();
var tag = css_info.tag;
inner_html = '<'+tag+'>' + inner_html + '</'+tag+'>';
jq_elm.html( inner_html );
}
});
}

return function taSanitize(unsafe, oldsafe, ignore){

if ( !ignore ) {
try {
var jq_container = angular.element('<div>' + unsafe + '</div>');
fixChildren( jq_container );
unsafe = jq_container.html();
} catch (e) {
}
}

// unsafe and oldsafe should be valid HTML strings
// any exceptions (lets say, color for example) should be made here but with great care
// setup unsafe element for modification
Expand Down

0 comments on commit e61f69c

Please sign in to comment.