├── .browserslistrc
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── LICENSE
├── README.md
├── babel.config.js
├── dist
├── demo.html
├── vue-mobile-detection.common.js
├── vue-mobile-detection.common.js.map
├── vue-mobile-detection.umd.js
├── vue-mobile-detection.umd.js.map
├── vue-mobile-detection.umd.min.js
└── vue-mobile-detection.umd.min.js.map
├── docs
├── favicon.ico
├── index.html
└── js
│ ├── app.0dba17f6.js
│ ├── app.0dba17f6.js.map
│ ├── chunk-vendors.c6e5b2fc.js
│ └── chunk-vendors.c6e5b2fc.js.map
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
└── index.html
├── src
├── App.vue
├── assets
│ └── logo.png
├── components
│ ├── VueMobileDetection.js
│ └── index.js
└── main.js
└── vue.config.js
/.browserslistrc:
--------------------------------------------------------------------------------
1 | > 1%
2 | last 2 versions
3 | not dead
4 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | node: true,
5 | },
6 | extends: ["plugin:vue/vue3-essential", "eslint:recommended", "@vue/prettier"],
7 | parserOptions: {
8 | parser: "babel-eslint",
9 | },
10 | rules: {
11 | "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
12 | "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
13 | },
14 | };
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 |
6 | # local env files
7 | .env.local
8 | .env.*.local
9 |
10 | # Log files
11 | npm-debug.log*
12 | yarn-debug.log*
13 | yarn-error.log*
14 | pnpm-debug.log*
15 |
16 | # Editor directories and files
17 | .idea
18 | .vscode
19 | *.suo
20 | *.ntvs*
21 | *.njsproj
22 | *.sln
23 | *.sw?
24 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 120
3 | }
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Alberto Jerez
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # IMPORTANT
3 | **Version 2 of this plugin only works with Vue 3. If you need Vue 2 compatibility install version 1.0.0**
4 |
5 |
6 | # vue-mobile-detection
7 | Vue.js global function `this.$isMobile()` that returns a Boolean value depending on whether or not the user is browsing with a mobile
8 |
9 |
10 |
11 |
12 |
13 |
14 | ## Demo
15 |
16 | https://ajerez.github.io/vue-mobile-detection/
17 |
18 |
19 | ## Installation
20 |
21 | #### With npm (Recommended)
22 | ```bash
23 | npm i vue-mobile-detection
24 | ```
25 |
26 | #### yarn
27 | ```bash
28 | yarn add vue-mobile-detection
29 | ```
30 |
31 | ## Usage
32 |
33 | #### Plugin installation
34 |
35 | ```vue
36 |
37 | import VueMobileDetection from "vue-mobile-detection";
38 | import App from "./App.vue";
39 |
40 | const app = createApp(App);
41 | app.use(VueMobileDetection);
42 |
43 | /* After the install you can use this.$isMobile() in all your vue components */
44 | ```
45 |
46 | #### Using the plugin
47 |
48 | ```vue
49 |
50 |
51 |
52 |
53 |
MOBILE
54 |
DESKTOP OR TABLET
55 |
56 |
57 |
58 |
66 |
67 | ```
68 |
69 |
70 | ## License
71 |
72 | This project is licensed under the terms of the MIT license
73 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ["@vue/cli-plugin-babel/preset"],
3 | };
4 |
--------------------------------------------------------------------------------
/dist/demo.html:
--------------------------------------------------------------------------------
1 |
2 | vue-mobile-detection demo
3 |
4 |
5 |
6 |
9 |
--------------------------------------------------------------------------------
/dist/vue-mobile-detection.common.js:
--------------------------------------------------------------------------------
1 | module.exports =
2 | /******/ (function(modules) { // webpackBootstrap
3 | /******/ // The module cache
4 | /******/ var installedModules = {};
5 | /******/
6 | /******/ // The require function
7 | /******/ function __webpack_require__(moduleId) {
8 | /******/
9 | /******/ // Check if module is in cache
10 | /******/ if(installedModules[moduleId]) {
11 | /******/ return installedModules[moduleId].exports;
12 | /******/ }
13 | /******/ // Create a new module (and put it into the cache)
14 | /******/ var module = installedModules[moduleId] = {
15 | /******/ i: moduleId,
16 | /******/ l: false,
17 | /******/ exports: {}
18 | /******/ };
19 | /******/
20 | /******/ // Execute the module function
21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22 | /******/
23 | /******/ // Flag the module as loaded
24 | /******/ module.l = true;
25 | /******/
26 | /******/ // Return the exports of the module
27 | /******/ return module.exports;
28 | /******/ }
29 | /******/
30 | /******/
31 | /******/ // expose the modules object (__webpack_modules__)
32 | /******/ __webpack_require__.m = modules;
33 | /******/
34 | /******/ // expose the module cache
35 | /******/ __webpack_require__.c = installedModules;
36 | /******/
37 | /******/ // define getter function for harmony exports
38 | /******/ __webpack_require__.d = function(exports, name, getter) {
39 | /******/ if(!__webpack_require__.o(exports, name)) {
40 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41 | /******/ }
42 | /******/ };
43 | /******/
44 | /******/ // define __esModule on exports
45 | /******/ __webpack_require__.r = function(exports) {
46 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48 | /******/ }
49 | /******/ Object.defineProperty(exports, '__esModule', { value: true });
50 | /******/ };
51 | /******/
52 | /******/ // create a fake namespace object
53 | /******/ // mode & 1: value is a module id, require it
54 | /******/ // mode & 2: merge all properties of value into the ns
55 | /******/ // mode & 4: return value when already ns object
56 | /******/ // mode & 8|1: behave like require
57 | /******/ __webpack_require__.t = function(value, mode) {
58 | /******/ if(mode & 1) value = __webpack_require__(value);
59 | /******/ if(mode & 8) return value;
60 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61 | /******/ var ns = Object.create(null);
62 | /******/ __webpack_require__.r(ns);
63 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65 | /******/ return ns;
66 | /******/ };
67 | /******/
68 | /******/ // getDefaultExport function for compatibility with non-harmony modules
69 | /******/ __webpack_require__.n = function(module) {
70 | /******/ var getter = module && module.__esModule ?
71 | /******/ function getDefault() { return module['default']; } :
72 | /******/ function getModuleExports() { return module; };
73 | /******/ __webpack_require__.d(getter, 'a', getter);
74 | /******/ return getter;
75 | /******/ };
76 | /******/
77 | /******/ // Object.prototype.hasOwnProperty.call
78 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79 | /******/
80 | /******/ // __webpack_public_path__
81 | /******/ __webpack_require__.p = "";
82 | /******/
83 | /******/
84 | /******/ // Load entry module and return exports
85 | /******/ return __webpack_require__(__webpack_require__.s = "fb15");
86 | /******/ })
87 | /************************************************************************/
88 | /******/ ({
89 |
90 | /***/ "8875":
91 | /***/ (function(module, exports, __webpack_require__) {
92 |
93 | var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// addapted from the document.currentScript polyfill by Adam Miller
94 | // MIT license
95 | // source: https://github.com/amiller-gh/currentScript-polyfill
96 |
97 | // added support for Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1620505
98 |
99 | (function (root, factory) {
100 | if (true) {
101 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
102 | __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
103 | (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
104 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
105 | } else {}
106 | }(typeof self !== 'undefined' ? self : this, function () {
107 | function getCurrentScript () {
108 | var descriptor = Object.getOwnPropertyDescriptor(document, 'currentScript')
109 | // for chrome
110 | if (!descriptor && 'currentScript' in document && document.currentScript) {
111 | return document.currentScript
112 | }
113 |
114 | // for other browsers with native support for currentScript
115 | if (descriptor && descriptor.get !== getCurrentScript && document.currentScript) {
116 | return document.currentScript
117 | }
118 |
119 | // IE 8-10 support script readyState
120 | // IE 11+ & Firefox support stack trace
121 | try {
122 | throw new Error();
123 | }
124 | catch (err) {
125 | // Find the second match for the "at" string to get file src url from stack.
126 | var ieStackRegExp = /.*at [^(]*\((.*):(.+):(.+)\)$/ig,
127 | ffStackRegExp = /@([^@]*):(\d+):(\d+)\s*$/ig,
128 | stackDetails = ieStackRegExp.exec(err.stack) || ffStackRegExp.exec(err.stack),
129 | scriptLocation = (stackDetails && stackDetails[1]) || false,
130 | line = (stackDetails && stackDetails[2]) || false,
131 | currentLocation = document.location.href.replace(document.location.hash, ''),
132 | pageSource,
133 | inlineScriptSourceRegExp,
134 | inlineScriptSource,
135 | scripts = document.getElementsByTagName('script'); // Live NodeList collection
136 |
137 | if (scriptLocation === currentLocation) {
138 | pageSource = document.documentElement.outerHTML;
139 | inlineScriptSourceRegExp = new RegExp('(?:[^\\n]+?\\n){0,' + (line - 2) + '}[^<]*