ns-components-angular
Version:
Angular Wrapper Components for NSComponents
2 lines (1 loc) • 10.5 kB
TypeScript
export declare const NSTouchToMouseCode = "var nsModuleExport = function(root,name,prototype)\r\n\t{\r\n\t\tif(typeof exports === 'object' && typeof module === 'object')\r\n\t\t{\r\n\t\t\tmodule.exports[name] = prototype;\r\n\t\t}\r\n\t\telse if (typeof define === \"function\" && define.amd)\r\n\t\t{\r\n\t\t\tdefine(name,[], function () {return prototype;});\r\n\t\t}\r\n\t\telse if(typeof exports === 'object')\r\n\t\t{\r\n\t\t\texports[name] = prototype;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\troot[name] = prototype;\r\n\t\t}\r\n\t};var nsIsWeb = function(root)\r\n\t{\r\n\t\tif(typeof exports === 'object' && typeof module === 'object')\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\telse if (typeof define === \"function\" && define.amd)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\telse if(typeof exports === 'object')\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t};if(!nsIsWeb())\r\n\t\t{\r\nvar nsutilRef = require('./nsUtil.min.js');\r\nvar NSUtil = nsutilRef.NSUtil;\r\n\r\n\t\t}\r\n\"use strict\";\r\nvar NSTouchToMouse = (function()\r\n{\r\n\tfunction NSTouchToMouse(element,setting,doc,win) \r\n\t{\r\n\t\tthis.util = new NSUtil();\r\n\t\tthis.doc = this.util.getDoc(doc);\r\n\t\tthis.win = this.util.getWin(win);\r\n\t\tthis.__element = this.util.getElement(element);\r\n\t\tthis.__setting = setting;\r\n\t\tthis.__config = null;\r\n\t\tthis.__touchEventRef = null;\r\n\t\tthis.__gestureChangeRef = null;\r\n\t\tthis.__gestureEndRef = null;\r\n\t\tthis.__objLocal = {documentClick: false,doubleTapWaiting: false,preTouchStart: false,gestureChanged: false};\r\n\t\tthis.__objEvents = null;\r\n\t\tthis.__useConstructor = false;\r\n\t\tthis.__initialize();\r\n\t};\r\n\t\r\n\tNSTouchToMouse.prototype.isTouchSupported = function()\r\n\t{\r\n\t\tvar isTouchSupported = ((\"ontouchstart\" in this.win) || (this.win.navigator.msMaxTouchPoints > 0));\r\n\t\treturn isTouchSupported;\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.isGestureSupported = function()\r\n\t{\r\n\t\tvar isGestureSupported = (\"ongesturestart\" in this.win);\r\n\t\treturn isGestureSupported;\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.destroy = function()\r\n\t{\r\n\t\tif(this.__touchEventRef)\r\n\t\t{\r\n\t\t\tthis.util.removeEvent(this.__element,\"touchstart\",this.__touchEventRef);\r\n\t\t\tthis.util.removeEvent(this.__element,\"touchmove\",this.__touchEventRef,true);\r\n\t\t\tthis.util.removeEvent(this.__element,\"touchend\",this.__touchEventRef,true);\r\n\t\t\tthis.util.removeEvent(this.__element,\"touchcancel\",this.__touchEventRef,true);\r\n\t\t\tthis.__touchEventRef = null;\r\n\t\t}\r\n\t\tif(this.__gestureChangeRef)\r\n\t\t{\r\n\t\t\tthis.util.removeEvent(this.__element,\"gesturechange\",this.__gestureChangeRef);\r\n\t\t\tthis.__gestureChangeRef = null;\r\n\t\t}\r\n\t\tif(this.__gestureEndRef)\r\n\t\t{\r\n\t\t\tthis.util.removeEvent(this.__element,\"gestureend\",this.__gestureEndRef);\r\n\t\t\tthis.__gestureEndRef = null;\r\n\t\t}\r\n\t\tthis.__objLocal = {documentClick: false,doubleTapWaiting: false,preTouchStart: false,gestureChanged: false};\r\n\t};\r\n\t\r\n\tNSTouchToMouse.prototype.__initialize = function()\r\n\t{\r\n\t\tif(!this.__element)\r\n\t\t{\r\n\t\t\tthis.util.throwNSError(\"NSTouchToMouse\",\"Element is not valid\");\r\n\t\t}\r\n\t\tvar setting = this.__setting || {};\r\n\t\tthis.__config = {\r\n\t\t\tdoubleTapInterval: this.util.isUndefinedOrNull(setting[\"doubleTapInterval\"]) ? 500 : parseInt(setting[\"doubleTapInterval\"]),\r\n\t\t\tsuppressMouseEvent: Boolean.parse(setting[\"suppressMouseEvent\"]),\r\n\t\t\ttouchStartHandler: setting[\"touchStartHandler\"],//format function(screenXPos,screenYPos,event)\r\n\t\t\ttouchMoveHandler: setting[\"touchMoveHandler\"],//format function(screenXPos,screenYPos,event)\r\n\t\t\ttouchEndHandler: setting[\"touchEndHandler\"],//format function(screenXPos,screenYPos,event)\r\n\t\t\tdoubleTapHandler: setting[\"doubleTapHandler\"],//format function(screenXPos,screenYPos,event)\r\n\t\t\tpinchHandler: setting[\"pinchHandler\"],//format function(scale,event)\r\n\t\t};\r\n\t\tthis.__initObjEvents();\r\n\t\tthis.__addListeners();\r\n\t\tthis.__useConstructor = this.__isMouseEventConstructorExists();\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__initObjEvents = function()\r\n\t{\r\n\t\tthis.__objEvents = {\r\n\t\t\t\"touchstart\":{mouseEventType: \"mousedown\",callback:this.__touchStartHandler.bind(this)},\r\n\t\t\t\"touchmove\":{mouseEventType: \"mousemove\",callback:this.__touchMoveHandler.bind(this)},\r\n\t\t\t\"touchend\":{mouseEventType: \"mouseup\",callback:this.__touchEndHandler.bind(this),fireExtraEvent:this.__fireClickEvent.bind(this)},\r\n\t\t};\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__addListeners = function()\r\n\t{\r\n\t\tvar isTouchSupported = this.isTouchSupported();\r\n\t\tvar isGestureSupported = this.isGestureSupported();\r\n\t\tif (isTouchSupported) \r\n\t\t{\r\n\t\t\tif(!this.__touchEventRef)\r\n\t\t\t{\r\n\t\t\t\tthis.__touchEventRef = this.__touchEventHandler.bind(this);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"touchstart\",this.__touchEventRef);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"touchmove\",this.__touchEventRef,true);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"touchend\",this.__touchEventRef,true);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"touchcancel\",this.__touchEventRef,true);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthis.util.debug(\"NSTouchToMouse\",\"Touch is not supported\");\r\n\t\t}\r\n\t\tif(isGestureSupported)\r\n\t\t{\r\n\t\t\tif(!this.__gestureChangeRef)\r\n\t\t\t{\r\n\t\t\t\tthis.__gestureChangeRef = this.__gestureChangeHandler.bind(this);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"gesturechange\",this.__gestureChangeRef);\r\n\t\t\t}\r\n\t\t\tif(!this.__gestureEndRef)\r\n\t\t\t{\r\n\t\t\t\tthis.__gestureEndRef = this.__gestureEndHandler.bind(this);\r\n\t\t\t\tthis.util.addEvent(this.__element,\"gestureend\",this.__gestureEndRef);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthis.util.debug(\"NSTouchToMouse\",\"Gesture is not supported\");\r\n\t\t}\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__touchEventHandler = function(event)\r\n\t{\r\n\t\tif(!this.__objLocal.gestureChanged)\r\n\t\t{\r\n\t\t\tevent = this.util.getEvent(event);\r\n\t\t\tvar touch = event.touchEvent;\r\n\t\t\tvar item = this.__objEvents[event.type];\r\n\t\t\tif(item)\r\n\t\t\t{\r\n\t\t\t\tvar mouseEventType = item.mouseEventType;\r\n\t\t\t\titem.callback(event,touch);\r\n\t\t\t\tthis.__fireMouseEvent(mouseEventType,event,touch);\r\n\t\t\t\tif(item.fireExtraEvent)\r\n {\r\n \titem.fireExtraEvent(event,touch);\r\n }\r\n event.preventDefault();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tthis.util.debug(\"NSTouchToMouse\",event.type + \" is not supported\");\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__gestureChangeHandler = function(event)\r\n\t{\r\n\t\tevent = this.util.getEvent(event);\r\n\t\tthis.__objLocal.gestureChanged = true;\r\n\t\tif(this.__config.pinchHandler)\r\n\t\t{\r\n\t\t\tthis.__config.pinchHandler(event.scale,event);\r\n\t\t}\r\n\t\tthis.__objLocal.preTouchStart = true;\r\n event.preventDefault();\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__gestureEndHandler = function(event)\r\n\t{\r\n\t\tevent = this.util.getEvent(event);\r\n\t\tthis.__objLocal.gestureChanged = false;\r\n\t\tevent.preventDefault();\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__touchStartHandler = function(event,touch)\r\n\t{\r\n\t\tthis.__fireCallback(\"touchStartHandler\",event,touch);\r\n\t\tthis.__objLocal.preTouchStart = true;\r\n\t\tthis.__objLocal.documentClick = true;\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__touchMoveHandler = function(event,touch)\r\n\t{\r\n\t\tthis.__fireCallback(\"touchMoveHandler\",event,touch);\r\n\t\tthis.__objLocal.preTouchStart = false;\r\n\t\tthis.__objLocal.documentClick = false;\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__touchEndHandler = function(event,touch)\r\n\t{\r\n\t\tif (this.__objLocal.doubleTapWaiting && this.__objLocal.preTouchStart) \r\n\t\t{\t\r\n\t\t\tthis.__fireCallback(\"doubleTapHandler\",event,touch);\r\n\t\t}\r\n\t\telse \r\n\t\t{\r\n\t\t\tthis.__objLocal.doubleTapWaiting = true;\r\n\t\t\tthis.__fireCallback(\"touchEndHandler\",event,touch);\r\n\t\t\tvar self = this;\r\n\t\t\twindow.setTimeout(function () \r\n\t\t\t{\r\n\t\t\t\tself.__objLocal.doubleTapWaiting = false;\r\n\t\t\t}, this.__config.doubleTapInterval);\t\t\t\t\t\t\t\r\n\t\t}\r\n\t\tthis.__objLocal.preTouchStart = false;\r\n\t};\r\n\t\r\n\tNSTouchToMouse.prototype.__fireClickEvent = function(event,touch)\r\n\t{\r\n\t\tif(this.__objLocal.documentClick)\r\n\t\t{\r\n\t\t\tthis.__fireMouseEvent(\"click\",event,touch);\r\n this.__objLocal.documentClick = false;\r\n\t\t}\r\n\t};\r\n\t\r\n\tNSTouchToMouse.prototype.__fireMouseEvent = function(mouseEventType,event,touch)\r\n\t{\r\n\t\tif(!this.__config.suppressMouseEvent)\r\n\t\t{\r\n\t\t\tvar mouseEvent = null;\r\n\t\t\tvar option = {bubbles: true,cancelable: true,view:this.win,detail:1,screenX:touch.screenX,screenY:touch.screenY,clientX:touch.clientX,clientY:touch.clientY,ctrlKey:false,\r\n\t\t\t\t\t\t altKey:false,shiftKey:false,metaKey:false,button:0,relatedTarget:null};\r\n\t\t\tif(this.__useConstructor)\r\n\t\t\t{\r\n\t\t\t\tmouseEvent = new MouseEvent(mouseEventType,option);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmouseEvent = this.doc.createEvent(\"MouseEvent\");\r\n\t\t\t\tmouseEvent.initMouseEvent(mouseEventType,option.bubbles,option.cancelable,option.view,option.detail,\r\n\t\t\t\t\t\t\t\t\t\t option.screenX,option.screenY,option.clientX,option.clientY,option.ctrlKey,\r\n\t\t\t\t\t\t\t\t\t\t option.altKey,option.shiftKey,option.metaKey,option.button,option.relatedTarget);\r\n\t\t\t}\r\n\t\t\ttouch.target.dispatchEvent(mouseEvent);\r\n\t\t}\r\n\t};\r\n\t\r\n\tNSTouchToMouse.prototype.__isMouseEventConstructorExists = function()\r\n\t{\r\n\t\ttry \r\n\t\t{\r\n\t\t new MouseEvent(\"test\");\r\n\t\t return true;\r\n\t\t} \r\n\t\tcatch(error) \r\n\t\t{\r\n\t\t}\r\n\t\treturn false;\r\n\t};\r\n\r\n\tNSTouchToMouse.prototype.__fireCallback = function(callbackKey,event,touch)\r\n\t{\r\n\t\tif(this.__config[callbackKey])\r\n\t\t{\r\n\t\t\tthis.__config[callbackKey](touch.screenX,touch.screenY,event);\r\n\t\t}\r\n\t};\r\n\r\n\treturn NSTouchToMouse;\r\n})();\r\nnsModuleExport(this,\"NSTouchToMouse\",NSTouchToMouse);";