select2.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487
  1. /*
  2. Copyright 2012 Igor Vaynberg
  3. Version: @@ver@@ Timestamp: @@timestamp@@
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in
  5. compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the License is
  8. distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and limitations under the License.
  10. */
  11. (function ($, undefined) {
  12. "use strict";
  13. /*global document, window, jQuery, console */
  14. if (window.Select2 !== undefined) {
  15. return;
  16. }
  17. var KEY, AbstractSelect2, SingleSelect2, MultiSelect2;
  18. KEY = {
  19. TAB: 9,
  20. ENTER: 13,
  21. ESC: 27,
  22. SPACE: 32,
  23. LEFT: 37,
  24. UP: 38,
  25. RIGHT: 39,
  26. DOWN: 40,
  27. SHIFT: 16,
  28. CTRL: 17,
  29. ALT: 18,
  30. PAGE_UP: 33,
  31. PAGE_DOWN: 34,
  32. HOME: 36,
  33. END: 35,
  34. BACKSPACE: 8,
  35. DELETE: 46,
  36. isArrow: function (k) {
  37. k = k.which ? k.which : k;
  38. switch (k) {
  39. case KEY.LEFT:
  40. case KEY.RIGHT:
  41. case KEY.UP:
  42. case KEY.DOWN:
  43. return true;
  44. }
  45. return false;
  46. },
  47. isControl: function (k) {
  48. k = k.which ? k.which : k;
  49. switch (k) {
  50. case KEY.SHIFT:
  51. case KEY.CTRL:
  52. case KEY.ALT:
  53. return true;
  54. }
  55. return false;
  56. },
  57. isFunctionKey: function (k) {
  58. k = k.which ? k.which : k;
  59. return k >= 112 && k <= 123;
  60. }
  61. };
  62. function indexOf(value, array) {
  63. var i = 0, l = array.length, v;
  64. if (value.constructor === String) {
  65. for (; i < l; i = i + 1) if (value.localeCompare(array[i]) === 0) return i;
  66. } else {
  67. for (; i < l; i = i + 1) {
  68. v = array[i];
  69. if (v.constructor === String) {
  70. if (v.localeCompare(value) === 0) return i;
  71. } else {
  72. if (v === value) return i;
  73. }
  74. }
  75. }
  76. return -1;
  77. }
  78. /**
  79. * Compares equality of a and b taking into account that a and b may be strings, in which case localCompare is used
  80. * @param a
  81. * @param b
  82. */
  83. function equal(a, b) {
  84. if (a === b) return true;
  85. if (a === undefined || b === undefined) return false;
  86. if (a === null || b === null) return false;
  87. if (a.constructor === String) return a.localeCompare(b) === 0;
  88. if (b.constructor === String) return b.localeCompare(a) === 0;
  89. return false;
  90. }
  91. /**
  92. * Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty
  93. * strings
  94. * @param string
  95. * @param separator
  96. */
  97. function splitVal(string, separator) {
  98. var val, i, l;
  99. if (string === null || string.length < 1) return [];
  100. val = string.split(separator);
  101. for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
  102. return val;
  103. }
  104. function getSideBorderPadding(element) {
  105. return element.outerWidth() - element.width();
  106. }
  107. function installKeyUpChangeEvent(element) {
  108. element.bind("keydown", function () {
  109. element.data("keyup-change-value", element.val());
  110. });
  111. element.bind("keyup", function () {
  112. if (element.val() !== element.data("keyup-change-value")) {
  113. element.trigger("keyup-change");
  114. }
  115. });
  116. }
  117. /**
  118. * filters mouse events so an event is fired only if the mouse moved.
  119. *
  120. * filters out mouse events that occur when mouse is stationary but
  121. * the elements under the pointer are scrolled.
  122. */
  123. $(document).delegate("*", "mousemove", function (e) {
  124. $(document).data("select2-lastpos", {x: e.pageX, y: e.pageY});
  125. });
  126. function installFilteredMouseMove(element) {
  127. element.bind("mousemove", function (e) {
  128. var lastpos = $(document).data("select2-lastpos");
  129. if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
  130. $(e.target).trigger("mousemove-filtered", e);
  131. }
  132. });
  133. }
  134. /**
  135. * Debounces a function. Returns a function that calls the original fn function only if no invocations have been made
  136. * within the last quietMillis milliseconds.
  137. *
  138. * @param quietMillis number of milliseconds to wait before invoking fn
  139. * @param fn function to be debounced
  140. * @return debounced version of fn
  141. */
  142. function debounce(quietMillis, fn) {
  143. var timeout;
  144. return function () {
  145. window.clearTimeout(timeout);
  146. timeout = window.setTimeout(fn, quietMillis);
  147. };
  148. }
  149. function installDebouncedScroll(threshold, element) {
  150. var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
  151. element.bind("scroll", function (e) {
  152. if (indexOf(e.target, element.get()) >= 0) notify(e);
  153. });
  154. }
  155. function killEvent(event) {
  156. event.preventDefault();
  157. event.stopPropagation();
  158. }
  159. function measureTextWidth(e) {
  160. var sizer, width;
  161. sizer = $("<div></div>").css({
  162. position: "absolute",
  163. left: "-1000px",
  164. top: "-1000px",
  165. display: "none",
  166. fontSize: e.css("fontSize"),
  167. fontFamily: e.css("fontFamily"),
  168. fontStyle: e.css("fontStyle"),
  169. fontWeight: e.css("fontWeight"),
  170. letterSpacing: e.css("letterSpacing"),
  171. textTransform: e.css("textTransform"),
  172. whiteSpace: "nowrap"
  173. });
  174. sizer.text(e.val());
  175. $("body").append(sizer);
  176. width = sizer.width();
  177. sizer.remove();
  178. return width;
  179. }
  180. /**
  181. * Produces an ajax-based query function
  182. *
  183. * @param options object containing configuration paramters
  184. * @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
  185. * @param options.url url for the data
  186. * @param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
  187. * @param options.dataType request data type: ajax, jsonp, other datatatypes supported by jQuery's $.ajax function or the transport function if specified
  188. * @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
  189. * @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
  190. * The expected format is an object containing the following keys:
  191. * results array of objects that will be used as choices
  192. * more (optional) boolean indicating whether there are more results available
  193. * Example: {results:[{id:1, text:'Red'},{id:2, text:'Blue'}], more:true}
  194. */
  195. function ajax(options) {
  196. var timeout, // current scheduled but not yet executed request
  197. requestSequence = 0, // sequence used to drop out-of-order responses
  198. handler = null,
  199. quietMillis = options.quietMillis || 100;
  200. return function (query) {
  201. window.clearTimeout(timeout);
  202. timeout = window.setTimeout(function () {
  203. requestSequence += 1; // increment the sequence
  204. var requestNumber = requestSequence, // this request's sequence number
  205. data = options.data, // ajax data function
  206. transport = options.transport || $.ajax;
  207. data = data.call(this, query.term, query.page, query.context);
  208. if( null !== handler){
  209. handler.abort();
  210. }
  211. handler = transport.call(null, {
  212. url: options.url,
  213. dataType: options.dataType,
  214. data: data,
  215. success: function (data) {
  216. if (requestNumber < requestSequence) {
  217. return;
  218. }
  219. // TODO 3.0 - replace query.page with query so users have access to term, page, etc.
  220. var results = options.results(data, query.page);
  221. self.context = results.context;
  222. query.callback(results);
  223. }
  224. });
  225. }, quietMillis);
  226. };
  227. }
  228. /**
  229. * Produces a query function that works with a local array
  230. *
  231. * @param options object containing configuration parameters. The options parameter can either be an array or an
  232. * object.
  233. *
  234. * If the array form is used it is assumed that it contains objects with 'id' and 'text' keys.
  235. *
  236. * If the object form is used ti is assumed that it contains 'data' and 'text' keys. The 'data' key should contain
  237. * an array of objects that will be used as choices. These objects must contain at least an 'id' key. The 'text'
  238. * key can either be a String in which case it is expected that each element in the 'data' array has a key with the
  239. * value of 'text' which will be used to match choices. Alternatively, text can be a function(item) that can extract
  240. * the text.
  241. */
  242. function local(options) {
  243. var data = options, // data elements
  244. text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
  245. if (!$.isArray(data)) {
  246. text = data.text;
  247. // if text is not a function we assume it to be a key name
  248. if (!$.isFunction(text)) text = function (item) { return item[data.text]; };
  249. data = data.results;
  250. }
  251. return function (query) {
  252. var t = query.term.toUpperCase(), filtered = {};
  253. if (t === "") {
  254. query.callback({results: data});
  255. return;
  256. }
  257. filtered.results = $(data)
  258. .filter(function () {return text(this).toUpperCase().indexOf(t) >= 0;})
  259. .get();
  260. query.callback(filtered);
  261. };
  262. }
  263. // TODO javadoc
  264. function tags(data) {
  265. // TODO even for a function we should probably return a wrapper that does the same object/string check as
  266. // the function for arrays. otherwise only functions that return objects are supported.
  267. if ($.isFunction(data)) {
  268. return data;
  269. }
  270. // if not a function we assume it to be an array
  271. return function (query) {
  272. var t = query.term.toUpperCase(), filtered = {results: []};
  273. $(data).each(function () {
  274. var isObject = this.text !== undefined,
  275. text = isObject ? this.text : this;
  276. if (t === "" || text.toUpperCase().indexOf(t) >= 0) {
  277. filtered.results.push(isObject ? this : {id: this, text: this});
  278. }
  279. });
  280. query.callback(filtered);
  281. };
  282. }
  283. /**
  284. * blurs any Select2 container that has focus when an element outside them was clicked or received focus
  285. */
  286. $(document).ready(function () {
  287. $(document).delegate("*", "mousedown focusin", function (e) {
  288. var target = $(e.target).closest("div.select2-container").get(0);
  289. $(document).find("div.select2-container-active").each(function () {
  290. if (this !== target) $(this).data("select2").blur();
  291. });
  292. });
  293. });
  294. /**
  295. * Creates a new class
  296. *
  297. * @param superClass
  298. * @param methods
  299. */
  300. function clazz(SuperClass, methods) {
  301. var constructor = function () {};
  302. constructor.prototype = new SuperClass;
  303. constructor.prototype.constructor = constructor;
  304. constructor.prototype.parent = SuperClass.prototype;
  305. constructor.prototype = $.extend(constructor.prototype, methods);
  306. return constructor;
  307. }
  308. AbstractSelect2 = clazz(Object, {
  309. bind: function (func) {
  310. var self = this;
  311. return function () {
  312. func.apply(self, arguments);
  313. };
  314. },
  315. init: function (opts) {
  316. var results, search, resultsSelector = ".select2-results";
  317. // prepare options
  318. this.opts = opts = this.prepareOpts(opts);
  319. this.id=opts.id;
  320. // destroy if called on an existing component
  321. if (opts.element.data("select2") !== undefined &&
  322. opts.element.data("select2") !== null) {
  323. this.destroy();
  324. }
  325. this.container = this.createContainer();
  326. if (opts.element.attr("class") !== undefined) {
  327. this.container.addClass(opts.element.attr("class"));
  328. }
  329. // swap container for the element
  330. this.opts.element
  331. .data("select2", this)
  332. .hide()
  333. .after(this.container);
  334. this.container.data("select2", this);
  335. this.dropdown = this.container.find(".select2-drop");
  336. this.results = results = this.container.find(resultsSelector);
  337. this.search = search = this.container.find("input[type=text]");
  338. this.resultsPage = 0;
  339. this.context = null;
  340. // initialize the container
  341. this.initContainer();
  342. installFilteredMouseMove(this.results);
  343. this.container.delegate(resultsSelector, "mousemove-filtered", this.bind(this.highlightUnderEvent));
  344. installDebouncedScroll(80, this.results);
  345. this.container.delegate(resultsSelector, "scroll-debounced", this.bind(this.loadMoreIfNeeded));
  346. // if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
  347. if ($.fn.mousewheel) {
  348. results.mousewheel(function (e, delta, deltaX, deltaY) {
  349. var top = results.scrollTop(), height;
  350. if (deltaY > 0 && top - deltaY <= 0) {
  351. results.scrollTop(0);
  352. killEvent(e);
  353. } else if (deltaY < 0 && results.get(0).scrollHeight - results.scrollTop() + deltaY <= results.height()) {
  354. results.scrollTop(results.get(0).scrollHeight - results.height());
  355. killEvent(e);
  356. }
  357. });
  358. }
  359. installKeyUpChangeEvent(search);
  360. search.bind("keyup-change", this.bind(this.updateResults));
  361. search.bind("focus", function () { search.addClass("select2-focused");});
  362. search.bind("blur", function () { search.removeClass("select2-focused");});
  363. this.container.delegate(resultsSelector, "click", this.bind(function (e) {
  364. if ($(e.target).closest(".select2-result:not(.select2-disabled)").length > 0) {
  365. this.highlightUnderEvent(e);
  366. this.selectHighlighted(e);
  367. } else {
  368. killEvent(e);
  369. this.focusSearch();
  370. }
  371. }));
  372. if ($.isFunction(this.opts.initSelection)) {
  373. // initialize selection based on the current value of the source element
  374. this.initSelection();
  375. // if the user has provided a function that can set selection based on the value of the source element
  376. // we monitor the change event on the element and trigger it, allowing for two way synchronization
  377. this.monitorSource();
  378. }
  379. },
  380. destroy: function () {
  381. var select2 = this.opts.element.data("select2");
  382. if (select2 !== undefined) {
  383. select2.container.remove();
  384. select2.opts.element
  385. .removeData("select2")
  386. .unbind(".select2")
  387. .show();
  388. }
  389. },
  390. prepareOpts: function (opts) {
  391. var element, select, idKey;
  392. element = opts.element;
  393. if (element.get(0).tagName.toLowerCase() === "select") {
  394. this.select = select = opts.element;
  395. }
  396. if (select) {
  397. // these options are not allowed when attached to a select because they are picked up off the element itself
  398. $.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
  399. if (this in opts) {
  400. throw new Error("Option '" + this + "' is not allowed for Select2 when attached to a <select> element.");
  401. }
  402. });
  403. }
  404. opts = $.extend({}, {
  405. formatResult: function (data) { return data.text; },
  406. formatSelection: function (data) { return data.text; },
  407. formatNoMatches: function () { return "No matches found"; },
  408. formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
  409. minimumResultsForSearch: 0,
  410. minimumInputLength: 0,
  411. id: function (e) { return e.id; }
  412. }, opts);
  413. if (typeof(opts.id) !== "function") {
  414. idKey = opts.id;
  415. opts.id = function (e) { return e[idKey]; };
  416. }
  417. if (select) {
  418. opts.query = this.bind(function (query) {
  419. var data = {results: [], more: false},
  420. term = query.term.toUpperCase(),
  421. placeholder = this.getPlaceholder();
  422. element.find("option").each(function (i) {
  423. var e = $(this),
  424. text = e.text();
  425. if (i === 0 && placeholder !== undefined && text === "") return true;
  426. if (text.toUpperCase().indexOf(term) >= 0) {
  427. data.results.push({id: e.attr("value"), text: text});
  428. }
  429. });
  430. query.callback(data);
  431. });
  432. // this is needed because inside val() we construct choices from options and there id is hardcoded
  433. opts.id=function(e) { return e.id; };
  434. } else {
  435. if (!("query" in opts)) {
  436. if ("ajax" in opts) {
  437. opts.query = ajax(opts.ajax);
  438. } else if ("data" in opts) {
  439. opts.query = local(opts.data);
  440. } else if ("tags" in opts) {
  441. opts.query = tags(opts.tags);
  442. opts.createSearchChoice = function (term) { return {id: term, text: term}; };
  443. opts.initSelection = function (element) {
  444. var data = [];
  445. $(splitVal(element.val(), ",")).each(function () {
  446. data.push({id: this, text: this});
  447. });
  448. return data;
  449. };
  450. }
  451. }
  452. }
  453. if (typeof(opts.query) !== "function") {
  454. throw "query function not defined for Select2 " + opts.element.attr("id");
  455. }
  456. return opts;
  457. },
  458. /**
  459. * Monitor the original element for changes and update select2 accordingly
  460. */
  461. monitorSource: function () {
  462. this.opts.element.bind("change.select2", this.bind(function (e) {
  463. if (this.opts.element.data("select2-change-triggered") !== true) {
  464. this.initSelection();
  465. }
  466. }));
  467. },
  468. /**
  469. * Triggers the change event on the source element
  470. */
  471. triggerChange: function () {
  472. // Prevents recursive triggering
  473. this.opts.element.data("select2-change-triggered", true);
  474. this.opts.element.trigger("change");
  475. this.opts.element.data("select2-change-triggered", false);
  476. },
  477. opened: function () {
  478. return this.container.hasClass("select2-dropdown-open");
  479. },
  480. open: function () {
  481. if (this.opened()) return;
  482. this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
  483. this.updateResults(true);
  484. this.dropdown.show();
  485. this.ensureHighlightVisible();
  486. this.focusSearch();
  487. },
  488. close: function () {
  489. if (!this.opened()) return;
  490. this.dropdown.hide();
  491. this.container.removeClass("select2-dropdown-open");
  492. this.results.empty();
  493. this.clearSearch();
  494. },
  495. clearSearch: function () {
  496. },
  497. ensureHighlightVisible: function () {
  498. var results = this.results, children, index, child, hb, rb, y, more;
  499. children = results.children(".select2-result");
  500. index = this.highlight();
  501. if (index < 0) return;
  502. child = $(children[index]);
  503. hb = child.offset().top + child.outerHeight();
  504. // if this is the last child lets also make sure select2-more-results is visible
  505. if (index === children.length - 1) {
  506. more = results.find("li.select2-more-results");
  507. if (more.length > 0) {
  508. hb = more.offset().top + more.outerHeight();
  509. }
  510. }
  511. rb = results.offset().top + results.outerHeight();
  512. if (hb > rb) {
  513. results.scrollTop(results.scrollTop() + (hb - rb));
  514. }
  515. y = child.offset().top - results.offset().top;
  516. // make sure the top of the element is visible
  517. if (y < 0) {
  518. results.scrollTop(results.scrollTop() + y); // y is negative
  519. }
  520. },
  521. moveHighlight: function (delta) {
  522. var choices = this.results.children(".select2-result"),
  523. index = this.highlight();
  524. while (index > -1 && index < choices.length) {
  525. index += delta;
  526. if (!$(choices[index]).hasClass("select2-disabled")) {
  527. this.highlight(index);
  528. break;
  529. }
  530. }
  531. },
  532. highlight: function (index) {
  533. var choices = this.results.children(".select2-result");
  534. if (arguments.length === 0) {
  535. return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
  536. }
  537. choices.removeClass("select2-highlighted");
  538. if (index >= choices.length) index = choices.length - 1;
  539. if (index < 0) index = 0;
  540. $(choices[index]).addClass("select2-highlighted");
  541. this.ensureHighlightVisible();
  542. if (this.opened()) this.focusSearch();
  543. },
  544. highlightUnderEvent: function (event) {
  545. var el = $(event.target).closest(".select2-result");
  546. if (el.length > 0) {
  547. this.highlight(el.index());
  548. }
  549. },
  550. loadMoreIfNeeded: function () {
  551. var results = this.results,
  552. more = results.find("li.select2-more-results"),
  553. below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
  554. offset = -1, // index of first element without data
  555. page = this.resultsPage + 1;
  556. if (more.length === 0) return;
  557. below = more.offset().top - results.offset().top - results.height();
  558. if (below <= 0) {
  559. more.addClass("select2-active");
  560. this.opts.query({
  561. term: this.search.val(),
  562. page: page,
  563. context: self.context,
  564. callback: this.bind(function (data) {
  565. var parts = [], self = this;
  566. $(data.results).each(function () {
  567. parts.push("<li class='select2-result'>");
  568. parts.push(self.opts.formatResult(this));
  569. parts.push("</li>");
  570. });
  571. more.before(parts.join(""));
  572. results.find(".select2-result").each(function (i) {
  573. var e = $(this);
  574. if (e.data("select2-data") !== undefined) {
  575. offset = i;
  576. } else {
  577. e.data("select2-data", data.results[i - offset - 1]);
  578. }
  579. });
  580. if (data.more) {
  581. more.removeClass("select2-active");
  582. } else {
  583. more.remove();
  584. }
  585. this.resultsPage = page;
  586. })});
  587. }
  588. },
  589. /**
  590. * @param initial whether or not this is the call to this method right after the dropdown has been opened
  591. */
  592. updateResults: function (initial) {
  593. var search = this.search, results = this.results, opts = this.opts, self=this;
  594. search.addClass("select2-active");
  595. function render(html) {
  596. results.html(html);
  597. results.scrollTop(0);
  598. search.removeClass("select2-active");
  599. }
  600. if (search.val().length < opts.minimumInputLength) {
  601. render("<li class='select2-no-results'>" + opts.formatInputTooShort(search.val(), opts.minimumInputLength) + "</li>");
  602. return;
  603. }
  604. this.resultsPage = 1;
  605. opts.query({
  606. term: search.val(),
  607. page: this.resultsPage,
  608. context: null,
  609. callback: this.bind(function (data) {
  610. var parts = [], // html parts
  611. def; // default choice
  612. // create a default choice and prepend it to the list
  613. if (this.opts.createSearchChoice && search.val() !== "") {
  614. def = this.opts.createSearchChoice.call(null, search.val(), data.results);
  615. if (def !== undefined && def !== null && self.id(def) !== undefined && self.id(def) !== null) {
  616. if ($(data.results).filter(
  617. function () {
  618. return equal(self.id(this), self.id(def));
  619. }).length === 0) {
  620. data.results.unshift(def);
  621. }
  622. }
  623. }
  624. if (data.results.length === 0) {
  625. render("<li class='select2-no-results'>" + opts.formatNoMatches(search.val()) + "</li>");
  626. return;
  627. }
  628. $(data.results).each(function () {
  629. parts.push("<li class='select2-result'>");
  630. parts.push(opts.formatResult(this));
  631. parts.push("</li>");
  632. });
  633. if (data.more === true) {
  634. parts.push("<li class='select2-more-results'>Loading more results...</li>");
  635. }
  636. render(parts.join(""));
  637. results.children(".select2-result").each(function (i) {
  638. var d = data.results[i];
  639. $(this).data("select2-data", d);
  640. });
  641. this.postprocessResults(data, initial);
  642. })});
  643. },
  644. cancel: function () {
  645. this.close();
  646. },
  647. blur: function () {
  648. /* we do this in a timeout so that current event processing can complete before this code is executed.
  649. this allows tab index to be preserved even if this code blurs the textfield */
  650. window.setTimeout(this.bind(function () {
  651. this.close();
  652. this.container.removeClass("select2-container-active");
  653. this.clearSearch();
  654. this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
  655. this.search.blur();
  656. }), 10);
  657. },
  658. focusSearch: function () {
  659. /* we do this in a timeout so that current event processing can complete before this code is executed.
  660. this makes sure the search field is focussed even if the current event would blur it */
  661. window.setTimeout(this.bind(function () {
  662. this.search.focus();
  663. }), 10);
  664. },
  665. selectHighlighted: function () {
  666. var data = this.results.find(".select2-highlighted:not(.select2-disabled)").data("select2-data");
  667. if (data) {
  668. this.onSelect(data);
  669. }
  670. },
  671. getPlaceholder: function () {
  672. return this.opts.element.attr("placeholder") || this.opts.element.data("placeholder") || this.opts.placeholder;
  673. },
  674. /**
  675. * Get the desired width for the container element. This is
  676. * derived first from option `width` passed to select2, then
  677. * the inline 'style' on the original element, and finally
  678. * falls back to the jQuery calculated element width.
  679. *
  680. * @returns The width string (with units) for the container.
  681. */
  682. getContainerWidth: function () {
  683. var style, attrs, matches, i, l;
  684. if (this.opts.width !== undefined)
  685. return this.opts.width;
  686. style = this.opts.element.attr('style');
  687. if (style !== undefined) {
  688. attrs = style.split(';');
  689. for (i = 0, l = attrs.length; i < l; i = i + 1) {
  690. matches = attrs[i].replace(/\s/g, '')
  691. .match(/width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/);
  692. if (matches !== null && matches.length >= 1)
  693. return matches[1];
  694. }
  695. }
  696. return this.opts.element.width() + 'px';
  697. }
  698. });
  699. SingleSelect2 = clazz(AbstractSelect2, {
  700. createContainer: function () {
  701. return $("<div></div>", {
  702. "class": "select2-container",
  703. "style": "width: " + this.getContainerWidth()
  704. }).html([
  705. " <a href='javascript:void(0)' class='select2-choice'>",
  706. " <span></span><abbr class='select2-search-choice-close' style='display:none;'></abbr>",
  707. " <div><b></b></div>" ,
  708. "</a>",
  709. " <div class='select2-drop' style='display:none;'>" ,
  710. " <div class='select2-search'>" ,
  711. " <input type='text' autocomplete='off'/>" ,
  712. " </div>" ,
  713. " <ul class='select2-results'>" ,
  714. " </ul>" ,
  715. "</div>"].join(""));
  716. },
  717. open: function () {
  718. if (this.opened()) return;
  719. this.parent.open.apply(this, arguments);
  720. },
  721. close: function () {
  722. if (!this.opened()) return;
  723. this.parent.close.apply(this, arguments);
  724. },
  725. focus: function () {
  726. this.close();
  727. this.selection.focus();
  728. },
  729. isFocused: function () {
  730. return this.selection.is(":focus");
  731. },
  732. cancel: function () {
  733. this.parent.cancel.apply(this, arguments);
  734. this.selection.focus();
  735. },
  736. initContainer: function () {
  737. var selection, container = this.container, clickingInside = false,
  738. selector = ".select2-choice";
  739. this.selection = selection = container.find(selector);
  740. this.search.bind("keydown", this.bind(function (e) {
  741. switch (e.which) {
  742. case KEY.UP:
  743. case KEY.DOWN:
  744. this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
  745. killEvent(e);
  746. return;
  747. case KEY.TAB:
  748. case KEY.ENTER:
  749. this.selectHighlighted();
  750. killEvent(e);
  751. return;
  752. case KEY.ESC:
  753. this.cancel(e);
  754. e.preventDefault();
  755. return;
  756. }
  757. }));
  758. container.delegate(selector, "click", this.bind(function (e) {
  759. clickingInside = true;
  760. if (this.opened()) {
  761. this.close();
  762. selection.focus();
  763. } else {
  764. this.open();
  765. }
  766. e.preventDefault();
  767. clickingInside = false;
  768. }));
  769. container.delegate(selector, "keydown", this.bind(function (e) {
  770. if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
  771. return;
  772. }
  773. this.open();
  774. if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN || e.which === KEY.SPACE) {
  775. // prevent the page from scrolling
  776. killEvent(e);
  777. }
  778. if (e.which === KEY.ENTER) {
  779. // do not propagate the event otherwise we open, and propagate enter which closes
  780. killEvent(e);
  781. }
  782. }));
  783. container.delegate(selector, "focus", function () { container.addClass("select2-container-active"); });
  784. container.delegate(selector, "blur", this.bind(function () {
  785. if (clickingInside) return;
  786. if (!this.opened()) this.blur();
  787. }));
  788. selection.delegate("abbr", "click", this.bind(function (e) {
  789. this.val("");
  790. killEvent(e);
  791. this.close();
  792. this.triggerChange();
  793. }));
  794. this.setPlaceholder();
  795. },
  796. /**
  797. * Sets selection based on source element's value
  798. */
  799. initSelection: function () {
  800. var selected;
  801. if (this.opts.element.val() === "") {
  802. this.updateSelection({id: "", text: ""});
  803. } else {
  804. selected = this.opts.initSelection.call(null, this.opts.element);
  805. if (selected !== undefined && selected !== null) {
  806. this.updateSelection(selected);
  807. }
  808. }
  809. this.close();
  810. this.setPlaceholder();
  811. },
  812. prepareOpts: function () {
  813. var opts = this.parent.prepareOpts.apply(this, arguments);
  814. if (opts.element.get(0).tagName.toLowerCase() === "select") {
  815. // install sthe selection initializer
  816. opts.initSelection = function (element) {
  817. var selected = element.find(":selected");
  818. // a single select box always has a value, no need to null check 'selected'
  819. return {id: selected.attr("value"), text: selected.text()};
  820. };
  821. }
  822. return opts;
  823. },
  824. setPlaceholder: function () {
  825. var placeholder = this.getPlaceholder();
  826. if (this.opts.element.val() === "" && placeholder !== undefined) {
  827. // check for a first blank option if attached to a select
  828. if (this.select && this.select.find("option:first").text() !== "") return;
  829. if (typeof(placeholder) === "object") {
  830. this.updateSelection(placeholder);
  831. } else {
  832. this.selection.find("span").html(placeholder);
  833. }
  834. this.selection.addClass("select2-default");
  835. this.selection.find("abbr").hide();
  836. }
  837. },
  838. postprocessResults: function (data, initial) {
  839. var selected = 0, self = this, showSearchInput = true;
  840. // find the selected element in the result list
  841. this.results.find(".select2-result").each(function (i) {
  842. if (equal(self.id($(this).data("select2-data")), self.opts.element.val())) {
  843. selected = i;
  844. return false;
  845. }
  846. });
  847. // and highlight it
  848. this.highlight(selected);
  849. // hide the search box if this is the first we got the results and there are a few of them
  850. if (initial === true) {
  851. showSearchInput = data.results.length >= this.opts.minimumResultsForSearch;
  852. this.search.parent().toggle(showSearchInput);
  853. //add "select2-with-searchbox" to the container if search box is shown
  854. this.container[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");
  855. }
  856. },
  857. onSelect: function (data) {
  858. var old = this.opts.element.val();
  859. this.opts.element.val(this.id(data));
  860. this.updateSelection(data);
  861. this.close();
  862. this.selection.focus();
  863. if (!equal(old, this.id(data))) { this.triggerChange(); }
  864. },
  865. updateSelection: function (data) {
  866. this.selection
  867. .find("span")
  868. .html(this.opts.formatSelection(data));
  869. this.selection.removeClass("select2-default");
  870. if (this.opts.allowClear && this.getPlaceholder() !== undefined) {
  871. this.selection.find("abbr").show();
  872. }
  873. },
  874. val: function () {
  875. var val, data = null;
  876. if (arguments.length === 0) {
  877. return this.opts.element.val();
  878. }
  879. val = arguments[0];
  880. if (this.select) {
  881. // val is an id
  882. this.select
  883. .val(val)
  884. .find(":selected").each(function () {
  885. data = {id: $(this).attr("value"), text: $(this).text()};
  886. return false;
  887. });
  888. this.updateSelection(data);
  889. } else {
  890. // val is an object. !val is true for [undefined,null,'']
  891. this.opts.element.val(!val ? "" : this.id(val));
  892. this.updateSelection(val);
  893. }
  894. this.setPlaceholder();
  895. },
  896. clearSearch: function () {
  897. this.search.val("");
  898. }
  899. });
  900. MultiSelect2 = clazz(AbstractSelect2, {
  901. createContainer: function () {
  902. return $("<div></div>", {
  903. "class": "select2-container select2-container-multi",
  904. "style": "width: " + this.getContainerWidth()
  905. }).html([
  906. " <ul class='select2-choices'>",
  907. //"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" ,
  908. " <li class='select2-search-field'>" ,
  909. " <input type='text' autocomplete='off' style='width: 25px;'>" ,
  910. " </li>" ,
  911. "</ul>" ,
  912. "<div class='select2-drop' style='display:none;'>" ,
  913. " <ul class='select2-results'>" ,
  914. " </ul>" ,
  915. "</div>"].join(""));
  916. },
  917. prepareOpts: function () {
  918. var opts = this.parent.prepareOpts.apply(this, arguments);
  919. opts = $.extend({}, {
  920. closeOnSelect: true
  921. }, opts);
  922. // TODO validate placeholder is a string if specified
  923. if (opts.element.get(0).tagName.toLowerCase() === "select") {
  924. // install sthe selection initializer
  925. opts.initSelection = function (element) {
  926. var data = [];
  927. element.find(":selected").each(function () {
  928. data.push({id: $(this).attr("value"), text: $(this).text()});
  929. });
  930. return data;
  931. };
  932. }
  933. return opts;
  934. },
  935. initContainer: function () {
  936. var selector = ".select2-choices", selection;
  937. this.searchContainer = this.container.find(".select2-search-field");
  938. this.selection = selection = this.container.find(selector);
  939. this.search.bind("keydown", this.bind(function (e) {
  940. if (e.which === KEY.BACKSPACE && this.search.val() === "") {
  941. this.close();
  942. var choices,
  943. selected = selection.find(".select2-search-choice-focus");
  944. if (selected.length > 0) {
  945. this.unselect(selected.first());
  946. this.search.width(10);
  947. killEvent(e);
  948. return;
  949. }
  950. choices = selection.find(".select2-search-choice");
  951. if (choices.length > 0) {
  952. choices.last().addClass("select2-search-choice-focus");
  953. }
  954. } else {
  955. selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
  956. }
  957. if (this.opened()) {
  958. switch (e.which) {
  959. case KEY.UP:
  960. case KEY.DOWN:
  961. this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
  962. killEvent(e);
  963. return;
  964. case KEY.ENTER:
  965. case KEY.TAB:
  966. this.selectHighlighted();
  967. killEvent(e);
  968. return;
  969. case KEY.ESC:
  970. this.cancel(e);
  971. e.preventDefault();
  972. return;
  973. }
  974. }
  975. if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
  976. return;
  977. }
  978. this.open();
  979. if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
  980. // prevent the page from scrolling
  981. killEvent(e);
  982. }
  983. }));
  984. this.search.bind("keyup", this.bind(this.resizeSearch));
  985. this.container.delegate(selector, "click", this.bind(function (e) {
  986. this.open();
  987. this.focusSearch();
  988. e.preventDefault();
  989. }));
  990. this.container.delegate(selector, "focus", this.bind(function () {
  991. this.container.addClass("select2-container-active");
  992. this.clearPlaceholder();
  993. }));
  994. // set the placeholder if necessary
  995. this.clearSearch();
  996. },
  997. initSelection: function () {
  998. var data;
  999. if (this.opts.element.val() === "") {
  1000. this.updateSelection([]);
  1001. }
  1002. if (this.select || this.opts.element.val() !== "") {
  1003. data = this.opts.initSelection.call(null, this.opts.element);
  1004. if (data !== undefined && data !== null) {
  1005. this.updateSelection(data);
  1006. }
  1007. }
  1008. this.close();
  1009. // set the placeholder if necessary
  1010. this.clearSearch();
  1011. },
  1012. clearSearch: function () {
  1013. var placeholder = this.getPlaceholder();
  1014. if (placeholder !== undefined
  1015. && this.getVal().length === 0
  1016. && this.search.hasClass("select2-focused") === false) {
  1017. this.search.val(placeholder).addClass("select2-default");
  1018. // stretch the search box to full width of the container so as much of the placeholder is visible as possible
  1019. this.search.width(this.getContainerWidth());
  1020. } else {
  1021. this.search.val("").width(10);
  1022. }
  1023. },
  1024. clearPlaceholder: function () {
  1025. if (this.search.hasClass("select2-default")) {
  1026. this.search.val("").removeClass("select2-default");
  1027. }
  1028. },
  1029. open: function () {
  1030. if (this.opened()) return;
  1031. this.parent.open.apply(this, arguments);
  1032. this.resizeSearch();
  1033. this.focusSearch();
  1034. },
  1035. close: function () {
  1036. if (!this.opened()) return;
  1037. this.parent.close.apply(this, arguments);
  1038. },
  1039. focus: function () {
  1040. this.close();
  1041. this.search.focus();
  1042. },
  1043. isFocused: function () {
  1044. return this.search.hasClass("select2-focused");
  1045. },
  1046. updateSelection: function (data) {
  1047. var ids = [], filtered = [], self = this;
  1048. // filter out duplicates
  1049. $(data).each(function () {
  1050. if (indexOf(self.id(this), ids) < 0) {
  1051. ids.push(self.id(this));
  1052. filtered.push(this);
  1053. }
  1054. });
  1055. data = filtered;
  1056. this.selection.find(".select2-search-choice").remove();
  1057. $(data).each(function () {
  1058. self.addSelectedChoice(this);
  1059. });
  1060. self.postprocessResults();
  1061. },
  1062. onSelect: function (data) {
  1063. this.addSelectedChoice(data);
  1064. if (this.select) { this.postprocessResults(); }
  1065. if (this.opts.closeOnSelect) {
  1066. this.close();
  1067. this.search.width(10);
  1068. } else {
  1069. this.search.width(10);
  1070. this.resizeSearch();
  1071. }
  1072. // since its not possible to select an element that has already been
  1073. // added we do not need to check if this is a new element before firing change
  1074. this.triggerChange();
  1075. this.focusSearch();
  1076. },
  1077. cancel: function () {
  1078. this.close();
  1079. this.focusSearch();
  1080. },
  1081. addSelectedChoice: function (data) {
  1082. var choice,
  1083. id = this.id(data),
  1084. parts,
  1085. val = this.getVal();
  1086. parts = ["<li class='select2-search-choice'>",
  1087. this.opts.formatSelection(data),
  1088. "<a href='javascript:void(0)' class='select2-search-choice-close' tabindex='-1'></a>",
  1089. "</li>"
  1090. ];
  1091. choice = $(parts.join(""));
  1092. choice.find("a")
  1093. .bind("click dblclick", this.bind(function (e) {
  1094. this.unselect($(e.target));
  1095. this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
  1096. killEvent(e);
  1097. this.close();
  1098. this.focusSearch();
  1099. })).bind("focus", this.bind(function () {
  1100. this.container.addClass("select2-container-active");
  1101. }));
  1102. choice.data("select2-data", data);
  1103. choice.insertBefore(this.searchContainer);
  1104. val.push(id);
  1105. this.setVal(val);
  1106. },
  1107. unselect: function (selected) {
  1108. var val = this.getVal(),
  1109. index;
  1110. selected = selected.closest(".select2-search-choice");
  1111. if (selected.length === 0) {
  1112. throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
  1113. }
  1114. index = indexOf(this.id(selected.data("select2-data")), val);
  1115. if (index >= 0) {
  1116. val.splice(index, 1);
  1117. this.setVal(val);
  1118. if (this.select) this.postprocessResults();
  1119. }
  1120. selected.remove();
  1121. this.triggerChange();
  1122. },
  1123. postprocessResults: function () {
  1124. var val = this.getVal(),
  1125. choices = this.results.find(".select2-result"),
  1126. self = this;
  1127. choices.each(function () {
  1128. var choice = $(this), id = self.id(choice.data("select2-data"));
  1129. if (indexOf(id, val) >= 0) {
  1130. choice.addClass("select2-disabled");
  1131. } else {
  1132. choice.removeClass("select2-disabled");
  1133. }
  1134. });
  1135. choices.each(function (i) {
  1136. if (!$(this).hasClass("select2-disabled")) {
  1137. self.highlight(i);
  1138. return false;
  1139. }
  1140. });
  1141. },
  1142. resizeSearch: function () {
  1143. var minimumWidth, left, maxWidth, containerLeft, searchWidth;
  1144. minimumWidth = measureTextWidth(this.search) + 10;
  1145. left = this.search.offset().left;
  1146. maxWidth = this.selection.width();
  1147. containerLeft = this.selection.offset().left;
  1148. searchWidth = maxWidth - (left - containerLeft) - getSideBorderPadding(this.search);
  1149. if (searchWidth < minimumWidth) {
  1150. searchWidth = maxWidth - getSideBorderPadding(this.search);
  1151. }
  1152. if (searchWidth < 40) {
  1153. searchWidth = maxWidth - getSideBorderPadding(this.search);
  1154. }
  1155. this.search.width(searchWidth);
  1156. },
  1157. getVal: function () {
  1158. var val;
  1159. if (this.select) {
  1160. val = this.select.val();
  1161. return val === null ? [] : val;
  1162. } else {
  1163. val = this.opts.element.val();
  1164. return splitVal(val, ",");
  1165. }
  1166. },
  1167. setVal: function (val) {
  1168. var unique = [];
  1169. if (this.select) {
  1170. this.select.val(val);
  1171. } else {
  1172. // filter out duplicates
  1173. $(val).each(function () {
  1174. if (indexOf(this, unique) < 0) unique.push(this);
  1175. });
  1176. this.opts.element.val(unique.length === 0 ? "" : unique.join(","));
  1177. }
  1178. },
  1179. val: function () {
  1180. var val, data = [], self=this;
  1181. if (arguments.length === 0) {
  1182. return this.getVal();
  1183. }
  1184. val = arguments[0];
  1185. if (this.select) {
  1186. // val is a list of ids
  1187. this.setVal(val);
  1188. this.select.find(":selected").each(function () {
  1189. data.push({id: $(this).attr("value"), text: $(this).text()});
  1190. });
  1191. this.updateSelection(data);
  1192. } else {
  1193. val = (val === null) ? [] : val;
  1194. this.setVal(val);
  1195. // val is a list of objects
  1196. $(val).each(function () { data.push(self.id(this)); });
  1197. this.setVal(data);
  1198. this.updateSelection(val);
  1199. }
  1200. this.clearSearch();
  1201. }
  1202. });
  1203. $.fn.select2 = function () {
  1204. var args = Array.prototype.slice.call(arguments, 0),
  1205. opts,
  1206. select2,
  1207. value, multiple, allowedMethods = ["val", "destroy", "open", "close", "focus", "isFocused"];
  1208. this.each(function () {
  1209. if (args.length === 0 || typeof(args[0]) === "object") {
  1210. opts = args.length === 0 ? {} : $.extend({}, args[0]);
  1211. opts.element = $(this);
  1212. if (opts.element.get(0).tagName.toLowerCase() === "select") {
  1213. multiple = opts.element.attr("multiple");
  1214. } else {
  1215. multiple = opts.multiple || false;
  1216. if ("tags" in opts) {opts.multiple = multiple = true;}
  1217. }
  1218. select2 = multiple ? new MultiSelect2() : new SingleSelect2();
  1219. select2.init(opts);
  1220. } else if (typeof(args[0]) === "string") {
  1221. if (indexOf(args[0], allowedMethods) < 0) {
  1222. throw "Unknown method: " + args[0];
  1223. }
  1224. value = undefined;
  1225. select2 = $(this).data("select2");
  1226. if (select2 === undefined) return;
  1227. value = select2[args[0]].apply(select2, args.slice(1));
  1228. if (value !== undefined) {return false;}
  1229. } else {
  1230. throw "Invalid arguments to select2 plugin: " + args;
  1231. }
  1232. });
  1233. return (value === undefined) ? this : value;
  1234. };
  1235. // exports
  1236. window.Select2 = {
  1237. query: {
  1238. ajax: ajax,
  1239. local: local,
  1240. tags: tags
  1241. }, util: {
  1242. debounce: debounce
  1243. }, "class": {
  1244. "abstract": AbstractSelect2,
  1245. "single": SingleSelect2,
  1246. "multi": MultiSelect2
  1247. }
  1248. };
  1249. }(jQuery));