Detecting if platform is mobile

This commit is contained in:
Salvador de la Puente González 2016-03-16 12:29:20 +01:00
Родитель 44bfcb02a3
Коммит bd0665467f
9 изменённых файлов: 64 добавлений и 17 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -1,3 +1,4 @@
tools/
wp-add-to-homescreen/composer.lock
wp-add-to-homescreen/vendor/
wp-add-to-homescreen/lib/vendor/

Просмотреть файл

@ -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) {
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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -1,3 +0,0 @@
{
"start_url": "/",
}