From 4955be239d8690b647c1d7a5fb91976d60ae5267 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 26 Jun 2014 11:48:04 -0300 Subject: [PATCH] Testing if the object exists before use it It's necessary to make the code compatible with IE8 and IE9. --- select2.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/select2.js b/select2.js index faeac47a..1b928626 100644 --- a/select2.js +++ b/select2.js @@ -855,7 +855,9 @@ the specific language governing permissions and limitations under the Apache Lic if (element.length && element[0].detachEvent && self._sync) { element.each(function () { - this.detachEvent("onpropertychange", self._sync); + if (self._sync) { + this.detachEvent("onpropertychange", self._sync); + } }); } if (this.propertyObserver) { @@ -1116,11 +1118,15 @@ the specific language governing permissions and limitations under the Apache Lic if (readonly === undefined) readonly = false; this.readonly(readonly); - syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass); - this.container.addClass(evaluate(this.opts.containerCssClass, this.opts.element)); + if (this.container) { + syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass); + this.container.addClass(evaluate(this.opts.containerCssClass, this.opts.element)); + } - syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass); - this.dropdown.addClass(evaluate(this.opts.dropdownCssClass, this.opts.element)); + if (this.dropdown) { + syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass); + this.dropdown.addClass(evaluate(this.opts.dropdownCssClass, this.opts.element)); + } });