Skip to content

Add background image support #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .naverc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v8
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Building
### Install prerequisites

```
sudo npm install -g gulp
sudo npm install -g gulp nave
```

### Build
Expand All @@ -37,12 +37,20 @@ sudo npm install -g gulp
git clone https://github.com/loadingio/loading-bar
cd loading-bar
npm install
nave auto
gulp
```

Built files will be written into `./build` directory


Releasing
=============

```
./gen-dist.sh
```

LICENSE
=============

Expand Down
83 changes: 82 additions & 1 deletion dist/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ wrap = function(content){
}
};
window.ldBar = ldBar = function(selector, option){
var xmlns, root, cls, idPrefix, id, domTree, newNode, x$, config, attr, that, isStroke, parseRes, dom, svg, text, group, length, path0, path1, patimg, img, ret, size, this$ = this;
var xmlns, root, cls, idPrefix, id, domTree, newNode, x$, config, attr, that, isStroke, parseRes, dom, svg, text, group, length, path0, path1, patimg, img, ret, size, img2, this$ = this;
option == null && (option = {});
xmlns = {
xlink: "http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -579,7 +579,88 @@ wrap = function(content){
return this$.inited = true;
});
img.src = config.img;
if (config.img2) {
if (config["img-size"]) {
ret = config["img-size"].split(',');
size = {
width: +ret[0],
height: +ret[1]
};
} else {
size = {
width: 100,
height: 100
};
}
group[0] = domTree('g', {
rect: {
attr: {
x: 0,
y: 0,
width: 100,
height: 100,
mask: "url(#" + id.mask + ")",
fill: config["fill-background"]
}
}
});
svg.querySelector('mask image').attrs({
width: size.width,
height: size.height
});
group[2] = domTree('g', {
image: {
attr: {
width: size.width,
height: size.height,
x: 0,
y: 0,
preserveAspectRatio: config["aspect-ratio"],
"xlink:href": config.img2,
'class': 'solid'
}
}
});
img2 = new Image();
img2.addEventListener('load', function(){
var ret, size, v;
if (config["img-size"]) {
ret = config["img-size"].split(',');
size = {
width: +ret[0],
height: +ret[1]
};
} else if (img2.width && img2.height) {
size = {
width: img2.width,
height: img2.height
};
} else {
size = {
width: 100,
height: 100
};
}
svg.querySelector('mask image').attrs({
width: size.width,
height: size.height
});
group[2].querySelector('image').attrs({
width: size.width,
height: size.height
});
this$.fit();
v = this$.value;
this$.value = undefined;
this$.set(v, true);
return this$.inited = true;
});
img2.src = config.img2;
}
svg.appendChild(group[0]);
if (config.img2) {
svg.appendChild(group[2]);
}
svg.appendChild(group[1]);
}
svg.attrs({
Expand Down
2 changes: 1 addition & 1 deletion dist/loading-bar.min.js

Large diffs are not rendered by default.

Binary file modified dist/loading-bar.zip
Binary file not shown.
15 changes: 8 additions & 7 deletions gen-dist → gen-dist.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/bin/env bash
N="./node_modules/.bin"
rm -r dist 2> /dev/null
mkdir -p dist
echo "build src/loading-bar.ls ..."
./node_modules/.bin/lsc -cbp src/loading-bar.ls > dist/loading-bar-raw.js
$N/lsc -cbp src/loading-bar.ls > dist/loading-bar-raw.js
echo "build src/presets.ls ..."
./node_modules/.bin/lsc -cbp src/presets.ls > dist/presets.js
$N/lsc -cbp src/presets.ls > dist/presets.js
echo "build src/loading-bar.styl -> dist/loading-bar.css ..."
./node_modules/.bin/stylus -p src/loading-bar.styl > dist/loading-bar.css
$N/stylus -p src/loading-bar.styl > dist/loading-bar.css
echo "bundle loading-bar ..."
./node_modules/.bin/browserify dist/loading-bar-raw.js > dist/loading-bar.js
$N/browserify dist/loading-bar-raw.js > dist/loading-bar.js
rm -f dist/loading-bar-raw.js
rm -f dist/presets.js

echo "minifying loading-bar.js ..."
./node_modules/.bin/uglifyjs dist/loading-bar.js > dist/loading-bar.min.js
$N/uglifyjs dist/loading-bar.js > dist/loading-bar.min.js
echo "minifying loading-bar.css ..."
./node_modules/.bin/uglifycss dist/loading-bar.css > dist/loading-bar.min.css
$N/uglifycss dist/loading-bar.css > dist/loading-bar.min.css

echo "zip loading-bar.js and loading-bar.css ..."
rm -f dist/loading-bar.zip
zip -r dist/loading-bar.zip dist/loading-bar.js dist/loading-bar.css dist/loading-bar.min.js dist/loading-bar.min.css

echo "done."
Expand Down
19 changes: 8 additions & 11 deletions gulpfile.ls
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
argv = require 'yargs' .argv
only-compile = false
only-compile = argv.only-compile


require! <[ watchify gulp browserify glob path fs globby touch gulp-livescript]>
Expand Down Expand Up @@ -57,7 +57,7 @@ for-browserify =


# Organize Tasks
gulp.task \default, ->
gulp.task \default, (done) ->
do function run-all
gulp.start do
\lib
Expand All @@ -67,8 +67,9 @@ gulp.task \default, ->
\compressjs
...

watch for-browserify, ->
gulp.start \browserify
if argv.only-compile
return done!

watch ["#{src-path}/*.styl"], ->
gulp.start \css
watch ["#{src-path}/*.ls"], ->
Expand All @@ -79,24 +80,21 @@ gulp.task \default, ->
gulp.start \compressjs


browserify-cache = {}
bundler = browserify do
entries: ls-entry-file
debug: true
paths:
src-path
...
extensions: <[ .ls ]>
cache: browserify-cache
package-cache: {}
cache: {} # required for watchify
package-cache: {} # required for watchify
plugin:
watchify unless only-compile
...

bundler.transform browserify-livescript

first-browserify-done = no

function bundle
bundler
.bundle!
Expand All @@ -115,9 +113,8 @@ function bundle
#.pipe sourcemaps.write '.'
.pipe gulp.dest out-dir
.pipe tap (file) ->
log-info \browserify, "Browserify finished #{if out-dir isnt build-path then "out-dir: #{out-dir}"}"
log-info \browserify, "Browserify finished."
console.log "------------------------------------------"
first-browserify-done := yes

gulp.task \browserify, ->
bundle!
Expand Down
99 changes: 93 additions & 6 deletions lib/loading-bar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var presets, simpleStr, wrap, slice$ = [].slice, toString$ = {}.toString;
var presets, simpleStr, wrap, toString$ = {}.toString;
presets = require('./presets').presets;
simpleStr = function(arr){
return arr.join('');
Expand All @@ -13,10 +13,14 @@ wrap = function(content){
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"" + viewBox + "\">";
},
gradient: function(dir, dur){
var colors, ret, len, gx, gy, x, y, i$, i, idx;
var colors, res$, i$, to$, ret, len, gx, gy, x, y, i, idx;
dir == null && (dir = 45);
dur == null && (dur = 1);
colors = slice$.call(arguments, 2);
res$ = [];
for (i$ = 2, to$ = arguments.length; i$ < to$; ++i$) {
res$.push(arguments[i$]);
}
colors = res$;
ret = [this.head("0 0 100 100")];
len = colors.length * 4 + 1;
dir = dir * Math.PI / 180;
Expand Down Expand Up @@ -118,7 +122,7 @@ wrap = function(content){
}
};
window.ldBar = ldBar = function(selector, option){
var xmlns, root, cls, idPrefix, id, domTree, newNode, x$, config, attr, that, isStroke, parseRes, dom, svg, text, group, length, path0, path1, patimg, img, ret, size, this$ = this;
var xmlns, root, cls, idPrefix, id, domTree, newNode, x$, config, attr, that, isStroke, parseRes, dom, svg, text, group, length, path0, path1, patimg, img, ret, size, img2, this$ = this;
option == null && (option = {});
xmlns = {
xlink: "http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -544,7 +548,7 @@ wrap = function(content){
});
img = new Image();
img.addEventListener('load', function(){
var ret, size;
var ret, size, v;
if (config["img-size"]) {
ret = config["img-size"].split(',');
size = {
Expand All @@ -571,11 +575,94 @@ wrap = function(content){
height: size.height
});
this$.fit();
this$.set(undefined, false);
v = this$.value;
this$.value = undefined;
this$.set(v, true);
return this$.inited = true;
});
img.src = config.img;
if (config.img2) {
if (config["img-size"]) {
ret = config["img-size"].split(',');
size = {
width: +ret[0],
height: +ret[1]
};
} else {
size = {
width: 100,
height: 100
};
}
group[0] = domTree('g', {
rect: {
attr: {
x: 0,
y: 0,
width: 100,
height: 100,
mask: "url(#" + id.mask + ")",
fill: config["fill-background"]
}
}
});
svg.querySelector('mask image').attrs({
width: size.width,
height: size.height
});
group[2] = domTree('g', {
image: {
attr: {
width: size.width,
height: size.height,
x: 0,
y: 0,
preserveAspectRatio: config["aspect-ratio"],
"xlink:href": config.img2,
'class': 'solid'
}
}
});
img2 = new Image();
img2.addEventListener('load', function(){
var ret, size, v;
if (config["img-size"]) {
ret = config["img-size"].split(',');
size = {
width: +ret[0],
height: +ret[1]
};
} else if (img2.width && img2.height) {
size = {
width: img2.width,
height: img2.height
};
} else {
size = {
width: 100,
height: 100
};
}
svg.querySelector('mask image').attrs({
width: size.width,
height: size.height
});
group[2].querySelector('image').attrs({
width: size.width,
height: size.height
});
this$.fit();
v = this$.value;
this$.value = undefined;
this$.set(v, true);
return this$.inited = true;
});
img2.src = config.img2;
}
svg.appendChild(group[0]);
if (config.img2) {
svg.appendChild(group[2]);
}
svg.appendChild(group[1]);
}
svg.attrs({
Expand Down
Loading