'use strict'; /* global MozActivity, Sanitizer */ (function(exports) { /** * ImeMenu displays a list of currently enabled IMEs in an overlay. * @class ImeMenu * @param {Array} listItems An array of objects to display. * @param {String} title L10n ID of the the content of the header. * @param {Function} successCb Called when the user selects an option. * @param {Function} cancelCb Called when the menu is cancelled. */ function ImeMenu(listItems, title, successCb, cancelCb) { this.onselected = successCb || function() {}; this.oncancel = cancelCb || function() {}; this.listItems = listItems; this.title = title; } ImeMenu.prototype = { /** * Start the ImeMenu instance * @memberof ImeMenu.prototype */ start: function() { this.initUI(); }, /** * Builds dom and adds event listeners * @memberof ImeMenu.prototype */ initUI: function() { var dummy = document.createElement('div'); dummy.innerHTML = Sanitizer.unwrapSafeHTML(this.imeMenuView({ title: this.title })); this.container = dummy.firstElementChild; // We have a menu with all the options this.menu = this.container.querySelector('.ime-menu-list'); this.buildMenu(this.listItems); // We append to System app (actually to '#screen') document.getElementById('screen').appendChild(this.container); this.container.addEventListener('submit', this); this.container.addEventListener('click', this); window.addEventListener('attentionopened', this, true); window.addEventListener('screenchange', this, true); window.addEventListener('home', this); window.addEventListener('holdhome', this); this.container.addEventListener('mousedown', this.preventFocusChange); window.dispatchEvent(new CustomEvent('imemenushow')); }, /** * Removes the dom and stops event listeners * @memberof ImeMenu.prototype */ stop: function() { document.getElementById('screen').removeChild(this.container); window.removeEventListener('attentionopened', this, true); window.removeEventListener('screenchange', this, true); window.removeEventListener('home', this); window.removeEventListener('holdhome', this); this.container.removeEventListener('mousedown', this.preventFocusChange); }, /** * Returns the view for the ime menu. * @memberof ImeMenu.prototype */ imeMenuView: function({title, cancelLabel}) { return Sanitizer.createSafeHTML `