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

Best practice for encapsulating property expressions in Angular templates

Repeating expression In my Angular 6 component template, I have the a && (b || c) expression repeated 3 times. I am looking for a way to abstract it instead of duplicating the code. parent.component.html <component [prop1]="1" [prop2]="a ...

tips for creating a mobile-friendly responsive button

I have been scouring the internet for a solution to this issue. Essentially, I am trying to position the button on the right side in desktop view. Here is an example: chrome view However, when the site is resized or viewed on mobile devices, the button sh ...

Submit a collection of images and an object to the server using ReactJS

I'm currently working with Reactjs on the frontend. In order to set the profile picture to state, I've implemented the following code: handleImageChange = (event) => { event.preventDefault(); var file = event.target.files[ ...

JavaScript Equivalent to C#'s BinaryReader.ReadString() Function

Currently, I am in the process of translating C# code into JavaScript. While transferring multiple datatypes from this file to matching functionalities found in various JavaScript libraries was relatively smooth, there is one specific function that seems t ...

Tips for deactivating data monitoring in a Vue.js component attribute

Looking to develop a Vue.js component that accepts properties from its parent component, like this example: <table-cell :value="foo" format="date" /> Although value and format are set as properties, Vue automatically sets up obse ...

In TypeScript, both 'module' and 'define' are nowhere to be found

When I transpile my TypeScript using "-m umd" for a project that includes server, client, and shared code, I encounter an issue where the client-side code does not work in the browser. Strangely, no errors are displayed in the browser console, and breakpoi ...

Is it possible for the vertical borders of <span> to overlap?

When nesting multiple spans within each other and giving them borders, their horizontal borders overlap by default while their vertical borders stack. Check out a live example on JsFiddle: https://jsfiddle.net/4un9tnxy/ .html: <span><span>a& ...

There appears to be a syntax error in the Values section of the .env file when using nodejs

I have been working on implementing nodemailer for a contact form. After researching several resources, I came across the following code snippet in server.js: // require('dotenv').config(); require('dotenv').config({ path: require(&apos ...

The background image fails to load in ReactJS application

Usually, I have no trouble finding solutions to my problems, but this time I'm really stuck - and I apologize in advance if my question seems silly or trivial. I am currently working on a simple React app where I need to set a background image for th ...

Method for displaying or concealing list items with an onClick event in React without relying on JQUERY

I'm working on a feature to show/hide a specific <li> element. While I know this can be achieved with JQuery, I prefer not to mix actual DOM manipulation with React's virtual DOM handling. With that in mind, I have assigned each <li> ...

Struggling to accurately convert the string into a date object

I have an array of objects structured like this: const days = [ { _id: 12312323, date : '30/12/2021', dateStatus : 'presence' }, ... ] I am looking to convert the date property from a string to a Date object using the follo ...

What is the best way to find an element using either 'className1' or 'className2'?

Within my project, all locators are defined as elements of an enum and follow this format: For example, if it is a CSS locator - DIV_LOCATION("css=div.location-text.text-overflow"). This method parses the string and identifies it as a CSS locator if it be ...

Weekly downloads for NPM show no activity

https://i.stack.imgur.com/4Uhk4.png https://i.stack.imgur.com/0vikS.png Why are all the weekly downloads showing zero for npm packages? I'm new here and confused about why this is happening, any insights? If you could please help me open this issue ...

Experiencing issues with references while trying to import tone.js

I am facing an issue with my express.js server setup on my Mac. I am trying to incorporate Tone.js, which can be found at , following the provided instructions. npm install tone To integrate Tone.js successfully: import * as Tone from 'tone' Ho ...

Click on the text within a paragraph element

Is there a way to retrieve the selected text or its position within a paragraph (<p>)? I'm displaying a text sentence by sentence using a Vue.js loop of paragraphs. <p class="mreadonly text-left mark-context" v-for="line in ...

Sharing data between ejs and javascript files

When using Express, I have encountered an issue with passing a variable to an EJS file called "index.ejs". res.render("index",{passedUser:req.user.alias}) Although I am able to successfully print it using <%=passedUser%> in the EJS file, I require ...

What methods can be utilized to create sound effects in presentations using CSS?

Let us begin by acknowledging that: HTML is primarily for structure CSS mainly deals with presentation JS focuses on behavior Note: The discussion of whether presentation that responds to user interaction is essentially another term for behavior is open ...

How can one set relative paths for links when including a file from a different directory that contains links?

My project directory is structured as follows: root css img src login login.php dashboard basic header.php footer.php profile.php manage.php department ...

Is it possible for a PHP form to generate new values based on user input after being submitted?

After a user fills out and submits a form, their inputs are sent over using POST to a specified .php page. The question arises: can buttons or radio checks on the same page perform different operations on those inputs depending on which one is clicked? It ...

What could be causing my default prop to not be transmitted to the child component in vuejs2?

Having trouble passing a default value to my Leaflet map child component before fetching the desired data from an API endpoint. I tried using country coordinates like latitude and longitude, but it's not working as expected. This is how I attempted t ...