| | |
| | | document.addEventListener('touchstart', shield, false);//取消浏览器的所有事件,使得active的样式在手机上正常生效 |
| | | document.oncontextmenu=shield;//屏蔽选择函数 |
| | | // H5 plus事件处理 |
| | | var ws=null,as='pop-in'; |
| | | var ws = null, |
| | | as = 'pop-in'; |
| | | |
| | | function plusReady(){ |
| | | ws=plus.webview.currentWebview(); |
| | | plus.key.addEventListener('backbutton', function(){ |
| | |
| | | ws.scrollIndicator||(ws.scrollIndicator='none'); |
| | | ws.scalable||(ws.scalable=false); |
| | | ws.backButtonAutoControl||(ws.backButtonAutoControl='close'); |
| | | ws.titleNView=ws.titleNView||{autoBackButton:true}; |
| | | ws.titleNView = ws.titleNView || { |
| | | autoBackButton: true |
| | | }; |
| | | ws.titleNView.backgroundColor = '#D74B28'; |
| | | ws.titleNView.titleColor = '#CCCCCC'; |
| | | ws.doc&&(ws.titleNView.buttons=ws.titleNView.buttons||[],ws.titleNView.buttons.push({fontSrc:'_www/helloh5.ttf',text:'\ue301',fontSize:'20px',onclick:'javascript:openDoc()'})); |
| | | ws.doc && (ws.titleNView.buttons = ws.titleNView.buttons || [], ws.titleNView.buttons.push({ |
| | | fontSrc: '_www/helloh5.ttf', |
| | | text: '\ue301', |
| | | fontSize: '20px', |
| | | onclick: 'javascript:openDoc()' |
| | | })); |
| | | t&&(ws.titleNView.titleText=t); |
| | | openw = plus.webview.create(id, id, ws); |
| | | openw.addEventListener('loaded', function(){ |
| | |
| | | }; |
| | | // 格式化日期时间字符串,格式为"YYYY-MM-DD HH:MM:SS" |
| | | w.dateToStr=function(d){ |
| | | return (d.getFullYear()+"-"+ultZeroize(d.getMonth()+1)+"-"+ultZeroize(d.getDate())+" "+ultZeroize(d.getHours())+":"+ultZeroize(d.getMinutes())+":"+ultZeroize(d.getSeconds())); |
| | | return (d.getFullYear() + "-" + ultZeroize(d.getMonth() + 1) + "-" + ultZeroize(d.getDate()) + " " + |
| | | ultZeroize(d.getHours()) + ":" + ultZeroize(d.getMinutes()) + ":" + ultZeroize(d.getSeconds())); |
| | | }; |
| | | /** |
| | | * zeroize value with length(default is 2). |
| | |
| | | })(window); |
| | | |
| | | // fast click |
| | | ;(function () { |
| | | ; |
| | | (function() { |
| | | 'use strict'; |
| | | |
| | | /** |
| | |
| | | |
| | | // Some old versions of Android don't have Function.prototype.bind |
| | | function bind(method, context) { |
| | | return function() { return method.apply(context, arguments); }; |
| | | return function() { |
| | | return method.apply(context, arguments); |
| | | }; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // Synthesise a click event, with an extra attribute so it can be tracked |
| | | clickEvent = document.createEvent('MouseEvents'); |
| | | clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); |
| | | clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, |
| | | touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); |
| | | clickEvent.forwardedTouchEvent = true; |
| | | targetElement.dispatchEvent(clickEvent); |
| | | }; |
| | |
| | | var length; |
| | | |
| | | // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. |
| | | if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { |
| | | if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && |
| | | targetElement.type !== 'time' && targetElement.type !== 'month') { |
| | | length = targetElement.value.length; |
| | | targetElement.setSelectionRange(length, length); |
| | | } else { |
| | |
| | | * @returns {boolean} |
| | | */ |
| | | FastClick.prototype.touchHasMoved = function(event) { |
| | | var touch = event.changedTouches[0], boundary = this.touchBoundary; |
| | | var touch = event.changedTouches[0], |
| | | boundary = this.touchBoundary; |
| | | |
| | | if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { |
| | | if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > |
| | | boundary) { |
| | | return true; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // If the touch has moved, cancel the click tracking |
| | | if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { |
| | | if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved( |
| | | event)) { |
| | | this.trackingClick = false; |
| | | this.targetElement = null; |
| | | } |
| | |
| | | |
| | | // If no for attribute exists, attempt to retrieve the first labellable descendant element |
| | | // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label |
| | | return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); |
| | | return labelElement.querySelector( |
| | | 'button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); |
| | | }; |
| | | |
| | | |
| | |
| | | * @returns {boolean} |
| | | */ |
| | | FastClick.prototype.onTouchEnd = function(event) { |
| | | var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; |
| | | var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this |
| | | .targetElement; |
| | | |
| | | if (!this.trackingClick) { |
| | | return true; |
| | |
| | | touch = event.changedTouches[0]; |
| | | |
| | | // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null |
| | | targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; |
| | | targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window |
| | | .pageYOffset) || targetElement; |
| | | targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; |
| | | } |
| | | |
| | |
| | | |
| | | // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. |
| | | // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). |
| | | if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { |
| | | if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && |
| | | targetTagName === 'input')) { |
| | | this.targetElement = null; |
| | | return false; |
| | | } |
| | |
| | | // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 |
| | | |
| | | metaViewport = document.querySelector('meta[name=viewport]'); |
| | | if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { |
| | | if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document |
| | | .documentElement.scrollWidth <= window.outerWidth)) { |
| | | return true; |
| | | } |
| | | } |