An import map is added after module script load was triggered

I have a Rails app, and my custom javascript doesn’t work.
In Chrome console I can see the following errors:

An import map is added after module script load was triggered.

Uncaught TypeError: Failed to resolve module specifier “application”. Relative references must start with either “/”, “./”, or “../”.

Uncaught TypeError: Failed to resolve module specifier “@hotwired/turbo-rails”. Relative references must start with either “/”, “./”, or “../”.

I cannot uderstand why there are these errors, I moved the importmap before the script with type module, but I’m still getting this error.
In my application.html.erb I have

<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_importmap_tags %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true, type: "module" %>

This is my importmap.rb file:

# Pin npm packages by running ./bin/importmap

pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"

This is my app/javascript/application.js file:

// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"

This is the app/javascript/cotrollers/application.js

import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus   = application

export { application }

This is the content of the app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

And I cannot see the custom javascript in the app/assets/javascripts/ folder.
What am I missing? thanks

Video don’t load in Firefox unless the page is refreshed

I am trying to build my very first website. Everything work fine but I notice that my video won’t load in Firefox unless I refresh the page containing that video. These videos are in webm format that Firefox supports, and they work fine in both Chrome and Safari (albeit in Safari the autoplay does’t work. Not ideal, but can live with it for now). The following are my html tag for the video

{entry.data.vid ? (     
   <video poster="/assets/video/Loading.gif" preload="auto" controls loop muted autoplay>
      <source src={entry.data.vid + ".webm"} type="video/webm">
      Opps. Something went wrong with my video.
   </video>
) : (entry.data.img && (
   <img src={entry.data.img} alt={entry.data.img_alt || ''} />)
)}

As you can see, some pages have videos, the rest only have images (This website is build using Astro framework with animations between pages btw). This same problem persist both on my local machine or hosted on the server. This is a newly installed Firefox with no add-ons.

I tried with other video format (mp4), that doesn’t work either. I tried removing preload=”auto” and autoplay attribute, that doesn’t work as well.
I check the console in Firefox (with control-shift-j) and see the following errors in Parent process whenever I refresh a page (regardless of it containing a video or just an image). Not sure if it is relevant or not.

NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIFaviconService.replaceFaviconDataFromDataURL] loadFavicon resource:///modules/PlacesUIUtils.sys.mjs:213 loadFavicon resource:///modules/PlacesUIUtils.sys.mjs:644 setIconFromLink resource:///actors/LinkHandlerParent.sys.mjs:139 receiveMessage resource:///actors/LinkHandlerParent.sys.mjs:60 LinkHandlerParent.sys.mjs:148:17 setIconFromLink resource:///actors/LinkHandlerParent.sys.mjs:148 receiveMessage resource:///actors/LinkHandlerParent.sys.mjs:60 

When I look at Multiprocess section of the console though, I see the “All candidate resources failed to load. Media load paused.” warning only on page that contains video and only before page refresh Image showing the warning.

Sorry for such a simple question, I am sure this is some very basic problem that only a novice would ask, but I would really appreciate any suggestions that you guys can give.

uneven number of data points on each trial_data collection

I have a task where peole see a dot moving and then disappearing. When that happens they need to indicate with the mouse where it started and where it vanished. The motion trajectory can be 1 line, 2 lines, or 3 lines.
The data I collect is the actual initial position of the dot (in both axes), the actual vanishing position (both axes), the trial number, the condition, the perceived position of the dot (start, vanish both axes), the direction of the first line, and if there is a 2nd line the direction of it.
Because there are uneven data points, my values are not correctly placed under the right header at the csv file that I “send” the data to.
I would appriciate it if anyone could help with making the headers align with the data.

I tried to create a loop when I push the headers. It works for the 3 lines trajectory but not with the others.

Fullcalendar non-gregorian months

I am looking for a way to display a fullcalenar month grid divided by Hebrew calendar months.

I managed to display the hebrew date within the cells of the month grid view usign dayCellContent (including bootstrap classes):

//Array of letters representing the day of the month
const hebDateLetters = ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י', 'יא', 'יב', 'יג', 'יד', 'טו', 'טז', 'יז', 'יח', 'יט', 'כ', 'כא', 'כב', 'כג', 'כד', 'כה', 'כו', 'כז', 'כח', 'כט', 'ל',]; 

...

dayCellContent: (info)=>{
        var hebDate = new Intl.DateTimeFormat('he-IL-u-ca-hebrew', {day: 'numeric'}).format(info.date);
        var hebMonth = new Intl.DateTimeFormat('he-IL-u-ca-hebrew', {month: 'long'}).format(info.date);

        //Container element
        const container = document.createElement("div");
        container.setAttribute("class", "container p-1"); 

        //First row element
        const elRow1 = document.createElement("div");
        elRow1.setAttribute("class", 'row m-0 w-100');
        const elCol1 = document.createElement("div");
        elCol1.setAttribute("class", 'col p-0');
        elCol1.innerText = hebDate !=1 ? hebDateLetters[hebDate-1] : hebDateLetters[hebDate-1] + " " + hebMonth; // Condition to display Hebrew month name on first day of the month
        elRow1.appendChild(elCol1);

        //Second row element
        const elRow2 = document.createElement("div");
        elRow2.setAttribute("class", 'row m-0 w-100');
        const elCol2 = document.createElement("div");
        elCol2.setAttribute("class", 'col p-0 c-date');
        elCol2.innerText = info.date.getDate();
        elRow2.appendChild(elCol2);

        container.appendChild(elRow1);
        container.appendChild(elRow2);
        return {html: container.outerHTML};
      }

This is what I achived

Calendar Image

My next step would be to display the months according to the Hebrew calendar. I’ve been trying to build a custom view as discribed here: Custom view with JS, but I’m not fully sure how to use this to achive what I’m looking for.

How to make this code synchronous by blocking the execution thread?

I have a piece of code with an API call in the topmost JS import which I need to use everywhere else in the project.
How to make this asynchronous?

My HTML file looks like:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="src/style.css">
  </head>
  <body>
    <h1 id="header"></h1>

    <script src="src/script1.js"></script>
    <script src="src/script2.js"></script>
  </body>
</html>

First JS file:

const fetchData= async () => {
    const configUrl = 'https://jsonplaceholder.typicode.com/todos/1';

    try {
        const response = await fetch(configUrl);

        if (!response.ok) {
            throw new Error(`Network response was not ok: ${response.status} - ${response.statusText}`);
        }

        const res = await response.json();
        console.log('data 0:',res)
        return data;
    } catch (error) {
        console.error('Error fetching data:', error);
    }
};

window.data = fetchData();

console.log("data 1:",data);

Second JS file:

console.log("data 2:",window.data)

Basically I want window.data with the data from the endpoint to be accessible everywhere. I want to continue the program execution only after the api call is done. That is, the thread should be blocked for the API call and rest of the program (js files) should execute only after the api call.
Im not ready to move other JS file code to first 1 nor import it inside first using @import in .then block of first.

Is there any clean approach for this?

Live example: https://playcode.io/1696111

In the example I want console.log inside script2.js to print the API data.

`RecipientsDisplay` component using react/ vue

  • This functionality should work on any screen size and when the screen is resized. For simplicity, this will only be tested in a recent version of a Chromium browser.

  • If all the recipient email addresses fit in the available space, we can simply display them delimited by a comma and space (e.g. a, b).

  • When there is not enough space to display all recipients, we trim the text. However, to prevent showing clipped email addresses that are hard to read, we trim entire email addresses. If we cannot fit the entirety of a recipient email address, it shouldn’t be shown at all.

  • When at least one recipient is trimmed, we put a comma, space, and ellipsis after the last fitting recipient (e.g. a, b, ...). Furthermore, the rightmost end of the column should show a “badge” with the number of trimmed recipients (+N).

  • If there is not enough space to show even the first recipient, the badge should show the number of trimmed recipients excluding the first recipient, and the recipient should be truncated with an ellipsis only. If there is only one recipient, there will be no badge, and the recipient should still be truncated by an ellipsis.

Trim recipients that do not fit in the column. Show , ... after the last fitting recipient and a badge with +N at the end of the column.

If there is not enough space to show the ellipsis and the extra space, trim that recipient as well.

If there is not enough space to show the first recipient, the badge should show the number of trimmed recipients excluding the first recipient, and the recipient should be truncated with an ellipsis only. If there is only one recipient, there should be no badge.

Measurements

  • Font size: 16px
  • Foreground color: #f0f0f0
  • Background color: #666666
  • Border radius: 3px
  • Top padding: 2px
  • Bottom padding: 2px
  • Left padding: 5px
  • Right padding: 5px
  • Font size: 16px
  • Foreground color: #333333
  • Top padding: 5px
  • Bottom padding: 5px
  • Left padding: 10px
  • Right padding: 10px

onmouseover event suddenly not working in Edge browser

I have the following code throughout my site to swap images on hover:

<img class="rounded-lg object-cover shadow-lg transition hover:scale-[1.05]"
src="/assets/profiles/leadership/volker-photo-detail-hover.png"
onmouseover="this.src='/assets/profiles/leadership/volker-photo-detail-hover.png';"
onmouseout="this.src='/assets/profiles/leadership/volker-photo-detail.png';">

which has been working fine for the last year, but suddenly it won’t work correctly in Microsoft Edge browser. It works fine in Chrome and Firefox. You can test here: https://jwmdrc.org/ (work in progress so not really accessible on smaller screens/mobiles yet) in different browsers and see that it’s only Edge that is affected.

Maybe this is due to a recent update? Has anyone else encountered this and/or know of a solution?

Thanks

Edit: built with Statamic and Tailwind

Loading of script tag is slower in Chrome than Firefox

I want to load large amounts of data from a local file in an html application.

At the moment my strategy is to keep the data as javascript arrays in separate .js files and load them by dynamically adding elements to the header of the page, like so:

const head = document.getElementsByTagName['head'][0]
const js = document.createElement('script')
js.async = true
js.src = "localDataFile.js"
head.appendChild(js)

The contents of localDataFile.js look like the following, where dataString contains the data encoded as a base64 string.

const base64DataString = "..."
globalFunction(base64DataString)

An example .js file I am using has a size of 300 MiB.
This file takes ~40 seconds to load in Chrome v112, and ~17 seconds in Firefox v102.

My question:
Is there any way to speed up parsing of this javascript file for Chrome, or both?
More generally, are there any better strategies in getting the data to the html application without using a web server?

Issue with Tailwind CSS and shadcn/ui in applying background opacity to custom colors

I’m encountering an unexpected behavior when using Tailwind CSS in conjunction with shadcn/ui library for styling buttons. The problem arises when attempting to apply background opacity to a custom color defined in globals.css using HSL values as follows:

--primary: 348, 76%, 64%;

The issue occurs when trying to set the background opacity of a button using this custom color in shadcn/ui. For instance:

<button class="hover:bg-primary/90">Button</button>

The intention here is to have a button with a hover effect that applies 90% opacity to the background color defined as –primary. However, this opacity setting seems to have no effect, and the button retains its original opacity.

I have ensured that the custom color is properly defined and available in the project’s global styles. Yet, applying opacity to it using the Tailwind utility classes does not yield the expected result.

Blocked a frame with origin “http://localhost:5173

My Frontend is running on http://localhost:5173 (vue)
My backend is running on http://localhost:8000 (laravel rest api)

Problem :-
When i add http://localhost:8000 in a iframe in my vue frontend
(basically i wanna show laravel home screen in my frontend using iframe )
But the problem is when i try to access the dom of iframe content it gives me error that Blocked a frame with origin “http://localhost:5173”
But if i add http://localhost:5173 ( frontend home screen ) it works perfectly fine
My question is how can i give access my frontend from laravel backend so i can access document in my frontend

 <iframe
                    v-if="size === 'L' && !isLoading && !error"
                    @click="handlePopup"
                    src="http://localhost:8000"
                    class="!cursor-text scroll-smooth"
                    sandbox="allow-scripts allow-forms allow-same-origin allow-pointer-lock allow-                           presentation allow-popups allow-popups-to-escape-sandbox"
                    style="border: 0; width: 100%; height: 100%"
                    :onLoad="
                        () => {
                            initializeIframe();
                        }
                    "
                    ref="iframeRef"
                    allow-same-origin
                ></iframe>

