Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
125
gaia/apps/settings/js/panels/keyboard_add_layouts/core.js
Executable file
125
gaia/apps/settings/js/panels/keyboard_add_layouts/core.js
Executable file
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* The module initializes a ListView displaying all installed layouts.
|
||||
* Implementation details please refer to {@link KeyboardAddLayoutsCore}.
|
||||
*
|
||||
* @module keyboard_add_layouts/core
|
||||
*/
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var ListView = require('modules/mvvm/list_view');
|
||||
|
||||
/**
|
||||
* @alias module:keyboard_add_layouts/core
|
||||
* @class KeyboardAddLayoutsCore
|
||||
* @requires module:modules/settings_service
|
||||
* @requires module:modules/mvvm/list_view
|
||||
* @param {KeyboardContext} context
|
||||
The kyboard context providing installed keyboards.
|
||||
* @param {Function} template
|
||||
The template function used to render an installed
|
||||
keyboard.
|
||||
* @returns {KeyboardAddLayoutsCore}
|
||||
*/
|
||||
function KeyboardAddLayoutsCore(context, template) {
|
||||
this._enabled = false;
|
||||
this._listView = null;
|
||||
this._keyboardContext = context;
|
||||
this._keyboardTemplate = template;
|
||||
}
|
||||
|
||||
KeyboardAddLayoutsCore.prototype = {
|
||||
/**
|
||||
* The value indicates whether the module is responding. If it is false, the
|
||||
* UI stops reflecting the updates from the keyboard context.
|
||||
*
|
||||
* @access public
|
||||
* @memberOf KeyboardAddLayoutsCore.prototype
|
||||
* @type {Boolean}
|
||||
*/
|
||||
get enabled() {
|
||||
return this._enabled;
|
||||
},
|
||||
|
||||
set enabled(value) {
|
||||
this._enabled = value;
|
||||
if (this._listView) {
|
||||
this._listView.enabled = this._enabled;
|
||||
}
|
||||
// Disable all inner list views
|
||||
this._keyboardTemplate.listViews.forEach(function(listView) {
|
||||
listView.enabled = this._enabled;
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* @access private
|
||||
* @memberOf KeyboardAddLayoutsCore.prototype
|
||||
* @param {HTMLElement} listViewRoot
|
||||
* @param {ObservableArray} keyboards
|
||||
* @param {Function} keyboardTemplate
|
||||
*/
|
||||
_initInstalledLayoutListView:
|
||||
function kal_initListView(listViewRoot, keyboards, keyboardTemplate) {
|
||||
this._listView = ListView(listViewRoot, keyboards, keyboardTemplate);
|
||||
},
|
||||
|
||||
/**
|
||||
* The handler is invoked when users disable the must-have input type. In
|
||||
* the handler we navigate to the dialog.
|
||||
*
|
||||
* @access private
|
||||
* @memberOf KeyboardAddLayoutsCore.prototype
|
||||
* @param {Object} layout
|
||||
* @param {String} missingType
|
||||
*/
|
||||
_showEnabledDefaultDialog: function kal_showDialog(layout, missingType) {
|
||||
require(['modules/dialog_service'], function(DialogService) {
|
||||
document.l10n.formatValue('keyboardType-' + missingType).then(
|
||||
type => {
|
||||
DialogService.alert({
|
||||
id: 'defaultKeyboardEnabled',
|
||||
args: {
|
||||
layoutName: layout.inputManifest.name,
|
||||
appName: layout.manifest.name
|
||||
}
|
||||
}, {
|
||||
title: {
|
||||
id: 'mustHaveOneKeyboard',
|
||||
args: {
|
||||
type: type
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @access public
|
||||
* @memberOf KeyboardAddLayoutsCore.prototype
|
||||
* @param {Array} elements
|
||||
* Elements needed by this module.
|
||||
* @param {HTMLElement} elements.listViewRoot
|
||||
* The root element for the list view displaying the
|
||||
* installed keyboards.
|
||||
*/
|
||||
init: function kal_onInit(elements) {
|
||||
var that = this;
|
||||
this._keyboardContext.init(function() {
|
||||
that._keyboardContext.keyboards(function(keyboards) {
|
||||
that._initInstalledLayoutListView(
|
||||
elements.listViewRoot, keyboards, that._keyboardTemplate);
|
||||
that.enabled = true;
|
||||
});
|
||||
});
|
||||
|
||||
this._keyboardContext.defaultKeyboardEnabled(
|
||||
this._showEnabledDefaultDialog);
|
||||
}
|
||||
};
|
||||
|
||||
return function ctor_kalCore(context, template) {
|
||||
return new KeyboardAddLayoutsCore(context, template);
|
||||
};
|
||||
});
|
||||
56
gaia/apps/settings/js/panels/keyboard_add_layouts/keyboard_template.js
Executable file
56
gaia/apps/settings/js/panels/keyboard_add_layouts/keyboard_template.js
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* The template function for generating an UI element for a keyboard object.
|
||||
*
|
||||
* @module keyboard_add_layouts/keyboard_template
|
||||
*/
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var ListView = require('modules/mvvm/list_view');
|
||||
|
||||
return function kal_keyboardTemplate(keyboard, recycled, helper) {
|
||||
// This function is served as a parent template, we expected to get the
|
||||
// childTemplate and all generated list views.
|
||||
// XXX: we need a better way the recycle and reuse list view objects.
|
||||
var layoutTemplate = this.childTemplate;
|
||||
var listViews = this.listViews;
|
||||
|
||||
var container, header, h2, ul, listView;
|
||||
if (recycled) {
|
||||
container = recycled;
|
||||
h2 = container.querySelector('h2');
|
||||
ul = container.querySelector('ul');
|
||||
} else {
|
||||
container = document.createElement('div');
|
||||
header = document.createElement('header');
|
||||
h2 = document.createElement('h2');
|
||||
ul = document.createElement('ul');
|
||||
header.appendChild(h2);
|
||||
container.appendChild(header);
|
||||
container.appendChild(ul);
|
||||
}
|
||||
|
||||
// if we find a listView for the ul, reuse it, otherwise create one
|
||||
listView = listViews.some(function eachListView(list) {
|
||||
if (list.element === ul) {
|
||||
list.set(keyboard.layouts);
|
||||
list.enabled = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!listView) {
|
||||
listView = ListView(ul, keyboard.layouts, layoutTemplate);
|
||||
listView.enabled = true;
|
||||
listViews.push(listView);
|
||||
}
|
||||
|
||||
helper.observeAndCall(keyboard, {
|
||||
name: function refreshName() {
|
||||
h2.textContent = keyboard.name;
|
||||
}
|
||||
});
|
||||
|
||||
return container;
|
||||
};
|
||||
});
|
||||
46
gaia/apps/settings/js/panels/keyboard_add_layouts/layout_template.js
Executable file
46
gaia/apps/settings/js/panels/keyboard_add_layouts/layout_template.js
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* The template function for generating an UI element for a layout object.
|
||||
*
|
||||
* @module keyboard_add_layouts/layout_template
|
||||
*/
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
return function kal_layoutTemplate(layout, recycled, helper) {
|
||||
var container = null;
|
||||
var nameBdi, checkbox;
|
||||
if (recycled) {
|
||||
container = recycled;
|
||||
checkbox = container.querySelector('gaia-checkbox');
|
||||
nameBdi = container.querySelector('bdi');
|
||||
} else {
|
||||
container = document.createElement('li');
|
||||
checkbox = document.createElement('gaia-checkbox');
|
||||
nameBdi = document.createElement('bdi');
|
||||
|
||||
checkbox.appendChild(document.createElement('label'));
|
||||
checkbox.lastChild.appendChild(nameBdi);
|
||||
|
||||
container.appendChild(checkbox);
|
||||
}
|
||||
|
||||
if (layout.nameL10nId) {
|
||||
nameBdi.dataset.l10nId = layout.nameL10nId;
|
||||
}
|
||||
|
||||
checkbox.addEventListener('change', function(e) {
|
||||
layout.enabled = e.target.checked;
|
||||
});
|
||||
|
||||
helper.observeAndCall(layout, {
|
||||
name: function refreshName() {
|
||||
nameBdi.textContent = layout.name;
|
||||
},
|
||||
enabled: function() {
|
||||
checkbox.checked = layout.enabled;
|
||||
}
|
||||
});
|
||||
|
||||
return container;
|
||||
};
|
||||
});
|
||||
29
gaia/apps/settings/js/panels/keyboard_add_layouts/nested_template_factory.js
Executable file
29
gaia/apps/settings/js/panels/keyboard_add_layouts/nested_template_factory.js
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* This is a factory method that returns a template function that is able to
|
||||
* render nested lists. The constructor takes two template functions. One for
|
||||
* the first level item and one for the second level item. The created inner
|
||||
* list views is exposed via the listViews property.
|
||||
*
|
||||
* @module keyboard_add_layouts/nested_template_factory
|
||||
*/
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
return function ctor_nestedTemplate(parentTemplate, childTemplate) {
|
||||
var listViews = [];
|
||||
var template = parentTemplate.bind({
|
||||
listViews: listViews,
|
||||
childTemplate: childTemplate
|
||||
});
|
||||
|
||||
// Expose the list views.
|
||||
Object.defineProperty(template, 'listViews', {
|
||||
configurable: false,
|
||||
get: function() {
|
||||
return listViews;
|
||||
}
|
||||
});
|
||||
|
||||
return template;
|
||||
};
|
||||
});
|
||||
37
gaia/apps/settings/js/panels/keyboard_add_layouts/panel.js
Executable file
37
gaia/apps/settings/js/panels/keyboard_add_layouts/panel.js
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var SettingsPanel = require('modules/settings_panel');
|
||||
var KeyboardContext = require('modules/keyboard_context');
|
||||
var KeyboardHelper = require('shared/keyboard_helper');
|
||||
var NestedTemplateFactory =
|
||||
require('panels/keyboard_add_layouts/nested_template_factory');
|
||||
var keyboardTemplate =
|
||||
require('panels/keyboard_add_layouts/keyboard_template');
|
||||
var layoutTemplate = require('panels/keyboard_add_layouts/layout_template');
|
||||
var Core = require('panels/keyboard_add_layouts/core');
|
||||
|
||||
return function ctor_addLayoutsPanel() {
|
||||
var nestedTemplate =
|
||||
NestedTemplateFactory(keyboardTemplate, layoutTemplate);
|
||||
var core = Core(KeyboardContext, nestedTemplate);
|
||||
|
||||
return SettingsPanel({
|
||||
onInit: function kalp_onInit(rootElement) {
|
||||
core.init({
|
||||
listViewRoot: rootElement.querySelector('.keyboardAppContainer')
|
||||
});
|
||||
},
|
||||
onBeforeShow: function kalp_onBeforeShow() {
|
||||
core.enabled = true;
|
||||
},
|
||||
onBeforeHide: function kalp_onBeforeHide() {
|
||||
// save changes to settings
|
||||
KeyboardHelper.saveToSettings();
|
||||
},
|
||||
onHide: function kalp_onHide() {
|
||||
core.enabled = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
Loading…
Reference in a new issue