Source: panels/keyboard/installed_keyboards.js

  1. /**
  2. * The module initializes a ListView displaying the installed keyboards.
  3. * Implementation details please refer to {@link KeyboardCore}.
  4. *
  5. * @module keyboard/installed_keyboards
  6. */
  7. define(function(require) {
  8. 'use strict';
  9. var ListView = require('modules/mvvm/list_view');
  10. /**
  11. * @alias module:keyboard/installed_keyboards
  12. * @class KeyboardCore
  13. * @requires module:modules/mvvm/list_view
  14. * @param {KeyboardContext} context
  15. The kyboard context providing installed keyboards.
  16. * @param {Function} template
  17. The template function used to render an installed
  18. keyboard.
  19. * @returns {KeyboardCore}
  20. */
  21. function KeyboardCore(context, template) {
  22. this._enabled = false;
  23. this._listView = null;
  24. this._keyboardContext = context;
  25. this._keyboardTemplate = template;
  26. }
  27. KeyboardCore.prototype = {
  28. /**
  29. * The value indicates whether the module is responding. If it is false, the
  30. * UI stops reflecting the updates from the keyboard context.
  31. *
  32. * @access public
  33. * @memberOf KeyboardCore.prototype
  34. * @type {Boolean}
  35. */
  36. get enabled() {
  37. return this._enabled;
  38. },
  39. set enabled(value) {
  40. this._enabled = value;
  41. if (this._listView) {
  42. this._listView.enabled = this._enabled;
  43. }
  44. },
  45. /**
  46. * @access private
  47. * @memberOf KeyboardCore.prototype
  48. * @param {HTMLElement} listViewRoot
  49. * @param {ObservableArray} keyboards
  50. * @param {Function} keyboardTemplate
  51. */
  52. _initAllKeyboardListView:
  53. function k_initListView(listViewRoot, keyboards, keyboardTemplate) {
  54. listViewRoot.hidden = (keyboards.length === 0);
  55. this._listView = ListView(listViewRoot, keyboards, keyboardTemplate);
  56. },
  57. /**
  58. * @access public
  59. * @memberOf KeyboardCore.prototype
  60. * @param {Array} elements
  61. * Elements needed by this module.
  62. * @param {HTMLElement} elements.listViewRoot
  63. * The root element for the list view displaying the
  64. * installed keyboards.
  65. */
  66. init: function k_init(elements) {
  67. var that = this;
  68. this._keyboardContext.init(function() {
  69. that._keyboardContext.keyboards(function(keyboards) {
  70. that._initAllKeyboardListView(
  71. elements.listViewRoot, keyboards, that._keyboardTemplate);
  72. that.enabled = true;
  73. });
  74. });
  75. }
  76. };
  77. return function ctor_keyboardCore(context, template) {
  78. return new KeyboardCore(context, template);
  79. };
  80. });