From bd0665467f939e330d3e16977a2fca717f621150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20de=20la=20Puente=20Gonz=C3=A1lez?= Date: Wed, 16 Mar 2016 12:29:20 +0100 Subject: [PATCH] Detecting if platform is mobile --- .gitignore | 1 + Makefile | 2 ++ wp-add-to-homescreen/.bowerrc | 3 ++ wp-add-to-homescreen/bower.json | 31 +++++++++++++++++++ .../class-wp-add-to-homescreen-plugin.php | 6 +++- wp-add-to-homescreen/composer.json | 12 +++---- .../lib/js/add-to-homescreen.js | 15 ++++++--- .../lib/js/start-add-to-homescreen.js | 8 +++-- wp-add-to-homescreen/lib/manifest.php | 3 -- 9 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 wp-add-to-homescreen/.bowerrc create mode 100644 wp-add-to-homescreen/bower.json delete mode 100644 wp-add-to-homescreen/lib/manifest.php diff --git a/.gitignore b/.gitignore index cd7949e..cead685 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tools/ wp-add-to-homescreen/composer.lock wp-add-to-homescreen/vendor/ +wp-add-to-homescreen/lib/vendor/ diff --git a/Makefile b/Makefile index e3a23d8..87163ac 100644 --- a/Makefile +++ b/Makefile @@ -23,3 +23,5 @@ tools/phpunit.phar: mv tools/phpunit-old.phar tools/phpunit.phar chmod +x $(PHPUNIT) +build: + cd wp-add-to-homescreen && bower update diff --git a/wp-add-to-homescreen/.bowerrc b/wp-add-to-homescreen/.bowerrc new file mode 100644 index 0000000..0327a0f --- /dev/null +++ b/wp-add-to-homescreen/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "lib/vendor" +} \ No newline at end of file diff --git a/wp-add-to-homescreen/bower.json b/wp-add-to-homescreen/bower.json new file mode 100644 index 0000000..6118e35 --- /dev/null +++ b/wp-add-to-homescreen/bower.json @@ -0,0 +1,31 @@ +{ + "name": "wp-add-to-homescreen", + "homepage": "https://github.com/mozilla/wp-add-to-homescreen", + "authors": [ + "Salvador de la Puente González " + ], + "description": "Make your WordPress sites to appear in mobile home screens.", + "main": "", + "moduleType": [], + "keywords": [ + "add", + "home", + "screen", + "app-like", + "launcher", + "wordpress" + ], + "license": "GPL2", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "lib/vendor", + "test", + "tests" + ], + "dependencies": { + "isMobile": "~0.4.0" + } +} diff --git a/wp-add-to-homescreen/class-wp-add-to-homescreen-plugin.php b/wp-add-to-homescreen/class-wp-add-to-homescreen-plugin.php index 7a289d7..c886c35 100644 --- a/wp-add-to-homescreen/class-wp-add-to-homescreen-plugin.php +++ b/wp-add-to-homescreen/class-wp-add-to-homescreen-plugin.php @@ -22,6 +22,8 @@ class WP_Add_To_Homescreen_Plugin { private $add2home_style; + private $isMobile_script; + private function __construct() { $plugin_main_file = plugin_dir_path(__FILE__) . 'wp-add-to-homescreen.php'; $this->set_urls(); @@ -33,6 +35,7 @@ class WP_Add_To_Homescreen_Plugin { } private function set_urls() { + $this->isMobile_script = plugins_url('/lib/vendor/isMobile/isMobile.min.js', __FILE__); $this->add2home_script = plugins_url('/lib/js/add-to-homescreen.js', __FILE__); $this->add2home_start_script = plugins_url( '/lib/js/start-add-to-homescreen.js', @@ -64,7 +67,8 @@ class WP_Add_To_Homescreen_Plugin { public function enqueue_assets() { wp_enqueue_style('add-to-homescreen-style', $this->add2home_style); - wp_register_script('add-to-homescreen', $this->add2home_script, array(), false, true); + wp_enqueue_script('isMobile', $this->isMobile_script); + wp_register_script('add-to-homescreen', $this->add2home_script, array('isMobile'), false, true); wp_localize_script('add-to-homescreen', 'wpAddToHomescreenSetup', array( 'libUrl' => plugins_url('lib/', __FILE__), 'invitationText' => 'Make this site appear among your apps!', diff --git a/wp-add-to-homescreen/composer.json b/wp-add-to-homescreen/composer.json index ad5fd93..6ece62c 100644 --- a/wp-add-to-homescreen/composer.json +++ b/wp-add-to-homescreen/composer.json @@ -1,6 +1,7 @@ { "name": "mozilla/wp-add-to-homescreen", "description": "Make your WordPress sites to appear in home screens.", + "minimum-stability": "dev", "authors": [ { "name": "Salvador de la Puente González", @@ -8,18 +9,17 @@ } ], "repositories": [ + { + "type": "vcs", + "url": "https://github.com/mozilla/wp-sw-manager" + }, { "type": "vcs", "url": "https://github.com/marco-c/wp-web-app-manifest-generator" } ], - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/mozilla/wp-sw-manager" - } - ], "require": { + "marco-c/wp_serve_file": "dev-master", "marco-c/wp-web-app-manifest-generator": "dev-master", "mozilla/wp-sw-manager": "dev-master" } diff --git a/wp-add-to-homescreen/lib/js/add-to-homescreen.js b/wp-add-to-homescreen/lib/js/add-to-homescreen.js index a582ba5..91a1fb5 100644 --- a/wp-add-to-homescreen/lib/js/add-to-homescreen.js +++ b/wp-add-to-homescreen/lib/js/add-to-homescreen.js @@ -1,5 +1,5 @@ -(function(globals, setup){ +(function(globals, setup, isMobile){ 'use strict'; var window = globals; @@ -22,8 +22,11 @@ }, init: function (overlayContainer, buttonContainer) { - this.overlay.element = this.installOverlay(overlayContainer); - this.installAddToHomescreenButton(buttonContainer); + if (this.isPlatformSupported()) { + alert('isMobile!!'); + this.overlay.element = this.installOverlay(overlayContainer); + this.installAddToHomescreenButton(buttonContainer); + } }, installAddToHomescreenButton: function (container) { @@ -50,6 +53,10 @@ return overlay; }, + isPlatformSupported: function () { + return isMobile.any; + }, + detectBrowser: function () { if (/Gecko\/[\d\.]+ Firefox\/[\d\.]+/.test(navigator.userAgent)) { return 'fennec'; @@ -127,4 +134,4 @@ }; -})(window, wpAddToHomescreenSetup); +})(window, wpAddToHomescreenSetup, isMobile); diff --git a/wp-add-to-homescreen/lib/js/start-add-to-homescreen.js b/wp-add-to-homescreen/lib/js/start-add-to-homescreen.js index 8883459..f14cea9 100644 --- a/wp-add-to-homescreen/lib/js/start-add-to-homescreen.js +++ b/wp-add-to-homescreen/lib/js/start-add-to-homescreen.js @@ -1,4 +1,6 @@ -(function(globals, wpAddToHomescreen){ +(function(globals, wpAddToHomescreen, isMobile){ 'use strict'; - wpAddToHomescreen.init(document.body, document.body); -})(window, wpAddToHomescreen); + if (isMobile.any) { + wpAddToHomescreen.init(document.body, document.body); + } +})(window, wpAddToHomescreen, isMobile); diff --git a/wp-add-to-homescreen/lib/manifest.php b/wp-add-to-homescreen/lib/manifest.php deleted file mode 100644 index 99cff2d..0000000 --- a/wp-add-to-homescreen/lib/manifest.php +++ /dev/null @@ -1,3 +0,0 @@ -{ - "start_url": "/", -}