From 9d2a98604804ee0c0c37aa5ecd924a6c3ee7a0e9 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 26 Feb 2018 09:19:28 -0500 Subject: [PATCH] Add @Toutouwai request related to processwire/processwire-issues#84 for improving touch input detection in ProcessLogin via method like InputDetect module with whatinput JS. --- wire/modules/Process/ProcessLogin/ProcessLogin.js | 12 ++++++++---- .../modules/Process/ProcessLogin/ProcessLogin.min.js | 2 +- .../modules/Process/ProcessLogin/ProcessLogin.module | 8 +++++++- wire/modules/Process/ProcessLogin/what-input.min.js | 7 +++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 wire/modules/Process/ProcessLogin/what-input.min.js diff --git a/wire/modules/Process/ProcessLogin/ProcessLogin.js b/wire/modules/Process/ProcessLogin/ProcessLogin.js index 19f52a4c..461570fe 100644 --- a/wire/modules/Process/ProcessLogin/ProcessLogin.js +++ b/wire/modules/Process/ProcessLogin/ProcessLogin.js @@ -13,8 +13,12 @@ $(document).ready(function() { } $("#login_hidpi").val(hidpi ? 1 : 0); - // detect whether or not it's a touch device - var touch = (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); - $("#login_touch").val(touch ? 1 : 0); - $("#login_width").val($(window).width()); + // via @Toutouwai #84 + $('#ProcessLoginForm').submit(function() { + var $html = $('html'); + var touch = $html.data('whatintent') == 'touch' || $html.data('whatinput') == 'touch'; + $('#login_touch').val(touch ? 1 : 0); + $('#login_width').val($(window).width()); + }); + }); \ No newline at end of file diff --git a/wire/modules/Process/ProcessLogin/ProcessLogin.min.js b/wire/modules/Process/ProcessLogin/ProcessLogin.min.js index 03c3221d..878499af 100644 --- a/wire/modules/Process/ProcessLogin/ProcessLogin.min.js +++ b/wire/modules/Process/ProcessLogin/ProcessLogin.min.js @@ -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())}); \ No newline at end of file +$(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())})}); \ No newline at end of file diff --git a/wire/modules/Process/ProcessLogin/ProcessLogin.module b/wire/modules/Process/ProcessLogin/ProcessLogin.module index d7cf0339..17b24568 100644 --- a/wire/modules/Process/ProcessLogin/ProcessLogin.module +++ b/wire/modules/Process/ProcessLogin/ProcessLogin.module @@ -29,7 +29,7 @@ class ProcessLogin extends Process { return array( 'title' => 'Login', 'summary' => 'Login to ProcessWire', - 'version' => 103, + 'version' => 104, 'permanent' => true, 'permission' => 'page-view', ); @@ -451,6 +451,12 @@ class ProcessLogin extends Process { $home = $this->pages->get("/"); $links .= "
{$home->title}
"; if($links) $out .= "

$links

"; + + 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; diff --git a/wire/modules/Process/ProcessLogin/what-input.min.js b/wire/modules/Process/ProcessLogin/what-input.min.js new file mode 100644 index 00000000..4d87f5c7 --- /dev/null +++ b/wire/modules/Process/ProcessLogin/what-input.min.js @@ -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}}}()}])}); \ No newline at end of file