mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 06:57:03 +03:00
Drop support for old browsers and some jQuery
This commit is contained in:
parent
091c4ec811
commit
d06fed09d6
38 changed files with 6137 additions and 872 deletions
|
|
@ -1,84 +0,0 @@
|
|||
(function() {
|
||||
ko.jqueryTmplTemplateEngine = function () {
|
||||
// Detect which version of jquery-tmpl you're using. Unfortunately jquery-tmpl
|
||||
// doesn't expose a version number, so we have to infer it.
|
||||
// Note that as of Knockout 1.3, we only support jQuery.tmpl 1.0.0pre and later,
|
||||
// which KO internally refers to as version "2", so older versions are no longer detected.
|
||||
var jQueryTmplVersion = this.jQueryTmplVersion = (function() {
|
||||
if (!jQueryInstance || !(jQueryInstance['tmpl']))
|
||||
return 0;
|
||||
// Since it exposes no official version number, we use our own numbering system. To be updated as jquery-tmpl evolves.
|
||||
try {
|
||||
if (jQueryInstance['tmpl']['tag']['tmpl']['open'].toString().indexOf('__') >= 0) {
|
||||
// Since 1.0.0pre, custom tags should append markup to an array called "__"
|
||||
return 2; // Final version of jquery.tmpl
|
||||
}
|
||||
} catch(ex) { /* Apparently not the version we were looking for */ }
|
||||
|
||||
return 1; // Any older version that we don't support
|
||||
})();
|
||||
|
||||
function ensureHasReferencedJQueryTemplates() {
|
||||
if (jQueryTmplVersion < 2)
|
||||
throw new Error("Your version of jQuery.tmpl is too old. Please upgrade to jQuery.tmpl 1.0.0pre or later.");
|
||||
}
|
||||
|
||||
function executeTemplate(compiledTemplate, data, jQueryTemplateOptions) {
|
||||
return jQueryInstance['tmpl'](compiledTemplate, data, jQueryTemplateOptions);
|
||||
}
|
||||
|
||||
this['renderTemplateSource'] = function(templateSource, bindingContext, options, templateDocument) {
|
||||
templateDocument = templateDocument || document;
|
||||
options = options || {};
|
||||
ensureHasReferencedJQueryTemplates();
|
||||
|
||||
// Ensure we have stored a precompiled version of this template (don't want to reparse on every render)
|
||||
var precompiled = templateSource['data']('precompiled');
|
||||
if (!precompiled) {
|
||||
var templateText = templateSource['text']() || "";
|
||||
// Wrap in "with($whatever.koBindingContext) { ... }"
|
||||
templateText = "{{ko_with $item.koBindingContext}}" + templateText + "{{/ko_with}}";
|
||||
|
||||
precompiled = jQueryInstance['template'](null, templateText);
|
||||
templateSource['data']('precompiled', precompiled);
|
||||
}
|
||||
|
||||
var data = [bindingContext['$data']]; // Prewrap the data in an array to stop jquery.tmpl from trying to unwrap any arrays
|
||||
var jQueryTemplateOptions = jQueryInstance['extend']({ 'koBindingContext': bindingContext }, options['templateOptions']);
|
||||
|
||||
var resultNodes = executeTemplate(precompiled, data, jQueryTemplateOptions);
|
||||
resultNodes['appendTo'](templateDocument.createElement("div")); // Using "appendTo" forces jQuery/jQuery.tmpl to perform necessary cleanup work
|
||||
|
||||
jQueryInstance['fragments'] = {}; // Clear jQuery's fragment cache to avoid a memory leak after a large number of template renders
|
||||
return resultNodes;
|
||||
};
|
||||
|
||||
this['createJavaScriptEvaluatorBlock'] = function(script) {
|
||||
return "{{ko_code ((function() { return " + script + " })()) }}";
|
||||
};
|
||||
|
||||
this['addTemplate'] = function(templateName, templateMarkup) {
|
||||
document.write("<script type='text/html' id='" + templateName + "'>" + templateMarkup + "<" + "/script>");
|
||||
};
|
||||
|
||||
if (jQueryTmplVersion > 0) {
|
||||
jQueryInstance['tmpl']['tag']['ko_code'] = {
|
||||
open: "__.push($1 || '');"
|
||||
};
|
||||
jQueryInstance['tmpl']['tag']['ko_with'] = {
|
||||
open: "with($1) {",
|
||||
close: "} "
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine();
|
||||
ko.jqueryTmplTemplateEngine.prototype.constructor = ko.jqueryTmplTemplateEngine;
|
||||
|
||||
// Use this one by default *only if jquery.tmpl is referenced*
|
||||
var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine();
|
||||
if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0)
|
||||
ko.setTemplateEngine(jqueryTmplTemplateEngineInstance);
|
||||
|
||||
ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine);
|
||||
})();
|
||||
|
|
@ -5,16 +5,13 @@ ko.nativeTemplateEngine = function () {
|
|||
ko.nativeTemplateEngine.prototype = new ko.templateEngine();
|
||||
ko.nativeTemplateEngine.prototype.constructor = ko.nativeTemplateEngine;
|
||||
ko.nativeTemplateEngine.prototype['renderTemplateSource'] = function (templateSource, bindingContext, options, templateDocument) {
|
||||
var useNodesIfAvailable = !(ko.utils.ieVersion < 9), // IE<9 cloneNode doesn't work properly
|
||||
templateNodesFunc = useNodesIfAvailable ? templateSource['nodes'] : null,
|
||||
templateNodes = templateNodesFunc ? templateSource['nodes']() : null;
|
||||
|
||||
var templateNodesFunc = templateSource.nodes,
|
||||
templateNodes = templateNodesFunc ? templateSource.nodes() : null;
|
||||
if (templateNodes) {
|
||||
return ko.utils.makeArray(templateNodes.cloneNode(true).childNodes);
|
||||
} else {
|
||||
var templateText = templateSource['text']();
|
||||
return ko.utils.parseHtmlFragment(templateText, templateDocument);
|
||||
}
|
||||
var templateText = templateSource['text']();
|
||||
return ko.utils.parseHtmlFragment(templateText, templateDocument);
|
||||
};
|
||||
|
||||
ko.nativeTemplateEngine.instance = new ko.nativeTemplateEngine();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue