Advertisement
Guest User

Discussions bio

a guest
Dec 31st, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. /**
  2. * @author: Flightmare (http://elderscrolls.wikia.com/wiki/User:Flightmare)
  3. * @version: 1.0
  4. * @license: CC-BY-SA 3.0
  5. * @description: Imports the discussions bio (app profile) into the masthead.
  6. */
  7. $( document ).ready(function() {
  8. //Test page for masthead and link to discussions profile and check for double loads
  9. if($('#discussion-bio').length === 0 && $('#UserProfileMasthead #discussionAllPostsByUser').attr('href')) {
  10. var userId = $('#UserProfileMasthead #discussionAllPostsByUser').attr('href').split('/')[3];
  11.  
  12. //Fetch bio
  13. $.ajax({
  14. type: 'GET',
  15. url: 'https://services.wikia.com/user-attribute/user/' + userId + '/attr/bio',
  16. success: function(data) {
  17. //Create new masthead entry
  18. $('.UserProfileMasthead .details').append('<li itemprop="bio" id="discussion-bio" style="max-height: 100px; overflow: hidden; transition: max-height 1s"><span>BIO</span> ' + data.value.replace(/(?:\r\n|\r|\n)/g, '<br />') + '</li>');
  19.  
  20. //Add expand toggle button if overflow happens
  21. if($('#discussion-bio').prop('scrollHeight') > $('#discussion-bio').outerHeight()) {
  22. $('#discussion-bio').after('<span id="discussion-bio-toggle" style="float:right">[Read more]</span>');
  23. $('#discussion-bio-toggle').click(function() {
  24. if($('#discussion-bio').css('max-height') == '100px' ) {
  25. $('#discussion-bio').css('max-height', 'inherit');
  26. $('#discussion-bio-toggle').text('[Read less]');
  27. } else {
  28. $('#discussion-bio').css('max-height', '100px');
  29. $('#discussion-bio-toggle').text('[Read more]');
  30. }
  31. });
  32. }
  33. }
  34. });
  35. }
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement