/*global jQuery, define, module, require*/ /*! * jquery.sumoselect * http://hemantnegi.github.io/jquery.sumoselect * 2016-12-12 * * Copyright 2015 Hemant Negi * Email : hemant.frnz@gmail.com * Compressor http://refresh-sf.com/ */ (function (factory) { 'use strict'; if (typeof define === 'function' && define.amd) { define(['jquery'], factory); } else if (typeof exports !== 'undefined') { module.exports = factory(require('jquery')); } else { factory(jQuery); } })(($) => { 'namespace sumo'; $.fn.SumoSelect = function (options) { // Extra check for IE compatibility const dispatchEvent = (target, eventName) => { let event = null; if (typeof (Event) === 'function') { event = new Event(eventName, { bubbles: true }); } else { event = document.createEvent('Event'); event.initEvent(eventName, true, true); } target.dispatchEvent(event); }; // missing forEach on NodeList for IE11 if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; } // This is the easiest way to have default options. const defaultOptions = { placeholder: 'Select Here', // Dont change it here. csvDispCount: 3, // display no. of items in multiselect. 0 to display all. captionFormat: '{0} Selected', // format of caption text. you can set your locale. 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. floatWidth: 400, // Screen width of device at which the list is rendered in floating popup fashion. forceCustomRendering: false, // force the custom modal on all devices below floatWidth resolution. nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'], // outputAsCSV: false, // true to POST data as csv ( false for Html control array ie. default select ) csvSepChar: ',', // separation char in csv mode okCancelInMulti: false, // display ok cancel buttons in desktop mode multiselect also. isClickAwayOk: false, // for okCancelInMulti=true. sets whether click outside will trigger Ok or Cancel (default is cancel). triggerChangeCombined: true, // im multi select mode whether to trigger change event on individual selection or combined selection. selectAll: false, // to display select all button in multiselect mode.|| also select all will not be available on mobile devices. selectAllPartialCheck: true, // Display a disabled checkbox in multiselect mode when all the items are not selected. search: false, // to display input for filtering content. selectAlltext will be input text placeholder searchText: 'Search...', // placeholder for search input searchFn(haystack, needle) { // search function return haystack.toLowerCase().indexOf(needle.toLowerCase()) < 0; }, noMatch: 'No matches for "{0}"', prefix: '', // some prefix usually the field name. eg. 'Hello' locale: ['OK', 'Cancel', 'Select All', 'Clear all'], // all text that is used. don't change the index. up: false, // set true to open upside. showTitle: true, // set to false to prevent title (tooltip) from appearing clearAll: false, // im multi select - clear all checked options closeAfterClearAll: false, // im multi select - close select after clear max: null, // Maximum number of options selected (when multiple) // eslint-disable-next-line no-unused-vars renderLi: (li, _originalOption) => li // Custom
  • item renderer }; const ret = this.each(function () { const selObj = this; // the original select object. if (this.sumo || !$(this).is('select')) return; //already initialized const settings = $.extend({}, defaultOptions, options, $(this).data()); this.sumo = { E: $(selObj), //the jquery object of original select element. is_multi: $(selObj).attr('multiple'), //if its a multiple select select: '', caption: '', placeholder: '', optDiv: '', CaptionCont: '', ul: '', is_floating: false, is_opened: false, //backdrop: '', mob: false, // if to open device default select Pstate: [], lastUnselected: null, selectedCount: 0, createElems() { const O = this; const selectedOptions = O.E.find('option:checked'); O.E.wrap('