fork download
  1. /*1298995513,169775559*/
  2.  
  3. if (window.CavalryLogger) {
  4. CavalryLogger.start_js(["dfIHW"]);
  5. }
  6.  
  7. function ProfileChooser() {
  8. this.parent.construct(this);
  9. this.checkedItems = {};
  10. this.cache = {};
  11. this.suggested = {};
  12. this.activeCache = null;
  13. this.index = 0;
  14. }
  15. ProfileChooser.extend('ProfileBrowser');
  16. ProfileChooser.prototype = {
  17. VALUE_DEFAULT: 'default',
  18. VALUE_SELECTED: 'selected',
  19. VALUE_DISABLED: 'disabled',
  20. NUM_PER_PAGE: 50,
  21. preloadCache: function (b, c) {
  22. this.suggested = c;
  23. this.cache = b;
  24. for (var a in this.cache) this.sortSuggested(a);
  25. },
  26. subscribeListView: function () {
  27. this.listView.subscribe('scrollTrigger', function () {
  28. var b = this.index;
  29. var a = b + this.NUM_PER_PAGE;
  30. var c = this.cache[this.activeCache].slice(b, a);
  31. if (c.length) {
  32. this.index = a;
  33. this.appendToView(c);
  34. this.listView.resetScroll();
  35. }
  36. }.bind(this));
  37. this.listView.subscribe('clickedCheckable', function (a, e) {
  38. var c = CSS.hasClass(e.item, 'selectedCheckable');
  39. var b = DOM.find(e.item, '.checkbox');
  40. var f = this.listView.getRoot();
  41. if (!c && CSS.hasClass(f, 'limitReached')) {
  42. b.checked = false;
  43. return;
  44. }
  45. var g = b.value;
  46. this.typeahead.getData().data[g].selected = !c;
  47. this.checkedItems[g] = !c ? 1 : 0;
  48. this.typeahead.getCore().hiddenInput.value = JSON.stringify(this.checkedItems);
  49. this.listView.toggleCheckableItem(e.item, c);
  50. var d = this.getCheckedCount();
  51. CSS.conditionClass(f, 'limitReached', d >= this.getSelectionLimit());
  52. this.inform('updateCheckableCount', {
  53. listview: f.id,
  54. count: d
  55. });
  56. }.bind(this));
  57. },
  58. subscribeSelector: function () {
  59. this.selector.subscribe('changeListEndpoint', function (a, b) {
  60. b.anchor.removeAttribute('data-listendpoint');
  61. this.resetTypeahead(b.showTypeahead);
  62. this.queryListEndpoint(b.endpoint, b.value);
  63. }.bind(this));
  64. this.selector.subscribe('changeValue', function (a, b) {
  65. this.resetTypeahead(b.showTypeahead);
  66. if (b.value == this.VALUE_SELECTED) {
  67. var c = [];
  68. for (var d in this.checkedItems) this.checkedItems[d] && c.push(d);
  69. this.cache[b.value] = c;
  70. }
  71. this.resetView(b.value);
  72. }.bind(this));
  73. },
  74. subscribeTypeahead: function () {
  75. var a = this.typeahead.getData();
  76. a.subscribe('activity', function (b, c) {
  77. this.listView.setLoadingState(c.activity || this.querying);
  78. c.activity && this.listView.swapList(this.typeahead.getView().element);
  79. }.bind(this));
  80. a.subscribe('fillCache', function (b, e) {
  81. this.cache[this.VALUE_DEFAULT] = e.alluids;
  82. this.sortSuggested(this.VALUE_DEFAULT);
  83. this.cache[this.VALUE_DISABLED] = e.disabled;
  84. this.cache[this.VALUE_SELECTED] = e.selected;
  85. var c = this.selector.getSelectedAnchor();
  86. var f = this.selector.getSelectedValue();
  87. if (this.cache[f]) {
  88. this.resetView(f);
  89. } else {
  90. var d = c.getAttribute('data-listendpoint');
  91. if (d) {
  92. this.queryListEndpoint(d, f);
  93. c.removeAttribute('data-listendpoint');
  94. }
  95. }
  96. this.checkedItems = e.selected;
  97. this.typeahead.getCore().hiddenInput.value = JSON.stringify(this.checkedItems);
  98. this.activeCache = f;
  99. }.bind(this));
  100. this.typeahead.subscribe('render', function (b, c) {
  101. if (!this.typeahead.getCore().getValue()) {
  102. this.listView.resetScroll();
  103. this.index = c.length;
  104. }
  105. }.bind(this));
  106. this.typeahead.subscribe('reset', function () {
  107. this.resetView(this.activeCache);
  108. }.bind(this));
  109. },
  110. queryListEndpoint: function (a, b) {
  111. this.querying = true;
  112. this.listView.setLoadingState(true);
  113. new AsyncRequest(a).setHandler(function (d) {
  114. var c = d.getPayload();
  115. this.cache[b] = c.ids;
  116. this.suggested[b] = c.suggested;
  117. this.sortSuggested(b);
  118. this.resetView(b);
  119. this.listView.setLoadingState(false);
  120. this.querying = false;
  121. }.bind(this)).send();
  122. },
  123. resetTypeahead: function (b) {
  124. CSS.conditionShow(this.typeahead.getElement(), b);
  125. var a = this.typeahead.getCore();
  126. a.reset();
  127. b && a.getElement().focus();
  128. a.hiddenInput.value = JSON.stringify(this.checkedItems);
  129. },
  130. sortSuggested: function (b) {
  131. var c = this.suggested[b];
  132. if (!c) return;
  133. var a = this.cache[b];
  134. var e = Object.from(a);
  135. var d = c.filter(function (f) {
  136. if (f in e) {
  137. a.splice(a.indexOf(f), 1);
  138. return true;
  139. }
  140. return false;
  141. });
  142. this.cache[b] = d.concat(a);
  143. },
  144. resetView: function (a) {
  145. this.activeCache = a;
  146. var b = this.typeahead.getData();
  147. var c = this.cache[a];
  148. b.setSuggestedUids(this.suggested[a] || []);
  149. b.respond('', c, true);
  150. b.setInclusions(c);
  151. },
  152. appendToView: function (b) {
  153. var a = this.typeahead.getData().buildData(b);
  154. this.typeahead.getView().appendResults(a);
  155. },
  156. getCheckedCount: function () {
  157. var a = 0;
  158. for (var b in this.checkedItems) if (this.checkedItems[b]) a++;
  159. return a;
  160. }
  161. };
  162.  
  163. function ProfileChooserSelector() {
  164. this.parent.construct(this);
  165. }
  166. ProfileChooserSelector.extend('ProfileBrowserSelector');
  167. ProfileChooserSelector.prototype = {
  168. handle: function (c) {
  169. var a = DOM.find(c.option, 'a');
  170. var b = a.getAttribute('data-listendpoint');
  171. var e = Selector.getOptionValue(c.option);
  172. var d = a.getAttribute('data-typeahead');
  173. if (b) {
  174. this.inform('changeListEndpoint', {
  175. anchor: a,
  176. endpoint: b,
  177. value: e,
  178. showTypeahead: d
  179. });
  180. return;
  181. }
  182. this.inform('changeValue', {
  183. value: e,
  184. showTypeahead: d
  185. });
  186. }
  187. };
  188.  
  189. function ProfileChooserDataSource(b, c, a) {
  190. this.parent.construct(this, b);
  191. this.selectedEntries = c;
  192. this.disabledEntries = a;
  193. this.suggestedUids = {};
  194. this.inclusions = [];
  195. this.exclusionsObj = Object.from(this.exclusions);
  196. }
  197. ProfileChooserDataSource.extend('DataSource');
  198. ProfileChooserDataSource.prototype = {
  199. bootstrap: function () {
  200. if (this.bootstrapped) return;
  201. this.fetch(this.bootstrapEndpoint, this.bootstrapData, '', '');
  202. this.bootstrapped = true;
  203. },
  204. processEntries: function (a, b) {
  205. var c = this.parent.processEntries(a, b);
  206. c = this.removeExclusions(c);
  207. c.each(function (e) {
  208. var d = this.data[e];
  209. d.selected = e in this.selectedEntries;
  210. d.disabled = e in this.disabledEntries;
  211. }, this);
  212. this.setInclusions(c);
  213. return c;
  214. },
  215. setInclusions: function (a) {
  216. this.inclusions = a || [];
  217. return this;
  218. },
  219. buildCacheResults: function (d, a) {
  220. var c = this.parent.buildCacheResults(d, a);
  221. var b = Object.from(this.inclusions);
  222. return c.filter(function (e) {
  223. return e in b;
  224. });
  225. },
  226. buildUids: function (c, a) {
  227. if (c) return this.parent.buildUids(c, a);
  228. if (this.inclusions) return this.inclusions;
  229. var b = this.exclusionsObj;
  230. return values(this.data || {}).sort(function (d, e) {
  231. return d.index - e.index;
  232. }).map(function (d) {
  233. return d.uid;
  234. }).concat(a || []).filter(function (d) {
  235. if (d in b) return false;
  236. return (b[d] = true);
  237. });
  238. },
  239. buildData: function (c) {
  240. var a = this.parent.buildData(c);
  241. var b = this.suggestedUids;
  242. a.each(function (d) {
  243. d.suggested = (d.uid in b);
  244. });
  245. return a;
  246. },
  247. removeExclusions: function (a) {
  248. return a.filter(function (b) {
  249. return !(b in this.exclusionsObj);
  250. }.bind(this));
  251. },
  252. setSuggestedUids: function (a) {
  253. this.suggestedUids = Object.from(a);
  254. },
  255. fillCache: function (a) {
  256. a = this.removeExclusions(a);
  257. this.parent.fillCache(a);
  258. this.inform('fillCache', {
  259. alluids: a,
  260. selected: this.selectedEntries,
  261. disabled: this.disabledEntries
  262. });
  263. }
  264. };
  265.  
  266. function ProfileChooserTypeaheadCore(a, b) {
  267. this.parent.construct(this, a, b);
  268. }
  269. ProfileChooserTypeaheadCore.extend('TypeaheadCore');
  270. ProfileChooserTypeaheadCore.prototype = {
  271. keepFocused: false,
  272. initToggle: bagofholding,
  273. initView: bagofholding,
  274. select: bagofholding,
  275. keyup: function () {
  276. this.checkValue();
  277. }
  278. };
  279.  
  280. function ProfileChooserTypeaheadView(a, b) {
  281. this.parent.construct(this, a, b);
  282. }
  283. ProfileChooserTypeaheadView.extend('TypeaheadView');
  284. ProfileChooserTypeaheadView.prototype = {
  285. render: function (j, e, f) {
  286. var d = this.results[this.index],
  287. c = this.autoSelect ? 0 : -1,
  288. a = [];
  289. if (j) {
  290. var h;
  291. var i = {
  292. search: _tx("\u003cstrong>{value}\u003c\/strong>", {
  293. value: htmlize(j)
  294. })
  295. };
  296. if (!e || !e.length) {
  297. h = _tx("No results for: {search}", i);
  298. } else if (e.length == 1) {
  299. h = _tx("Top result for: {search}", i);
  300. } else {
  301. i.count = e.length;
  302. h = _tx("Top {count} results for: {search}", i);
  303. }
  304. a = ['<div class="fbProfileBrowserSummaryBox pvm phs mhs">', h, '</div>'];
  305. }
  306. a.push('<div class="fbProfileBrowserListContainer">', this.buildMarkup(e), '</div>');
  307. this.results = e;
  308. CSS.conditionClass(this.element, 'hideSummary', !j);
  309. this.element.innerHTML = a.join('');
  310. this.items = this.getItems();
  311. if (d && f) for (var b = 0, g = e.length; b < g; ++b) if (d.uid == e[b].uid) {
  312. c = b;
  313. break;
  314. }
  315. this.highlight(c, false);
  316. this.inform('render', e);
  317. },
  318. buildMarkup: function (c) {
  319. var d = [];
  320. var b = [];
  321. var a = [];
  322. c.each(function (e) {
  323. if (e.suggested) {
  324. d.push(e);
  325. } else b.push(e);
  326. });
  327. if (d.length) {
  328. a.push('<div class="clearfix">', this.parent.buildMarkup(d), '</div>');
  329. if (b.length) a.push('<div class="suggestedDivider mts">', '<span class="fss fcg fwb phs dividerText">', _tx("ALL FRIENDS"), '</span>', '</div>');
  330. }
  331. a.push(this.parent.buildMarkup(b));
  332. return a.join('');
  333. },
  334. renderer: function (a, b) {
  335. if (!a) return [];
  336. var c = a.suggested ? _tx("Suggested") : a.category;
  337. var d = htmlize(a.text);
  338. var e = d.length > 20 ? 'long' : '';
  339. return ['<li class="multiColumnCheckable checkableListItem ', a.disabled ? ' disabledCheckable' : '', a.selected ? ' selectedCheckable' : '', '">', '<input type="checkbox" class="checkbox" name="checkableitems[]"', 'value="', htmlspecialchars(a.uid), '"', a.selected ? ' checked="1"' : '', a.disabled ? ' disabled="1"' : '', '/>', '<a class="anchor" href="#" tabindex="-1">', '<div class="UIImageBlock clearfix UIImageBlock_Entity">', '<img src="', a.photo, '" ', 'class="photo UIImageBlock_Image img UIImageBlock_ENT_Image"', '/>', '<div class="content UIImageBlock_Content">', '<div class="fcb fwb text ', e, '">', d, '</div>', '<div class="fcg text subtitle">', c, '</div>', '</div>', '</div>', '</a>', '</li>'];
  340. },
  341. highlight: function (a, b) {
  342. if (a > this.items.length - 1) {
  343. a = -1;
  344. } else if (a < -1) a = this.items.length - 1;
  345. if (a >= 0 && this.results[a] && !this.results[a].disabled) {
  346. this.selected = this.items[a];
  347. } else this.selected = null;
  348. this.index = a;
  349. if (b !== false) this.inform('highlight', {
  350. index: a,
  351. selected: this.results[a]
  352. });
  353. },
  354. appendResults: function (b) {
  355. var a = DOM.find(this.element, '.fbProfileBrowserListContainer');
  356. DOM.appendContent(a, HTML(this.buildMarkup(b)));
  357. }
  358. };
  359.  
  360. if (window.Bootloader) {
  361. Bootloader.done(["dfIHW"]);
  362. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty