From ab1a8b93bf8d3e10a6f2955e1f6363533608abb1 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Thu, 26 Jul 2012 08:59:51 +0300 Subject: [PATCH] some code cleanup. fixes #269 --- select2.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/select2.js b/select2.js index cc550651..052da3e9 100755 --- a/select2.js +++ b/select2.js @@ -93,7 +93,7 @@ nextUid=(function() { var counter=1; return function() { return counter++; }; }()); function escapeMarkup(markup) { - if (typeof(markup) === "string") { + if (markup && typeof(markup) === "string") { return markup.replace("&", "&"); } else { return markup; @@ -393,7 +393,7 @@ */ $(document).ready(function () { $(document).delegate("*", "mousedown touchend", function (e) { - var target = $(e.target).closest("div.select2-container").get(0); + var target = $(e.target).closest("div.select2-container").get(0), attr; if (target) { $(document).find("div.select2-container-active").each(function () { if (this !== target) $(this).data("select2").blur(); @@ -406,8 +406,9 @@ } target=$(e.target); - if ("LABEL" === e.target.tagName && target.attr("for").length > 0) { - target = $("#"+target.attr("for")); + attr = target.attr("for"); + if ("LABEL" === e.target.tagName && attr && attr.length > 0) { + target = $("#"+attr); target = target.data("select2"); if (target !== undefined) { target.focus(); e.preventDefault();} }