danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

file upload click is hard/not fast response in mobile devices #2109

Open Balasankararao opened 5 years ago

Balasankararao commented 5 years ago

Hi All,

ng-file-upload responds very hard which clicking on paper clip in mobile devices including anrdoid and IOS.

Is it a possible change that can be done. I found the below code on the interenet and it works. Is it possible to include the change? Thanks!!!

  if (!isInputTypeFile()) {
                //--Original Code
               //elem.bind('click touchstart touchend', clickHandler);

                //--Code changes, as for IOS trigger event for soft touch also
                //Platform、Device and Operation
                 var system = {
                     win: false,
                     mac: false,
                     xll: false,
                     ipad:false
                        };
                     //check platform is desktop and mobile emulator just only need ‘touchend’,otherwise it will open file window three times
                 var p = navigator.platform;
                 system.win = p.indexOf("Win") == 0;
                 system.mac = p.indexOf("Mac") == 0;
                 system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
                 system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
                 if (system.win || system.mac || system.xll||system.ipad) {
                    var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
                    var u = navigator.userAgent;
                    if (null == u) {
                                     elem.bind('touchend', clickHandler);
                                    }else{
                    var result = regex_match.exec(u);
                        if (null == result) {
                             elem.bind('click touchstart touchend', clickHandler);
                            } else {
                        elem.bind('touchend', clickHandler);
                                }
                            }
                     }else{
                        elem.bind('click touchstart touchend', clickHandler);
                    }
            } else {
                elem.bind('click', resetModel);
            }

I am new to this forum , Please correct me if any thing is not according to the standards.