Hey,
I have this code for toggling "read more" and "read less" on elements which contain more than a certain number of characters:
var showChar = 250; // How many characters are shown by default
var ellipsestext = "...";
var moretext = "+ קראו עוד";
var lesstext = "- סגירה";
jQuery('.offer-bottom').each(function() {
var content = jQuery(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 + "</span><span class='morecontent'><span>" + h + "</span><a class='morelink'>" + moretext + "</a></span>";
jQuery(this).html(html);
}
});
jQuery(".morelink").click(function(){
if(jQuery(this).hasClass("less")) {
jQuery(this).removeClass("less");
jQuery(this).html(moretext);
} else {
jQuery(this).addClass("less");
jQuery(this).html(lesstext);
}
jQuery(this).closest(".offer-bottom").toggleClass("show-more-text");
return false;
});
It works well if I use it on document.ready - but I need it to work also after the results are updated (as I have an ajax search there), but when I try to save the code inside the
jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
});
function, the view just won't save and give an error - UNLESS I remove these 2 lines:
var c = content.substr(0, showChar);
var h = content.substr(showChar, content.length - showChar);
hidden link (print screen of error)
I tried to debug these lines - but can't see anything wrong with them.
Any ideas?
Thx Shane!
No - I tried with another view, and it keeps not saving the view the code is in.
However in a new install of a fresh site - it does save.
So strange..
Unfortunately I cannot see nothing wrong with this content apart from the request being blocked when trying to save when the substr() function is used on this particular view.
Here is the error, see screenshot.
What I would do is to perhaps remake the view and add the code to that new view given that it works on other views.