1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 10:45:54 +02:00

Add @Toutouwai request related to processwire/processwire-issues#84 for improving touch input detection in ProcessLogin via method like InputDetect module with whatinput JS.

This commit is contained in:
Ryan Cramer
2018-02-26 09:19:28 -05:00
parent 37f95199f4
commit 9d2a986048
4 changed files with 23 additions and 6 deletions

View File

@@ -13,8 +13,12 @@ $(document).ready(function() {
} }
$("#login_hidpi").val(hidpi ? 1 : 0); $("#login_hidpi").val(hidpi ? 1 : 0);
// detect whether or not it's a touch device // via @Toutouwai #84
var touch = (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); $('#ProcessLoginForm').submit(function() {
$("#login_touch").val(touch ? 1 : 0); var $html = $('html');
$("#login_width").val($(window).width()); var touch = $html.data('whatintent') == 'touch' || $html.data('whatinput') == 'touch';
$('#login_touch').val(touch ? 1 : 0);
$('#login_width').val($(window).width());
});
}); });

View File

@@ -1 +1 @@
$(document).ready(function(){if(window.devicePixelRatio>1){var a=true}else{var b="(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)";var a=window.matchMedia&&window.matchMedia(b).matches}$("#login_hidpi").val(a?1:0);var c=(("ontouchstart" in window)||(navigator.MaxTouchPoints>0)||(navigator.msMaxTouchPoints>0));$("#login_touch").val(c?1:0);$("#login_width").val($(window).width())}); $(document).ready(function(){if(window.devicePixelRatio>1){var a=true}else{var b="(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)";var a=window.matchMedia&&window.matchMedia(b).matches}$("#login_hidpi").val(a?1:0);$("#ProcessLoginForm").submit(function(){var c=$("html");var d=c.data("whatintent")=="touch"||c.data("whatinput")=="touch";$("#login_touch").val(d?1:0);$("#login_width").val($(window).width())})});

View File

@@ -29,7 +29,7 @@ class ProcessLogin extends Process {
return array( return array(
'title' => 'Login', 'title' => 'Login',
'summary' => 'Login to ProcessWire', 'summary' => 'Login to ProcessWire',
'version' => 103, 'version' => 104,
'permanent' => true, 'permanent' => true,
'permission' => 'page-view', 'permission' => 'page-view',
); );
@@ -451,6 +451,12 @@ class ProcessLogin extends Process {
$home = $this->pages->get("/"); $home = $this->pages->get("/");
$links .= "<div><a href='{$home->url}'><i class='fa fa-home'></i> {$home->title}</a></div>"; $links .= "<div><a href='{$home->url}'><i class='fa fa-home'></i> {$home->title}</a></div>";
if($links) $out .= "<p>$links</p>"; if($links) $out .= "<p>$links</p>";
if(!$this->wire('modules')->isInstalled('InputDetect')) {
/** @var Config $config */
$config = $this->wire('config');
$config->scripts->prepend($config->urls->ProcessLogin . 'what-input.min.js');
}
} }
return $out; return $out;

View File

@@ -0,0 +1,7 @@
/**
* what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
* @version v4.1.1
* @link https://github.com/ten1seven/what-input
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){var e=document.documentElement,t="initial",n=null,o=["input","select","textarea"],r=[16,17,18,91,93],i={keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch"},u=[],d=!1,s=!1,a={x:null,y:null},p={2:"touch",3:"touch",4:"mouse"},c=function(){i[y()]="mouse",f(),v()},f=function(){window.PointerEvent?(e.addEventListener("pointerdown",m),e.addEventListener("pointermove",w)):window.MSPointerEvent?(e.addEventListener("MSPointerDown",m),e.addEventListener("MSPointerMove",w)):(e.addEventListener("mousedown",m),e.addEventListener("mousemove",w),"ontouchstart"in window&&(e.addEventListener("touchstart",h),e.addEventListener("touchend",h))),e.addEventListener(y(),w),e.addEventListener("keydown",m),e.addEventListener("keyup",m)},m=function(e){if(!d){var u=e.which,s=i[e.type];if("pointer"===s&&(s=l(e)),t!==s||n!==s){var a=document.activeElement,p=!1;a&&a.nodeName&&o.indexOf(a.nodeName.toLowerCase())===-1&&(p=!0),("touch"===s||"mouse"===s&&r.indexOf(u)===-1||"keyboard"===s&&p)&&(t=n=s,v())}}},v=function(){e.setAttribute("data-whatinput",t),e.setAttribute("data-whatintent",t),u.indexOf(t)===-1&&(u.push(t),e.className+=" whatinput-types-"+t)},w=function(t){if(a.x!==t.screenX||a.y!==t.screenY?(s=!1,a.x=t.screenX,a.y=t.screenY):s=!0,!d&&!s){var o=i[t.type];"pointer"===o&&(o=l(t)),n!==o&&(n=o,e.setAttribute("data-whatintent",n))}},h=function(e){"touchstart"===e.type?(d=!1,m(e)):d=!0},l=function(e){return"number"==typeof e.pointerType?p[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},y=function(){var e=void 0;return e="onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"};return"addEventListener"in window&&Array.prototype.indexOf&&c(),{ask:function(e){return"loose"===e?n:t},types:function(){return u}}}()}])});