Detecting if platform is mobile
This commit is contained in:
Родитель
44bfcb02a3
Коммит
bd0665467f
|
@ -1,3 +1,4 @@
|
|||
tools/
|
||||
wp-add-to-homescreen/composer.lock
|
||||
wp-add-to-homescreen/vendor/
|
||||
wp-add-to-homescreen/lib/vendor/
|
||||
|
|
2
Makefile
2
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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"directory": "lib/vendor"
|
||||
}
|
|
@ -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 <salva@unoyunodiez.com>"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
|
@ -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!',
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
(function(globals, setup){
|
||||
(function(globals, setup, isMobile){
|
||||
'use strict';
|
||||
|
||||
var window = globals;
|
||||
|
@ -22,8 +22,11 @@
|
|||
},
|
||||
|
||||
init: function (overlayContainer, 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);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
(function(globals, wpAddToHomescreen){
|
||||
(function(globals, wpAddToHomescreen, isMobile){
|
||||
'use strict';
|
||||
if (isMobile.any) {
|
||||
wpAddToHomescreen.init(document.body, document.body);
|
||||
})(window, wpAddToHomescreen);
|
||||
}
|
||||
})(window, wpAddToHomescreen, isMobile);
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"start_url": "/",
|
||||
}
|
Загрузка…
Ссылка в новой задаче