Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1.  
  2. $Core.searchFriendsInput =
  3. {
  4. aParams: {},
  5. iCnt: 0,
  6. aFoundUsers: {},
  7. aLiveUsers: {},
  8. sId: '',
  9. bNoSearch: false,
  10.  
  11. aFoundUser: {}, // Store the found user here
  12. sHtml : '', // Store the final html here. Useful for onBeforePrepend
  13. init: function($aParams)
  14. {
  15. this.aParams = $aParams;
  16. if (!isset(this.aParams['search_input_id']))
  17. {
  18. this.aParams['search_input_id'] = 'search_input_name_' + Math.round(Math.random() * 10000);
  19. }
  20. if (this._get('no_build')){
  21. this.sId = $aParams['id'].replace('#', '');
  22. }
  23. else{
  24. this.sId = $aParams['id'].replace('#', '').replace('.', '') + '__tmp__';
  25. }
  26. this.build();
  27. },
  28.  
  29. build: function()
  30. {
  31. var $sHtml = '';
  32. if (!this._get('no_build')){
  33.  
  34. $sHtml += '<div style="width:' + this._get('width') + '; position:relative;" class="js_friend_search_form" id="' + this.sId + '">';
  35. $sHtml += '<input type="text" id="' + this._get('search_input_id') + '" name="null" value="' + this._get('default_value') + '" autocomplete="off" onfocus="$Core.searchFriendsInput.buildFriends(this);" onkeyup="$Core.searchFriendsInput.getFriends(this);" style="width:100%;" class="js_temp_friend_search_input" />';
  36. $sHtml += '<div class="js_temp_friend_search_form" style="display:none;"></div>';
  37. $sHtml += '</div>';
  38.  
  39. $(this._get('id')).html($sHtml);
  40. }
  41. else{
  42. $sHtml += '<div class="js_temp_friend_search_form js_temp_friend_search_form_main" style="display:none;"></div>';
  43. $('#' + this.sId).find('form:first').append($sHtml);
  44. }
  45.  
  46. $('#' + this.sId).find('.js_temp_friend_search_input').keypress(function(e)
  47. {
  48. switch (e.keyCode)
  49. {
  50. case 9:
  51. case 40:
  52. case 38:
  53. var $iNextCnt = 0;
  54. $('.js_friend_search_link').each(function()
  55. {
  56. $iNextCnt++;
  57. if ($(this).hasClass('js_temp_friend_search_form_holder_focus'))
  58. {
  59. $(this).removeClass('js_temp_friend_search_form_holder_focus');
  60.  
  61. return false;
  62. }
  63. });
  64.  
  65. if (!$iNextCnt)
  66. {
  67. return false;
  68. }
  69.  
  70. $Core.searchFriendsInput.bNoSearch = true;
  71.  
  72. var $iNewCnt = 0;
  73. var $iActualFocus = 0;
  74. $('.js_friend_search_link').each(function()
  75. {
  76. $iNewCnt++;
  77. if ((e.keyCode == 38 ? ($iNextCnt - 1) == $iNewCnt : ($iNextCnt + 1) == $iNewCnt))
  78. {
  79. $iActualFocus++;
  80. $(this).addClass('js_temp_friend_search_form_holder_focus');
  81. return false;
  82. }
  83. });
  84.  
  85. if (!$iActualFocus)
  86. {
  87. $('.js_friend_search_link').each(function()
  88. {
  89. $(this).addClass('js_temp_friend_search_form_holder_focus');
  90.  
  91. return false;
  92. });
  93. }
  94.  
  95. return false;
  96. break;
  97. case 13:
  98. $Core.searchFriendsInput.bNoSearch = true;
  99. $('.js_friend_search_link').each(function()
  100. {
  101. if ($(this).hasClass('js_temp_friend_search_form_holder_focus'))
  102. {
  103. $Core.searchFriendsInput.processClick(this, $(this).attr('rel'));
  104. }
  105. });
  106. break;
  107. default:
  108. // p(e.keyCode);
  109. break;
  110. }
  111. });
  112. },
  113.  
  114. buildFriends: function($oObj)
  115. {
  116. $($oObj).val('');
  117.  
  118. if (empty($Cache.friends) && !isset(this.aParams['is_mail']))
  119. {
  120. $.ajaxCall('friend.buildCache', (this._get('allow_custom') ? '&allow_custom=1' : ''), 'GET');
  121. }
  122. },
  123.  
  124. getFriends: function($oObj)
  125. {
  126. if (empty($oObj.value))
  127. {
  128. this.closeSearch($oObj);
  129.  
  130. return;
  131. }
  132.  
  133. if (this.bNoSearch)
  134. {
  135. this.bNoSearch = false;
  136.  
  137. return;
  138. }
  139.  
  140.  
  141. if (isset(this.aParams['is_mail']) && this.aParams['is_mail'] == true)
  142. {
  143. $.ajaxCall('friend.getLiveSearch', 'parent_id=' + $($oObj).attr('id') + '&search_for=' + $($oObj).val() + '&width=' + this._get('width') + '&total_search=' + $Core.searchFriendsInput._get('max_search'), 'GET');
  144. return;
  145. }
  146.  
  147. var $iFound = 0;
  148. var $sHtml = '';
  149. $($Cache.friends).each(function($sKey, $aUser)
  150. {
  151. var $mRegSearch = new RegExp($oObj.value, 'i');
  152.  
  153. if ($aUser['full_name'].match($mRegSearch))
  154. {
  155. if (isset($Core.searchFriendsInput.aLiveUsers[$aUser['user_id']]))
  156. {
  157. return;
  158. }
  159.  
  160. $iFound++;
  161.  
  162. $Core.searchFriendsInput.storeUser($aUser['user_id'], $aUser);
  163.  
  164. $sHtml += '<li><a rel="' + $aUser['user_id'] + '" class="js_friend_search_link ' + (($iFound === 1 && !$Core.searchFriendsInput._get('global_search')) ? 'js_temp_friend_search_form_holder_focus' : '') + '" href="#" onclick="return $Core.searchFriendsInput.processClick(this, \'' + $aUser['user_id'] + '\');"><img src="' + $aUser['user_image'] + '" alt="" style="width:25px; height:25px;" />' + $aUser['full_name'] + '<div class="clear"></div></a></li>';
  165. if ($iFound > $Core.searchFriendsInput._get('max_search'))
  166. {
  167. return false;
  168. }
  169. }
  170. });
  171.  
  172. if ($iFound)
  173. {
  174. if (this._get('global_search')){
  175. $sHtml += '<li><a href="#" class="holder_notify_drop_link" onclick="$(this).parents(\'form:first\').submit(); return false;">' + oTranslations['friend.show_more_results_for_search_term'].replace('{search_term}',htmlspecialchars($oObj.value)) + '</a></li>';
  176. }
  177.  
  178. $($oObj).parent().find('.js_temp_friend_search_form').html('<div class="js_temp_friend_search_form_holder" style="width:' + this._get('width') + ';"><ul>' + $sHtml + '</ul></div>').show();
  179. }
  180. else
  181. {
  182. $($oObj).parent().find('.js_temp_friend_search_form').html('').hide();
  183. }
  184. },
  185.  
  186. storeUser: function($iUserId, $aData)
  187. {
  188. this.aFoundUsers[$iUserId] = $aData;
  189. },
  190.  
  191. removeSelected: function($oObj, $iUserId)
  192. {
  193. if (isset(this.aLiveUsers[$iUserId]))
  194. {
  195. delete this.aLiveUsers[$iUserId];
  196. }
  197. $($oObj).parents('li:first').remove();
  198. },
  199.  
  200. processClick: function($oObj, $iUserId)
  201. {
  202. if (!isset(this.aFoundUsers[$iUserId]))
  203. {
  204. return false;
  205. }
  206.  
  207. if (isset(this.aLiveUsers[$iUserId]))
  208. {
  209. return false;
  210. }
  211.  
  212. this.aLiveUsers[$iUserId] = true;
  213. $Behavior.reloadLiveUsers = function(){
  214. $Core.searchFriendsInput.aLiveUsers = {};
  215. $Behavior.reloadLiveUsers = function(){}
  216. }
  217. this.bNoSearch = false;
  218.  
  219. var $aUser = this.aFoundUser = this.aFoundUsers[$iUserId];
  220. var $oPlacement = $(this._get('placement'));
  221.  
  222. //$($oObj).parents('.js_friend_search_form:first').find('.js_temp_friend_search_input').val('').focus();
  223. $($oObj).parents('.js_friend_search_form:first').find('.js_temp_friend_search_form').html('').hide();
  224.  
  225. var $sHtml = '';
  226. $sHtml += '<li>';
  227.  
  228. $sHtml += '<a href="#" class="friend_search_remove" title="Remove" onclick="$Core.searchFriendsInput.removeSelected(this, ' + $iUserId + '); return false;">Remove</a>';
  229. if (!this._get('inline_bubble'))
  230. {
  231. $sHtml += '<div class="friend_search_image"><img src="' + $aUser['user_image'] + '" alt="" style="width:25px; height:25px;" /></div>';
  232. }
  233. $sHtml += '<div class="friend_search_name">' + $aUser['full_name'] + '</div>';
  234. if (!this._get('inline_bubble'))
  235. {
  236. $sHtml += '<div class="clear"></div>';
  237. }
  238. $sHtml += '<div><input type="hidden" name="' + this._get('input_name') + '[]" value="' + $aUser['user_id'] + '" /></div>';
  239. $sHtml += '</li>';
  240. this.sHtml = $sHtml;
  241.  
  242. if (empty($oPlacement.html()))
  243. {
  244. $oPlacement.html('<div class="js_custom_search_friend_holder"><ul' + (this._get('inline_bubble') ? ' class="inline_bubble"' : '') + '></ul>' + (this._get('inline_bubble') ? '<div class="clear"></div>' : '') + '</div>');
  245. }
  246.  
  247. if (this._get('onBeforePrepend'))
  248. {
  249. this._get('onBeforePrepend')(this._get('onBeforePrepend'));
  250. }
  251.  
  252. $oPlacement.find('ul').prepend(this.sHtml);
  253.  
  254. if (this._get('onclick'))
  255. {
  256. this._get('onclick')(this._get('onclick'));
  257. }
  258.  
  259. if (this._get('global_search')){
  260. window.location.href = $aUser['user_profile'];
  261. $($oObj).parents('.js_temp_friend_search_form:first').hide();
  262. }
  263.  
  264. this.aFoundUsers = {};
  265.  
  266. if (this._get('inline_bubble')){
  267. $('#' + this._get('search_input_id') + '').val('').focus();
  268. }
  269.  
  270. return false;
  271. },
  272.  
  273. closeSearch: function($oObj)
  274. {
  275. $($oObj).parent().find('.js_temp_friend_search_form').html('').hide();
  276. },
  277.  
  278. _get: function($sParam)
  279. {
  280. return (isset(this.aParams[$sParam]) ? this.aParams[$sParam] : '');
  281. }
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement