Merge branch 'MDL-55012-master' of git://github.com/damyon/moodle
This commit is contained in:
+30
-8
@@ -1528,14 +1528,6 @@ EditorClean.prototype = {
|
||||
|
||||
// Run some more rules that care about quotes and whitespace.
|
||||
rules = [
|
||||
// Get all style attributes so we can work on them.
|
||||
{regex: /(<[^>]*?style\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO-blah, MSO:blah style attributes.
|
||||
group2 = group2.replace(/(?:^|;)[\s]*MSO[-:](?:&[\w]*;|[^;"])*/gi,"");
|
||||
// Remove backgroud color style.
|
||||
group2 = group2.replace(/background-color:.*?;/gi,"");
|
||||
return group1 + group2 + group3;
|
||||
}},
|
||||
// Get all class attributes so we can work on them.
|
||||
{regex: /(<[^>]*?class\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO classes.
|
||||
@@ -1548,6 +1540,9 @@ EditorClean.prototype = {
|
||||
{regex: /<a [^>]*?name\s*?=\s*?"OLE_LINK\d*?"[^>]*?>\s*?<\/a>/gi, replace: ""}
|
||||
];
|
||||
|
||||
// Clean all style attributes from the text.
|
||||
content = this._cleanStyles(content);
|
||||
|
||||
// Apply the rules.
|
||||
content = this._filterContentWithRules(content, rules);
|
||||
|
||||
@@ -1560,6 +1555,33 @@ EditorClean.prototype = {
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean all inline styles from pasted text.
|
||||
*
|
||||
* This code intentionally doesn't use YUI Nodes. YUI was quite a bit slower at this, so using raw DOM objects instead.
|
||||
*
|
||||
* @method _cleanStyles
|
||||
* @private
|
||||
* @param {String} content The content to clean
|
||||
* @return {String} The cleaned HTML
|
||||
*/
|
||||
_cleanStyles: function(content) {
|
||||
var holder = document.createElement('div');
|
||||
holder.innerHTML = content;
|
||||
var elementsWithStyle = holder.querySelectorAll('[style]');
|
||||
var i = 0;
|
||||
|
||||
for (i = 0; i < elementsWithStyle.length; i++) {
|
||||
elementsWithStyle[i].removeAttribute('style');
|
||||
}
|
||||
|
||||
var elementsWithClass = holder.querySelectorAll('[class]');
|
||||
for (i = 0; i < elementsWithClass.length; i++) {
|
||||
elementsWithClass[i].removeAttribute('class');
|
||||
}
|
||||
|
||||
return holder.innerHTML;
|
||||
},
|
||||
/**
|
||||
* Clean empty or un-unused spans from passed HTML.
|
||||
*
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
+30
-8
@@ -1516,14 +1516,6 @@ EditorClean.prototype = {
|
||||
|
||||
// Run some more rules that care about quotes and whitespace.
|
||||
rules = [
|
||||
// Get all style attributes so we can work on them.
|
||||
{regex: /(<[^>]*?style\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO-blah, MSO:blah style attributes.
|
||||
group2 = group2.replace(/(?:^|;)[\s]*MSO[-:](?:&[\w]*;|[^;"])*/gi,"");
|
||||
// Remove backgroud color style.
|
||||
group2 = group2.replace(/background-color:.*?;/gi,"");
|
||||
return group1 + group2 + group3;
|
||||
}},
|
||||
// Get all class attributes so we can work on them.
|
||||
{regex: /(<[^>]*?class\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO classes.
|
||||
@@ -1536,6 +1528,9 @@ EditorClean.prototype = {
|
||||
{regex: /<a [^>]*?name\s*?=\s*?"OLE_LINK\d*?"[^>]*?>\s*?<\/a>/gi, replace: ""}
|
||||
];
|
||||
|
||||
// Clean all style attributes from the text.
|
||||
content = this._cleanStyles(content);
|
||||
|
||||
// Apply the rules.
|
||||
content = this._filterContentWithRules(content, rules);
|
||||
|
||||
@@ -1548,6 +1543,33 @@ EditorClean.prototype = {
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean all inline styles from pasted text.
|
||||
*
|
||||
* This code intentionally doesn't use YUI Nodes. YUI was quite a bit slower at this, so using raw DOM objects instead.
|
||||
*
|
||||
* @method _cleanStyles
|
||||
* @private
|
||||
* @param {String} content The content to clean
|
||||
* @return {String} The cleaned HTML
|
||||
*/
|
||||
_cleanStyles: function(content) {
|
||||
var holder = document.createElement('div');
|
||||
holder.innerHTML = content;
|
||||
var elementsWithStyle = holder.querySelectorAll('[style]');
|
||||
var i = 0;
|
||||
|
||||
for (i = 0; i < elementsWithStyle.length; i++) {
|
||||
elementsWithStyle[i].removeAttribute('style');
|
||||
}
|
||||
|
||||
var elementsWithClass = holder.querySelectorAll('[class]');
|
||||
for (i = 0; i < elementsWithClass.length; i++) {
|
||||
elementsWithClass[i].removeAttribute('class');
|
||||
}
|
||||
|
||||
return holder.innerHTML;
|
||||
},
|
||||
/**
|
||||
* Clean empty or un-unused spans from passed HTML.
|
||||
*
|
||||
|
||||
+30
-8
@@ -287,14 +287,6 @@ EditorClean.prototype = {
|
||||
|
||||
// Run some more rules that care about quotes and whitespace.
|
||||
rules = [
|
||||
// Get all style attributes so we can work on them.
|
||||
{regex: /(<[^>]*?style\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO-blah, MSO:blah style attributes.
|
||||
group2 = group2.replace(/(?:^|;)[\s]*MSO[-:](?:&[\w]*;|[^;"])*/gi,"");
|
||||
// Remove backgroud color style.
|
||||
group2 = group2.replace(/background-color:.*?;/gi,"");
|
||||
return group1 + group2 + group3;
|
||||
}},
|
||||
// Get all class attributes so we can work on them.
|
||||
{regex: /(<[^>]*?class\s*?=\s*?")([^>"]*)(")/gi, replace: function(match, group1, group2, group3) {
|
||||
// Remove MSO classes.
|
||||
@@ -307,6 +299,9 @@ EditorClean.prototype = {
|
||||
{regex: /<a [^>]*?name\s*?=\s*?"OLE_LINK\d*?"[^>]*?>\s*?<\/a>/gi, replace: ""}
|
||||
];
|
||||
|
||||
// Clean all style attributes from the text.
|
||||
content = this._cleanStyles(content);
|
||||
|
||||
// Apply the rules.
|
||||
content = this._filterContentWithRules(content, rules);
|
||||
|
||||
@@ -319,6 +314,33 @@ EditorClean.prototype = {
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean all inline styles from pasted text.
|
||||
*
|
||||
* This code intentionally doesn't use YUI Nodes. YUI was quite a bit slower at this, so using raw DOM objects instead.
|
||||
*
|
||||
* @method _cleanStyles
|
||||
* @private
|
||||
* @param {String} content The content to clean
|
||||
* @return {String} The cleaned HTML
|
||||
*/
|
||||
_cleanStyles: function(content) {
|
||||
var holder = document.createElement('div');
|
||||
holder.innerHTML = content;
|
||||
var elementsWithStyle = holder.querySelectorAll('[style]');
|
||||
var i = 0;
|
||||
|
||||
for (i = 0; i < elementsWithStyle.length; i++) {
|
||||
elementsWithStyle[i].removeAttribute('style');
|
||||
}
|
||||
|
||||
var elementsWithClass = holder.querySelectorAll('[class]');
|
||||
for (i = 0; i < elementsWithClass.length; i++) {
|
||||
elementsWithClass[i].removeAttribute('class');
|
||||
}
|
||||
|
||||
return holder.innerHTML;
|
||||
},
|
||||
/**
|
||||
* Clean empty or un-unused spans from passed HTML.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user