(function ($, document, window, undefined) { var s2 = window.s2 = window.s2 || {}; var util = s2.util; var assert = util.assert; s2.Dropdown = util.clazz(util.Observable, { construct: function (opts) { assert.isNotNull(opts, "opts parameter must be set"); assert.isElement(opts.select, "opts.select must point to the select element"); this.super(); this.opts = opts; }, bind: function (container, tag) { assert.isElement(container, "container parameter must be set"); assert.isElement(tag, "tag parameter must be set"); this.container = container; this.element = tag; this.element.addClass("s2-dropdown"); this.element.detach(); this.element.removeClass("s2-hidden"); //util.detectPlatform(this.element); }, show: function () { var self = this; self.opts.select.parent("body").append(this.element); self.position(); self.container.addClass("s2-active"); }, hide: function () { var self = this; self.element.detach(); self.container.removeClass("s2-active"); }, position: function () { var self = this, container = self.container; var offset = container.offset(), height = container.outerHeight(false), width = container.outerWidth(false), dropTop = offset.top + height, dropLeft = offset.left; self.element.css({ top: dropTop, left: dropLeft, width: width }); } }); s2.SearchField = util.clazz(util.Observable, { construct: function (element) { this.super(); var self = this; this.value = element.val(); this.element = element; this.element.on("keyup.s2", function () { self.onKeyUp.apply(self, arguments) }); }, onKeyUp: function (e) { var self = this; if (self.value !== self.element.val()) { self.trigger("valueChanged", { oldValue: self.value, value: self.element.val(), event: e}); self.value = self.element.val(); } }, focus: function () { this.element.focus(); }, val: function () { return this.element.val(); } }); s2.ResultList = util.clazz(util.Observable, { construct: function (opts) { assert.isNotNull(opts, "opts argument must be set"); assert.isElement(opts.select, "opts.select must point to the select element"); this.super(); this.opts = opts; this.tag = util.tag(); this.queryParams = {}; }, render: function () { return new util.Markup("
"); }, bind: function (container) { var self = this; this.container = container; this.element = container.find("#" + this.tag); assert.isElement(this.element, "Could not find result list element"); this.container.attr("tabindex", "0"); this.container.on("keydown", function (e) { self.onKeyDown(e); }); this.container.on("focusout", function (e) { self.onBlur(e); }); this.element.on("click", function () { self.onClick.apply(self, arguments); }); //util.detectPlatform(this.element); }, show: function () { var self = this; self.update(); }, update: function () { var self = this; var index = 0; self.data = []; self.element.find(".s2-options").remove(); var options = $(" "); self.element.append(options); $.each(self.query(), function () { var option = $(["