Inheritance: jQueryApi.jQueryEvent
コード例 #1
0
ファイル: ReadModule.cs プロジェクト: a-fung/MangaWeb3
        private void TouchHandler(jQueryTouchEvent e)
        {
            if (!inTransition)
            {
                if (e.Type == "touch_start")
                {
                    inTouchHandler = true;
                    touchInitialOffset = Offset;
                    touchInitialXPosition = e.ClientX;

                    if (Settings.DisplayType == 2 && (currentVerticalScrollPage = GetMangaPageFromClientX(touchInitialXPosition)) != null && currentVerticalScrollPage.Height > attachedObject.GetHeight())
                    {
                        touchScrollDirection = 0;
                        touchInitialOffsetY = currentVerticalScrollPage.OffsetY;
                        touchInitialYPosition = e.ClientY;
                    }
                    else
                    {
                        touchScrollDirection = 1;
                    }
                }

                if (inTouchHandler)
                {
                    inTouchHandler = e.Type != "touch_end";

                    if (touchScrollDirection == 0)
                    {
                        if (Math.Abs(e.ClientX - touchInitialXPosition) > 35)
                        {
                            touchScrollDirection = 1;
                        }
                        else if (Math.Abs(e.ClientY - touchInitialYPosition) > 35)
                        {
                            touchScrollDirection = 2;

                            // try to snap to current page
                            if (Settings.UseAnimation)
                            {
                                mangaArea.AddClass("navigate");
                                Offset = -currentVerticalScrollPage.Offset;
                                Utility.OnTransitionEnd(
                                    mangaArea,
                                    delegate
                                    {
                                        mangaArea.RemoveClass("navigate");
                                    });
                            }
                            else
                            {
                                Offset = -currentVerticalScrollPage.Offset;
                            }
                        }
                    }

                    if (touchScrollDirection != 2)
                    {
                        MangaPage firstPage;
                        int targetOffset = e.ClientX - touchInitialXPosition + touchInitialOffset;
                        int minOffset = attachedObject.GetWidth() / 2 - (firstPage = GetMangaPage(pagesHead)).Offset - firstPage.Width;
                        int maxOffset = attachedObject.GetWidth() / 2 - GetMangaPage(pagesTail).Offset;
                        Offset = targetOffset < minOffset ? minOffset : targetOffset > maxOffset ? maxOffset : targetOffset;
                        RefreshMangaArea(false);

                        if (Settings.UseAnimation)
                        {
                            int index = 0;

                            if (e.Type == "touch_start")
                            {
                                lastTouchTime = new List<Date>();
                                lastTouchOffset = new List<int>();
                                lastTouchTime[0] = new Date();
                                lastTouchOffset[0] = Offset;
                            }
                            else
                            {
                                Date currentTime = new Date();
                                index = lastTouchOffset[lastTouchOffset.Count - 1] == Offset && currentTime - lastTouchTime[lastTouchOffset.Count - 1] < 100 ? lastTouchOffset.Count - 1 : lastTouchOffset.Count;
                                lastTouchTime[index] = currentTime;
                                lastTouchOffset[index] = Offset;
                            }

                            if (e.Type == "touch_end" && index > 0)
                            {
                                int dx = lastTouchOffset[index] - lastTouchOffset[index - 1];
                                int dt = lastTouchTime[index] - lastTouchTime[index - 1] + 1;
                                int distance = Math.Round(dx * 100 / dt);

                                lastTouchOffset = (List<int>)(object)(lastTouchTime = null);

                                if (distance != 0)
                                {
                                    inTransition = true;
                                    mangaArea.AddClass("inertia");
                                    Offset += distance;
                                    Utility.OnTransitionEnd(
                                        mangaArea,
                                        delegate
                                        {
                                            inTransition = false;
                                            mangaArea.RemoveClass("inertia");
                                            RefreshMangaArea();

                                            minOffset = attachedObject.GetWidth() / 2 - (firstPage = GetMangaPage(pagesHead)).Offset - firstPage.Width;
                                            maxOffset = attachedObject.GetWidth() / 2 - GetMangaPage(pagesTail).Offset;

                                            if (Offset < minOffset || Offset > maxOffset)
                                            {
                                                inTransition = true;
                                                mangaArea.AddClass("inertia-bounce");
                                                Offset = Offset < minOffset ? minOffset : maxOffset;
                                                Utility.OnTransitionEnd(
                                                    mangaArea,
                                                    delegate
                                                    {
                                                        inTransition = false;
                                                        mangaArea.RemoveClass("inertia-bounce");
                                                        RefreshMangaArea();
                                                    });
                                            }
                                        });
                                }
                            }
                        }
                    }

                    if (touchScrollDirection != 1)
                    {
                        int targetOffset = e.ClientY - touchInitialYPosition + touchInitialOffsetY;
                        int minOffset = attachedObject.GetHeight() - currentVerticalScrollPage.Height;
                        int maxOffset = 0;
                        currentVerticalScrollPage.OffsetY = targetOffset < minOffset ? minOffset : targetOffset > maxOffset ? maxOffset : targetOffset;

                        if (Settings.UseAnimation)
                        {
                            int index = 0;

                            if (e.Type == "touch_start")
                            {
                                lastTouchTimeY = new List<Date>();
                                lastTouchOffsetY = new List<int>();
                                lastTouchTimeY[0] = new Date();
                                lastTouchOffsetY[0] = currentVerticalScrollPage.OffsetY;
                            }
                            else
                            {
                                Date currentTime = new Date();
                                index = lastTouchOffsetY[lastTouchOffsetY.Count - 1] == currentVerticalScrollPage.OffsetY && currentTime - lastTouchTimeY[lastTouchOffsetY.Count - 1] < 100 ? lastTouchOffsetY.Count - 1 : lastTouchOffsetY.Count;
                                lastTouchTimeY[index] = currentTime;
                                lastTouchOffsetY[index] = currentVerticalScrollPage.OffsetY;
                            }

                            if (e.Type == "touch_end" && index > 0)
                            {
                                int dy = lastTouchOffsetY[index] - lastTouchOffsetY[index - 1];
                                int dt = lastTouchTimeY[index] - lastTouchTimeY[index - 1] + 1;
                                int distance = Math.Round(dy * 100 / dt);

                                lastTouchOffsetY = (List<int>)(object)(lastTouchTimeY = null);

                                if (distance != 0)
                                {
                                    inTransition = true;
                                    currentVerticalScrollPage.AttachedObject.AddClass("inertia");
                                    currentVerticalScrollPage.OffsetY += distance;
                                    Utility.OnTransitionEnd(
                                        currentVerticalScrollPage.AttachedObject,
                                        delegate
                                        {
                                            inTransition = false;
                                            currentVerticalScrollPage.AttachedObject.RemoveClass("inertia");

                                            if (currentVerticalScrollPage.OffsetY < minOffset || currentVerticalScrollPage.OffsetY > maxOffset)
                                            {
                                                inTransition = true;
                                                currentVerticalScrollPage.AttachedObject.AddClass("inertia-bounce");
                                                currentVerticalScrollPage.OffsetY = currentVerticalScrollPage.OffsetY < minOffset ? minOffset : maxOffset;
                                                Utility.OnTransitionEnd(
                                                    currentVerticalScrollPage.AttachedObject,
                                                    delegate
                                                    {
                                                        inTransition = false;
                                                        currentVerticalScrollPage.AttachedObject.RemoveClass("inertia-bounce");
                                                    });
                                            }
                                        });
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: ReadModule.cs プロジェクト: a-fung/MangaWeb3
 private void SliderTouchHandler(jQueryTouchEvent e)
 {
     if (!inTransition)
     {
         if (e.Type == "touch_start")
         {
             inSliderTouchHandler = true;
             sliderTouchInitialOffset = SliderOffset;
             sliderTouchInitialXPosition = e.ClientX;
         }
         else if (inSliderTouchHandler)
         {
             int targetOffset = e.ClientX - sliderTouchInitialXPosition + sliderTouchInitialOffset;
             int maxOffset = sliderHandle.Parent().GetInnerWidth() - sliderHandle.GetOuterWidth();
             targetOffset = targetOffset < 0 ? 0 : targetOffset > maxOffset ? maxOffset : targetOffset;
             CurrentPage = manga.pages - 1 - Math.Floor(targetOffset / (maxOffset + 1) * manga.pages);
             SliderOffset = targetOffset;
             if (e.Type == "touch_end")
             {
                 inSliderTouchHandler = false;
                 NavigateTo(CurrentPage);
             }
         }
     }
 }