Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var classLegendariesDropdownId = '#<% =classLegendariesUi.ClientID.ToString() %>';
- //Initiate classLegendaries
- $(document).ready(function () {
- getClassLegendaries();
- });
- function getClassLegendaries() {
- $(classLegendariesDropdownId).select2({
- width: '100%', // need to override the changed default
- closeOnSelect: false,
- ajax: {
- url: '/API/classlegendariesapi.aspx?classId=' + $('#<% =New_Application_Class_DropDownList.ClientID.ToString() %>').val(),
- dataType: 'json'
- },
- placeholder: "Select your legendaries",
- dropdownAdapter: $.fn.select2.amd.require('select2/selectAllAdapter'),
- templateResult: formatLegendary,
- templateSelection: formatLegendary
- });
- }
- function resetClassLegendariesSelect() {
- $(classLegendariesDropdownId).val('').trigger('change');
- }
- function forceRefreshClassLegendariesSelect() {
- $(classLegendariesDropdownId).trigger('change');
- }
- function formatLegendary(legendary) {
- if (!legendary.id) {
- return legendary.text;
- }
- var $legendary = $(
- '<a rel="item=' + legendary.id + '&bonus=3570">' + legendary.text + '</a>'
- );
- return $legendary;
- };
- $(function () {
- $(document).ready(function () {
- Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
- function EndRequestHandler(sender, args) {
- getClassLegendaries();
- }
- });
- });
- /*
- Add options to select/unselect all options in select2 multiple select elements
- &
- Define the adapter so that it's reusable
- */
- $.fn.select2.amd.define('select2/selectAllAdapter', [
- 'select2/utils',
- 'select2/dropdown',
- 'select2/dropdown/attachBody'
- ], function (Utils, Dropdown, AttachBody) {
- function SelectAll() { }
- SelectAll.prototype.render = function (decorated) {
- var self = this,
- $rendered = decorated.call(this),
- $selectAll = $(
- '<button class="btn btn-xs btn-success" type="button" style="margin-left:6px;"><i class="fa fa-check-square-o"></i> Select All</button>'
- ),
- $unselectAll = $(
- '<button class="btn btn-xs btn-warning" type="button" style="margin-left:6px;"><i class="fa fa-square-o"></i> Unselect All</button>'
- ),
- $btnContainer = $('<div style="margin-top:3px;background-color:#000;">').append($selectAll).append($unselectAll);
- if (!this.$element.prop("multiple")) {
- // this isn't a multi-select -> don't add the buttons!
- return $rendered;
- }
- $rendered.find('.select2-dropdown').prepend($btnContainer);
- $selectAll.on('click', function (e) {
- var $results = $rendered.find('.select2-results__option[aria-selected=false]');
- $results.each(function () {
- self.trigger('select', {
- data: $(this).data('data')
- });
- });
- self.trigger('close');
- });
- $unselectAll.on('click', function (e) {
- var $results = $rendered.find('.select2-results__option[aria-selected=true]');
- $results.each(function () {
- self.trigger('unselect', {
- data: $(this).data('data')
- });
- });
- self.trigger('close');
- });
- return $rendered;
- };
- return Utils.Decorate(
- Utils.Decorate(
- Dropdown,
- AttachBody
- ),
- SelectAll
- );
- });
- /*
- adapter could have been defined elsewhere in a global includes script or whereever
- we can now use it elsewhere
- this can also be applied to non-multi-selects (the buttons won't be added)
- */
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement