Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. $(document).ready(function(){var type=$('.type')
  2. type.material_select();var chips=$('.search-chips');var preload_data=[];var preload=$('.search input[name=search]');if(preload.length){preload.val().split(',').forEach(function(value){preload_data.push({tag:value});});}
  3. chips.material_chip({placeholder:'Search',secondaryPlaceholder:'Search',data:preload_data});var suggest;var suggestions=$('.search-suggestions');function search(){var search=$(this).val().trim();clearTimeout(suggest);if(search==''){suggestions.empty();}else{suggest=setTimeout(function(){$.get('/suggest/'+ type.val()+'/'+ encodeURIComponent(search),function(data){suggestions.empty();if(type.val()=='p'){for(var index=0;index<data.length;index++){var person=data[index];suggestions.append('<li data-chip="'+ person['username']+'"><img src=https://www.roblox.com/headshot-thumbnail/image?userId='+ person['id']+'&width=75&height=75&format=png>'+ person['username']+'<li>');}}else{for(var index=0;index<data.length;index++){var item=data[index];suggestions.append('<li data-chip="'+(('acronym'in item)?item['acronym']:item['name'])+'"><img src=http://www.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid='+ item['id']+'&fmt=png&wd=75&ht=75>'+ item['name']+(('acronym'in item)?' ('+ item['acronym']+')':'')+'<li>');}}
  4. suggestions.find('li').click(function(){chips.addChip(0,{tag:$(this).attr('data-chip')},chips);chips.find('input').val('').focus();clearTimeout(suggest);suggestions.empty();});});},250);}}
  5. chips.find('input').keydown(function(e){if(e.keyCode==13&&$(this).val()==''){var chipData=chips.material_chip("data");if(chipData.length>0){var data="";for(var index=0;index<chipData.length;index++){data+=chipData[index]["tag"].replace(/\s+/g,"+").replace(/[^a-zA-Z0-9_+*]/g,"")+(index==(chipData.length- 1)?"":",");}
  6. window.location.href='/'+ type.val()+'/'+ data;}}else{suggestions.empty();}}).keyup(search).focus(search);$('a[href="#recommendation"]').click(function(event){event.preventDefault();chips.addChip(0,{tag:$(this).attr('data-chip')},chips);});})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement