{"id":16190586,"url":"https://github.com/linusborg/vue-directive-clickout","last_synced_at":"2025-03-19T03:30:56.606Z","repository":{"id":66114592,"uuid":"69445592","full_name":"LinusBorg/vue-directive-clickout","owner":"LinusBorg","description":"a directive to catch clicks outside of an element, compatible with Vue 2.0 only","archived":false,"fork":false,"pushed_at":"2017-09-12T20:27:58.000Z","size":278,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-02-28T15:08:54.745Z","etag":null,"topics":["vue"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LinusBorg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-28T09:03:18.000Z","updated_at":"2022-01-02T06:36:30.000Z","dependencies_parsed_at":"2023-02-20T18:00:48.186Z","dependency_job_id":null,"html_url":"https://github.com/LinusBorg/vue-directive-clickout","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusBorg%2Fvue-directive-clickout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusBorg%2Fvue-directive-clickout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusBorg%2Fvue-directive-clickout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusBorg%2Fvue-directive-clickout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LinusBorg","download_url":"https://codeload.github.com/LinusBorg/vue-directive-clickout/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965723,"owners_count":20375920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vue"],"created_at":"2024-10-10T07:43:38.070Z","updated_at":"2025-03-19T03:30:56.231Z","avatar_url":"https://github.com/LinusBorg.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-directive-clickout\n\n\u003e a small Vue 2.0 directive to detect clicks outside of an element and run a callback function.\n\n## Installation\n\n### NPM\n\nInstall the package from npm\n```\nnpm install --save vue-directive-clickout\n```\nLoad it in your main js file and register it:\n```js\nimport VueDirectiveClickout from 'vue-directive-clickout'\n\n// register it globally\nVue.directive('clickout', VueDirectiveClickout)\n\n// you can also register it locally in individual components only:\nexport default {\n  // other component options...\n  directives: {\n    'clickout': VueClickoutDirective\n  }\n}\n```\n\n### Via script tag\n\nInsert the script tag after you import Vue:\n```html\n\u003cscript src=\"https://unpkg.com/vue@next/dist/vue.js\"\u003e\u003c/script\u003e\n```\n\nIt will be automatically registered globally (with Vue.component) as a directive with the name `v-clickout`\n\n\n## Usage\n\nSimply add the directive to any element for which you want to register clicks outside of (e.g. a modal window)\n```html\n\u003cdiv v-clickout=\"close\" class=\"modal-window\"\u003e\n\n\u003c/div\u003e\n```\nand provide a method by that name in your component. The method receives the event as an argument, just like it would for a normal click event.\n```js\nexport default {\n  // ... other component options\n  methods: {\n    close(event) {\n      console.log(event.target)\n    }\n  }\n}\n```\n\n### The `.bubble` modifier\n\nBy default, click events *inside* of or *on* the element that the directive is defined on do not trigger the callback.\n\nYou can change this behaviour by adding the `.bubble` modifier:\n```html\n\u003cdiv v-clickout.bubble=\"close\" class=\"modal-window\"\u003e\n  \u003cbutton\u003eClick Me\u003c/button\u003e\n  \u003c!-- Clicking this button  (or anywhere inside of the div) will call the \"close\" callback --\u003e\n\u003c/div\u003e\n```\nThis may be useful to have e.g. an image modal that closes when you click *anywhere*, including the image.\n\n### The `.visible` modifier\n\nIf you add the `.visible` modifier, the callback will only be run if the element is visible\\*.\nThis is usefull if you can't toggle a v-clickout element with `v-if` (which would remove the element from the document, and therefore the directive \u0026 event) and instead have to rely on `v-show` (which adds `display: none` to the style attribute but keeps the element in the DOM) or something similar.\n\n\u003csmall\u003e(\\*) This means: the computed Style of the element has neither `display: none` nor\n`visibility: hidden`\u003c/small\u003e\n\n```html\n\u003cdiv v-clickout.visible=\"close\" style=\"display:none\"\u003e\n  \u003c!-- Clicking ouside of this element will *not* trigger the callback because the element is not visible --\u003e\n  \u003cbutton\u003eClick Me\u003c/button\u003e\n\u003c/div\u003e\n```\n\n## Limitations\n\nYou *must* pass a component method as a callback to this directive. You *can't* use an expression. For example, the following will not work:\n```html\n\u003cdiv v-clickout.bubble=\"$emit('close')\" class=\"modal-window\"\u003e\n  \u003c!-- content --\u003e\n\u003c/div\u003e\n```\nFor any expression that does not resolve to a function, like the above example, this directive will log a warning to a console (in development mode).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusborg%2Fvue-directive-clickout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinusborg%2Fvue-directive-clickout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusborg%2Fvue-directive-clickout/lists"}