needed help in freemarker language

i have a page where the news is displayed and i have below 2 buttons next and previous.
problem is: on click of next button news gets loaded as a continous list .

i am expected to have the old news getting reloaded with new news on click of next button. below is my code.

please do help me with the solution to this problem

<#assign qlimit = 15>
<#assign cqid = currentObject.foreignId>

<#if params.initialpass>
<section id="single-col-stories">
    <ul style="padding-left: 0px;" >
</#if>

<#list currentObject.children as childId>
        <#if childId?index == 0>
            <#assign currentSection = node(childId).pubInfo.sectionPath>
        </#if>
        <@include object=childId template="list-right-image" />
</#list>

<#if params.initialpass>
    </ul>
</section>

<#if currentObject.children?size gte qlimit>
<div class="load-more" id="load-more-button">
    <a class="btn-on-white white" id="lmb-${cqid}">Next</a>
</div>
<div class="previous" id="previous-button">
    <a class="btn-on-white-test whitetest" id="lmb-${cqid}test">Prev</a>
</div>
</#if>

    <script>

        $( document ).ready(function() {

                var pageNumber = 1;
                var limit = ${qlimit:8};
                var loadButtonClicked = false;
                var previousButtonClicked = false;

                function loadMoreFunc() {
                    if(loadButtonClicked==false){
                        loadButtonClicked=true;
                        var sectionQueryUrl = "/query/section?";
                        var urlPath = window.location.pathname;
                        if (urlPath.indexOf("/news/")==0){
                            var squery = {
                                "param.section": "/news/*",
                                "param.limit": limit,
                                "param.offset": pageNumber * limit,
                                "param.tagName": $('.section-sub-nav a.ebrow-link.selected').text().trim() || "*",
                                "option.outputMode": "FRAGMENT",
                                "option.template": "section"
                            }
                        } else if (urlPath.indexOf("/slide-shows/")==0){
                            var squery = {
                                "param.section": "/slide-shows/*",
                                "param.limit": limit,
                                "param.offset": pageNumber * limit,
                                "param.tagName": $('.section-sub-nav a.ebrow-link.selected').text().trim() || "*",
                                "option.outputMode": "FRAGMENT",
                                "option.template": "section"
                            }
                        } else {
                            var squery = {
                                "param.section": "${currentSection}",
                                "param.limit": limit,
                                "param.offset": pageNumber * limit,
                                "param.tagName": $('.section-sub-nav a.ebrow-link.selected').text().trim() || "*",
                                "option.outputMode": "FRAGMENT",
                                "option.template": "section"
                            }
                        }

                        sectionQueryUrl += $.param(squery, true);

                        $.get( sectionQueryUrl, function( response ) {
                                var parseResponse = $.parseHTML('<ul>'+response+'</ul>');
                                var foundStories = $(parseResponse).find('li');
                                if(foundStories.length > 6){
                                    $('#single-col-stories ul').append($(foundStories));
                                    $("#load-more-button").show();
                                    
                                }else{
                                    $("#load-more-button").hide();

                                }
                                pageNumber++;
                                loadButtonClicked=false;
                            });
                        }
                };

                $('#lmb-${cqid}').click(loadMoreFunc);

                $('.section-sub-nav a.ebrow-link').on('click',function(e){
                    e.preventDefault();
                    e.stopPropagation();
                    $this = $(this);
                    if(!$this.hasClass('selected') && loadButtonClicked==false){
                        $('.section-sub-nav a.ebrow-link').removeClass('selected');
                        $this.addClass('selected');
                        $('#single-col-stories ul').empty();
                        pageNumber = 0;
                        loadMoreFunc();
                    }
                });

        });

    </script>

</#if>

Show one specific result in a list in React

import {useState, useEffect } from 'react'
import axios from 'axios'

const Singlecountry = ({searchedCountries, setWeather, weather}) => {
  const weatherName = searchedCountries[0].capital
console.log(weather)
  
  useEffect(() => {
 

    axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${weatherName}&appid=${process.env.REACT_APP_API_KEY}`)
      .then(response => {
        const apiResponse = response.data;
        console.log(apiResponse)
        console.log(`Current temperature in ${apiResponse.name} is ${apiResponse.main.temp - 273.15}℃`);
    setWeather([apiResponse])
      }).catch(error => {
        console.log(error);
    })
  }, [])
  
  return(
  <div>
  capital: {searchedCountries.map(c => <p>{c.capital}</p>)}
  area: {searchedCountries.map(c => <p>{c.area}</p>)}
  <h2>Languages</h2>
  <ul>
  {
    searchedCountries.map(c =>
      
        <ul>
          {Object.values(c.languages).map(l => <li>{l}</li>)}
        </ul>
     
    )
  }
</ul>
  {searchedCountries.map(c => <img src={Object.values(c.flags)[0]} alt="" /> )}
  <h3>Weather</h3>


        </div>
  )
}

const Countries = ({ searchedCountries, handleClick, show, setWeather, setCountries, weather}) => {
  if (searchedCountries.length >= 10) {
    return (
      <div>
        <p>too many countries to list, please narrow your search</p>
      </div>
    )
  } 
  if (searchedCountries.length === 1) {
    return (
 <Singlecountry searchedCountries={searchedCountries} setWeather={setWeather} weather={weather}/>
    )
  }
  if (show === true) {
    return (
      <Singlecountry searchedCountries={searchedCountries} setWeather={setWeather} />
    )
  }
  return (
    <ul>
    {searchedCountries.map(c => <li>{c.name.common}<button onClick={handleClick} >show</button></li>)}
  </ul>
  )
}


const App = () => {
const [countries, setCountries] = useState([])
const [newSearch, setNewSearch] = useState('')
const [show, setShow] = useState(false)
const [weather, setWeather] = useState('')


const handleSearchChange = (event) => {
  setNewSearch(event.target.value)
}

const handleClick = () => {
 setShow(!show)
}

const searchedCountries = 
countries.filter(c => c.name.common.includes(newSearch))

useEffect(() => {
  axios
  .get('https://restcountries.com/v3.1/all')
  .then(response => {
    setCountries(response.data)
  })
}, [])


  return (
    <div>
<div><p>find countries</p><input value={newSearch} onChange={handleSearchChange} /></div>
<div>
  <h2>countries</h2>
  <Countries searchedCountries={searchedCountries} handleClick={handleClick} show={show} setCountries={setCountries} setWeather={setWeather} weather={weather}/>
</div>
    </div>
  )
}


export default App

In this React App, the user searches for information on countries which the app gets from a fetch request to an API.

If there are between 1 and 10 matches – it displays just the name of the country along with a button saying “show”, like this: List of results

On clicking the show button, I would like to display more in depth information specific to that country, like so: Single Result.

However, when I click “show” – it displays all the information for all the countries beginning with “D”, rather than the single country, like so: Too many countries.

Does anyone know of a way to just display the information for one country when clicking the “show” button?

Thanks.

Reading multiple objects, in a single object, with in an array, with unique keys. into FlatList

I am trying to display this data in a FlatList.

Array [
  Object {
    "-N1gqvHXUi2LLGdtIumv": Object {
      "Message": "Aeaaeaea",
      "Message_CreatedAt": 1652167522975,
      "Message_by_Email": "[email protected]",
      "Message_by_ID": "DgGfooQIMQQ1rs5xlmmSKCSTrKA2",
    },
    "-N1hB3A_Q7-K75UbvPSM": Object {
      "Message": "Yyoo",
      "Message_CreatedAt": 1652173063182,
      "Message_by_Email": "[email protected]",
      "Message_by_ID": "DgGfooQIMQQ1rs5xlmmSKCSTrKA2",
    },
  },
]

My data looks like this, its multiple objects in a single object within an array, and each object has multiple unique Ids how can I read the data.

My FlatList code

 <FlatList data={data} renderItem={(Item) => <Text>{Item.item. Message}</Text>}

Here the problem is, FlatList is considering the main object and not the children, how can I access and render the children in a Flatlist and how can I access the unique Id.

How to use viewerJS in Angular?

I want to show my images using viewrJS so I have test that with JSfiddle. But that way i couldnt use in angular

here is the JSfiddle

in JSfiddle I have set the element accessing part like this

const viewer = new Viewer(document.getElementById('grid'),{});

it is not inside the function too. why that like this was when I put inside the function image is viewing not first time it is coming second time.

I wanted to use this solution in angular. have any way to do that?

Angular Material Cards in a Grid via NgFor, if one card changes height, then all cards in the same row do as well. How to disable this behavior?

I have a grid in which I create multiple mat-cards via ngFor. These mat cards contain a button each which expands the card itself.

.outerDiv{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(370px, 5fr));
    grid-column-gap: 20px;
    align-items: stretch;
  }

.innerMatCardContainer {
    box-shadow: 5px 5px 3px -3px var(--hailoDarkGray);
    border-radius: 2px;
    margin-bottom: 20px;
    justify-content: center;
    align-items: center;
  }

The problem is, that if one card is expanded, then all cards in that row also expand.

Is there a way to disable this behavior, so as to achieve a row of mat cards, each being able to be differently sized?

Here is a demonstrative graphic of the issue:

JavaScript to change CSS dynamically when scrolling

I want to change some css properties when scrolling.
This worked with jQuery and I can’t make it work using JavaScript.

This is the function that reads and set CSS properties:

function parallel_height_js(){
  let scroll_top = window.scrollY;
  console.log('scroll top = ',scroll_top)
  let header_height = document.getElementsByClassName("sample-header-section")[0].clientHeight;
  console.log('Header height = ',header_height)
  document.getElementsByClassName("text-section")[0].style.marginTop = header_height;
  console.log('text margin top = ',document.getElementsByClassName("text-section")[0].style.marginTop)
  document.getElementsByClassName("sample-header")[0].style.height = header_height - scroll_top;
  console.log('header height = ',document.getElementsByClassName("sample-header")[0].style.height)
}

Afterwards, I execute the following to execute the function at scrolling or resizing:

parallel_height_js();

window.onscroll = parallel_height_js;
window.onresize = parallel_height_js;

In the browser console I get this from console.log:

scroll top =  8
Header height =  517
text margin top =  
header height =  

I checked that I am accessing the right elements when trying to set the CSS value, but this CSS value is not changing.

I’m trying to understand how to make 2 classes hover at same time

.ellenon {
  box-sizing: border-box;
  width: 350px;
  height:350px;
  background-image: url("https://wallpapercave.com/wp/wp5609581.jpg");
  filter: grayscale(100%);
  color:white;
  transition: 0.5s;
}

.ellenon :where(h1, p) {
  line-height:1.5em;
  letter-spacing: 1.1px;
  padding-right: 10px;
  padding-left: 10px;
  transition: 0.5s;
}

.ellenon:hover {
  filter: grayscale(0%);
}

.ellenon h1:hover {
  transform: translate(0px, -20px);
  color:transparent;
  transition: 0.5s;
}

.ellenon p:hover {
   transform: translate(0px, 20px);
  color:transparent;
  transition: 0.5s;
}

.ellenon2:hover {
  transform: translate(0px, -20px);
  color:transparent;
}
<div class="ellenon"><a href="https://codepen.io/" class="ellenon2"><h1>What is Lorem Ipsum?</h1> <p>
Lorem Ipsum is simply dummy text</p></a></div>

Hello there, im trying to create a simple css animation as you can see in my code. Hoever i can’t understand how to execute both hovers once the user hover the external div. Is this possible with raw CSS or JS is needed?

Thanks

Jest test is throwing TypeError: is not a function when calling function with Require

I am using Jest to test and cover my express js code. I have a file default.js which is exporting a simple function:

async function foo(req, res) {
  let out = {}
  // performs some computations

  res.send({
    file: 'Default',
    data:  out.data
  })
}

module.export = {foo}

This is then being called in app.js:

const def = require('./default')

app.get('/default/:a/:b' async (req, res) => {
  def.foo(req, res)
})

This works fine. However, when I try to create a test on the Handler function in default.js Jest throws this error:

TypeError: def.foo is not a function

This is my test file:

const def = require('./default')

describe('Default Test', function() {

  test('responds to /default/:a/:b', () => {
    const req = {
      params: {
        a: 'country',
        b: 'city'
      }
    }

    const res = {
      text: '',
      send: function(input) {
        this.text = input
      }
    }

    def.foo(req, res)

    expect(res.json).toEqual({
        file: 'Default',
      })
  })
})

Never mind that the test should fail with the expect function. But the test is failing at default.foo it is not finding this function. Why is this?

Website is not secure after the login page? [closed]

We are developing a website and we are using AWS as a cloud service provider. We are facing a issue like
SCENERIO

  1. While we go with login page URL , the website is secured.
  2. after login, the main page of the website is secure only.
  3. If I click something in the website, it changed into not secure.
    I don’t no why its happening. Before API integration , its working fine. I checked with AWS, everything is fine. If it is wrong configuration in AWS ,the starting login page itself , it will show “not secure”. But currently , its showing secure.
    Developers using react JS . Please help me to sort it out. Whether the issue was in AWS or code.

how to set object keys to common denominators?

I have an array of objects and want every object in the array to have the same keys.

var obj1 = {"type": "test", "info": "a lot", "value": 7};
var obj2 = {"value": 5};
var obj3 = {"context": "demo", "info": "very long", "value": 3};
var obj4 = {"info": "no way"};

var dataSet = [obj1,obj2,obj3,obj4];

My attempt is to create an array with all possible keys in the first step.
Then loop through that keys array and update the objects if the key was not found.

keys.forEach(function(a,b){
  dataSet.forEach(function(c,d){    
    //key not found
    if(a in c === false)
    {
      //add key to object 
      dataSet[b][a] = false;
    }
  });
});

Howewer, it does not seem to work correctly.
This is my output:

after logic:  [
  {
    "type": false,
    "info": "a lot",
    "value": 7
  },
  {
    "value": 5,
    "info": false
  },
  {
    "context": "demo",
    "info": "very long",
    "value": false
  },
  {
    "info": "no way",
    "context": false
  }
]

What am I missing there?

var obj1 = {"type": "test", "info": "a lot", "value": 7};
var obj2 = {"value": 5};
var obj3 = {"context": "demo", "info": "very long", "value": 3};
var obj4 = {"info": "no way"};

var dataSet = [obj1,obj2,obj3,obj4];
var keys    = [];

console.log("before logic: ", dataSet);

//Step 1: Fill keys array
dataSet.forEach(function(a,b){  
  Object.keys(a).forEach(function(c,d)
  {
    //add keys to array if not already exists
    if(!keys.includes(c))
    {
      keys.push(c);
    }
  });
});

//Step2: loop through keys array and add key to object if not existing
keys.forEach(function(a,b){
  dataSet.forEach(function(c,d){    
    //key not found
    if(a in c === false)
    {
      //add key to object 
      dataSet[b][a] = false;
    }
  });
});

console.log("after logic: ", dataSet);

Modal pop up not being opened in mobile in reactjs

I created a search modal pop up in my website using reactjs. it is working perfect in the desktop version. But when I switch to the mobile version it does not work and doesn’t open the modal, in other sense it doesn’t add the class open to the div.

I am adding and removing the class on the click of the icon of the search. but on mobile it doesn’t seem to work.

Why is that?

Here is my code:

'use strict';

class Search extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            results: [],
            search: false,
        };

        this.search = this.search.bind(this);
    }

    componentDidMount() {
        let opener = document.querySelector('.search-opener');

        if (! opener){
            console.log("Cant Work")
            return;
        }

        opener.addEventListener('click', () => {
            document.querySelector('#searchPopup').classList.add('open');
        });

        document.querySelector('.search-box .close').addEventListener('click', () => {
            document.querySelector('#searchPopup').classList.remove('open');
        });
    }

    componentDidUpdate() {
        if (AOS) {
            AOS.refreshHard();
        }
    }

    search(e) {
        if (! e.target.value) {
            this.setState({
                results: [],
            });

            return;
        }

        this.setState({
            searching: true
        });

        fetch(`${mywebsitename.homeUrl}/wp-json/mywebsitename/v1/search/?term=${e.target.value}`)
            .then(response => response.json())
            .then(results => {
                this.setState({
                    results,
                    searching: false,
                });
            });
    }

    getBadgeColor(postType) {
        if (postType === 'page') return 3;
        if (postType === 'shop') return 2;
        if (postType === 'event') return 1;
        if (postType === 'post') return 5;
    }

    render() {
        let aosDuration = 0;
        let fakeEl = jQuery('<x>');

        return (
            <div className="search-box">
                <div className="close mb-1">
                    <i className="mdi mdi-close mdi-24px"></i>
                </div>
                <div className="form-group">
                    <input type="search" className="form-control search-input" id="searchInput" aria-describedby="searchHelp" placeholder="Type something.." onInput={this.search} />
                    <small id="searchHelp" className="form-text text-muted">Search...</small>
                </div>
                {
                    this.state.searching ? 
                    <div className="text-center text-color-7 mb-5">
                        <i className="mdi mdi-loading mdi-spin mr-2"></i> Searching..
                    </div> :
                    <ul className="results list-reset">
                        {this.state.results.map(result =>
                            <li key={result.ID} className="d-flex align-items-start" data-aos="fade-up" data-aos-duration={aosDuration+=150}>
                                <span className={`badge border border-color-${this.getBadgeColor(result.post_type)}-dark text-color-${this.getBadgeColor(result.post_type)}-dark mr-3`}>{result.post_type}</span>
                                <h6><a href={fakeEl.html(result.guid).text()}>{result.post_title}</a></h6>
                            </li>
                        )}
                    </ul> 
                }
            </div>
        );
    }
}

let el = document.createElement('div');
el.id = 'searchPopup';
el.classList.add('search-popup');
document.querySelector('#page').prepend(el);

ReactDOM.render(React.createElement(Search), el);

clearTimeout does not work DESPITE proven consistency of context? [closed]

I know this issue should be supposedly beaten to death, but there is a case of clearTimeout not working despite proven consistency of context. The following code runs within an object where is this.timeoutId is defined:

... // the object's definition
popupDelayInMs: 1000,
timeoutId: false,
...

      if (this.timeoutId);
      {
        console.log('TEST: CLEARED timeoutId:', this.timeoutId);
        clearTimeout(this.timeoutID);
        this.timeoutId = false;
      };
      console.log('TEST: going to set timeoutId to get images for:', tEText, title);
      this.timeoutId = setTimeout(function()
      {
        console.log('TEST: WITHIN timeoutId, getting image for:', tEText, title);
        GM_xmlhttpRequest(
        {
          ...
        }); // end of GM_xmlhttpRequest(
      }.bind(this), this.popupDelayInMs); // end of this.timeoutId = setTimeout(function()
      console.log('TEST: timeoutId WAS SET to, images for:',  this.timeoutId, tEText, title);      

And the log for this code is below.
Notice the lines that say “WITHIN”. The only ones that should have appeared are “Nunnally Vi Britannia”, “Cecile Croomey” as there is no “CLEARED” before them, and the other three are still executed while their timeoutId — that are proven to exist and match the numbers assigned at the time of setTimeout creation — were cleared:

10:22:45.792 TEST: CLEARED timeoutId: false ANN Character Image Preview Popup.user.js:189:17
10:22:45.793 TEST: going to set timeoutId to get images for: Nunnally Vi Britannia Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:193:15
10:22:45.793 TEST: timeoutId WAS SET to, images for: 25 Nunnally Vi Britannia Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:229:15
10:22:46.794 TEST: WITHIN timeoutId, getting image for: Nunnally Vi Britannia Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:196:17
10:22:48.728 TEST: CLEARED timeoutId: 25 ANN Character Image Preview Popup.user.js:189:17
10:22:48.728 TEST: going to set timeoutId to get images for: V.V. Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:193:15
10:22:48.729 TEST: timeoutId WAS SET to, images for: 28 V.V. Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:229:15
10:22:49.212 TEST: CLEARED timeoutId: 28 ANN Character Image Preview Popup.user.js:189:17
10:22:49.214 TEST: going to set timeoutId to get images for: Shinichirou Tamaki Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:193:15
10:22:49.215 TEST: timeoutId WAS SET to, images for: 29 Shinichirou Tamaki Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:229:15
10:22:49.562 TEST: CLEARED timeoutId: 29 ANN Character Image Preview Popup.user.js:189:17
10:22:49.563 TEST: going to set timeoutId to get images for: Jeremiah Gottwald Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:193:15
10:22:49.563 TEST: timeoutId WAS SET to, images for: 30 Jeremiah Gottwald Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:229:15
10:22:49.737 TEST: WITHIN timeoutId, getting image for: V.V. Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:196:17
10:22:50.171 TEST: CLEARED timeoutId: 30 ANN Character Image Preview Popup.user.js:189:17
10:22:50.172 TEST: going to set timeoutId to get images for: Cecile Croomey Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:193:15
10:22:50.173 TEST: timeoutId WAS SET to, images for: 31 Cecile Croomey Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:229:15
10:22:50.224 TEST: WITHIN timeoutId, getting image for: Shinichirou Tamaki Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:196:17
10:22:50.574 TEST: WITHIN timeoutId, getting image for: Jeremiah Gottwald Code Geass: Lelouch of the Rebellion R2 ANN Character Image Preview Popup.user.js:196:17
10:22:51.179 TEST: WITHIN timeoutId, getting image for: Cecile Croomey Code Geass: Lelouch of the Rebellion R2

I have read lots of questions on the issue, but it did not help so far.

Thanks in advance.

Woocommerce, force color selection on variations

Would anybody know the code for functions.php for this?

I have a product. It has three colors and comes with three sizes. I’ve already added code to allow color to be selected and change the corresponding variation image without having to select size. Step 1. Done.

Next I want to FORCE variations to always be selected. In the product tab, I can set the ‘default color and default size’ to a specific variation. This is ok, but i can still DESELECT the current selected color (meaning, all off the image gallery gets shown). What I need is to make sure that the customer cannot deselect any swatch/variation on the color selection, and instead, can only choose another color.

To clarify, it would behave like Zara’s website. You can see, when selecting color, you cannot deselect a color and instead simply changes the variation images according to which one is selected. Note that a size doesn’t have be selected for this either atmo.

https://www.zara.com/us/en/premium-cotton-shirt-p04174015.html?v1=172577525&v2=2025627

I also want to remove ‘choose an option’ completely ideally. Any solutions?