mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Bugfix: compose mail select contacts for cc/bcc failed
Cleanup: Inputosaurus and Knockout Change: Knockout domData now uses WeakMap Replaced: Knockout domManipulation with a documentFragment
This commit is contained in:
parent
fe7c7fede4
commit
ebe2c0536f
23 changed files with 410 additions and 889 deletions
131
vendors/knockout/src/templating/templateSources.js
vendored
131
vendors/knockout/src/templating/templateSources.js
vendored
|
|
@ -7,109 +7,52 @@
|
|||
// 2. ko.templateSources.anonymousElement - uses ko.utils.domData to read/write text *associated* with the DOM element, but
|
||||
// without reading/writing the actual element text content, since it will be overwritten
|
||||
// with the rendered template output.
|
||||
// You can implement your own template source if you want to fetch/store templates somewhere other than in DOM elements.
|
||||
// Template sources need to have the following functions:
|
||||
// text() - returns the template text from your storage location
|
||||
// text(value) - writes the supplied template text to your storage location
|
||||
// data(key) - reads values stored using data(key, value) - see below
|
||||
// data(key, value) - associates "value" with this template and the key "key". Is used to store information like "isRewritten".
|
||||
//
|
||||
// Optionally, template sources can also have the following functions:
|
||||
// nodes() - returns a DOM element containing the nodes of this template, where available
|
||||
// nodes(value) - writes the given DOM element to your storage location
|
||||
// If a DOM element is available for a given template source, template engines are encouraged to use it in preference over text()
|
||||
// for improved speed. However, all templateSources must supply text() even if they don't supply nodes().
|
||||
//
|
||||
// Once you've implemented a templateSource, make your template engine use it by subclassing whatever template engine you were
|
||||
// using and overriding "makeTemplateSource" to return an instance of your custom template source.
|
||||
|
||||
ko.templateSources = {};
|
||||
|
||||
// ---- ko.templateSources.domElement -----
|
||||
|
||||
// template types
|
||||
var templateTemplate = 3,
|
||||
templateElement = 4;
|
||||
|
||||
ko.templateSources.domElement = function(element) {
|
||||
this.domElement = element;
|
||||
|
||||
if (element) {
|
||||
this.templateType =
|
||||
element.matches("TEMPLATE") && element.content && element.content.nodeType === 11 ? templateTemplate :
|
||||
templateElement;
|
||||
}
|
||||
}
|
||||
|
||||
ko.templateSources.domElement.prototype['text'] = function(/* valueToWrite */) {
|
||||
var elemContentsProperty = "innerHTML";
|
||||
if (arguments.length == 0) {
|
||||
return this.domElement.innerHTML;
|
||||
}
|
||||
ko.utils.setHtml(this.domElement, arguments[0]);
|
||||
};
|
||||
|
||||
var dataDomDataPrefix = ko.utils.domData.nextKey() + "_";
|
||||
ko.templateSources.domElement.prototype['data'] = function(key /*, valueToWrite */) {
|
||||
if (arguments.length === 1) {
|
||||
return ko.utils.domData.get(this.domElement, dataDomDataPrefix + key);
|
||||
}
|
||||
ko.utils.domData.set(this.domElement, dataDomDataPrefix + key, arguments[1]);
|
||||
};
|
||||
|
||||
var templatesDomDataKey = ko.utils.domData.nextKey();
|
||||
function getTemplateDomData(element) {
|
||||
return ko.utils.domData.get(element, templatesDomDataKey) || {};
|
||||
}
|
||||
function setTemplateDomData(element, data) {
|
||||
ko.utils.domData.set(element, templatesDomDataKey, data);
|
||||
}
|
||||
|
||||
ko.templateSources.domElement.prototype['nodes'] = function(/* valueToWrite */) {
|
||||
var element = this.domElement;
|
||||
if (arguments.length == 0) {
|
||||
var templateData = getTemplateDomData(element),
|
||||
nodes = templateData.containerData || (
|
||||
this.templateType === templateTemplate ? element.content :
|
||||
this.templateType === templateElement ? element :
|
||||
undefined);
|
||||
if (!nodes || templateData.alwaysCheckText) {
|
||||
// If the template is associated with an element that stores the template as text,
|
||||
// parse and cache the nodes whenever there's new text content available. This allows
|
||||
// the user to update the template content by updating the text of template node.
|
||||
var text = this['text']();
|
||||
if (text && text !== templateData.textData) {
|
||||
nodes = ko.utils.parseHtmlForTemplateNodes(text, element.ownerDocument);
|
||||
setTemplateDomData(element, {containerData: nodes, textData: text, alwaysCheckText: true});
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
var valueToWrite = arguments[0];
|
||||
if (this.templateType !== undefined) {
|
||||
this['text'](""); // clear the text from the node
|
||||
}
|
||||
setTemplateDomData(element, {containerData: valueToWrite});
|
||||
};
|
||||
let templatesDomDataKey = ko.utils.domData.nextKey();
|
||||
|
||||
// ---- ko.templateSources.anonymousTemplate -----
|
||||
// Anonymous templates are normally saved/retrieved as DOM nodes through "nodes".
|
||||
// For compatibility, you can also read "text"; it will be serialized from the nodes on demand.
|
||||
// Writing to "text" is still supported, but then the template data will not be available as DOM nodes.
|
||||
|
||||
ko.templateSources.anonymousTemplate = function(element) {
|
||||
this.domElement = element;
|
||||
};
|
||||
ko.templateSources.anonymousTemplate.prototype = new ko.templateSources.domElement();
|
||||
ko.templateSources.anonymousTemplate.prototype.constructor = ko.templateSources.anonymousTemplate;
|
||||
ko.templateSources.anonymousTemplate.prototype['text'] = function(/* valueToWrite */) {
|
||||
if (arguments.length == 0) {
|
||||
var templateData = getTemplateDomData(this.domElement);
|
||||
if (templateData.textData === undefined && templateData.containerData)
|
||||
templateData.textData = templateData.containerData.innerHTML;
|
||||
return templateData.textData;
|
||||
class anonymousTemplate
|
||||
{
|
||||
constructor(element)
|
||||
{
|
||||
this.domElement = element;
|
||||
}
|
||||
var valueToWrite = arguments[0];
|
||||
setTemplateDomData(this.domElement, {textData: valueToWrite});
|
||||
|
||||
nodes(...args)
|
||||
{
|
||||
let element = this.domElement;
|
||||
if (!args.length) {
|
||||
return ko.utils.domData.get(element, templatesDomDataKey) || (
|
||||
this.templateType === 11 ? element.content :
|
||||
this.templateType === 1 ? element :
|
||||
undefined);
|
||||
}
|
||||
ko.utils.domData.set(element, templatesDomDataKey, args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- ko.templateSources.domElement -----
|
||||
class domElement extends anonymousTemplate
|
||||
{
|
||||
constructor(element)
|
||||
{
|
||||
super(element);
|
||||
|
||||
if (element) {
|
||||
this.templateType =
|
||||
element.matches("TEMPLATE") && element.content ? element.content.nodeType : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ko.templateSources = {
|
||||
domElement: domElement,
|
||||
anonymousTemplate: anonymousTemplate
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue