fis-spriter-csssprites
Advanced tools
Comparing version 0.1.2 to 0.1.3
12
index.js
@@ -22,2 +22,4 @@ /** | ||
} | ||
//文件属性中useSprite == true的css做图片合并 | ||
@@ -38,6 +40,12 @@ fis.util.map(ret.src, function(subpath, file) { | ||
function _process(file, ret, settings, opt) { | ||
var res = cssParser(file.getContent()); | ||
var images = {}; | ||
fis.util.map(ret.src, function (subpath, file) { | ||
if (file.isImage()) { | ||
images[file.getUrl(opt.hash, opt.domain)] = file; | ||
} | ||
}); | ||
var res = cssParser(file.getContent(), images); | ||
var content = res.content; | ||
if (res.map && res.map.length > 0) { | ||
var css = imgGen(file, res.map, ret, settings, opt); | ||
var css = imgGen(file, res.map, images, ret, settings, opt); | ||
content = content + css; | ||
@@ -44,0 +52,0 @@ } |
@@ -9,3 +9,3 @@ /** | ||
var Rules = require('./css/rules.js'); | ||
module.exports = function (content) { | ||
module.exports = function (content, images) { | ||
var _arr_css = [] | ||
@@ -17,3 +17,3 @@ , _content; | ||
var rules = Rules.wrap(selector.trim(), css.trim()); | ||
if (rules.isSprites()) { | ||
if (rules.isSprites() && images.hasOwnProperty(rules.getImageUrl())) { | ||
_arr_css.push(rules); | ||
@@ -20,0 +20,0 @@ css = rules.getCss(); |
@@ -9,8 +9,8 @@ /* | ||
module.exports = function(file, list, ret, settings, opt) { | ||
var gen = new Generator(file, list, ret, settings, opt); | ||
module.exports = function(file, list, images, ret, settings, opt) { | ||
var gen = new Generator(file, list, images, ret, settings, opt); | ||
return gen.css; | ||
}; | ||
function Generator(file, list, ret, settings, opt) { | ||
function Generator(file, list, images, ret, settings, opt) { | ||
var default_settings = { | ||
@@ -40,2 +40,3 @@ 'margin': 3, | ||
this.css = ''; | ||
this.images = images; | ||
@@ -61,12 +62,4 @@ var list_x = []; | ||
getImage: function(release) { | ||
var i; | ||
for (i in this.ret.src) { | ||
if (this.ret.src.hasOwnProperty(i) | ||
&& this.ret.src[i].getUrl(this.opt.hash, this.opt.domain) == release) { | ||
if (this.ret.src[i].release != false) { | ||
return this.ret.src[i]; | ||
} else { | ||
break; | ||
} | ||
} | ||
if (this.images.hasOwnProperty(release)) { | ||
return this.images[release]; | ||
} | ||
@@ -73,0 +66,0 @@ return false; |
{ | ||
"name": "fis-spriter-csssprites", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "基于fis的csssprite,支持repeat-x,repeat-x,background-position", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25510
579