只读模式
group, 分享
评论更多问题
博客标签总是存在一个
This commit is contained in:
lealife
2015-06-15 18:01:48 +08:00
parent 7e458bb433
commit 6987a38820
1453 changed files with 114561 additions and 91536 deletions

101
public/tinymce/classes/html/Styles.js Normal file → Executable file
View File

@ -29,14 +29,20 @@
define("tinymce/html/Styles", [], function() {
return function(settings, schema) {
/*jshint maxlen:255 */
/*eslint max-len:0 */
var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
trimRightRegExp = /\s+$/,
undef, i, encodingLookup = {}, encodingItems, invisibleChar = '\uFEFF';
undef, i, encodingLookup = {}, encodingItems, validStyles, invalidStyles, invisibleChar = '\uFEFF';
settings = settings || {};
if (schema) {
validStyles = schema.getValidStyles();
invalidStyles = schema.getInvalidStyles();
}
encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' ');
for (i = 0; i < encodingItems.length; i++) {
encodingLookup[encodingItems[i]] = invisibleChar + i;
@ -78,38 +84,42 @@ define("tinymce/html/Styles", [], function() {
var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter;
var urlConverterScope = settings.url_converter_scope || this;
function compress(prefix, suffix) {
function compress(prefix, suffix, noJoin) {
var top, right, bottom, left;
// IE 11 will produce a border-image: none when getting the style attribute from <p style="border: 1px solid red"></p>
// So lets asume it shouldn't be there
if (styles['border-image'] === 'none') {
delete styles['border-image'];
}
// Get values and check it it needs compressing
top = styles[prefix + '-top' + suffix];
if (!top) {
return;
}
right = styles[prefix + '-right' + suffix];
if (top != right) {
if (!right) {
return;
}
bottom = styles[prefix + '-bottom' + suffix];
if (right != bottom) {
if (!bottom) {
return;
}
left = styles[prefix + '-left' + suffix];
if (bottom != left) {
if (!left) {
return;
}
// Compress
styles[prefix + suffix] = left;
var box = [top, right, bottom, left];
i = box.length - 1;
while (i--) {
if (box[i] !== box[i + 1]) {
break;
}
}
if (i > -1 && noJoin) {
return;
}
styles[prefix + suffix] = i == -1 ? box[0] : box.join(' ');
delete styles[prefix + '-top' + suffix];
delete styles[prefix + '-right' + suffix];
delete styles[prefix + '-bottom' + suffix];
@ -122,7 +132,7 @@ define("tinymce/html/Styles", [], function() {
function canCompress(key) {
var value = styles[key], i;
if (!value || value.indexOf(' ') < 0) {
if (!value) {
return;
}
@ -197,8 +207,16 @@ define("tinymce/html/Styles", [], function() {
url = decode(url || url2 || url3);
if (!settings.allow_script_urls && /(java|vb)script:/i.test(url.replace(/[\s\r\n]+/, ''))) {
return "";
if (!settings.allow_script_urls) {
var scriptUrl = url.replace(/[\s\r\n]+/, '');
if (/(java|vb)script:/i.test(scriptUrl)) {
return "";
}
if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) {
return "";
}
}
// Convert the URL to relative/absolute depending on config
@ -223,8 +241,16 @@ define("tinymce/html/Styles", [], function() {
name = matches[1].replace(trimRightRegExp, '').toLowerCase();
value = matches[2].replace(trimRightRegExp, '');
// Decode escaped sequences like \65 -> e
/*jshint loopfunc:true*/
/*eslint no-loop-func:0 */
value = value.replace(/\\[0-9a-f]+/g, function(e) {
return String.fromCharCode(parseInt(e.substr(1), 16));
});
if (name && value.length > 0) {
if (!settings.allow_script_urls && (name == "behavior" || /expression\s*\(/.test(value))) {
// Don't allow behavior name or expression/comments within the values
if (!settings.allow_script_urls && (name == "behavior" || /expression\s*\(|\/\*|\*\//.test(value))) {
continue;
}
@ -245,9 +271,8 @@ define("tinymce/html/Styles", [], function() {
styleRegExp.lastIndex = matches.index + matches[0].length;
}
// Compress the styles to reduce it's size for example IE will expand styles
compress("border", "");
compress("border", "", true);
compress("border", "-width");
compress("border", "-color");
compress("border", "-style");
@ -259,6 +284,12 @@ define("tinymce/html/Styles", [], function() {
if (styles.border === 'medium none') {
delete styles.border;
}
// IE 11 will produce a border-image: none when getting the style attribute from <p style="border: 1px solid red"></p>
// So lets asume it shouldn't be there
if (styles['border-image'] === 'none') {
delete styles['border-image'];
}
}
return styles;
@ -269,16 +300,16 @@ define("tinymce/html/Styles", [], function() {
*
* @method serialize
* @param {Object} styles Object to serialize as string for example: {border: '1px solid red'}
* @param {String} element_name Optional element name, if specified only the styles that matches the schema will be serialized.
* @param {String} elementName Optional element name, if specified only the styles that matches the schema will be serialized.
* @return {String} String representation of the style object for example: border: 1px solid red.
*/
serialize: function(styles, element_name) {
serialize: function(styles, elementName) {
var css = '', name, value;
function serializeStyles(name) {
var styleList, i, l, value;
styleList = schema.styles[name];
styleList = validStyles[name];
if (styleList) {
for (i = 0, l = styleList.length; i < l; i++) {
name = styleList[i];
@ -291,18 +322,36 @@ define("tinymce/html/Styles", [], function() {
}
}
function isValid(name, elementName) {
var styleMap;
styleMap = invalidStyles['*'];
if (styleMap && styleMap[name]) {
return false;
}
styleMap = invalidStyles[elementName];
if (styleMap && styleMap[name]) {
return false;
}
return true;
}
// Serialize styles according to schema
if (element_name && schema && schema.styles) {
if (elementName && validStyles) {
// Serialize global styles and element specific styles
serializeStyles('*');
serializeStyles(element_name);
serializeStyles(elementName);
} else {
// Output the styles in the order they are inside the object
for (name in styles) {
value = styles[name];
if (value !== undef && value.length > 0) {
css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
if (!invalidStyles || isValid(name, elementName)) {
css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
}
}
}
}