1/* global define, jQuery */ 2(function (factory) { 3 if (typeof define === 'function' && define.amd) { 4 define(['jquery'], factory) 5 } else if (typeof module === 'object' && module.exports) { 6 module.exports = factory(require('jquery')) 7 } else { 8 // Browser globals 9 factory(jQuery || window.django.jQuery) 10 } 11}(function ($) { 12 'use strict' 13 var init = function ($element, options) { 14 $element.select2(options) 15 } 16 17 var initHeavy = function ($element, options) { 18 var settings = $.extend({ 19 ajax: { 20 data: function (params) { 21 var result = { 22 term: params.term, 23 page: params.page, 24 field_id: $element.data('field_id') 25 } 26 27 var dependentFields = $element.data('select2-dependent-fields') 28 if (dependentFields) { 29 dependentFields = dependentFields.trim().split(/\s+/) 30 $.each(dependentFields, function (i, dependentField) { 31 result[dependentField] = $('[name=' + dependentField + ']', $element.closest('form')).val() 32 }) 33 } 34 35 return result 36 }, 37 processResults: function (data, page) { 38 return { 39 results: data.results, 40 pagination: { 41 more: data.more 42 } 43 } 44 } 45 } 46 }, options) 47 48 $element.select2(settings) 49 } 50 51 $.fn.djangoSelect2 = function (options) { 52 var settings = $.extend({}, options) 53 $.each(this, function (i, element) { 54 var $element = $(element) 55 if ($element.hasClass('django-select2-heavy')) { 56 initHeavy($element, settings) 57 } else { 58 init($element, settings) 59 } 60 $element.on('select2:select', function (e) { 61 var name = $(e.currentTarget).attr('name') 62 $('[data-select2-dependent-fields~=' + name + ']').each(function () { 63 $(this).val('').trigger('change') 64 }) 65 }) 66 }) 67 return this 68 } 69 70 $(function () { 71 $('.django-select2').djangoSelect2() 72 }) 73 74 return $.fn.djangoSelect2 75}))
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.