Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

select2-custom.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. "use strict";
  2. $(document).ready(function(){
  3. // Single Search Select
  4. $(".js-example-basic-single").select2();
  5. $(".js-example-disabled-results").select2();
  6. // Multi Select
  7. $(".js-example-basic-multiple").select2();
  8. // With Placeholder
  9. $(".js-example-placeholder-multiple").select2({
  10. placeholder: "Select Your Name"
  11. });
  12. //Limited Numbers
  13. $(".js-example-basic-multiple-limit").select2({
  14. maximumSelectionLength: 2
  15. });
  16. // Tagging Suppoort
  17. $(".js-example-tags").select2({
  18. tags: true
  19. });
  20. // Automatic tokenization
  21. $(".js-example-tokenizer").select2({
  22. tags: true,
  23. tokenSeparators: [',', ' ']
  24. });
  25. // Loading Array Data
  26. var data = [{
  27. id: 0,
  28. text: 'enhancement'
  29. }, {
  30. id: 1,
  31. text: 'bug'
  32. }, {
  33. id: 2,
  34. text: 'duplicate'
  35. }, {
  36. id: 3,
  37. text: 'invalid'
  38. }, {
  39. id: 4,
  40. text: 'wontfix'
  41. }];
  42. $(".js-example-data-array").select2({
  43. data: data
  44. });
  45. //RTL Suppoort
  46. $(".js-example-rtl").select2({
  47. dir: "rtl"
  48. });
  49. // Diacritics support
  50. $(".js-example-diacritics").select2();
  51. // Responsive width Search Select
  52. $(".js-example-responsive").select2();
  53. $(".js-example-basic-hide-search").select2({
  54. minimumResultsForSearch: Infinity
  55. });
  56. $(".js-example-disabled").select2({
  57. disabled: true
  58. });
  59. $(".js-programmatic-enable").on("click", function() {
  60. $(".js-example-disabled").prop("disabled", false);
  61. });
  62. $(".js-programmatic-disable").on("click", function() {
  63. $(".js-example-disabled").prop("disabled", true);
  64. });
  65. $(".js-example-theme-single").select2({
  66. theme: "classic"
  67. });
  68. function formatRepo(repo) {
  69. if (repo.loading) return repo.text;
  70. var markup = "<div class='select2-result-repository clearfix'>" +
  71. "<div class='select2-result-repository__avatar'><img src='" + repo.owner.avatar_url + "' /></div>" +
  72. "<div class='select2-result-repository__meta'>" +
  73. "<div class='select2-result-repository__title'>" + repo.full_name + "</div>";
  74. if (repo.description) {
  75. markup += "<div class='select2-result-repository__description'>" + repo.description + "</div>";
  76. }
  77. markup += "<div class='select2-result-repository__statistics'>" +
  78. "<div class='select2-result-repository__forks'><i class='icofont icofont-flash'></i> " + repo.forks_count + " Forks</div>" +
  79. "<div class='select2-result-repository__stargazers'><i class='icofont icofont-star'></i> " + repo.stargazers_count + " Stars</div>" +
  80. "<div class='select2-result-repository__watchers'><i class='icofont icofont-eye-alt'></i> " + repo.watchers_count + " Watchers</div>" +
  81. "</div>" +
  82. "</div></div>";
  83. return markup;
  84. }
  85. function formatRepoSelection(repo) {
  86. return repo.full_name || repo.text;
  87. }
  88. $(".js-data-example-ajax").select2({
  89. ajax: {
  90. url: "https://api.github.com/search/repositories",
  91. dataType: 'json',
  92. delay: 250,
  93. data: function(params) {
  94. return {
  95. q: params.term, // search term
  96. page: params.page
  97. };
  98. },
  99. processResults: function(data, params) {
  100. // parse the results into the format expected by Select2
  101. // since we are using custom formatting functions we do not need to
  102. // alter the remote JSON data, except to indicate that infinite
  103. // scrolling can be used
  104. params.page = params.page || 1;
  105. return {
  106. results: data.items,
  107. pagination: {
  108. more: (params.page * 30) < data.total_count
  109. }
  110. };
  111. },
  112. cache: true
  113. },
  114. escapeMarkup: function(markup) {
  115. return markup;
  116. }, // let our custom formatter work
  117. minimumInputLength: 1,
  118. templateResult: formatRepo, // omitted for brevity, see the source of this page
  119. templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
  120. });
  121. // Multi-select js start
  122. $('#my-select').multiSelect();
  123. $('#public-methods').multiSelect();
  124. $('#select-all').on('click',function() {
  125. $('#public-methods').multiSelect('select_all');
  126. return false;
  127. });
  128. $('#deselect-all').on('click',function() {
  129. $('#public-methods').multiSelect('deselect_all');
  130. return false;
  131. });
  132. $('#select-5').on('click',function() {
  133. $('#public-methods').multiSelect('select', ['elem_1', 'elem_3', 'elem_4', 'elem_5']);
  134. return false;
  135. });
  136. $('#deselect-5').on('click',function() {
  137. $('#public-methods').multiSelect('deselect', ['elem_1', 'elem_3', 'elem_4', 'elem_5']);
  138. return false;
  139. });
  140. $('#refresh').on('click', function() {
  141. $('#public-methods').multiSelect('refresh');
  142. return false;
  143. });
  144. $('#add-option').on('click', function() {
  145. $('#public-methods').multiSelect('addOption', {
  146. value: 42,
  147. text: 'test 42',
  148. index: 0
  149. });
  150. return false;
  151. });
  152. $('#optgroup').multiSelect({
  153. selectableOptgroup: true
  154. });
  155. $('#custom-headers1').multiSelect({
  156. selectableHeader: "<div class='custom-header'>Selectable items</div>",
  157. selectionHeader: "<div class='custom-header'>Selection items</div>",
  158. selectableFooter: "<div class='custom-header'>Selectable footer</div>",
  159. selectionFooter: "<div class='custom-header'>Selection footer</div>"
  160. });
  161. // Single Select
  162. // $('#example-single').multiselect();
  163. // // Multi Select
  164. // $('#example-multiple-selected').multiselect();
  165. // // Multi Group Select
  166. // $('#example-multiple-optgroups').multiselect();
  167. // // Select all group select
  168. // $('#example-enableClickableOptGroups').multiselect({
  169. // enableClickableOptGroups: true
  170. // });
  171. // // Disable Options Select
  172. // $('#example-enableClickableOptGroups-init').multiselect({
  173. // enableClickableOptGroups: true
  174. // });
  175. // // Collapse group select
  176. // $('#example-enableCollapsibleOptGroups').multiselect({
  177. // enableCollapsibleOptGroups: true
  178. // });
  179. $('.searchable').multiSelect({
  180. selectableHeader: "<input type='text' class='form-control' autocomplete='off' placeholder='try \"12\"'>",
  181. selectionHeader: "<input type='text' class='form-control' autocomplete='off' placeholder='try \"4\"'>",
  182. afterInit: function(ms) {
  183. var that = this,
  184. $selectableSearch = that.$selectableUl.prev(),
  185. $selectionSearch = that.$selectionUl.prev(),
  186. selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
  187. selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
  188. that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
  189. .on('keydown', function(e) {
  190. if (e.which === 40) {
  191. that.$selectableUl.focus();
  192. return false;
  193. }
  194. });
  195. that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
  196. .on('keydown', function(e) {
  197. if (e.which == 40) {
  198. that.$selectionUl.focus();
  199. return false;
  200. }
  201. });
  202. },
  203. afterSelect: function() {
  204. this.qs1.cache();
  205. this.qs2.cache();
  206. },
  207. afterDeselect: function() {
  208. this.qs1.cache();
  209. this.qs2.cache();
  210. }
  211. });
  212. // Multi-select js end
  213. });