diff --git a/jquery.customSelect.js b/jquery.customSelect.js
index ce57c28..7143d41 100644
--- a/jquery.customSelect.js
+++ b/jquery.customSelect.js
@@ -29,7 +29,14 @@
customSelectSpanInner = customSelectSpan.children(':first'),
html = currentSelected.html() || ' ';
- customSelectSpanInner.html(html);
+ if(customSelectSpan.hasClass(getClass('NoWrap')) == true)
+ {
+ noWrapTextApply(customSelectSpan, html)
+ }
+ else
+ {
+ customSelectSpanInner.html(html);
+ }
if (currentSelected.attr('disabled')) {
customSelectSpan.addClass(getClass('DisabledOption'));
@@ -39,19 +46,79 @@
setTimeout(function () {
customSelectSpan.removeClass(getClass('Open'));
- $(document).off('mouseup.customSelect');
+ $(document).off('mouseup.customSelect');
+ $select.css({
+ width: customSelectSpan.outerWidth()
+ });
}, 60);
},
+
+ noWrapTextApply = function(customSelectSpan, txt){
+ var arrWords = txt.split(' '),
+ arrLetters = txt.split(''),
+ label = customSelectSpan.find('.' + getClass('Inner')),
+ testLabel = customSelectSpan.find('.' + getClass('TestInner')),
+ maxWidth = customSelectSpan.width(),
+ finishText = '...',
+ tempText = txt;
+
+ testLabel.html(txt);
+ if(testLabel.width() > maxWidth)
+ {
+ if(arrWords.length > 1)
+ {
+ for(var i = arrWords.length - 1; i >= 0; --i)
+ {
+ tempText = '';
+ for(var j = 0, total = i; j < total; ++j)
+ {
+ tempText = tempText + ((j == 0) ? arrWords[j] : ' ' + arrWords[j]);
+ }
+ testLabel.html(tempText + finishText);
+ if(testLabel.width() < maxWidth)
+ {
+ tempText = tempText + finishText;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for(var i = arrLetters.length - 1; i >= 0; --i)
+ {
+ tempText = '';
+ for(var j = 0, total = i; j < total; ++j)
+ {
+ tempText = tempText + arrLetters[j];
+ }
+ testLabel.html(tempText + finishText);
+ if(testLabel.width() > maxWidth)
+ {
+ tempText = tempText + finishText;
+ break;
+ }
+ }
+ }
+ label.html(tempText);
+ }
+ else
+ {
+ label.html(txt);
+ }
+ },
+
getClass = function(suffix){
return prefix + suffix;
};
return this.each(function () {
var $select = $(this),
- customSelectInnerSpan = $('').addClass(getClass('Inner')),
+ customSelectInnerSpan = $('2').addClass(getClass('Inner')),
+ customSelectInnerTestSpan = $('2').addClass(getClass('TestInner')).html('...'),
customSelectSpan = $('');
$select.after(customSelectSpan.append(customSelectInnerSpan));
+ $select.after(customSelectSpan.append(customSelectInnerTestSpan));
customSelectSpan.addClass(prefix);
@@ -61,12 +128,14 @@
if (options.mapStyle) {
customSelectSpan.attr('style', $select.attr('style'));
}
+ if(options.noWrap) {
+ customSelectSpan.addClass(getClass('NoWrap'));
+ }
$select
.addClass('hasCustomSelect')
.on('render.customSelect', function () {
- changed($select,customSelectSpan);
- $select.css('width','');
+ $select.css('width','');
var selectBoxWidth = parseInt($select.outerWidth(), 10) -
(parseInt(customSelectSpan.outerWidth(), 10) -
parseInt(customSelectSpan.width(), 10));
@@ -91,12 +160,14 @@
$select.css({
'-webkit-appearance': 'menulist-button',
- width: customSelectSpan.outerWidth(),
+ width: customSelectSpan.width(),
position: 'absolute',
opacity: 0,
height: selectBoxHeight,
fontSize: customSelectSpan.css('font-size')
});
+
+ changed($select,customSelectSpan);
})
.on('change.customSelect', function () {
customSelectSpan.addClass(getClass('Changed'));
@@ -150,4 +221,4 @@
});
}
});
-})(jQuery);
+})(jQuery);
\ No newline at end of file
diff --git a/jquery.customSelect.min.js b/jquery.customSelect.min.js
index e68c5e1..c4f0600 100644
--- a/jquery.customSelect.min.js
+++ b/jquery.customSelect.min.js
@@ -7,4 +7,4 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @license http://www.gnu.org/licenses/gpl.html GPL2 License
*/
-(function(a){a.fn.extend({customSelect:function(c){if(typeof document.body.style.maxHeight==="undefined"){return this}var e={customClass:"customSelect",mapClass:true,mapStyle:true},c=a.extend(e,c),d=c.customClass,f=function(h,k){var g=h.find(":selected"),j=k.children(":first"),i=g.html()||" ";j.html(i);if(g.attr("disabled")){k.addClass(b("DisabledOption"))}else{k.removeClass(b("DisabledOption"))}setTimeout(function(){k.removeClass(b("Open"));a(document).off("mouseup.customSelect")},60)},b=function(g){return d+g};return this.each(function(){var g=a(this),i=a("").addClass(b("Inner")),h=a("");g.after(h.append(i));h.addClass(d);if(c.mapClass){h.addClass(g.attr("class"))}if(c.mapStyle){h.attr("style",g.attr("style"))}g.addClass("hasCustomSelect").on("render.customSelect",function(){f(g,h);g.css("width","");var k=parseInt(g.outerWidth(),10)-(parseInt(h.outerWidth(),10)-parseInt(h.width(),10));h.css({display:"inline-block"});var j=h.outerHeight();if(g.attr("disabled")){h.addClass(b("Disabled"))}else{h.removeClass(b("Disabled"))}i.css({width:k,display:"inline-block"});g.css({"-webkit-appearance":"menulist-button",width:h.outerWidth(),position:"absolute",opacity:0,height:j,fontSize:h.css("font-size")})}).on("change.customSelect",function(){h.addClass(b("Changed"));f(g,h)}).on("keyup.customSelect",function(j){if(!h.hasClass(b("Open"))){g.trigger("blur.customSelect");g.trigger("focus.customSelect")}else{if(j.which==13||j.which==27){f(g,h)}}}).on("mousedown.customSelect",function(){h.removeClass(b("Changed"))}).on("mouseup.customSelect",function(j){if(!h.hasClass(b("Open"))){if(a("."+b("Open")).not(h).length>0&&typeof InstallTrigger!=="undefined"){g.trigger("focus.customSelect")}else{h.addClass(b("Open"));j.stopPropagation();a(document).one("mouseup.customSelect",function(k){if(k.target!=g.get(0)&&a.inArray(k.target,g.find("*").get())<0){g.trigger("blur.customSelect")}else{f(g,h)}})}}}).on("focus.customSelect",function(){h.removeClass(b("Changed")).addClass(b("Focus"))}).on("blur.customSelect",function(){h.removeClass(b("Focus")+" "+b("Open"))}).on("mouseenter.customSelect",function(){h.addClass(b("Hover"))}).on("mouseleave.customSelect",function(){h.removeClass(b("Hover"))}).trigger("render.customSelect")})}})})(jQuery);
\ No newline at end of file
+!function(e){"use strict";e.fn.extend({customSelect:function(t){if("undefined"==typeof document.body.style.maxHeight)return this;var s={customClass:"customSelect",mapClass:!0,mapStyle:!0},t=e.extend(s,t),n=t.customClass,a=function(t,s){var n=t.find(":selected"),a=s.children(":first"),i=n.html()||" ";1==s.hasClass(l("NoWrap"))?o(s,i):a.html(i),n.attr("disabled")?s.addClass(l("DisabledOption")):s.removeClass(l("DisabledOption")),setTimeout(function(){s.removeClass(l("Open")),e(document).off("mouseup.customSelect"),t.css({width:s.outerWidth()})},60)},o=function(e,t){var s=t.split(" "),n=t.split(""),a=e.find("."+l("Inner")),o=e.find("."+l("TestInner")),i=e.width(),c="...",r=t;if(o.html(t),o.width()>i){if(s.length>1)for(var u=s.length-1;u>=0;--u){r="";for(var d=0,m=u;m>d;++d)r+=0==d?s[d]:" "+s[d];if(o.html(r+c),o.width()=0;--u){r="";for(var d=0,m=u;m>d;++d)r+=n[d];if(o.html(r+c),o.width()>i){r+=c;break}}a.html(r)}else a.html(t)},l=function(e){return n+e};return this.each(function(){var s=e(this),o=e("2").addClass(l("Inner")),i=e("2").addClass(l("TestInner")).html("..."),c=e("");s.after(c.append(o)),s.after(c.append(i)),c.addClass(n),t.mapClass&&c.addClass(s.attr("class")),t.mapStyle&&c.attr("style",s.attr("style")),t.noWrap&&c.addClass(l("NoWrap")),s.addClass("hasCustomSelect").on("render.customSelect",function(){s.css("width","");var e=parseInt(s.outerWidth(),10)-(parseInt(c.outerWidth(),10)-parseInt(c.width(),10));c.css({display:"inline-block"});var t=c.outerHeight();s.attr("disabled")?c.addClass(l("Disabled")):c.removeClass(l("Disabled")),o.css({width:e,display:"inline-block"}),s.css({"-webkit-appearance":"menulist-button",width:c.width(),position:"absolute",opacity:0,height:t,fontSize:c.css("font-size")}),a(s,c)}).on("change.customSelect",function(){c.addClass(l("Changed")),a(s,c)}).on("keyup.customSelect",function(e){c.hasClass(l("Open"))?(13==e.which||27==e.which)&&a(s,c):(s.trigger("blur.customSelect"),s.trigger("focus.customSelect"))}).on("mousedown.customSelect",function(){c.removeClass(l("Changed"))}).on("mouseup.customSelect",function(t){c.hasClass(l("Open"))||(e("."+l("Open")).not(c).length>0&&"undefined"!=typeof InstallTrigger?s.trigger("focus.customSelect"):(c.addClass(l("Open")),t.stopPropagation(),e(document).one("mouseup.customSelect",function(t){t.target!=s.get(0)&&e.inArray(t.target,s.find("*").get())<0?s.trigger("blur.customSelect"):a(s,c)})))}).on("focus.customSelect",function(){c.removeClass(l("Changed")).addClass(l("Focus"))}).on("blur.customSelect",function(){c.removeClass(l("Focus")+" "+l("Open"))}).on("mouseenter.customSelect",function(){c.addClass(l("Hover"))}).on("mouseleave.customSelect",function(){c.removeClass(l("Hover"))}).trigger("render.customSelect")})}})}(jQuery);
\ No newline at end of file