ui_bibz 3.0.13 → 4.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.github/workflows/linter.yml +13 -12
- data/.overcommit.yml +6 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/Gemfile +19 -12
- data/Gemfile.lock +178 -138
- data/app/assets/config/ui_bibz.js +12 -0
- data/app/assets/javascripts/forms/formula.js +82 -0
- data/app/assets/javascripts/forms/input-connected.js +132 -0
- data/app/assets/javascripts/forms/jquery.multi-select-extend.js +52 -0
- data/app/assets/javascripts/forms.js +160 -0
- data/app/assets/javascripts/interfaces.js +56 -0
- data/app/assets/javascripts/tables.js +49 -0
- data/app/assets/javascripts/ui_bibz_js.js +37 -0
- data/app/assets/stylesheets/navigations/_nav.sass +2 -0
- data/app/assets/stylesheets/navigations/_navbar.sass +12 -0
- data/app/assets/stylesheets/navigations/_progress_bar.sass +2 -0
- data/app/assets/stylesheets/navigations/_toolbar.sass +3 -0
- data/app/assets/stylesheets/sass/_boxes.sass +1 -0
- data/app/assets/stylesheets/sass/_containers.sass +2 -0
- data/app/assets/stylesheets/sass/_fixes.sass +2 -0
- data/app/assets/stylesheets/sass/_forms.sass +8 -0
- data/app/assets/stylesheets/sass/_navigations.sass +4 -0
- data/app/assets/stylesheets/sass/_notifications.sass +4 -0
- data/app/assets/stylesheets/sass/_tables.sass +2 -0
- data/app/assets/stylesheets/sass/_variables_mixins_functions.sass +3 -0
- data/app/assets/stylesheets/sass/boxes/_card.sass +4 -0
- data/app/assets/stylesheets/sass/containers/_panel.scss +330 -0
- data/app/assets/stylesheets/sass/forms/_bootstrap_select.sass +5 -0
- data/app/assets/stylesheets/sass/forms/_button.sass +3 -0
- data/app/assets/stylesheets/sass/forms/_date_picker.sass +3 -0
- data/app/assets/stylesheets/sass/forms/_form_check.sass +10 -0
- data/app/assets/stylesheets/sass/forms/_formula_field.sass +17 -0
- data/app/assets/stylesheets/sass/forms/_multiselect.sass +44 -0
- data/app/assets/stylesheets/sass/forms/_range.sass +44 -0
- data/app/assets/stylesheets/sass/forms/_slider.sass +136 -0
- data/app/assets/stylesheets/sass/forms/_surround_field.sass +25 -0
- data/app/assets/stylesheets/sass/notifications/_badge.sass +5 -0
- data/app/assets/stylesheets/sass/notifications/_glyph.sass +3 -0
- data/app/assets/stylesheets/sass/notifications/_star.sass +2 -0
- data/app/assets/stylesheets/sass/notifications/_toast.sass +3 -0
- data/app/assets/stylesheets/sass/tables/_table.sass +39 -0
- data/app/assets/stylesheets/sass/tables/_table_card.sass +39 -0
- data/app/assets/stylesheets/ui_bibz.sass +26 -0
- data/bin/test +3 -5
- data/config/importmap.rb +19 -0
- data/config/initializers/assets.rb +5 -0
- data/config/initializers/will_paginate.rb +1 -3
- data/lib/ui_bibz/builders/data_html_options_builder.rb +118 -0
- data/lib/ui_bibz/builders/html_classes_builder.rb +89 -0
- data/lib/ui_bibz/builders/html_options_builder.rb +22 -0
- data/lib/ui_bibz/factory_methods/component_initialize_factory_method.rb +33 -0
- data/lib/ui_bibz/helpers/ui/core/boxes_helper.rb +12 -12
- data/lib/ui_bibz/helpers/ui/core/forms_helper.rb +50 -50
- data/lib/ui_bibz/helpers/ui/core/icons_helper.rb +6 -6
- data/lib/ui_bibz/helpers/ui/core/layouts_helper.rb +2 -2
- data/lib/ui_bibz/helpers/ui/core/lists_helper.rb +2 -2
- data/lib/ui_bibz/helpers/ui/core/navigations_helper.rb +12 -12
- data/lib/ui_bibz/helpers/ui/core/notifications_helper.rb +4 -4
- data/lib/ui_bibz/helpers/ui/core/windows_helper.rb +10 -2
- data/lib/ui_bibz/helpers/ui/ux_helper.rb +2 -2
- data/lib/ui_bibz/helpers/utils_helper.rb +2 -2
- data/lib/ui_bibz/infos.rb +3 -3
- data/lib/ui_bibz/inputs/ui_bibz_form/ui_bibz_form_builder.rb +12 -12
- data/lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb +1 -1
- data/lib/ui_bibz/rails/engine.rb +21 -4
- data/lib/ui_bibz/strategies/component_initialize_abstract_strategy.rb +27 -0
- data/lib/ui_bibz/strategies/component_initialize_block_strategy.rb +31 -0
- data/lib/ui_bibz/strategies/component_initialize_hash_strategy.rb +18 -0
- data/lib/ui_bibz/strategies/component_initialize_standard_strategy.rb +18 -0
- data/lib/ui_bibz/ui/concerns/card_itemable_concern.rb +4 -4
- data/lib/ui_bibz/ui/concerns/notification_concern.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/card.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/card_accordion.rb +4 -4
- data/lib/ui_bibz/ui/core/boxes/card_column.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/card_deck.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/card_grid.rb +0 -3
- data/lib/ui_bibz/ui/core/boxes/card_group.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/components/card_body.rb +9 -9
- data/lib/ui_bibz/ui/core/boxes/components/card_col.rb +2 -2
- data/lib/ui_bibz/ui/core/boxes/components/card_list_group.rb +1 -1
- data/lib/ui_bibz/ui/core/boxes/components/card_row.rb +1 -1
- data/lib/ui_bibz/ui/core/component.rb +13 -62
- data/lib/ui_bibz/ui/core/forms/buttons/button.rb +3 -1
- data/lib/ui_bibz/ui/core/forms/buttons/button_group.rb +11 -11
- data/lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb +7 -7
- data/lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb +2 -2
- data/lib/ui_bibz/ui/core/forms/choices/choice_group.rb +5 -6
- data/lib/ui_bibz/ui/core/forms/choices/components/choice.rb +1 -1
- data/lib/ui_bibz/ui/core/forms/dates/date_picker_field.rb +15 -15
- data/lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_link.rb +1 -1
- data/lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb +5 -5
- data/lib/ui_bibz/ui/core/forms/numbers/slider_field.rb +1 -1
- data/lib/ui_bibz/ui/core/forms/selects/dropdown_select_field.rb +10 -10
- data/lib/ui_bibz/ui/core/forms/selects/multi_column_field.rb +2 -2
- data/lib/ui_bibz/ui/core/forms/surrounds/surround_field.rb +32 -32
- data/lib/ui_bibz/ui/core/forms/textareas/markdown_editor_field.rb +7 -8
- data/lib/ui_bibz/ui/core/icons/components/glyph_text.rb +1 -1
- data/lib/ui_bibz/ui/core/icons/glyph.rb +4 -3
- data/lib/ui_bibz/ui/core/layouts/row.rb +2 -2
- data/lib/ui_bibz/ui/core/lists/components/list.rb +4 -4
- data/lib/ui_bibz/ui/core/lists/list_group.rb +1 -1
- data/lib/ui_bibz/ui/core/navigations/breadcrumb.rb +6 -4
- data/lib/ui_bibz/ui/core/navigations/components/nav_link_span.rb +1 -2
- data/lib/ui_bibz/ui/core/navigations/components/navbar_form.rb +6 -5
- data/lib/ui_bibz/ui/core/navigations/components/toolbar_form.rb +2 -2
- data/lib/ui_bibz/ui/core/navigations/nav.rb +10 -6
- data/lib/ui_bibz/ui/core/navigations/navbar.rb +21 -19
- data/lib/ui_bibz/ui/core/navigations/pagination.rb +3 -3
- data/lib/ui_bibz/ui/core/navigations/toolbar.rb +5 -5
- data/lib/ui_bibz/ui/core/notifications/alert.rb +4 -5
- data/lib/ui_bibz/ui/core/notifications/badge.rb +6 -2
- data/lib/ui_bibz/ui/core/notifications/components/toast_header.rb +1 -1
- data/lib/ui_bibz/ui/core/notifications/progress_bar.rb +3 -3
- data/lib/ui_bibz/ui/core/notifications/toast.rb +8 -9
- data/lib/ui_bibz/ui/core/windows/components/offcanvas_body.rb +47 -0
- data/lib/ui_bibz/ui/core/windows/components/offcanvas_header.rb +54 -0
- data/lib/ui_bibz/ui/core/windows/modal.rb +9 -9
- data/lib/ui_bibz/ui/core/windows/offcanvas.rb +84 -0
- data/lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb +4 -20
- data/lib/ui_bibz/ui/extensions/core/component/klass_extension.rb +11 -19
- data/lib/ui_bibz/ui/extensions/core/forms/connect_extension.rb +1 -1
- data/lib/ui_bibz/ui/ux/containers/components/panel_column.rb +3 -3
- data/lib/ui_bibz/ui/ux/containers/components/panel_deck.rb +3 -3
- data/lib/ui_bibz/ui/ux/containers/components/panel_group.rb +3 -3
- data/lib/ui_bibz/ui/ux/containers/components/panel_header.rb +4 -4
- data/lib/ui_bibz/ui/ux/containers/panel.rb +13 -13
- data/lib/ui_bibz/ui/ux/tables/components/actions.rb +4 -4
- data/lib/ui_bibz/ui/ux/tables/components/column.rb +1 -1
- data/lib/ui_bibz/ui/ux/tables/components/columns.rb +2 -2
- data/lib/ui_bibz/ui/ux/tables/extensions/sortable.rb +1 -1
- data/lib/ui_bibz/ui/ux/tables/table.rb +5 -5
- data/lib/ui_bibz/ui/ux/tables/table_card.rb +6 -6
- data/lib/ui_bibz/ui/ux/tables/table_search_field.rb +1 -1
- data/lib/ui_bibz/utils/breakdown_class_name_generator.rb +3 -3
- data/lib/ui_bibz/utils/screwdriver.rb +1 -1
- data/lib/ui_bibz/view_objects/glyph_component_view_object.rb +38 -0
- data/lib/ui_bibz.rb +25 -0
- data/test/builders/data_html_classes_builder_test.rb +37 -0
- data/test/builders/html_classes_builder_test.rb +76 -0
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/stylesheets/application.css +1 -15
- data/test/dummy/app/channels/application_cable/channel.rb +6 -0
- data/test/dummy/app/channels/application_cable/connection.rb +6 -0
- data/test/dummy/app/jobs/application_job.rb +9 -0
- data/test/dummy/app/mailers/application_mailer.rb +6 -0
- data/test/dummy/app/views/layouts/application.html.erb +10 -12
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/rails +3 -3
- data/test/dummy/bin/rake +2 -2
- data/test/dummy/bin/setup +12 -12
- data/test/dummy/config/application.rb +13 -17
- data/test/dummy/config/boot.rb +3 -3
- data/test/dummy/config/database.yml +2 -2
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +21 -16
- data/test/dummy/config/environments/production.rb +16 -41
- data/test/dummy/config/environments/test.rb +19 -8
- data/test/dummy/config/importmap.rb +11 -0
- data/test/dummy/config/initializers/content_security_policy.rb +21 -24
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -2
- data/test/dummy/config/initializers/inflections.rb +4 -4
- data/test/dummy/config/initializers/permissions_policy.rb +12 -0
- data/test/dummy/config/locales/en.yml +13 -3
- data/test/dummy/config/puma.rb +7 -2
- data/test/dummy/config/storage.yml +5 -5
- data/test/dummy/config.ru +2 -1
- data/test/simple_form_test.rb +24 -24
- data/test/ui/core/boxes/card_test.rb +2 -1
- data/test/ui/core/component_test.rb +2 -2
- data/test/ui/core/forms/buttons/button_group_test.rb +1 -1
- data/test/ui/core/forms/buttons/button_link_test.rb +1 -1
- data/test/ui/core/forms/buttons/button_refresh_test.rb +1 -1
- data/test/ui/core/forms/buttons/button_test.rb +2 -2
- data/test/ui/core/forms/choices/box_switch_field_test.rb +10 -10
- data/test/ui/core/forms/choices/checkbox_field_test.rb +1 -1
- data/test/ui/core/forms/choices/choice_group_test.rb +1 -1
- data/test/ui/core/forms/dropdowns/dropdown_test.rb +1 -1
- data/test/ui/core/forms/numbers/formula_field_test.rb +1 -1
- data/test/ui/core/forms/selects/dropdown_select_field_test.rb +2 -2
- data/test/ui/core/forms/selects/select_field_test.rb +1 -1
- data/test/ui/core/forms/surrounds/surround_field_test.rb +4 -4
- data/test/ui/core/forms/texts/auto_complete_field_test.rb +2 -2
- data/test/ui/core/icons/glyph_test.rb +8 -4
- data/test/ui/core/icons/star_test.rb +12 -6
- data/test/ui/core/navigations/breadcrumb_test.rb +1 -1
- data/test/ui/core/navigations/link_test.rb +1 -1
- data/test/ui/core/navigations/nav_test.rb +11 -0
- data/test/ui/core/notifications/alert_test.rb +1 -1
- data/test/ui/core/notifications/badge_test.rb +3 -3
- data/test/ui/core/notifications/popover_test.rb +4 -4
- data/test/ui/core/notifications/spinner_test.rb +1 -1
- data/test/ui/core/notifications/toast_test.rb +1 -1
- data/test/ui/core/notifications/tooltip_test.rb +4 -4
- data/test/ui/core/windows/offcanvas_test.rb +27 -0
- data/test/ui/ux/containers/panel_test.rb +1 -1
- data/test/ui/ux/tables/table_test.rb +3 -3
- data/test/view_objects/glyph_component_view_object_test.rb +17 -0
- data/ui_bibz.gemspec +6 -20
- data/vendor/assets/fonts/fontawesome/fa-brands-400.ttf +0 -0
- data/vendor/assets/fonts/fontawesome/fa-brands-400.woff2 +0 -0
- data/vendor/assets/fonts/fontawesome/fa-regular-400.ttf +0 -0
- data/vendor/assets/fonts/fontawesome/fa-regular-400.woff2 +0 -0
- data/vendor/assets/fonts/fontawesome/fa-solid-900.ttf +0 -0
- data/vendor/assets/fonts/fontawesome/fa-solid-900.woff2 +0 -0
- data/vendor/assets/fonts/fontawesome/fa-v4compatibility.ttf +0 -0
- data/vendor/assets/fonts/fontawesome/fa-v4compatibility.woff2 +0 -0
- data/vendor/assets/javascripts/bootstrap-markdown.js +1 -1555
- data/vendor/assets/javascripts/bootstrap-multiselect.min.js +40 -1176
- data/vendor/assets/javascripts/bootstrap-switch.min.js +9 -21
- data/vendor/assets/javascripts/bs-custom-file-input.min.js +0 -1
- data/vendor/assets/javascripts/fontawesome/all.js +5977 -0
- data/vendor/assets/javascripts/fontawesome/all.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/brands.js +749 -0
- data/vendor/assets/javascripts/fontawesome/brands.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/conflict-detection.js +1138 -0
- data/vendor/assets/javascripts/fontawesome/conflict-detection.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/fontawesome.js +3126 -0
- data/vendor/assets/javascripts/fontawesome/fontawesome.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/regular.js +445 -0
- data/vendor/assets/javascripts/fontawesome/regular.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/solid.js +1672 -0
- data/vendor/assets/javascripts/fontawesome/solid.min.js +6 -0
- data/vendor/assets/javascripts/fontawesome/v4-shims.js +225 -0
- data/vendor/assets/javascripts/fontawesome/v4-shims.min.js +6 -0
- data/vendor/assets/javascripts/fuzzysort.js +562 -0
- data/vendor/assets/javascripts/jquery-3.7.0.min.js +2 -0
- data/vendor/assets/javascripts/jquery.multi-select.min.js +725 -1
- data/vendor/assets/stylesheets/bootstrap-multiselect.sass +115 -0
- data/vendor/assets/stylesheets/bootstrap-switch.scss +211 -0
- data/vendor/assets/stylesheets/fontawesome/_animated.scss +142 -9
- data/vendor/assets/stylesheets/fontawesome/_bordered-pulled.scss +13 -13
- data/vendor/assets/stylesheets/fontawesome/_core.scss +28 -6
- data/vendor/assets/stylesheets/fontawesome/_fixed-width.scss +2 -1
- data/vendor/assets/stylesheets/fontawesome/_functions.scss +57 -0
- data/vendor/assets/stylesheets/fontawesome/_icons.scss +7 -1438
- data/vendor/assets/stylesheets/fontawesome/_list.scss +4 -4
- data/vendor/assets/stylesheets/fontawesome/_mixins.scss +53 -34
- data/vendor/assets/stylesheets/fontawesome/_rotated-flipped.scss +25 -18
- data/vendor/assets/stylesheets/fontawesome/_screen-reader.scss +12 -3
- data/vendor/assets/stylesheets/fontawesome/_shims.scss +640 -664
- data/vendor/assets/stylesheets/fontawesome/_sizing.scss +16 -0
- data/vendor/assets/stylesheets/fontawesome/_stacked.scss +5 -4
- data/vendor/assets/stylesheets/fontawesome/_variables.scss +4896 -1393
- data/vendor/assets/stylesheets/fontawesome/brands.scss +17 -10
- data/vendor/assets/stylesheets/fontawesome/fontawesome.scss +7 -2
- data/vendor/assets/stylesheets/fontawesome/regular.scss +13 -10
- data/vendor/assets/stylesheets/fontawesome/solid.scss +13 -11
- data/vendor/assets/stylesheets/fontawesome/v4-shims.scss +6 -1
- data/vendor/assets/stylesheets/multi-select.css +92 -0
- metadata +120 -348
- data/.gitlab-ci.yml +0 -17
- data/.travis.yml +0 -24
- data/lib/ui_bibz/ui/extensions/core/component/popover_extension.rb +0 -70
- data/structure.md +0 -68
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/javascripts/packs/index.js +0 -3
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -9
- data/test/dummy/config/initializers/assets.rb +0 -14
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -7
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/session_store.rb +0 -5
- data/test/dummy/config/initializers/ui_bibz.rb +0 -5
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -16
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/config/spring.rb +0 -8
- data/test/dummy/test/models/user_test.rb +0 -9
- data/vendor/assets/fonts/fa-brands-400.eot +0 -0
- data/vendor/assets/fonts/fa-brands-400.svg +0 -3570
- data/vendor/assets/fonts/fa-brands-400.ttf +0 -0
- data/vendor/assets/fonts/fa-brands-400.woff +0 -0
- data/vendor/assets/fonts/fa-brands-400.woff2 +0 -0
- data/vendor/assets/fonts/fa-regular-400.eot +0 -0
- data/vendor/assets/fonts/fa-regular-400.svg +0 -803
- data/vendor/assets/fonts/fa-regular-400.ttf +0 -0
- data/vendor/assets/fonts/fa-regular-400.woff +0 -0
- data/vendor/assets/fonts/fa-regular-400.woff2 +0 -0
- data/vendor/assets/fonts/fa-solid-900.eot +0 -0
- data/vendor/assets/fonts/fa-solid-900.svg +0 -4938
- data/vendor/assets/fonts/fa-solid-900.ttf +0 -0
- data/vendor/assets/fonts/fa-solid-900.woff +0 -0
- data/vendor/assets/fonts/fa-solid-900.woff2 +0 -0
- data/vendor/assets/javascripts/all.js +0 -4441
- data/vendor/assets/javascripts/all.min.js +0 -5
- data/vendor/assets/stylesheets/all.min.css +0 -5
- data/vendor/assets/stylesheets/fontawesome/_larger.scss +0 -23
- data/vendor/assets/stylesheets/svg-with-js.css +0 -5
- /data/{test/dummy/app/mailers/.keep → app/assets/stylesheets/sass/forms/_dropdown.sass} +0 -0
- /data/{test/dummy/app/views/users/index.html.erb → app/assets/stylesheets/sass/forms/_input_refresh_button.sass} +0 -0
@@ -1 +1,725 @@
|
|
1
|
-
!function(e){"use strict";var t=function(t,s){this.options=s,this.$element=e(t),this.$container=e("<div/>",{"class":"ms-container"}),this.$selectableContainer=e("<div/>",{"class":"ms-selectable"}),this.$selectionContainer=e("<div/>",{"class":"ms-selection"}),this.$selectableUl=e("<ul/>",{"class":"ms-list",tabindex:"-1"}),this.$selectionUl=e("<ul/>",{"class":"ms-list",tabindex:"-1"}),this.scrollTo=0,this.elemsSelector="li:visible:not(.ms-optgroup-label,.ms-optgroup-container,."+s.disabledClass+")"};t.prototype={constructor:t,init:function(){var t=this,s=this.$element;if(0===s.next(".ms-container").length){s.css({position:"absolute",left:"-9999px"}),s.attr("id",s.attr("id")?s.attr("id"):Math.ceil(1e3*Math.random())+"multiselect"),this.$container.attr("id","ms-"+s.attr("id")),this.$container.addClass(t.options.cssClass),s.find("option").each(function(){t.generateLisFromOption(this)}),this.$selectionUl.find(".ms-optgroup-label").hide(),t.options.selectableHeader&&t.$selectableContainer.append(t.options.selectableHeader),t.$selectableContainer.append(t.$selectableUl),t.options.selectableFooter&&t.$selectableContainer.append(t.options.selectableFooter),t.options.selectionHeader&&t.$selectionContainer.append(t.options.selectionHeader),t.$selectionContainer.append(t.$selectionUl),t.options.selectionFooter&&t.$selectionContainer.append(t.options.selectionFooter),t.$container.append(t.$selectableContainer),t.$container.append(t.$selectionContainer),s.after(t.$container),t.activeMouse(t.$selectableUl),t.activeKeyboard(t.$selectableUl);var l=t.options.dblClick?"dblclick":"click";t.$selectableUl.on(l,".ms-elem-selectable",function(){t.select(e(this).data("ms-value"))}),t.$selectionUl.on(l,".ms-elem-selection",function(){t.deselect(e(this).data("ms-value"))}),t.activeMouse(t.$selectionUl),t.activeKeyboard(t.$selectionUl),s.on("focus",function(){t.$selectableUl.focus()})}var i=s.find("option:selected").map(function(){return e(this).val()}).get();t.select(i,"init"),"function"==typeof t.options.afterInit&&t.options.afterInit.call(this,this.$container)},generateLisFromOption:function(t,s,l){for(var i=this,n=i.$element,o="",a=e(t),r=0;r<t.attributes.length;r++){var c=t.attributes[r];"value"!==c.name&&"disabled"!==c.name&&(o+=c.name+'="'+c.value+'" ')}var d=e("<li "+o+"><span>"+i.escapeHTML(a.text())+"</span></li>"),h=d.clone(),p=a.val(),f=i.sanitize(p);d.data("ms-value",p).addClass("ms-elem-selectable").attr("id",f+"-selectable"),h.data("ms-value",p).addClass("ms-elem-selection").attr("id",f+"-selection").hide(),(a.prop("disabled")||n.prop("disabled"))&&(h.addClass(i.options.disabledClass),d.addClass(i.options.disabledClass));var u=a.parent("optgroup");if(u.length>0){var m=u.attr("label"),v=i.sanitize(m),b=i.$selectableUl.find("#optgroup-selectable-"+v),g=i.$selectionUl.find("#optgroup-selection-"+v);if(0===b.length){var $='<li class="ms-optgroup-container"></li>',C='<ul class="ms-optgroup"><li class="ms-optgroup-label"><span>'+m+"</span></li></ul>";b=e($),g=e($),b.attr("id","optgroup-selectable-"+v),g.attr("id","optgroup-selection-"+v),b.append(e(C)),g.append(e(C)),i.options.selectableOptgroup&&(b.find(".ms-optgroup-label").on("click",function(){var t=u.children(":not(:selected, :disabled)").map(function(){return e(this).val()}).get();i.select(t)}),g.find(".ms-optgroup-label").on("click",function(){var t=u.children(":selected:not(:disabled)").map(function(){return e(this).val()}).get();i.deselect(t)})),i.$selectableUl.append(b),i.$selectionUl.append(g)}s=void 0==s?b.find("ul").children().length:s+1,d.insertAt(s,b.children()),h.insertAt(s,g.children())}else s=void 0==s?i.$selectableUl.children().length:s,d.insertAt(s,i.$selectableUl),h.insertAt(s,i.$selectionUl)},addOption:function(t){var s=this;void 0!==t.value&&null!==t.value&&(t=[t]),e.each(t,function(t,l){if(void 0!==l.value&&null!==l.value&&0===s.$element.find("option[value='"+l.value+"']").length){var i=e('<option value="'+l.value+'">'+l.text+"</option>"),t=parseInt("undefined"==typeof l.index?s.$element.children().length:l.index),n=void 0==l.nested?s.$element:e("optgroup[label='"+l.nested+"']");i.insertAt(t,n),s.generateLisFromOption(i.get(0),t,l.nested)}})},escapeHTML:function(t){return e("<div>").text(t).html()},activeKeyboard:function(t){var s=this;t.on("focus",function(){e(this).addClass("ms-focus")}).on("blur",function(){e(this).removeClass("ms-focus")}).on("keydown",function(l){switch(l.which){case 40:case 38:return l.preventDefault(),l.stopPropagation(),void s.moveHighlight(e(this),38===l.which?-1:1);case 37:case 39:return l.preventDefault(),l.stopPropagation(),void s.switchList(t);case 9:if(s.$element.is("[tabindex]")){l.preventDefault();var i=parseInt(s.$element.attr("tabindex"),10);return i=l.shiftKey?i-1:i+1,void e('[tabindex="'+i+'"]').focus()}l.shiftKey&&s.$element.trigger("focus")}return e.inArray(l.which,s.options.keySelect)>-1?(l.preventDefault(),l.stopPropagation(),void s.selectHighlighted(t)):void 0})},moveHighlight:function(e,t){var s=e.find(this.elemsSelector),l=s.filter(".ms-hover"),i=null,n=s.first().outerHeight(),o=e.height();"#"+this.$container.prop("id");if(s.removeClass("ms-hover"),1===t){if(i=l.nextAll(this.elemsSelector).first(),0===i.length){var a=l.parent();if(a.hasClass("ms-optgroup")){var r=a.parent(),c=r.next(":visible");i=c.length>0?c.find(this.elemsSelector).first():s.first()}else i=s.first()}}else if(-1===t&&(i=l.prevAll(this.elemsSelector).first(),0===i.length)){var a=l.parent();if(a.hasClass("ms-optgroup")){var r=a.parent(),d=r.prev(":visible");i=d.length>0?d.find(this.elemsSelector).last():s.last()}else i=s.last()}if(i.length>0){i.addClass("ms-hover");var h=e.scrollTop()+i.position().top-o/2+n/2;e.scrollTop(h)}},selectHighlighted:function(e){var t=e.find(this.elemsSelector),s=t.filter(".ms-hover").first();s.length>0&&(e.parent().hasClass("ms-selectable")?this.select(s.data("ms-value")):this.deselect(s.data("ms-value")),t.removeClass("ms-hover"))},switchList:function(e){e.blur(),this.$container.find(this.elemsSelector).removeClass("ms-hover"),e.parent().hasClass("ms-selectable")?this.$selectionUl.focus():this.$selectableUl.focus()},activeMouse:function(t){var s=this;this.$container.on("mouseenter",s.elemsSelector,function(){e(this).parents(".ms-container").find(s.elemsSelector).removeClass("ms-hover"),e(this).addClass("ms-hover")}),this.$container.on("mouseleave",s.elemsSelector,function(){e(this).parents(".ms-container").find(s.elemsSelector).removeClass("ms-hover")})},refresh:function(){this.destroy(),this.$element.multiSelect(this.options)},destroy:function(){e("#ms-"+this.$element.attr("id")).remove(),this.$element.css("position","").css("left",""),this.$element.removeData("multiselect")},select:function(t,s){"string"==typeof t&&(t=[t]);var l=this,i=this.$element,n=e.map(t,function(e){return l.sanitize(e)}),o=this.$selectableUl.find("#"+n.join("-selectable, #")+"-selectable").filter(":not(."+l.options.disabledClass+")"),a=this.$selectionUl.find("#"+n.join("-selection, #")+"-selection").filter(":not(."+l.options.disabledClass+")"),r=i.find("option:not(:disabled)").filter(function(){return e.inArray(this.value,t)>-1});if("init"===s&&(o=this.$selectableUl.find("#"+n.join("-selectable, #")+"-selectable"),a=this.$selectionUl.find("#"+n.join("-selection, #")+"-selection")),o.length>0){o.addClass("ms-selected").hide(),a.addClass("ms-selected").show(),r.prop("selected",!0),l.$container.find(l.elemsSelector).removeClass("ms-hover");var c=l.$selectableUl.children(".ms-optgroup-container");if(c.length>0){c.each(function(){var t=e(this).find(".ms-elem-selectable");t.length===t.filter(".ms-selected").length&&e(this).find(".ms-optgroup-label").hide()});var d=l.$selectionUl.children(".ms-optgroup-container");d.each(function(){var t=e(this).find(".ms-elem-selection");t.filter(".ms-selected").length>0&&e(this).find(".ms-optgroup-label").show()})}else if(l.options.keepOrder&&"init"!==s){var h=l.$selectionUl.find(".ms-selected");h.length>1&&h.last().get(0)!=a.get(0)&&a.insertAfter(h.last())}"init"!==s&&(i.trigger("change"),"function"==typeof l.options.afterSelect&&l.options.afterSelect.call(this,t))}},deselect:function(t){"string"==typeof t&&(t=[t]);var s=this,l=this.$element,i=e.map(t,function(e){return s.sanitize(e)}),n=this.$selectableUl.find("#"+i.join("-selectable, #")+"-selectable"),o=this.$selectionUl.find("#"+i.join("-selection, #")+"-selection").filter(".ms-selected").filter(":not(."+s.options.disabledClass+")"),a=l.find("option").filter(function(){return e.inArray(this.value,t)>-1});if(o.length>0){n.removeClass("ms-selected").show(),o.removeClass("ms-selected").hide(),a.prop("selected",!1),s.$container.find(s.elemsSelector).removeClass("ms-hover");var r=s.$selectableUl.children(".ms-optgroup-container");if(r.length>0){r.each(function(){var t=e(this).find(".ms-elem-selectable");t.filter(":not(.ms-selected)").length>0&&e(this).find(".ms-optgroup-label").show()});var c=s.$selectionUl.children(".ms-optgroup-container");c.each(function(){var t=e(this).find(".ms-elem-selection");0===t.filter(".ms-selected").length&&e(this).find(".ms-optgroup-label").hide()})}l.trigger("change"),"function"==typeof s.options.afterDeselect&&s.options.afterDeselect.call(this,t)}},select_all:function(){var t=this.$element,s=t.val();if(t.find('option:not(":disabled")').prop("selected",!0),this.$selectableUl.find(".ms-elem-selectable").filter(":not(."+this.options.disabledClass+")").addClass("ms-selected").hide(),this.$selectionUl.find(".ms-optgroup-label").show(),this.$selectableUl.find(".ms-optgroup-label").hide(),this.$selectionUl.find(".ms-elem-selection").filter(":not(."+this.options.disabledClass+")").addClass("ms-selected").show(),this.$selectionUl.focus(),t.trigger("change"),"function"==typeof this.options.afterSelect){var l=e.grep(t.val(),function(t){return e.inArray(t,s)<0});this.options.afterSelect.call(this,l)}},deselect_all:function(){var e=this.$element,t=e.val();e.find("option").prop("selected",!1),this.$selectableUl.find(".ms-elem-selectable").removeClass("ms-selected").show(),this.$selectionUl.find(".ms-optgroup-label").hide(),this.$selectableUl.find(".ms-optgroup-label").show(),this.$selectionUl.find(".ms-elem-selection").removeClass("ms-selected").hide(),this.$selectableUl.focus(),e.trigger("change"),"function"==typeof this.options.afterDeselect&&this.options.afterDeselect.call(this,t)},sanitize:function(e){var t,s,l=0;if(0==e.length)return l;var i=0;for(t=0,i=e.length;i>t;t++)s=e.charCodeAt(t),l=(l<<5)-l+s,l|=0;return l}},e.fn.multiSelect=function(){var s=arguments[0],l=arguments;return this.each(function(){var i=e(this),n=i.data("multiselect"),o=e.extend({},e.fn.multiSelect.defaults,i.data(),"object"==typeof s&&s);n||i.data("multiselect",n=new t(this,o)),"string"==typeof s?n[s](l[1]):n.init()})},e.fn.multiSelect.defaults={keySelect:[32],selectableOptgroup:!1,disabledClass:"disabled",dblClick:!1,keepOrder:!1,cssClass:""},e.fn.multiSelect.Constructor=t,e.fn.insertAt=function(e,t){return this.each(function(){0===e?t.prepend(this):t.children().eq(e-1).after(this)})}}(window.jQuery);
|
1
|
+
/*
|
2
|
+
* MultiSelect v0.9.12
|
3
|
+
* Copyright (c) 2012 Louis Cuny
|
4
|
+
*
|
5
|
+
* This program is free software. It comes without any warranty, to
|
6
|
+
* the extent permitted by applicable law. You can redistribute it
|
7
|
+
* and/or modify it under the terms of the Do What The Fuck You Want
|
8
|
+
* To Public License, Version 2, as published by Sam Hocevar. See
|
9
|
+
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
10
|
+
*/
|
11
|
+
|
12
|
+
(function (root, factory) {
|
13
|
+
if (root === undefined && window !== undefined) root = window;
|
14
|
+
if (typeof define === 'function' && define.amd) {
|
15
|
+
// AMD. Register as an anonymous module unless amdModuleId is set
|
16
|
+
define(["jquery"], function (a0) {
|
17
|
+
return (factory(a0));
|
18
|
+
});
|
19
|
+
} else if (typeof module === 'object' && module.exports) {
|
20
|
+
// Node. Does not work with strict CommonJS, but
|
21
|
+
// only CommonJS-like environments that support module.exports,
|
22
|
+
// like Node.
|
23
|
+
module.exports = factory(require("jquery"));
|
24
|
+
} else {
|
25
|
+
factory(root["jQuery"]);
|
26
|
+
}
|
27
|
+
}(this, function (jQuery) {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
// add a case insensitive contains selector to jQuery ":icontains"
|
32
|
+
$.expr[':'].icontains = function(a, i, m) {
|
33
|
+
return jQuery(a).text().toUpperCase()
|
34
|
+
.indexOf(m[3].toUpperCase()) >= 0;
|
35
|
+
};
|
36
|
+
|
37
|
+
var multi$;
|
38
|
+
|
39
|
+
(function ($) {
|
40
|
+
|
41
|
+
"use strict";
|
42
|
+
|
43
|
+
|
44
|
+
/* MULTISELECT CLASS DEFINITION
|
45
|
+
* ====================== */
|
46
|
+
|
47
|
+
var MultiSelect = function (element, options) {
|
48
|
+
this.options = options;
|
49
|
+
this.$element = $(element);
|
50
|
+
this.$orig = $(element).clone();
|
51
|
+
this.$container = $('<div/>', { 'class': "ms-container" });
|
52
|
+
this.$selectableContainer = $('<div/>', { 'class': 'ms-selectable' });
|
53
|
+
this.$selectionContainer = $('<div/>', { 'class': 'ms-selection' });
|
54
|
+
this.$selectableUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
|
55
|
+
this.$selectionUl = $('<ul/>', { 'class': "ms-list", 'tabindex' : '-1' });
|
56
|
+
this.scrollTo = 0;
|
57
|
+
this.elemsSelector = "li[style!='display: none;']:not(.ms-optgroup-label,.ms-optgroup-container,."+options.disabledClass+")";
|
58
|
+
};
|
59
|
+
|
60
|
+
MultiSelect.prototype = {
|
61
|
+
constructor: MultiSelect,
|
62
|
+
|
63
|
+
init: function(){
|
64
|
+
var that = this,
|
65
|
+
ms = this.$element;
|
66
|
+
|
67
|
+
if (ms.next('.ms-container').length === 0){
|
68
|
+
ms.css({ position: 'absolute', left: '-9999px' });
|
69
|
+
ms.attr('id', ms.attr('id') ? ms.attr('id') : Math.ceil(Math.random()*1000)+'multiselect');
|
70
|
+
this.$container.attr('id', 'ms-'+ms.attr('id'));
|
71
|
+
this.$container.addClass(that.options.cssClass);
|
72
|
+
ms.find('option').each(function(){
|
73
|
+
that.generateListFromOption(this);
|
74
|
+
});
|
75
|
+
|
76
|
+
this.$selectionUl.find('.ms-optgroup-label').hide();
|
77
|
+
|
78
|
+
if (that.options.selectableHeader){
|
79
|
+
that.$selectableContainer.append(that.options.selectableHeader);
|
80
|
+
}
|
81
|
+
if (that.options.searchEngine){
|
82
|
+
that.$container.append($("<div class='ms-search-wrapper'><span class='icon-search'></span><input type='text' class='ms-search form-control' /></div>"));
|
83
|
+
that.$container.on('keyup', '.ms-search', function() {
|
84
|
+
that.filter($(this).val());
|
85
|
+
});
|
86
|
+
}
|
87
|
+
that.$selectableContainer.append(that.$selectableUl);
|
88
|
+
if (that.options.selectableFooter){
|
89
|
+
that.$selectableContainer.append(that.options.selectableFooter);
|
90
|
+
}
|
91
|
+
|
92
|
+
if (that.options.selectionHeader){
|
93
|
+
that.$selectionContainer.append(that.options.selectionHeader);
|
94
|
+
}
|
95
|
+
if (that.options.selectionSearch){
|
96
|
+
that.$selectionContainer.append($("<input type='text' class='ms--search' />"));
|
97
|
+
}
|
98
|
+
that.$selectionContainer.append(that.$selectionUl);
|
99
|
+
if (that.options.selectionFooter){
|
100
|
+
that.$selectionContainer.append(that.options.selectionFooter);
|
101
|
+
}
|
102
|
+
|
103
|
+
that.$container.append(that.$selectableContainer);
|
104
|
+
that.$container.append(that.$selectionContainer);
|
105
|
+
ms.after(that.$container);
|
106
|
+
|
107
|
+
that.activeMouse(that.$selectableUl);
|
108
|
+
that.activeKeyboard(that.$selectableUl);
|
109
|
+
|
110
|
+
var action = that.options.dblClick ? 'dblclick' : 'click';
|
111
|
+
var selector = that.options.selectButton ? '.select-button' : '';
|
112
|
+
|
113
|
+
that.$selectableUl.on(action, '.ms-elem-selectable '+ selector, function(){
|
114
|
+
var value = $(this).data('ms-value') || $(this).parents("li").data('ms-value');
|
115
|
+
that.select(value);
|
116
|
+
if ($.isFunction(that.options.selectButton)) {
|
117
|
+
that.options.selectButton($(this));
|
118
|
+
}
|
119
|
+
});
|
120
|
+
that.$selectionUl.on(action, '.ms-elem-selection '+ selector, function(){
|
121
|
+
var value = $(this).data('ms-value') || $(this).parents("li").data('ms-value');
|
122
|
+
that.deselect(value);
|
123
|
+
if ($.isFunction(that.options.selectButton)) {
|
124
|
+
that.options.selectButton($(this));
|
125
|
+
}
|
126
|
+
});
|
127
|
+
|
128
|
+
if ($.isFunction(that.options.previewButton)) {
|
129
|
+
that.$selectableUl.on(action, '.ms-elem-selectable .preview-button', that.options.previewButton);
|
130
|
+
that.$selectionUl.on(action, '.ms-elem-selection .preview-button', that.options.previewButton);
|
131
|
+
}
|
132
|
+
|
133
|
+
if (that.options.selectAll) {
|
134
|
+
that.$container.find(that.options.selectAll).click(function() {
|
135
|
+
that.select_all();
|
136
|
+
});
|
137
|
+
}
|
138
|
+
if (that.options.deselectAll) {
|
139
|
+
that.$container.find(that.options.deselectAll).click(function() {
|
140
|
+
that.deselect_all();
|
141
|
+
});
|
142
|
+
}
|
143
|
+
if (that.options.refreshClass) {
|
144
|
+
that.$container.find(that.options.refreshClass).click(function() {
|
145
|
+
that.refresh();
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
that.activeMouse(that.$selectionUl);
|
150
|
+
that.activeKeyboard(that.$selectionUl);
|
151
|
+
|
152
|
+
ms.on('focus', function(){
|
153
|
+
that.$selectableUl.focus();
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
157
|
+
var selectedValues = ms.find('option:selected').map(function(){ return $(this).val(); }).get();
|
158
|
+
that.select(selectedValues, 'init');
|
159
|
+
|
160
|
+
if (typeof that.options.afterInit === 'function') {
|
161
|
+
that.options.afterInit.call(this, this.$container);
|
162
|
+
}
|
163
|
+
|
164
|
+
that.$container.siblings(".add-another").hide();
|
165
|
+
|
166
|
+
// ugly
|
167
|
+
if (typeof post_multiselect_init === "function") {
|
168
|
+
post_multiselect_init(that);
|
169
|
+
}
|
170
|
+
},
|
171
|
+
|
172
|
+
|
173
|
+
'filter': function(value){
|
174
|
+
var that = this;
|
175
|
+
|
176
|
+
if (value == "")
|
177
|
+
that.$container.find("li").removeClass("unmatched");
|
178
|
+
else {
|
179
|
+
// hide all
|
180
|
+
that.$container.find("li").addClass("unmatched");
|
181
|
+
|
182
|
+
// show matching li AND the optgroup label if it exists
|
183
|
+
that.$container.find("li:icontains('"+value+"')").removeClass("unmatched")
|
184
|
+
.prev(".ms-optgroup-label").removeClass("unmatched");
|
185
|
+
|
186
|
+
// show the whole optgroup if the value matches an optgroup label
|
187
|
+
that.$container.find("li.ms-optgroup-label:icontains('"+value+"')")
|
188
|
+
.siblings("li").removeClass("unmatched");
|
189
|
+
}
|
190
|
+
},
|
191
|
+
|
192
|
+
|
193
|
+
'generateListFromOption' : function(option, index, $container){
|
194
|
+
var that = this,
|
195
|
+
ms = that.$element,
|
196
|
+
attributes = "",
|
197
|
+
$option = $(option);
|
198
|
+
|
199
|
+
for (var cpt = 0; cpt < option.attributes.length; cpt++){
|
200
|
+
var attr = option.attributes[cpt];
|
201
|
+
|
202
|
+
if(attr.name !== 'value' && attr.name !== 'disabled'){
|
203
|
+
attributes += attr.name+'="'+attr.value+'" ';
|
204
|
+
}
|
205
|
+
}
|
206
|
+
var selectableLi = $('<li '+attributes+'><span>'+that.escapeHTML($option.text())+'</span></li>'),
|
207
|
+
selectedLi = selectableLi.clone(),
|
208
|
+
value = $option.val(),
|
209
|
+
elementId = that.sanitize(value);
|
210
|
+
|
211
|
+
selectableLi
|
212
|
+
.data('ms-value', value)
|
213
|
+
.addClass('ms-elem-selectable')
|
214
|
+
.attr('id', elementId+'-selectable');
|
215
|
+
|
216
|
+
if($option.attr("disabled") == "disabled"){
|
217
|
+
selectableLi
|
218
|
+
.prop('disabled', true)
|
219
|
+
.addClass('disabled')
|
220
|
+
}
|
221
|
+
|
222
|
+
selectedLi
|
223
|
+
.data('ms-value', value)
|
224
|
+
.addClass('ms-elem-selection')
|
225
|
+
.attr('id', elementId+'-selection')
|
226
|
+
.hide();
|
227
|
+
|
228
|
+
if ($option.prop('disabled') || ms.prop('disabled')){
|
229
|
+
selectedLi.addClass(that.options.disabledClass);
|
230
|
+
selectableLi.addClass(that.options.disabledClass);
|
231
|
+
}
|
232
|
+
|
233
|
+
var $optgroup = $option.parent('optgroup');
|
234
|
+
|
235
|
+
if ($optgroup.length > 0){
|
236
|
+
var optgroupLabel = $optgroup.attr('label'),
|
237
|
+
optgroupId = that.sanitize(optgroupLabel),
|
238
|
+
$selectableOptgroup = that.$selectableUl.find('#optgroup-selectable-'+optgroupId),
|
239
|
+
$selectionOptgroup = that.$selectionUl.find('#optgroup-selection-'+optgroupId);
|
240
|
+
|
241
|
+
if ($selectableOptgroup.length === 0){
|
242
|
+
var optgroupContainerTpl = '<li class="ms-optgroup-container"></li>',
|
243
|
+
optgroupTpl = '<ul class="ms-optgroup"><li class="ms-optgroup-label"><span>'+optgroupLabel+'</span></li></ul>';
|
244
|
+
|
245
|
+
$selectableOptgroup = $(optgroupContainerTpl);
|
246
|
+
$selectionOptgroup = $(optgroupContainerTpl);
|
247
|
+
$selectableOptgroup.attr('id', 'optgroup-selectable-'+optgroupId);
|
248
|
+
$selectionOptgroup.attr('id', 'optgroup-selection-'+optgroupId);
|
249
|
+
$selectableOptgroup.append($(optgroupTpl));
|
250
|
+
$selectionOptgroup.append($(optgroupTpl));
|
251
|
+
if (that.options.selectableOptgroup){
|
252
|
+
$selectableOptgroup.find('.ms-optgroup-label').on('click', function(){
|
253
|
+
var values = $optgroup.children(':not(:selected, :disabled)').map(function(){ return $(this).val();}).get();
|
254
|
+
that.select(values);
|
255
|
+
});
|
256
|
+
$selectionOptgroup.find('.ms-optgroup-label').on('click', function(){
|
257
|
+
var values = $optgroup.children(':selected:not(:disabled)').map(function(){ return $(this).val();}).get();
|
258
|
+
that.deselect(values);
|
259
|
+
});
|
260
|
+
}
|
261
|
+
that.$selectableUl.append($selectableOptgroup);
|
262
|
+
that.$selectionUl.append($selectionOptgroup);
|
263
|
+
}
|
264
|
+
index = index === undefined ? $selectableOptgroup.find('ul').children().length : index + 1;
|
265
|
+
selectableLi.insertAt(index, $selectableOptgroup.children());
|
266
|
+
selectedLi.insertAt(index, $selectionOptgroup.children());
|
267
|
+
} else {
|
268
|
+
index = index === undefined ? that.$selectableUl.children().length : index;
|
269
|
+
|
270
|
+
selectableLi.insertAt(index, that.$selectableUl);
|
271
|
+
selectedLi.insertAt(index, that.$selectionUl);
|
272
|
+
}
|
273
|
+
},
|
274
|
+
|
275
|
+
'addOption' : function(options){
|
276
|
+
var that = this;
|
277
|
+
|
278
|
+
if (options.value !== undefined && options.value !== null){
|
279
|
+
options = [options];
|
280
|
+
}
|
281
|
+
$.each(options, function(index, option){
|
282
|
+
if (option.value !== undefined && option.value !== null &&
|
283
|
+
that.$element.find("option[value='"+option.value+"']").length === 0) {
|
284
|
+
var $option = $('<option value="'+option.value+'">'+option.text+'</option>'),
|
285
|
+
$container = option.nested === undefined ? that.$element : that.$element.find("optgroup[label='"+option.nested+"']"),
|
286
|
+
index = parseInt((typeof option.index === 'undefined' ? $container.children().length : option.index));
|
287
|
+
|
288
|
+
// if the optgroup does not exist, create it
|
289
|
+
if (option.nested && $container.length == 0) {
|
290
|
+
$container = $('<optgroup label="'+ option.nested+'" />');
|
291
|
+
$container.insertAt(index, that.$element);
|
292
|
+
index = 0;
|
293
|
+
}
|
294
|
+
if (option.optionClass) {
|
295
|
+
$option.addClass(option.optionClass);
|
296
|
+
}
|
297
|
+
|
298
|
+
if (option.disabled) {
|
299
|
+
$option.prop('disabled', true);
|
300
|
+
}
|
301
|
+
|
302
|
+
$option.insertAt(index, $container);
|
303
|
+
that.generateListFromOption($option.get(0), index, option.nested);
|
304
|
+
}
|
305
|
+
});
|
306
|
+
that.updateCounters();
|
307
|
+
},
|
308
|
+
|
309
|
+
'removeOption' : function(options){
|
310
|
+
var that = this;
|
311
|
+
|
312
|
+
if (options.value !== undefined && options.value !== null){
|
313
|
+
options = [options];
|
314
|
+
}
|
315
|
+
// first deselect all (to eventually trigger other events
|
316
|
+
$.each(options, function(index, option) {
|
317
|
+
if (option.value !== undefined && option.value !== null) {
|
318
|
+
that.$selectionUl.find("li").each(function(cnt, li) {
|
319
|
+
if ($(li).data("ms-value") == option.value) {
|
320
|
+
that.deselect($(li).data("ms-value"));
|
321
|
+
}
|
322
|
+
});
|
323
|
+
}
|
324
|
+
});
|
325
|
+
|
326
|
+
// then remove options from selectable list
|
327
|
+
$.each(options, function(index, option) {
|
328
|
+
if (option.value !== undefined && option.value !== null) {
|
329
|
+
var $option = that.$element.find("option[value='"+option.value+"']");
|
330
|
+
if ($option.length === 1) {
|
331
|
+
var $containerli;
|
332
|
+
var $container = $option.parent("optgroup");
|
333
|
+
$option.remove();
|
334
|
+
|
335
|
+
that.$selectableUl.find("li").each(function(cnt, li) {
|
336
|
+
if ($(li).data("ms-value") == option.value) {
|
337
|
+
$containerli = $(li).parents(".ms-optgroup-container");
|
338
|
+
$(li).remove();
|
339
|
+
if ($containerli.find('.ms-elem-selectable').length == 0) {
|
340
|
+
$containerli.remove();
|
341
|
+
$container.remove();
|
342
|
+
}
|
343
|
+
}
|
344
|
+
});
|
345
|
+
}
|
346
|
+
}
|
347
|
+
});
|
348
|
+
that.updateCounters();
|
349
|
+
},
|
350
|
+
|
351
|
+
'escapeHTML' : function(text){
|
352
|
+
var escaped = "";
|
353
|
+
if (this.options.previewButton) {
|
354
|
+
escaped += $("<span class='preview-button icon icon-eye'>")[0].outerHTML;
|
355
|
+
}
|
356
|
+
escaped += "<span class='ms-overflow-text'>" + $("<div>").text(text).html() + "</span>";
|
357
|
+
if (this.options.selectButton) {
|
358
|
+
escaped += $("<span class='select-button icon icon-selector'>")[0].outerHTML;
|
359
|
+
}
|
360
|
+
return escaped;
|
361
|
+
},
|
362
|
+
|
363
|
+
'activeKeyboard' : function($list){
|
364
|
+
var that = this;
|
365
|
+
|
366
|
+
$list.on('focus', function(){
|
367
|
+
$(this).addClass('ms-focus');
|
368
|
+
})
|
369
|
+
.on('blur', function(){
|
370
|
+
$(this).removeClass('ms-focus');
|
371
|
+
})
|
372
|
+
.on('keydown', function(e){
|
373
|
+
switch (e.which) {
|
374
|
+
case 40:
|
375
|
+
case 38:
|
376
|
+
e.preventDefault();
|
377
|
+
e.stopPropagation();
|
378
|
+
that.moveHighlight($(this), (e.which === 38) ? -1 : 1);
|
379
|
+
return;
|
380
|
+
case 37:
|
381
|
+
case 39:
|
382
|
+
e.preventDefault();
|
383
|
+
e.stopPropagation();
|
384
|
+
that.switchList($list);
|
385
|
+
return;
|
386
|
+
case 9:
|
387
|
+
if(that.$element.is('[tabindex]')){
|
388
|
+
e.preventDefault();
|
389
|
+
var tabindex = parseInt(that.$element.attr('tabindex'), 10);
|
390
|
+
tabindex = (e.shiftKey) ? tabindex-1 : tabindex+1;
|
391
|
+
$('[tabindex="'+(tabindex)+'"]').focus();
|
392
|
+
return;
|
393
|
+
}else{
|
394
|
+
if(e.shiftKey){
|
395
|
+
that.$element.trigger('focus');
|
396
|
+
}
|
397
|
+
}
|
398
|
+
}
|
399
|
+
if($.inArray(e.which, that.options.keySelect) > -1){
|
400
|
+
e.preventDefault();
|
401
|
+
e.stopPropagation();
|
402
|
+
that.selectHighlighted($list);
|
403
|
+
return;
|
404
|
+
}
|
405
|
+
});
|
406
|
+
},
|
407
|
+
|
408
|
+
'moveHighlight': function($list, direction){
|
409
|
+
var $elems = $list.find(this.elemsSelector),
|
410
|
+
$currElem = $elems.filter('.ms-hover'),
|
411
|
+
$nextElem = null,
|
412
|
+
elemHeight = $elems.first().outerHeight(),
|
413
|
+
containerHeight = $list.height(),
|
414
|
+
containerSelector = '#'+this.$container.prop('id');
|
415
|
+
|
416
|
+
$elems.removeClass('ms-hover');
|
417
|
+
if (direction === 1){ // DOWN
|
418
|
+
|
419
|
+
$nextElem = $currElem.nextAll(this.elemsSelector).first();
|
420
|
+
if ($nextElem.length === 0){
|
421
|
+
var $optgroupUl = $currElem.parent();
|
422
|
+
|
423
|
+
if ($optgroupUl.hasClass('ms-optgroup')){
|
424
|
+
var $optgroupLi = $optgroupUl.parent(),
|
425
|
+
$nextOptgroupLi = $optgroupLi.next("[style!='display: none;']");
|
426
|
+
|
427
|
+
if ($nextOptgroupLi.length > 0){
|
428
|
+
$nextElem = $nextOptgroupLi.find(this.elemsSelector).first();
|
429
|
+
} else {
|
430
|
+
$nextElem = $elems.first();
|
431
|
+
}
|
432
|
+
} else {
|
433
|
+
$nextElem = $elems.first();
|
434
|
+
}
|
435
|
+
}
|
436
|
+
} else if (direction === -1){ // UP
|
437
|
+
|
438
|
+
$nextElem = $currElem.prevAll(this.elemsSelector).first();
|
439
|
+
if ($nextElem.length === 0){
|
440
|
+
var $optgroupUl = $currElem.parent();
|
441
|
+
|
442
|
+
if ($optgroupUl.hasClass('ms-optgroup')){
|
443
|
+
var $optgroupLi = $optgroupUl.parent(),
|
444
|
+
$prevOptgroupLi = $optgroupLi.prev("[style!='display: none;']");
|
445
|
+
|
446
|
+
if ($prevOptgroupLi.length > 0){
|
447
|
+
$nextElem = $prevOptgroupLi.find(this.elemsSelector).last();
|
448
|
+
} else {
|
449
|
+
$nextElem = $elems.last();
|
450
|
+
}
|
451
|
+
} else {
|
452
|
+
$nextElem = $elems.last();
|
453
|
+
}
|
454
|
+
}
|
455
|
+
}
|
456
|
+
if ($nextElem.length > 0){
|
457
|
+
$nextElem.addClass('ms-hover');
|
458
|
+
var scrollTo = $list.scrollTop() + $nextElem.position().top -
|
459
|
+
containerHeight / 2 + elemHeight / 2;
|
460
|
+
|
461
|
+
$list.scrollTop(scrollTo);
|
462
|
+
}
|
463
|
+
},
|
464
|
+
|
465
|
+
'selectHighlighted' : function($list){
|
466
|
+
var $elems = $list.find(this.elemsSelector),
|
467
|
+
$highlightedElem = $elems.filter('.ms-hover').first();
|
468
|
+
|
469
|
+
if ($highlightedElem.length > 0){
|
470
|
+
if ($list.parent().hasClass('ms-selectable')){
|
471
|
+
this.select($highlightedElem.data('ms-value'));
|
472
|
+
} else {
|
473
|
+
this.deselect($highlightedElem.data('ms-value'));
|
474
|
+
}
|
475
|
+
$elems.removeClass('ms-hover');
|
476
|
+
}
|
477
|
+
},
|
478
|
+
|
479
|
+
'switchList' : function($list){
|
480
|
+
$list.blur();
|
481
|
+
this.$container.find(this.elemsSelector).removeClass('ms-hover');
|
482
|
+
if ($list.parent().hasClass('ms-selectable')){
|
483
|
+
this.$selectionUl.focus();
|
484
|
+
} else {
|
485
|
+
this.$selectableUl.focus();
|
486
|
+
}
|
487
|
+
},
|
488
|
+
|
489
|
+
'activeMouse' : function($list){
|
490
|
+
var that = this;
|
491
|
+
|
492
|
+
this.$container.on('mouseenter', that.elemsSelector, function(){
|
493
|
+
$(this).parents('.ms-container').find(that.elemsSelector).removeClass('ms-hover');
|
494
|
+
$(this).addClass('ms-hover');
|
495
|
+
});
|
496
|
+
|
497
|
+
this.$container.on('mouseleave', that.elemsSelector, function () {
|
498
|
+
$(this).parents('.ms-container').find(that.elemsSelector).removeClass('ms-hover');
|
499
|
+
});
|
500
|
+
},
|
501
|
+
|
502
|
+
'refresh' : function() {
|
503
|
+
this.destroy();
|
504
|
+
this.$element.html(this.$orig.html());
|
505
|
+
this.$element.multiSelect(this.options);
|
506
|
+
},
|
507
|
+
|
508
|
+
'destroy' : function(){
|
509
|
+
$("#ms-"+this.$element.attr("id")).remove();
|
510
|
+
this.$element.off('focus');
|
511
|
+
this.$element.css('position', '').css('left', '');
|
512
|
+
this.$element.removeData('multiselect');
|
513
|
+
},
|
514
|
+
|
515
|
+
'updateCounters': function(){
|
516
|
+
if (this.options.counterClass) {
|
517
|
+
this.$container.find(".ms-selectable "+this.options.counterClass).text(this.$selectableUl.find(".ms-elem-selectable").filter("[style!='display: none;']").length);
|
518
|
+
this.$container.find(".ms-selection "+this.options.counterClass).text(this.$selectionUl.find(".ms-elem-selection").filter("[style!='display: none;']").length);
|
519
|
+
}
|
520
|
+
},
|
521
|
+
|
522
|
+
'select' : function(value, method){
|
523
|
+
if (typeof value === 'string' ||typeof value === 'number') {
|
524
|
+
value = ['' + value];
|
525
|
+
}
|
526
|
+
|
527
|
+
var that = this,
|
528
|
+
ms = this.$element,
|
529
|
+
msIds = $.map(value, function(val){ return(that.sanitize(val)); }),
|
530
|
+
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'),
|
531
|
+
selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection').filter(':not(.'+that.options.disabledClass+')'),
|
532
|
+
options = ms.find('option:not(:disabled)').filter(function(){ return($.inArray(this.value, value) > -1); });
|
533
|
+
|
534
|
+
if (method === 'init'){
|
535
|
+
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'),
|
536
|
+
selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection');
|
537
|
+
}
|
538
|
+
|
539
|
+
if (selectables.length > 0){
|
540
|
+
selectables.addClass('ms-selected').hide();
|
541
|
+
selections.addClass('ms-selected').show();
|
542
|
+
|
543
|
+
options.prop('selected', true);
|
544
|
+
|
545
|
+
that.$container.find(that.elemsSelector).removeClass('ms-hover');
|
546
|
+
|
547
|
+
var selectableOptgroups = that.$selectableUl.children('.ms-optgroup-container').not(".unmatched");
|
548
|
+
if (selectableOptgroups.length > 0){
|
549
|
+
selectableOptgroups.each(function(){
|
550
|
+
var selectablesLi = $(this).find('.ms-elem-selectable');
|
551
|
+
if (selectablesLi.length === selectablesLi.filter('.ms-selected').length){
|
552
|
+
$(this).find('.ms-optgroup-label').hide();
|
553
|
+
}
|
554
|
+
});
|
555
|
+
|
556
|
+
var selectionOptgroups = that.$selectionUl.children('.ms-optgroup-container').not(".unmatched");
|
557
|
+
selectionOptgroups.each(function(){
|
558
|
+
var selectionsLi = $(this).find('.ms-elem-selection');
|
559
|
+
if (selectionsLi.filter('.ms-selected').length > 0){
|
560
|
+
$(this).find('.ms-optgroup-label').show();
|
561
|
+
}
|
562
|
+
});
|
563
|
+
} else {
|
564
|
+
if (that.options.keepOrder && method !== 'init'){
|
565
|
+
var selectionLiLast = that.$selectionUl.find('.ms-selected');
|
566
|
+
if((selectionLiLast.length > 1) && (selectionLiLast.last().get(0) != selections.get(0))) {
|
567
|
+
selections.insertAfter(selectionLiLast.last());
|
568
|
+
}
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
if (method !== 'init'){
|
573
|
+
ms.trigger('change');
|
574
|
+
if (typeof that.options.afterSelect === 'function') {
|
575
|
+
that.options.afterSelect.call(this, value);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
}
|
579
|
+
that.updateCounters();
|
580
|
+
},
|
581
|
+
|
582
|
+
'deselect' : function(value){
|
583
|
+
if (typeof value === 'string'){ value = [value]; }
|
584
|
+
|
585
|
+
var that = this,
|
586
|
+
ms = this.$element,
|
587
|
+
msIds = $.map(value, function(val){ return(that.sanitize(val)); }),
|
588
|
+
selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'),
|
589
|
+
selections = this.$selectionUl.find('#' + msIds.join('-selection, #')+'-selection').filter('.ms-selected').filter(':not(.'+that.options.disabledClass+')'),
|
590
|
+
options = ms.find('option').filter(function(){ return($.inArray(this.value, value) > -1); });
|
591
|
+
|
592
|
+
if (selections.length > 0){
|
593
|
+
selectables.removeClass('ms-selected').show();
|
594
|
+
selections.removeClass('ms-selected').hide();
|
595
|
+
options.prop('selected', false);
|
596
|
+
|
597
|
+
that.$container.find(that.elemsSelector).removeClass('ms-hover');
|
598
|
+
|
599
|
+
var selectableOptgroups = that.$selectableUl.children('.ms-optgroup-container').not(".unmatched");
|
600
|
+
if (selectableOptgroups.length > 0){
|
601
|
+
selectableOptgroups.each(function(){
|
602
|
+
var selectablesLi = $(this).find('.ms-elem-selectable');
|
603
|
+
if (selectablesLi.filter(':not(.ms-selected)').length > 0){
|
604
|
+
$(this).find('.ms-optgroup-label').show();
|
605
|
+
}
|
606
|
+
});
|
607
|
+
|
608
|
+
var selectionOptgroups = that.$selectionUl.children('.ms-optgroup-container').not(".unmatched");
|
609
|
+
selectionOptgroups.each(function(){
|
610
|
+
var selectionsLi = $(this).find('.ms-elem-selection');
|
611
|
+
if (selectionsLi.filter('.ms-selected').length === 0){
|
612
|
+
$(this).find('.ms-optgroup-label').hide();
|
613
|
+
}
|
614
|
+
});
|
615
|
+
}
|
616
|
+
ms.trigger('change');
|
617
|
+
that.updateCounters();
|
618
|
+
|
619
|
+
if (typeof that.options.afterDeselect === 'function') {
|
620
|
+
that.options.afterDeselect.call(this, value);
|
621
|
+
}
|
622
|
+
}
|
623
|
+
},
|
624
|
+
|
625
|
+
'select_all' : function(){
|
626
|
+
var ms = this.$element,
|
627
|
+
values = ms.val();
|
628
|
+
|
629
|
+
ms.find('option:not(":disabled")').prop('selected', true);
|
630
|
+
this.$selectableUl.find('.ms-elem-selectable').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').hide();
|
631
|
+
this.$selectionUl.find('.ms-optgroup-label').show();
|
632
|
+
this.$selectableUl.find('.ms-optgroup-label').hide();
|
633
|
+
this.$selectionUl.find('.ms-elem-selection').filter(':not(.'+this.options.disabledClass+')').addClass('ms-selected').show();
|
634
|
+
this.$selectionUl.focus();
|
635
|
+
|
636
|
+
ms.trigger('change');
|
637
|
+
this.updateCounters();
|
638
|
+
|
639
|
+
if (typeof this.options.afterSelect === 'function') {
|
640
|
+
var selectedValues = $.grep(ms.val(), function(item){
|
641
|
+
return $.inArray(item, values) < 0;
|
642
|
+
});
|
643
|
+
this.options.afterSelect.call(this, selectedValues);
|
644
|
+
}
|
645
|
+
},
|
646
|
+
|
647
|
+
'deselect_all' : function(){
|
648
|
+
var ms = this.$element,
|
649
|
+
values = ms.val();
|
650
|
+
|
651
|
+
ms.find('option').prop('selected', false);
|
652
|
+
this.$selectableUl.find('.ms-elem-selectable').removeClass('ms-selected').show();
|
653
|
+
this.$selectionUl.find('.ms-optgroup-label').hide();
|
654
|
+
this.$selectableUl.find('.ms-optgroup-label').show();
|
655
|
+
this.$selectionUl.find('.ms-elem-selection').removeClass('ms-selected').hide();
|
656
|
+
this.$selectableUl.focus();
|
657
|
+
|
658
|
+
ms.trigger('change');
|
659
|
+
this.updateCounters();
|
660
|
+
|
661
|
+
if (typeof this.options.afterDeselect === 'function') {
|
662
|
+
this.options.afterDeselect.call(this, values);
|
663
|
+
}
|
664
|
+
},
|
665
|
+
|
666
|
+
sanitize: function(value){
|
667
|
+
var hash = 0, i, character;
|
668
|
+
if (value.length == 0) return hash;
|
669
|
+
var ls = 0;
|
670
|
+
for (i = 0, ls = value.length; i < ls; i++) {
|
671
|
+
character = value.charCodeAt(i);
|
672
|
+
hash = ((hash<<5)-hash)+character;
|
673
|
+
hash |= 0; // Convert to 32bit integer
|
674
|
+
}
|
675
|
+
return hash;
|
676
|
+
}
|
677
|
+
};
|
678
|
+
|
679
|
+
/* MULTISELECT PLUGIN DEFINITION
|
680
|
+
* ======================= */
|
681
|
+
|
682
|
+
$.fn.multiSelect = function () {
|
683
|
+
var option = arguments[0],
|
684
|
+
args = arguments;
|
685
|
+
|
686
|
+
return this.each(function () {
|
687
|
+
var $this = $(this),
|
688
|
+
data = $this.data('multiselect'),
|
689
|
+
options = $.extend({}, $.fn.multiSelect.defaults, $this.data(), typeof option === 'object' && option);
|
690
|
+
|
691
|
+
if (!data){ $this.data('multiselect', (data = new MultiSelect(this, options))); }
|
692
|
+
|
693
|
+
if (typeof option === 'string'){
|
694
|
+
data[option](args[1]);
|
695
|
+
} else {
|
696
|
+
data.init();
|
697
|
+
}
|
698
|
+
$.fn.multiSelect.instances[data.$element[0]["id"]] = $this.data('multiselect');
|
699
|
+
});
|
700
|
+
};
|
701
|
+
|
702
|
+
$.fn.multiSelect.instances = {};
|
703
|
+
$.fn.multiSelect.defaults = {
|
704
|
+
keySelect: [32],
|
705
|
+
selectableOptgroup: false,
|
706
|
+
disabledClass : 'disabled',
|
707
|
+
dblClick : false,
|
708
|
+
keepOrder: false,
|
709
|
+
cssClass: ''
|
710
|
+
};
|
711
|
+
|
712
|
+
$.fn.multiSelect.Constructor = MultiSelect;
|
713
|
+
|
714
|
+
$.fn.insertAt = function(index, $parent) {
|
715
|
+
return this.each(function() {
|
716
|
+
if (index === 0) {
|
717
|
+
$parent.prepend(this);
|
718
|
+
} else {
|
719
|
+
$parent.children().eq(index - 1).after(this);
|
720
|
+
}
|
721
|
+
});
|
722
|
+
};
|
723
|
+
multi$ = $;
|
724
|
+
})(jQuery);
|
725
|
+
}));
|