From c5d6cb13276b257048a4b52903be2f5b1f2d7bbc Mon Sep 17 00:00:00 2001 From: Justin DuJardin Date: Sat, 31 Mar 2012 10:20:49 -0700 Subject: [PATCH] Deal with non-existent style attributes, and returning calculated pixel widths as a fallback. --- select2.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/select2.js b/select2.js index 4df4c0f9..42d38d46 100755 --- a/select2.js +++ b/select2.js @@ -1,4 +1,4 @@ -/* +/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information @@ -603,16 +603,18 @@ AbstractSelect2.prototype.getContainerWidth = function() { if (this.opts.width !== undefined) return this.opts.width; - + var style = this.opts.element.attr('style'); - var attrs = style.split(';'); - for (var i = 0; i < attrs.length; i++) { - var matches = attrs[i].replace(/\s/g,'') + if(style !== undefined){ + var attrs = style.split(';'); + for (var i = 0; i < attrs.length; i++) { + var matches = attrs[i].replace(/\s/g,'') .match(/width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/); - if(matches != null && matches.length >= 1) - return matches[1]; + if(matches != null && matches.length >= 1) + return matches[1]; + } } - return this.opts.element.width(); + return this.opts.element.width() + 'px'; };