Hormold

VK Change (#1378542603)

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