Created
April 7, 2017 15:12
-
-
Save gagimilicevic/b674d35139af559f0dd26f7e67ae7adf to your computer and use it in GitHub Desktop.
Read More - Read Less javascript snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
var minimized_elements = $('div.minimize'); | |
minimized_elements.each(function(){ | |
var t = $(this).text(); | |
if(t.length < 600) return; | |
$(this).html( | |
t.slice(0,600)+'<span>... </span><a href="#" class="more">' + customscript_vars.read_more + '</a>'+ | |
'<span style="display:none;">'+ t.slice(600,t.length)+' <a href="#" class="less">' + customscript_vars.read_less + '</a></span>' | |
); | |
}); | |
$('a.more', minimized_elements).click(function(event){ | |
event.preventDefault(); | |
$(this).hide().prev().hide(); | |
$(this).next().show(); | |
}); | |
$('a.less', minimized_elements).click(function(event){ | |
event.preventDefault(); | |
$(this).parent().hide().prev().show().prev().show(); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment