1/*! 2 * jquery.sumoselect - v3.0.3 3 * http://hemantnegi.github.io/jquery.sumoselect 4 * 2016-12-12 5 * 6 * Copyright 2015 Hemant Negi 7 * Email : [email protected] 8 * Compressor http://refresh-sf.com/ 9 */ 10 11(function (factory) { 12 'use strict'; 13 if (typeof define === 'function' && define.amd) { 14 define(['jquery'], factory); 15 } else if (typeof exports !== 'undefined') { 16 module.exports = factory(require('jquery')); 17 } else { 18 factory(jQuery); 19 } 20 21})(function ($) { 22 23 'namespace sumo'; 24 $.fn.SumoSelect = function (options) { 25 const i18n = window.ninja_footables.i18n 26 // This is the easiest way to have default options. 27 var settings = $.extend({ 28 placeholder: 'Select Here', // Dont change it here. 29 csvDispCount: 2, // display no. of items in multiselect. 0 to display all. 30 captionFormat: `{0} ${i18n.caption_format}`, // format of caption text. you can set your locale. 31 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. 32 floatWidth: 400, // Screen width of device at which the list is rendered in floating popup fashion. 33 forceCustomRendering: true, // force the custom modal on all devices below floatWidth resolution. 34 nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'], // 35 outputAsCSV: false, // true to POST data as csv ( false for Html control array ie. default select ) 36 csvSepChar: ',', // separation char in csv mode 37 okCancelInMulti: false, // display ok cancel buttons in desktop mode multiselect also. 38 isClickAwayOk: false, // for okCancelInMulti=true. sets whether click outside will trigger Ok or Cancel (default is cancel). 39 triggerChangeCombined: true, // im multi select mode whether to trigger change event on individual selection or combined selection. 40 selectAll: false, // to display select all button in multiselect mode.|| also select all will not be available on mobile devices. 41 42 search: true, // to display input for filtering content. selectAlltext will be input text placeholder 43 searchText: 'Search...', // placeholder for search input 44 searchFn: function(haystack, needle) { // search function 45 return haystack.toLowerCase().indexOf(needle.toLowerCase()) < 0; 46 }, 47 noMatch: 'No matches for "{0}"', 48 prefix: '', // some prefix usually the field name. eg. '<b>Hello</b>' 49 locale: ['OK', 'Cancel', 'Select All', i18n.clear_all], // all text that is used. don't change the index. 50 up: false, // set true to open upside. 51 showTitle: true, // set to false to prevent title (tooltip) from appearing 52 clearAll: true, // im multi select - clear all checked options 53 closeAfterClearAll: true, // im multi select - close select after clear 54 }, options); 55 56 var ret = this.each(function () { 57 var selObj = this; // the original select object. 58 if (this.sumo || !$(this).is('select')) return; //already initialized 59 60 this.sumo = { 61 E: $(selObj), //the jquery object of original select element. 62 is_multi: $(selObj).attr('multiple'), //if its a multiple select 63 select: '', 64 caption: '', 65 placeholder: '', 66 optDiv: '', 67 CaptionCont: '', 68 ul: '', 69 is_floating: false, 70 is_opened: false, 71 //backdrop: '', 72 mob: false, // if to open device default select 73 Pstate: [], 74 lastUnselected: null, 75 76 createElems: function () { 77 var O = this; 78 O.E.wrap('<div class="SumoSelect" style="min-width: 150px" tabindex="0" role="button" aria-expanded="false">'); 79 O.select = O.E.parent(); 80 O.caption = $('<span>'); 81 O.CaptionCont = $('<p class="CaptionCont SelectBox" ><label><i></i></label></p>') 82 .attr('style', O.E.attr('style')) 83 .prepend(O.caption); 84 O.select.append(O.CaptionCont); 85 86 // default turn off if no multiselect 87 if (!O.is_multi) settings.okCancelInMulti = false 88 89 if (O.E.attr('disabled')) 90 O.select.addClass('disabled').removeAttr('tabindex'); 91 92 //if output as csv and is a multiselect. 93 if (settings.outputAsCSV && O.is_multi && O.E.attr('name')) { 94 //create a hidden field to store csv value. 95 O.select.append($('<input class="HEMANT123" type="hidden" />').attr('name', O.E.attr('name')).val(O.getSelStr())); 96 97 // so it can not post the original select. 98 O.E.removeAttr('name'); 99 } 100 101 //break for mobile rendring.. if forceCustomRendering is false
102 if (O.isMobile() && !settings.forceCustomRendering) { 103 O.setNativeMobile(); 104 return; 105 } 106 107 // if there is a name attr in select add a class to container div 108 if (O.E.attr('name')) O.select.addClass('sumo_' + O.E.attr('name').replace(/\[\]/, '')) 109 110 //hide original select 111 O.E.addClass('SumoUnder').attr('tabindex', '-1'); 112 113 //## Creating the list... 114 O.optDiv = $('<div class="optWrapper ' + (settings.up ? 'up' : '') + '">'); 115 116 //branch for floating list in low res devices. 117 O.floatingList(); 118 119 //Creating the markup for the available options 120 O.ul = $('<ul class="options">'); 121 O.optDiv.append(O.ul); 122 123 // Select all functionality 124 if (settings.clearAll && O.is_multi) O.ClearAll(); 125 if (settings.selectAll && O.is_multi) O.SelAll(); 126 127 // search functionality 128 if (settings.search) O.Search(); 129 130 O.ul.append(O.prepItems(O.E.children())); 131 132 //if multiple then add the class multiple and add OK / CANCEL button 133 if (O.is_multi) O.multiSelelect(); 134 135 O.select.append(O.optDiv); 136 O.basicEvents(); 137 O.selAllState(); 138 }, 139 140 prepItems: function (opts, d) { 141 var lis = [], O = this; 142 $(opts).each(function (i, opt) { // parsing options to li 143 opt = $(opt); 144 lis.push(opt.is('optgroup') ? 145 $('<li class="group ' + (opt[0].disabled ? 'disabled' : '') + '"><label>' + opt.attr('label') + '</label><ul></ul></li>') 146 .find('ul') 147 .append(O.prepItems(opt.children(), opt[0].disabled)) 148 .end() 149 : 150 O.createLi(opt, d) 151 ); 152 }); 153 return lis; 154 }, 155 156 //## Creates a LI element from a given option and binds events to it 157 //## returns the jquery instance of li (not inserted in dom) 158 createLi: function (opt, d) { 159 var O = this; 160 161 if (!opt.attr('value')) opt.attr('value', opt.val()); 162 var li = $('<li class="opt"><label>' + opt.text() + '</label></li>'); 163 164 li.data('opt', opt); // store a direct reference to option. 165 opt.data('li', li); // store a direct reference to list item. 166 if (O.is_multi) li.prepend('<span><i></i></span>'); 167 168 if (opt[0].disabled || d) 169 li = li.addClass('disabled'); 170 171 O.onOptClick(li); 172 173 if (opt[0].selected) 174 li.addClass('selected'); 175 176 if (opt.attr('class')) 177 li.addClass(opt.attr('class')); 178 179 if (opt.attr('title')) 180 li.attr('title', opt.attr('title')); 181 182 return li; 183 }, 184 185 //## Returns the selected items as string in a Multiselect. 186 getSelStr: function () { 187 // get the pre selected items. 188 var sopt = []; 189 this.E.find('option:selected').each(function () { sopt.push($(this).val()); }); 190 return sopt.join(settings.csvSepChar); 191 }, 192 193 //## THOSE OK/CANCEL BUTTONS ON MULTIPLE SELECT. 194 multiSelelect: function () { 195 var O = this; 196 O.optDiv.addClass('multiple'); 197 O.okbtn = $('<p tabindex="0" class="btnOk">' + settings.locale[0] + '</p>').click(function () { 198 //if combined change event is set. 199 O._okbtn(); 200 O.hideOpts(); 201 }); 202 O.cancelBtn = $('<p tabindex="0" class="btnCancel">' + settings.locale[1] + '</p>').click(function () { 203 O._cnbtn(); 204 O.hideOpts(); 205 }); 206 var btns = O.okbtn.add(O.cancelBtn);
207 O.optDiv.append($('<div class="MultiControls">').append(btns)); 208 209 // handling keyboard navigation on ok cancel buttons. 210 btns.on('keydown.sumo', function (e) { 211 var el = $(this); 212 switch (e.which) { 213 case 32: // space 214 case 13: // enter 215 el.trigger('click'); 216 break; 217 218 case 9: //tab 219 if (el.hasClass('btnOk')) return; 220 case 27: // esc 221 O._cnbtn(); 222 O.hideOpts(); 223 return; 224 } 225 e.stopPropagation(); 226 e.preventDefault(); 227 }); 228 }, 229 230 _okbtn: function () { 231 var O = this, cg = 0; 232 //if combined change event is set. 233 if (settings.triggerChangeCombined) { 234 //check for a change in the selection. 235 if (O.E.find('option:selected').length !== O.Pstate.length) { 236 cg = 1; 237 } 238 else { 239 O.E.find('option').each(function (i, e) { 240 if (e.selected && O.Pstate.indexOf(i) < 0) cg = 1; 241 }); 242 } 243 244 if (cg) { 245 O.callChange(); 246 O.setText(); 247 } 248 } 249 }, 250 _cnbtn: function () { 251 var O = this; 252 //remove all selections 253 O.E.find('option:selected').each(function () { this.selected = false; }); 254 O.optDiv.find('li.selected').removeClass('selected') 255 256 //restore selections from saved state. 257 for (var i = 0; i < O.Pstate.length; i++) { 258 O.E.find('option')[O.Pstate[i]].selected = true; 259 O.ul.find('li.opt').eq(O.Pstate[i]).addClass('selected'); 260 } 261 O.selAllState(); 262 }, 263 264 SelAll: function () { 265 var O = this; 266 if (!O.is_multi) return; 267 O.selAll = $('<p class="select-all"><span><i></i></span><label>' + settings.locale[2] + '</label></p>'); 268 O.optDiv.addClass('selall'); 269 O.selAll.on('click', function () { 270 O.selAll.toggleClass('selected'); 271 O.toggSelAll(O.selAll.hasClass('selected'), 1); 272 //O.selAllState(); 273 }); 274 275 O.optDiv.prepend(O.selAll); 276 }, 277 278 ClearAll: function () { 279 const O = this; 280 if (!O.is_multi) return; 281 O.selAll = $('<p class="reset-all"><span><i></i></span><label></label></p>'); 282 [, , , O.selAll.find('label')[0].innerText] = settings.locale; 283 O.optDiv.addClass('resetAll'); 284 285 // Simplified event handler with mobile support 286 O.selAll.on('click touchstart', function(e) { 287 e.preventDefault(); 288 e.stopPropagation(); 289 290 // Unselect all options directly 291 O.E.find('option:selected').prop('selected', false); 292 O.optDiv.find('li.opt').removeClass('selected'); 293 294 // Update UI 295 O.setText(); 296 O.selAllState(); 297 O.callChange(); 298 299 // Close if configured 300 if (settings.closeAfterClearAll) { 301 O.hideOpts(); 302 } 303 }); 304 305 // Add to the DOM with improved touch target 306 O.optDiv.prepend(O.selAll); 307 }, 308 309 // search module (can be removed if not required.) 310 Search: function () { 311 var O = this, 312 cc = O.CaptionCont.addClass('search'), 313 P = $('<p class="no-match">'), 314 fn = (options.searchFn && typeof options.searchFn == 'function') ? options.searchFn : settings.searchFn; 315 316 O.ftxt = $('<input type="text" class="search-txt" value="" placeholder="' + settings.searchText + '">') 317 .on('click', function (e) { 318 e.stopPropagation(); 319 }); 320 cc.append(O.ftxt); 321 O.optDiv.children('ul').after(P); 322 323 O.ftxt.on('keyup.sumo', function () { 324 var hid = O.optDiv.find('ul.options li.opt').each(function (ix, e) { 325 var e = $(e), 326 opt = e.data('opt')[0]; 327 opt.hidden = fn(e.text(), O.ftxt.val()); 328 e.toggleClass('hidden', opt.hidden); 329 }).not('.hidden'); 330
331 P.html(settings.noMatch.replace(/\{0\}/g, '<em></em>')).toggle(!hid.length); 332 P.find('em').text(O.ftxt.val()); 333 O.selAllState(); 334 }); 335 }, 336 337 selAllState: function () { 338 var O = this; 339 if (settings.selectAll && O.is_multi) { 340 var sc = 0, vc = 0; 341 O.optDiv.find('li.opt').not('.hidden').each(function (ix, e) { 342 if ($(e).hasClass('selected')) sc++; 343 if (!$(e).hasClass('disabled')) vc++; 344 }); 345 //select all checkbox state change. 346 if (sc === vc) O.selAll.removeClass('partial').addClass('selected'); 347 else if (sc === 0) O.selAll.removeClass('selected partial'); 348 else O.selAll.addClass('partial')//.removeClass('selected'); 349 } 350 }, 351 352 showOpts: function () { 353 var O = this; 354 if (O.E.attr('disabled')) return; // if select is disabled then retrun 355 O.E.trigger('sumo:opening', O); 356 O.is_opened = true; 357 O.select.addClass('open').attr('aria-expanded', 'true'); 358 O.E.trigger('sumo:opened', O); 359 360 if (O.ftxt) O.ftxt.focus(); 361 else O.select.focus(); 362 363 // hide options on click outside. 364 $(document).on('click.sumo', function (e) { 365 if (!O.select.is(e.target) // if the target of the click isn't the container... 366 && O.select.has(e.target).length === 0) { // ... nor a descendant of the container 367 if (!O.is_opened) return; 368 O.hideOpts(); 369 if (settings.okCancelInMulti) { 370 if (settings.isClickAwayOk) 371 O._okbtn(); 372 else 373 O._cnbtn(); 374 } 375 } 376 }); 377 378 if (O.is_floating) { 379 var H = O.optDiv.children('ul').outerHeight() + 2; // +2 is clear fix 380 if (O.is_multi) H = H + parseInt(O.optDiv.css('padding-bottom')); 381 const extraHeight = 25; // extra height clearAll on mobile devices 382 O.optDiv.css('height', H + extraHeight); 383 $('body').addClass('sumoStopScroll'); 384 } 385 386 O.setPstate(); 387 }, 388 389 //maintain state when ok/cancel buttons are available storing the indexes. 390 setPstate: function () { 391 var O = this; 392 if (O.is_multi && (O.is_floating || settings.okCancelInMulti)) { 393 O.Pstate = []; 394 // assuming that find returns elements in tree order 395 O.E.find('option').each(function (i, e) { if (e.selected) O.Pstate.push(i); }); 396 } 397 }, 398 399 callChange: function () { 400 this.E.trigger('change').trigger('click'); 401 }, 402 403 hideOpts: function () { 404 var O = this; 405 if (O.is_opened) { 406 O.E.trigger('sumo:closing', O); 407 O.is_opened = false; 408 O.select.removeClass('open').attr('aria-expanded', 'true').find('ul li.sel').removeClass('sel'); 409 O.E.trigger('sumo:closed', O); 410 $(document).off('click.sumo'); 411 O.select.focus(); 412 $('body').removeClass('sumoStopScroll'); 413 414 // clear the search 415 if (settings.search) { 416 O.ftxt.val(''); 417 O.ftxt.trigger('keyup.sumo'); 418 } 419 } 420 }, 421 setOnOpen: function () { 422 var O = this, 423 li = O.optDiv.find('li.opt:not(.hidden)').eq(settings.search ? 0 : O.E[0].selectedIndex); 424 if (li.hasClass('disabled')) { 425 li = li.next(':not(disabled)') 426 if (!li.length) return; 427 } 428 O.optDiv.find('li.sel').removeClass('sel'); 429 li.addClass('sel'); 430 O.showOpts();
vendor: 5,709 bytes, lines 431-556
431 }, 432 nav: function (up) { 433 var O = this, c, 434 s = O.ul.find('li.opt:not(.disabled, .hidden)'), 435 sel = O.ul.find('li.opt.sel:not(.hidden)'), 436 idx = s.index(sel); 437 if (O.is_opened && sel.length) { 438 439 if (up && idx > 0) 440 c = s.eq(idx - 1); 441 else if (!up && idx < s.length - 1 && idx > -1) 442 c = s.eq(idx + 1); 443 else return; // if no items before or after 444 445 sel.removeClass('sel'); 446 sel = c.addClass('sel'); 447 448 // setting sel item to visible view. 449 var ul = O.ul, 450 st = ul.scrollTop(), 451 t = sel.position().top + st; 452 if (t >= st + ul.height() - sel.outerHeight()) 453 ul.scrollTop(t - ul.height() + sel.outerHeight()); 454 if (t < st) 455 ul.scrollTop(t); 456 457 } 458 else 459 O.setOnOpen(); 460 }, 461 462 basicEvents: function () { 463 var O = this; 464 O.CaptionCont.click(function (evt) { 465 O.E.trigger('click'); 466 if (O.is_opened) O.hideOpts(); else O.showOpts(); 467 evt.stopPropagation(); 468 }); 469 470 O.select.on('keydown.sumo', function (e) { 471 switch (e.which) { 472 case 38: // up 473 O.nav(true); 474 break; 475 476 case 40: // down 477 O.nav(false); 478 break; 479 480 case 65: // shortcut ctrl + a to select all and ctrl + shift + a to unselect all. 481 if (O.is_multi && e.ctrlKey) { 482 O.toggSelAll(!e.shiftKey, 1); 483 break; 484 } 485 else 486 return; 487 488 case 32: // space 489 if (settings.search && O.ftxt.is(e.target)) return; 490 case 13: // enter 491 if (O.is_opened) 492 O.optDiv.find('ul li.sel').trigger('click'); 493 else 494 O.setOnOpen(); 495 break; 496 case 9: //tab 497 if (!settings.okCancelInMulti) 498 O.hideOpts(); 499 return; 500 case 27: // esc 501 if (settings.okCancelInMulti) O._cnbtn(); 502 O.hideOpts(); 503 return; 504 505 default: 506 return; // exit this handler for other keys 507 } 508 e.preventDefault(); // prevent the default action (scroll / move caret) 509 }); 510 511 $(window).on('resize.sumo', function () { 512 O.floatingList(); 513 }); 514 }, 515 516 onOptClick: function (li) { 517 var O = this; 518 li.click(function () { 519 var li = $(this); 520 if (li.hasClass('disabled')) return; 521 var txt = ""; 522 if (O.is_multi) { 523 li.toggleClass('selected'); 524 li.data('opt')[0].selected = li.hasClass('selected'); 525 if (li.data('opt')[0].selected === false) { 526 O.lastUnselected = li.data('opt')[0].textContent; 527 } 528 O.selAllState(); 529 } 530 else { 531 li.parent().find('li.selected').removeClass('selected'); //if not multiselect then remove all selections from this list 532 li.toggleClass('selected'); 533 li.data('opt')[0].selected = true; 534 } 535 536 //branch for combined change event. 537 if (!(O.is_multi && settings.triggerChangeCombined && (O.is_floating || settings.okCancelInMulti))) { 538 O.setText(); 539 O.callChange(); 540 } 541 542 if (!O.is_multi) O.hideOpts(); //if its not a multiselect then hide on single select. 543 }); 544 }, 545 546 // fixed some variables that were not explicitly typed (michc) 547 setText: function () { 548 var O = this; 549 let lengthSelected = 0; 550 O.placeholder = ""; 551 if (O.is_multi) { 552 var sels = O.E.find(':selected').not(':disabled'); //selected options. 553 lengthSelected = sels.length; 554 555 for (var i = 0; i < sels.length; i++) { 556 if (i + 1 >
556= settings.csvDispCount && settings.csvDispCount) { 557 if (sels.length === O.E.find('option').length && settings.captionFormatAllSelected) { 558 O.placeholder = settings.captionFormatAllSelected.replace(/\{0\}/g, sels.length) + ','; 559 } else { 560 O.placeholder = settings.captionFormat.replace(/\{0\}/g, sels.length) + ','; 561 } 562 563 break; 564 } 565 else O.placeholder += $(sels[i]).text() + ", "; 566 } 567 O.placeholder = O.placeholder.replace(/,([^,]*)$/, '$1'); //remove unexpected "," from last. 568 } 569 else { 570 O.placeholder = O.E.find(':selected').not(':disabled').text(); 571 lengthSelected = option.length; 572 } 573 574 var is_placeholder = false; 575 576 if (!O.placeholder) { 577 578 is_placeholder = true; 579 580 O.placeholder = O.E.attr('placeholder'); 581 if (!O.placeholder) //if placeholder is there then set it 582 O.placeholder = O.E.find('option:disabled:selected').text(); 583 } 584 585 O.select.attr('selected-count', lengthSelected); 586 O.select.attr('is-selected', lengthSelected ? 'true' : 'false'); 587 588 O.placeholder = O.placeholder ? (settings.prefix + ' ' + O.placeholder) : settings.placeholder 589 590 //set display text 591 O.caption.html(O.placeholder); 592 if (settings.showTitle) O.CaptionCont.attr('title', O.placeholder); 593 594 //set the hidden field if post as csv is true. 595 var csvField = O.select.find('input.HEMANT123'); 596 if (csvField.length) csvField.val(O.getSelStr()); 597 598 //add class placeholder if its a placeholder text. 599 if (is_placeholder) O.caption.addClass('placeholder'); else O.caption.removeClass('placeholder'); 600 return O.placeholder; 601 }, 602 603 isMobile: function () { 604 605 // Adapted from http://www.detectmobilebrowsers.com 606 var ua = navigator.userAgent || navigator.vendor || window.opera; 607 608 // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices 609 for (var i = 0; i < settings.nativeOnDevice.length; i++) if (ua.toString().toLowerCase().indexOf(settings.nativeOnDevice[i].toLowerCase()) > 0) return settings.nativeOnDevice[i]; 610 return false; 611 }, 612 613 setNativeMobile: function () { 614 var O = this; 615 O.E.addClass('SelectClass')//.css('height', O.select.outerHeight()); 616 O.mob = true; 617 O.E.change(function () { 618 O.setText(); 619 }); 620 }, 621 622 floatingList: function () { 623 var O = this; 624 //called on init and also on resize. 625 //O.is_floating = true if window width is < specified float width 626 O.is_floating = $(window).width() <= settings.floatWidth; 627 628 //set class isFloating 629 O.optDiv.toggleClass('isFloating', O.is_floating); 630 631 //remove height if not floating 632 if (!O.is_floating) O.optDiv.css('height', ''); 633 634 //toggle class according to okCancelInMulti flag only when it is not floating 635 O.optDiv.toggleClass('okCancelInMulti', settings.okCancelInMulti && !O.is_floating); 636 }, 637 638 //HELPERS FOR OUTSIDERS 639 // validates range of given item operations 640 vRange: function (i) { 641 var O = this; 642 var opts = O.E.find('option'); 643 if (opts.length <= i || i < 0) throw "index out of bounds" 644 return O; 645 }, 646 647 //toggles selection on c as boolean. 648 toggSel: function (c, i) { 649 var O = this; 650 var opt;
651 if (typeof (i) === "number") { 652 O.vRange(i); 653 opt = O.E.find('option')[i]; 654 } 655 else { 656 opt = O.E.find('option[value="' + i + '"]')[0] || 0; 657 } 658 if (!opt || opt.disabled) 659 return; 660 661 if (opt.selected !== c) { 662 opt.selected = c; 663 if (!O.mob) $(opt).data('li').toggleClass('selected', c); 664 665 O.callChange(); 666 O.setPstate(); 667 O.setText(); 668 O.selAllState(); 669 } 670 }, 671 672 //toggles disabled on c as boolean. 673 toggDis: function (c, i) { 674 var O = this.vRange(i); 675 O.E.find('option')[i].disabled = c; 676 if (c) O.E.find('option')[i].selected = false; 677 if (!O.mob) O.optDiv.find('ul.options li').eq(i).toggleClass('disabled', c).removeClass('selected'); 678 O.setText(); 679 }, 680 681 // toggle disable/enable on complete select control 682 toggSumo: function (val) { 683 var O = this; 684 O.enabled = val; 685 O.select.toggleClass('disabled', val); 686 687 if (val) { 688 O.E.attr('disabled', 'disabled'); 689 O.select.removeAttr('tabindex'); 690 } 691 else { 692 O.E.removeAttr('disabled'); 693 O.select.attr('tabindex', '0'); 694 } 695 696 return O; 697 }, 698 699 // toggles all option on c as boolean. 700 // set direct=false/0 bypasses okCancelInMulti behaviour. 701 toggSelAll: function (c, direct) { 702 var O = this; 703 O.E.find('option:not(:disabled,:hidden)') 704 .each(function (ix, e) { 705 var is_selected = e.selected, 706 e = $(e).data('li'); 707 if (e.hasClass('hidden')) return; 708 if (!!c) { 709 if (!is_selected) e.trigger('click'); 710 } 711 else { 712 if (is_selected) e.trigger('click'); 713 } 714 }); 715 716 if (!direct) { 717 if (!O.mob && O.selAll) O.selAll.removeClass('partial').toggleClass('selected', !!c); 718 O.callChange(); 719 O.setText(); 720 O.setPstate(); 721 } 722 }, 723 724 /* outside accessibility options 725 which can be accessed from the element instance. 726 */ 727 reload: function () { 728 var elm = this.unload(); 729 return $(elm).SumoSelect(settings); 730 }, 731 732 unload: function () { 733 var O = this; 734 O.select.before(O.E); 735 O.E.show(); 736 737 if (settings.outputAsCSV && O.is_multi && O.select.find('input.HEMANT123').length) { 738 O.E.attr('name', O.select.find('input.HEMANT123').attr('name')); // restore the name; 739 } 740 O.select.remove(); 741 delete selObj.sumo; 742 return selObj; 743 }, 744 745 //## add a new option to select at a given index. 746 add: function (val, txt, i) { 747 if (typeof val === "undefined") throw "No value to add" 748 749 var O = this; 750 var opts = O.E.find('option') 751 if (typeof txt === "number") { i = txt; txt = val; } 752 if (typeof txt === "undefined") { txt = val; } 753 754 var opt = $("<option></option>").val(val).html(txt); 755 756 if (opts.length < i) throw "index out of bounds" 757 758 if (typeof i === "undefined" || opts.length === i) { // add it to the last if given index is last no or no index provides. 759 O.E.append(opt); 760 if (!O.mob) O.ul.append(O.createLi(opt)); 761 } 762 else { 763 opts.eq(i).before(opt); 764 if (!O.mob) O.ul.find('li.opt').eq(i).before(O.createLi(opt)); 765 } 766 767 return selObj; 768 }, 769 770 //## removes an item at a given index. 771 remove: function (i) { 772 var O = this.vRange(i); 773 O.E.find('option').eq(i).remove(); 774 if (!O.mob) O.optDiv.find('ul.options li').eq(i).remove(); 775 O.setText(); 776 }, 777 778 // removes all but the selected one 779 removeAll: function () { 780 var O = this; 781 var options = O.E.find('option'); 782 783 for (var x = (options.length - 1); x >= 0; x--) { 784 if (options[x].selected !== true) { 785 O.remove(x); 786 } 787 } 788 789 }, 790 791 792 find: function (val) { 793 var O = this; 794 var options = O.E.find('option'); 795 for (var x in options) { 796 if (options[x].value === val) { 797 return parseInt(x); 798 } 799 } 800 801 return -1; 802 803 }, 804 805 //## Select an item at a given index. 806 selectItem: function (i) { this.toggSel(true, i); }, 807 808 //## UnSelect an iten at a given index. 809 unSelectItem: function (i) { this.toggSel(false, i); }, 810 811 //## Select all items of the select. 812 selectAll: function () { this.toggSelAll(true); }, 813 814 //## UnSelect all items of the select. 815 unSelectAll: function () { this.toggSelAll(false); }, 816 817 //## Disable an iten at a given index. 818 disableItem: function (i) { this.toggDis(true, i) }, 819 820 //## Removes disabled an iten at a given index. 821 enableItem: function (i) { this.toggDis(false, i) }, 822 823 //## New simple methods as getter and setter are not working fine in ie8-
824 //## variable to check state of control if enabled or disabled. 825 enabled: true, 826 //## Enables the control 827 enable: function () { return this.toggSumo(false) }, 828 829 //## Disables the control 830 disable: function () { return this.toggSumo(true) }, 831 832 833 init: function () { 834 var O = this; 835 O.createElems(); 836 O.setText(); 837 return O 838 } 839 840 }; 841 842 selObj.sumo.init(); 843 }); 844 845 return ret.length === 1 ? ret[0] : ret; 846 }; 847 848 849});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.