Skip to content

Commit b913900

Browse files
committed
added bundle and improvements
1 parent 6b512b0 commit b913900

File tree

8 files changed

+74
-42
lines changed

8 files changed

+74
-42
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ node_modules
22
*.sublime-project
33
*.sublime-workspace
44
npm-debug.log
5-
build
5+
build/bundle.js
66
dev/index.js
77
static
88
*.js

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ node_modules
22
*.sublime-project
33
*.sublime-workspace
44
npm-debug.log
5-
build
65
dev/index.js
76
static

README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,47 @@ To mask out the background when a dialog / modal or similar is opened, a overlay
44

55
### [See it in action](https://vue-comps.github.io/vue-overlay)
66

7-
Only for [**webpack**](https://webpack.github.io/) workflows.
8-
9-
107
# Install
118

129
```sh
1310
npm install --save-dev vue-overlay
1411
```
12+
or include `build/bundle.js`
1513

1614
## Usage
1715
```coffee
18-
overlay = require("../overlay.js")(Vue) # overlay is a singleton
19-
20-
zindex = overlay.open(options) # returns the z-index of the overlay + 1
16+
# overlay is a singleton and is designed
17+
# to be used in different places simultaniously
18+
overlay = require("vue-overlay")(Vue)
19+
# or, when using bundle.js
20+
overlay = window.vueComps.overlay
21+
22+
# returns the z-index of the overlay + 1 (starts with 1001)
23+
zindex = overlay.open(options)
24+
overlay.open() # z-index will raise by 5
25+
26+
# close hooks of the first options object will be called
27+
# and z-index will be lowered by 5
2128
overlay.close()
29+
overlay.close() # overlay really closes
30+
31+
# the overlay comes without animation, but you can easily set them up,
32+
# for example with velocity.js:
33+
Velocity = require("velocity-animate")
34+
overlay.fade = ({el,opacity,cb}) ->
35+
Velocity el, {opacity: opacity},
36+
{
37+
duration: 300
38+
queue: false
39+
easing: 'easeOutQuad'
40+
complete: cb
41+
}
2242
```
2343
#### Options
2444
| Name | type | default | description |
2545
| ---:| --- | ---| --- |
2646
| opacity | Number | 0.5 | opacity of the overlay |
27-
| dismissable | Boolean | true | Is the overlay dismissable by click or ESC? |
47+
| dismissable | Boolean | true | is the overlay dismissable by click or ESC? |
2848
| onBeforeOpen | Function | null | hook before open animation |
2949
| onOpened | Function | null | hook after open animation |
3050
| onBeforeClose | Function | null | hook before close animation |

build/common.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
window.vueComps ?= {}
2+
window.vueComps.overlay = require('../overlay.js')(Vue)

build/webpack.config.coffee

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
webpack = require "webpack"
2+
3+
module.exports =
4+
entry: "./build/common.coffee"
5+
output:
6+
filename: "bundle.js"
7+
path: __dirname
8+
module:
9+
loaders: [
10+
{ test: /\.coffee$/, loader: "coffee"}
11+
]
12+
plugins: [
13+
new webpack.optimize.UglifyJsPlugin compress: warnings: false
14+
new webpack.optimize.OccurenceOrderPlugin()
15+
]

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"node": "*"
1818
},
1919
"dependencies": {
20-
"velocity-animate": "^1.2.3",
2120
"vue-filters": "^0.1.6",
2221
"vue-mixins": "^0.2.2"
2322
},
@@ -47,6 +46,7 @@
4746
"karma-webpack": "^1.7.0",
4847
"mocha": "^2.4.5",
4948
"parse5": "^2.1.5",
49+
"script-runner": "^0.1.4",
5050
"style-loader": "^0.13.1",
5151
"stylus-loader": "^2.0.0",
5252
"template-html-loader": "0.0.3",
@@ -67,7 +67,9 @@
6767
],
6868
"readmeFilename": "README.md",
6969
"scripts": {
70-
"build": "NODE_ENV=production vue-compiler --out / src/*.vue",
70+
"build:vue": "NODE_ENV=production vue-compiler --out . src/*.vue",
71+
"build:webpack": "webpack --config build/webpack.config.coffee",
72+
"build": "run-npm build:*",
7173
"dev": "vue-dev-server",
7274
"watch": "karma start --browsers Chrome --auto-watch --reporters spec",
7375
"test": "karma start --single-run",

src/overlay-component.vue

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ div#overlay(
88
</template>
99

1010
<script lang="coffee">
11-
Velocity = require("velocity-animate")
12-
1311
module.exports =
1412
1513
mixins:[
@@ -32,6 +30,9 @@ module.exports =
3230
height: "120vh"
3331
"background-color": "black"
3432
"will-change": "opacity"
33+
fade: ({el,opacity,cb}) ->
34+
@style.opacity = opacity
35+
cb?()
3536
3637
el: -> document.createElement "div"
3738
@@ -48,14 +49,7 @@ module.exports =
4849
@stack.push options
4950
options.onBeforeOpen?()
5051
@style["z-index"] += 5
51-
Velocity @$el, {opacity: options.opacity},
52-
{
53-
duration: 300
54-
queue: false
55-
easing: 'easeOutQuad'
56-
complete: options.onOpened
57-
}
58-
52+
@fade el:@$el, opacity:options.opacity, cb:options.onOpened
5953
return @style["z-index"]+1
6054
6155
close: ->
@@ -68,14 +62,7 @@ module.exports =
6862
opacity = @stack[@stack.length-1].opacity
6963
options.onBeforeClose?()
7064
@style["z-index"]-=5
71-
Velocity @$el, {opacity: opacity},
72-
{
73-
duration: 300
74-
queue: false
75-
easing: 'easeOutQuad'
76-
complete: =>
77-
78-
options.onClosed?()
79-
@$remove() if @stack.length == 0
80-
}
65+
@fade el:@$el, opacity:opacity, cb: =>
66+
options.onClosed?()
67+
@$remove() if @stack.length == 0
8168
</script>

test/overlay.coffee

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@ describe "overlay", ->
1414
env.overlay.$el.parentNode.nodeType.should.equal 11
1515

1616
it "should open first overlay", (done) ->
17-
env.openOverlay()
18-
env.firstOpened.should.be.true
19-
env.overlay.style["z-index"].should.equal 1000
20-
done()
17+
env.openOverlay ->
18+
env.$nextTick ->
19+
env.firstOpened.should.be.true
20+
if window.getComputedStyle
21+
style = window.getComputedStyle(env.overlay.$el)
22+
style.getPropertyValue("opacity").should.equal '0.5'
23+
env.overlay.style["z-index"].should.equal 1000
24+
done()
2125

2226
it "should open second overlay", (done) ->
23-
env.openSecondOverlay()
24-
env.overlay.style["z-index"].should.equal 1005
25-
env.overlay.close()
26-
env.overlay.close()
27-
done()
27+
env.openSecondOverlay ->
28+
env.$nextTick ->
29+
if window.getComputedStyle
30+
style = window.getComputedStyle(env.overlay.$el)
31+
style.getPropertyValue("opacity").should.equal '0.6'
32+
env.overlay.style["z-index"].should.equal 1005
33+
env.overlay.close()
34+
env.overlay.close()
35+
done()
2836

2937
it "should not close when not dismissable", (done) ->
30-
env.overlay.open(dismissable:false)
38+
env.overlay.open(dismissable:false,onClosed:done)
3139
env.overlay.dismiss()
3240
env.overlay.stack.length.should.equal 1
3341
env.overlay.close()
34-
done()

0 commit comments

Comments
 (0)