Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is a text to be displayed...More
- <em>This is</em> a text to be d...More
- *This is* a text to be d...More
- p.each(function(mel){
- var t = mel.get('html'); //get all the content of p
- var str = t; //duplicate the string
- var div = new Element('div', {html:str}); //this function strips tags though don't know if it's useful here
- var text = div.textContent || div.innerText || "";
- text;
- if (text.length<100) return;
- var tOne = t.substr(0,100); //breaking text on visible and non-visible
- var tTwo = t.substr(101,t.length); //all the further code works creating "More" after 100 characters
- var dots = new Element('span', {
- 'class':'unedit',
- 'text':'...'
- });
- var more = new Element('a', {
- href: '#',
- 'class':'more unedit',
- 'text':'More'
- });
- var unseen = new Element('span', {
- 'class':'appended',
- 'html':tTwo,
- styles: {
- 'display':'none',
- }
- })
- var less = new Element('a', {
- href: '#',
- 'class':'less unedit',
- 'text':'Less'
- })
- unseen.grab(new Element('br'));
- unseen.grab(less);
- mel.set('html', tOne);
- mel.grab(dots);
- mel.grab(more);
- mel.grab(unseen);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement