jquery.sumoselect.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /*!
  2. * jquery.sumoselect - v3.0.2
  3. * http://hemantnegi.github.io/jquery.sumoselect
  4. * 2014-04-08
  5. *
  6. * Copyright 2015 Hemant Negi
  7. * Email : hemant.frnz@gmail.com
  8. * Compressor http://refresh-sf.com/
  9. */
  10. (function ($) {
  11. 'namespace sumo';
  12. $.fn.SumoSelect = function (options) {
  13. // This is the easiest way to have default options.
  14. var settings = $.extend({
  15. placeholder: 'Select Here', // Dont change it here.
  16. csvDispCount: 3, // display no. of items in multiselect. 0 to display all.
  17. captionFormat:'{0} Selected', // format of caption text. you can set your locale.
  18. captionFormatAllSelected:'{0} all selected!', // format of caption text when all elements are selected. set null to use captionFormat. It will not work if there are disabled elements in select.
  19. floatWidth: 400, // Screen width of device at which the list is rendered in floating popup fashion.
  20. forceCustomRendering: false, // force the custom modal on all devices below floatWidth resolution.
  21. nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'], //
  22. outputAsCSV: false, // true to POST data as csv ( false for Html control array ie. default select )
  23. csvSepChar: ',', // separation char in csv mode
  24. okCancelInMulti: false, // display ok cancel buttons in desktop mode multiselect also.
  25. triggerChangeCombined: true, // im multi select mode wether to trigger change event on individual selection or combined selection.
  26. selectAll: false, // to display select all button in multiselect mode.|| also select all will not be available on mobile devices.
  27. search: false, // to display input for filtering content. selectAlltext will be input text placeholder
  28. searchText: 'Search...', // placeholder for search input
  29. noMatch: 'No matches for "{0}"',
  30. prefix: '', // some prefix usually the field name. eg. '<b>Hello</b>'
  31. locale: ['OK', 'Cancel', 'Select All'], // all text that is used. don't change the index.
  32. up: false // set true to open upside.
  33. }, options);
  34. var ret = this.each(function () {
  35. var selObj = this; // the original select object.
  36. if (this.sumo || !$(this).is('select')) return; //already initialized
  37. this.sumo = {
  38. E: $(selObj), //the jquery object of original select element.
  39. is_multi: $(selObj).attr('multiple'), //if its a multiple select
  40. select: '',
  41. caption: '',
  42. placeholder: '',
  43. optDiv: '',
  44. CaptionCont: '',
  45. ul:'',
  46. is_floating: false,
  47. is_opened: false,
  48. //backdrop: '',
  49. mob:false, // if to open device default select
  50. Pstate: [],
  51. createElems: function () {
  52. var O = this;
  53. O.E.wrap('<div class="SumoSelect" tabindex="0">');
  54. O.select = O.E.parent();
  55. O.caption = $('<span>');
  56. O.CaptionCont = $('<p class="CaptionCont"><label><i></i></label></p>').addClass('SelectBox').attr('style', O.E.attr('style')).prepend(O.caption);
  57. O.select.append(O.CaptionCont);
  58. // default turn off if no multiselect
  59. if(!O.is_multi)settings.okCancelInMulti = false
  60. if(O.E.attr('disabled'))
  61. O.select.addClass('disabled').removeAttr('tabindex');
  62. //if output as csv and is a multiselect.
  63. if (settings.outputAsCSV && O.is_multi && O.E.attr('name')) {
  64. //create a hidden field to store csv value.
  65. O.select.append($('<input class="HEMANT123" type="hidden" />').attr('name', O.E.attr('name')).val(O.getSelStr()));
  66. // so it can not post the original select.
  67. O.E.removeAttr('name');
  68. }
  69. //break for mobile rendring.. if forceCustomRendering is false
  70. if (O.isMobile() && !settings.forceCustomRendering) {
  71. O.setNativeMobile();
  72. return;
  73. }
  74. // if there is a name attr in select add a class to container div
  75. if(O.E.attr('name')) O.select.addClass('sumo_'+O.E.attr('name'))
  76. //hide original select
  77. O.E.addClass('SumoUnder').attr('tabindex','-1');
  78. //## Creating the list...
  79. O.optDiv = $('<div class="optWrapper '+ (settings.up?'up':'') +'">');
  80. //branch for floating list in low res devices.
  81. O.floatingList();
  82. //Creating the markup for the available options
  83. O.ul = $('<ul class="options">');
  84. O.optDiv.append(O.ul);
  85. // Select all functionality
  86. if(settings.selectAll) O.SelAll();
  87. // search functionality
  88. if(settings.search) O.Search();
  89. O.ul.append(O.prepItems(O.E.children()));
  90. //if multiple then add the class multiple and add OK / CANCEL button
  91. if (O.is_multi) O.multiSelelect();
  92. O.select.append(O.optDiv);
  93. O.basicEvents();
  94. O.selAllState();
  95. },
  96. prepItems: function(opts, d){
  97. var lis = [], O=this;
  98. $(opts).each(function (i, opt) { // parsing options to li
  99. opt = $(opt);
  100. lis.push(opt.is('optgroup')?
  101. $('<li class="group '+ (opt[0].disabled?'disabled':'') +'"><label>' + opt.attr('label') +'</label><ul></ul><li>')
  102. .find('ul')
  103. .append(O.prepItems(opt.children(), opt[0].disabled))
  104. .end()
  105. :
  106. O.createLi(opt, d)
  107. );
  108. });
  109. return lis;
  110. },
  111. //## Creates a LI element from a given option and binds events to it
  112. //## returns the jquery instance of li (not inserted in dom)
  113. createLi: function (opt, d) {
  114. var O = this;
  115. if(!opt.attr('value'))opt.attr('value',opt.val());
  116. // todo: remove this data val
  117. li = $('<li class="opt"><label>' + opt.text() + '</label></li>');//.data('val',opt.val());
  118. li.data('opt', opt); // store a direct reference to option.
  119. opt.data('li', li); // store a direct reference to list item.
  120. if (O.is_multi) li.prepend('<span><i></i></span>');
  121. if (opt[0].disabled || d)
  122. li = li.addClass('disabled');
  123. O.onOptClick(li);
  124. if (opt[0].selected)
  125. li.addClass('selected');
  126. if (opt.attr('class'))
  127. li.addClass(opt.attr('class'));
  128. return li;
  129. },
  130. //## Returns the selected items as string in a Multiselect.
  131. getSelStr: function () {
  132. // get the pre selected items.
  133. sopt = [];
  134. this.E.find('option:selected').each(function () { sopt.push($(this).val()); });
  135. return sopt.join(settings.csvSepChar);
  136. },
  137. //## THOSE OK/CANCEL BUTTONS ON MULTIPLE SELECT.
  138. multiSelelect: function () {
  139. var O = this;
  140. O.optDiv.addClass('multiple');
  141. O.okbtn = $('<p class="btnOk">'+settings.locale[0]+'</p>').click(function () {
  142. //if combined change event is set.
  143. if (settings.triggerChangeCombined) {
  144. //check for a change in the selection.
  145. changed = false;
  146. if (O.E.find('option:selected').length != O.Pstate.length) {
  147. changed = true;
  148. }
  149. else {
  150. O.E.find('option').each(function (i,e) {
  151. if(e.selected && O.Pstate.indexOf(i) < 0) changed = true;
  152. });
  153. }
  154. if (changed) {
  155. O.callChange();
  156. O.setText();
  157. }
  158. }
  159. O.hideOpts();
  160. });
  161. O.cancelBtn = $('<p class="btnCancel">'+settings.locale[1]+'</p>').click(function () {
  162. O._cnbtn();
  163. O.hideOpts();
  164. });
  165. O.optDiv.append($('<div class="MultiControls">').append(O.okbtn).append(O.cancelBtn));
  166. },
  167. _cnbtn:function(){
  168. var O = this;
  169. //remove all selections
  170. O.E.find('option:selected').each(function () { this.selected = false; });
  171. O.optDiv.find('li.selected').removeClass('selected')
  172. //restore selections from saved state.
  173. for(var i = 0; i < O.Pstate.length; i++) {
  174. O.E.find('option')[O.Pstate[i]].selected = true;
  175. O.ul.find('li.opt').eq(O.Pstate[i]).addClass('selected');
  176. }
  177. O.selAllState();
  178. },
  179. SelAll:function(){
  180. var O = this;
  181. if(!O.is_multi)return;
  182. O.selAll = $('<p class="select-all"><span><i></i></span><label>' + settings.locale[2] + '</label></p>');
  183. O.selAll.on('click',function(){
  184. //O.toggSelAll(!);
  185. O.selAll.toggleClass('selected');
  186. O.optDiv.find('li.opt').not('.hidden').each(function(ix,e){
  187. e = $(e);
  188. if(O.selAll.hasClass('selected')){
  189. if(!e.hasClass('selected'))e.trigger('click');
  190. }
  191. else
  192. if(e.hasClass('selected'))e.trigger('click');
  193. });
  194. });
  195. O.optDiv.prepend(O.selAll);
  196. },
  197. // search module (can be removed if not required.)
  198. Search: function(){
  199. var O = this,
  200. cc = O.CaptionCont.addClass('search'),
  201. P = $('<p class="no-match">');
  202. O.ftxt = $('<input type="text" class="search-txt" value="" placeholder="' + settings.searchText + '">')
  203. .on('click', function(e){
  204. e.stopPropagation();
  205. });
  206. cc.append(O.ftxt);
  207. O.optDiv.children('ul').after(P);
  208. O.ftxt.on('keyup.sumo',function(){
  209. var hid = O.optDiv.find('ul.options li.opt').each(function(ix,e){
  210. e = $(e);
  211. if(e.text().toLowerCase().indexOf(O.ftxt.val().toLowerCase()) > -1)
  212. e.removeClass('hidden');
  213. else
  214. e.addClass('hidden');
  215. }).not('.hidden');
  216. P.html(settings.noMatch.replace(/\{0\}/g, O.ftxt.val())).toggle(!hid.length);
  217. O.selAllState();
  218. });
  219. },
  220. selAllState: function () {
  221. var O = this;
  222. if (settings.selectAll) {
  223. var sc = 0, vc = 0;
  224. O.optDiv.find('li.opt').not('.hidden').each(function (ix, e) {
  225. if ($(e).hasClass('selected')) sc++;
  226. if (!$(e).hasClass('disabled')) vc++;
  227. });
  228. //select all checkbox state change.
  229. if (sc == vc) O.selAll.removeClass('partial').addClass('selected');
  230. else if (sc == 0) O.selAll.removeClass('selected partial');
  231. else O.selAll.addClass('partial')//.removeClass('selected');
  232. }
  233. },
  234. showOpts: function () {
  235. var O = this;
  236. if (O.E.attr('disabled')) return; // if select is disabled then retrun
  237. O.is_opened = true;
  238. O.select.addClass('open');
  239. if(O.ftxt)O.ftxt.focus();
  240. else O.select.focus();
  241. // hide options on click outside.
  242. $(document).on('click.sumo', function (e) {
  243. if (!O.select.is(e.target) // if the target of the click isn't the container...
  244. && O.select.has(e.target).length === 0){ // ... nor a descendant of the container
  245. if(!O.is_opened)return;
  246. O.hideOpts();
  247. if (settings.okCancelInMulti)O._cnbtn();
  248. }
  249. });
  250. if (O.is_floating) {
  251. H = O.optDiv.children('ul').outerHeight() + 2; // +2 is clear fix
  252. if (O.is_multi) H = H + parseInt(O.optDiv.css('padding-bottom'));
  253. O.optDiv.css('height', H);
  254. $('body').addClass('sumoStopScroll');
  255. }
  256. O.setPstate();
  257. },
  258. //maintain state when ok/cancel buttons are available storing the indexes.
  259. setPstate: function(){
  260. var O = this;
  261. if (O.is_multi && (O.is_floating || settings.okCancelInMulti)){
  262. O.Pstate = [];
  263. // assuming that find returns elements in tree order
  264. O.E.find('option').each(function (i, e){if(e.selected) O.Pstate.push(i);});
  265. }
  266. },
  267. callChange:function(){
  268. this.E.trigger('change').trigger('click');
  269. },
  270. hideOpts: function () {
  271. var O = this;
  272. if(O.is_opened){
  273. O.is_opened = false;
  274. O.select.removeClass('open').find('ul li.sel').removeClass('sel');
  275. $(document).off('click.sumo');
  276. O.select.focus();
  277. $('body').removeClass('sumoStopScroll');
  278. // clear the search
  279. if(settings.search){
  280. O.ftxt.val('');
  281. O.optDiv.find('ul.options li').removeClass('hidden');
  282. O.optDiv.find('.no-match').toggle(false);
  283. }
  284. }
  285. },
  286. setOnOpen: function () {
  287. var O = this,
  288. li = O.optDiv.find('li.opt:not(.hidden)').eq(settings.search?0:O.E[0].selectedIndex);
  289. O.optDiv.find('li.sel').removeClass('sel');
  290. li.addClass('sel');
  291. O.showOpts();
  292. },
  293. nav: function (up) {
  294. var O = this, c,
  295. s=O.ul.find('li.opt:not(.disabled, .hidden)'),
  296. sel = O.ul.find('li.opt.sel:not(.hidden)'),
  297. idx = s.index(sel);
  298. if (O.is_opened && sel.length) {
  299. if (up && idx > 0)
  300. c = s.eq(idx-1);
  301. else if(!up && idx < s.length-1 && idx > -1)
  302. c = s.eq(idx+1);
  303. else return; // if no items before or after
  304. sel.removeClass('sel');
  305. sel = c.addClass('sel');
  306. // setting sel item to visible view.
  307. var ul = O.ul,
  308. st = ul.scrollTop(),
  309. t = sel.position().top + st;
  310. if(t >= st + ul.height()-sel.outerHeight())
  311. ul.scrollTop(t - ul.height() + sel.outerHeight());
  312. if(t<st)
  313. ul.scrollTop(t);
  314. }
  315. else
  316. O.setOnOpen();
  317. },
  318. basicEvents: function () {
  319. var O = this;
  320. O.CaptionCont.click(function (evt) {
  321. O.E.trigger('click');
  322. if (O.is_opened) O.hideOpts(); else O.showOpts();
  323. evt.stopPropagation();
  324. });
  325. O.select.on('keydown.sumo', function (e) {
  326. switch (e.which) {
  327. case 38: // up
  328. O.nav(true);
  329. break;
  330. case 40: // down
  331. O.nav(false);
  332. break;
  333. case 32: // space
  334. if(settings.search && O.ftxt.is(e.target))return;
  335. case 13: // enter
  336. if (O.is_opened)
  337. O.optDiv.find('ul li.sel').trigger('click');
  338. else
  339. O.setOnOpen();
  340. break;
  341. case 9: //tab
  342. case 27: // esc
  343. if (settings.okCancelInMulti)O._cnbtn();
  344. O.hideOpts();
  345. return;
  346. default:
  347. return; // exit this handler for other keys
  348. }
  349. e.preventDefault(); // prevent the default action (scroll / move caret)
  350. });
  351. $(window).on('resize.sumo', function () {
  352. O.floatingList();
  353. });
  354. },
  355. onOptClick: function (li) {
  356. var O = this;
  357. li.click(function () {
  358. var li = $(this);
  359. if(li.hasClass('disabled'))return;
  360. txt = "";
  361. if (O.is_multi) {
  362. li.toggleClass('selected');
  363. li.data('opt')[0].selected = li.hasClass('selected');
  364. O.selAllState();
  365. }
  366. else {
  367. li.parent().find('li.selected').removeClass('selected'); //if not multiselect then remove all selections from this list
  368. li.toggleClass('selected');
  369. li.data('opt')[0].selected = true;
  370. }
  371. //branch for combined change event.
  372. if (!(O.is_multi && settings.triggerChangeCombined && (O.is_floating || settings.okCancelInMulti))) {
  373. O.setText();
  374. O.callChange();
  375. }
  376. if (!O.is_multi) O.hideOpts(); //if its not a multiselect then hide on single select.
  377. });
  378. },
  379. setText: function () {
  380. var O = this;
  381. O.placeholder = "";
  382. if (O.is_multi) {
  383. sels = O.E.find(':selected').not(':disabled'); //selected options.
  384. for (i = 0; i < sels.length; i++) {
  385. if (i + 1 >= settings.csvDispCount && settings.csvDispCount) {
  386. if (sels.length == O.E.find('option').length && settings.captionFormatAllSelected) {
  387. O.placeholder = settings.captionFormatAllSelected.replace(/\{0\}/g, sels.length)+',';
  388. } else {
  389. O.placeholder = settings.captionFormat.replace(/\{0\}/g, sels.length)+',';
  390. }
  391. break;
  392. }
  393. else O.placeholder += $(sels[i]).text() + ", ";
  394. }
  395. O.placeholder = O.placeholder.replace(/,([^,]*)$/, '$1'); //remove unexpected "," from last.
  396. }
  397. else {
  398. O.placeholder = O.E.find(':selected').not(':disabled').text();
  399. }
  400. is_placeholder = false;
  401. if (!O.placeholder) {
  402. is_placeholder = true;
  403. O.placeholder = O.E.attr('placeholder');
  404. if (!O.placeholder) //if placeholder is there then set it
  405. O.placeholder = O.E.find('option:disabled:selected').text();
  406. }
  407. O.placeholder = O.placeholder ? (settings.prefix + ' ' + O.placeholder) : settings.placeholder
  408. //set display text
  409. O.caption.html(O.placeholder);
  410. O.CaptionCont.attr('title', O.placeholder);
  411. //set the hidden field if post as csv is true.
  412. csvField = O.select.find('input.HEMANT123');
  413. if (csvField.length) csvField.val(O.getSelStr());
  414. //add class placeholder if its a placeholder text.
  415. if (is_placeholder) O.caption.addClass('placeholder'); else O.caption.removeClass('placeholder');
  416. return O.placeholder;
  417. },
  418. isMobile: function () {
  419. // Adapted from http://www.detectmobilebrowsers.com
  420. var ua = navigator.userAgent || navigator.vendor || window.opera;
  421. // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
  422. for (var i = 0; i < settings.nativeOnDevice.length; i++) if (ua.toString().toLowerCase().indexOf(settings.nativeOnDevice[i].toLowerCase()) > 0) return settings.nativeOnDevice[i];
  423. return false;
  424. },
  425. setNativeMobile: function () {
  426. var O = this;
  427. O.E.addClass('SelectClass')//.css('height', O.select.outerHeight());
  428. O.mob = true;
  429. O.E.change(function () {
  430. O.setText();
  431. });
  432. },
  433. floatingList: function () {
  434. var O = this;
  435. //called on init and also on resize.
  436. //O.is_floating = true if window width is < specified float width
  437. O.is_floating = $(window).width() <= settings.floatWidth;
  438. //set class isFloating
  439. O.optDiv.toggleClass('isFloating', O.is_floating);
  440. //remove height if not floating
  441. if (!O.is_floating) O.optDiv.css('height', '');
  442. //toggle class according to okCancelInMulti flag only when it is not floating
  443. O.optDiv.toggleClass('okCancelInMulti', settings.okCancelInMulti && !O.is_floating);
  444. },
  445. //HELPERS FOR OUTSIDERS
  446. // validates range of given item operations
  447. vRange: function (i) {
  448. var O = this;
  449. opts = O.E.find('option');
  450. if (opts.length <= i || i < 0) throw "index out of bounds"
  451. return O;
  452. },
  453. //toggles selection on c as boolean.
  454. toggSel: function (c, i) {
  455. var O = this;
  456. if (typeof(i) === "number"){
  457. O.vRange(i);
  458. opt = O.E.find('option')[i];
  459. }
  460. else{
  461. opt = O.E.find('option[value="'+i+'"]')[0]||0;
  462. }
  463. if (!opt || opt.disabled)
  464. return;
  465. if(opt.selected != c){
  466. opt.selected = c;
  467. if(!O.mob) $(opt).data('li').toggleClass('selected',c);
  468. O.callChange();
  469. O.setPstate();
  470. O.setText();
  471. O.selAllState();
  472. }
  473. },
  474. //toggles disabled on c as boolean.
  475. toggDis: function (c, i) {
  476. var O = this.vRange(i);
  477. O.E.find('option')[i].disabled = c;
  478. if(c)O.E.find('option')[i].selected = false;
  479. if(!O.mob)O.optDiv.find('ul.options li').eq(i).toggleClass('disabled', c).removeClass('selected');
  480. O.setText();
  481. },
  482. // toggle disable/enable on complete select control
  483. toggSumo: function(val) {
  484. var O = this;
  485. O.enabled = val;
  486. O.select.toggleClass('disabled', val);
  487. if (val) {
  488. O.E.attr('disabled', 'disabled');
  489. O.select.removeAttr('tabindex');
  490. }
  491. else{
  492. O.E.removeAttr('disabled');
  493. O.select.attr('tabindex','0');
  494. }
  495. return O;
  496. },
  497. //toggles alloption on c as boolean.
  498. toggSelAll: function (c) {
  499. var O = this;
  500. O.E.find('option').each(function (ix, el) {
  501. if (O.E.find('option')[$(this).index()].disabled) return;
  502. O.E.find('option')[$(this).index()].selected = c;
  503. if (!O.mob)
  504. O.optDiv.find('ul.options li').eq($(this).index()).toggleClass('selected', c);
  505. O.setText();
  506. });
  507. if(!O.mob && O.selAll)O.selAll.removeClass('partial').toggleClass('selected',c);
  508. O.callChange();
  509. O.setPstate();
  510. },
  511. /* outside accessibility options
  512. which can be accessed from the element instance.
  513. */
  514. reload:function(){
  515. var elm = this.unload();
  516. return $(elm).SumoSelect(settings);
  517. },
  518. unload: function () {
  519. var O = this;
  520. O.select.before(O.E);
  521. O.E.show();
  522. if (settings.outputAsCSV && O.is_multi && O.select.find('input.HEMANT123').length) {
  523. O.E.attr('name', O.select.find('input.HEMANT123').attr('name')); // restore the name;
  524. }
  525. O.select.remove();
  526. delete selObj.sumo;
  527. return selObj;
  528. },
  529. //## add a new option to select at a given index.
  530. add: function (val, txt, i) {
  531. if (typeof val == "undefined") throw "No value to add"
  532. var O = this;
  533. opts=O.E.find('option')
  534. if (typeof txt == "number") { i = txt; txt = val; }
  535. if (typeof txt == "undefined") { txt = val; }
  536. opt = $("<option></option>").val(val).html(txt);
  537. if (opts.length < i) throw "index out of bounds"
  538. if (typeof i == "undefined" || opts.length == i) { // add it to the last if given index is last no or no index provides.
  539. O.E.append(opt);
  540. if(!O.mob)O.ul.append(O.createLi(opt));
  541. }
  542. else {
  543. opts.eq(i).before(opt);
  544. if(!O.mob)O.ul.find('li.opt').eq(i).before(O.createLi(opt));
  545. }
  546. return selObj;
  547. },
  548. //## removes an item at a given index.
  549. remove: function (i) {
  550. var O = this.vRange(i);
  551. O.E.find('option').eq(i).remove();
  552. if(!O.mob)O.optDiv.find('ul.options li').eq(i).remove();
  553. O.setText();
  554. },
  555. //## Select an item at a given index.
  556. selectItem: function (i) { this.toggSel(true, i); },
  557. //## UnSelect an iten at a given index.
  558. unSelectItem: function (i) { this.toggSel(false, i); },
  559. //## Select all items of the select.
  560. selectAll: function () { this.toggSelAll(true); },
  561. //## UnSelect all items of the select.
  562. unSelectAll: function () { this.toggSelAll(false); },
  563. //## Disable an iten at a given index.
  564. disableItem: function (i) { this.toggDis(true, i) },
  565. //## Removes disabled an iten at a given index.
  566. enableItem: function (i) { this.toggDis(false, i) },
  567. //## New simple methods as getter and setter are not working fine in ie8-
  568. //## variable to check state of control if enabled or disabled.
  569. enabled : true,
  570. //## Enables the control
  571. enable: function(){return this.toggSumo(false)},
  572. //## Disables the control
  573. disable: function(){return this.toggSumo(true)},
  574. init: function () {
  575. var O = this;
  576. O.createElems();
  577. O.setText();
  578. return O
  579. }
  580. };
  581. selObj.sumo.init();
  582. });
  583. return ret.length == 1 ? ret[0] : ret;
  584. };
  585. }(jQuery));