From dc5e36ec5c3d94b6448a1e1d5ac0989e27d1ddd0 Mon Sep 17 00:00:00 2001 From: Naomi Guyer Date: Tue, 1 May 2012 17:14:16 +1200 Subject: [PATCH] BUGFIX: 7117 Fixes Includes: * Changes to chosen to include a custom function that will let the drop-down rise-up if there is room and it would otherwise drop beneath the size of the window (changes in coffeescript, jquery output, and chosen css) * Changes in SCSS to stop the automatic addition of scrollbars, and to limit the extra space at the bottom of the filter div Issues remaining: * jLayout is calculating the height of the filter div incorrectly. It is assuming the div is around 70px longer than it is. This height assumption is linked somehow to chosen, as initiating the select box results in a correct height calculation. --- admin/css/screen.css | 6 +- admin/scss/_style.scss | 9 ++- admin/thirdparty/chosen/chosen/chosen.css | 45 ++++++++++++++- .../thirdparty/chosen/chosen/chosen.jquery.js | 55 ++++++++++++++++-- .../chosen/chosen/chosen.jquery.min.js | 2 +- .../chosen/coffee/chosen.jquery.coffee | 56 ++++++++++++++++--- 6 files changed, 154 insertions(+), 19 deletions(-) diff --git a/admin/css/screen.css b/admin/css/screen.css index 008cf6d24..11e2dcc50 100644 --- a/admin/css/screen.css +++ b/admin/css/screen.css @@ -355,8 +355,9 @@ body.cms { overflow: hidden; } /* -------------------------------------------------------- Content Tools is the sidebar on the left of the main content panel */ .cms-content-tools { background-color: #c6d7df; width: 192px; border-right: 1px solid #bfcad2; overflow-y: auto; overflow-x: hidden; z-index: 70; -moz-box-shadow: rgba(107, 120, 123, 0.5) 0 0 4px; -webkit-box-shadow: rgba(107, 120, 123, 0.5) 0 0 4px; -o-box-shadow: rgba(107, 120, 123, 0.5) 0 0 4px; box-shadow: rgba(107, 120, 123, 0.5) 0 0 4px; float: left; position: relative; } +.cms-content-tools.filter { padding: 0 !important; } .cms-content-tools .cms-panel-header { clear: both; margin: 0 0 7px; line-height: 24px; border-bottom: 1px solid rgba(201, 205, 206, 0.8); -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); -o-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); } -.cms-content-tools .cms-panel-content { width: 176px; padding: 0 8px; overflow: auto; height: 100%; } +.cms-content-tools .cms-panel-content { width: 176px; padding: 0 8px; overflow: auto; overflow-x: hidden; height: 100%; } .cms-content-tools .cms-panel-content .dropdown select { width: 160px; } .cms-content-tools .cms-panel-content #LastEditedFrom { -moz-box-shadow: none; -webkit-box-shadow: none; -o-box-shadow: none; box-shadow: none; } .cms-content-tools .cms-panel-content #LastEditedFrom input { width: 160px; } @@ -524,7 +525,8 @@ body.cms-dialog { overflow: auto; background: url("../images/textures/bg_cms_mai .htmleditorfield-mediaform .ss-htmleditorfield-file .details { padding: 16px; } /** -------------------------------------------- Search forms (used in AssetAdmin, ModelAdmin, etc) -------------------------------------------- */ -.cms-search-form { overflow: auto; margin-bottom: 16px; } +.cms-search-form { margin-bottom: 16px; } +.filter .cms-search-form { margin-bottom: 0; } /** -------------------------------------------- Step labels -------------------------------------------- */ .step-label > * { display: inline-block; vertical-align: top; } diff --git a/admin/scss/_style.scss b/admin/scss/_style.scss index 9caf17b7f..241b32a92 100644 --- a/admin/scss/_style.scss +++ b/admin/scss/_style.scss @@ -611,6 +611,10 @@ body.cms { @include box-shadow($color-shadow-dark 0 0 ($grid-x / 2)); float: left; position: relative; + + &.filter{ + padding:0 !important; + } .cms-panel-header { clear: both; @@ -624,6 +628,7 @@ body.cms { width: ($grid-x * 22); padding: 0 $grid-x; overflow: auto; + overflow-x:hidden; height:100%; .dropdown select { width:$grid-x * 20; @@ -1454,8 +1459,10 @@ body.cms-dialog { * Search forms (used in AssetAdmin, ModelAdmin, etc) * -------------------------------------------- */ .cms-search-form { - overflow: auto; margin-bottom: $grid-y*2; + .filter &{ + margin-bottom:0; + } } /** -------------------------------------------- diff --git a/admin/thirdparty/chosen/chosen/chosen.css b/admin/thirdparty/chosen/chosen/chosen.css index 36abf3412..9ba19ee3c 100644 --- a/admin/thirdparty/chosen/chosen/chosen.css +++ b/admin/thirdparty/chosen/chosen/chosen.css @@ -6,7 +6,7 @@ zoom: 1; *display: inline; } -.chzn-container .chzn-drop { +.chzn-container .chzn-drop{ background: #fff; border: 1px solid #aaa; border-top: 0; @@ -19,6 +19,29 @@ box-shadow : 0 4px 5px rgba(0,0,0,.15); z-index: 999; } +.chzn-container.chzn-with-rise .chzn-drop, .chzn-container.chzn-with-rise .chzn-drop{ + border: 1px solid #aaa; + border-bottom: 0; + position: absolute; + top: 0px; + left: 0; + -webkit-box-shadow: 0 -4px -5px rgba(0,0,0,.15); + -moz-box-shadow : 0 -4px -5px rgba(0,0,0,.15); + -o-box-shadow : 0 -4px -5px rgba(0,0,0,.15); + box-shadow : 0 -4px -5px rgba(0,0,0,.15); + z-index: 999; + -webkit-border-radius: 5px; + -moz-border-radius : 5px; + border-radius : 5px; + -webkit-border-bottom-left-radius : 0; + -webkit-border-bottom-right-radius: 0; + -moz-border-radius-bottomleft : 0; + -moz-border-radius-bottomright: 0; + border-bottom-left-radius : 0; + border-bottom-right-radius: 0; +} + + /* @end */ /* @group Single Chosen */ @@ -52,7 +75,7 @@ text-decoration: none; } .chzn-container-single .chzn-default { - color: #999; + color: #999; } .chzn-container-single .chzn-single span { margin-right: 26px; @@ -330,6 +353,8 @@ border-bottom-left-radius : 0; border-bottom-right-radius: 0; } + + .chzn-container-active .chzn-single-with-drop div { background: transparent; border-left: none; @@ -389,4 +414,20 @@ padding: 4px 5px 4px 20px; direction: rtl; } + +.chzn-with-rise .chzn-single-with-drop, .chzn-with-rise .chzn-single-with-drop{ + -webkit-border-radius: 5px; + -moz-border-radius : 5px; + border-radius : 5px; + + -webkit-border-top-left-radius : 0; + -webkit-border-top-right-radius: 0; + -moz-border-radius-topleft : 0; + -moz-border-radius-topright: 0; + border-top-left-radius : 0; + border-top-right-radius: 0; +} + + + /* @end */ diff --git a/admin/thirdparty/chosen/chosen/chosen.jquery.js b/admin/thirdparty/chosen/chosen/chosen.jquery.js index 4c8ac89b1..14e2282b9 100644 --- a/admin/thirdparty/chosen/chosen/chosen.jquery.js +++ b/admin/thirdparty/chosen/chosen/chosen.jquery.js @@ -321,7 +321,7 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.set_up_html = function() { - var container_div, dd_top, dd_width, sf_width; + var container_div, dd_top, dd_width, rise, sf_width; this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id(); this.container_id += "_chzn"; this.f_width = this.form_field_jq.outerWidth(); @@ -340,7 +340,13 @@ Copyright (c) 2011 by Harvest this.container = $('#' + this.container_id); this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single")); this.dropdown = this.container.find('div.chzn-drop').first(); - dd_top = this.container.height(); + /* + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + */ + + rise = this.rise_up(this.container, this.dropdown); + dd_top = rise ? -this.container.find('.chzn-drop').height() : this.container.height(); dd_width = this.container.width - get_side_border_padding(this.dropdown); this.dropdown.css({ "width": dd_width + "px", @@ -582,14 +588,20 @@ Copyright (c) 2011 by Harvest }; Chosen.prototype.results_show = function() { - var dd_top, dd_width; + var dd_top, dd_width, rise; 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); } } - dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1; + /* + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + */ + + rise = this.rise_up(this.container, this.dropdown); + dd_top = rise ? -this.container.find('.chzn-drop').height() : this.is_multiple ? this.container.height() : this.container.height() - 1; dd_width = this.container.width() - get_side_border_padding(this.dropdown); this.dropdown.css({ "top": dd_top + "px", @@ -961,7 +973,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 dd_top, div, h, rise, style, style_block, styles, w, _i, _len; if (this.is_multiple) { h = 0; w = 0; @@ -984,7 +996,13 @@ Copyright (c) 2011 by Harvest this.search_field.css({ 'width': w + 'px' }); - dd_top = this.container.height(); + /* + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + */ + + rise = this.rise_up(this.container, this.dropdown); + dd_top = rise ? -this.container.find('.chzn-drop').height() : this.container.height(); return this.dropdown.css({ "top": dd_top + "px" }); @@ -1000,6 +1018,31 @@ Copyright (c) 2011 by Harvest return string; }; + /* + SILVERSTRIPE CUSTOM FUNCTION + Rise_up function handles the case where a dropdown exceeds the height of the window + # Adds class if true, returns true + # Removes class if false, returns false + This facilitates the behaviour where the drop-down will drop up if there is no room + to drop down + */ + + + Chosen.prototype.rise_up = function(container, dropdown) { + var elHeight, elPos, endOfWindow, trigger; + trigger = container.find('a.chzn-single'); + endOfWindow = ($(window).height() + $(document).scrollTop()) - container.find('a').innerHeight(); + elPos = trigger.offset().top; + elHeight = dropdown.innerHeight(); + if (elPos + elHeight > endOfWindow && elPos - elHeight > 0) { + container.addClass('chzn-with-rise'); + return true; + } else { + container.removeClass('chzn-with-rise'); + return false; + } + }; + return Chosen; })(AbstractChosen); diff --git a/admin/thirdparty/chosen/chosen/chosen.jquery.min.js b/admin/thirdparty/chosen/chosen/chosen.jquery.min.js index f8e68d5e6..3179d44ed 100644 --- a/admin/thirdparty/chosen/chosen/chosen.jquery.min.js +++ b/admin/thirdparty/chosen/chosen/chosen.jquery.min.js @@ -9,4 +9,4 @@ // based on version 0.9.8, applied a very simple patch that fix percentaage width support on select tag // This file is generated by `cake build`, do not edit it by hand. -(function(){var a;a=function(){function a(){this.options_index=0,this.parsed=[]}return a.name="SelectParser",a.prototype.add_node=function(a){return a.nodeName==="OPTGROUP"?this.add_group(a):this.add_option(a)},a.prototype.add_group=function(a){var b,c,d,e,f,g;b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:a.label,children:0,disabled:a.disabled}),f=a.childNodes,g=[];for(d=0,e=f.length;d"+a.html+"")},a.prototype.results_update_field=function(){return this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},a.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},a.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},a.prototype.keyup_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale();switch(b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:a.preventDefault();if(this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},a.prototype.generate_field_id=function(){var a;return a=this.generate_random_id(),this.form_field.id=a,a},a.prototype.generate_random_char=function(){var a,b,c;return a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ",c=Math.floor(Math.random()*a.length),b=a.substring(c,c+1)},a}(),b.AbstractChosen=a}.call(this),function(){var a,b,c,d,e={}.hasOwnProperty,f=function(a,b){function d(){this.constructor=a}for(var c in b)e.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};d=this,a=jQuery,a.fn.extend({chosen:function(c){return!a.browser.msie||a.browser.version!=="6.0"&&a.browser.version!=="7.0"?this.each(function(d){var e;e=a(this);if(!e.hasClass("chzn-done"))return e.data("chosen",new b(this,c))}):this}}),b=function(b){function e(){return e.__super__.constructor.apply(this,arguments)}return f(e,b),e.name="Chosen",e.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},e.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},e.prototype.set_up_html=function(){var b,d,e,f;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/(:|\.)/g,"_"):this.generate_field_id(),this.container_id+="_chzn",this.f_width=this.form_field_jq.outerWidth(),this.default_text=this.form_field_jq.data("placeholder")?this.form_field_jq.data("placeholder"):this.default_text_default,b=a("
",{id:this.container_id,"class":"chzn-container"+(this.is_rtl?" chzn-rtl":""),style:"width: "+(this.options.width||this.f_width)+"px;"}),this.is_multiple?b.html('
    '):b.html(''+this.default_text+'
      '),this.form_field_jq.hide().after(b),this.container=a("#"+this.container_id),this.container.addClass("chzn-container-"+(this.is_multiple?"multi":"single")),this.dropdown=this.container.find("div.chzn-drop").first(),d=this.container.height(),e=this.container.width-c(this.dropdown),this.dropdown.css({width:e+"px",top:d+"px"}),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first(),f=e-c(this.search_container)-c(this.search_field),this.search_field.css({width:f+"px"})),this.results_build(),this.set_tab_index(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},e.prototype.register_observers=function(){var a=this;return this.container.mousedown(function(b){return a.container_mousedown(b)}),this.container.mouseup(function(b){return a.container_mouseup(b)}),this.container.mouseenter(function(b){return a.mouse_enter(b)}),this.container.mouseleave(function(b){return a.mouse_leave(b)}),this.search_results.mouseup(function(b){return a.search_results_mouseup(b)}),this.search_results.mouseover(function(b){return a.search_results_mouseover(b)}),this.search_results.mouseout(function(b){return a.search_results_mouseout(b)}),this.form_field_jq.bind("liszt:updated",function(b){return a.results_update_field(b)}),this.search_field.blur(function(b){return a.input_blur(b)}),this.search_field.keyup(function(b){return a.keyup_checker(b)}),this.search_field.keydown(function(b){return a.keydown_checker(b)}),this.is_multiple?(this.search_choices.click(function(b){return a.choices_click(b)}),this.search_field.focus(function(b){return a.input_focus(b)})):this.container.click(function(a){return a.preventDefault()})},e.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},e.prototype.container_mousedown=function(b){var c;if(!this.is_disabled)return c=b!=null?a(b.target).hasClass("search-choice-close"):!1,b&&b.type==="mousedown"&&!this.results_showing&&b.stopPropagation(),!this.pending_destroy_click&&!c?(this.active_field?!this.is_multiple&&b&&(a(b.target)[0]===this.selected_item[0]||a(b.target).parents("a.chzn-single").length)&&(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).click(this.click_test_action),this.results_show()),this.activate_field()):this.pending_destroy_click=!1},e.prototype.container_mouseup=function(a){if(a.target.nodeName==="ABBR")return this.results_reset(a)},e.prototype.blur_test=function(a){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},e.prototype.close_field=function(){return a(document).unbind("click",this.click_test_action),this.is_multiple||(this.selected_item.attr("tabindex",this.search_field.attr("tabindex")),this.search_field.attr("tabindex",-1)),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},e.prototype.activate_field=function(){return!this.is_multiple&&!this.active_field&&(this.search_field.attr("tabindex",this.selected_item.attr("tabindex")),this.selected_item.attr("tabindex",-1)),this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},e.prototype.test_active_click=function(b){return a(b.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},e.prototype.results_build=function(){var a,b,c,e,f;this.parsing=!0,this.results_data=d.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.find("span").text(this.default_text),this.form_field.options.length<=this.disable_search_threshold?this.container.addClass("chzn-container-single-nosearch"):this.container.removeClass("chzn-container-single-nosearch")),a="",f=this.results_data;for(c=0,e=f.length;c'+a("
      ").text(b.label).html()+"")},e.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight();if(b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(c'+b.html+''),d=a("#"+c).find("a").first(),d.click(function(a){return e.choice_destroy_link_click(a)})},e.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),this.is_disabled?b.stopPropagation:(this.pending_destroy_click=!0,this.choice_destroy(a(b.target)))},e.prototype.choice_destroy=function(a){return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),this.result_deselect(a.attr("rel")),a.parents("li").first().remove()},e.prototype.results_reset=function(b){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.is_multiple||this.selected_item.addClass("chzn-default"),this.show_search_field_default(),a(b.target).remove(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},e.prototype.result_select=function(a){var b,c,d,e;if(this.result_highlight)return b=this.result_highlight,c=b.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(b):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=b,this.selected_item.removeClass("chzn-default")),b.addClass("result-selected"),e=c.substr(c.lastIndexOf("_")+1),d=this.results_data[e],d.selected=!0,this.form_field.options[d.options_index].selected=!0,this.is_multiple?this.choice_build(d):(this.selected_item.find("span").first().text(d.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!a.metaKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),this.form_field_jq.trigger("change"),this.search_field_scale()},e.prototype.result_activate=function(a){return a.addClass("active-result")},e.prototype.result_deactivate=function(a){return a.removeClass("active-result")},e.prototype.result_deselect=function(b){var c,d;return d=this.results_data[b],d.selected=!1,this.form_field.options[d.options_index].selected=!1,c=a("#"+this.container_id+"_o_"+b),c.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change"),this.search_field_scale()},e.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('')},e.prototype.winnow_results=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;this.no_results_clear(),j=0,k=this.search_field.val()===this.default_text?"":a("
      ").text(a.trim(this.search_field.val())).html(),g=this.search_contains?"":"^",f=new RegExp(g+k.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),n=new RegExp(k.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),s=this.results_data;for(o=0,q=s.length;o=0||c.html.indexOf("[")===0){e=c.html.replace(/\[|\]/g,"").split(" ");if(e.length)for(p=0,r=e.length;p"+c.html.substr(l+k.length),m=m.substr(0,l)+""+m.substr(l)):m=c.html,h.html(m),this.result_activate(h),c.group_array_index!=null&&a("#"+this.results_data[c.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&i===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(h))}}return j<1&&k.length?this.no_results(k):this.winnow_results_set_highlight()},e.prototype.winnow_results_clear=function(){var b,c,d,e,f;this.search_field.val(""),c=this.search_results.find("li"),f=[];for(d=0,e=c.length;d'+this.results_none_found+' ""'),c.find("span").first().html(b),this.search_results.append(c)},e.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},e.prototype.keydown_arrow=function(){var b,c;this.result_highlight?this.results_showing&&(c=this.result_highlight.nextAll("li.active-result").first(),c&&this.result_do_highlight(c)):(b=this.search_results.find("li.active-result").first(),b&&this.result_do_highlight(a(b)));if(!this.results_showing)return this.results_show()},e.prototype.keyup_arrow=function(){var a;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},e.prototype.keydown_backstroke=function(){return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(this.pending_backstroke=this.search_container.siblings("li.search-choice").last(),this.pending_backstroke.addClass("search-choice-focus"))},e.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},e.prototype.keydown_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale(),b!==8&&this.pending_backstroke&&this.clear_backstroke();switch(b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},e.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(i=0,j=g.length;i",{style:f}),c.text(this.search_field.val()),a("body").append(c),h=c.width()+25,c.remove(),h>this.f_width-10&&(h=this.f_width-10),this.search_field.css({width:h+"px"}),b=this.container.height(),this.dropdown.css({top:b+"px"})}},e.prototype.generate_random_id=function(){var b;b="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(a("#"+b).length>0)b+=this.generate_random_char();return b},e}(AbstractChosen),c=function(a){var b;return b=a.outerWidth()-a.width()},d.get_side_border_padding=c}.call(this); \ No newline at end of file +(function(){var a;a=function(){function a(){this.options_index=0,this.parsed=[]}return a.name="SelectParser",a.prototype.add_node=function(a){return a.nodeName==="OPTGROUP"?this.add_group(a):this.add_option(a)},a.prototype.add_group=function(a){var b,c,d,e,f,g;b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:a.label,children:0,disabled:a.disabled}),f=a.childNodes,g=[];for(d=0,e=f.length;d"+a.html+"")},a.prototype.results_update_field=function(){return this.result_clear_highlight(),this.result_single_selected=null,this.results_build()},a.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},a.prototype.results_search=function(a){return this.results_showing?this.winnow_results():this.results_show()},a.prototype.keyup_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale();switch(b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:a.preventDefault();if(this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},a.prototype.generate_field_id=function(){var a;return a=this.generate_random_id(),this.form_field.id=a,a},a.prototype.generate_random_char=function(){var a,b,c;return a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ",c=Math.floor(Math.random()*a.length),b=a.substring(c,c+1)},a}(),b.AbstractChosen=a}.call(this),function(){var a,b,c,d,e={}.hasOwnProperty,f=function(a,b){function d(){this.constructor=a}for(var c in b)e.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};d=this,a=jQuery,a.fn.extend({chosen:function(c){return!a.browser.msie||a.browser.version!=="6.0"&&a.browser.version!=="7.0"?this.each(function(d){var e;e=a(this);if(!e.hasClass("chzn-done"))return e.data("chosen",new b(this,c))}):this}}),b=function(b){function e(){return e.__super__.constructor.apply(this,arguments)}return f(e,b),e.name="Chosen",e.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.is_rtl=this.form_field_jq.hasClass("chzn-rtl")},e.prototype.finish_setup=function(){return this.form_field_jq.addClass("chzn-done")},e.prototype.set_up_html=function(){var b,d,e,f,g;return this.container_id=this.form_field.id.length?this.form_field.id.replace(/(:|\.)/g,"_"):this.generate_field_id(),this.container_id+="_chzn",this.f_width=this.form_field_jq.outerWidth(),this.default_text=this.form_field_jq.data("placeholder")?this.form_field_jq.data("placeholder"):this.default_text_default,b=a("
      ",{id:this.container_id,"class":"chzn-container"+(this.is_rtl?" chzn-rtl":""),style:"width: "+(this.options.width||this.f_width)+"px;"}),this.is_multiple?b.html('
        '):b.html(''+this.default_text+'
          '),this.form_field_jq.hide().after(b),this.container=a("#"+this.container_id),this.container.addClass("chzn-container-"+(this.is_multiple?"multi":"single")),this.dropdown=this.container.find("div.chzn-drop").first(),f=this.rise_up(this.container,this.dropdown),d=f?-this.container.find(".chzn-drop").height():this.container.height(),e=this.container.width-c(this.dropdown),this.dropdown.css({width:e+"px",top:d+"px"}),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chzn-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chzn-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chzn-search").first(),this.selected_item=this.container.find(".chzn-single").first(),g=e-c(this.search_container)-c(this.search_field),this.search_field.css({width:g+"px"})),this.results_build(),this.set_tab_index(),this.form_field_jq.trigger("liszt:ready",{chosen:this})},e.prototype.register_observers=function(){var a=this;return this.container.mousedown(function(b){return a.container_mousedown(b)}),this.container.mouseup(function(b){return a.container_mouseup(b)}),this.container.mouseenter(function(b){return a.mouse_enter(b)}),this.container.mouseleave(function(b){return a.mouse_leave(b)}),this.search_results.mouseup(function(b){return a.search_results_mouseup(b)}),this.search_results.mouseover(function(b){return a.search_results_mouseover(b)}),this.search_results.mouseout(function(b){return a.search_results_mouseout(b)}),this.form_field_jq.bind("liszt:updated",function(b){return a.results_update_field(b)}),this.search_field.blur(function(b){return a.input_blur(b)}),this.search_field.keyup(function(b){return a.keyup_checker(b)}),this.search_field.keydown(function(b){return a.keydown_checker(b)}),this.is_multiple?(this.search_choices.click(function(b){return a.choices_click(b)}),this.search_field.focus(function(b){return a.input_focus(b)})):this.container.click(function(a){return a.preventDefault()})},e.prototype.search_field_disabled=function(){this.is_disabled=this.form_field_jq[0].disabled;if(this.is_disabled)return this.container.addClass("chzn-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus",this.activate_action),this.close_field();this.container.removeClass("chzn-disabled"),this.search_field[0].disabled=!1;if(!this.is_multiple)return this.selected_item.bind("focus",this.activate_action)},e.prototype.container_mousedown=function(b){var c;if(!this.is_disabled)return c=b!=null?a(b.target).hasClass("search-choice-close"):!1,b&&b.type==="mousedown"&&!this.results_showing&&b.stopPropagation(),!this.pending_destroy_click&&!c?(this.active_field?!this.is_multiple&&b&&(a(b.target)[0]===this.selected_item[0]||a(b.target).parents("a.chzn-single").length)&&(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(document).click(this.click_test_action),this.results_show()),this.activate_field()):this.pending_destroy_click=!1},e.prototype.container_mouseup=function(a){if(a.target.nodeName==="ABBR")return this.results_reset(a)},e.prototype.blur_test=function(a){if(!this.active_field&&this.container.hasClass("chzn-container-active"))return this.close_field()},e.prototype.close_field=function(){return a(document).unbind("click",this.click_test_action),this.is_multiple||(this.selected_item.attr("tabindex",this.search_field.attr("tabindex")),this.search_field.attr("tabindex",-1)),this.active_field=!1,this.results_hide(),this.container.removeClass("chzn-container-active"),this.winnow_results_clear(),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},e.prototype.activate_field=function(){return!this.is_multiple&&!this.active_field&&(this.search_field.attr("tabindex",this.selected_item.attr("tabindex")),this.selected_item.attr("tabindex",-1)),this.container.addClass("chzn-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},e.prototype.test_active_click=function(b){return a(b.target).parents("#"+this.container_id).length?this.active_field=!0:this.close_field()},e.prototype.results_build=function(){var a,b,c,e,f;this.parsing=!0,this.results_data=d.SelectParser.select_to_array(this.form_field),this.is_multiple&&this.choices>0?(this.search_choices.find("li.search-choice").remove(),this.choices=0):this.is_multiple||(this.selected_item.find("span").text(this.default_text),this.form_field.options.length<=this.disable_search_threshold?this.container.addClass("chzn-container-single-nosearch"):this.container.removeClass("chzn-container-single-nosearch")),a="",f=this.results_data;for(c=0,e=f.length;c'+a("
          ").text(b.label).html()+"")},e.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight();if(b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(c'+b.html+''),d=a("#"+c).find("a").first(),d.click(function(a){return e.choice_destroy_link_click(a)})},e.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),this.is_disabled?b.stopPropagation:(this.pending_destroy_click=!0,this.choice_destroy(a(b.target)))},e.prototype.choice_destroy=function(a){return this.choices-=1,this.show_search_field_default(),this.is_multiple&&this.choices>0&&this.search_field.val().length<1&&this.results_hide(),this.result_deselect(a.attr("rel")),a.parents("li").first().remove()},e.prototype.results_reset=function(b){this.form_field.options[0].selected=!0,this.selected_item.find("span").text(this.default_text),this.is_multiple||this.selected_item.addClass("chzn-default"),this.show_search_field_default(),a(b.target).remove(),this.form_field_jq.trigger("change");if(this.active_field)return this.results_hide()},e.prototype.result_select=function(a){var b,c,d,e;if(this.result_highlight)return b=this.result_highlight,c=b.attr("id"),this.result_clear_highlight(),this.is_multiple?this.result_deactivate(b):(this.search_results.find(".result-selected").removeClass("result-selected"),this.result_single_selected=b,this.selected_item.removeClass("chzn-default")),b.addClass("result-selected"),e=c.substr(c.lastIndexOf("_")+1),d=this.results_data[e],d.selected=!0,this.form_field.options[d.options_index].selected=!0,this.is_multiple?this.choice_build(d):(this.selected_item.find("span").first().text(d.text),this.allow_single_deselect&&this.single_deselect_control_build()),(!a.metaKey||!this.is_multiple)&&this.results_hide(),this.search_field.val(""),this.form_field_jq.trigger("change"),this.search_field_scale()},e.prototype.result_activate=function(a){return a.addClass("active-result")},e.prototype.result_deactivate=function(a){return a.removeClass("active-result")},e.prototype.result_deselect=function(b){var c,d;return d=this.results_data[b],d.selected=!1,this.form_field.options[d.options_index].selected=!1,c=a("#"+this.container_id+"_o_"+b),c.removeClass("result-selected").addClass("active-result").show(),this.result_clear_highlight(),this.winnow_results(),this.form_field_jq.trigger("change"),this.search_field_scale()},e.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect&&this.selected_item.find("abbr").length<1)return this.selected_item.find("span").first().after('')},e.prototype.winnow_results=function(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;this.no_results_clear(),j=0,k=this.search_field.val()===this.default_text?"":a("
          ").text(a.trim(this.search_field.val())).html(),g=this.search_contains?"":"^",f=new RegExp(g+k.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),n=new RegExp(k.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"i"),s=this.results_data;for(o=0,q=s.length;o=0||c.html.indexOf("[")===0){e=c.html.replace(/\[|\]/g,"").split(" ");if(e.length)for(p=0,r=e.length;p"+c.html.substr(l+k.length),m=m.substr(0,l)+""+m.substr(l)):m=c.html,h.html(m),this.result_activate(h),c.group_array_index!=null&&a("#"+this.results_data[c.group_array_index].dom_id).css("display","list-item")):(this.result_highlight&&i===this.result_highlight.attr("id")&&this.result_clear_highlight(),this.result_deactivate(h))}}return j<1&&k.length?this.no_results(k):this.winnow_results_set_highlight()},e.prototype.winnow_results_clear=function(){var b,c,d,e,f;this.search_field.val(""),c=this.search_results.find("li"),f=[];for(d=0,e=c.length;d'+this.results_none_found+' ""'),c.find("span").first().html(b),this.search_results.append(c)},e.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},e.prototype.keydown_arrow=function(){var b,c;this.result_highlight?this.results_showing&&(c=this.result_highlight.nextAll("li.active-result").first(),c&&this.result_do_highlight(c)):(b=this.search_results.find("li.active-result").first(),b&&this.result_do_highlight(a(b)));if(!this.results_showing)return this.results_show()},e.prototype.keyup_arrow=function(){var a;if(!this.results_showing&&!this.is_multiple)return this.results_show();if(this.result_highlight)return a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices>0&&this.results_hide(),this.result_clear_highlight())},e.prototype.keydown_backstroke=function(){return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(this.pending_backstroke=this.search_container.siblings("li.search-choice").last(),this.pending_backstroke.addClass("search-choice-focus"))},e.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},e.prototype.keydown_checker=function(a){var b,c;b=(c=a.which)!=null?c:a.keyCode,this.search_field_scale(),b!==8&&this.pending_backstroke&&this.clear_backstroke();switch(b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:this.keydown_arrow()}},e.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j,k;if(this.is_multiple){d=0,i=0,g="position:absolute; left: -1000px; top: -1000px; display:none;",h=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"];for(j=0,k=h.length;j",{style:g}),c.text(this.search_field.val()),a("body").append(c),i=c.width()+25,c.remove(),i>this.f_width-10&&(i=this.f_width-10),this.search_field.css({width:i+"px"}),e=this.rise_up(this.container,this.dropdown),b=e?-this.container.find(".chzn-drop").height():this.container.height(),this.dropdown.css({top:b+"px"})}},e.prototype.generate_random_id=function(){var b;b="sel"+this.generate_random_char()+this.generate_random_char()+this.generate_random_char();while(a("#"+b).length>0)b+=this.generate_random_char();return b},e.prototype.rise_up=function(b,c){var d,e,f,g;return g=b.find("a.chzn-single"),f=a(window).height()+a(document).scrollTop()-b.find("a").innerHeight(),e=g.offset().top,d=c.innerHeight(),e+d>f&&e-d>0?(b.addClass("chzn-with-rise"),!0):(b.removeClass("chzn-with-rise"),!1)},e}(AbstractChosen),c=function(a){var b;return b=a.outerWidth()-a.width()},d.get_side_border_padding=c}.call(this); \ No newline at end of file diff --git a/admin/thirdparty/chosen/coffee/chosen.jquery.coffee b/admin/thirdparty/chosen/coffee/chosen.jquery.coffee index 6359b9986..fa3dd781a 100644 --- a/admin/thirdparty/chosen/coffee/chosen.jquery.coffee +++ b/admin/thirdparty/chosen/coffee/chosen.jquery.coffee @@ -6,6 +6,7 @@ root = this $ = jQuery $.fn.extend({ + chosen: (options) -> # Do no harm and return as soon as possible for unsupported browsers, namely IE6 and IE7 return this if $.browser.msie and ($.browser.version is "6.0" or $.browser.version is "7.0") @@ -50,8 +51,14 @@ class Chosen extends AbstractChosen @container = ($ '#' + @container_id) @container.addClass( "chzn-container-" + (if @is_multiple then "multi" else "single") ) @dropdown = @container.find('div.chzn-drop').first() - - dd_top = @container.height() + + ### + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + ### + rise = @rise_up(@container, @dropdown) + dd_top = if rise then -this.container.find('.chzn-drop').height() else @container.height() + #patch applied: https://github.com/harvesthq/chosen/issues/300 dd_width = (@container.width - get_side_border_padding(@dropdown)) @@ -71,7 +78,7 @@ class Chosen extends AbstractChosen @selected_item = @container.find('.chzn-single').first() sf_width = dd_width - get_side_border_padding(@search_container) - get_side_border_padding(@search_field) @search_field.css( {"width" : sf_width + "px"} ) - + this.results_build() this.set_tab_index() @form_field_jq.trigger("liszt:ready", {chosen: this}) @@ -173,6 +180,7 @@ class Chosen extends AbstractChosen @parsing = true @results_data = root.SelectParser.select_to_array @form_field + if @is_multiple and @choices > 0 @search_choices.find("li.search-choice").remove() @choices = 0 @@ -202,7 +210,6 @@ class Chosen extends AbstractChosen @search_results.html content @parsing = false - result_add_group: (group) -> if not group.disabled group.dom_id = @container_id + "_g_" + group.array_index @@ -237,9 +244,14 @@ class Chosen extends AbstractChosen if not @is_multiple @selected_item.addClass "chzn-single-with-drop" if @result_single_selected - this.result_do_highlight( @result_single_selected ) + this.result_do_highlight( @result_single_selected ) - dd_top = if @is_multiple then @container.height() else (@container.height() - 1) + ### + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + ### + rise = @rise_up(@container, @dropdown) + dd_top = if rise then -this.container.find('.chzn-drop').height() else if @is_multiple then @container.height() else (@container.height() - 1) #patch applied: https://github.com/harvesthq/chosen/issues/300, add variable assignment dd_width dd_width = this.container.width() - get_side_border_padding(@dropdown); @@ -552,7 +564,13 @@ class Chosen extends AbstractChosen @search_field.css({'width': w + 'px'}) - dd_top = @container.height() + ### + CALL CUSTOM FUNCTION: rise_up + # if rise-up true, reverse drop-up direction + ### + rise = @rise_up(@container, @dropdown) + dd_top = if rise then -this.container.find('.chzn-drop').height() else @container.height() + @dropdown.css({"top": dd_top + "px"}) generate_random_id: -> @@ -560,6 +578,30 @@ class Chosen extends AbstractChosen while $("#" + string).length > 0 string += this.generate_random_char() string + + + + ### + SILVERSTRIPE CUSTOM FUNCTION + Rise_up function handles the case where a dropdown exceeds the height of the window + # Adds class if true, returns true + # Removes class if false, returns false + This facilitates the behaviour where the drop-down will drop up if there is no room + to drop down + ### + rise_up: (container, dropdown) -> + trigger = container.find('a.chzn-single'); + endOfWindow = ($(window).height() + $(document).scrollTop()) - container.find('a').innerHeight(); + elPos = trigger.offset().top + elHeight = dropdown.innerHeight() + + if elPos + elHeight > endOfWindow and elPos - elHeight > 0 + container.addClass('chzn-with-rise') + true + else + container.removeClass('chzn-with-rise') + false + get_side_border_padding = (elmt) -> side_border_padding = elmt.outerWidth() - elmt.width()