Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - wide_dd.js (Старый размер - 20202 | Новый - 0):
- 0. - (function() {
- 1. -
- 2. - var wdd = {
- 3. - _textEvent: function(e) {
- 4. - var el = e.target, id = el.dd, dd = cur.wdd[id];
- 5. - switch (e.type) {
- 6. - case 'focus':
- 7. - el.focused = true;
- 8. - if (!el.active) {
- 9. - val(el, '');
- 10. - el.style.color = '';
- 11. - el.active = 1;
- 12. - el.phd = false;
- 13. - }
- 14. -
- 15. - wdd._updateTextInput(dd);
- 16. - wdd._updateList(dd);
- 17. - break;
- 18. -
- 19. - case 'blur':
- 20. - el.focused = false;
- 21. - if (!(el.active = (!el.phd && el.value) ? 1 : '')) { // not val(el)
- 22. - if (isEmpty(dd.selected)) {
- 23. - val(el, el.ph);
- 24. - el.style.color = '#777';
- 25. - el.phd = true;
- 26. - } else {
- 27. - hide(el);
- 28. - if (!dd.full) show(dd.add);
- 29. - }
- 30. - } else if (dd.over && dd.opts.chooseOnBlur && dd.opts.chooseOnBlur(dd.over)) {
- 31. - wdd.select(id);
- 32. - hide(el);
- 33. - if (!dd.full) show(dd.add);
- 34. - }
- 35. -
- 36. - wdd._hideList(dd);
- 37. - break;
- 38. -
- 39. - case 'keydown':
- 40. - case 'keypress':
- 41. - clearTimeout(dd.updateTimer);
- 42. - dd.updateTimer = setTimeout(wdd._updateList.pbind(dd, false), 0);
- 43. -
- 44. - var el = ge('wddi' + dd.over + '_' + id);
- 45. - if (e.keyCode == KEY.UP) {
- 46. - if (el && domPS(el)) {
- 47. - wdd.over(id, domPS(el).id.replace(/^wddi/, '').replace(new RegExp('_' + id + '$', ''), ''), true);
- 48. - }
- 49. - return cancelEvent(e);
- 50. - } else if (e.keyCode == KEY.DOWN) {
- 51. - if (el && domNS(el)) {
- 52. - wdd.over(id, domNS(el).id.replace(/^wddi/, '').replace(new RegExp('_' + id + '$', ''), ''), true);
- 53. - }
- 54. - return cancelEvent(e);
- 55. - } else if (e.keyCode == KEY.RETURN) {
- 56. - wdd.select(id);
- 57. - return cancelEvent(e);
- 58. - } else if (e.keyCode == KEY.ESC) {
- 59. - debugLog('before blur');
- 60. - dd.text.blur();
- 61. - }
- 62. - break;
- 63. - }
- 64. - },
- 65. - _getTextValue: function() {
- 66. - return this.active ? this.value : '';
- 67. - },
- 68. - _widenTextInput: function(dd) {
- 69. - if (vk.rtl) {
- 70. - dd.text.style.width = (Math.max((dd.text.offsetTop > 20 ? dd.fullWidth : dd.partWidth) - dd.fullWidth + (dd.text.offsetLeft + dd.text.offsetWidth) - 2, dd.addWidth) - dd.textDelta) + 'px';
- 71. - } else {
- 72. - dd.text.style.width = (Math.max((dd.text.offsetTop > 20 ? dd.fullWidth : dd.partWidth) - (dd.text.offsetLeft - dd.textOffset) - 2, dd.addWidth) - dd.textDelta) + 'px';
- 73. - }
- 74. - wdd._showList(dd);
- 75. - },
- 76. - _updateTextInput: function(dd) {
- 77. - if (!dd.addWidth) return;
- 78. - dd.text.style.width = (dd.addWidth - dd.textDelta) + 'px';
- 79. - setTimeout(wdd._widenTextInput.pbind(dd), 0);
- 80. - },
- 81. - _focusText: function(dd) {
- 82. - if (dd.full) {
- 83. - return;
- 84. - }
- 85. - hide(dd.add);
- 86. - show(dd.text);
- 87. - wdd._updateTextInput(dd);
- 88. - setTimeout(elfocus.pbind(dd.text), 0);
- 89. - },
- 90. -
- 91. - _clickEvent: function(dd, e) {
- 92. - if (e.target == dd.arrow) return;
- 93. - if (e.target == dd.text.parentNode) {
- 94. - return wdd._focusText(dd);
- 95. - }
- 96. - for (var el = e.target; el && el != dd.text.parentNode; el = el.parentNode) {
- 97. - if (el == dd.add) {
- 98. - return wdd._focusText(dd);
- 99. - }
- 100. - }
- 101. - },
- 102. - _arrDownEvent: function(dd, e) {
- 103. - if (isVisible(dd.listWrap)) {
- 104. - wdd._hideList(dd);
- 105. - } else {
- 106. - wdd._focusText(dd);
- 107. - }
- 108. - },
- 109. - _afterInit: function(dd) {
- 110. - wdd._index(dd);
- 111. - if (!browser.opera_mobile) {
- 112. - wdd._textEvent({target: dd.text, type: dd.text.focused ? 'focus' : 'blur'});
- 113. - }
- 114. - if (dd.text.focused) {
- 115. - wdd._updateList(dd);
- 116. - } else {
- 117. - wdd._updateTextInput(dd);
- 118. - }
- 119. - addEvent(dd.text.parentNode, 'click', wdd._clickEvent.pbind(dd));
- 120. - addEvent(dd.arrow, 'mousedown', wdd._arrDownEvent.pbind(dd));
- 121. - extend(dd, {
- 122. - addWidth: getSize(dd.add)[0],
- 123. - textDelta: getSize(dd.text)[0] - intval(getStyle(dd.text, 'width')),
- 124. - fullWidth: getSize(domPN(dd.text))[0] - 4,
- 125. - textOffset: dd.text.offsetLeft
- 126. - });
- 127. - dd.partWidth = dd.fullWidth - getSize(dd.arrow)[0];
- 128. - },
- 129. -
- 130. - _updateList: function(dd, force, q) {
- 131. - if (!dd.cache['']) return;
- 132. -
- 133. - q = q !== undefined ? q : trim(val(dd.text));
- 134. - if (dd.lastQ === q && !force) {
- 135. - wdd._showList(dd);
- 136. - return;
- 137. - }
- 138. - dd.lastQ = q;
- 139. - clearTimeout(dd.requestTimer);
- 140. -
- 141. - var custom = dd.opts.custom, data = custom && custom(q);
- 142. - if (data) {
- 143. - wdd._renderList(dd, data);
- 144. - } else {
- 145. - data = dd.cache[q];
- 146. - if (data) {
- 147. - wdd._renderList(dd, data, true);
- 148. - } else {
- 149. - data = wdd._search(dd, q);
- 150. - wdd._renderList(dd, data, !dd.opts.url);
- 151. - if (dd.opts.url) {
- 152. - dd.requestTimer = setTimeout(wdd._requestList.pbind(dd), dd.opts.requestWait);
- 153. - }
- 154. - }
- 155. - }
- 156. - },
- 157. - _index: function(dd) {
- 158. - var def = dd.opts.defaultItems, items = dd.opts.items, defIds = [], i, l;
- 159. - for (i = 0, l = def.length; i < l; ++i) {
- 160. - defIds.push(i);
- 161. - }
- 162. - dd.cache[''] = defIds;
- 163. -
- 164. - for (i = 0, l = items.length; i < l; ++i) {
- 165. - wdd._indexItem(dd, i, items[i]);
- 166. - }
- 167. - },
- 168. - _indexItem: function(dd, k, v) {
- 169. - var i, j, l, words = '', keys = dd.opts.searchKeys, indexedKeys = {};
- 170. - for (i = 0, l = keys.length; i < l; ++i) {
- 171. - words += ' ' + (v[keys[i]] || '').replace(dd.opts.delimeter, ' ').replace(/<[^>]*>/g, '');
- 172. - }
- 173. - words = trim(words.toLowerCase()).split(/\s+/);
- 174. - for (i = 0; i < words.length; i++) {
- 175. - for (j = 1; j <= dd.opts.wholeIndex; j++) {
- 176. - var key = words[i].substr(0, j);
- 177. - if (indexedKeys[key]) continue;
- 178. - if (!dd.index[key]) dd.index[key] = [];
- 179. - dd.index[key].push(k);
- 180. - indexedKeys[key] = 1;
- 181. - }
- 182. - }
- 183. - },
- 184. - _search: function(dd, q) {
- 185. - q = trim(q.toLowerCase().replace(dd.opts.delimeter, ' '));
- 186. - if (!q) {
- 187. - return dd.cache[''];
- 188. - }
- 189. -
- 190. - var whole = dd.opts.wholeIndex;
- 191. - if (q.length <= whole && q.indexOf(' ') == -1) {
- 192. - return dd.index[q] || [];
- 193. - }
- 194. -
- 195. - q = q.split(' ');
- 196. - var minSize = 0, minQ = '', i, l, res;
- 197. - for (i = 0, l = q.length; i < l; ++i) {
- 198. - var part = q[i].substr(0, whole);
- 199. - var items = dd.index[part];
- 200. - if (!minQ || !items || items.length < minSize) {
- 201. - minSize = items ? items.length : 0;
- 202. - minQ = part;
- 203. - }
- 204. - if (!minSize) return [];
- 205. - }
- 206. -
- 207. - var res = [], keys = dd.opts.searchKeys, len = keys.length;
- 208. - for (i = 0, l = dd.index[minQ].length; i < l; ++i) {
- 209. - var v = dd.index[minQ][i], item = dd.opts.items[v];
- 210. - var fail = false, words = '', key;
- 211. - for (var j = 0; j < len; ++j) {
- 212. - words += ' ' + (item[keys[j]] || '').replace(dd.opts.delimeter, ' ').replace(/<[^>]*>/g, '');
- 213. - }
- 214. - words = words.toLowerCase();
- 215. - for (j = 0, len = q.length; j < len; ++j) {
- 216. - if (words.indexOf(' ' + q[j]) == -1) {
- 217. - fail = true;
- 218. - break;
- 219. - }
- 220. - }
- 221. - if (!fail) {
- 222. - res.push(v);
- 223. - }
- 224. - }
- 225. - return res;
- 226. - },
- 227. - _requestList: function(dd) {
- 228. - var q = trim(val(dd.text));
- 229. - if (!q) return;
- 230. -
- 231. - ajax.post(dd.opts.url, extend({str: q}, dd.opts.params || {}), {onDone: function(data) {
- 232. - dd.cache[q] = wdd._search(dd, q).concat(data);
- 233. - wdd._renderList(dd, data, true, true);
- 234. - }});
- 235. - },
- 236. - _renderList: function(dd, data, showEmpty, append) {
- 237. - var html = [], shown = 0, q = dd.lastQ, hl = wdd._highlight, markfn = dd.opts.itemMark;
- 238. - if (dd.outdated) append = false;
- 239. - if (append) {
- 240. - shown = dd.list.childNodes.length;
- 241. - } else {
- 242. - dd.shown = {};
- 243. - shown = 0;
- 244. - }
- 245. - for (var i = 0, l = data.length; i < l; ++i) {
- 246. - var item = data[i];
- 247. - if (!isArray(item)) {
- 248. - item = dd.opts.items[item];
- 249. - }
- 250. -
- 251. - var id = item[0] + '', id_ = id + '_', cl = '';
- 252. - if (dd.selected[id_] || dd.shown[id_] || dd.selCount && item[8] > 0) continue;
- 253. - dd.shown[id_] = item;
- 254. -
- 255. - var mark = isArray(item[3]) ? '' : (markfn(item) ? '<div class="wdd_mark"></div>' : '');
- 256. - var img = item[3] ? '<b class="fl_l wddi_thumb"><img class="wddi_img" src="' + (isArray(item[3]) ? '/images/icons/multichat.png' : item[3]) + '" />' + mark + '</b>' : '', cl;
- 257. - if (shown) {
- 258. - cl = 'wddi';
- 259. - } else {
- 260. - cl = 'wddi_over';
- 261. - dd.over = id;
- 262. - }
- 263. - var text = q && hl(item[1] || '', q) || (item[1] || ''), sub = q && hl(item[2] || '', q) || (item[2] || '');
- 264. - html.push('\
- 265. - <div class="' + cl + '" onmousedown="WideDropdown.select(\'' + dd.id + '\', event)" onmouseover="WideDropdown.over(\'' + dd.id + '\', \'' + clean(id) + '\')" id="wddi' + id + '_' + dd.id + '" onclick="">\
- 266. - <div class="wddi_data">' + img + '\
- 267. - <div class="wddi_text">' + text + '</div>\
- 268. - <div class="wddi_sub">' + sub + '</div>\
- 269. - </div>\
- 270. - </div>');
- 271. - ++shown;
- 272. - }
- 273. - html = html.join('');
- 274. - if (!shown && showEmpty) {
- 275. - html = '<div class="wddi_no">' + (q ? dd.opts.noResult : dd.opts.introText) + '</div>';
- 276. - }
- 277. - if (append) {
- 278. - dd.list.innerHTML += html;
- 279. - } else if (html) {
- 280. - dd.outdated = false;
- 281. - dd.list.innerHTML = html;
- 282. - } else {
- 283. - dd.outdated = true;
- 284. - }
- 285. - if (!dd.outdated) {
- 286. - dd.list.style.height = (shown > 6) ? '210px' : '';
- 287. - wdd._showList(dd);
- 288. -
- 289. - if (dd.scroll) {
- 290. - if (shown > 6) {
- 291. - dd.scroll.show();
- 292. - if (append) {
- 293. - dd.scroll.update(false, true);
- 294. - } else {
- 295. - dd.scroll.scrollTop();
- 296. - }
- 297. - } else {
- 298. - dd.scroll.hide();
- 299. - }
- 300. - }
- 301. -
- 302. - setTimeout(wdd._checkScroll.pbind(dd), 0);
- 303. - }
- 304. - },
- 305. - _highlight: function(label, q) {
- 306. - label = q.indexOf(' ') == -1 ? label.split(' ') : [label];
- 307. - var tmp = '';
- 308. - var qRus = parseLatin(q);
- 309. -
- 310. - if (qRus != null) {
- 311. - q = q + '|' + qRus;
- 312. - }
- 313. - var re = new RegExp('(?![^&;]+;)(?!<[^<>]*)((\\(*)(' + escapeRE(q) + '))(?![^<>]*>)(?![^&;]+;)', 'gi');
- 314. - for (var i in label) {
- 315. - tmp += (i > 0 ? ' ' : '') + label[i].replace(re, '$2<span class="wdd_hl">$3</span>');
- 316. - }
- 317. - return tmp;
- 318. - },
- 319. - _checkScroll: function(dd) {
- 320. - if (dd.scroll !== undefined) return;
- 321. - dd.scroll = false;
- 322. - stManager.add(['notifier.css', 'notifier.js'], function() {
- 323. - dd.scroll = new Scrollbar(dd.list, {
- 324. - prefix: 'fc_',
- 325. - nomargin: true,
- 326. - global: true,
- 327. - nokeys: true,
- 328. - right: vk.rtl ? 'auto' : 0,
- 329. - left: !vk.rtl ? 'auto' : 0
- 330. - });
- 331. - });
- 332. - },
- 333. - _showList: function(dd) {
- 334. - if (!dd.text.focused) return;
- 335. - dd.listWrap.style.marginTop = getSize(dd.listWrap.parentNode)[1] + 'px';
- 336. - if (!isVisible(dd.listWrap)) {
- 337. - ge(dd.listWrap).style.display = 'block';
- 338. - wdd._updateList(dd, true);
- 339. - }
- 340. - },
- 341. - _hideList: function(dd) {
- 342. - hide(dd.listWrap);
- 343. - },
- 344. - _updateImgs: function(dd, noAnim) {
- 345. - var el = dd.img;
- 346. - if (!dd.img) return;
- 347. -
- 348. - var i = 0, text = [], markfn = dd.opts.itemMark, imgs = [], cnt = 0, t;
- 349. - for (var k in dd.selected) {
- 350. - var item = dd.selected[k], img = item[3], href = item[4], onl = item[5], ids = item[6];
- 351. - if (isArray(img)) {
- 352. - for (var j = 0, l = img.length, el; j < l; ++j) {
- 353. - el = clone(item);
- 354. - el[0] = ids[j]; // for online status
- 355. - el[3] = img[j];
- 356. - el[4] = href[j];
- 357. - el[5] = onl[j];
- 358. - imgs.push(el);
- 359. - }
- 360. - } else {
- 361. - imgs.push(item);
- 362. - }
- 363. - }
- 364. - cnt = imgs.length;
- 365. - for (var k in imgs) {
- 366. - var item = imgs[k], img = item[3], href = item[4], cl, t, n, o, r;
- 367. - if (cnt > 3) {
- 368. - ++i;
- 369. - cl = 'wdd_img_tiny ' + ((i == 1 || i == 4) ? 'fl_l' : 'fl_r');
- 370. - } else if (cnt == 3) {
- 371. - cl = (i++ ? 'wdd_img_tiny fl_r' : 'wdd_img_half fl_l');
- 372. - } else if (cnt == 2) {
- 373. - cl = 'wdd_img_half ' + (i++ ? 'fl_r' : 'fl_l');
- 374. - } else {
- 375. - cl = 'wdd_img_full';
- 376. - }
- 377. - text.push(href ? ('<a href="' + href + '" class="' + cl + '">') : '<div class="' + cl + '">');
- 378. - text.push('<img class="wdd_img" src="' + img + '" />');
- 379. - if (markfn(item)) {
- 380. - text.push('<div class="wdd_mark"></div>');
- 381. - }
- 382. - text.push(href ? '</a>' : '</div>');
- 383. - if (i >= 4) break;
- 384. - }
- 385. - t = text.join('') || dd.opts.defImgText || '';
- 386. - dd.imgRand = false;
- 387. - if (noAnim === true) {
- 388. - val(dd.img, t);
- 389. - } else {
- 390. - o = ce('div', {className: 'wdd_img_layer', innerHTML: t});
- 391. - r = dd.imgRand = Math.random();
- 392. - for (n = domFC(dd.img); n && n.className == 'wdd_img_layer';) n = domNS(n);
- 393. - cssAnim(n ? dd.img.insertBefore(o, n) : dd.img.appendChild(o), {opacity: 1}, {duration: 150}, function() {
- 394. - if (dd.imgRand === r) {
- 395. - val(dd.img, t);
- 396. - }
- 397. - });
- 398. - }
- 399. - },
- 400. -
- 401. - init: function(el, opts) {
- 402. - if (!(el = ge(el))) return false;
- 403. -
- 404. - stManager.add(['notifier.css', 'notifier.js']); // for black scrollbar
- 405. -
- 406. - var id = el.id;
- 407. - if (!el.id) return false;
- 408. -
- 409. - if (!cur.wdd) {
- 410. - cur.wdd = {};
- 411. - } else if (cur.wdd[id]) {
- 412. - return false;
- 413. - }
- 414. -
- 415. - opts = extend({ // defaults
- 416. - cacheLength: 10000,
- 417. - requestWait: 300,
- 418. - wholeIndex: 2,
- 419. - maxItems: 29,
- 420. - searchKeys: [1],
- 421. - defaultItems: opts.items || [],
- 422. - items: opts.defaultItems || [],
- 423. - itemMark: function(item) {
- 424. - return intval(item[5]);
- 425. - }
- 426. - }, opts || {});
- 427. -
- 428. - var dd = {
- 429. - id: id,
- 430. - text: geByClass1('wdd_text', el),
- 431. - arrow: geByClass1('wdd_arr', el),
- 432. - img: opts.img && ge(opts.img),
- 433. - opts: opts,
- 434. - selected: {},
- 435. - selCount: 0,
- 436. - index: {},
- 437. - delimeter: /[\s\(\)\.,\-]+/g,
- 438. - cache: {}
- 439. - };
- 440. - if (dd.text.ph = dd.text.getAttribute('placeholder') || '') {
- 441. - el.setAttribute('placeholder', '');
- 442. - }
- 443. - dd.text.dd = id;
- 444. -
- 445. - dd.add = el.insertBefore(ce('div', {className: 'wdd_add fl_l', innerHTML: '\
- 446. - <div class="wdd_add2">\
- 447. - <table cellspacing="0" cellpadding="0"><tr>\
- 448. - <td><div class="wdd_add3">\
- 449. - <nobr>' + getLang('global_add') + '</nobr>\
- 450. - </div></td>\
- 451. - <td><div class="wdd_add_plus" onmousedown="WideDropdown.focus(\'' + id + '\')"></div></td>\
- 452. - </table>\
- 453. - </div>'}), dd.text);
- 454. - dd.bubbles = el.insertBefore(ce('div', {className: 'wdd_bubbles'}), dd.add);
- 455. - dd.listWrap = el.insertBefore(ce('div', {className: 'wdd_lwrap', innerHTML: '<div class="wdd_list"></div><div class="wdd_bottom1"></div><div class="wdd_bottom2"></div>'}, {display: 'none', width: opts.width || getSize(el)[0]}), el.firstChild);
- 456. - dd.list = dd.listWrap.firstChild;
- 457. -
- 458. - if (!browser.opera_mobile) {
- 459. - dd.text.active = val(dd.text) ? 1 : '';
- 460. - dd.text.getValue = wdd._getTextValue.bind(dd.text);
- 461. - addEvent(dd.text, 'focus blur ' + (browser.opera ? 'keypress' : 'keydown'), wdd._textEvent)
- 462. - }
- 463. -
- 464. - setTimeout(wdd._afterInit.pbind(dd), 0);
- 465. -
- 466. - return (cur.wdd[id] = dd);
- 467. - },
- 468. - initSelect: function (el, opts) {
- 469. - if (!(el = ge(el))) return false;
- 470. -
- 471. - stManager.add(['notifier.css', 'notifier.js']); // for black scrollbar
- 472. -
- 473. - var id = el.id;
- 474. - if (!el.id) return false;
- 475. -
- 476. - if (!cur.wdd) {
- 477. - cur.wdd = {};
- 478. - } else if (cur.wdd[id]) {
- 479. - return false;
- 480. - }
- 481. -
- 482. - opts = extend({ // defaults
- 483. - cacheLength: 10000,
- 484. - requestWait: 300,
- 485. - wholeIndex: 2,
- 486. - maxItems: 29,
- 487. - searchKeys: [1],
- 488. - defaultItems: opts.items || [],
- 489. - items: opts.defaultItems || [],
- 490. - itemMark: function(item) {
- 491. - return intval(item[5]);
- 492. - }
- 493. - }, opts || {});
- 494. -
- 495. - var dd = {
- 496. - id: id,
- 497. - text: opts.text || geByClass1('wdd_text', el),
- 498. - opts: opts,
- 499. - selected: {},
- 500. - selCount: 0,
- 501. - index: {},
- 502. - delimeter: /[\s\(\)\.,\-]+/g,
- 503. - cache: {}
- 504. - };
- 505. - dd.text.dd = id;
- 506. -
- 507. - dd.listWrap = el.insertBefore(ce('div', {className: 'wdd_lwrap', innerHTML: '<div class="wdd_list"></div><div class="wdd_bottom1"></div><div class="wdd_bottom2"></div>'}, {display: 'none', width: opts.width || getSize(el)[0]}), el.firstChild);
- 508. - dd.list = dd.listWrap.firstChild;
- 509. -
- 510. - setTimeout(wdd._index.pbind(dd), 0);
- 511. -
- 512. - return (cur.wdd[id] = dd);
- 513. - },
- 514. - deinit: function(el, c) {
- 515. - if (!c) c = cur;
- 516. - if (!c.wdd || !(el = ge(el))) return false;
- 517. -
- 518. - var id = el.id;
- 519. - if (!el.id) return false;
- 520. -
- 521. - var dd = c.wdd[id];
- 522. - if (!dd) return false;
- 523. -
- 524. - cleanElems(dd.text, domPN(dd.text));
- 525. - delete(c.wdd[id]);
- 526. -
- 527. - return true;
- 528. - },
- 529. - items: function(id, def, list) {
- 530. - var dd = cur.wdd[id];
- 531. - if (!list) list = def;
- 532. - extend(dd, {
- 533. - index: {},
- 534. - cache: {}
- 535. - });
- 536. - extend(dd.opts, {
- 537. - defaultItems: def || [],
- 538. - items: list || []
- 539. - });
- 540. - wdd._index(dd);
- 541. - wdd._updateList(dd, true);
- 542. - },
- 543. - over: function(id, item, check) {
- 544. - var dd = cur.wdd[id], el;
- 545. - if (dd.over) {
- 546. - if (el = ge('wddi' + dd.over + '_' + id)) {
- 547. - el.className = el.className.replace('wddi_over', 'wddi');
- 548. - }
- 549. - }
- 550. - dd.over = item;
- 551. - if (el = ge('wddi' + dd.over + '_' + id)) {
- 552. - el.className = el.className.replace(/wddi(\s|$)/, 'wddi_over ');
- 553. - if (check && dd.scroll) {
- 554. - var et = el.offsetTop, eh = el.offsetHeight, lt = dd.list.scrollTop, lh = dd.list.offsetHeight;
- 555. - if (et < lt) {
- 556. - dd.list.scrollTop = et;
- 557. - dd.scroll.update();
- 558. - } else if (et + eh > lt + lh) {
- 559. - dd.list.scrollTop = et + eh - lh;
- 560. - dd.scroll.update();
- 561. - }
- 562. - }
- 563. - }
- 564. - },
- 565. - select: function(id, e, item) {
- 566. - var dd = cur.wdd[id], sel = item ? item[0] : dd.over, sel_ = sel + '_';
- 567. - if (!item) item = dd.shown[sel_];
- 568. - if (sel === undefined || dd.selected[sel_] || !item) return;
- 569. -
- 570. - dd.over = false;
- 571. -
- 572. - if (dd.opts.onItemSelect && dd.opts.onItemSelect(item) === false) {
- 573. - return e && cancelEvent(e);
- 574. - }
- 575. -
- 576. - dd.selected[sel_] = item;
- 577. - ++dd.selCount;
- 578. - dd.full = (dd.opts.maxItems && dd.selCount >= dd.opts.maxItems || item[8] > 0);
- 579. -
- 580. - dd.bubbles.appendChild(ce('div', {id: 'wddb' + sel_ + id, className: 'summary_tab_sel fl_l', innerHTML: '\
- 581. - <div class="summary_tab2">\
- 582. - <table cellspacing="0" cellpadding="0"><tr>\
- 583. - <td><div class="summary_tab3">\
- 584. - <nobr>' + item[1] + '</nobr>\
- 585. - </div></td>\
- 586. - <td><div class="summary_tab_x" onmousedown="WideDropdown.deselect(\'' + id + '\', \'' + clean(sel+'') + '\', event)"></div></td>\
- 587. - </table>\
- 588. - </div>'}));
- 589. -
- 590. - val(dd.text, '');
- 591. - dd.text.blur();
- 592. - wdd._textEvent({target: dd.text, type: dd.text.focused ? 'focus' : 'blur'});
- 593. - if (dd.full) {
- 594. - hide(dd.add);
- 595. - dd.arrow.style.visibility = 'hidden';
- 596. - } else {
- 597. - wdd._updateList(dd, true);
- 598. - }
- 599. -
- 600. - var res = dd.opts.onChange ? dd.opts.onChange(1, sel) : true, noAnim = (res === 1);
- 601. - if (res !== 0) {
- 602. - setTimeout(wdd._updateImgs.pbind(dd, noAnim), 0);
- 603. - }
- 604. -
- 605. - return e && cancelEvent(e);
- 606. - },
- 607. - updimgs: function(id) {
- 608. - var dd = cur.wdd[id], res = dd.opts.onChange ? dd.opts.onChange(0) : true, noAnim = (res === 1);
- 609. - if (res !== 0) {
- 610. - setTimeout(wdd._updateImgs.pbind(dd, noAnim), 0);
- 611. - }
- 612. - },
- 613. - deselect: function(id, sel, e) {
- 614. - var dd = cur.wdd[id];
- 615. - if (sel === undefined) {
- 616. - dd.selCount = dd.full = 0;
- 617. - dd.arrow.style.visibility = 'hidden';
- 618. - for (var i in dd.selected) {
- 619. - delete(dd.selected[i]);
- 620. - }
- 621. - val(dd.bubbles, '');
- 622. - dd.text.blur();
- 623. - hide(dd.add);
- 624. - show(dd.text);
- 625. - dd.text.style.width = (dd.partWidth - dd.textDelta - 2) + 'px';
- 626. - wdd._updateList(dd, true);
- 627. - wdd._updateImgs(dd);
- 628. - } else {
- 629. - var sel_ = sel + '_';
- 630. - if (!dd.selected[sel_]) return;
- 631. -
- 632. - delete(dd.selected[sel_]);
- 633. - re('wddb' + sel_ + id);
- 634. -
- 635. - if (dd.selCount) {
- 636. - --dd.selCount;
- 637. - }
- 638. - dd.full = 0;
- 639. - dd.arrow.style.visibility = '';
- 640. -
- 641. - dd.text.blur();
- 642. - if (dd.selCount) {
- 643. - show(dd.add);
- 644. - hide(dd.text)
- 645. - } else {
- 646. - hide(dd.add);
- 647. - show(dd.text);
- 648. - wdd._updateTextInput(dd);
- 649. - }
- 650. -
- 651. - wdd._updateList(dd, true);
- 652. - }
- 653. -
- 654. - var res = dd.opts.onChange ? dd.opts.onChange(-1, sel) : true, noAnim = (res === 1);
- 655. - if (res !== 0) {
- 656. - setTimeout(wdd._updateImgs.pbind(dd, noAnim), 0);
- 657. - }
- 658. -
- 659. - if (e) return cancelEvent(e);
- 660. - },
- 661. - focus: function(id) {
- 662. - wdd._focusText(cur.wdd[id]);
- 663. - },
- 664. - clear: function(id) {
- 665. - var dd = cur.wdd[id];
- 666. - val(dd.text, '');
- 667. - dd.text.blur();
- 668. - wdd._textEvent({target: dd.text, type: dd.text.focused ? 'focus' : 'blur'});
- 669. - wdd._updateList(dd, true);
- 670. - }
- 671. - };
- 672. -
- 673. - window.WideDropdown = wdd;
- 674. - })();
- 675. -
- 676. - try {stManager.done('wide_dd.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment