The addition of a cancel swipe feature to an HTML5 eBook is causing the text input field for note-taking to malfunction

I am currently working on the development of a process to create HTML5 based eBooks for both desktop and mobile use using Adobe InDesign and exporting them with a plugin called In5. This plugin allows for the incorporation of html, css, and javascript during export. The challenge I have run into is that a portion of the smooth swipe JS/JQuery code that I discovered on the In5 forums seems to be causing issues with the text input field on desktop browsers (oddly enough, it does not affect iPads).

$(function(){
  $("#container").swipe("destroy");
  var pageWidth = parseInt($(".page").width());
  var pageChangeThreshold = pageWidth*.001;
  var pageWrap = $('.pages'), startPos, vertMode = false,
  nextProp = 'left', backProp = 'right', moveProp = 'left';
  
var cancelSwipe = function(){                                       //This Function breaks the note taking for some reason, changing name does not fix. removing the function totally breaks the swiping
pageWrap.animate({left:startPos+'px'}, 'fast');
};


  $("#container").swipe({
          allowPageScroll: (vertMode ? 'horizontal' : 'vertical'), fingers:1, 
          excludedElements:$.fn.swipe.defaults.excludedElements+',.mejs-overlay-button,map,[onclick],[data-useswipe="1"],[data-tapstart="1"], .panzoom,.scroll-horiz',
        swipeStatus:function(event, phase, direction, distance, duration, fingers) {
            switch(phase){
                case 'start':
                    startPos = parseInt(pageWrap.css(moveProp));
                    break;
                case 'end':
                    if(distance > pageChangeThreshold){
                        switch(direction){  
                            case nextProp:
                                if(nav.current < nav.numPages) nav.next();
                                else cancelSwipe();
                                break;
                            case backProp:
                                if(nav.current > 1) nav.back();
                                else cancelSwipe();
                                break;
                        }

                    } else {
                        cancelSwipe();
                    }

                    break;

                case 'move':            
                    switch(direction){
                        case nextProp:
                            pageWrap.css(moveProp, (startPos-distance)+'px');
                            break;
                        case backProp:
                            pageWrap.css(moveProp, (startPos+distance)+'px');
                            break;
                    }

                    break;

                case 'cancel':          //These lines of code seem to break the pop-out menu on iOS, renamed from 'cancel' to 'cancelSwipe' seems to have fixed this
                    cancelSwipe();
                    break;
            }
        },
        
        threshold:4,
        maxTimeThreshold:4000
    });
})

The exact line causing the issue appears to be:

pageWrap.animate({left:startPos+'px'}, 'fast');

This is the code we designed for the note-taking application:

    <div class="allnotes">
    <input type="text" id="textInput"><button id="add" class="addButton"></button>
        <hr>
        <div id="notes" class="notes"></div>
        <script>
            function get_notes() {
                var notes = new Array;
                var notes_str = localStorage.getItem('note');
                if (notes_str !== null) {
                    notes = JSON.parse(notes_str);
                }
                return notes;
            }
            function add() {
                var textInput = " <button id=\"goto" +$('.page').attr('data-name')+"\" class=\"gotopagebutton\">pg. "+$('.page').attr('data-name')+"</button>"+document.getElementById('textInput').value;
                var notes = get_notes();
                notes.push(textInput);
                localStorage.setItem('note', JSON.stringify(notes));
                shownotes();
                return false;
            }
            function remove() {
                var id = this.getAttribute('id');
                var notes = get_notes();
                notes.splice(id, 1);
                localStorage.setItem('note', JSON.stringify(notes));
                shownotes();
                return false;
            }
            function gotopage(destinationpageNumber) {
                var currentpagenumber = $('.page').attr('data-name');
                currentpagenumber = parseInt(currentpagenumber);
                destinationpageNumber = parseInt(destinationpageNumber.split(' ')[1]);
                var distance = destinationpageNumber - currentpagenumber;
                var offset = currentpagenumber - nav.current;
                nav.to(nav.current+distance);
                // if (distance == 0) {
                //     go(event,[{n:1,id:96334,act:'reverse'},{n:1,id:96324,act:'reverse'}]);
                // }
            }
            function shownotes() {
                var notes = get_notes();
                var html = '<ul>';
                for (var i = 0; i < notes.length; i++) {
                    html += '<li>' + notes[i] + " " + '<button class=\"remove\" id=\"' + i + '\">x</button></li>';
                };
                html += '</ul>';
                document.getElementById('notes').innerHTML = html;
                var removebuttons = document.getElementsByClassName('remove');
                for (var i = 0; i < removebuttons.length; i++) {
                    removebuttons[i].addEventListener('click', remove);
                };
                var gotopagebuttons = document.getElementsByClassName('gotopagebutton');
                for (var i = 0; i < gotopagebuttons.length; i++) { 
                    gotopagebuttons[i].addEventListener('click', gotopage.bind(null, gotopagebuttons[i].innerHTML));
                };
                
            }
            document.getElementById('add').addEventListener('click', add);
            shownotes();
        </script>
</div>

Can someone assist in identifying why the .animate function might disrupt the selection or focus of the text input field? Alternatively, could you suggest another method to cancel a swipe action on a touch screen device (such as an iPad or Windows tablet)?

Here is a sample page showing the problem upon export.

Answer №1

following the line (page: 0001.html)

  runFunction();

insert this:

$("#textInput").focus();

this solution appears to resolve the issue of not being able to manually select the input box. It seems like there is a script running that prevents manual selection, as evidenced by the page blinking when attempting to click on it. However, setting focus through jquery fixes the problem.

I trust this information proves helpful

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A technique for postponing the addition of a class to a div

I am attempting to create a unique type of slider effect. Inside a single div named #slider, I have 9 items displayed in a line. Link to JsFiddle The slider is 1860px wide, but only 620px is visible at any given time due to the parent having an overflow: ...

Revamp the design of the Google image layout

I am trying to replicate the layout of a Google search results page. My goal is to have a full-width div appear on screen when an image is clicked, with a small triangle at the bottom of the clicked image. I attempted to place the img inside another div, ...

How can I parse URL paths in jQuery for ASP.NET?

I want to incorporate "~/" and have it resolved on the client side. Here is an example of what I am trying to do: <a href="~/page.aspx">website link</a> <img src="~/page.aspx" /> In my ASP.NET code, I have my base URLs set up like this ...

Comparing functions and function issues when using onClick in JavaScript

I have successfully created an Image Element on my web page dynamically using JavaScript. I am now trying to set an onClick event for the newly created image element. However, I am encountering a problem and I cannot figure out why?, This is the code I ...

What could be causing the transparency of my buttons when viewed on my device?

Recently, I customized the appearance of buttons in my App by adding colors. Surprisingly, everything looks perfect when I test it on a local server on my PC. However, once I deploy the App to my Android device, all the buttons become transparent. In my v ...

Customizing padding and margin in material-UI styles

Having issues with excessive padding and margin inside my tab component, even after trying to override it. I've followed some suggestions on StackOverflow but none seem to work. Here's how it looks: https://i.stack.imgur.com/Bgi3u.png Here is th ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Modifying the boolean variable value in aspx.vb code

Recently, I started learning asp.net and I am facing an issue with changing the value of my boolean variable when I click a button. Below is my code: Partial Class Title Dim checker As Boolean Protected Sub Enterbutton1(ByVal sender As Object, ByVal e ...

Filtering JSON objects in Vue when the API is only returning a limited number of items

Currently, I am retrieving a JSON Object from an API with a limit of 200. The process involves fetching the initial 200 like this: https://testapi.com/posts.json In our application, we have implemented pagination with 10 posts per page. When we reach pag ...

Refining a collection of item elements by examining a string attribute, disregarding letter case differences

I'm working on a code snippet that generates item components from my list of objects (Frivillig). <app-frivillig-item *ngFor="let frivilligEl of frivillige" [frivillig]="frivilligEl"> </app-frivillig-item> Now, I have a new requireme ...

Troubleshooting a Jquery Ajax Problem

Currently, I am developing a feature for my project that involves creating popup windows for tips. Once the user clicks on the 'turn on tips' button, these windows are supposed to appear next to specific elements. However, I encountered an issue ...

Seeking assistance to prevent data duplication when transferring information from list1 to list2 in React.js

As I work on developing two lists in React.js, I encountered an issue with avoiding repetitions when transferring items from list-1 to list-2. I need assistance creating a function that prevents duplicate items in list-2 while also ensuring that the items ...

Exploring Next.js with getStaticPaths for multi-language support

In my current Next.js project, I am working on implementing multiple locales for dynamic pages using i18n. Within my next.config.js file, the following configuration is set: module.exports = { i18n: { locales: ["en-US", "da-DK", "se-SE", "no-NO", "n ...

What causes *ngIf to display blank boxes and what is the solution to resolve this problem?

I am currently working on an HTML project where I need to display objects from an array using Angular. My goal is to only show the objects in the array that are not empty. While I have managed to hide the content of empty objects, the boxes holding this co ...

Error in HTML: Text variable is not displaying the number value

Currently, I am facing a challenge with my code. I have a variable named "Timer" that I want to increment by one and then display the number. However, I am unable to see the "Test Successful!" message displayed on the screen. Surprisingly, there are no e ...

Issue with CSS rendering in Internet Explorer

Although my website appears perfectly in Firefox, the entire style sheet doesn't seem to load properly in IE 7. It's only displaying certain styles. Any assistance on this issue would be greatly appreciated! ...

Saving table sorting in Redux with Ant Design Table

I am currently working with Antd Version 4.2.2 in my ReactJS project. Specifically, I am utilizing the Ant Design < Table /> component. My goal is to save the sorting order that is applied to the columns into Redux state. Here is my current approa ...

"MongoDB's .find function functions properly in the shell environment, but encounters issues when

As a newcomer to Node Express Mongo, I decided to venture into creating my own website after following tutorials. The page I'm working on is a login page. While other people's code has worked for me, my attempt didn't go as planned. Even con ...

Phase 2 "Loading" visual backdrop

I'm attempting to include a loading animation GIF in my Cycle 2 plugin. Is there a way to ensure that the GIF loads before the images? Right now, I have set my loading.gif as a background image. The issue is that the loading.gif isn't displaying ...

ReactJS bug: Array rendering problem affected by recent changes

Why does ReactJS remove the first element instead of the middle element when using array.splice to remove an element from an array? This is my code. I am using Redux as well. const reducerNotesAndLogin = (state = initialState, action) => { var tableNo ...