From: Ryan Lane Date: Thu, 2 May 2013 20:44:54 +0000 (-0500) Subject: mediawiki.htmlform: Use auto width for Chosen selects X-Git-Tag: 1.31.0-rc.0~19789^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=02e0f091ab5cd239dd13409e095a6cde28b94501;p=lhc%2Fweb%2Fwiklou.git mediawiki.htmlform: Use auto width for Chosen selects Upgrading jQuery Chosen to 0.9.14 (which adds a "width" option) and setting width: auto in chosen calls for HTMLForm elements. Change-Id: Ib87f00ae0f3ad960d35d7a3c4529e56bbdaa6c38 --- diff --git a/resources/jquery.chosen/chosen.css b/resources/jquery.chosen/chosen.css index 8f6db26f4a..17793ed742 100644 --- a/resources/jquery.chosen/chosen.css +++ b/resources/jquery.chosen/chosen.css @@ -3,6 +3,7 @@ font-size: 13px; position: relative; display: inline-block; + vertical-align: middle; zoom: 1; *display: inline; } @@ -11,13 +12,24 @@ border: 1px solid #aaa; border-top: 0; position: absolute; - top: 29px; - left: 0; + top: 100%; + left: -9999px; -webkit-box-shadow: 0 4px 5px rgba(0,0,0,.15); -moz-box-shadow : 0 4px 5px rgba(0,0,0,.15); box-shadow : 0 4px 5px rgba(0,0,0,.15); z-index: 1010; + width: 100%; + -moz-box-sizing : border-box; + -ms-box-sizing : border-box; + -webkit-box-sizing: border-box; + -khtml-box-sizing : border-box; + box-sizing : border-box; +} + +.chzn-container.chzn-with-drop .chzn-drop { + left: 0; } + /* @end */ /* @group Single Chosen */ @@ -111,8 +123,15 @@ border: 1px solid #aaa; font-family: sans-serif; font-size: 1em; + width: 100%; + -moz-box-sizing : border-box; + -ms-box-sizing : border-box; + -webkit-box-sizing: border-box; + -khtml-box-sizing : border-box; + box-sizing : border-box; } .chzn-container-single .chzn-drop { + margin-top: -1px; -webkit-border-radius: 0 0 4px 4px; -moz-border-radius : 0 0 4px 4px; border-radius : 0 0 4px 4px; @@ -120,12 +139,11 @@ -webkit-background-clip: padding-box; background-clip : padding-box; } -/* @end */ - -.chzn-container-single-nosearch .chzn-search input { +.chzn-container-single-nosearch .chzn-search { position: absolute; - left: -9000px; + left: -9999px; } +/* @end */ /* @group Multi Chosen */ .chzn-container-multi .chzn-choices { @@ -143,6 +161,12 @@ height: auto !important; height: 1%; position: relative; + width: 100%; + -moz-box-sizing : border-box; + -ms-box-sizing : border-box; + -webkit-box-sizing: border-box; + -khtml-box-sizing : border-box; + box-sizing : border-box; } .chzn-container-multi .chzn-choices li { float: left; @@ -240,7 +264,7 @@ -webkit-overflow-scrolling: touch; } .chzn-container-multi .chzn-results { - margin: -1px 0 0; + margin: 0; padding: 0; } .chzn-container .chzn-results li { @@ -318,7 +342,7 @@ box-shadow : 0 0 5px rgba(0,0,0,.3); border: 1px solid #5897fb; } -.chzn-container-active .chzn-single-with-drop { +.chzn-container-active.chzn-with-drop .chzn-single { border: 1px solid #aaa; -webkit-box-shadow: 0 1px 0 #fff inset; -moz-box-shadow : 0 1px 0 #fff inset; @@ -337,11 +361,11 @@ border-bottom-left-radius : 0; border-bottom-right-radius: 0; } -.chzn-container-active .chzn-single-with-drop div { +.chzn-container-active.chzn-with-drop .chzn-single div { background: transparent; border-left: none; } -.chzn-container-active .chzn-single-with-drop div b { +.chzn-container-active.chzn-with-drop .chzn-single div b { background-position: -18px 2px; } .chzn-container-active .chzn-choices { @@ -381,9 +405,12 @@ .chzn-rtl .chzn-choices li { float: right; } .chzn-rtl .chzn-choices .search-choice { padding: 3px 5px 3px 19px; margin: 3px 5px 3px 0; } .chzn-rtl .chzn-choices .search-choice .search-choice-close { left: 4px; right: auto; } +.chzn-rtl .chzn-search { left: 9999px; } +.chzn-rtl.chzn-with-drop .chzn-search { left: 0px; } +.chzn-rtl .chzn-drop { left: 9999px; } .chzn-rtl.chzn-container-single .chzn-results { margin: 0 0 4px 4px; padding: 0 4px 0 0; } .chzn-rtl .chzn-results .group-option { padding-left: 0; padding-right: 15px; } -.chzn-rtl.chzn-container-active .chzn-single-with-drop div { border-right: none; } +.chzn-rtl.chzn-container-active.chzn-with-drop .chzn-single div { border-right: none; } .chzn-rtl .chzn-search input { background: #fff url('chosen-sprite.png') no-repeat -30px -20px; background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-gradient(linear, 0 0, 0 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); @@ -397,7 +424,7 @@ .chzn-container-single.chzn-rtl .chzn-single div b { background-position: 6px 2px; } -.chzn-container-single.chzn-rtl .chzn-single-with-drop div b { +.chzn-container-single.chzn-rtl.chzn-with-drop .chzn-single div b { background-position: -12px 2px; } /* @end */ diff --git a/resources/jquery.chosen/chosen.jquery.js b/resources/jquery.chosen/chosen.jquery.js index 8f2cb92f97..a240ebd456 100644 --- a/resources/jquery.chosen/chosen.jquery.js +++ b/resources/jquery.chosen/chosen.jquery.js @@ -1,7 +1,7 @@ // Chosen, a Select Box Enhancer for jQuery and Protoype // by Patrick Filler for Harvest, http://getharvest.com // -// Version 0.9.12 +// Version 0.9.14 // Full source at https://github.com/harvesthq/chosen // Copyright (c) 2011 Harvest http://getharvest.com @@ -108,6 +108,9 @@ Copyright (c) 2011 by Harvest function AbstractChosen(form_field, options) { this.form_field = form_field; this.options = options != null ? options : {}; + if (!AbstractChosen.browser_is_supported()) { + return; + } this.is_multiple = this.form_field.multiple; this.set_default_text(); this.set_default_values(); @@ -145,11 +148,11 @@ Copyright (c) 2011 by Harvest if (this.form_field.getAttribute("data-placeholder")) { this.default_text = this.form_field.getAttribute("data-placeholder"); } else if (this.is_multiple) { - this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options"; + this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text; } else { - this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option"; + this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text; } - return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match"; + return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; }; AbstractChosen.prototype.mouse_enter = function() { @@ -232,6 +235,13 @@ Copyright (c) 2011 by Harvest } }; + AbstractChosen.prototype.choices_click = function(evt) { + evt.preventDefault(); + if (!this.results_showing) { + return this.results_show(); + } + }; + AbstractChosen.prototype.keyup_checker = function(evt) { var stroke, _ref; stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; @@ -282,6 +292,29 @@ Copyright (c) 2011 by Harvest return newchar = chars.substring(rand, rand + 1); }; + AbstractChosen.prototype.container_width = function() { + var width; + if (this.options.width != null) { + return this.options.width; + } + width = window.getComputedStyle != null ? parseFloat(window.getComputedStyle(this.form_field).getPropertyValue('width')) : (typeof jQuery !== "undefined" && jQuery !== null) && (this.form_field_jq != null) ? this.form_field_jq.outerWidth() : this.form_field.getWidth(); + return width + "px"; + }; + + AbstractChosen.browser_is_supported = function() { + var _ref; + if (window.navigator.appName === "Microsoft Internet Explorer") { + return (null !== (_ref = document.documentMode) && _ref >= 8); + } + return true; + }; + + AbstractChosen.default_multiple_text = "Select Some Options"; + + AbstractChosen.default_single_text = "Select an Option"; + + AbstractChosen.default_no_result_text = "No results match"; + return AbstractChosen; })(); @@ -297,7 +330,7 @@ Copyright (c) 2011 by Harvest (function() { - var $, Chosen, get_side_border_padding, root, + var $, Chosen, root, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -307,14 +340,7 @@ Copyright (c) 2011 by Harvest $.fn.extend({ chosen: function(options) { - var browser, match, ua; - ua = navigator.userAgent.toLowerCase(); - match = /(msie) ([\w.]+)/.exec(ua) || []; - browser = { - name: match[1] || "", - version: match[2] || "0" - }; - if (browser.name === "msie" && (browser.version === "6.0" || (browser.version === "7.0" && document.documentMode === 7))) { + if (!AbstractChosen.browser_is_supported()) { return this; } return this.each(function(input_field) { @@ -337,7 +363,7 @@ Copyright (c) 2011 by Harvest Chosen.prototype.setup = function() { this.form_field_jq = $(this.form_field); - this.current_value = this.form_field_jq.val(); + this.current_selectedIndex = this.form_field.selectedIndex; return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); }; @@ -346,7 +372,7 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.set_up_html = function() { - var container_classes, container_div, container_props, dd_top, dd_width, sf_width; + var container_classes, container_props; this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id(); this.container_id += "_chzn"; container_classes = ["chzn-container"]; @@ -357,28 +383,20 @@ Copyright (c) 2011 by Harvest if (this.is_rtl) { container_classes.push("chzn-rtl"); } - this.f_width = this.form_field_jq.outerWidth(); container_props = { - id: this.container_id, - "class": container_classes.join(' '), - style: 'width: ' + this.f_width + 'px;', - title: this.form_field.title + 'id': this.container_id, + 'class': container_classes.join(' '), + 'style': "width: " + (this.container_width()) + ";", + 'title': this.form_field.title }; - container_div = $("
", container_props); + this.container = $("
", container_props); if (this.is_multiple) { - container_div.html('
    '); + this.container.html('
      '); } else { - container_div.html('' + this.default_text + '
        '); + this.container.html('' + this.default_text + '
          '); } - this.form_field_jq.hide().after(container_div); - this.container = $('#' + this.container_id); + this.form_field_jq.hide().after(this.container); this.dropdown = this.container.find('div.chzn-drop').first(); - dd_top = this.container.height(); - dd_width = this.f_width - get_side_border_padding(this.dropdown); - this.dropdown.css({ - "width": dd_width + "px", - "top": dd_top + "px" - }); this.search_field = this.container.find('input').first(); this.search_results = this.container.find('ul.chzn-results').first(); this.search_field_scale(); @@ -389,13 +407,10 @@ Copyright (c) 2011 by Harvest } else { this.search_container = this.container.find('div.chzn-search').first(); this.selected_item = this.container.find('.chzn-single').first(); - sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field); - this.search_field.css({ - "width": sf_width + "px" - }); } this.results_build(); this.set_tab_index(); + this.set_label_behavior(); return this.form_field_jq.trigger("liszt:ready", { chosen: this }); @@ -424,6 +439,9 @@ Copyright (c) 2011 by Harvest this.search_results.mouseout(function(evt) { _this.search_results_mouseout(evt); }); + this.search_results.bind('mousewheel DOMMouseScroll', function(evt) { + _this.search_results_mousewheel(evt); + }); this.form_field_jq.bind("liszt:updated", function(evt) { _this.results_update_field(evt); }); @@ -475,13 +493,11 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.container_mousedown = function(evt) { - var target_closelink; if (!this.is_disabled) { - target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false; if (evt && evt.type === "mousedown" && !this.results_showing) { evt.preventDefault(); } - if (!this.pending_destroy_click && !target_closelink) { + if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) { if (!this.active_field) { if (this.is_multiple) { this.search_field.val(""); @@ -493,8 +509,6 @@ Copyright (c) 2011 by Harvest this.results_toggle(); } return this.activate_field(); - } else { - return this.pending_destroy_click = false; } } }; @@ -505,6 +519,18 @@ Copyright (c) 2011 by Harvest } }; + Chosen.prototype.search_results_mousewheel = function(evt) { + var delta, _ref, _ref1; + delta = -((_ref = evt.originalEvent) != null ? _ref.wheelDelta : void 0) || ((_ref1 = evt.originialEvent) != null ? _ref1.detail : void 0); + if (delta != null) { + evt.preventDefault(); + if (evt.type === 'DOMMouseScroll') { + delta = delta * 40; + } + return this.search_results.scrollTop(delta + this.search_results.scrollTop()); + } + }; + Chosen.prototype.blur_test = function(evt) { if (!this.active_field && this.container.hasClass("chzn-container-active")) { return this.close_field(); @@ -613,26 +639,18 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.results_show = function() { - var dd_top; - if (!this.is_multiple) { - this.selected_item.addClass("chzn-single-with-drop"); - if (this.result_single_selected) { - this.result_do_highlight(this.result_single_selected); - } - } else if (this.max_selected_options <= this.choices) { + if (this.result_single_selected != null) { + this.result_do_highlight(this.result_single_selected); + } else if (this.is_multiple && this.max_selected_options <= this.choices) { this.form_field_jq.trigger("liszt:maxselected", { chosen: this }); return false; } - dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1; + this.container.addClass("chzn-with-drop"); this.form_field_jq.trigger("liszt:showing_dropdown", { chosen: this }); - this.dropdown.css({ - "top": dd_top + "px", - "left": 0 - }); this.results_showing = true; this.search_field.focus(); this.search_field.val(this.search_field.val()); @@ -640,16 +658,11 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.results_hide = function() { - if (!this.is_multiple) { - this.selected_item.removeClass("chzn-single-with-drop"); - } this.result_clear_highlight(); + this.container.removeClass("chzn-with-drop"); this.form_field_jq.trigger("liszt:hiding_dropdown", { chosen: this }); - this.dropdown.css({ - "left": "-9000px" - }); return this.results_showing = false; }; @@ -662,6 +675,23 @@ Copyright (c) 2011 by Harvest } }; + Chosen.prototype.set_label_behavior = function() { + var _this = this; + this.form_field_label = this.form_field_jq.parents("label"); + if (!this.form_field_label.length && this.form_field.id.length) { + this.form_field_label = $("label[for=" + this.form_field.id + "]"); + } + if (this.form_field_label.length > 0) { + return this.form_field_label.click(function(evt) { + if (_this.is_multiple) { + return _this.container_mousedown(evt); + } else { + return _this.activate_field(); + } + }); + } + }; + Chosen.prototype.show_search_field_default = function() { if (this.is_multiple && this.choices < 1 && !this.active_field) { this.search_field.val(this.default_text); @@ -696,13 +726,6 @@ Copyright (c) 2011 by Harvest } }; - Chosen.prototype.choices_click = function(evt) { - evt.preventDefault(); - if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) { - return this.results_show(); - } - }; - Chosen.prototype.choice_build = function(item) { var choice_id, html, link, _this = this; @@ -728,11 +751,9 @@ Copyright (c) 2011 by Harvest Chosen.prototype.choice_destroy_link_click = function(evt) { evt.preventDefault(); + evt.stopPropagation(); if (!this.is_disabled) { - this.pending_destroy_click = true; return this.choice_destroy($(evt.target)); - } else { - return evt.stopPropagation; } }; @@ -763,7 +784,7 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.results_reset_cleanup = function() { - this.current_value = this.form_field_jq.val(); + this.current_selectedIndex = this.form_field.selectedIndex; return this.selected_item.find("abbr").remove(); }; @@ -797,12 +818,12 @@ Copyright (c) 2011 by Harvest this.results_hide(); } this.search_field.val(""); - if (this.is_multiple || this.form_field_jq.val() !== this.current_value) { + if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) { this.form_field_jq.trigger("change", { 'selected': this.form_field.options[item.options_index].value }); } - this.current_value = this.form_field_jq.val(); + this.current_selectedIndex = this.form_field.selectedIndex; return this.search_field_scale(); } }; @@ -1035,7 +1056,7 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.search_field_scale = function() { - var dd_top, div, h, style, style_block, styles, w, _i, _len; + var div, h, style, style_block, styles, w, _i, _len; if (this.is_multiple) { h = 0; w = 0; @@ -1052,16 +1073,15 @@ Copyright (c) 2011 by Harvest $('body').append(div); w = div.width() + 25; div.remove(); + if (!this.f_width) { + this.f_width = this.container.outerWidth(); + } if (w > this.f_width - 10) { w = this.f_width - 10; } - this.search_field.css({ + return this.search_field.css({ 'width': w + 'px' }); - dd_top = this.container.height(); - return this.dropdown.css({ - "top": dd_top + "px" - }); } }; @@ -1080,11 +1100,4 @@ Copyright (c) 2011 by Harvest root.Chosen = Chosen; - get_side_border_padding = function(elmt) { - var side_border_padding; - return side_border_padding = elmt.outerWidth() - elmt.width(); - }; - - root.get_side_border_padding = get_side_border_padding; - }).call(this); diff --git a/resources/mediawiki/mediawiki.htmlform.js b/resources/mediawiki/mediawiki.htmlform.js index 0a2819b047..87529b4d6b 100644 --- a/resources/mediawiki/mediawiki.htmlform.js +++ b/resources/mediawiki/mediawiki.htmlform.js @@ -115,12 +115,12 @@ $toConvert = $( 'table .mw-chosen' ); if ( $toConvert.length ) { $converted = convertCheckboxesToMulti( $toConvert, 'table' ); - $converted.find( '.htmlform-chzn-select' ).chosen(); + $converted.find( '.htmlform-chzn-select' ).chosen( { width: 'auto' } ); } $toConvert = $( 'div .mw-chosen' ); if ( $toConvert.length ) { $converted = convertCheckboxesToMulti( $toConvert, 'div' ); - $converted.find( '.htmlform-chzn-select' ).chosen(); + $converted.find( '.htmlform-chzn-select' ).chosen( { width: 'auto' } ); } } ); }