├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── dist └── vue-not-visible.js ├── docs ├── .nojekyll ├── index.html └── js │ └── vue-not-visible.js ├── package.json ├── src └── index.js ├── webpack.config.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | example 3 | node_modules -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at tduble94@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Юра Панарин 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-not-visible 2 | 3 | Vue directive for conditional rendering (like v-if) element on screen smaller than breakpoints; 4 | 5 | [![NPM](https://nodei.co/npm/vue-not-visible.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-not-visible/) 6 | 7 | 8 | 📺 [Demo](https://pxyup.github.io/vue-not-visible/index.html) 9 | 10 | ## Install 11 | 12 | ```bash 13 | $ npm install --save vue-not-visible 14 | ``` 15 | 16 | ```bash 17 | $ yarn add vue-not-visible 18 | ``` 19 | 20 | 21 | ## Use default 22 | 23 | ```js 24 | import Vue from 'vue' 25 | import vueNotVisible from 'vue-not-visible' 26 | 27 | /* const BREAKPOINTS = { 28 | mobile: 425, 29 | tablet: 768, 30 | tablet_landscape: 1024, 31 | desktop: 1200, 32 | desktop_large: 1440, 33 | hd: 1920, 34 | } 35 | */ 36 | Vue.use(vueNotVisible) // this is default 37 | 38 | ``` 39 | 40 | ```html 41 | 52 | ``` 53 | 54 | ## Use custom breakpoints 55 | 56 | ```js 57 | import Vue from 'vue' 58 | import vueNotVisible from 'vue-not-visible' 59 | 60 | Vue.use(vueNotVisible, {ipad: 1280}) // this is custom 61 | 62 | ``` 63 | 64 | ```html 65 | 73 | ``` 74 | 75 | ## License 76 | [MIT License](https://github.com/PxyUp/vue-not-visible/blob/master/LICENSE) -------------------------------------------------------------------------------- /dist/vue-not-visible.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vueNotVisible=t():e.vueNotVisible=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);const o={mobile:425,tablet:768,tablet_landscape:1024,desktop:1200,desktop_large:1440,hd:1920},r={install(e,t){const n=t||o,r=new e;window.addEventListener("resize",()=>{r.$emit("$vueNotVisible",window.innerWidth)}),e.directive("not-visible",{bind(e,t){let o=document.createComment(" ");if(!n[t.value])throw new Error(`Missing breakpoint for ${t.value}`);r.$on("$vueNotVisible",r=>{n[t.value]>r?e.parentNode&&e.parentNode.replaceChild(o,e):o.parentNode&&o.parentNode.replaceChild(e,o)})},inserted(){window.dispatchEvent(new Event("resize"))}})}};t.default=r}])}); -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PxyUp/vue-not-visible/54f72d85756c97e827b5c5e5ff3fbdb6ace03299/docs/.nojekyll -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 29 |
30 |
31 | {{ message }} You screen more than tablet > 768 32 |
33 |
34 | {{ message }} You screen more than mobile > 425 35 |
36 |
37 | {{ message }} You screen more than desktop > 1200 38 |
39 |
40 | 41 | 42 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /docs/js/vue-not-visible.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vueNotVisible=t():e.vueNotVisible=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);const o={mobile:425,tablet:768,tablet_landscape:1024,desktop:1200,desktop_large:1440,hd:1920},r={install(e,t){const n=t||o,r=new e;window.addEventListener("resize",()=>{r.$emit("$vueNotVisible",window.innerWidth)}),e.directive("not-visible",{bind(e,t){let o=document.createComment(" ");if(!n[t.value])throw new Error(`Missing breakpoint for ${t.value}`);r.$on("$vueNotVisible",r=>{n[t.value]>r?e.parentNode&&e.parentNode.replaceChild(o,e):o.parentNode&&o.parentNode.replaceChild(e,o)})},inserted(){window.dispatchEvent(new Event("resize"))}})}};t.default=r}])}); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-not-visible", 3 | "version": "1.0.9", 4 | "description": "Vue directive for conditional rendering (like v-if) element on screen smaller than breakpoints;", 5 | "main": "dist/vue-not-visible.js", 6 | "repository": "git@github.com:PxyUp/vue-not-visible.git", 7 | "author": "Yura Panarin ", 8 | "license": "MIT", 9 | "scripts": { 10 | "build": "webpack", 11 | "precommit": "yarn build && git add --all" 12 | }, 13 | "keywords": [ 14 | "Vuejs", 15 | "Vue", 16 | "vue2", 17 | "breakpoints", 18 | "responsive", 19 | "screen", 20 | "mobile", 21 | "helpers", 22 | "ui" 23 | ], 24 | "devDependencies": { 25 | "clean-webpack-plugin": "^0.1.19", 26 | "git-pre-commit": "^2.1.4", 27 | "vue": "^2.5.17", 28 | "webpack": "^4.16.5", 29 | "webpack-bundle-analyzer": "^2.13.1", 30 | "webpack-cli": "^3.1.0" 31 | }, 32 | "engines": { 33 | "node": ">=6" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 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 | }; --------------------------------------------------------------------------------