Skip to content

Commit e61f69c

Browse files
committed
fix(taSanitize): copy code to lib/factories.js (#424)
1 parent e3c9cf6 commit e61f69c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lib/factories.js

+51
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,58 @@ angular.module('textAngular.factories', [])
5656
};
5757
return taFixChrome;
5858
}).factory('taSanitize', ['$sanitize', function taSanitizeFactory($sanitize){
59+
60+
var convert_info = {
61+
'font-weight': {
62+
values: [ 'bold' ],
63+
tag: 'b'
64+
},
65+
'font-style': {
66+
values: [ 'italic' ],
67+
tag: 'i'
68+
}
69+
};
70+
71+
function fixChildren( jq_elm ) {
72+
var children = jq_elm.children();
73+
if ( !children.length ) {
74+
return;
75+
}
76+
angular.forEach( children, function( child ) {
77+
var jq_child = angular.element(child);
78+
fixElement( jq_child );
79+
fixChildren( jq_child );
80+
});
81+
}
82+
83+
function fixElement( jq_elm ) {
84+
var styleString = jq_elm.attr('style');
85+
if ( !styleString ) {
86+
return;
87+
}
88+
angular.forEach( convert_info, function( css_info, css_key ) {
89+
var css_value = jq_elm.css(css_key);
90+
if ( css_info.values.indexOf(css_value) >= 0 && styleString.indexOf(css_key) >= 0 ) {
91+
jq_elm.css( css_key, '' );
92+
var inner_html = jq_elm.html();
93+
var tag = css_info.tag;
94+
inner_html = '<'+tag+'>' + inner_html + '</'+tag+'>';
95+
jq_elm.html( inner_html );
96+
}
97+
});
98+
}
99+
59100
return function taSanitize(unsafe, oldsafe, ignore){
101+
102+
if ( !ignore ) {
103+
try {
104+
var jq_container = angular.element('<div>' + unsafe + '</div>');
105+
fixChildren( jq_container );
106+
unsafe = jq_container.html();
107+
} catch (e) {
108+
}
109+
}
110+
60111
// unsafe and oldsafe should be valid HTML strings
61112
// any exceptions (lets say, color for example) should be made here but with great care
62113
// setup unsafe element for modification

0 commit comments

Comments
 (0)