JavaScriptを色々あれこれしようとするがひたすら失敗を繰り返している
| Revision | 46 (tree) |
|---|---|
| Time | 2016-12-10 08:56:46 |
| Author | |
(empty log message)
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | if (null != this.DOMbase) { |
| 38 | 38 | this.debuglog('initDOMobj() Clear the reference to DOM element'); |
| 39 | 39 | this.DOMobject.removeEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 40 | + this.DOMobject.removeEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 40 | 41 | |
| 41 | 42 | this.DOMbase.removeChild(this.DOMobject); |
| 42 | 43 | this.DOMobject.outerHTML = ""; |
| @@ -116,6 +117,7 @@ | ||
| 116 | 117 | this.DOMbase.dataset.mirrorlr = this.mirrorLRdeg; |
| 117 | 118 | this.DOMbase.dataset.mirrorud = this.mirrorUDdeg; |
| 118 | 119 | this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 120 | + this.DOMbase.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 119 | 121 | // DispObj作成 |
| 120 | 122 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 121 | 123 | this.DOMobject = document.createElement(elType); |
| @@ -220,6 +222,7 @@ | ||
| 220 | 222 | this.mirrorLRdeg = parseInt(ele.dataset.mirrorlr); |
| 221 | 223 | this.mirrorUDdeg = parseInt(ele.dataset.mirrorud); |
| 222 | 224 | this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 225 | + this.DOMbase.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 223 | 226 | |
| 224 | 227 | if( ele.children.length < 1 ){ |
| 225 | 228 | console.error('保存ファイルから前回の状態を復元できません 要素の構成エラー 表示に必要な要素の情報が欠けている\nobjid=' + ele.dataset.objid + ', className=' + ele.className); |
| @@ -315,7 +318,17 @@ | ||
| 315 | 318 | window.appArea.setMouseEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); |
| 316 | 319 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 317 | 320 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 318 | - | |
| 321 | + this.startMovingElement(evt); | |
| 322 | + } | |
| 323 | + onTouchStart(evt){ | |
| 324 | + this.debuglog("onTouchStart"); | |
| 325 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 326 | + window.appArea.setSingleTouchEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 327 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 328 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 329 | + this.startMovingElement(evt.touches[0]); | |
| 330 | + } | |
| 331 | + startMovingElement(evt){ | |
| 319 | 332 | /* test |
| 320 | 333 | let xy1 = rotateUD(0, -45, parseInt(evt.pageX), parseInt(evt.pageY)); |
| 321 | 334 | let xy2 = rotateZ(0, 0, 45, xy1[0], xy1[1]); |
| @@ -57,6 +57,7 @@ | ||
| 57 | 57 | this.domScaler.classList.add('scaler'); |
| 58 | 58 | this.domScaler.title = "ドラッグでサイズを変更します"; |
| 59 | 59 | this.domScaler.addEventListener('mousedown', this.onMouseDownScale.bind(this), false); |
| 60 | + this.domScaler.addEventListener('touchstart', this.onTouchStartScale.bind(this), false); | |
| 60 | 61 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domScaler)); |
| 61 | 62 | } |
| 62 | 63 | // 回転操作マーカー作成 |
| @@ -66,6 +67,7 @@ | ||
| 66 | 67 | this.domRoller.classList.add('roller'); |
| 67 | 68 | this.domRoller.title = "ドラッグで回転します"; |
| 68 | 69 | this.domRoller.addEventListener('mousedown', this.onMouseDownRoll.bind(this), false); |
| 70 | + this.domRoller.addEventListener('touchstart', this.onTouchStartRoll.bind(this), false); | |
| 69 | 71 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domRoller)); |
| 70 | 72 | } |
| 71 | 73 | createMirrorLR() { |
| @@ -74,6 +76,7 @@ | ||
| 74 | 76 | this.domMirrorLR.classList.add('mirrorLR'); |
| 75 | 77 | this.domMirrorLR.title = "左右反転します"; |
| 76 | 78 | this.domMirrorLR.addEventListener('mousedown', this.onMouseDownMirror.bind(this), false); |
| 79 | + this.domMirrorLR.addEventListener('touchstart', this.onTouchStartMirror.bind(this), false); | |
| 77 | 80 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domMirrorLR)); |
| 78 | 81 | } |
| 79 | 82 | createMirrorUD() { |
| @@ -82,6 +85,7 @@ | ||
| 82 | 85 | this.domMirrorUD.classList.add('mirrorUD'); |
| 83 | 86 | this.domMirrorUD.title = "上下反転します"; |
| 84 | 87 | this.domMirrorUD.addEventListener('mousedown', this.onMouseDownMirror.bind(this), false); |
| 88 | + this.domMirrorUD.addEventListener('touchstart', this.onTouchStartMirror.bind(this), false); | |
| 85 | 89 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domMirrorUD)); |
| 86 | 90 | } |
| 87 | 91 |
| @@ -181,12 +185,22 @@ | ||
| 181 | 185 | if (eleFocus.length < 2) return; |
| 182 | 186 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 183 | 187 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 184 | - | |
| 185 | 188 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 186 | 189 | window.appArea.setMouseEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); |
| 187 | - | |
| 188 | - | |
| 189 | - | |
| 190 | + this.startScaling(evt); | |
| 191 | + } | |
| 192 | + onTouchStartScale(evt){ | |
| 193 | + this.debuglog('onTouchStartScale'); | |
| 194 | + let eleFocus = this.getFocusdElements(); | |
| 195 | + if (eleFocus.length < 2) return; | |
| 196 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 197 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 198 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 199 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 200 | + this.startScaling(evt.touches[0]); | |
| 201 | + } | |
| 202 | + startScaling(evt){ | |
| 203 | + let eleFocus = this.getFocusdElements(); | |
| 190 | 204 | // 画像を反転している場合、マウス入力座標も反転させる |
| 191 | 205 | this.x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; |
| 192 | 206 | this.y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; |
| @@ -385,11 +399,22 @@ | ||
| 385 | 399 | if (eleFocus.length < 2) return; |
| 386 | 400 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 387 | 401 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 388 | - | |
| 389 | 402 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 390 | 403 | window.appArea.setMouseEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); |
| 391 | - | |
| 392 | - | |
| 404 | + this.startRolling(evt); | |
| 405 | + } | |
| 406 | + onTouchStartRoll(evt){ | |
| 407 | + this.debuglog('onTouchStartRoll'); | |
| 408 | + let eleFocus = this.getFocusdElements(); | |
| 409 | + if (eleFocus.length < 2) return; | |
| 410 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 411 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 412 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 413 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 414 | + this.startRolling(evt.touches[0]); | |
| 415 | + } | |
| 416 | + startRolling(evt){ | |
| 417 | + let eleFocus = this.getFocusdElements(); | |
| 393 | 418 | // 変化しない値を使いまわすために保持 |
| 394 | 419 | this.x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; |
| 395 | 420 | this.y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; |
| @@ -455,10 +480,16 @@ | ||
| 455 | 480 | this.debuglog('onMouseDownMirror'); |
| 456 | 481 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 457 | 482 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 458 | - | |
| 459 | 483 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 460 | 484 | window.appArea.setMouseEventObj(null, this.mouseMoveMirror.bind(this), this.mouseUpMirror.bind(this)); |
| 461 | 485 | } |
| 486 | + onTouchStartMirror(evt) { | |
| 487 | + this.debuglog('onTouchStartMirror'); | |
| 488 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 489 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 490 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 491 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveMirror.bind(this), this.mouseUpMirror.bind(this)); | |
| 492 | + } | |
| 462 | 493 | mouseMoveMirror(evt) { |
| 463 | 494 | let eleFocus = this.getFocusdElements(); |
| 464 | 495 | if (eleFocus.length < 2) return; |
| @@ -6,6 +6,8 @@ | ||
| 6 | 6 | this.DOMobject = dom; |
| 7 | 7 | this.mouseMoveFunc = null; |
| 8 | 8 | this.mouseUpFunc = null; |
| 9 | + this.touchMoveFunc = null; | |
| 10 | + this.touchEndFunc = null; | |
| 9 | 11 | } |
| 10 | 12 | // 保存ファイルから編集エリア内容 (DispFieldの divとそこに連なるelement) を |
| 11 | 13 | // 取得するための正規表現object取得 |
| @@ -25,6 +27,9 @@ | ||
| 25 | 27 | this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); |
| 26 | 28 | this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 27 | 29 | this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); |
| 30 | + this.DOMobject.addEventListener('touchmove', this.onTouchMove.bind(this), false); | |
| 31 | + this.DOMobject.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 32 | + this.DOMobject.addEventListener('touchend', this.onTouchEnd.bind(this), false); | |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | 35 |
| @@ -104,14 +109,39 @@ | ||
| 104 | 109 | this.mouseMoveFunc = mouseMove; |
| 105 | 110 | this.mouseUpFunc = mouseUp; |
| 106 | 111 | } |
| 112 | + // Touch I/F 用 | |
| 113 | + // 最初のtouch objectのみを返す (そのため mouse I/Fと同じように扱える) | |
| 114 | + setSingleTouchEventObj( | |
| 115 | + strclass, // touch end callback 第2引数 targetとして返してほしいelementが持つ css class名 | |
| 116 | + touchMove, // touch moveで呼んでほしい関数 or null | |
| 117 | + touchEnd // touch endで呼んでほしい関数 or null | |
| 118 | + ) { | |
| 119 | + this.debuglog('setSingleTouchEventObj strclass=' + strclass + ', callbackMove=' + ((null != touchMove)? touchMove.name: 'null') + ', callbackUp=' + ((null != touchEnd)? touchEnd.name: 'null')); | |
| 107 | 120 | |
| 121 | + // Callbackを上書きしてしまう場合はエラー出力し、ひとまず処理を継続 | |
| 122 | + if (null != touchMove || null != touchEnd) { | |
| 123 | + if (null != this.touchMoveFunc || null != this.touchEndFunc) { | |
| 124 | + console.error('マウスイベント callback設定上書き \n\ | |
| 125 | +Before strclass=' + this.strclass + 'callbackMove=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', callbackUp=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null') + '\n\ | |
| 126 | +After strclass=' + strclass + 'callbackMove=' + ((null != touchMove) ? touchMove.name : 'null') + ', callbackUp=' + ((null != touchEnd) ? touchEnd.name : 'null')); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + this.strclass = strclass; | |
| 131 | + this.touchMoveFunc = touchMove; | |
| 132 | + this.touchEndFunc = touchEnd; | |
| 133 | + } | |
| 134 | + | |
| 108 | 135 | // Event handler ------------------- |
| 109 | 136 | |
| 110 | - // ■マウス左ボタン押下 (Drag処理) | |
| 137 | + // マウス左ボタン押下 (Drag処理) | |
| 111 | 138 | onMouseDown(evt) { |
| 112 | 139 | this.debuglog('マウスクリック onMouseDown()'); |
| 113 | 140 | } |
| 114 | - // ■ マウス移動 (ドラッグ中) | |
| 141 | + onTouchStart(evt){ | |
| 142 | + this.debuglog('タッチ開始 onTouchStart()'); | |
| 143 | + } | |
| 144 | + // マウス移動 (ドラッグ中) | |
| 115 | 145 | onMouseMove(evt) { |
| 116 | 146 | |
| 117 | 147 | if (null != this.mouseMoveFunc) { |
| @@ -118,13 +148,18 @@ | ||
| 118 | 148 | this.mouseMoveFunc(evt); |
| 119 | 149 | } |
| 120 | 150 | } |
| 151 | + onTouchMove(evt){ | |
| 152 | + if (null != this.touchMoveFunc) { | |
| 153 | + this.touchMoveFunc(evt.touches[0]); | |
| 154 | + } | |
| 155 | + } | |
| 121 | 156 | |
| 122 | - // ■ ドロップ処理 | |
| 157 | + // ドロップ処理 | |
| 123 | 158 | onMouseUp(evt) { |
| 124 | 159 | this.debuglog('マウスアップ onMouseUp() findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); |
| 125 | 160 | let e = findClassNameParent(this.strclass, evt.target); |
| 126 | 161 | if (null == e) { |
| 127 | - console.error('マウスアップ 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 162 | + console.error('入力完了処理 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 128 | 163 | // ひとまず処理を継続する |
| 129 | 164 | } |
| 130 | 165 |
| @@ -132,7 +167,19 @@ | ||
| 132 | 167 | this.mouseUpFunc(evt, e); |
| 133 | 168 | } |
| 134 | 169 | } |
| 170 | + onTouchEnd(evt){ | |
| 171 | + this.debuglog('タッチエンド onTouchEnd() findClass=' + this.strclass + ', callback move=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', End=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null')); | |
| 172 | + let e = findClassNameParent(this.strclass, evt.touches[0].target); | |
| 173 | + if (null == e) { | |
| 174 | + console.error('入力完了処理 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', End=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null')); | |
| 175 | + // ひとまず処理を継続する | |
| 176 | + } | |
| 135 | 177 | |
| 178 | + if (null != this.touchEndFunc) { | |
| 179 | + this.touchEndFunc(evt.touches[0], e); | |
| 180 | + } | |
| 181 | + } | |
| 136 | 182 | |
| 137 | 183 | |
| 184 | + | |
| 138 | 185 | } |
| @@ -30,6 +30,8 @@ | ||
| 30 | 30 | this.DOMpalbg[cnt].style.top = 40 + 'px'; |
| 31 | 31 | this.DOMpalbg[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 32 | 32 | this.DOMpalbg[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 33 | + this.DOMpalbg[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 34 | + this.DOMpalbg[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 33 | 35 | this.DOMpalbg[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 34 | 36 | this.DOMpalbg[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 35 | 37 | this.DOMpalbg[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -41,6 +43,8 @@ | ||
| 41 | 43 | this.DOMpaltxtcol[cnt].style.top = 40 + 'px'; |
| 42 | 44 | this.DOMpaltxtcol[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 43 | 45 | this.DOMpaltxtcol[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 46 | + this.DOMpaltxtcol[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 47 | + this.DOMpaltxtcol[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 44 | 48 | this.DOMpaltxtcol[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 45 | 49 | this.DOMpaltxtcol[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 46 | 50 | this.DOMpaltxtcol[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -52,6 +56,8 @@ | ||
| 52 | 56 | this.DOMpalact[cnt].style.top = 40 + 'px'; |
| 53 | 57 | this.DOMpalact[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 54 | 58 | this.DOMpalact[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 59 | + this.DOMpalact[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 60 | + this.DOMpalact[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 55 | 61 | this.DOMpalact[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 56 | 62 | this.DOMpalact[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 57 | 63 | this.DOMpalact[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -63,6 +69,8 @@ | ||
| 63 | 69 | this.DOMpalset[cnt].style.top = 40 + 'px'; |
| 64 | 70 | this.DOMpalset[cnt].addEventListener('mousedown', this.onMouseDownSetting.bind(this), false); |
| 65 | 71 | this.DOMpalset[cnt].addEventListener('mouseup', this.mouseUpSetting.bind(this), false); |
| 72 | + this.DOMpalset[cnt].addEventListener('touchstart', this.onTouchStartSetting.bind(this), false); | |
| 73 | + this.DOMpalset[cnt].addEventListener('touchend', this.touchEndSetting.bind(this), false); | |
| 66 | 74 | this.DOMpalset[cnt].addEventListener('dragstart', prohibitDropHandler_dragStart.bind(this), false); |
| 67 | 75 | this.DOMpalset[cnt].addEventListener('dragover', prohibitDropHandler_dragOver.bind(this), false); |
| 68 | 76 | this.DOMpalset[cnt].addEventListener('drop', prohibitDropHandler_drop.bind(this), false); |
| @@ -208,10 +216,18 @@ | ||
| 208 | 216 | onMouseDown(evt) { |
| 209 | 217 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 210 | 218 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 211 | - | |
| 212 | 219 | // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) |
| 213 | 220 | window.appArea.setMouseEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); |
| 214 | - | |
| 221 | + this.startMovingElement(evt); | |
| 222 | + } | |
| 223 | + onTouchStart(evt){ | |
| 224 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 225 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 226 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) | |
| 227 | + window.appArea.setSingleTouchEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 228 | + this.startMovingElement(evt.touches[0]); | |
| 229 | + } | |
| 230 | + startMovingElement(evt){ | |
| 215 | 231 | // Drag対象を保持 |
| 216 | 232 | this.draggingDOM = evt.target; |
| 217 | 233 | // ElementのDrag開始位置を保持 |
| @@ -251,7 +267,15 @@ | ||
| 251 | 267 | if (null == this.draggingDOM) return; |
| 252 | 268 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 253 | 269 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 254 | - | |
| 270 | + this.endMovingElement(evt); | |
| 271 | + } | |
| 272 | + touchEnd(evt) { | |
| 273 | + if (null == this.draggingDOM) return; | |
| 274 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 275 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 276 | + this.endMovingElement(evt.touches[0]); | |
| 277 | + } | |
| 278 | + endMovingElement(evt){ | |
| 255 | 279 | let palobjid = this.draggingDOM.dataset.objid; |
| 256 | 280 | let palid = this.draggingDOM.dataset.palid; |
| 257 | 281 |
| @@ -311,11 +335,21 @@ | ||
| 311 | 335 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 312 | 336 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 313 | 337 | } |
| 338 | + onTouchStartSetting(evt) { | |
| 339 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 340 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 341 | + } | |
| 314 | 342 | mouseUpSetting(evt) { |
| 315 | 343 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 316 | 344 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 317 | - | |
| 318 | - | |
| 345 | + this.executeSettingButton(evt); | |
| 346 | + } | |
| 347 | + touchEndSetting(evt){ | |
| 348 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 349 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 350 | + this.executeSettingButton(evt.touches[0]); | |
| 351 | + } | |
| 352 | + executeSettingButton(evt){ | |
| 319 | 353 | switch (evt.target.dataset.objid) { |
| 320 | 354 | case "palset0": // 設定パレット非表示 |
| 321 | 355 | this.DOMpalset[0].parentNode.style.display = "none"; |
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | if (null != this.DOMbase) { |
| 38 | 38 | this.debuglog('initDOMobj() Clear the reference to DOM element'); |
| 39 | 39 | this.DOMobject.removeEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 40 | + this.DOMobject.removeEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 40 | 41 | |
| 41 | 42 | this.DOMbase.removeChild(this.DOMobject); |
| 42 | 43 | this.DOMobject.outerHTML = ""; |
| @@ -116,6 +117,7 @@ | ||
| 116 | 117 | this.DOMbase.dataset.mirrorlr = this.mirrorLRdeg; |
| 117 | 118 | this.DOMbase.dataset.mirrorud = this.mirrorUDdeg; |
| 118 | 119 | this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 120 | + this.DOMbase.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 119 | 121 | // DispObj作成 |
| 120 | 122 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 121 | 123 | this.DOMobject = document.createElement(elType); |
| @@ -220,6 +222,7 @@ | ||
| 220 | 222 | this.mirrorLRdeg = parseInt(ele.dataset.mirrorlr); |
| 221 | 223 | this.mirrorUDdeg = parseInt(ele.dataset.mirrorud); |
| 222 | 224 | this.DOMbase.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 225 | + this.DOMbase.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 223 | 226 | |
| 224 | 227 | if( ele.children.length < 1 ){ |
| 225 | 228 | console.error('保存ファイルから前回の状態を復元できません 要素の構成エラー 表示に必要な要素の情報が欠けている\nobjid=' + ele.dataset.objid + ', className=' + ele.className); |
| @@ -315,7 +318,17 @@ | ||
| 315 | 318 | window.appArea.setMouseEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); |
| 316 | 319 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 317 | 320 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 318 | - | |
| 321 | + this.startMovingElement(evt); | |
| 322 | + } | |
| 323 | + onTouchStart(evt){ | |
| 324 | + this.debuglog("onTouchStart"); | |
| 325 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 326 | + window.appArea.setSingleTouchEventObj('DispBase',this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 327 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 328 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 329 | + this.startMovingElement(evt.touches[0]); | |
| 330 | + } | |
| 331 | + startMovingElement(evt){ | |
| 319 | 332 | /* test |
| 320 | 333 | let xy1 = rotateUD(0, -45, parseInt(evt.pageX), parseInt(evt.pageY)); |
| 321 | 334 | let xy2 = rotateZ(0, 0, 45, xy1[0], xy1[1]); |
| @@ -57,6 +57,7 @@ | ||
| 57 | 57 | this.domScaler.classList.add('scaler'); |
| 58 | 58 | this.domScaler.title = "ドラッグでサイズを変更します"; |
| 59 | 59 | this.domScaler.addEventListener('mousedown', this.onMouseDownScale.bind(this), false); |
| 60 | + this.domScaler.addEventListener('touchstart', this.onTouchStartScale.bind(this), false); | |
| 60 | 61 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domScaler)); |
| 61 | 62 | } |
| 62 | 63 | // 回転操作マーカー作成 |
| @@ -66,6 +67,7 @@ | ||
| 66 | 67 | this.domRoller.classList.add('roller'); |
| 67 | 68 | this.domRoller.title = "ドラッグで回転します"; |
| 68 | 69 | this.domRoller.addEventListener('mousedown', this.onMouseDownRoll.bind(this), false); |
| 70 | + this.domRoller.addEventListener('touchstart', this.onTouchStartRoll.bind(this), false); | |
| 69 | 71 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domRoller)); |
| 70 | 72 | } |
| 71 | 73 | createMirrorLR() { |
| @@ -74,6 +76,7 @@ | ||
| 74 | 76 | this.domMirrorLR.classList.add('mirrorLR'); |
| 75 | 77 | this.domMirrorLR.title = "左右反転します"; |
| 76 | 78 | this.domMirrorLR.addEventListener('mousedown', this.onMouseDownMirror.bind(this), false); |
| 79 | + this.domMirrorLR.addEventListener('touchstart', this.onTouchStartMirror.bind(this), false); | |
| 77 | 80 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domMirrorLR)); |
| 78 | 81 | } |
| 79 | 82 | createMirrorUD() { |
| @@ -82,6 +85,7 @@ | ||
| 82 | 85 | this.domMirrorUD.classList.add('mirrorUD'); |
| 83 | 86 | this.domMirrorUD.title = "上下反転します"; |
| 84 | 87 | this.domMirrorUD.addEventListener('mousedown', this.onMouseDownMirror.bind(this), false); |
| 88 | + this.domMirrorUD.addEventListener('touchstart', this.onTouchStartMirror.bind(this), false); | |
| 85 | 89 | window.renderLoop.requestRenderFunc(this.renderCreateForcus.bind(this, this.domMirrorUD)); |
| 86 | 90 | } |
| 87 | 91 |
| @@ -181,12 +185,22 @@ | ||
| 181 | 185 | if (eleFocus.length < 2) return; |
| 182 | 186 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 183 | 187 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 184 | - | |
| 185 | 188 | // Mouse eventをappAreaからScalerに渡してもらうように設定 |
| 186 | 189 | window.appArea.setMouseEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); |
| 187 | - | |
| 188 | - | |
| 189 | - | |
| 190 | + this.startScaling(evt); | |
| 191 | + } | |
| 192 | + onTouchStartScale(evt){ | |
| 193 | + this.debuglog('onTouchStartScale'); | |
| 194 | + let eleFocus = this.getFocusdElements(); | |
| 195 | + if (eleFocus.length < 2) return; | |
| 196 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 197 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 198 | + // Mouse eventをappAreaからScalerに渡してもらうように設定 | |
| 199 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveScale.bind(this), this.mouseUpScale.bind(this)); | |
| 200 | + this.startScaling(evt.touches[0]); | |
| 201 | + } | |
| 202 | + startScaling(evt){ | |
| 203 | + let eleFocus = this.getFocusdElements(); | |
| 190 | 204 | // 画像を反転している場合、マウス入力座標も反転させる |
| 191 | 205 | this.x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; |
| 192 | 206 | this.y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; |
| @@ -385,11 +399,22 @@ | ||
| 385 | 399 | if (eleFocus.length < 2) return; |
| 386 | 400 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 387 | 401 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 388 | - | |
| 389 | 402 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 390 | 403 | window.appArea.setMouseEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); |
| 391 | - | |
| 392 | - | |
| 404 | + this.startRolling(evt); | |
| 405 | + } | |
| 406 | + onTouchStartRoll(evt){ | |
| 407 | + this.debuglog('onTouchStartRoll'); | |
| 408 | + let eleFocus = this.getFocusdElements(); | |
| 409 | + if (eleFocus.length < 2) return; | |
| 410 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 411 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 412 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 413 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveRoll.bind(this), this.mouseUpRoll.bind(this)); | |
| 414 | + this.startRolling(evt.touches[0]); | |
| 415 | + } | |
| 416 | + startRolling(evt){ | |
| 417 | + let eleFocus = this.getFocusdElements(); | |
| 393 | 418 | // 変化しない値を使いまわすために保持 |
| 394 | 419 | this.x1 = parseInt(eleFocus[0].style.left) + parseInt(eleFocus[0].style.width) / 2; |
| 395 | 420 | this.y1 = parseInt(eleFocus[0].style.top) + parseInt(eleFocus[0].style.height) / 2; |
| @@ -455,10 +480,16 @@ | ||
| 455 | 480 | this.debuglog('onMouseDownMirror'); |
| 456 | 481 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 457 | 482 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 458 | - | |
| 459 | 483 | // Mouse eventをappAreaからRollerに渡してもらうように設定 |
| 460 | 484 | window.appArea.setMouseEventObj(null, this.mouseMoveMirror.bind(this), this.mouseUpMirror.bind(this)); |
| 461 | 485 | } |
| 486 | + onTouchStartMirror(evt) { | |
| 487 | + this.debuglog('onTouchStartMirror'); | |
| 488 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 489 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 490 | + // Mouse eventをappAreaからRollerに渡してもらうように設定 | |
| 491 | + window.appArea.setSingleTouchEventObj(null, this.mouseMoveMirror.bind(this), this.mouseUpMirror.bind(this)); | |
| 492 | + } | |
| 462 | 493 | mouseMoveMirror(evt) { |
| 463 | 494 | let eleFocus = this.getFocusdElements(); |
| 464 | 495 | if (eleFocus.length < 2) return; |
| @@ -6,6 +6,8 @@ | ||
| 6 | 6 | this.DOMobject = dom; |
| 7 | 7 | this.mouseMoveFunc = null; |
| 8 | 8 | this.mouseUpFunc = null; |
| 9 | + this.touchMoveFunc = null; | |
| 10 | + this.touchEndFunc = null; | |
| 9 | 11 | } |
| 10 | 12 | // 保存ファイルから編集エリア内容 (DispFieldの divとそこに連なるelement) を |
| 11 | 13 | // 取得するための正規表現object取得 |
| @@ -25,6 +27,9 @@ | ||
| 25 | 27 | this.DOMobject.addEventListener('mousemove', this.onMouseMove.bind(this), false); |
| 26 | 28 | this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 27 | 29 | this.DOMobject.addEventListener('mouseup', this.onMouseUp.bind(this), false); |
| 30 | + this.DOMobject.addEventListener('touchmove', this.onTouchMove.bind(this), false); | |
| 31 | + this.DOMobject.addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 32 | + this.DOMobject.addEventListener('touchend', this.onTouchEnd.bind(this), false); | |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | 35 |
| @@ -104,14 +109,39 @@ | ||
| 104 | 109 | this.mouseMoveFunc = mouseMove; |
| 105 | 110 | this.mouseUpFunc = mouseUp; |
| 106 | 111 | } |
| 112 | + // Touch I/F 用 | |
| 113 | + // 最初のtouch objectのみを返す (そのため mouse I/Fと同じように扱える) | |
| 114 | + setSingleTouchEventObj( | |
| 115 | + strclass, // touch end callback 第2引数 targetとして返してほしいelementが持つ css class名 | |
| 116 | + touchMove, // touch moveで呼んでほしい関数 or null | |
| 117 | + touchEnd // touch endで呼んでほしい関数 or null | |
| 118 | + ) { | |
| 119 | + this.debuglog('setSingleTouchEventObj strclass=' + strclass + ', callbackMove=' + ((null != touchMove)? touchMove.name: 'null') + ', callbackUp=' + ((null != touchEnd)? touchEnd.name: 'null')); | |
| 107 | 120 | |
| 121 | + // Callbackを上書きしてしまう場合はエラー出力し、ひとまず処理を継続 | |
| 122 | + if (null != touchMove || null != touchEnd) { | |
| 123 | + if (null != this.touchMoveFunc || null != this.touchEndFunc) { | |
| 124 | + console.error('マウスイベント callback設定上書き \n\ | |
| 125 | +Before strclass=' + this.strclass + 'callbackMove=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', callbackUp=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null') + '\n\ | |
| 126 | +After strclass=' + strclass + 'callbackMove=' + ((null != touchMove) ? touchMove.name : 'null') + ', callbackUp=' + ((null != touchEnd) ? touchEnd.name : 'null')); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + this.strclass = strclass; | |
| 131 | + this.touchMoveFunc = touchMove; | |
| 132 | + this.touchEndFunc = touchEnd; | |
| 133 | + } | |
| 134 | + | |
| 108 | 135 | // Event handler ------------------- |
| 109 | 136 | |
| 110 | - // ■マウス左ボタン押下 (Drag処理) | |
| 137 | + // マウス左ボタン押下 (Drag処理) | |
| 111 | 138 | onMouseDown(evt) { |
| 112 | 139 | this.debuglog('マウスクリック onMouseDown()'); |
| 113 | 140 | } |
| 114 | - // ■ マウス移動 (ドラッグ中) | |
| 141 | + onTouchStart(evt){ | |
| 142 | + this.debuglog('タッチ開始 onTouchStart()'); | |
| 143 | + } | |
| 144 | + // マウス移動 (ドラッグ中) | |
| 115 | 145 | onMouseMove(evt) { |
| 116 | 146 | |
| 117 | 147 | if (null != this.mouseMoveFunc) { |
| @@ -118,13 +148,18 @@ | ||
| 118 | 148 | this.mouseMoveFunc(evt); |
| 119 | 149 | } |
| 120 | 150 | } |
| 151 | + onTouchMove(evt){ | |
| 152 | + if (null != this.touchMoveFunc) { | |
| 153 | + this.touchMoveFunc(evt.touches[0]); | |
| 154 | + } | |
| 155 | + } | |
| 121 | 156 | |
| 122 | - // ■ ドロップ処理 | |
| 157 | + // ドロップ処理 | |
| 123 | 158 | onMouseUp(evt) { |
| 124 | 159 | this.debuglog('マウスアップ onMouseUp() findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); |
| 125 | 160 | let e = findClassNameParent(this.strclass, evt.target); |
| 126 | 161 | if (null == e) { |
| 127 | - console.error('マウスアップ 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 162 | + console.error('入力完了処理 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.mouseMoveFunc ? this.mouseMoveFunc.name : 'null') + ', Up=' + (this.mouseUpFunc ? this.mouseUpFunc.name : 'null')); | |
| 128 | 163 | // ひとまず処理を継続する |
| 129 | 164 | } |
| 130 | 165 |
| @@ -132,7 +167,19 @@ | ||
| 132 | 167 | this.mouseUpFunc(evt, e); |
| 133 | 168 | } |
| 134 | 169 | } |
| 170 | + onTouchEnd(evt){ | |
| 171 | + this.debuglog('タッチエンド onTouchEnd() findClass=' + this.strclass + ', callback move=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', End=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null')); | |
| 172 | + let e = findClassNameParent(this.strclass, evt.touches[0].target); | |
| 173 | + if (null == e) { | |
| 174 | + console.error('入力完了処理 指定要素が見つからない findClass=' + this.strclass + ', callback move=' + (this.touchMoveFunc ? this.touchMoveFunc.name : 'null') + ', End=' + (this.touchEndFunc ? this.touchEndFunc.name : 'null')); | |
| 175 | + // ひとまず処理を継続する | |
| 176 | + } | |
| 135 | 177 | |
| 178 | + if (null != this.touchEndFunc) { | |
| 179 | + this.touchEndFunc(evt.touches[0], e); | |
| 180 | + } | |
| 181 | + } | |
| 136 | 182 | |
| 137 | 183 | |
| 184 | + | |
| 138 | 185 | } |
| @@ -30,6 +30,8 @@ | ||
| 30 | 30 | this.DOMpalbg[cnt].style.top = 40 + 'px'; |
| 31 | 31 | this.DOMpalbg[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 32 | 32 | this.DOMpalbg[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 33 | + this.DOMpalbg[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 34 | + this.DOMpalbg[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 33 | 35 | this.DOMpalbg[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 34 | 36 | this.DOMpalbg[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 35 | 37 | this.DOMpalbg[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -41,6 +43,8 @@ | ||
| 41 | 43 | this.DOMpaltxtcol[cnt].style.top = 40 + 'px'; |
| 42 | 44 | this.DOMpaltxtcol[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 43 | 45 | this.DOMpaltxtcol[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 46 | + this.DOMpaltxtcol[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 47 | + this.DOMpaltxtcol[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 44 | 48 | this.DOMpaltxtcol[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 45 | 49 | this.DOMpaltxtcol[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 46 | 50 | this.DOMpaltxtcol[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -52,6 +56,8 @@ | ||
| 52 | 56 | this.DOMpalact[cnt].style.top = 40 + 'px'; |
| 53 | 57 | this.DOMpalact[cnt].addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 54 | 58 | this.DOMpalact[cnt].addEventListener('mouseup', this.mouseUp.bind(this), false); |
| 59 | + this.DOMpalact[cnt].addEventListener('touchstart', this.onTouchStart.bind(this), false); | |
| 60 | + this.DOMpalact[cnt].addEventListener('touchend', this.touchEnd.bind(this), false); | |
| 55 | 61 | this.DOMpalact[cnt].addEventListener('dragstart', this.onDragStart.bind(this), false); |
| 56 | 62 | this.DOMpalact[cnt].addEventListener('dragover', this.onDragOver.bind(this), false); |
| 57 | 63 | this.DOMpalact[cnt].addEventListener('drop', this.onDrop.bind(this), false); |
| @@ -63,6 +69,8 @@ | ||
| 63 | 69 | this.DOMpalset[cnt].style.top = 40 + 'px'; |
| 64 | 70 | this.DOMpalset[cnt].addEventListener('mousedown', this.onMouseDownSetting.bind(this), false); |
| 65 | 71 | this.DOMpalset[cnt].addEventListener('mouseup', this.mouseUpSetting.bind(this), false); |
| 72 | + this.DOMpalset[cnt].addEventListener('touchstart', this.onTouchStartSetting.bind(this), false); | |
| 73 | + this.DOMpalset[cnt].addEventListener('touchend', this.touchEndSetting.bind(this), false); | |
| 66 | 74 | this.DOMpalset[cnt].addEventListener('dragstart', prohibitDropHandler_dragStart.bind(this), false); |
| 67 | 75 | this.DOMpalset[cnt].addEventListener('dragover', prohibitDropHandler_dragOver.bind(this), false); |
| 68 | 76 | this.DOMpalset[cnt].addEventListener('drop', prohibitDropHandler_drop.bind(this), false); |
| @@ -208,10 +216,18 @@ | ||
| 208 | 216 | onMouseDown(evt) { |
| 209 | 217 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 210 | 218 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 211 | - | |
| 212 | 219 | // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) |
| 213 | 220 | window.appArea.setMouseEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); |
| 214 | - | |
| 221 | + this.startMovingElement(evt); | |
| 222 | + } | |
| 223 | + onTouchStart(evt){ | |
| 224 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 225 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 226 | + // Mouse eventをappAreaからCSSPalに渡してもらうように設定 (evt.targetは必ずpalette要素である前提。子要素なし。) | |
| 227 | + window.appArea.setSingleTouchEventObj(evt.target.dataset.objid, this.mouseMove.bind(this), this.mouseUp.bind(this)); | |
| 228 | + this.startMovingElement(evt.touches[0]); | |
| 229 | + } | |
| 230 | + startMovingElement(evt){ | |
| 215 | 231 | // Drag対象を保持 |
| 216 | 232 | this.draggingDOM = evt.target; |
| 217 | 233 | // ElementのDrag開始位置を保持 |
| @@ -251,7 +267,15 @@ | ||
| 251 | 267 | if (null == this.draggingDOM) return; |
| 252 | 268 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 253 | 269 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 254 | - | |
| 270 | + this.endMovingElement(evt); | |
| 271 | + } | |
| 272 | + touchEnd(evt) { | |
| 273 | + if (null == this.draggingDOM) return; | |
| 274 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 275 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 276 | + this.endMovingElement(evt.touches[0]); | |
| 277 | + } | |
| 278 | + endMovingElement(evt){ | |
| 255 | 279 | let palobjid = this.draggingDOM.dataset.objid; |
| 256 | 280 | let palid = this.draggingDOM.dataset.palid; |
| 257 | 281 |
| @@ -311,11 +335,21 @@ | ||
| 311 | 335 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 312 | 336 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 313 | 337 | } |
| 338 | + onTouchStartSetting(evt) { | |
| 339 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 340 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 341 | + } | |
| 314 | 342 | mouseUpSetting(evt) { |
| 315 | 343 | evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) |
| 316 | 344 | evt.preventDefault(); // 要素既定のdefault動作を止める |
| 317 | - | |
| 318 | - | |
| 345 | + this.executeSettingButton(evt); | |
| 346 | + } | |
| 347 | + touchEndSetting(evt){ | |
| 348 | + evt.stopPropagation(); // event伝播を自分のところで止める(上位に行かなくなる) | |
| 349 | + evt.preventDefault(); // 要素既定のdefault動作を止める | |
| 350 | + this.executeSettingButton(evt.touches[0]); | |
| 351 | + } | |
| 352 | + executeSettingButton(evt){ | |
| 319 | 353 | switch (evt.target.dataset.objid) { |
| 320 | 354 | case "palset0": // 設定パレット非表示 |
| 321 | 355 | this.DOMpalset[0].parentNode.style.display = "none"; |