/** * Input elements and utilities for Lens LAF. * * Brings up the keyboard screen when a text input element is touched, and a * selection modal when a select element is touched. Add a `data-lens-ignore` * attribute to input elements to prevent this behavior for the element. * * @name Lens.LAF.Input * @namespace */ define(["lib/jquery", "lib/underscore", "common/util/dom_utils", "Components/modal", "ARCore/keyboards"], function($, _, DOMUtils, Modal, Keyboards) { "use strict"; var enabled = true; var Input = /** @lends Lens.LAF.Input */ { /** * Enables input styling and interaction */ enable: function() { DOMUtils.addStylesheet("LAF/widgets/input.less"); enabled = true; }, /** * Disabled input styling and interaction */ disable: function() { DOMUtils.removeStylesheet("LAF/widgets/input.less"); enabled = false; }, /** * Returns true iff this LAF module is enabled * @return {Boolean} * @memberOf Lens.LAF.Input */ enabled: function() { return enabled; } }; $(function(){ document.addEventListener("click", function(evt) { if(!enabled) { return; } if($(evt.target).is("input[type=text]:not([data-lens-ignore])")) { // text input if(_.contains(Keyboards.available(), Keyboards.PHONE)) { // use phone keyboard; just focus text $(evt.target).focus(); $(evt.target).select(); } else { Modal.textEntry($(evt.target).val(), function(text) { $(evt.target).val(text); }); } } if($(evt.target).is("select:not([data-lens-ignore])")) { // select element Modal.select({ options: $(evt.target).find("option").map(function(i, option) { return $(option).text(); }).get() }, function(selected) { var val = $(evt.target).find("option:contains('" + selected + "')").val(); $(evt.target).val(val); }); } else { $(document.activeElement).blur(); } }); }); Input.enable(); Lens._addMember(Input, "Input", Lens.LAF); return Input; });