mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-08 07:48:02 +08:00
7ef9ebb45f
Added "[labs]imap_folder_list_limit" setting (optimization)
20 lines
6.4 KiB
JavaScript
20 lines
6.4 KiB
JavaScript
/*
|
|
Knockout.Punches
|
|
Enhanced binding syntaxes for Knockout 3+
|
|
(c) Michael Best
|
|
License: MIT (http://www.opensource.org/licenses/mit-license.php)
|
|
Version 0.5.0
|
|
*/
|
|
(function(c){"function"===typeof define&&define.amd?define(["knockout"],c):c(ko)})(function(c){function k(a,b){return u(B(a),"preprocess",b)}function B(a){return"object"===typeof a?a:c.getBindingHandler(a)||(c.bindingHandlers[a]={})}function u(a,b,d){if(a[b]){var g=a[b];a[b]=function(a,b,c){if(a=g.call(this,a,b,c))return d.call(this,a,b,c)}}else a[b]=d;return a}function r(a){var b=c.bindingProvider.instance;if(b.preprocessNode){var d=b.preprocessNode;b.preprocessNode=function(b){var c=d.call(this,
|
|
b);c||(c=a.call(this,b));return c}}else b.preprocessNode=a}function D(a,b){var d=c.getBindingHandler;c.getBindingHandler=function(g){var c;return d(g)||(c=g.match(a))&&b(c,g)}}function v(a){if(-1===a.indexOf("|"))return a;var b=a.match(/"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|\|\||[|:]|[^\s|:"'][^|:"']*[^\s|:"']|[^\s|:"']/g);if(b&&1<b.length){b.push("|");a=b[0];for(var d,c,e=!1,f=!1,C=1;c=b[C];++C)"|"===c?(e&&(":"===d&&(a+="undefined"),a+=")"),e=f=!0):(f?a="ko.filters['"+c+"']("+a:e&&":"===c?(":"===d&&(a+=
|
|
"undefined"),a+=","):a+=c,f=!1),d=c}return a}function w(a){k(a,v)}function x(a,b,d){function g(d){e[d]&&(e[d]=function(g,e){var h=Array.prototype.slice.call(arguments,0);h[1]=function(){var b={};b[a]=e();return b};return c.bindingHandlers[b][d].apply(this,h)})}var e=c.utils.extend({},this);g("init");g("update");e.preprocess&&(e.preprocess=null);c.virtualElements.allowedBindings[b]&&(c.virtualElements.allowedBindings[d]=!0);return e}function s(a,b){var d=c.getBindingHandler(a);if(d){var g=d.getNamespacedHandler||
|
|
x;d.getNamespacedHandler=function(){return k(g.apply(this,arguments),b)}}}function E(a,b,d){if("{"!==a.charAt(0))return a;a=c.expressionRewriting.parseObjectLiteral(a);c.utils.arrayForEach(a,function(a){d(b+F+a.key,a.value)})}function p(a){k(a,E)}function m(a){return/^([$_a-z][$\w]*|.+(\.\s*[$_a-z][$\w]*|\[.+\]))$/i.test(a)?"function(_x,_y,_z){return("+a+")(_x,_y,_z);}":a}function t(a){k(a,m)}function q(a,b,d){a=B(a);a._propertyPreprocessors||(u(a,"preprocess",N),a._propertyPreprocessors={});u(a._propertyPreprocessors,
|
|
b,d)}function N(a,b,d){if("{"!==a.charAt(0))return a;a=c.expressionRewriting.parseObjectLiteral(a);var g=[],e=this._propertyPreprocessors||{};c.utils.arrayForEach(a,function(a){var b=a.key;a=a.value;e[b]&&(a=e[b](a,b,d));a&&g.push("'"+b+"':"+a)});return"{"+g.join(",")+"}"}function y(a){return function(b){return"function("+a+"){return("+b+");}"}}function G(a,b,d){function c(a){var f=a.match(/^([\s\S]*)}}([\s\S]*?)\{\{([\s\S]*)$/);f?(c(f[1]),b(f[2]),d(f[3])):d(a)}if(a=a.match(/^([\s\S]*?)\{\{([\s\S]*)}}([\s\S]*)$/))b(a[1]),
|
|
c(a[2]),b(a[3])}function z(a){return null==a?"":a.trim?a.trim():a.toString().replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")}function H(a){if(3===a.nodeType&&a.nodeValue&&-1!==a.nodeValue.indexOf("{{")&&"TEXTAREA"!=(a.parentNode||{}).nodeName){var b=[];G(a.nodeValue,function(a){a&&b.push(document.createTextNode(a))},function(d){d&&b.push.apply(b,O.wrapExpression(d,a))});if(b.length){if(a.parentNode){for(var d=0,c=b.length,e=a.parentNode;d<c;++d)e.insertBefore(b[d],a);e.removeChild(a)}return b}}}function I(){r(H)}
|
|
function J(a){if(1===a.nodeType&&a.attributes.length)for(var b=a.getAttribute(A),d=c.utils.arrayPushAll([],a.attributes),g=d.length,e=0;e<g;++e){var f=d[e];if(f.specified&&f.name!=A&&-1!==f.value.indexOf("{{")){var h=[],n="";G(f.value,function(a){a&&h.push('"'+a.replace(/"/g,'\\"')+'"')},function(a){a&&(n=a,h.push("ko.unwrap("+a+")"))});1<h.length&&(n='""+'+h.join("+"));if(n){var k=f.name.toLowerCase(),k=P.attributeBinding(k,n,a)||K(k,n,a),b=b?b+(","+k):k;a.setAttribute(A,b);a.removeAttribute(f.name)}}}}
|
|
function K(a,b,d){return c.getBindingHandler(a)?a+":"+b:"attr."+a+":"+b}function L(){r(J)}var l=c.unwrap,h=c.punches={utils:{addBindingPreprocessor:k,addNodePreprocessor:r,addBindingHandlerCreator:D,setBindingPreprocessor:k,setNodePreprocessor:r}};h.enableAll=function(){I();L();p("attr");p("css");p("event");p("style");w("text");w("html");s("attr",v);t("click");t("submit");t("optionsAfterRender");s("event",m);q("template","beforeRemove",m);q("template","afterAdd",m);q("template","afterRender",m)};
|
|
c.filters={uppercase:function(a){return String.prototype.toUpperCase.call(l(a))},lowercase:function(a){return String.prototype.toLowerCase.call(l(a))},"default":function(a,b){a=l(a);return"function"===typeof a?a:"string"===typeof a?""===z(a)?b:a:null==a||0==a.length?b:a},replace:function(a,b,d){return String.prototype.replace.call(l(a),b,d)},fit:function(a,b,d,c){a=l(a);if(b&&(""+a).length>b)switch(d=""+(d||"..."),b-=d.length,a=""+a,c){case "left":return d+a.slice(-b);case "middle":return c=Math.ceil(b/
|
|
2),a.substr(0,c)+d+a.slice(c-b);default:return a.substr(0,b)+d}else return a},json:function(a,b,d){return c.toJSON(a,d,b)},number:function(a){return(+l(a)).toLocaleString()}};h.textFilter={preprocessor:v,enableForBinding:w};var F=".";D(/([^\.]+)\.(.+)/,function(a,b){var d=a[1],g=c.bindingHandlers[d];if(g)return d=(g.getNamespacedHandler||x).call(g,a[2],d,b),c.bindingHandlers[b]=d});h.namespacedBinding={defaultGetHandler:x,setDefaultBindingPreprocessor:s,addDefaultBindingPreprocessor:s,preprocessor:E,
|
|
enableForBinding:p};h.wrappedCallback={preprocessor:m,enableForBinding:t};h.preprocessBindingProperty={setPreprocessor:q,addPreprocessor:q};var M=y("$data,$event");h.expressionCallback={makePreprocessor:y,eventPreprocessor:M,enableForBinding:function(a,b){b=Array.prototype.slice.call(arguments,1).join();k(a,y(b))}};c.bindingHandlers.on={getNamespacedHandler:function(a){a=c.getBindingHandler("event"+F+a);return k(a,M)}};if(!c.virtualElements.allowedBindings.html){var Q=c.bindingHandlers.html.update;
|
|
c.bindingHandlers.html.update=function(a,b){if(8===a.nodeType){var d=l(b());null!=d?(d=c.utils.parseHtmlFragment(""+d),c.virtualElements.setDomNodeChildren(a,d)):c.virtualElements.emptyNode(a)}else Q(a,b)};c.virtualElements.allowedBindings.html=!0}var O=h.interpolationMarkup={preprocessor:H,enable:I,wrapExpression:function(a,b){var d=b?b.ownerDocument:document,c=!0,e,f=a[0],h=a[a.length-1],k=[];if("#"===f){if("/"===h?e=a.slice(1,-1):(e=a.slice(1),c=!1),f=e.match(/^([^,"'{}()\/:[\]\s]+)\s+([^\s:].*)/))e=
|
|
f[1]+":"+f[2]}else"/"!==f&&(e="{"===f&&"}"===h?"html:"+z(a.slice(1,-1)):"text:"+z(a));e&&k.push(d.createComment("ko "+e));c&&k.push(d.createComment("/ko"));return k}},A="data-bind",P=h.attributeInterpolationMarkup={preprocessor:J,enable:L,attributeBinding:K};return h});
|