How can I change material of specific element if it shares mesh with others?

I’m working on simulation of building IFC model in time. I want elements to change its material when they reach their timeEnd. It works, but the problem is that elements share same mesh, so when 1 element of mesh reaches timeEnd, it changes material of whole mesh. Should I clone mesh for every element, then change its material?

function processTimeStep(entry, time) {
const expressID = entry.expressID;
const isStartTime = entry.timeStart === time 
const isEndTime = entry.timeEnd === time
const fragmentId = findFragmentIdByExpressId(expressID, model.getFragmentMap([expressID]));
const fragmentMap = model.getFragmentMap([expressID]);
if (fragmentId) {
    const fragment = fragments.list[fragmentId];
        const itemMesh = fragment.mesh; 
        if (isStartTime) {
             hider.set(true, fragmentMap)
        } else if (isEndTime) {
            itemMesh.material = fragment.originalMaterial;

        }
    }
}

Script Engine in Service

I want to run JavaScript code using Script Engine. I found a project called Rhino-android, and I got the desired result when I clicked the button in Activity. However, when I implemented it to work in Service, it came out that there is no Script Engine Factory. Can you help me with this?

implement Project.

    implementation 'com.sun.phobos:jsr223-api:1.0'
    implementation 'io.apisense:rhino-android:1.0'
    implementation group: 'org.mozilla', name: 'rhino', version: '1.7.13'
   ScriptEngineManager manager = new ScriptEngineManager();
   Log.d(TAG, "manager = " + manager);
   List<ScriptEngineFactory> list = manager.getEngineFactories();
   Log.d(TAG, "list = " + list);
   for (ScriptEngineFactory factory: list){
      Log.i(TAG, "factory = " + factory.getEngineName() + ", engines = " + factory.getNames());
   }

system pointing with update sql

`Hello everyone,
I am a beginner in php development. I am looking for a solution to clock the presence of my members in javascript, and at the same time update my table based on the id.

Here’s what I started doing:

_ 2 requests:

$present=update_examination_present($EXAM_id);

$absent=update_examination_absent($EXAM_id;

_ Button of my table:

`<td><INPUT type=”button” class=”btn btn-warning” title=”Pointing of <?php echo $list_pgChildren[$a][‘ADHE_nom’].” “.$list_pgChildren[$a][‘ADHE_prenom’]; ?>” value=”POINTAGE” onclick=”myFunction(this);pointage(a)”></INPUT> <?php`your text` } elseif($list_pgChildren[$a][‘EXAM_present’]==1) { ?> <INPUT type=”button” class=”btn btn-success” title=”Modifying <?php echo $list_pgChildren[$a][‘ADHE_nom’].” “.$list_pgChildren[$a][‘ADHE_prenom’]; ?>” value=”PRESENT” onclick=”myFunction(this)”></INPUT> <?php } ?>`

_ my script which works with my “INPUT type=button”:

<script language="JavaScript" type="text/javascript">function myFunction(anObject){ if (anObject.value == "POINTING"){ //alert('I'm doing this'); anObject.value = "PRESENT"; }else { //alert('I do this'); anObject.value = "POINTAGE";}}</script>

I would like to integrate my 2 requests into the script:

_ if I click the first time on my “POINTAGE” button, it executes my “$present” query and displays “PRESENT” on my button.

_ if I click again on this same “PRESENT” button, it executes my “$absent” query and displays “POINTAGE” on my button.
Can you help me please?

Alternative to Fuse JS (FuzzySearch Javascript)

i have 33k+ Records of Product in Indexed DB. i have implemented search for that using Fuse js. But For my some cases it wouldn’t give proper results. i played with its options but not got satisfied results. So looking for alternative minimal size & wide in functionality of fuzzy search.

Please let me know if you have used or know any js that can give results in most of complex searchs. i am trying to make similar version of DoFinder