File tree Expand file tree Collapse file tree 7 files changed +5954
-1
lines changed Expand file tree Collapse file tree 7 files changed +5954
-1
lines changed Original file line number Diff line number Diff line change
1
+ .vscode
2
+ example
3
+ node_modules
Original file line number Diff line number Diff line change 1
- # vue-screen-resize
1
+ # vue-not-visible
2
+
3
+ Vue directive for removing from dom (like v-if) element on screen smaller then breakpoints;
4
+
5
+ ## Install
6
+
7
+ ``` bash
8
+ $ npm install --save vue-not-visible
9
+ ```
10
+
11
+ ``` bash
12
+ $ yarn add vue-not-visible
13
+ ```
14
+
15
+
16
+ ## Use default
17
+
18
+ ``` js
19
+ import Vue from ' vue'
20
+ import vueNotVisible from ' vue-not-visible'
21
+
22
+ /* const BREAKPOINTS = {
23
+ mobile: 425,
24
+ tablet: 768,
25
+ tablet_landscape: 1024,
26
+ desktop: 1200,
27
+ desktop_large: 1440,
28
+ hd: 1920,
29
+ }
30
+ */
31
+ Vue .use (vueNotVisible) // this is default
32
+ Vue .use (vueNotVisible, {ipad: 1280 }) // this is custom
33
+
34
+ ```
35
+
36
+ ``` html
37
+ <template >
38
+ <div id =" test" >
39
+ {{ message }} {{ count }}
40
+ <div v-not-visible =" 'tablet'" >
41
+ <div v-on:click =" count = count + 1" >Not visible on table(screen < 768)</div >
42
+ </div >
43
+ <div v-not-visible =" 'mobile'" >
44
+ <div v-on:click =" count = count + 1" >Not visible on mobile(screen < 425)</div >
45
+ </div >
46
+ </div >
47
+ </template >
48
+ ```
49
+
50
+ ## Use custom breakpoints
51
+
52
+ ``` js
53
+ import Vue from ' vue'
54
+ import vueNotVisible from ' vue-not-visible'
55
+
56
+ Vue .use (vueNotVisible, {ipad: 1280 }) // this is custom
57
+
58
+ ```
59
+
60
+ ``` html
61
+ <template >
62
+ <div id =" test" >
63
+ {{ message }} {{ count }}
64
+ <div v-not-visible =" 'ipad'" >
65
+ <div v-on:click =" count = count + 1" >Not visible on ipad(screen < 1280)</div >
66
+ </div >
67
+ </div >
68
+ </template >
69
+ ```
70
+
71
+ ## License
72
+ [ MIT License] ( https://github.com/PxyUp/vue-not-visible/blob/master/LICENSE )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " vue-not-visible" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Vue directive for removing from dom (like v-if) element on screen smaller then breakpoints;" ,
5
+ "main" : " /src/index.js" ,
6
+ "repository" :
" [email protected] :PxyUp/vue-not-visible.git" ,
7
+ "author" :
" Yura Panarin <[email protected] >" ,
8
+ "license" : " MIT" ,
9
+ "scripts" : {
10
+ "build" : " webpack" ,
11
+ "precommit" : " yarn build && git add --all"
12
+ },
13
+ "devDependencies" : {
14
+ "clean-webpack-plugin" : " ^0.1.19" ,
15
+ "git-pre-commit" : " ^2.1.4" ,
16
+ "vue" : " ^2.5.17" ,
17
+ "webpack" : " ^4.16.5" ,
18
+ "webpack-bundle-analyzer" : " ^2.13.1" ,
19
+ "webpack-cli" : " ^3.1.0"
20
+ },
21
+ "engines" : {
22
+ "node" : " >=6"
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+
2
+ const BREAKPOINTS = {
3
+ mobile : 425 ,
4
+ tablet : 768 ,
5
+ tablet_landscape : 1024 ,
6
+ desktop : 1200 ,
7
+ desktop_large : 1440 ,
8
+ hd : 1920 ,
9
+ }
10
+
11
+ const plugin = {
12
+ install ( Vue , options ) {
13
+ const _breakpoints = options || BREAKPOINTS
14
+ const eventBus$ = new Vue ( ) ;
15
+ window . addEventListener ( 'resize' , ( ) => {
16
+ eventBus$ . $emit ( '$vueNotVisible' , window . innerWidth )
17
+ } )
18
+ Vue . directive ( 'not-visible' , {
19
+ bind ( el , binding ) {
20
+ let removeChild = document . createComment ( ' ' ) ;
21
+ if ( ! _breakpoints [ binding . value ] ) {
22
+ throw new Error ( `Missing breakpoint for ${ binding . value } ` )
23
+ }
24
+ eventBus$ . $on ( '$vueNotVisible' , value => {
25
+ if ( _breakpoints [ binding . value ] > value ) {
26
+ if ( el . parentNode ) {
27
+ el . parentNode . replaceChild ( removeChild , el )
28
+ }
29
+ } else {
30
+ if ( removeChild . parentNode ) {
31
+ removeChild . parentNode . replaceChild ( el , removeChild )
32
+ }
33
+ }
34
+ } )
35
+ } ,
36
+ inserted ( ) {
37
+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
38
+ }
39
+ } )
40
+ }
41
+ }
42
+
43
+ export default plugin
Original file line number Diff line number Diff line change
1
+ const CleanWebpackPlugin = require ( 'clean-webpack-plugin' ) ;
2
+ const BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin ;
3
+
4
+ module . exports = {
5
+ entry : "./src/index.js" ,
6
+ output : {
7
+ libraryTarget : "umd" ,
8
+ library : "vueNotVisible" ,
9
+ filename : "vue-not-visible.js"
10
+ } ,
11
+ resolve : {
12
+ extensions : [ ".js" ] ,
13
+ } ,
14
+ target : 'web' ,
15
+ mode : "production" ,
16
+ plugins : [
17
+ new CleanWebpackPlugin ( [ './dist' ] )
18
+ ] ,
19
+ } ;
You can’t perform that action at this time.
0 commit comments