yellow: '#ff0'
},
- specialComments: [],
- contentBlocks: [],
-
process: function(data, options) {
- var self = this,
- replace = function(pattern, replacement) {
- if (typeof arguments[0] == 'function')
- arguments[0]();
- else
- data = data.replace.apply(data, arguments);
- };
+ var context = {
+ specialComments: [],
+ contentBlocks: []
+ };
+ var replace = function(pattern, replacement) {
+ if (typeof arguments[0] == 'function')
+ arguments[0]();
+ else
+ data = data.replace.apply(data, arguments);
+ };
options = options || {};
// strip comments one by one
replace(function stripComments() {
- data = self.stripComments(data);
+ data = CleanCSS._stripComments(context, data);
});
// replace content: with a placeholder
replace(function stripContent() {
- data = self.stripContent(data);
+ data = CleanCSS._stripContent(context, data);
});
replace(/;\s*;+/g, ';') // whitespace between semicolons & multiple semicolons
replace(/calc\([^\}]+\}/g, function(match) {
return match.replace(/\+/g, ' + ');
});
- replace(/__CSSCOMMENT__/g, function() { return self.specialComments.shift(); });
- replace(/__CSSCONTENT__/g, function() { return self.contentBlocks.shift(); });
+ replace(/__CSSCOMMENT__/g, function() { return context.specialComments.shift(); });
+ replace(/__CSSCONTENT__/g, function() { return context.contentBlocks.shift(); });
return data.trim() // trim spaces at beginning and end
},
// Strips special comments (/*! ... */) by replacing them by __CSSCOMMENT__ marker
// for further restoring. Plain comments are removed. It's done by scanning datq using
// String#indexOf scanning instead of regexps to speed up the process.
- stripComments: function(data) {
+ _stripComments: function(context, data) {
var tempData = [],
nextStart = 0,
nextEnd = 0,
tempData.push(data.substring(cursor, nextStart))
if (data[nextStart + 2] == '!') {
// in case of special comments, replace them with a placeholder
- this.specialComments.push(data.substring(nextStart, nextEnd + 2));
+ context.specialComments.push(data.substring(nextStart, nextEnd + 2));
tempData.push('__CSSCOMMENT__');
}
cursor = nextEnd + 2;
// Strips content tags by replacing them by __CSSCONTENT__ marker
// for further restoring. It's done via string scanning instead of
// regexps to speed up the process.
- stripContent: function(data) {
+ _stripContent: function(context, data) {
var tempData = [],
nextStart = 0,
nextEnd = 0,
tempData.push(data.substring(cursor, nextStart - 1));
tempData.push('__CSSCONTENT__');
- this.contentBlocks.push(data.substring(nextStart - 1, nextEnd + 1));
+ context.contentBlocks.push(data.substring(nextStart - 1, nextEnd + 1));
cursor = nextEnd + 1;
}