mardi 27 octobre 2020

Less/More option disappears on closing one notification (Ruby on Rails)

I'm writing a ROR code in which a notification at top will appear if transaction fails with Less/More option. But problem occurs when user closes one notification then Less/More option disappears for the other.

This is the code that I'm using

$(document).ready(function() {
    if ( $(window).width() < 1025 ) {
    var showChar = 20;
    var ellipsestext = "...";
    var moretext = "More";
    var lesstext = "Less";
    
    $('.confirm-account').each(function() {
        var content = $(this).html();
 
        if(content.length > showChar) {
 
            var c = content.substr(0, showChar);
            var h = content.substr(showChar, content.length - showChar);
 
            var html = c + '<span class="moreellipses">' + ellipsestext+ '&nbsp;</span><span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';
 
            $(this).html(html);
        }
    });
 
    $(".morelink").click(function(){
      $('.system-message').empty();
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().toggle();
        $(this).prev().toggle();
        return false;
    });
  }

Is there any way possible in which the Less/More option remains there even after closing one notification?

Aucun commentaire:

Enregistrer un commentaire